2143 Commits

Author SHA1 Message Date
Shaun Ren
802d7317cb vkd3d-shader/hlsl: Implement the InterlockedXor() intrinsic. 2025-01-20 15:42:45 +01:00
Shaun Ren
5b9634a7b7 vkd3d-shader/hlsl: Implement the InterlockedMin() intrinsic. 2025-01-20 15:42:43 +01:00
Shaun Ren
b447fdce51 vkd3d-shader/hlsl: Implement the InterlockedExchange() intrinsic. 2025-01-20 15:41:07 +01:00
Shaun Ren
5f943e9110 tests/hlsl: Add tests for valid destination types of atomic operations. 2025-01-20 15:30:54 +01:00
Shaun Ren
b3c13b443f tests/hlsl: Add tests to check the void return type of atomic ops. 2025-01-20 15:26:10 +01:00
Shaun Ren
728cf1dcfe tests/hlsl: Add tests to check the types of the value arguments of atomic ops. 2025-01-20 15:26:10 +01:00
Shaun Ren
c8b87f9bd9 tests/hlsl: Add a test for UAV InterlockedCompareExchange(). 2025-01-20 15:26:10 +01:00
Shaun Ren
24653b88f3 tests/shader_runner_gl: Bind buffer UAVs for compute shaders. 2025-01-20 15:25:56 +01:00
Shaun Ren
9fab6e4383 tests/shader_runner_gl: Add "opengl" tag. 2025-01-20 15:23:09 +01:00
Shaun Ren
31c3d46925 tests/shader_runner_vulkan: Check if create_shader_stage() fails in create_compute_pipeline(). 2025-01-20 14:59:12 +01:00
Conor McCarthy
10edcec030 vkd3d: Do not require the ALLOW_DEPTH_STENCIL flag for depth/stencil formats in GetCopyableFootprints(). 2025-01-20 14:37:13 +01:00
Conor McCarthy
e99906f05d vkd3d: Return correctly aligned depth/stencil sizes from GetCopyableFootprints(). 2025-01-20 13:59:46 +01:00
Conor McCarthy
1a4dedbc8d vkd3d: Return the correct depth/stencil plane format from GetCopyableFootprints(). 2025-01-20 13:45:16 +01:00
Nikolay Sivov
a082daeb56 vkd3d-shader/hlsl: Implement the isinf() intrinsic.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-01-16 19:25:02 +01:00
Francisco Casas
2d91bd9200 vkd3d-shader/hlsl: Properly lower casts to int for negative numbers.
While it looks complicated, it is what fxc/d3dcompiler does.

A shader as simple as:

    float4 f;

    float4 main() : sv_target
    {
        return (int4)f;
    }

results in the following instructions:

    ps_2_0
    def c1, 0, 1, 0, 0
    frc r0, c0
    cmp r1, -r0, c1.x, c1.y
    add r0, -r0, c0
    mov r2, c0
    cmp r1, r2, c1.x, r1
    add r0, r0, r1
    mov oC0, r0
2025-01-16 18:46:49 +01:00
Francisco Casas
4f7c117296 tests: Test casting negative floats to int.
Turns out we are not doing this correctly in SM1, because the rounding
should be to the number that is closer to zero and lower_casts_to_int()
doesn't do that.

A vertex shader test is added since in SM1 they must rely on the SLT
operation instead of the CMP operation.
2025-01-16 18:43:12 +01:00
Francisco Casas
0a5955372a vkd3d-shader/hlsl: Lower separate SampleGrad() for SM1. 2025-01-14 17:59:50 +01:00
Francisco Casas
00b79cd781 tests: Test SampleGrad() on ps_3_0.
fxc compiles this method even without the backcompat option.

Furthermore, it even does it on ps_2_0 despite the fact that it maps to
a texldd instruction, which is not available on plain ps_2_0, nor ps_2_b,
only on ps_2_a and ps_3_0 according to documentation.

It is worth mentioning that the additional offset parameter is not
supported when lowering.
2025-01-14 17:59:50 +01:00
Francisco Casas
9b3b47b1b8 vkd3d-shader: Avoid left shifting signed integers. (ubsan)
Otherwise ubsan reports these errors on the bitwise.shader_test:

    libs/vkd3d-shader/hlsl_constant_ops.c:970:50: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
    libs/vkd3d-shader/hlsl_constant_ops.c:970:50: runtime error: left shift of negative value -12
