From a2e85a8a76379cd891ccc0fc14525d65f96c1474 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Fri, 26 May 2023 11:14:07 +0200 Subject: [PATCH] vkd3d-shader/hlsl: Parse SampleCmpLevelZero() method. --- libs/vkd3d-shader/hlsl.c | 1 + libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 8 +++++++- libs/vkd3d-shader/tpf.c | 8 +++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index cf865056..152ec627 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -2445,6 +2445,7 @@ static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const stru [HLSL_RESOURCE_LOAD] = "load_resource", [HLSL_RESOURCE_SAMPLE] = "sample", [HLSL_RESOURCE_SAMPLE_CMP] = "sample_cmp", + [HLSL_RESOURCE_SAMPLE_CMP_LZ] = "sample_cmp_lz", [HLSL_RESOURCE_SAMPLE_LOD] = "sample_lod", [HLSL_RESOURCE_SAMPLE_LOD_BIAS] = "sample_biased", [HLSL_RESOURCE_SAMPLE_GRAD] = "sample_grad", diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index f8f894c4..7d02448e 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -616,6 +616,7 @@ enum hlsl_resource_load_type HLSL_RESOURCE_LOAD, HLSL_RESOURCE_SAMPLE, HLSL_RESOURCE_SAMPLE_CMP, + HLSL_RESOURCE_SAMPLE_CMP_LZ, HLSL_RESOURCE_SAMPLE_LOD, HLSL_RESOURCE_SAMPLE_LOD_BIAS, HLSL_RESOURCE_SAMPLE_GRAD, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index fd0675cd..cf483d82 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3862,7 +3862,7 @@ static bool add_sample_cmp_method_call(struct hlsl_ctx *ctx, struct list *instrs const struct hlsl_type *object_type = object->data_type; const unsigned int sampler_dim = hlsl_sampler_dim_count(object_type->sampler_dim); const unsigned int offset_dim = hlsl_offset_dim_count(object_type->sampler_dim); - struct hlsl_resource_load_params load_params = {.type = HLSL_RESOURCE_SAMPLE_CMP}; + struct hlsl_resource_load_params load_params = { 0 }; const struct hlsl_type *sampler_type; struct hlsl_ir_node *load; @@ -3872,6 +3872,11 @@ static bool add_sample_cmp_method_call(struct hlsl_ctx *ctx, struct list *instrs return raise_invalid_method_object_type(ctx, object_type, name, loc); } + if (!strcmp(name, "SampleCmpLevelZero")) + load_params.type = HLSL_RESOURCE_SAMPLE_CMP_LZ; + else + load_params.type = HLSL_RESOURCE_SAMPLE_CMP; + if (params->args_count < 3 || params->args_count > 5 + !!offset_dim) { hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, @@ -4191,6 +4196,7 @@ object_methods[] = { "Sample", add_sample_method_call }, { "SampleBias", add_sample_lod_method_call }, { "SampleCmp", add_sample_cmp_method_call }, + { "SampleCmpLevelZero", add_sample_cmp_method_call }, { "SampleGrad", add_sample_grad_method_call }, { "SampleLevel", add_sample_lod_method_call }, }; diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 6544aed4..267f2e2d 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4113,6 +4113,10 @@ static void write_sm4_sample(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer instr.opcode = VKD3D_SM4_OP_SAMPLE_C; break; + case HLSL_RESOURCE_SAMPLE_CMP_LZ: + instr.opcode = VKD3D_SM4_OP_SAMPLE_C_LZ; + break; + case HLSL_RESOURCE_SAMPLE_LOD: instr.opcode = VKD3D_SM4_OP_SAMPLE_LOD; break; @@ -4159,7 +4163,8 @@ static void write_sm4_sample(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer sm4_src_from_node(&instr.srcs[4], load->ddy.node, VKD3DSP_WRITEMASK_ALL); instr.src_count += 2; } - else if (load->load_type == HLSL_RESOURCE_SAMPLE_CMP) + else if (load->load_type == HLSL_RESOURCE_SAMPLE_CMP + || load->load_type == HLSL_RESOURCE_SAMPLE_CMP_LZ) { sm4_src_from_node(&instr.srcs[3], load->cmp.node, VKD3DSP_WRITEMASK_ALL); ++instr.src_count; @@ -4963,6 +4968,7 @@ static void write_sm4_resource_load(struct hlsl_ctx *ctx, case HLSL_RESOURCE_SAMPLE: case HLSL_RESOURCE_SAMPLE_CMP: + case HLSL_RESOURCE_SAMPLE_CMP_LZ: case HLSL_RESOURCE_SAMPLE_LOD: case HLSL_RESOURCE_SAMPLE_LOD_BIAS: case HLSL_RESOURCE_SAMPLE_GRAD: