vkd3d-shader/hlsl: Store SM4 resource stores in the vsir program.

This commit is contained in:
Francisco Casas 2024-11-07 15:31:28 -03:00 committed by Henri Verbeet
parent 5b4af411f5
commit 13dfccc1c6
Notes: Henri Verbeet 2024-11-21 19:34:59 +01:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1253
2 changed files with 54 additions and 43 deletions

View File

@ -8822,6 +8822,53 @@ static bool sm4_generate_vsir_instr_load(struct hlsl_ctx *ctx, struct vsir_progr
return true;
}
static bool sm4_generate_vsir_instr_resource_store(struct hlsl_ctx *ctx,
struct vsir_program *program, struct hlsl_ir_resource_store *store)
{
struct hlsl_type *resource_type = hlsl_deref_get_type(ctx, &store->resource);
struct hlsl_ir_node *coords = store->coords.node, *value = store->value.node;
struct hlsl_ir_node *instr = &store->node;
struct vkd3d_shader_instruction *ins;
unsigned int writemask;
if (!store->resource.var->is_uniform)
{
hlsl_fixme(ctx, &store->node.loc, "Store to non-uniform resource variable.");
return false;
}
if (resource_type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER)
{
hlsl_fixme(ctx, &store->node.loc, "Structured buffers store is not implemented.");
return false;
}
if (resource_type->sampler_dim == HLSL_SAMPLER_DIM_RAW_BUFFER)
{
if (!(ins = generate_vsir_add_program_instruction(ctx, program, &instr->loc, VKD3DSIH_STORE_RAW, 1, 2)))
return false;
writemask = vkd3d_write_mask_from_component_count(value->data_type->dimx);
if (!sm4_generate_vsir_init_dst_param_from_deref(ctx, program,
&ins->dst[0], &store->resource, &instr->loc, writemask))
return false;
}
else
{
if (!(ins = generate_vsir_add_program_instruction(ctx, program, &instr->loc, VKD3DSIH_STORE_UAV_TYPED, 1, 2)))
return false;
if (!sm4_generate_vsir_init_dst_param_from_deref(ctx, program,
&ins->dst[0], &store->resource, &instr->loc, VKD3DSP_WRITEMASK_ALL))
return false;
}
vsir_src_from_hlsl_node(&ins->src[0], ctx, coords, VKD3DSP_WRITEMASK_ALL);
vsir_src_from_hlsl_node(&ins->src[1], ctx, value, VKD3DSP_WRITEMASK_ALL);
return true;
}
static void sm4_generate_vsir_block(struct hlsl_ctx *ctx, struct hlsl_block *block, struct vsir_program *program)
{
struct vkd3d_string_buffer *dst_type_string;
@ -8872,6 +8919,11 @@ static void sm4_generate_vsir_block(struct hlsl_ctx *ctx, struct hlsl_block *blo
sm4_generate_vsir_block(ctx, &hlsl_ir_loop(instr)->body, program);
break;
case HLSL_IR_RESOURCE_STORE:
if (sm4_generate_vsir_instr_resource_store(ctx, program, hlsl_ir_resource_store(instr)))
replace_instr_with_last_vsir_instr(ctx, program, instr);
break;
case HLSL_IR_STORE:
if (sm4_generate_vsir_instr_store(ctx, program, hlsl_ir_store(instr)))
replace_instr_with_last_vsir_instr(ctx, program, instr);

View File

@ -5438,45 +5438,6 @@ static void write_sm4_resource_load(const struct tpf_compiler *tpf, const struct
}
}
static void write_sm4_resource_store(const struct tpf_compiler *tpf, const struct hlsl_ir_resource_store *store)
{
struct hlsl_type *resource_type = hlsl_deref_get_type(tpf->ctx, &store->resource);
struct hlsl_ir_node *coords = store->coords.node, *value = store->value.node;
struct sm4_instruction instr;
if (!store->resource.var->is_uniform)
{
hlsl_fixme(tpf->ctx, &store->node.loc, "Store to non-uniform resource variable.");
return;
}
if (resource_type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER)
{
hlsl_fixme(tpf->ctx, &store->node.loc, "Structured buffers store is not implemented.");
return;
}
memset(&instr, 0, sizeof(instr));
sm4_register_from_deref(tpf, &instr.dsts[0].reg, &instr.dsts[0].write_mask, &store->resource, &instr);
instr.dst_count = 1;
if (resource_type->sampler_dim == HLSL_SAMPLER_DIM_RAW_BUFFER)
{
instr.opcode = VKD3D_SM5_OP_STORE_RAW;
instr.dsts[0].write_mask = vkd3d_write_mask_from_component_count(value->data_type->dimx);
}
else
{
instr.opcode = VKD3D_SM5_OP_STORE_UAV_TYPED;
}
sm4_src_from_node(tpf, &instr.srcs[0], coords, VKD3DSP_WRITEMASK_ALL);
sm4_src_from_node(tpf, &instr.srcs[1], value, VKD3DSP_WRITEMASK_ALL);
instr.src_count = 2;
write_sm4_instruction(tpf, &instr);
}
static void write_sm4_switch(struct tpf_compiler *tpf, const struct hlsl_ir_switch *s)
{
const struct hlsl_ir_node *selector = s->selector.node;
@ -5664,6 +5625,8 @@ static void tpf_handle_instruction(struct tpf_compiler *tpf, const struct vkd3d_
case VKD3DSIH_SAMPLE_INFO:
case VKD3DSIH_SINCOS:
case VKD3DSIH_SQRT:
case VKD3DSIH_STORE_RAW:
case VKD3DSIH_STORE_UAV_TYPED:
case VKD3DSIH_UDIV:
case VKD3DSIH_UGE:
case VKD3DSIH_ULT:
@ -5722,10 +5685,6 @@ static void write_sm4_block(struct tpf_compiler *tpf, const struct hlsl_block *b
write_sm4_resource_load(tpf, hlsl_ir_resource_load(instr));
break;
case HLSL_IR_RESOURCE_STORE:
write_sm4_resource_store(tpf, hlsl_ir_resource_store(instr));
break;
case HLSL_IR_LOOP:
write_sm4_loop(tpf, hlsl_ir_loop(instr));
break;