2025-01-10 19:51:55 +01:00
Shaun Ren
646087d54c vkd3d-shader/hlsl: Collect together terms with constant coefficients.
We apply distributivity to applicable expressions, specifically with
the following rewrite rules:

  (x OPL a) OPR (x OPL b) -> x OPL (a OPR b)
  (y OPR (x OPL a)) OPR (x OPL b) -> y OPR (x OPL (a OPR b))
  ((x OPL a) OPR y) OPR (x OPL b) -> (x OPL (a OPR b)) OPR y
  (x OPL a) OPR ((x OPL b) OPR y) -> (x OPL (a OPR b)) OPR y
  (x OPL a) OPR (y OPR (x OPL b)) -> (x OPL (a OPR b)) OPR y

where a, b are constants.
2025-01-10 19:17:43 +01:00
Henri Verbeet
b60995b106 tests/shader_runner: Do not use skip() for shader model requirements.
Like we did before commit 067e6deee4aba447c6627ce02b58c6bdcd90470e.
These skips aren't all that interesting; it's entirely intentional that
e.g. a 2.0-3.0 run wouldn't run 4.0 shaders.
2024-12-19 21:17:05 +01:00
Giovanni Mascellani
922af42aca tests/hlsl: Add some clip/cull distance tests. 2024-12-19 20:54:56 +01:00
Anna (navi) Figueiredo Gomes
d5ed4df254 tests/shader_runner: Add a "mesa<23.3" tag. 2024-12-19 20:34:55 +01:00
Henri Verbeet
31ea11fb0e tests/shader_runner: Ignore the "backcompat" option for shader model 5.1+. 2024-12-19 12:24:02 +01:00
Elizabeth Figura
dd450c526f tests/d3d12: Make the dtof test a bit more interesting. 2024-12-18 17:30:16 +01:00
Francisco Casas
825784322d vkd3d-shader/ir: Properly lower texldp. 2024-12-18 17:30:15 +01:00
Francisco Casas
02fc26507b tests/hlsl: Test tex2Dproj(). 2024-12-18 17:29:10 +01:00
Francisco Casas
7cc802afd7 vkd3d-shader/ir: Properly lower texldb. 2024-12-18 17:27:43 +01:00
Anna (navi) Figueiredo Gomes
f09ac4959e vkd3d-shader/hlsl: Implement the GatherCmp() methods. 2024-12-18 17:27:43 +01:00
Anna (navi) Figueiredo Gomes
fd8bcc188f tests/hlsl: Add GatherCmp() tests. 2024-12-18 17:27:43 +01:00
Conor McCarthy
8d479d2ea6 vkd3d-shader/dxil: Implement DX intrinsic EvalCentroid. 2024-12-18 17:27:43 +01:00
Conor McCarthy
1bb3b13c0a vkd3d-shader/dxil: Implement DX intrinsic EvalSampleIndex. 2024-12-18 17:27:43 +01:00
Giovanni Mascellani
ed552e4519 tests/hlsl: Add tests for the EvaluateAttribute*() intrinsics.
Based on earlier tests by Conor McCarthy.
2024-12-18 17:27:31 +01:00
Elizabeth Figura
27c7776947 tests: Use fail(sm<5) instead of [require] for uav-atomics. 2024-12-17 16:37:41 +01:00
Elizabeth Figura
8fcbbfb8b1 tests/shader_runner: Test versions where the compilation result changes.
Adjust the algorithm for deciding for which profiles to test compilation.

We first ensure that if the compilation result changes (most often as the result
of a feature introduced in a specific version), we test the versions immediately
on either side of the change, to validate that vkd3d-shader is emulating the
same version behaviour.

We then ensure that we are testing at least one version from each set of sm1,
sm4, and sm6.
2024-12-17 16:35:09 +01:00
Elizabeth Figura
067e6deee4 tests/shader_runner: Test HLSL compilation in a separate pass.
Mainly in order to not waste time compile-testing the same version
more than once [as we do with e.g. the d3d11 and d3d12 runners, or
d3d12, GL, and Vulkan].
2024-12-17 16:24:00 +01:00
Elizabeth Figura
e91c07e1de tests/shader_runner: Record HLSL todo/fail state for each shader model.
When a shader fails to compile for a range of versions, we want to validate that
we are correctly implementing that behaviour. E.g. if a feature requires shader
model 5.0, we should validate that it compiles correctly with 5.0 (which we do),
but also that it *fails* to compile with 4.1 (which we do not).

