Commit Graph

515 Commits

Author SHA1 Message Date
Francisco Casas
e1c759e1c9 vkd3d-shader/hlsl: Record valid methods in object_methods[].
Also, call hlsl_sampler_dim_count() and hlsl_offset_dim_count() after
type checking, to avoid reaching unreacheable cases.
2024-02-19 21:11:46 +01:00
Evan Tang
ee867bd470 vkd3d-shader/hlsl: Parse rasteriser-ordered view types. 2024-02-15 23:29:46 +01:00
Giovanni Mascellani
5905489b7f vkd3d-shader/hlsl: Free the selector in postfix_expr (Valgrind). 2024-02-09 22:47:46 +01:00
Giovanni Mascellani
a10de1b239 vkd3d-shader/hlsl: Free the individual attributes in func_prototype (Valgrind). 2024-02-09 22:47:45 +01:00
Giovanni Mascellani
049327a270 vkd3d-shader/hlsl: Free the parse initializer in attribute (Valgrind). 2024-02-09 22:47:44 +01:00
Giovanni Mascellani
521082afbe vkd3d-shader/hlsl: Free variable identifiers in primary_expr (Valgrind). 2024-02-09 22:47:42 +01:00
Zebediah Figura
a8b0c03912 vkd3d-shader/hlsl: Always cast to bool in if() statements.
We emit sm4 if_nz for these, but that does a bitwise comparison to zero, which is wrong for floats.
2024-01-23 20:26:46 +01:00
Zebediah Figura
183172eff4 vkd3d-shader/hlsl: Validate that condition expressions are numeric. 2024-01-23 20:26:45 +01:00
Zebediah Figura
09220edd21 vkd3d-shader/hlsl: Validate the condition data type for loops as well. 2024-01-23 20:26:44 +01:00
Nikolay Sivov
2c1905b780 vkd3d-shader/hlsl: Allow annotations on techniques.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-01-23 20:26:19 +01:00
Nikolay Sivov
76a689d43f vkd3d-shader/hlsl: Allow annotations on passes.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-01-23 20:26:18 +01:00
Nikolay Sivov
e72f8f9a30 vkd3d-shader/hlsl: Add passes variables to the techniques.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-01-23 20:26:16 +01:00
Nikolay Sivov
fe8881747b vkd3d-shader/hlsl: Add initial support for parsing annotations.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-01-23 20:26:15 +01:00
Zebediah Figura
9ad48f16ea vkd3d-shader/hlsl: Forbid mismatched argument types in ternaries. 2024-01-18 23:15:44 +01:00
Zebediah Figura
275901557c vkd3d-shader/hlsl: Handle scalar values in ternaries. 2024-01-18 23:15:43 +01:00
Zebediah Figura
11112798c8 vkd3d-shader/hlsl: Handle scalar conditions in ternaries. 2024-01-18 23:15:42 +01:00
Zebediah Figura
2c8751478f vkd3d-shader/hlsl: Forbid objects in ternary conditions. 2024-01-18 23:15:41 +01:00
Zebediah Figura
16962ac6f1 vkd3d-shader/hlsl: Allow non-numeric types in the ternary operator. 2024-01-17 22:28:51 +01:00
Zebediah Figura
46bd099341 vkd3d-shader/hlsl: Separate an add_ternary() helper. 2024-01-17 22:28:50 +01:00
Nikolay Sivov
e1dca9b27a vkd3d-shader/hlsl: Add a scope for technique variables.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-01-15 19:57:39 +01:00
Nikolay Sivov
0a6d842ed1 vkd3d-shader/hlsl: Rename the rule for an optional name.
Names are optional for both techniques and passes.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-01-15 19:57:37 +01:00
Nikolay Sivov
e527d7c1e7 vkd3d-shader/hlsl: Handle effect group statement.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-01-11 23:04:46 +01:00
Nikolay Sivov
f7a02a5da2 vkd3d-shader/hlsl: Add variables for techniques.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-01-11 23:04:45 +01:00
Nikolay Sivov
8494342fa0 vkd3d-shader/hlsl: Rename rule for top-level techniques.
Only technique10 and technique11 types could be nested in groups.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-01-11 23:04:43 +01:00
Nikolay Sivov
c3af1f9989 vkd3d-shader/hlsl: Add 'fxgroup' token.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-01-11 23:04:42 +01:00
Henri Verbeet
3344c4e93d vkd3d-shader/hlsl: Store modifier flags as a uint32_t. 2024-01-08 21:45:26 +01:00
Henri Verbeet
fafe2a1dba vkd3d-shader/hlsl: Store swizzles as a uint32_t. 2024-01-08 21:45:24 +01:00
Zebediah Figura
98a02ceffb vkd3d-shader/hlsl: Avoid shadowing "load" in intrinsic_tex(). 2023-12-07 21:57:31 +01:00
Zebediah Figura
a102e99897 vkd3d-shader/hlsl: Avoid shadowing "block" in resolve_loop_continue(). 2023-12-07 21:57:30 +01:00
Nikolay Sivov
6a4a9a4518 vkd3d-shader/hlsl: Handle 'linear centroid' modifier. 2023-11-28 00:10:12 +01:00
Francisco Casas
4e1bf5e163 vkd3d-shader/hlsl: Discern between signed and unsigned ints when parsing. 2023-11-22 22:08:05 +01:00
Nikolay Sivov
e55b6a7fa1 vkd3d-shader/hlsl: Add constants to the block for log()/log10() builtins. 2023-11-20 22:07:24 +01:00
Akihiro Sagawa
aed2d142cf vkd3d-shader/hlsl: Add degrees() function. 2023-11-20 22:07:19 +01:00
Akihiro Sagawa
e493627130 vkd3d-shader/hlsl: Add radians() function. 2023-11-20 22:07:17 +01:00
Nikolay Sivov
88caf87789 vkd3d-shader/hlsl: Add a helper to check for a numeric type. 2023-11-15 21:48:49 +01:00
Nikolay Sivov
418c177a1b vkd3d-shader/hlsl: Implement texCUBEproj().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-10 20:23:44 +01:00
Nikolay Sivov
81ff57e07c vkd3d-shader/hlsl: Implement tex3Dproj().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-10 20:23:43 +01:00
Nikolay Sivov
dd6a9135f4 vkd3d-shader/hlsl: Implement tex2Dproj().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-10 20:23:41 +01:00
Zebediah Figura
fef118555c vkd3d-shader/hlsl: Do not prioritize an exact match when looking up functions.
Native does not always do this. For example, functions whose parameters are
float and float1 always result in an "ambiguous function call" error.

