From c89f5036043a992e0f3d08324fe200bacd69abc2 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Fri, 8 Nov 2024 12:16:46 -0300 Subject: [PATCH] vkd3d-shader/hlsl: Store SM4 HLSL_RESOURCE_SAMPLE_INFOs in the vsir program. --- libs/vkd3d-shader/hlsl_codegen.c | 28 ++++++++++++++++++++++++++++ libs/vkd3d-shader/tpf.c | 27 +-------------------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index bc5cbab1..b8983599 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -9165,6 +9165,31 @@ static bool sm4_generate_vsir_instr_gather(struct hlsl_ctx *ctx, struct vsir_pro return true; } +static bool sm4_generate_vsir_instr_sample_info(struct hlsl_ctx *ctx, + struct vsir_program *program, const struct hlsl_ir_resource_load *load) +{ + const struct hlsl_deref *resource = &load->resource; + const struct hlsl_ir_node *instr = &load->node; + struct hlsl_type *type = instr->data_type; + struct vkd3d_shader_instruction *ins; + + VKD3D_ASSERT(type->e.numeric.type == HLSL_TYPE_UINT || type->e.numeric.type == HLSL_TYPE_FLOAT); + + if (!(ins = generate_vsir_add_program_instruction(ctx, program, &instr->loc, VKD3DSIH_SAMPLE_INFO, 1, 1))) + return false; + + if (type->e.numeric.type == HLSL_TYPE_UINT) + ins->flags = VKD3DSI_SAMPLE_INFO_UINT; + + vsir_dst_from_hlsl_node(&ins->dst[0], ctx, instr); + + if (!sm4_generate_vsir_init_src_param_from_deref(ctx, program, + &ins->src[0], resource, ins->dst[0].write_mask, &instr->loc)) + return false; + + return true; +} + static bool sm4_generate_vsir_instr_resource_load(struct hlsl_ctx *ctx, struct vsir_program *program, const struct hlsl_ir_resource_load *load) { @@ -9207,6 +9232,9 @@ static bool sm4_generate_vsir_instr_resource_load(struct hlsl_ctx *ctx, case HLSL_RESOURCE_GATHER_ALPHA: return sm4_generate_vsir_instr_gather(ctx, program, load, VKD3D_SHADER_SWIZZLE(W, W, W, W)); + case HLSL_RESOURCE_SAMPLE_INFO: + return sm4_generate_vsir_instr_sample_info(ctx, program, load); + case HLSL_RESOURCE_SAMPLE_PROJ: vkd3d_unreachable(); diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 5e77891a..90bf602c 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -5007,28 +5007,6 @@ static void write_sm4_ret(const struct tpf_compiler *tpf) write_sm4_instruction(tpf, &instr); } -static void write_sm4_sampleinfo(const struct tpf_compiler *tpf, const struct hlsl_ir_resource_load *load) -{ - const struct hlsl_deref *resource = &load->resource; - const struct hlsl_ir_node *dst = &load->node; - struct sm4_instruction instr; - - VKD3D_ASSERT(dst->data_type->e.numeric.type == HLSL_TYPE_UINT || dst->data_type->e.numeric.type == HLSL_TYPE_FLOAT); - - memset(&instr, 0, sizeof(instr)); - instr.opcode = VKD3D_SM4_OP_SAMPLE_INFO; - if (dst->data_type->e.numeric.type == HLSL_TYPE_UINT) - instr.extra_bits |= VKD3DSI_SAMPLE_INFO_UINT << VKD3D_SM4_INSTRUCTION_FLAGS_SHIFT; - - sm4_dst_from_node(&instr.dsts[0], dst); - instr.dst_count = 1; - - sm4_src_from_deref(tpf, &instr.srcs[0], resource, instr.dsts[0].write_mask, &instr); - instr.src_count = 1; - - write_sm4_instruction(tpf, &instr); -} - static void write_sm4_resinfo(const struct tpf_compiler *tpf, const struct hlsl_ir_resource_load *load) { const struct hlsl_deref *resource = &load->resource; @@ -5156,10 +5134,6 @@ static void write_sm4_resource_load(const struct tpf_compiler *tpf, const struct switch (load->load_type) { - case HLSL_RESOURCE_SAMPLE_INFO: - write_sm4_sampleinfo(tpf, load); - break; - case HLSL_RESOURCE_RESINFO: write_sm4_resinfo(tpf, load); break; @@ -5176,6 +5150,7 @@ static void write_sm4_resource_load(const struct tpf_compiler *tpf, const struct case HLSL_RESOURCE_SAMPLE_GRAD: case HLSL_RESOURCE_LOAD: case HLSL_RESOURCE_SAMPLE_PROJ: + case HLSL_RESOURCE_SAMPLE_INFO: vkd3d_unreachable(); } }