The obvious and simple solution is to simply run compile tests for each version.
There are, however, at least 12 versions of HLSL up to and including 6.0, at
least 10 of which are known to introduce new features. Shader compilation takes
about 10-15% of the time that draw and dispatch does, both for native and
(currently) vkd3d. Testing every version for every shader would add a
noticeable amount of time to the tests.

In practice, the interesting versions to test for most shaders are:

* At least one from each range 1-3, 4-5, and 6. It's common enough for the
  semantics of the HLSL to differ between bytecode formats, or for features to
  be added or removed across those boundaries.

* If the shader requires a given feature, we want to test both sides of the cusp
  to ensure we're requiring the same version for the feature.

In practice this is 3 or 4 versions, which is measurably less than the 12 we'd
otherwise be running.

In order to achieve this goal of testing only the 3 or 4 interesting versions
for a shader, we need to know what version is actually required for a feature.
This is encoded in the shader itself using e.g. [pixel shader fail(sm<5)].

This patch therefore implements the first step towards this goal, namely,
determining which versions succeed and fail, so we can figure out which ones are
interesting.

We could require the test writer to specify which versions are interesting ahead
of time (e.g. "for version in 2.0 4.1 5.0 6.0") but this is both redundant (and
there are a *lot* of tests that need some feature gate) and easy for a test
writer to get wrong by missing interesting versions.
2024-12-17 16:18:21 +01:00
Henri Verbeet
c4f69f4d3d vkd3d-shader/hlsl: Prefer overload candidates without component count widening. 2024-12-16 17:09:40 +01:00
Henri Verbeet
64bb4150f0 vkd3d-shader/hlsl: Prefer overload candidates without component type narrowing. 2024-12-16 17:09:40 +01:00
Henri Verbeet
32d432ab5e vkd3d-shader/hlsl: Prefer overload candidates with matching component types. 2024-12-16 17:09:40 +01:00
Henri Verbeet
6b8878377f vkd3d-shader/hlsl: Prefer overload candidates with matching component type classes. 2024-12-16 17:09:40 +01:00
Henri Verbeet
63fce3062e vkd3d-shader/hlsl: Prefer overload candidates without component count narrowing. 2024-12-16 17:09:40 +01:00
Henri Verbeet
cdf6100fe5 tests: Add yet more overload resolution tests. 2024-12-16 17:09:40 +01:00
Elizabeth Figura
5827197246 tests/shader_runner: Don't bother distinguishing directive substrings.
Consider ']' a terminator for any string.
2024-12-12 17:28:45 +01:00
Elizabeth Figura
830bdd0037 tests/shader_runner: Use a separate variable for shader type. 2024-12-12 17:26:49 +01:00
Elizabeth Figura
edb36c078f tests/shader_runner: Use is_todo instead of separate shader states. 2024-12-12 17:26:37 +01:00
Victor Chiletto
a1d995e740 vkd3d-shader/hlsl: Unroll loops with conditional jumps. 2024-12-12 16:54:04 +01:00
Shaun Ren
2c9cf7c78b vkd3d-shader/hlsl: Implement normalization of binary expressions.
We normalize binary expressions by attempting to group constants
together, in order to facilitate further simplification of the
expressions.

For any binary operator OP, non-constants x, y, and constants a, b, we
apply the following rewrite rules:

  a OP x -> x OP a, if OP is commutative.

  (x OP a) OP b -> x OP (a OP b), if OP is associative.

  (x OP a) OP y -> (x OP y) OP a, if OP is associative and commutative.

  x OP (y OP a) -> (x OP y) OP a, if OP is associative.

Note that we consider floating point operations to be
non-associative.
2024-12-11 15:32:22 +01:00
Francisco Casas
aa3a716249 vkd3d-shader/hlsl: Allow lowering separate sampler arrays on deref offset 0. 2024-12-10 15:52:52 +01:00
Francisco Casas
2c9269ac3a vkd3d-shader/hlsl: Allocate samplers by decreasing bind count in SM1. 2024-12-10 15:52:50 +01:00