This does not fix any tests, because the relevant tests previously (incorrectly)
succeeded, and now fail with:

E5017: Aborting due to not yet implemented feature: Prioritize between multiple compatible function overloads.

when they should simply fail.
2023-11-09 21:15:17 +01:00
Zebediah Figura
b1c2852cd7 vkd3d-shader/hlsl: Store function overloads in a list.
The choice to store them in an rbtree was made early on. It does not seem likely
that HLSL programs would define many overloads for any of their functions, but I
suspect the idea was rather that intrinsics would be defined as plain
hlsl_ir_function_decl structures [cf. 447463e590]
and that some intrinsics that could operate on any type would therefore need
many overrides.

This is not how we deal with intrinsics, however. When the first intrinsics were
implemented I made the choice disregard this intended design, and instead match
and convert their types manually, in C. Nothing that has happened in the time
since has led me to question that choice, and in fact, the flexibility with
which we must accommodate functions has led me to believe that matching in this
way was definitely the right choice. The main other designs I see would have
been:

* define each intrinsic variant separately using existing HLSL types. Besides
  efficiency concerns (i.e. this would take more space in memory, and would take
  longer to generate each variant), the normal type-matching rules don't really
  apply to intrinsics.

  [For example: elementwise intrinsics like abs() return the same type as the
  input, including preserving the distinction between float and float1. It is
  legal to define separate HLSL overloads taking float and float1, but trying to
  invoke these functions yields an "ambiguous function call" error.]

