Signed-off-by: Francisco Casas fcasas@codeweavers.com --- libs/vkd3d-shader/hlsl_sm4.c | 47 ++++++++++++++++++++++-- libs/vkd3d-shader/vkd3d_shader_private.h | 1 + 2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 19450584..d55815f1 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -766,7 +766,6 @@ static uint32_t sm4_encode_instruction_modifier(const struct sm4_instruction_mod return word; }
- struct sm4_register { enum vkd3d_sm4_register_type type; @@ -1020,6 +1019,35 @@ static void write_sm4_instruction(struct vkd3d_bytecode_buffer *buffer, const st put_u32(buffer, instr->idx[j]); }
+static bool encode_texel_offset_as_aoffimmi(struct sm4_instruction *instr, + const struct hlsl_ir_node *texel_offset){ + struct sm4_instruction_modifier modif; + struct hlsl_ir_constant *offset; + + if (!texel_offset) + return false; + + if (texel_offset->type != HLSL_IR_CONSTANT) + return false; + offset = hlsl_ir_constant(texel_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; + if (modif.aoffimmi.u < -8 || 7 < modif.aoffimmi.u) + return false; + if (modif.aoffimmi.v < -8 || 7 < modif.aoffimmi.v) + return false; + if (modif.aoffimmi.w < -8 || 7 < modif.aoffimmi.w) + return false; + + instr->modifiers[instr->modifier_count] = modif; + instr->modifier_count++; + + return true; +} + static void write_sm4_dcl_constant_buffer(struct vkd3d_bytecode_buffer *buffer, const struct hlsl_buffer *cbuffer) { const struct sm4_instruction instr = @@ -1307,7 +1335,8 @@ static void write_sm4_ld(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buf
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_deref *resource, const struct hlsl_deref *sampler, + const struct hlsl_ir_node *coords, const struct hlsl_ir_node *texel_offset) { struct sm4_instruction instr; unsigned int writemask; @@ -1315,6 +1344,16 @@ static void write_sm4_sample(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer memset(&instr, 0, sizeof(instr)); instr.opcode = VKD3D_SM4_OP_SAMPLE;
+ if (texel_offset) + { + if (!encode_texel_offset_as_aoffimmi(&instr, texel_offset)) + { + hlsl_error(ctx, &texel_offset->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TEXEL_OFFSET, + "Offset must resolve to integer literal in the range -8 to 7\n"); + return; + } + } + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, NULL, dst); instr.dst_count = 1;
@@ -1627,6 +1666,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 *texel_offset = load->texel_offset.node;
if (load->sampler.var) { @@ -1658,7 +1698,8 @@ static void write_sm4_resource_load(struct hlsl_ctx *ctx, case HLSL_RESOURCE_SAMPLE: if (!load->sampler.var) hlsl_fixme(ctx, &load->node.loc, "SM4 combined sample expression."); - write_sm4_sample(ctx, buffer, resource_type, &load->node, &load->resource, &load->sampler, coords); + write_sm4_sample(ctx, buffer, resource_type, &load->node, &load->resource, &load->sampler, + coords, texel_offset); break; } } diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 62073cf1..718bb202 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -114,6 +114,7 @@ enum vkd3d_shader_error VKD3D_SHADER_ERROR_HLSL_OVERLAPPING_RESERVATIONS = 5015, VKD3D_SHADER_ERROR_HLSL_INVALID_RESERVATION = 5016, VKD3D_SHADER_ERROR_HLSL_NOT_IMPLEMENTED = 5017, + VKD3D_SHADER_ERROR_HLSL_INVALID_TEXEL_OFFSET = 5018,
VKD3D_SHADER_WARNING_HLSL_IMPLICIT_TRUNCATION = 5300,