mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/spirv: Emit variables for flat constant buffers.
This commit is contained in:
parent
25cf6a720b
commit
e0e261eac3
Notes:
Alexandre Julliard
2023-07-17 23:26:26 +02:00
Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/273
@ -2529,13 +2529,13 @@ static bool spirv_compiler_check_shader_visibility(const struct spirv_compiler *
|
||||
}
|
||||
|
||||
static struct vkd3d_push_constant_buffer_binding *spirv_compiler_find_push_constant_buffer(
|
||||
const struct spirv_compiler *compiler, const struct vkd3d_shader_constant_buffer *cb)
|
||||
const struct spirv_compiler *compiler, const struct vkd3d_shader_register_range *range)
|
||||
{
|
||||
unsigned int register_space = cb->range.space;
|
||||
unsigned int reg_idx = cb->range.first;
|
||||
unsigned int register_space = range->space;
|
||||
unsigned int reg_idx = range->first;
|
||||
unsigned int i;
|
||||
|
||||
if (cb->range.first != cb->range.last)
|
||||
if (range->first != range->last)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < compiler->shader_interface.push_constant_buffer_count; ++i)
|
||||
@ -5470,28 +5470,24 @@ static uint32_t spirv_compiler_build_descriptor_variable(struct spirv_compiler *
|
||||
return var_id;
|
||||
}
|
||||
|
||||
static void spirv_compiler_emit_dcl_constant_buffer(struct spirv_compiler *compiler,
|
||||
const struct vkd3d_shader_instruction *instruction)
|
||||
static void spirv_compiler_emit_constant_buffer(struct spirv_compiler *compiler, unsigned int size,
|
||||
const struct vkd3d_shader_register_range *range, const struct vkd3d_shader_register *reg)
|
||||
{
|
||||
const struct vkd3d_shader_constant_buffer *cb = &instruction->declaration.cb;
|
||||
struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
|
||||
uint32_t vec4_id, array_type_id, length_id, struct_id, var_id;
|
||||
const SpvStorageClass storage_class = SpvStorageClassUniform;
|
||||
const struct vkd3d_shader_register *reg = &cb->src.reg;
|
||||
struct vkd3d_push_constant_buffer_binding *push_cb;
|
||||
struct vkd3d_descriptor_variable_info var_info;
|
||||
struct vkd3d_symbol reg_symbol;
|
||||
|
||||
assert(!(instruction->flags & ~VKD3DSI_INDEXED_DYNAMIC));
|
||||
|
||||
if ((push_cb = spirv_compiler_find_push_constant_buffer(compiler, cb)))
|
||||
if ((push_cb = spirv_compiler_find_push_constant_buffer(compiler, range)))
|
||||
{
|
||||
/* Push constant buffers are handled in
|
||||
* spirv_compiler_emit_push_constant_buffers().
|
||||
*/
|
||||
unsigned int cb_size_in_bytes = cb->size * VKD3D_VEC4_SIZE * sizeof(uint32_t);
|
||||
unsigned int cb_size_in_bytes = size * VKD3D_VEC4_SIZE * sizeof(uint32_t);
|
||||
push_cb->reg = *reg;
|
||||
push_cb->size = cb->size;
|
||||
push_cb->size = size;
|
||||
if (cb_size_in_bytes > push_cb->pc.size)
|
||||
{
|
||||
WARN("Constant buffer size %u exceeds push constant size %u.\n",
|
||||
@ -5501,17 +5497,17 @@ static void spirv_compiler_emit_dcl_constant_buffer(struct spirv_compiler *compi
|
||||
}
|
||||
|
||||
vec4_id = vkd3d_spirv_get_type_id(builder, VKD3D_SHADER_COMPONENT_FLOAT, VKD3D_VEC4_SIZE);
|
||||
length_id = spirv_compiler_get_constant_uint(compiler, cb->size);
|
||||
length_id = spirv_compiler_get_constant_uint(compiler, size);
|
||||
array_type_id = vkd3d_spirv_build_op_type_array(builder, vec4_id, length_id);
|
||||
vkd3d_spirv_build_op_decorate1(builder, array_type_id, SpvDecorationArrayStride, 16);
|
||||
|
||||
struct_id = vkd3d_spirv_build_op_type_struct(builder, &array_type_id, 1);
|
||||
vkd3d_spirv_build_op_decorate(builder, struct_id, SpvDecorationBlock, NULL, 0);
|
||||
vkd3d_spirv_build_op_member_decorate1(builder, struct_id, 0, SpvDecorationOffset, 0);
|
||||
vkd3d_spirv_build_op_name(builder, struct_id, "cb%u_struct", cb->size);
|
||||
vkd3d_spirv_build_op_name(builder, struct_id, "cb%u_struct", size);
|
||||
|
||||
var_id = spirv_compiler_build_descriptor_variable(compiler, storage_class, struct_id,
|
||||
reg, &cb->range, VKD3D_SHADER_RESOURCE_BUFFER, false, &var_info);
|
||||
reg, range, VKD3D_SHADER_RESOURCE_BUFFER, false, &var_info);
|
||||
|
||||
vkd3d_symbol_make_register(®_symbol, reg);
|
||||
vkd3d_symbol_set_register_info(®_symbol, var_id, storage_class,
|
||||
@ -5521,6 +5517,16 @@ static void spirv_compiler_emit_dcl_constant_buffer(struct spirv_compiler *compi
|
||||
spirv_compiler_put_symbol(compiler, ®_symbol);
|
||||
}
|
||||
|
||||
static void spirv_compiler_emit_dcl_constant_buffer(struct spirv_compiler *compiler,
|
||||
const struct vkd3d_shader_instruction *instruction)
|
||||
{
|
||||
const struct vkd3d_shader_constant_buffer *cb = &instruction->declaration.cb;
|
||||
|
||||
assert(!(instruction->flags & ~VKD3DSI_INDEXED_DYNAMIC));
|
||||
|
||||
spirv_compiler_emit_constant_buffer(compiler, cb->size, &cb->range, &cb->src.reg);
|
||||
}
|
||||
|
||||
static void spirv_compiler_emit_dcl_immediate_constant_buffer(struct spirv_compiler *compiler,
|
||||
const struct vkd3d_shader_instruction *instruction)
|
||||
{
|
||||
@ -9429,6 +9435,26 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void spirv_compiler_emit_sm1_constant_buffer(struct spirv_compiler *compiler,
|
||||
const struct vkd3d_shader_desc *desc, enum vkd3d_shader_d3dbc_constant_register set,
|
||||
enum vkd3d_data_type data_type)
|
||||
{
|
||||
struct vkd3d_shader_register_range range = {.space = 0, .first = set, .last = set};
|
||||
uint32_t count = desc->flat_constant_count[set].external;
|
||||
struct vkd3d_shader_register reg =
|
||||
{
|
||||
.type = VKD3DSPR_CONSTBUFFER,
|
||||
.idx[0].offset = set, /* register ID */
|
||||
.idx[1].offset = set, /* register index */
|
||||
.idx[2].offset = count, /* size */
|
||||
.idx_count = 3,
|
||||
.data_type = data_type,
|
||||
};
|
||||
|
||||
if (count)
|
||||
spirv_compiler_emit_constant_buffer(compiler, count, &range, ®);
|
||||
}
|
||||
|
||||
static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler,
|
||||
const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_parser *parser,
|
||||
struct vkd3d_shader_code *spirv)
|
||||
@ -9444,6 +9470,13 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler,
|
||||
if (parser->shader_desc.temp_count)
|
||||
spirv_compiler_emit_temps(compiler, parser->shader_desc.temp_count);
|
||||
|
||||
spirv_compiler_emit_sm1_constant_buffer(compiler, &parser->shader_desc,
|
||||
VKD3D_SHADER_D3DBC_FLOAT_CONSTANT_REGISTER, VKD3D_DATA_FLOAT);
|
||||
spirv_compiler_emit_sm1_constant_buffer(compiler, &parser->shader_desc,
|
||||
VKD3D_SHADER_D3DBC_INT_CONSTANT_REGISTER, VKD3D_DATA_INT);
|
||||
spirv_compiler_emit_sm1_constant_buffer(compiler, &parser->shader_desc,
|
||||
VKD3D_SHADER_D3DBC_BOOL_CONSTANT_REGISTER, VKD3D_DATA_UINT);
|
||||
|
||||
compiler->location.column = 0;
|
||||
compiler->location.line = 1;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user