mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-09-13 09:16:14 -07:00
vkd3d-shader/hlsl: Store SM1 constant dcls on the vsir_program.
This commit is contained in:
parent
7abf3c3a37
commit
9a564872c5
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
@ -1471,6 +1471,7 @@ struct d3dbc_compiler
|
|||||||
struct vsir_program *program;
|
struct vsir_program *program;
|
||||||
struct vkd3d_bytecode_buffer buffer;
|
struct vkd3d_bytecode_buffer buffer;
|
||||||
struct vkd3d_shader_message_context *message_context;
|
struct vkd3d_shader_message_context *message_context;
|
||||||
|
bool failed;
|
||||||
|
|
||||||
/* OBJECTIVE: Store all the required information in the other fields so
|
/* OBJECTIVE: Store all the required information in the other fields so
|
||||||
* that this hlsl_ctx is no longer necessary. */
|
* that this hlsl_ctx is no longer necessary. */
|
||||||
@ -2169,31 +2170,42 @@ static void d3dbc_write_cast(struct d3dbc_compiler *d3dbc, const struct hlsl_ir_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void d3dbc_write_constant_defs(struct d3dbc_compiler *d3dbc)
|
static void d3dbc_write_vsir_def(struct d3dbc_compiler *d3dbc, const struct vkd3d_shader_instruction *ins)
|
||||||
{
|
{
|
||||||
const struct vkd3d_shader_version *version = &d3dbc->program->shader_version;
|
const struct vkd3d_shader_version *version = &d3dbc->program->shader_version;
|
||||||
struct vkd3d_bytecode_buffer *buffer = &d3dbc->buffer;
|
struct vkd3d_bytecode_buffer *buffer = &d3dbc->buffer;
|
||||||
struct hlsl_ctx *ctx = d3dbc->ctx;
|
uint32_t token;
|
||||||
unsigned int i, x;
|
|
||||||
|
|
||||||
for (i = 0; i < ctx->constant_defs.count; ++i)
|
const struct sm1_dst_register reg =
|
||||||
{
|
{
|
||||||
const struct hlsl_constant_register *constant_reg = &ctx->constant_defs.regs[i];
|
.type = VKD3DSPR_CONST,
|
||||||
uint32_t token = D3DSIO_DEF;
|
.writemask = VKD3DSP_WRITEMASK_ALL,
|
||||||
const struct sm1_dst_register reg =
|
.reg = ins->dst[0].reg.idx[0].offset,
|
||||||
{
|
};
|
||||||
.type = VKD3DSPR_CONST,
|
|
||||||
.writemask = VKD3DSP_WRITEMASK_ALL,
|
|
||||||
.reg = constant_reg->index,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (version->major > 1)
|
token = VKD3D_SM1_OP_DEF;
|
||||||
token |= 5 << D3DSI_INSTLENGTH_SHIFT;
|
if (version->major > 1)
|
||||||
put_u32(buffer, token);
|
token |= 5 << VKD3D_SM1_INSTRUCTION_LENGTH_SHIFT;
|
||||||
|
put_u32(buffer, token);
|
||||||
|
|
||||||
write_sm1_dst_register(buffer, ®);
|
write_sm1_dst_register(buffer, ®);
|
||||||
for (x = 0; x < 4; ++x)
|
for (unsigned int x = 0; x < 4; ++x)
|
||||||
put_f32(buffer, constant_reg->value.f[x]);
|
put_f32(buffer, ins->src[0].reg.u.immconst_f32[x]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void d3dbc_write_vsir_instruction(struct d3dbc_compiler *d3dbc, const struct vkd3d_shader_instruction *ins)
|
||||||
|
{
|
||||||
|
switch (ins->opcode)
|
||||||
|
{
|
||||||
|
case VKD3DSIH_DEF:
|
||||||
|
d3dbc_write_vsir_def(d3dbc, ins);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
vkd3d_shader_error(d3dbc->message_context, &ins->location, VKD3D_SHADER_ERROR_D3DBC_INVALID_OPCODE,
|
||||||
|
"vsir instruction with opcode %#x.", ins->opcode);
|
||||||
|
d3dbc->failed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2825,8 +2837,10 @@ static void d3dbc_write_swizzle(struct d3dbc_compiler *d3dbc, const struct hlsl_
|
|||||||
|
|
||||||
static void d3dbc_write_block(struct d3dbc_compiler *d3dbc, const struct hlsl_block *block)
|
static void d3dbc_write_block(struct d3dbc_compiler *d3dbc, const struct hlsl_block *block)
|
||||||
{
|
{
|
||||||
|
struct vkd3d_shader_instruction *vsir_instr;
|
||||||
struct hlsl_ctx *ctx = d3dbc->ctx;
|
struct hlsl_ctx *ctx = d3dbc->ctx;
|
||||||
const struct hlsl_ir_node *instr;
|
const struct hlsl_ir_node *instr;
|
||||||
|
unsigned int vsir_instr_idx;
|
||||||
|
|
||||||
LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry)
|
LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry)
|
||||||
{
|
{
|
||||||
@ -2879,6 +2893,12 @@ static void d3dbc_write_block(struct d3dbc_compiler *d3dbc, const struct hlsl_bl
|
|||||||
d3dbc_write_swizzle(d3dbc, instr);
|
d3dbc_write_swizzle(d3dbc, instr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case HLSL_IR_VSIR_INSTRUCTION_REF:
|
||||||
|
vsir_instr_idx = hlsl_ir_vsir_instruction_ref(instr)->vsir_instr_idx;
|
||||||
|
vsir_instr = &d3dbc->program->instructions.elements[vsir_instr_idx];
|
||||||
|
d3dbc_write_vsir_instruction(d3dbc, vsir_instr);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
hlsl_fixme(ctx, &instr->loc, "Instruction type %s.", hlsl_node_type_to_string(instr->type));
|
hlsl_fixme(ctx, &instr->loc, "Instruction type %s.", hlsl_node_type_to_string(instr->type));
|
||||||
}
|
}
|
||||||
@ -2897,6 +2917,7 @@ int d3dbc_compile(struct vsir_program *program, uint64_t config_flags,
|
|||||||
const struct vkd3d_shader_version *version = &program->shader_version;
|
const struct vkd3d_shader_version *version = &program->shader_version;
|
||||||
struct d3dbc_compiler d3dbc = {0};
|
struct d3dbc_compiler d3dbc = {0};
|
||||||
struct vkd3d_bytecode_buffer *buffer = &d3dbc.buffer;
|
struct vkd3d_bytecode_buffer *buffer = &d3dbc.buffer;
|
||||||
|
int result;
|
||||||
|
|
||||||
d3dbc.ctx = ctx;
|
d3dbc.ctx = ctx;
|
||||||
d3dbc.program = program;
|
d3dbc.program = program;
|
||||||
@ -2906,17 +2927,19 @@ int d3dbc_compile(struct vsir_program *program, uint64_t config_flags,
|
|||||||
|
|
||||||
bytecode_put_bytes(buffer, ctab->code, ctab->size);
|
bytecode_put_bytes(buffer, ctab->code, ctab->size);
|
||||||
|
|
||||||
d3dbc_write_constant_defs(&d3dbc);
|
|
||||||
d3dbc_write_semantic_dcls(&d3dbc);
|
d3dbc_write_semantic_dcls(&d3dbc);
|
||||||
d3dbc_write_sampler_dcls(&d3dbc);
|
d3dbc_write_sampler_dcls(&d3dbc);
|
||||||
d3dbc_write_block(&d3dbc, &entry_func->body);
|
d3dbc_write_block(&d3dbc, &entry_func->body);
|
||||||
|
|
||||||
put_u32(buffer, D3DSIO_END);
|
put_u32(buffer, D3DSIO_END);
|
||||||
|
|
||||||
|
result = ctx->result;
|
||||||
if (buffer->status)
|
if (buffer->status)
|
||||||
ctx->result = buffer->status;
|
result = buffer->status;
|
||||||
|
if (d3dbc.failed)
|
||||||
|
result = VKD3D_ERROR_INVALID_SHADER;
|
||||||
|
|
||||||
if (!ctx->result)
|
if (!result)
|
||||||
{
|
{
|
||||||
out->code = buffer->data;
|
out->code = buffer->data;
|
||||||
out->size = buffer->size;
|
out->size = buffer->size;
|
||||||
@ -2925,5 +2948,5 @@ int d3dbc_compile(struct vsir_program *program, uint64_t config_flags,
|
|||||||
{
|
{
|
||||||
vkd3d_free(buffer->data);
|
vkd3d_free(buffer->data);
|
||||||
}
|
}
|
||||||
return ctx->result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1028,6 +1028,7 @@ struct hlsl_ctx
|
|||||||
{
|
{
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
struct hlsl_vec4 value;
|
struct hlsl_vec4 value;
|
||||||
|
struct vkd3d_shader_location loc;
|
||||||
} *regs;
|
} *regs;
|
||||||
size_t count, size;
|
size_t count, size;
|
||||||
} constant_defs;
|
} constant_defs;
|
||||||
|
@ -4822,7 +4822,8 @@ static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void record_constant(struct hlsl_ctx *ctx, unsigned int component_index, float f)
|
static void record_constant(struct hlsl_ctx *ctx, unsigned int component_index, float f,
|
||||||
|
const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
struct hlsl_constant_defs *defs = &ctx->constant_defs;
|
struct hlsl_constant_defs *defs = &ctx->constant_defs;
|
||||||
struct hlsl_constant_register *reg;
|
struct hlsl_constant_register *reg;
|
||||||
@ -4844,6 +4845,7 @@ static void record_constant(struct hlsl_ctx *ctx, unsigned int component_index,
|
|||||||
memset(reg, 0, sizeof(*reg));
|
memset(reg, 0, sizeof(*reg));
|
||||||
reg->index = component_index / 4;
|
reg->index = component_index / 4;
|
||||||
reg->value.f[component_index % 4] = f;
|
reg->value.f[component_index % 4] = f;
|
||||||
|
reg->loc = *loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void allocate_const_registers_recurse(struct hlsl_ctx *ctx,
|
static void allocate_const_registers_recurse(struct hlsl_ctx *ctx,
|
||||||
@ -4904,7 +4906,7 @@ static void allocate_const_registers_recurse(struct hlsl_ctx *ctx,
|
|||||||
vkd3d_unreachable();
|
vkd3d_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
record_constant(ctx, constant->reg.id * 4 + x, f);
|
record_constant(ctx, constant->reg.id * 4 + x, f, &constant->node.loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -4997,17 +4999,17 @@ static void allocate_sincos_const_registers(struct hlsl_ctx *ctx, struct hlsl_bl
|
|||||||
|
|
||||||
ctx->d3dsincosconst1 = allocate_numeric_registers_for_type(ctx, allocator, 1, UINT_MAX, type);
|
ctx->d3dsincosconst1 = allocate_numeric_registers_for_type(ctx, allocator, 1, UINT_MAX, type);
|
||||||
TRACE("Allocated D3DSINCOSCONST1 to %s.\n", debug_register('c', ctx->d3dsincosconst1, type));
|
TRACE("Allocated D3DSINCOSCONST1 to %s.\n", debug_register('c', ctx->d3dsincosconst1, type));
|
||||||
record_constant(ctx, ctx->d3dsincosconst1.id * 4 + 0, -1.55009923e-06f);
|
record_constant(ctx, ctx->d3dsincosconst1.id * 4 + 0, -1.55009923e-06f, &instr->loc);
|
||||||
record_constant(ctx, ctx->d3dsincosconst1.id * 4 + 1, -2.17013894e-05f);
|
record_constant(ctx, ctx->d3dsincosconst1.id * 4 + 1, -2.17013894e-05f, &instr->loc);
|
||||||
record_constant(ctx, ctx->d3dsincosconst1.id * 4 + 2, 2.60416674e-03f);
|
record_constant(ctx, ctx->d3dsincosconst1.id * 4 + 2, 2.60416674e-03f, &instr->loc);
|
||||||
record_constant(ctx, ctx->d3dsincosconst1.id * 4 + 3, 2.60416680e-04f);
|
record_constant(ctx, ctx->d3dsincosconst1.id * 4 + 3, 2.60416680e-04f, &instr->loc);
|
||||||
|
|
||||||
ctx->d3dsincosconst2 = allocate_numeric_registers_for_type(ctx, allocator, 1, UINT_MAX, type);
|
ctx->d3dsincosconst2 = allocate_numeric_registers_for_type(ctx, allocator, 1, UINT_MAX, type);
|
||||||
TRACE("Allocated D3DSINCOSCONST2 to %s.\n", debug_register('c', ctx->d3dsincosconst2, type));
|
TRACE("Allocated D3DSINCOSCONST2 to %s.\n", debug_register('c', ctx->d3dsincosconst2, type));
|
||||||
record_constant(ctx, ctx->d3dsincosconst2.id * 4 + 0, -2.08333340e-02f);
|
record_constant(ctx, ctx->d3dsincosconst2.id * 4 + 0, -2.08333340e-02f, &instr->loc);
|
||||||
record_constant(ctx, ctx->d3dsincosconst2.id * 4 + 1, -1.25000000e-01f);
|
record_constant(ctx, ctx->d3dsincosconst2.id * 4 + 1, -1.25000000e-01f, &instr->loc);
|
||||||
record_constant(ctx, ctx->d3dsincosconst2.id * 4 + 2, 1.00000000e+00f);
|
record_constant(ctx, ctx->d3dsincosconst2.id * 4 + 2, 1.00000000e+00f, &instr->loc);
|
||||||
record_constant(ctx, ctx->d3dsincosconst2.id * 4 + 3, 5.00000000e-01f);
|
record_constant(ctx, ctx->d3dsincosconst2.id * 4 + 3, 5.00000000e-01f, &instr->loc);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -6012,6 +6014,61 @@ static void sm1_generate_vsir_signature(struct hlsl_ctx *ctx, struct vsir_progra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sm1_generate_vsir_constant_defs(struct hlsl_ctx *ctx, struct vsir_program *program,
|
||||||
|
struct hlsl_block *block)
|
||||||
|
{
|
||||||
|
struct vkd3d_shader_instruction_array *instructions = &program->instructions;
|
||||||
|
struct vkd3d_shader_dst_param *dst_param;
|
||||||
|
struct vkd3d_shader_src_param *src_param;
|
||||||
|
struct vkd3d_shader_instruction *ins;
|
||||||
|
struct hlsl_ir_node *vsir_instr;
|
||||||
|
unsigned int i, x;
|
||||||
|
|
||||||
|
for (i = 0; i < ctx->constant_defs.count; ++i)
|
||||||
|
{
|
||||||
|
const struct hlsl_constant_register *constant_reg = &ctx->constant_defs.regs[i];
|
||||||
|
|
||||||
|
if (!shader_instruction_array_reserve(instructions, instructions->count + 1))
|
||||||
|
{
|
||||||
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ins = &instructions->elements[instructions->count];
|
||||||
|
if (!vsir_instruction_init_with_params(program, ins, &constant_reg->loc, VKD3DSIH_DEF, 1, 1))
|
||||||
|
{
|
||||||
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
++instructions->count;
|
||||||
|
|
||||||
|
dst_param = &ins->dst[0];
|
||||||
|
vsir_register_init(&dst_param->reg, VKD3DSPR_CONST, VKD3D_DATA_FLOAT, 1);
|
||||||
|
ins->dst[0].reg.dimension = VSIR_DIMENSION_VEC4;
|
||||||
|
ins->dst[0].reg.idx[0].offset = constant_reg->index;
|
||||||
|
ins->dst[0].write_mask = VKD3DSP_WRITEMASK_ALL;
|
||||||
|
|
||||||
|
src_param = &ins->src[0];
|
||||||
|
vsir_register_init(&src_param->reg, VKD3DSPR_IMMCONST, VKD3D_DATA_FLOAT, 0);
|
||||||
|
src_param->reg.type = VKD3DSPR_IMMCONST;
|
||||||
|
src_param->reg.precision = VKD3D_SHADER_REGISTER_PRECISION_DEFAULT;
|
||||||
|
src_param->reg.non_uniform = false;
|
||||||
|
src_param->reg.data_type = VKD3D_DATA_FLOAT;
|
||||||
|
src_param->reg.dimension = VSIR_DIMENSION_VEC4;
|
||||||
|
for (x = 0; x < 4; ++x)
|
||||||
|
src_param->reg.u.immconst_f32[x] = constant_reg->value.f[x];
|
||||||
|
src_param->swizzle = VKD3D_SHADER_NO_SWIZZLE;
|
||||||
|
|
||||||
|
if (!(vsir_instr = hlsl_new_vsir_instruction_ref(ctx, instructions->count - 1, NULL, NULL,
|
||||||
|
&constant_reg->loc)))
|
||||||
|
{
|
||||||
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hlsl_block_add_instr(block, vsir_instr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* OBJECTIVE: Translate all the information from ctx and entry_func to the
|
/* OBJECTIVE: Translate all the information from ctx and entry_func to the
|
||||||
* vsir_program and ctab blob, so they can be used as input to d3dbc_compile()
|
* vsir_program and ctab blob, so they can be used as input to d3dbc_compile()
|
||||||
* without relying on ctx and entry_func. */
|
* without relying on ctx and entry_func. */
|
||||||
@ -6020,6 +6077,7 @@ static void sm1_generate_vsir(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl
|
|||||||
{
|
{
|
||||||
struct vkd3d_shader_version version = {0};
|
struct vkd3d_shader_version version = {0};
|
||||||
struct vkd3d_bytecode_buffer buffer = {0};
|
struct vkd3d_bytecode_buffer buffer = {0};
|
||||||
|
struct hlsl_block block;
|
||||||
|
|
||||||
version.major = ctx->profile->major_version;
|
version.major = ctx->profile->major_version;
|
||||||
version.minor = ctx->profile->minor_version;
|
version.minor = ctx->profile->minor_version;
|
||||||
@ -6041,6 +6099,10 @@ static void sm1_generate_vsir(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl
|
|||||||
ctab->size = buffer.size;
|
ctab->size = buffer.size;
|
||||||
|
|
||||||
sm1_generate_vsir_signature(ctx, program);
|
sm1_generate_vsir_signature(ctx, program);
|
||||||
|
|
||||||
|
hlsl_block_init(&block);
|
||||||
|
sm1_generate_vsir_constant_defs(ctx, program, &block);
|
||||||
|
list_move_head(&entry_func->body.instrs, &block.instrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct hlsl_ir_jump *loop_unrolling_find_jump(struct hlsl_block *block, struct hlsl_ir_node *stop_point,
|
static struct hlsl_ir_jump *loop_unrolling_find_jump(struct hlsl_block *block, struct hlsl_ir_node *stop_point,
|
||||||
|
@ -136,7 +136,7 @@ static void vkd3d_shader_instruction_make_nop(struct vkd3d_shader_instruction *i
|
|||||||
vsir_instruction_init(ins, &location, VKD3DSIH_NOP);
|
vsir_instruction_init(ins, &location, VKD3DSIH_NOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool vsir_instruction_init_with_params(struct vsir_program *program,
|
bool vsir_instruction_init_with_params(struct vsir_program *program,
|
||||||
struct vkd3d_shader_instruction *ins, const struct vkd3d_shader_location *location,
|
struct vkd3d_shader_instruction *ins, const struct vkd3d_shader_location *location,
|
||||||
enum vkd3d_shader_opcode opcode, unsigned int dst_count, unsigned int src_count)
|
enum vkd3d_shader_opcode opcode, unsigned int dst_count, unsigned int src_count)
|
||||||
{
|
{
|
||||||
|
@ -1389,6 +1389,9 @@ enum vkd3d_result vsir_program_normalise(struct vsir_program *program, uint64_t
|
|||||||
const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_message_context *message_context);
|
const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_message_context *message_context);
|
||||||
enum vkd3d_result vsir_program_validate(struct vsir_program *program, uint64_t config_flags,
|
enum vkd3d_result vsir_program_validate(struct vsir_program *program, uint64_t config_flags,
|
||||||
const char *source_name, struct vkd3d_shader_message_context *message_context);
|
const char *source_name, struct vkd3d_shader_message_context *message_context);
|
||||||
|
bool vsir_instruction_init_with_params(struct vsir_program *program,
|
||||||
|
struct vkd3d_shader_instruction *ins, const struct vkd3d_shader_location *location,
|
||||||
|
enum vkd3d_shader_opcode opcode, unsigned int dst_count, unsigned int src_count);
|
||||||
|
|
||||||
static inline struct vkd3d_shader_dst_param *vsir_program_get_dst_params(
|
static inline struct vkd3d_shader_dst_param *vsir_program_get_dst_params(
|
||||||
struct vsir_program *program, unsigned int count)
|
struct vsir_program *program, unsigned int count)
|
||||||
|
Loading…
Reference in New Issue
Block a user