Commit Graph

270 Commits

Author SHA1 Message Date
Shaun Ren
1ed5f1a4d0 vkd3d-shader/tpf: Write the patch constant function in hull shaders.
We use a single hs_fork_phase here for the patch constant function.
2024-10-16 21:40:40 +02:00
Shaun Ren
ae2d86b99c vkd3d-shader/tpf: Determine SIV from SV and index in write_sm4_dcl_semantic(). 2024-10-16 21:12:29 +02:00
Shaun Ren
df3aaac7cf vkd3d-shader/tpf: Introduce tpf_write_shader_function(). 2024-10-16 21:12:13 +02:00
Shaun Ren
147f8898ca vkd3d-shader/hlsl: Process the patch constant function in hlsl_emit_bytecode().
Also, support patch constant function semantics in sm4_sysval_semantic_from_semantic_name().
2024-10-16 21:10:24 +02:00
Shaun Ren
cbed70c60f vkd3d-shader/tpf: Implement semantics for hull shaders. 2024-10-16 21:07:53 +02:00
Shaun Ren
beb342ed5f vkd3d-shader/tpf: Write hull shader declarations. 2024-10-16 21:07:53 +02:00
Francisco Casas
7eee877dd4 vkd3d-shader/tpf: Make hlsl_sm4_register_from_semantic() independent of HLSL IR. 2024-10-16 21:07:51 +02:00
Francisco Casas
a243862b8c vkd3d-shader/tpf: Make sysval_semantic_from_hlsl() independent of HLSL IR. 2024-10-16 21:05:10 +02:00
Francisco Casas
7cc8151b81 vkd3d-shader/tpf: Replace uses of ctx->profile with tpf->program->shader_version. 2024-10-16 18:50:15 +02:00
Francisco Casas
c75fbaf94e vkd3d-shader/tpf: Use the I/O signatures from the vsir program in tpf_write_signature(). 2024-10-16 17:40:26 +02:00
Francisco Casas
10442369d8 vkd3d-shader/tpf: Pass a tpf_compiler structure to tpf_compile() callees. 2024-10-16 17:26:47 +02:00
Francisco Casas
16d9a10dd5 vkd3d-shader/tpf: Rename "tpf_writer" to "tpf_compiler".
Analog to d3dbc_compiler.
2024-10-16 17:09:15 +02:00
Francisco Casas
5b21cc67f1 vkd3d-shader/hlsl: Split hlsl_sm4_write().
Similarly to the already done split from

    HLSL IR -> d3dbc

to

    HLSL IR -> vsir -> d3bc

we now start splitting the

    HLSL IR -> tpf

translation into

    HLSL IR -> vsir -> tpf

So hlsl_sm4_write is split into two functions, sm4_generate_vsir() and
tpf_compile().

This translation should be completed once tpf_compile() no longer needs
the hlsl_ctx and entry_func parameters.
2024-10-16 17:08:50 +02:00
Francisco Casas
104435df5f vkd3d-shader/tpf: Use dcl_input_ps_sgv for sv_isfrontface.
As the native compiler does.
2024-10-15 16:44:38 +02:00
Francisco Casas
ad2f821ff5 vkd3d-shader/tpf: Write sysval semantic consistently.
Specifically we should write the sysval semantic as an instruction idx
for the following instructions:

    VKD3D_SM4_OP_DCL_INPUT_SGV
    VKD3D_SM4_OP_DCL_INPUT_PS_SGV
    VKD3D_SM4_OP_DCL_INPUT_SIV
    VKD3D_SM4_OP_DCL_INPUT_PS_SIV
    VKD3D_SM4_OP_DCL_OUTPUT_SIV

and not the following ones:

    VKD3D_SM4_OP_DCL_INPUT
    VKD3D_SM4_OP_DCL_PS_INPUT
    VKD3D_SM4_OP_DCL_OUTPUT

Which is consistent with what we do when reading these instructions in
the following functions:

    shader_sm4_read_declaration_register_semantic()
    shader_sm4_read_dcl_input_ps_siv()

