mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/hlsl: Save hlsl_ir_stores in the vsir_program for SM1.
This commit is contained in:
parent
9aace1ac4e
commit
b46eac35c0
Notes:
Henri Verbeet
2024-09-04 18:48:04 +02:00
Approved-by: Elizabeth Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/941
@ -2795,52 +2795,6 @@ static void d3dbc_write_resource_load(struct d3dbc_compiler *d3dbc, const struct
|
|||||||
d3dbc_write_instruction(d3dbc, &sm1_instr);
|
d3dbc_write_instruction(d3dbc, &sm1_instr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void d3dbc_write_store(struct d3dbc_compiler *d3dbc, const struct hlsl_ir_node *instr)
|
|
||||||
{
|
|
||||||
const struct vkd3d_shader_version *version = &d3dbc->program->shader_version;
|
|
||||||
const struct hlsl_ir_store *store = hlsl_ir_store(instr);
|
|
||||||
struct hlsl_ctx *ctx = d3dbc->ctx;
|
|
||||||
const struct hlsl_reg reg = hlsl_reg_from_deref(ctx, &store->lhs);
|
|
||||||
const struct hlsl_ir_node *rhs = store->rhs.node;
|
|
||||||
struct sm1_instruction sm1_instr =
|
|
||||||
{
|
|
||||||
.opcode = D3DSIO_MOV,
|
|
||||||
|
|
||||||
.dst.type = VKD3DSPR_TEMP,
|
|
||||||
.dst.reg = reg.id,
|
|
||||||
.dst.writemask = hlsl_combine_writemasks(reg.writemask, store->writemask),
|
|
||||||
.has_dst = 1,
|
|
||||||
|
|
||||||
.srcs[0].type = VKD3DSPR_TEMP,
|
|
||||||
.srcs[0].reg = rhs->reg.id,
|
|
||||||
.srcs[0].swizzle = hlsl_swizzle_from_writemask(rhs->reg.writemask),
|
|
||||||
.src_count = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (store->lhs.var->is_output_semantic)
|
|
||||||
{
|
|
||||||
if (version->type == VKD3D_SHADER_TYPE_PIXEL && version->major == 1)
|
|
||||||
{
|
|
||||||
sm1_instr.dst.type = VKD3DSPR_TEMP;
|
|
||||||
sm1_instr.dst.reg = 0;
|
|
||||||
}
|
|
||||||
else if (!hlsl_sm1_register_from_semantic(&d3dbc->program->shader_version, store->lhs.var->semantic.name,
|
|
||||||
store->lhs.var->semantic.index, true, &sm1_instr.dst.type, &sm1_instr.dst.reg))
|
|
||||||
{
|
|
||||||
VKD3D_ASSERT(reg.allocated);
|
|
||||||
sm1_instr.dst.type = VKD3DSPR_OUTPUT;
|
|
||||||
sm1_instr.dst.reg = reg.id;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sm1_instr.dst.writemask = (1u << store->lhs.var->data_type->dimx) - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
VKD3D_ASSERT(reg.allocated);
|
|
||||||
|
|
||||||
sm1_map_src_swizzle(&sm1_instr.srcs[0], sm1_instr.dst.writemask);
|
|
||||||
d3dbc_write_instruction(d3dbc, &sm1_instr);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void d3dbc_write_swizzle(struct d3dbc_compiler *d3dbc, const struct hlsl_ir_node *instr)
|
static void d3dbc_write_swizzle(struct d3dbc_compiler *d3dbc, const struct hlsl_ir_node *instr)
|
||||||
{
|
{
|
||||||
const struct hlsl_ir_swizzle *swizzle = hlsl_ir_swizzle(instr);
|
const struct hlsl_ir_swizzle *swizzle = hlsl_ir_swizzle(instr);
|
||||||
@ -2909,10 +2863,6 @@ static void d3dbc_write_block(struct d3dbc_compiler *d3dbc, const struct hlsl_bl
|
|||||||
d3dbc_write_resource_load(d3dbc, instr);
|
d3dbc_write_resource_load(d3dbc, instr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HLSL_IR_STORE:
|
|
||||||
d3dbc_write_store(d3dbc, instr);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HLSL_IR_SWIZZLE:
|
case HLSL_IR_SWIZZLE:
|
||||||
d3dbc_write_swizzle(d3dbc, instr);
|
d3dbc_write_swizzle(d3dbc, instr);
|
||||||
break;
|
break;
|
||||||
|
@ -3333,8 +3333,8 @@ void hlsl_replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new)
|
|||||||
{
|
{
|
||||||
struct hlsl_src *src, *next;
|
struct hlsl_src *src, *next;
|
||||||
|
|
||||||
VKD3D_ASSERT(old->data_type->dimx == new->data_type->dimx);
|
VKD3D_ASSERT(old->data_type == new->data_type || old->data_type->dimx == new->data_type->dimx);
|
||||||
VKD3D_ASSERT(old->data_type->dimy == new->data_type->dimy);
|
VKD3D_ASSERT(old->data_type == new->data_type || old->data_type->dimy == new->data_type->dimy);
|
||||||
|
|
||||||
LIST_FOR_EACH_ENTRY_SAFE(src, next, &old->uses, struct hlsl_src, entry)
|
LIST_FOR_EACH_ENTRY_SAFE(src, next, &old->uses, struct hlsl_src, entry)
|
||||||
{
|
{
|
||||||
|
@ -6227,6 +6227,51 @@ static void sm1_generate_vsir_instr_constant(struct hlsl_ctx *ctx,
|
|||||||
hlsl_replace_node(instr, vsir_instr);
|
hlsl_replace_node(instr, vsir_instr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sm1_generate_vsir_init_dst_param_from_deref(struct hlsl_ctx *ctx,
|
||||||
|
struct vkd3d_shader_dst_param *dst_param, struct hlsl_deref *deref,
|
||||||
|
const struct vkd3d_shader_location *loc, unsigned int writemask)
|
||||||
|
{
|
||||||
|
enum vkd3d_shader_register_type type = VKD3DSPR_TEMP;
|
||||||
|
struct vkd3d_shader_version version;
|
||||||
|
uint32_t register_index;
|
||||||
|
struct hlsl_reg reg;
|
||||||
|
|
||||||
|
reg = hlsl_reg_from_deref(ctx, deref);
|
||||||
|
register_index = reg.id;
|
||||||
|
writemask = hlsl_combine_writemasks(reg.writemask, writemask);
|
||||||
|
|
||||||
|
if (deref->var->is_output_semantic)
|
||||||
|
{
|
||||||
|
version.major = ctx->profile->major_version;
|
||||||
|
version.minor = ctx->profile->minor_version;
|
||||||
|
version.type = ctx->profile->type;
|
||||||
|
|
||||||
|
if (version.type == VKD3D_SHADER_TYPE_PIXEL && version.major == 1)
|
||||||
|
{
|
||||||
|
type = VKD3DSPR_TEMP;
|
||||||
|
register_index = 0;
|
||||||
|
}
|
||||||
|
else if (!hlsl_sm1_register_from_semantic(&version, deref->var->semantic.name,
|
||||||
|
deref->var->semantic.index, true, &type, ®ister_index))
|
||||||
|
{
|
||||||
|
VKD3D_ASSERT(reg.allocated);
|
||||||
|
type = VKD3DSPR_OUTPUT;
|
||||||
|
register_index = reg.id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
writemask = (1u << deref->var->data_type->dimx) - 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
VKD3D_ASSERT(reg.allocated);
|
||||||
|
|
||||||
|
vsir_register_init(&dst_param->reg, type, VKD3D_DATA_FLOAT, 1);
|
||||||
|
dst_param->write_mask = writemask;
|
||||||
|
dst_param->reg.idx[0].offset = register_index;
|
||||||
|
|
||||||
|
if (deref->rel_offset.node)
|
||||||
|
hlsl_fixme(ctx, loc, "Translate relative addressing on dst register for vsir.");
|
||||||
|
}
|
||||||
|
|
||||||
static void sm1_generate_vsir_init_src_param_from_deref(struct hlsl_ctx *ctx,
|
static void sm1_generate_vsir_init_src_param_from_deref(struct hlsl_ctx *ctx,
|
||||||
struct vkd3d_shader_src_param *src_param, struct hlsl_deref *deref,
|
struct vkd3d_shader_src_param *src_param, struct hlsl_deref *deref,
|
||||||
unsigned int dst_writemask, const struct vkd3d_shader_location *loc)
|
unsigned int dst_writemask, const struct vkd3d_shader_location *loc)
|
||||||
@ -6303,6 +6348,36 @@ static void sm1_generate_vsir_instr_load(struct hlsl_ctx *ctx, struct vsir_progr
|
|||||||
hlsl_replace_node(instr, vsir_instr);
|
hlsl_replace_node(instr, vsir_instr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sm1_generate_vsir_instr_store(struct hlsl_ctx *ctx, struct vsir_program *program,
|
||||||
|
struct hlsl_ir_store *store)
|
||||||
|
{
|
||||||
|
struct vkd3d_shader_instruction_array *instructions = &program->instructions;
|
||||||
|
struct hlsl_ir_node *rhs = store->rhs.node;
|
||||||
|
struct hlsl_ir_node *instr = &store->node;
|
||||||
|
struct vkd3d_shader_instruction *ins;
|
||||||
|
struct vkd3d_shader_src_param *src_param;
|
||||||
|
struct hlsl_ir_node *vsir_instr;
|
||||||
|
|
||||||
|
if (!(ins = generate_vsir_add_program_instruction(ctx, program, &instr->loc, VKD3DSIH_MOV, 1, 1)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
sm1_generate_vsir_init_dst_param_from_deref(ctx, &ins->dst[0], &store->lhs, &ins->location, store->writemask);
|
||||||
|
|
||||||
|
src_param = &ins->src[0];
|
||||||
|
vsir_register_init(&src_param->reg, VKD3DSPR_TEMP, VKD3D_DATA_FLOAT, 1);
|
||||||
|
src_param->reg.idx[0].offset = rhs->reg.id;
|
||||||
|
src_param->swizzle = sm1_generate_vsir_get_src_swizzle(rhs->reg.writemask, ins->dst[0].write_mask);
|
||||||
|
|
||||||
|
if (!(vsir_instr = hlsl_new_vsir_instruction_ref(ctx, instructions->count - 1, NULL, NULL, &instr->loc)))
|
||||||
|
{
|
||||||
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_add_before(&instr->entry, &vsir_instr->entry);
|
||||||
|
hlsl_replace_node(instr, vsir_instr);
|
||||||
|
}
|
||||||
|
|
||||||
static bool sm1_generate_vsir_instr(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
static bool sm1_generate_vsir_instr(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||||
{
|
{
|
||||||
struct vsir_program *program = context;
|
struct vsir_program *program = context;
|
||||||
@ -6317,6 +6392,10 @@ static bool sm1_generate_vsir_instr(struct hlsl_ctx *ctx, struct hlsl_ir_node *i
|
|||||||
sm1_generate_vsir_instr_load(ctx, program, hlsl_ir_load(instr));
|
sm1_generate_vsir_instr_load(ctx, program, hlsl_ir_load(instr));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case HLSL_IR_STORE:
|
||||||
|
sm1_generate_vsir_instr_store(ctx, program, hlsl_ir_store(instr));
|
||||||
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user