[PATCH vkd3d 3/4] vkd3d-shader/hlsl: Write sample sm4 instructions with aoffimmi modifiers.

Francisco Casas fcasas at codeweavers.com
Fri Nov 26 09:40:57 CST 2021


Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
---
 libs/vkd3d-shader/hlsl_sm4.c | 53 +++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c
index 9c500f8e..a7da7759 100644
--- a/libs/vkd3d-shader/hlsl_sm4.c
+++ b/libs/vkd3d-shader/hlsl_sm4.c
@@ -1248,6 +1248,53 @@ static void write_sm4_constant(struct hlsl_ctx *ctx,
     write_sm4_instruction(buffer, &instr);
 }
 
+static void write_sm4_sample(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer,
+        const struct hlsl_type *resource_type, const struct hlsl_ir_node *dst,
+        const struct hlsl_deref *resource, const struct hlsl_deref *sampler,
+        const struct hlsl_ir_node *coords, const struct hlsl_ir_node *texcoord_offset)
+{
+    struct hlsl_ir_constant *offset;
+    struct sm4_instruction instr;
+    unsigned int writemask;
+
+    memset(&instr, 0, sizeof(instr));
+    instr.opcode = VKD3D_SM4_OP_SAMPLE;
+
+    if (texcoord_offset)
+    {
+        struct sm4_instruction_modifier modif;
+
+        if (texcoord_offset->type != HLSL_IR_CONSTANT)
+        {
+            hlsl_error(ctx, texcoord_offset->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+                "offset must resolve to integer literal in the range -8 to 7\n");
+            return;
+        }
+        offset = hlsl_ir_constant(texcoord_offset);
+
+        modif.type = VKD3D_SM4_MODIFIER_AOFFIMMI;
+        modif.aoffimmi.u = offset->value[0].i;
+        modif.aoffimmi.v = offset->value[1].i;
+        modif.aoffimmi.w = offset->value[2].i;
+        instr.modifiers[instr.modifier_count++] = modif;
+    }
+
+    sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, NULL, dst);
+    instr.dst_count = 1;
+
+    sm4_register_from_node(&instr.srcs[0].reg, &writemask, &instr.srcs[0].swizzle_type, coords);
+    instr.srcs[0].swizzle = hlsl_swizzle_from_writemask(writemask);
+
+    sm4_register_from_deref(ctx, &instr.srcs[1].reg, &writemask, &instr.srcs[1].swizzle_type, resource, resource_type);
+    instr.srcs[1].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask);
+
+    sm4_register_from_deref(ctx, &instr.srcs[2].reg, &writemask, &instr.srcs[2].swizzle_type, sampler, sampler->var->data_type);
+
+    instr.src_count = 3;
+
+    write_sm4_instruction(buffer, &instr);
+}
+
 static void write_sm4_ld(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer,
         const struct hlsl_type *resource_type, const struct hlsl_ir_node *dst,
         const struct hlsl_deref *resource, const struct hlsl_ir_node *coords)
@@ -1570,6 +1617,7 @@ static void write_sm4_resource_load(struct hlsl_ctx *ctx,
 {
     const struct hlsl_type *resource_type = load->resource.var->data_type;
     const struct hlsl_ir_node *coords = load->coords.node;
+    const struct hlsl_ir_node *texcoord_offset = load->texcoord_offset.node;
 
     if (!load->resource.var->is_uniform)
     {
@@ -1584,7 +1632,10 @@ static void write_sm4_resource_load(struct hlsl_ctx *ctx,
             break;
 
         case HLSL_RESOURCE_SAMPLE:
-            hlsl_fixme(ctx, load->node.loc, "Resource sample instruction.");
+            /* Combined sample expressions were lowered by lower_combined_samples(). */
+            assert(load->sampler.var);
+            write_sm4_sample(ctx, buffer, resource_type, &load->node, &load->resource, &load->sampler,
+                    coords, texcoord_offset);
             break;
     }
 }
-- 
2.25.1




More information about the wine-devel mailing list