and

    shader_sm4_read_dcl_input_ps()
    shader_sm4_read_declaration_dst()

for the non-SGV and non-SIV cases.

Note that the non-SGV and non-SIV instructions don't need/use this
extra information because they rely on the dst register type and index.

I suggest to introduce this change because the here replaced check is
brittle, and we might be omitting the sysval semantic in some cases.
2024-10-15 16:44:38 +02:00
Shaun Ren
0c5dc53fd2 vkd3d-shader/hlsl: Allocate temporary registers separately for each entry function. 2024-10-15 16:39:50 +02:00
Shaun Ren
5f8570b933 vkd3d-shader/hlsl: Track whether a variable is read in any entry function. 2024-10-15 16:18:36 +02:00
Shaun Ren
f15a1c0b23 vkd3d-shader/hlsl: Record semantic extern vars separately for each entry function.
This is required in order to process the entry point function and the
patch constant function in hull shaders.
2024-10-15 16:18:27 +02:00
Giovanni Mascellani
16efb7c0c6 vkd3d-shader: Ignore the patch constant signature when it doesn't make sense. 2024-10-09 13:13:00 +02:00
Giovanni Mascellani
1256b4f862 vkd3d-shader/d3d-asm: Rename vkd3d_shader_trace() to vsir_program_trace(). 2024-10-08 22:04:59 +02:00
Henri Verbeet
cf92d9f398 vkd3d-shader/ir: Store the thread group size in struct vsir_program. 2024-10-08 22:03:05 +02:00
Nikolay Sivov
5e52ccbf3d vkd3d-shader/hlsl: Move default values indexing fixup to the tpf writer stage.
The primary goal here is to move compilation profile type and version
check outside of a parsing stage. Default values for parameters were
never subjected to this fixup, and it does look tpf-specific, so moving
it where it belongs.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-10-01 17:27:12 +02:00
Giovanni Mascellani
8acaa3a62c vkd3d-shader/tpf: Propagate validation errors after parsing.
Also, trace the program when validation fails after parsing, mostly
to make debugging easier.
2024-09-30 20:48:43 +02:00
Giovanni Mascellani
8d85ea2dc5 vkd3d-shader: Get rid of the RESOURCE data type. 2024-09-26 17:42:16 +02:00
Giovanni Mascellani
e58726310b vkd3d-shader: Get rid of the UAV data type. 2024-09-26 17:42:16 +02:00
Giovanni Mascellani
2934f820a9 vkd3d-shader: Get rid of the SAMPLER data type. 2024-09-26 17:42:16 +02:00
Elizabeth Figura
c43e5c8eb5 vkd3d-shader/hlsl: Introduce the "error" type.
Currently, if an expression successfully parses according to the bison grammar,
but for one reason or another cannot generate a meaningful IR instruction, we
abort parsing with YYABORT. This includes, for example, an undefined variable or
function, invalid swizzle or field reference, or a constructor with a complex or
non-numeric data type.

Aborting parsing is unfortunate, however, because it means that any further
errors in the program cannot be caught by the programmer, increasing the number
of times they will need to fix errors and recompile.

The idea of this patch is that any such expression will instead generate an IR
node whose data type is of HLSL_CLASS_ERROR. Any further expression which would
consume an "error" typed instruction will instead immediately return an
expression of type "error" (probably the same one) instead of aborting or doing
any other type-checking.

Currently these "error" instructions should not pass the parsing stage, since
hlsl_compile_shader() will immediately notice that compilation has failed and
skip any optimization, lowering, or bytecode-writing.

