libs/vkd3d-shader: Introduce vkd3d_shader_interface structure.

This commit is contained in:
Józef Kucia 2017-08-16 13:11:52 +02:00
parent e6f6d01489
commit e3d6bac31b
6 changed files with 57 additions and 58 deletions

View File

@ -57,14 +57,19 @@ enum vkd3d_descriptor_type
VKD3D_DESCRIPTOR_TYPE_SAMPLER, /* s# */
};
struct vkd3d_shader_descriptor_binding
{
uint32_t set;
uint32_t binding;
};
struct vkd3d_shader_resource_binding
{
enum vkd3d_descriptor_type type;
unsigned int register_index;
bool is_buffer;
uint32_t descriptor_set;
uint32_t binding;
struct vkd3d_shader_descriptor_binding binding;
};
struct vkd3d_shader_push_constant
@ -76,10 +81,18 @@ struct vkd3d_shader_push_constant
unsigned int size; /* in bytes */
};
struct vkd3d_shader_interface
{
const struct vkd3d_shader_resource_binding *bindings;
unsigned int binding_count;
const struct vkd3d_shader_push_constant *push_constants;
unsigned int push_constant_count;
};
HRESULT vkd3d_shader_compile_dxbc(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_code *spirv, uint32_t compiler_options,
const struct vkd3d_shader_resource_binding *bindings, unsigned int binding_count,
const struct vkd3d_shader_push_constant *push_constants, unsigned int push_constant_count);
const struct vkd3d_shader_interface *shader_interface);
void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *code);
HRESULT vkd3d_shader_parse_root_signature(const struct vkd3d_shader_code *dxbc,

View File

@ -1562,9 +1562,7 @@ struct vkd3d_dxbc_compiler
struct vkd3d_control_flow_info *control_flow_info;
size_t control_flow_info_size;
unsigned int binding_count;
const struct vkd3d_shader_resource_binding *bindings;
unsigned int push_constant_count;
struct vkd3d_shader_interface shader_interface;
struct vkd3d_push_constant_buffer *push_constants;
bool after_declarations_section;
@ -1581,8 +1579,7 @@ struct vkd3d_dxbc_compiler
struct vkd3d_dxbc_compiler *vkd3d_dxbc_compiler_create(const struct vkd3d_shader_version *shader_version,
const struct vkd3d_shader_desc *shader_desc, uint32_t compiler_options,
const struct vkd3d_shader_resource_binding *bindings, unsigned int binding_count,
const struct vkd3d_shader_push_constant *constants, unsigned int constant_count)
const struct vkd3d_shader_interface *shader_interface)
{
const struct vkd3d_shader_signature *output_signature = &shader_desc->output_signature;
struct vkd3d_dxbc_compiler *compiler;
@ -1633,22 +1630,20 @@ struct vkd3d_dxbc_compiler *vkd3d_dxbc_compiler_create(const struct vkd3d_shader
compiler->input_signature = &shader_desc->input_signature;
compiler->output_signature = &shader_desc->output_signature;
if (binding_count)
if (shader_interface)
{
compiler->binding_count = binding_count;
compiler->bindings = bindings;
}
if (constant_count)
{
compiler->push_constant_count = constant_count;
if (!(compiler->push_constants = vkd3d_calloc(constant_count, sizeof(*compiler->push_constants))))
compiler->shader_interface = *shader_interface;
if (shader_interface->push_constant_count)
{
vkd3d_dxbc_compiler_destroy(compiler);
return NULL;
if (!(compiler->push_constants = vkd3d_calloc(shader_interface->push_constant_count,
sizeof(*compiler->push_constants))))
{
vkd3d_dxbc_compiler_destroy(compiler);
return NULL;
}
for (i = 0; i < shader_interface->push_constant_count; ++i)
compiler->push_constants[i].pc = shader_interface->push_constants[i];
}
for (i = 0; i < compiler->push_constant_count; ++i)
compiler->push_constants[i].pc = constants[i];
}
return compiler;
@ -1682,7 +1677,7 @@ static struct vkd3d_push_constant_buffer *vkd3d_dxbc_compiler_find_push_constant
unsigned int reg_idx = reg->idx[0].offset;
unsigned int i;
for (i = 0; i < compiler->push_constant_count; ++i)
for (i = 0; i < compiler->shader_interface.push_constant_count; ++i)
{
struct vkd3d_push_constant_buffer *current = &compiler->push_constants[i];
@ -1696,18 +1691,13 @@ static struct vkd3d_push_constant_buffer *vkd3d_dxbc_compiler_find_push_constant
return NULL;
}
struct vkd3d_descriptor_binding
{
uint32_t set;
uint32_t binding;
};
static struct vkd3d_descriptor_binding vkd3d_dxbc_compiler_get_descriptor_binding(
static struct vkd3d_shader_descriptor_binding vkd3d_dxbc_compiler_get_descriptor_binding(
struct vkd3d_dxbc_compiler *compiler, const struct vkd3d_shader_register *reg,
enum vkd3d_shader_resource_type resource_type)
{
const struct vkd3d_shader_interface *shader_interface = &compiler->shader_interface;
struct vkd3d_shader_descriptor_binding vk_binding;
enum vkd3d_descriptor_type descriptor_type;
struct vkd3d_descriptor_binding vk_binding;
unsigned int reg_idx = reg->idx[0].offset;
bool is_buffer_resource;
unsigned int i;
@ -1727,19 +1717,15 @@ static struct vkd3d_descriptor_binding vkd3d_dxbc_compiler_get_descriptor_bindin
is_buffer_resource = resource_type == VKD3D_SHADER_RESOURCE_BUFFER;
if (descriptor_type != VKD3D_DESCRIPTOR_TYPE_UNKNOWN)
{
for (i = 0; i < compiler->binding_count; ++i)
for (i = 0; i < shader_interface->binding_count; ++i)
{
const struct vkd3d_shader_resource_binding *current = &compiler->bindings[i];
const struct vkd3d_shader_resource_binding *current = &shader_interface->bindings[i];
if (current->type == descriptor_type && current->register_index == reg_idx
&& current->is_buffer == is_buffer_resource)
{
vk_binding.set = current->descriptor_set;
vk_binding.binding = current->binding;
return vk_binding;
}
return current->binding;
}
if (compiler->binding_count)
if (shader_interface->binding_count)
FIXME("Could not find descriptor binding for %#x, %u.\n", descriptor_type, reg_idx);
}
@ -1753,7 +1739,7 @@ static void vkd3d_dxbc_compiler_emit_descriptor_binding(struct vkd3d_dxbc_compil
enum vkd3d_shader_resource_type resource_type)
{
struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
struct vkd3d_descriptor_binding vk_binding;
struct vkd3d_shader_descriptor_binding vk_binding;
vk_binding = vkd3d_dxbc_compiler_get_descriptor_binding(compiler, reg, resource_type);
vkd3d_spirv_build_op_decorate1(builder, variable_id, SpvDecorationDescriptorSet, vk_binding.set);
@ -2628,7 +2614,7 @@ static void vkd3d_dxbc_compiler_emit_push_constants(struct vkd3d_dxbc_compiler *
uint32_t *member_ids;
count = 0;
for (i = 0; i < compiler->push_constant_count; ++i)
for (i = 0; i < compiler->shader_interface.push_constant_count; ++i)
{
const struct vkd3d_push_constant_buffer *cb = &compiler->push_constants[i];
@ -2643,7 +2629,7 @@ static void vkd3d_dxbc_compiler_emit_push_constants(struct vkd3d_dxbc_compiler *
vec4_id = vkd3d_spirv_get_type_id(builder, VKD3D_TYPE_FLOAT, VKD3D_VEC4_SIZE);
for (i = 0, j = 0; i < compiler->push_constant_count; ++i)
for (i = 0, j = 0; i < compiler->shader_interface.push_constant_count; ++i)
{
const struct vkd3d_push_constant_buffer *cb = &compiler->push_constants[i];
if (!cb->reg.type)
@ -2666,7 +2652,7 @@ static void vkd3d_dxbc_compiler_emit_push_constants(struct vkd3d_dxbc_compiler *
var_id = vkd3d_spirv_build_op_variable(builder, &builder->global_stream,
pointer_type_id, storage_class, 0);
for (i = 0, j = 0; i < compiler->push_constant_count; ++i)
for (i = 0, j = 0; i < compiler->shader_interface.push_constant_count; ++i)
{
const struct vkd3d_push_constant_buffer *cb = &compiler->push_constants[i];
if (!cb->reg.type)

View File

@ -20,8 +20,7 @@
HRESULT vkd3d_shader_compile_dxbc(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_code *spirv, uint32_t compiler_options,
const struct vkd3d_shader_resource_binding *bindings, unsigned int binding_count,
const struct vkd3d_shader_push_constant *push_constants, unsigned int push_constant_count)
const struct vkd3d_shader_interface *shader_interface)
{
struct vkd3d_dxbc_compiler *spirv_compiler;
struct vkd3d_shader_version shader_version;
@ -32,10 +31,8 @@ HRESULT vkd3d_shader_compile_dxbc(const struct vkd3d_shader_code *dxbc,
HRESULT hr;
bool ret;
TRACE("dxbc {%p, %zu}, spirv %p, compiler_options %#x, bindings %p, binding_count %u, "
"push_constants %p, push_constant_count %u.\n",
dxbc->code, dxbc->size, spirv, compiler_options, bindings, binding_count,
push_constants, push_constant_count);
TRACE("dxbc {%p, %zu}, spirv %p, compiler_options %#x, shader_interface %p.\n",
dxbc->code, dxbc->size, spirv, compiler_options, shader_interface);
if (FAILED(hr = shader_extract_from_dxbc(dxbc->code, dxbc->size, &shader_desc)))
{
@ -54,7 +51,7 @@ HRESULT vkd3d_shader_compile_dxbc(const struct vkd3d_shader_code *dxbc,
shader_sm4_read_header(parser_data, &ptr, &shader_version);
if (!(spirv_compiler = vkd3d_dxbc_compiler_create(&shader_version, &shader_desc,
compiler_options, bindings, binding_count, push_constants, push_constant_count)))
compiler_options, shader_interface)))
{
ERR("Failed to create DXBC compiler.\n");
shader_sm4_free(parser_data);

View File

@ -823,8 +823,7 @@ struct vkd3d_dxbc_compiler;
struct vkd3d_dxbc_compiler *vkd3d_dxbc_compiler_create(const struct vkd3d_shader_version *shader_version,
const struct vkd3d_shader_desc *shader_desc, uint32_t compiler_options,
const struct vkd3d_shader_resource_binding *bindings, unsigned int binding_count,
const struct vkd3d_shader_push_constant *constants, unsigned int constant_count) DECLSPEC_HIDDEN;
const struct vkd3d_shader_interface *shader_interface) DECLSPEC_HIDDEN;
void vkd3d_dxbc_compiler_handle_instruction(struct vkd3d_dxbc_compiler *compiler,
const struct vkd3d_shader_instruction *instruction) DECLSPEC_HIDDEN;
bool vkd3d_dxbc_compiler_generate_spirv(struct vkd3d_dxbc_compiler *compiler,

View File

@ -599,8 +599,8 @@ static void d3d12_root_signature_append_vk_binding(struct d3d12_root_signature *
root_signature->descriptor_mapping[i].type = descriptor_type;
root_signature->descriptor_mapping[i].register_index = register_idx;
root_signature->descriptor_mapping[i].is_buffer = buffer_descriptor;
root_signature->descriptor_mapping[i].descriptor_set = context->set_index;
root_signature->descriptor_mapping[i].binding = context->descriptor_binding++;
root_signature->descriptor_mapping[i].binding.set = context->set_index;
root_signature->descriptor_mapping[i].binding.binding = context->descriptor_binding++;
}
static uint32_t d3d12_root_signature_assign_vk_bindings(struct d3d12_root_signature *root_signature,
@ -1115,9 +1115,13 @@ static HRESULT create_shader_stage(struct d3d12_device *device,
else
{
struct vkd3d_shader_code dxbc = {code->pShaderBytecode, code->BytecodeLength};
if (FAILED(hr = vkd3d_shader_compile_dxbc(&dxbc, &spirv, 0,
root_signature->descriptor_mapping, root_signature->descriptor_count,
root_signature->push_constants, root_signature->constant_count)))
struct vkd3d_shader_interface shader_interface;
shader_interface.bindings = root_signature->descriptor_mapping;
shader_interface.binding_count = root_signature->descriptor_count;
shader_interface.push_constants = root_signature->push_constants;
shader_interface.push_constant_count = root_signature->constant_count;
if (FAILED(hr = vkd3d_shader_compile_dxbc(&dxbc, &spirv, 0, &shader_interface)))
{
WARN("Failed to compile shader, hr %#x.\n", hr);
return hr;

View File

@ -162,7 +162,7 @@ int main(int argc, char **argv)
return 1;
}
hr = vkd3d_shader_compile_dxbc(&dxbc, &spirv, options.compiler_options, NULL, 0, NULL, 0);
hr = vkd3d_shader_compile_dxbc(&dxbc, &spirv, options.compiler_options, NULL);
vkd3d_shader_free_shader_code(&dxbc);
if (FAILED(hr))
{