* introduce new (semi-)generic types. This is far more code and ends up acting
  like our current scheme (with helpers) in a slightly more complex form.

So I think we can go ahead and rip out this vestige of the original design for
intrinsics.

As for why to change it: rbtrees are simply more complex to deal with, and it
seems unlikely to me that the difference is going to matter. I do not expect any
program to define large quantities of intrinsics; linked list search should be
good enough.
2023-11-09 21:15:11 +01:00
Zebediah Figura
2b59a759d5 vkd3d-shader/hlsl: Rename hlsl_get_func_decl() to hlsl_get_first_func_decl(). 2023-11-09 21:15:09 +01:00
Nikolay Sivov
4284b7c522 vkd3d-shader/hlsl: Parse ceil() function.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-08 22:49:37 +01:00
Nikolay Sivov
522a0dfb56 vkd3d-shader/hlsl: Add tex2Dlod() function.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-08 22:49:26 +01:00
Zebediah Figura
4cfc7d44ab vkd3d-shader/hlsl: Remove some tokens from the lexer.
None of these currently have any meaning, and none of these can currently be
parsed as distinct tokens either (i.e. they will generate a syntax error
anyway).
2023-11-06 23:09:18 +01:00
Nikolay Sivov
dbcc4c4e40 vkd3d-shader/hlsl: Parse empty technique declarations.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-02 18:23:07 +01:00
Nikolay Sivov
ea8ff5394c vkd3d-shader/hlsl: Add a keyword for fx_5_0 techniques.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-02 18:23:05 +01:00
Nikolay Sivov
ecdc3f39d4 vkd3d-shader: Accept 'loop' attribute, on loops.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-01 21:47:49 +01:00
Nikolay Sivov
26784672d8 vkd3d-shader: Check loop [unroll] attribute for conflict with other attributes.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-01 21:47:49 +01:00
Nikolay Sivov
72623031a2 vkd3d-shader/hlsl: Validate break/continue context.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-31 21:59:01 +01:00
Nikolay Sivov
9a6e4a0c58 vkd3d-shader/hlsl: Check for duplicate case statements.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-31 21:58:59 +01:00
Nikolay Sivov
ec8dfa467f vkd3d-shader/hlsl: Add initial support for parsing 'switch' statements.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-31 21:58:57 +01:00
Henri Verbeet
96556a8834 vkd3d-shader/hlsl: Add support for RWTexture2DArray. 2023-10-19 23:07:31 +02:00
Henri Verbeet
2c71c18879 vkd3d-shader/hlsl: Add support for RWTexture1DArray. 2023-10-19 23:07:30 +02:00
Nikolay Sivov
1930b51d97 vkd3d-shader/hlsl: Allow interpolation modifiers on structure fields.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-09 21:58:27 +02:00
Nikolay Sivov
de860c3cbf vkd3d-shader/hlsl: Parse 'centroid' and 'noperspective' modifiers.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-09 21:58:24 +02:00
Nikolay Sivov
e4b423d6b5 vkd3d-shader/hlsl: Handle 'continue' statements.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-09 21:58:14 +02:00
Nikolay Sivov
0e5749e78e vkd3d-shader/hlsl: Allow 'break' instructions in loops.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-09 21:58:12 +02:00
Nikolay Sivov
b5c0c9c22f vkd3d-shader/hlsl: Add fwidth() function.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-05 16:15:10 +02:00
Petrichor Park
976fd67f51 vkd3d-shader/hlsl: Implement intrinsic tan.
This commit also extends the trigonometry tests a little bit to make
sure that tan works right.
2023-09-25 22:07:13 +02:00
Nikolay Sivov
177ea3bcbd vkd3d-shader/hlsl: Produce 2D resource declarations and loads for tex1D().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-09-13 23:11:11 +02:00
Nikolay Sivov
fc2aaee224 vkd3d-shader: Use ternary operator in fmod() implementation.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-09-07 19:15:26 +02:00
Nikolay Sivov
1002a6b357 vkd3d-shader/tpf: Use 'movc' to implement ternary operator.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-09-07 19:15:25 +02:00
Nikolay Sivov
c5d680d141 vkd3d-shader/hlsl: Add tex1D() function.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-09-07 19:15:06 +02:00
Zebediah Figura
a597dc8755 vkd3d-shader/hlsl: Define lit() in HLSL. 2023-08-30 22:49:03 +02:00
Zebediah Figura
9ab77658f2 vkd3d-shader/hlsl: Define smoothstep() in HLSL. 2023-08-30 22:49:01 +02:00
Zebediah Figura
f22e52f358 vkd3d-shader/hlsl: Separate an add_user_call() helper. 2023-08-30 22:48:57 +02:00
Nikolay Sivov
c39c5b3907 vkd3d-shader/hlsl: Add texCUBE() function.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-08-29 22:07:56 +02:00
Nikolay Sivov
18c1477464 vkd3d-shader/hlsl: Ignore 'inline' modifier for functions.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-08-28 20:39:53 +02:00
Nikolay Sivov
89eda51855 vkd3d-shader/hlsl: Change warning code for unknown loop attributes.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-08-24 21:43:50 +02:00
Nikolay Sivov
1153f6bb34 vkd3d-shader/hlsl: Parse "if" statement attributes.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-08-24 21:43:49 +02:00
Nikolay Sivov
4f2e07a45d vkd3d-shader/hlsl: Allow 'const' modifier without initializer in the global scope.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-08-15 21:51:50 +02:00
Zebediah Figura
0652bb1950 vkd3d-shader/hlsl: Store the "instrs" field of struct hlsl_attribute as a hlsl_block. 2023-08-08 21:15:08 +09:00
Zebediah Figura
372ddd1f29 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_load_component(). 2023-08-08 21:15:05 +09:00
Nikolay Sivov
d50b5fe767 vkd3d-shader/hlsl: Parse GetDimensions() method.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-07-31 21:07:48 +09:00
Zebediah Figura
819c5f1943 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_expr(). 2023-07-27 17:17:48 +09:00
Zebediah Figura
9d94506313 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_cast(). 2023-07-27 17:17:47 +09:00
Zebediah Figura
fe70ee2158 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_implicit_conversion(). 2023-07-27 17:17:46 +09:00
Zebediah Figura
21d5ee4df2 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_array_access(). 2023-07-27 17:17:41 +09:00
Zebediah Figura
c861a937e8 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_method_call(). 2023-07-27 17:17:37 +09:00
Zebediah Figura
f95ab2a5e8 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_assignment(). 2023-07-24 22:41:16 +02:00
Zebediah Figura
7e7a6d3691 vkd3d-shader/hlsl: Pass a hlsl_block pointer to hlsl_add_conditional(). 2023-07-24 22:41:15 +02:00
Zebediah Figura
cdabe172cb vkd3d-shader/hlsl: Return a hlsl_block from the "declaration" and "struct_declaration" rules. 2023-07-20 22:33:00 +02:00
Zebediah Figura
54bd6f7b4b vkd3d-shader/hlsl: Return a hlsl_block from the "declaration_statement" rule. 2023-07-20 22:32:59 +02:00
Zebediah Figura
77e1c5893e vkd3d-shader/hlsl: Return a hlsl_block from the "primary_expr" rule. 2023-07-20 22:32:57 +02:00
Zebediah Figura
aec9ea085e vkd3d-shader/hlsl: Return a hlsl_block from the "postfix_expr" rule. 2023-07-11 22:44:15 +02:00
Zebediah Figura
e222a786a1 vkd3d-shader/hlsl: Return a hlsl_block from binary and ternary expression rules. 2023-07-11 22:44:12 +02:00
Zebediah Figura
3079c874e3 vkd3d-shader/hlsl: Return a hlsl_block from the "unary_expr" rule. 2023-07-11 22:44:10 +02:00
Zebediah Figura
28dff58fb5 vkd3d-shader/hlsl: Return a hlsl_block from the "initializer_expr" rule. 2023-07-11 22:44:09 +02:00
Zebediah Figura
53d5ea639c vkd3d-shader/hlsl: Return a hlsl_block from the "assignment_expr" rule. 2023-07-11 22:44:06 +02:00
Zebediah Figura
6e303af519 vkd3d-shader/hlsl: Free the "iter" block pointer on success in create_loop().
Spotted by Giovanni Mascellani.
2023-07-05 22:32:48 +02:00
Zebediah Figura
b0ac77b44d vkd3d-shader/hlsl: Return a hlsl_block from the "expr_statement" and "expr" rules. 2023-07-05 22:32:47 +02:00
Zebediah Figura
07ce711583 vkd3d-shader/hlsl: Return a hlsl_block from the "jump_statement" rule. 2023-07-05 22:32:46 +02:00
Zebediah Figura
e4bf5933b9 vkd3d-shader/hlsl: Return a hlsl_block from the "selection_statement" rule. 2023-07-05 22:32:45 +02:00
Zebediah Figura
79dd9544b7 vkd3d-shader/hlsl: Return a hlsl_block from the "loop_statement" rule. 2023-07-05 22:32:43 +02:00
Zebediah Figura
23ff83e8a0 vkd3d-shader/hlsl: Return a hlsl_block from the "statement" rule.
As well as from the "statement_list" and "compound_statement" rules, which
trivially pass through from "statement".
2023-07-05 22:32:41 +02:00
Nikolay Sivov
06040d2a30 vkd3d-shader/hlsl: Disallow certain instruction types from constant expressions.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-07-04 22:39:57 +02:00
Nikolay Sivov
a65c0b0e22 vkd3d-shader/hlsl: Support evaluated expressions for sample count in multisampled textures declarations.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-07-04 22:39:55 +02:00
Francisco Casas
01800942a9 vkd3d-shader/hlsl: Declare vars individually when parsing struct declarations.
A struct declaration with variables is now absorbed into the 'declaration'
rule, like any other variable declaration.

