From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/hlsl_codegen.c | 28 ++++++++++++++++++++++++ tests/hlsl/combined-samplers.shader_test | 6 ++--- tests/hlsl/texture-ordering.shader_test | 8 +++---- 3 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 11ebe275..550e18c9 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -2191,6 +2191,33 @@ static bool lower_combined_samples(struct hlsl_ctx *ctx, struct hlsl_ir_node *in return true; }
+static bool sort_synthetic_separated_samplers_first(struct hlsl_ctx *ctx) +{ + struct list *insertion_point = &ctx->extern_vars; + struct hlsl_ir_var *var, *next; + unsigned int t; + + for (t = 0; t < 2; ++t) + { + LIST_FOR_EACH_ENTRY_SAFE(var, next, &ctx->extern_vars, struct hlsl_ir_var, extern_entry) + { + if (var->is_separated_resource) + { + unsigned int bind_count = hlsl_var_get_bind_count(var, HLSL_REGSET_TEXTURES); + + if ((t == 0) == (bind_count > 1)) + { + list_remove(&var->extern_entry); + list_add_after(insertion_point, &var->extern_entry); + insertion_point = &var->extern_entry; + } + } + } + } + + return false; +} + /* Lower DIV to RCP + MUL. */ static bool lower_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { @@ -4316,6 +4343,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry if (profile->major_version >= 4) hlsl_transform_ir(ctx, lower_combined_samples, body, NULL); hlsl_transform_ir(ctx, track_object_components_usage, body, NULL); + sort_synthetic_separated_samplers_first(ctx);
if (profile->major_version < 4) { diff --git a/tests/hlsl/combined-samplers.shader_test b/tests/hlsl/combined-samplers.shader_test index 16b5438e..16db3129 100644 --- a/tests/hlsl/combined-samplers.shader_test +++ b/tests/hlsl/combined-samplers.shader_test @@ -60,7 +60,7 @@ float4 main() : sv_target
[test] draw quad -todo probe all rgba (10, 10, 10, 11) +probe all rgba (10, 10, 10, 11)
[pixel shader] @@ -74,7 +74,7 @@ float4 main() : sv_target
[test] draw quad -todo probe all rgba (21, 21, 21, 11) +probe all rgba (21, 21, 21, 11)
[pixel shader] @@ -105,7 +105,7 @@ float4 main() : sv_target
[test] draw quad -todo probe all rgba (104, 104, 104, 111) +probe all rgba (104, 104, 104, 111)
% Sampler arrays with components that have different usage dimensions are only forbidden in SM4 upwards. diff --git a/tests/hlsl/texture-ordering.shader_test b/tests/hlsl/texture-ordering.shader_test index 16feb9e1..1d1329dc 100644 --- a/tests/hlsl/texture-ordering.shader_test +++ b/tests/hlsl/texture-ordering.shader_test @@ -132,7 +132,7 @@ float4 main() : sv_target
[test] draw quad -todo probe all rgba (450, 139, 876, 333) +probe all rgba (450, 139, 876, 333)
% Same as the first test, but inverting the declaration order. @@ -185,7 +185,7 @@ float4 main() : sv_target
[test] draw quad -todo probe all rgba (450, 138, 796, 333) +probe all rgba (450, 138, 796, 333)
% Same as the first test, but inverting the resource loads order. @@ -238,7 +238,7 @@ float4 main() : sv_target
[test] draw quad -todo probe all rgba (478, 913, 256, 333) +probe all rgba (478, 913, 256, 333)
% We can conclude that for declared texture arrays, if they are used, the "allocation size" is the @@ -271,4 +271,4 @@ float4 main() : sv_target
[test] draw quad -todo probe all rgba (215, 215, 215, 111) +probe all rgba (215, 215, 215, 111)