A further direction to take this is to pre-allocate one "error" expression
immediately when creating the HLSL parser, and return that expression when we
fail to allocate an hlsl_ir_node of any type. This means we do not need to
handle allocation errors when constructing nodes, saving us quite a lot of error
handling (which is not only tedious but currently often broken, if nothing else
by virtue of neglecting cleanup of local variables).
2024-09-23 15:28:47 +02:00
Nikolay Sivov
f64689eed8 vkd3d-shader/tpf: Set temps count in the STAT section.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-20 17:20:02 +02:00
Nikolay Sivov
478e28ea79 vkd3d-shader/tpf: Move STAT fields update to a separate helper.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-20 17:20:02 +02:00
Giovanni Mascellani
637a3cabe7 vkd3d-shader/ir: Allow failure in shader_signature_find_element_for_reg().
shader_signature_find_element_for_reg() is also used in the TPF parser,
where the program has not been validated yet, so it must not crash
on errors.

The I/O normaliser can instead assume that the shader is already
validated.

This fixes a crash with a shader used by The Falconeer. The bug is still
present, because the shader will be incorrectly rejected, but at least
the vkd3d-shader will fail gracefully.
2024-09-20 17:01:29 +02:00
Nikolay Sivov
32ced3bd8f vkd3d-shader/tpf: Set 'gather' instructions counter in the STAT. 2024-09-19 14:38:59 +02:00
Nikolay Sivov
01f6ef5e6d vkd3d-shader/tpf: Add a 'lod' counter to the STAT. 2024-09-19 14:38:59 +02:00
Nikolay Sivov
7c9695b261 vkd3d-shader/tpf: Handle barrier instructions in STAT.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-19 14:38:59 +02:00
Nikolay Sivov
0e9fcb1431 vkd3d-shader/tpf: Handle tessellation stage fields in STAT.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-16 14:04:46 +02:00
Nikolay Sivov
947b151ed4 vkd3d-shader/tpf: Handle atomic instructions in STAT.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-16 14:01:29 +02:00
Nikolay Sivov
7c12371298 vkd3d-shader/tpf: Handle bitwise instructions in STAT.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-16 14:01:18 +02:00
Nikolay Sivov
90fc57ff89 vkd3d-shader/tpf: Handle GS reflection fields in the STAT section.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-16 14:01:07 +02:00
Nikolay Sivov
4c03cda3c7 vkd3d-shader/tpf: Handle texture instructions in STAT.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-13 16:01:22 +02:00
Nikolay Sivov
9e4b2f5a1b vkd3d-shader/tpf: Handle 'movc' in STAT.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-13 16:01:22 +02:00
Nikolay Sivov
7bd6c6b172 vkd3d-shader/tpf: Handle 'emit' and 'cut' in STAT.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-13 16:01:22 +02:00
Nikolay Sivov
908833fa6b vkd3d-shader/tpf: Handle arithmetic instructions in STAT.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-13 16:01:22 +02:00
Nikolay Sivov
cfa8f0dccb vkd3d-shader/tpf: Handle conversion instructions in STAT.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-13 16:01:22 +02:00
Henri Verbeet
d30160710b vkd3d-shader/tpf: Include vkd3d_d3dcommon.h only from tpf.c. 2024-09-12 18:50:51 +02:00
Anna (navi) Figueiredo Gomes
e61046fb23 vkd3d-shader/hlsl: Implement the "earlydepthstencil" attribute. 2024-09-12 18:46:24 +02:00
Giovanni Mascellani
866f138875 vkd3d-shader/ir: Record the control flow type in the program. 2024-09-12 18:31:32 +02:00
Nikolay Sivov
ec644b395b vkd3d-shader/tpf: Create a stub STAT section.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-12 18:26:08 +02:00
Nikolay Sivov
de6abd964e vkd3d-shader/hlsl: Implement the mad() intrinsic.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-10 21:40:32 +02:00
Nikolay Sivov
75299c04fd vkd3d-shader: Handle the SV_SampleIndex semantic.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-10 21:39:03 +02:00
Nikolay Sivov
0a6bcf5da7 vkd3d-shader/tpf: Fix a typo when adding the SFI0 section.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-04 18:43:41 +02:00
Henri Verbeet
a214e96cf8 vkd3d-shader/tpf: Use enum vkd3d_sm4_data_type in sm4_resource_format(). 2024-09-04 18:42:26 +02:00