A struct declaration without variables is now reduced to the
'struct_declaration_without_vars' rule.

They both are reduced to a 'declaration_statement' in the end.
2023-07-04 22:39:24 +02:00
Francisco Casas
62c891b796 vkd3d-shader/hlsl: Declare vars individually when parsing regular declarations.
In a declaration with multiple variables, the variables must be created
before the initializer of the next variable is parsed. This is required
for initializers such as:

    float a = 1, b = a, c = b + 1;

A requisite for this is that the type information is parsed in the same
rule as the first variable (as a variable_def_typed) so it is
immediately available to declare the first variable. Then, the next
untyped variable declaration is parsed, and the type from the first
variable can be used to declare the second, before the third is parsed,
and so on.
2023-07-04 22:39:21 +02:00
Francisco Casas
a34cf2e64e vkd3d-shader/hlsl: Split declare_vars().
Basically, declare_vars() is separated in three functions:

1. check_invalid_in_out_modifiers(), which is to be called once per
   declaration and emits an error when in or out modifiers are used for
   these non-parameter variables.

2. declare_var(), which now handles one variable at the time and doesn't
   free any memory.

3. initialize_vars(), which takes care of preparing the initialization
   instructions of several variables and frees their struct
   parse_variable_def, using exclusively free_parse_variable_def().

This allows to declare variables individually before the initializer of
the next variable in the same declaration is parsed, which is used in
the following patches.

Also, simplifies memory management.
2023-07-04 22:39:18 +02:00