vkd3d-shader/hlsl: Store SM4 sampler declarations in the vsir program.

Looking at the implementation of shader_sm4_read_dcl_sampler(), vsir
stores the resource index range both in

    vkd3d_shader_instruction.declaration.sampler.range

and in the

    vkd3d_shader_instruction.declaration.sampler.src.reg.idx[1-2]

indexes, so we do the same.

It is also worth noting that for shader models lower than 5.1, vsir
has a normalization on the ins->declaration src register indexes.
Refer to the following comment:

    /* SM5.1 places a symbol identifier in idx[0] and moves
     * other values up one slot. Normalize to SM5.1. */

on shader_sm4_read_param().

This normalization is also added to the generated vsir instructions.
This commit is contained in:
Francisco Casas
2024-11-12 19:06:23 -03:00
committed by Henri Verbeet
parent 37a61bf41a
commit 1d290bf5db
Notes: Henri Verbeet 2024-12-09 16:18:05 +01:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1287
2 changed files with 89 additions and 44 deletions

View File

@@ -4349,47 +4349,6 @@ static void write_sm4_dcl_constant_buffer(const struct tpf_compiler *tpf, const
write_sm4_instruction(tpf, &instr);
}
static void write_sm4_dcl_samplers(const struct tpf_compiler *tpf, const struct extern_resource *resource)
{
unsigned int i;
struct sm4_instruction instr =
{
.opcode = VKD3D_SM4_OP_DCL_SAMPLER,
.dsts[0].reg.type = VKD3DSPR_SAMPLER,
.dst_count = 1,
};
VKD3D_ASSERT(resource->regset == HLSL_REGSET_SAMPLERS);
if (resource->component_type->sampler_dim == HLSL_SAMPLER_DIM_COMPARISON)
instr.extra_bits |= VKD3D_SM4_SAMPLER_COMPARISON << VKD3D_SM4_SAMPLER_MODE_SHIFT;
for (i = 0; i < resource->bind_count; ++i)
{
if (resource->var && !resource->var->objects_usage[HLSL_REGSET_SAMPLERS][i].used)
continue;
if (hlsl_version_ge(tpf->ctx, 5, 1))
{
VKD3D_ASSERT(!i);
instr.dsts[0].reg.idx[0].offset = resource->id;
instr.dsts[0].reg.idx[1].offset = resource->index;
instr.dsts[0].reg.idx[2].offset = resource->index; /* FIXME: array end */
instr.dsts[0].reg.idx_count = 3;
instr.idx[0] = resource->space;
instr.idx_count = 1;
}
else
{
instr.dsts[0].reg.idx[0].offset = resource->index + i;
instr.dsts[0].reg.idx_count = 1;
}
write_sm4_instruction(tpf, &instr);
}
}
static void write_sm4_dcl_textures(const struct tpf_compiler *tpf, const struct extern_resource *resource,
bool uav)
{
@@ -4561,6 +4520,37 @@ static void tpf_dcl_thread_group(const struct tpf_compiler *tpf, const struct vs
write_sm4_instruction(tpf, &instr);
}
static void tpf_dcl_sampler(const struct tpf_compiler *tpf, const struct vkd3d_shader_instruction *ins)
{
const struct vkd3d_shader_sampler *sampler = &ins->declaration.sampler;
struct sm4_instruction instr =
{
.opcode = VKD3D_SM4_OP_DCL_SAMPLER,
.extra_bits = ins->flags << VKD3D_SM4_SAMPLER_MODE_SHIFT,
.dsts[0].reg.type = VKD3DSPR_SAMPLER,
.dst_count = 1,
};
if (vkd3d_shader_ver_ge(&tpf->program->shader_version, 5, 1))
{
instr.dsts[0].reg.idx[0].offset = sampler->src.reg.idx[0].offset;
instr.dsts[0].reg.idx[1].offset = sampler->range.first;
instr.dsts[0].reg.idx[2].offset = sampler->range.last;
instr.dsts[0].reg.idx_count = 3;
instr.idx[0] = ins->declaration.sampler.range.space;
instr.idx_count = 1;
}
else
{
instr.dsts[0].reg.idx[0].offset = sampler->range.first;
instr.dsts[0].reg.idx_count = 1;
}
write_sm4_instruction(tpf, &instr);
}
static void write_sm4_dcl_global_flags(const struct tpf_compiler *tpf, uint32_t flags)
{
struct sm4_instruction instr =
@@ -4750,6 +4740,10 @@ static void tpf_handle_instruction(struct tpf_compiler *tpf, const struct vkd3d_
tpf_dcl_siv_semantic(tpf, VKD3D_SM4_OP_DCL_OUTPUT_SIV, &ins->declaration.register_semantic, 0);
break;
case VKD3DSIH_DCL_SAMPLER:
tpf_dcl_sampler(tpf, ins);
break;
case VKD3DSIH_ADD:
case VKD3DSIH_AND:
case VKD3DSIH_BREAK:
@@ -4920,9 +4914,7 @@ static void tpf_write_shdr(struct tpf_compiler *tpf, struct hlsl_ir_function_dec
{
const struct extern_resource *resource = &extern_resources[i];
if (resource->regset == HLSL_REGSET_SAMPLERS)
write_sm4_dcl_samplers(tpf, resource);
else if (resource->regset == HLSL_REGSET_TEXTURES)
if (resource->regset == HLSL_REGSET_TEXTURES)
write_sm4_dcl_textures(tpf, resource, false);
else if (resource->regset == HLSL_REGSET_UAVS)
write_sm4_dcl_textures(tpf, resource, true);