diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index ab4e8a44..c3de9eb7 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -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); diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index c2c62d2c..8d363945 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -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;