From aa3a7162491fc0ab73f08e5a6cb2edcb780d2f61 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Wed, 4 Dec 2024 15:44:48 -0300 Subject: [PATCH] vkd3d-shader/hlsl: Allow lowering separate sampler arrays on deref offset 0. --- libs/vkd3d-shader/hlsl_codegen.c | 15 ++++++++++++--- tests/hlsl/combined-samplers.shader_test | 8 ++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 93c50ae0..4eb96279 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -2806,6 +2806,16 @@ static struct hlsl_type *clone_texture_array_as_combined_sampler_array(struct hl return ctx->builtin_types.sampler[type->sampler_dim]; } +static bool deref_offset_is_zero(struct hlsl_ctx *ctx, const struct hlsl_deref *deref) +{ + enum hlsl_regset regset = hlsl_deref_get_regset(ctx, deref); + unsigned int index; + + if (!hlsl_regset_index_from_deref(ctx, deref, regset, &index)) + return false; + return index == 0; +} + /* Lower samples from separate texture and sampler variables to samples from * synthetized combined samplers. That is, translate SM4-style samples in the * source to SM1-style samples in the bytecode. */ @@ -2832,10 +2842,9 @@ static bool lower_separate_samples(struct hlsl_ctx *ctx, struct hlsl_ir_node *in VKD3D_ASSERT(hlsl_type_is_resource(resource->data_type)); VKD3D_ASSERT(hlsl_type_is_resource(sampler->data_type)); - if (sampler->data_type->class == HLSL_CLASS_ARRAY) + if (sampler->data_type->class == HLSL_CLASS_ARRAY && !deref_offset_is_zero(ctx, &load->sampler)) { - /* Only supported by d3dcompiler if the sampler is the first component - * of the sampler array. */ + /* Not supported by d3dcompiler. */ hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_NOT_IMPLEMENTED, "Lower separated samples with sampler arrays."); return false; diff --git a/tests/hlsl/combined-samplers.shader_test b/tests/hlsl/combined-samplers.shader_test index 526b1d7d..184e9018 100644 --- a/tests/hlsl/combined-samplers.shader_test +++ b/tests/hlsl/combined-samplers.shader_test @@ -114,7 +114,7 @@ if(sm<4) probe (0, 0) rgba(1, 1, 1, 11) if(sm>=4) probe (0, 0) rgba(10, 10, 10, 11) -[pixel shader todo(sm<4)] +[pixel shader] Texture2D tex; sampler sam[2]; @@ -124,7 +124,7 @@ float4 main() : sv_target } [test] -todo(sm<4 | msl) draw quad +todo(msl) draw quad probe (0, 0) rgba (21, 21, 21, 11) @@ -206,7 +206,7 @@ if(sm<4) probe (0, 0) rgba(453021, 453021, 453021, 111111) if(sm>=4) probe (0, 0) rgba(12333, 12333, 12333, 111111) -[pixel shader todo(sm<4)] +[pixel shader] Texture2D texA; sampler samA[2]; Texture2D texB[2]; @@ -221,7 +221,7 @@ float4 main() : sv_target } [test] -todo(sm<4 | msl) draw quad +todo(msl) draw quad if(sm<4) probe (0, 0) rgba(4351, 4351, 4351, 1111) if(sm>=4) probe (0, 0) rgba(3125, 3125, 3125, 1111)