From: Józef Kucia jkucia@codeweavers.com
We would like to allow building libvkd3d-shader as a standalone library without our Direct3D translation layers.
In the long term, it should be possible to build and use libvkd3d-shader without Win32 data types, Vulkan headers and libs.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- include/vkd3d_shader.h | 183 +++++++++++++++++++++++++- libs/vkd3d-shader/dxbc.c | 238 +++++++++++++++++----------------- libs/vkd3d-shader/vkd3d_shader_main.c | 14 +- libs/vkd3d/state.c | 14 +- libs/vkd3d/vkd3d_main.c | 15 ++- 5 files changed, 325 insertions(+), 139 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 48b51898d453..f99d21684b81 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -118,9 +118,186 @@ HRESULT vkd3d_shader_compile_dxbc(const struct vkd3d_shader_code *dxbc, const struct vkd3d_shader_interface *shader_interface); void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *code);
+enum vkd3d_filter +{ + VKD3D_FILTER_MIN_MAG_MIP_POINT = 0x0, + VKD3D_FILTER_MIN_MAG_POINT_MIP_LINEAR = 0x1, + VKD3D_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x4, + VKD3D_FILTER_MIN_POINT_MAG_MIP_LINEAR = 0x5, + VKD3D_FILTER_MIN_LINEAR_MAG_MIP_POINT = 0x10, + VKD3D_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x11, + VKD3D_FILTER_MIN_MAG_LINEAR_MIP_POINT = 0x14, + VKD3D_FILTER_MIN_MAG_MIP_LINEAR = 0x15, + VKD3D_FILTER_ANISOTROPIC = 0x55, + VKD3D_FILTER_COMPARISON_MIN_MAG_MIP_POINT = 0x80, + VKD3D_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR = 0x81, + VKD3D_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x84, + VKD3D_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR = 0x85, + VKD3D_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT = 0x90, + VKD3D_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x91, + VKD3D_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT = 0x94, + VKD3D_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR = 0x95, + VKD3D_FILTER_COMPARISON_ANISOTROPIC = 0xd5, + VKD3D_FILTER_MINIMUM_MIN_MAG_MIP_POINT = 0x100, + VKD3D_FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR = 0x101, + VKD3D_FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x104, + VKD3D_FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR = 0x105, + VKD3D_FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT = 0x110, + VKD3D_FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x111, + VKD3D_FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT = 0x114, + VKD3D_FILTER_MINIMUM_MIN_MAG_MIP_LINEAR = 0x115, + VKD3D_FILTER_MINIMUM_ANISOTROPIC = 0x155, + VKD3D_FILTER_MAXIMUM_MIN_MAG_MIP_POINT = 0x180, + VKD3D_FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR = 0x181, + VKD3D_FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x184, + VKD3D_FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR = 0x185, + VKD3D_FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT = 0x190, + VKD3D_FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x191, + VKD3D_FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT = 0x194, + VKD3D_FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR = 0x195, + VKD3D_FILTER_MAXIMUM_ANISOTROPIC = 0x1d5, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_FILTER), +}; + +enum vkd3d_texture_address_mode +{ + VKD3D_TEXTURE_ADDRESS_MODE_WRAP = 1, + VKD3D_TEXTURE_ADDRESS_MODE_MIRROR = 2, + VKD3D_TEXTURE_ADDRESS_MODE_CLAMP = 3, + VKD3D_TEXTURE_ADDRESS_MODE_BORDER = 4, + VKD3D_TEXTURE_ADDRESS_MODE_MIRROR_ONCE = 5, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_TEXTURE_ADDRESS_MODE), +}; + +enum vkd3d_comparison_func +{ + VKD3D_COMPARISON_FUNC_NEVER = 1, + VKD3D_COMPARISON_FUNC_LESS = 2, + VKD3D_COMPARISON_FUNC_EQUAL = 3, + VKD3D_COMPARISON_FUNC_LESS_EQUAL = 4, + VKD3D_COMPARISON_FUNC_GREATER = 5, + VKD3D_COMPARISON_FUNC_NOT_EQUAL = 6, + VKD3D_COMPARISON_FUNC_GREATER_EQUAL = 7, + VKD3D_COMPARISON_FUNC_ALWAYS = 8, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_COMPARISON_FUNC), +}; + +enum vkd3d_static_border_color +{ + VKD3D_STATIC_BORDER_COLOR_TRANSPARENT_BLACK = 0, + VKD3D_STATIC_BORDER_COLOR_OPAQUE_BLACK = 1, + VKD3D_STATIC_BORDER_COLOR_OPAQUE_WHITE = 2, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_STATIC_BORDER_COLOR), +}; + +struct vkd3d_static_sampler_desc +{ + enum vkd3d_filter filter; + enum vkd3d_texture_address_mode address_u; + enum vkd3d_texture_address_mode address_v; + enum vkd3d_texture_address_mode address_w; + float mip_lod_bias; + unsigned int max_anisotropy; + enum vkd3d_comparison_func comparison_func; + enum vkd3d_static_border_color border_color; + float min_lod; + float max_lod; + unsigned int shader_register; + unsigned int register_space; + enum vkd3d_shader_visibility shader_visibility; +}; + +enum vkd3d_descriptor_range_type +{ + VKD3D_DESCRIPTOR_RANGE_TYPE_SRV = 0, + VKD3D_DESCRIPTOR_RANGE_TYPE_UAV = 1, + VKD3D_DESCRIPTOR_RANGE_TYPE_CBV = 2, + VKD3D_DESCRIPTOR_RANGE_TYPE_SAMPLER = 3, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_DESCRIPTOR_RANGE_TYPE), +}; + +struct vkd3d_descriptor_range +{ + enum vkd3d_descriptor_range_type range_type; + unsigned int descriptor_count; + unsigned int base_shader_register; + unsigned int register_space; + unsigned int descriptor_table_offset; +}; + +struct vkd3d_root_descriptor_table +{ + unsigned int descriptor_range_count; + const struct vkd3d_descriptor_range *descriptor_ranges; +}; + +struct vkd3d_root_constants +{ + unsigned int shader_register; + unsigned int register_space; + unsigned int value_count; +}; + +struct vkd3d_root_descriptor +{ + unsigned int shader_register; + unsigned int register_space; +}; + +enum vkd3d_root_parameter_type +{ + VKD3D_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE = 0, + VKD3D_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS = 1, + VKD3D_ROOT_PARAMETER_TYPE_CBV = 2, + VKD3D_ROOT_PARAMETER_TYPE_SRV = 3, + VKD3D_ROOT_PARAMETER_TYPE_UAV = 4, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_ROOT_PARAMETER_TYPE), +}; + +struct vkd3d_root_parameter +{ + enum vkd3d_root_parameter_type parameter_type; + union + { + struct vkd3d_root_descriptor_table descriptor_table; + struct vkd3d_root_constants constants; + struct vkd3d_root_descriptor descriptor; + } u; + enum vkd3d_shader_visibility shader_visibility; +}; + +enum vkd3d_root_signature_flags +{ + VKD3D_ROOT_SIGNATURE_FLAG_NONE = 0x0, + VKD3D_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT = 0x1, + VKD3D_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS = 0x2, + VKD3D_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS = 0x4, + VKD3D_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS = 0x8, + VKD3D_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS = 0x10, + VKD3D_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS = 0x20, + VKD3D_ROOT_SIGNATURE_FLAG_ALLOW_STREAM_OUTPUT = 0x40, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_ROOT_SIGNATURE_FLAGS), +}; + +struct vkd3d_root_signature_desc +{ + unsigned int parameter_count; + const struct vkd3d_root_parameter *parameters; + unsigned int static_sampler_count; + const struct vkd3d_static_sampler_desc *static_samplers; + enum vkd3d_root_signature_flags flags; +}; + HRESULT vkd3d_shader_parse_root_signature(const struct vkd3d_shader_code *dxbc, - D3D12_ROOT_SIGNATURE_DESC *root_signature); -void vkd3d_shader_free_root_signature(D3D12_ROOT_SIGNATURE_DESC *root_signature); + struct vkd3d_root_signature_desc *root_signature); +void vkd3d_shader_free_root_signature(struct vkd3d_root_signature_desc *root_signature);
enum vkd3d_root_signature_version { @@ -129,7 +306,7 @@ enum vkd3d_root_signature_version VKD3D_FORCE_32_BIT_ENUM(VKD3D_ROOT_SIGNATURE_VERSION), };
-HRESULT vkd3d_shader_serialize_root_signature(const D3D12_ROOT_SIGNATURE_DESC *root_signature, +HRESULT vkd3d_shader_serialize_root_signature(const struct vkd3d_root_signature_desc *root_signature, enum vkd3d_root_signature_version version, struct vkd3d_shader_code *dxbc);
#define VKD3D_SHADER_MAX_UNORDERED_ACCESS_VIEWS 8 diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index 8f6147a6a46d..ab18602980d5 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -2064,7 +2064,7 @@ HRESULT shader_extract_from_dxbc(const void *dxbc, SIZE_T dxbc_length, }
static HRESULT shader_parse_descriptor_ranges(const char *data, DWORD data_size, - DWORD offset, DWORD count, D3D12_DESCRIPTOR_RANGE *ranges) + DWORD offset, DWORD count, struct vkd3d_descriptor_range *ranges) { const char *ptr; unsigned int i; @@ -2078,26 +2078,26 @@ static HRESULT shader_parse_descriptor_ranges(const char *data, DWORD data_size,
for (i = 0; i < count; ++i) { - read_dword(&ptr, &ranges[i].RangeType); - read_dword(&ptr, &ranges[i].NumDescriptors); - read_dword(&ptr, &ranges[i].BaseShaderRegister); - read_dword(&ptr, &ranges[i].RegisterSpace); - read_dword(&ptr, &ranges[i].OffsetInDescriptorsFromTableStart); + read_dword(&ptr, &ranges[i].range_type); + read_dword(&ptr, &ranges[i].descriptor_count); + read_dword(&ptr, &ranges[i].base_shader_register); + read_dword(&ptr, &ranges[i].register_space); + read_dword(&ptr, &ranges[i].descriptor_table_offset);
TRACE("Type %#x, descriptor count %u, base shader register %u, " "register space %u, offset %u.\n", - ranges[i].RangeType, ranges[i].NumDescriptors, - ranges[i].BaseShaderRegister, ranges[i].RegisterSpace, - ranges[i].OffsetInDescriptorsFromTableStart); + ranges[i].range_type, ranges[i].descriptor_count, + ranges[i].base_shader_register, ranges[i].register_space, + ranges[i].descriptor_table_offset); }
return S_OK; }
static HRESULT shader_parse_descriptor_table(const char *data, DWORD data_size, - DWORD offset, D3D12_ROOT_DESCRIPTOR_TABLE *table) + DWORD offset, struct vkd3d_root_descriptor_table *table) { - D3D12_DESCRIPTOR_RANGE *ranges; + struct vkd3d_descriptor_range *ranges; const char *ptr; DWORD count;
@@ -2113,16 +2113,16 @@ static HRESULT shader_parse_descriptor_table(const char *data, DWORD data_size,
TRACE("Descriptor range count %u.\n", count);
- table->NumDescriptorRanges = count; + table->descriptor_range_count = count;
if (!(ranges = vkd3d_calloc(count, sizeof(*ranges)))) return E_OUTOFMEMORY; - table->pDescriptorRanges = ranges; + table->descriptor_ranges = ranges; return shader_parse_descriptor_ranges(data, data_size, offset, count, ranges); }
static HRESULT shader_parse_root_constants(const char *data, DWORD data_size, - DWORD offset, D3D12_ROOT_CONSTANTS *constants) + DWORD offset, struct vkd3d_root_constants *constants) { const char *ptr;
@@ -2133,18 +2133,18 @@ static HRESULT shader_parse_root_constants(const char *data, DWORD data_size, } ptr = &data[offset];
- read_dword(&ptr, &constants->ShaderRegister); - read_dword(&ptr, &constants->RegisterSpace); - read_dword(&ptr, &constants->Num32BitValues); + read_dword(&ptr, &constants->shader_register); + read_dword(&ptr, &constants->register_space); + read_dword(&ptr, &constants->value_count);
TRACE("Shader register %u, register space %u, 32-bit value count %u.\n", - constants->ShaderRegister, constants->RegisterSpace, constants->Num32BitValues); + constants->shader_register, constants->register_space, constants->value_count);
return S_OK; }
static HRESULT shader_parse_root_descriptor(const char *data, DWORD data_size, - DWORD offset, D3D12_ROOT_DESCRIPTOR *descriptor) + DWORD offset, struct vkd3d_root_descriptor *descriptor) { const char *ptr;
@@ -2155,17 +2155,17 @@ static HRESULT shader_parse_root_descriptor(const char *data, DWORD data_size, } ptr = &data[offset];
- read_dword(&ptr, &descriptor->ShaderRegister); - read_dword(&ptr, &descriptor->RegisterSpace); + read_dword(&ptr, &descriptor->shader_register); + read_dword(&ptr, &descriptor->register_space);
TRACE("Shader register %u, register space %u.\n", - descriptor->ShaderRegister, descriptor->RegisterSpace); + descriptor->shader_register, descriptor->register_space);
return S_OK; }
static HRESULT shader_parse_root_parameters(const char *data, DWORD data_size, - DWORD offset, DWORD count, D3D12_ROOT_PARAMETER *parameters) + DWORD offset, DWORD count, struct vkd3d_root_parameter *parameters) { const char *ptr; unsigned int i; @@ -2180,28 +2180,28 @@ static HRESULT shader_parse_root_parameters(const char *data, DWORD data_size,
for (i = 0; i < count; ++i) { - read_dword(&ptr, ¶meters[i].ParameterType); - read_dword(&ptr, ¶meters[i].ShaderVisibility); + read_dword(&ptr, ¶meters[i].parameter_type); + read_dword(&ptr, ¶meters[i].shader_visibility); read_dword(&ptr, &offset);
TRACE("Type %#x, shader visibility %#x.\n", - parameters[i].ParameterType, parameters[i].ShaderVisibility); + parameters[i].parameter_type, parameters[i].shader_visibility);
- switch (parameters[i].ParameterType) + switch (parameters[i].parameter_type) { - case D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE: - hr = shader_parse_descriptor_table(data, data_size, offset, ¶meters[i].u.DescriptorTable); + case VKD3D_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE: + hr = shader_parse_descriptor_table(data, data_size, offset, ¶meters[i].u.descriptor_table); break; - case D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS: - hr = shader_parse_root_constants(data, data_size, offset, ¶meters[i].u.Constants); + case VKD3D_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS: + hr = shader_parse_root_constants(data, data_size, offset, ¶meters[i].u.constants); break; - case D3D12_ROOT_PARAMETER_TYPE_CBV: - case D3D12_ROOT_PARAMETER_TYPE_SRV: - case D3D12_ROOT_PARAMETER_TYPE_UAV: - hr = shader_parse_root_descriptor(data, data_size, offset, ¶meters[i].u.Descriptor); + case VKD3D_ROOT_PARAMETER_TYPE_CBV: + case VKD3D_ROOT_PARAMETER_TYPE_SRV: + case VKD3D_ROOT_PARAMETER_TYPE_UAV: + hr = shader_parse_root_descriptor(data, data_size, offset, ¶meters[i].u.descriptor); break; default: - FIXME("Unrecognized type %#x.\n", parameters[i].ParameterType); + FIXME("Unrecognized type %#x.\n", parameters[i].parameter_type); return E_INVALIDARG; }
@@ -2213,7 +2213,7 @@ static HRESULT shader_parse_root_parameters(const char *data, DWORD data_size, }
static HRESULT shader_parse_static_samplers(const char *data, DWORD data_size, - DWORD offset, DWORD count, D3D12_STATIC_SAMPLER_DESC *sampler_descs) + DWORD offset, DWORD count, struct vkd3d_static_sampler_desc *sampler_descs) { const char *ptr; unsigned int i; @@ -2227,26 +2227,26 @@ static HRESULT shader_parse_static_samplers(const char *data, DWORD data_size,
for (i = 0; i < count; ++i) { - read_dword(&ptr, &sampler_descs[i].Filter); - read_dword(&ptr, &sampler_descs[i].AddressU); - read_dword(&ptr, &sampler_descs[i].AddressV); - read_dword(&ptr, &sampler_descs[i].AddressW); - read_float(&ptr, &sampler_descs[i].MipLODBias); - read_dword(&ptr, &sampler_descs[i].MaxAnisotropy); - read_dword(&ptr, &sampler_descs[i].ComparisonFunc); - read_dword(&ptr, &sampler_descs[i].BorderColor); - read_float(&ptr, &sampler_descs[i].MinLOD); - read_float(&ptr, &sampler_descs[i].MaxLOD); - read_dword(&ptr, &sampler_descs[i].ShaderRegister); - read_dword(&ptr, &sampler_descs[i].RegisterSpace); - read_dword(&ptr, &sampler_descs[i].ShaderVisibility); + read_dword(&ptr, &sampler_descs[i].filter); + read_dword(&ptr, &sampler_descs[i].address_u); + read_dword(&ptr, &sampler_descs[i].address_v); + read_dword(&ptr, &sampler_descs[i].address_w); + read_float(&ptr, &sampler_descs[i].mip_lod_bias); + read_dword(&ptr, &sampler_descs[i].max_anisotropy); + read_dword(&ptr, &sampler_descs[i].comparison_func); + read_dword(&ptr, &sampler_descs[i].border_color); + read_float(&ptr, &sampler_descs[i].min_lod); + read_float(&ptr, &sampler_descs[i].max_lod); + read_dword(&ptr, &sampler_descs[i].shader_register); + read_dword(&ptr, &sampler_descs[i].register_space); + read_dword(&ptr, &sampler_descs[i].shader_visibility); }
return S_OK; }
static HRESULT shader_parse_root_signature(const char *data, DWORD data_size, - D3D12_ROOT_SIGNATURE_DESC *desc) + struct vkd3d_root_signature_desc *desc) { const char *ptr = data; DWORD count, offset; @@ -2264,13 +2264,13 @@ static HRESULT shader_parse_root_signature(const char *data, DWORD data_size, read_dword(&ptr, &offset); TRACE("Parameter count %u, offset %u.\n", count, offset);
- desc->NumParameters = count; - if (desc->NumParameters) + desc->parameter_count = count; + if (desc->parameter_count) { - D3D12_ROOT_PARAMETER *parameters; - if (!(parameters = vkd3d_calloc(desc->NumParameters, sizeof(*parameters)))) + struct vkd3d_root_parameter *parameters; + if (!(parameters = vkd3d_calloc(desc->parameter_count, sizeof(*parameters)))) return E_OUTOFMEMORY; - desc->pParameters = parameters; + desc->parameters = parameters; if (FAILED(hr = shader_parse_root_parameters(data, data_size, offset, count, parameters))) return hr; } @@ -2279,26 +2279,26 @@ static HRESULT shader_parse_root_signature(const char *data, DWORD data_size, read_dword(&ptr, &offset); TRACE("Static sampler count %u, offset %u.\n", count, offset);
- desc->NumStaticSamplers = count; - if (desc->NumStaticSamplers) + desc->static_sampler_count = count; + if (desc->static_sampler_count) { - D3D12_STATIC_SAMPLER_DESC *samplers; - if (!(samplers = vkd3d_calloc(desc->NumStaticSamplers, sizeof(*samplers)))) + struct vkd3d_static_sampler_desc *samplers; + if (!(samplers = vkd3d_calloc(desc->static_sampler_count, sizeof(*samplers)))) return E_OUTOFMEMORY; - desc->pStaticSamplers = samplers; + desc->static_samplers = samplers; if (FAILED(hr = shader_parse_static_samplers(data, data_size, offset, count, samplers))) return hr; }
- read_dword(&ptr, &desc->Flags); - TRACE("Flags %#x.\n", desc->Flags); + read_dword(&ptr, &desc->flags); + TRACE("Flags %#x.\n", desc->flags);
return S_OK; }
static HRESULT rts0_handler(const char *data, DWORD data_size, DWORD tag, void *context) { - D3D12_ROOT_SIGNATURE_DESC *desc = context; + struct vkd3d_root_signature_desc *desc = context;
if (tag != TAG_RTS0) return S_OK; @@ -2307,7 +2307,7 @@ static HRESULT rts0_handler(const char *data, DWORD data_size, DWORD tag, void * }
HRESULT vkd3d_shader_parse_root_signature(const struct vkd3d_shader_code *dxbc, - D3D12_ROOT_SIGNATURE_DESC *root_signature) + struct vkd3d_root_signature_desc *root_signature) { HRESULT hr;
@@ -2400,22 +2400,22 @@ static HRESULT shader_write_root_signature_header(struct root_signature_writer_c }
static HRESULT shader_write_descriptor_ranges(struct root_signature_writer_context *context, - const D3D12_ROOT_DESCRIPTOR_TABLE *table) + const struct vkd3d_root_descriptor_table *table) { - const D3D12_DESCRIPTOR_RANGE *ranges = table->pDescriptorRanges; + const struct vkd3d_descriptor_range *ranges = table->descriptor_ranges; unsigned int i;
- for (i = 0; i < table->NumDescriptorRanges; ++i) + for (i = 0; i < table->descriptor_range_count; ++i) { - if (!write_dword(context, ranges[i].RangeType)) + if (!write_dword(context, ranges[i].range_type)) return E_OUTOFMEMORY; - if (!write_dword(context, ranges[i].NumDescriptors)) + if (!write_dword(context, ranges[i].descriptor_count)) return E_OUTOFMEMORY; - if (!write_dword(context, ranges[i].BaseShaderRegister)) + if (!write_dword(context, ranges[i].base_shader_register)) return E_OUTOFMEMORY; - if (!write_dword(context, ranges[i].RegisterSpace)) + if (!write_dword(context, ranges[i].register_space)) return E_OUTOFMEMORY; - if (!write_dword(context, ranges[i].OffsetInDescriptorsFromTableStart)) + if (!write_dword(context, ranges[i].descriptor_table_offset)) return E_OUTOFMEMORY; }
@@ -2423,9 +2423,9 @@ static HRESULT shader_write_descriptor_ranges(struct root_signature_writer_conte }
static HRESULT shader_write_descriptor_table(struct root_signature_writer_context *context, - const D3D12_ROOT_DESCRIPTOR_TABLE *table) + const struct vkd3d_root_descriptor_table *table) { - if (!write_dword(context, table->NumDescriptorRanges)) + if (!write_dword(context, table->descriptor_range_count)) return E_OUTOFMEMORY; if (!write_dword(context, get_chunk_offset(context) + sizeof(DWORD))) /* offset */ return E_OUTOFMEMORY; @@ -2434,67 +2434,67 @@ static HRESULT shader_write_descriptor_table(struct root_signature_writer_contex }
static HRESULT shader_write_root_constants(struct root_signature_writer_context *context, - const D3D12_ROOT_CONSTANTS *constants) + const struct vkd3d_root_constants *constants) { - if (!write_dword(context, constants->ShaderRegister)) + if (!write_dword(context, constants->shader_register)) return E_OUTOFMEMORY; - if (!write_dword(context, constants->RegisterSpace)) + if (!write_dword(context, constants->register_space)) return E_OUTOFMEMORY; - if (!write_dword(context, constants->Num32BitValues)) + if (!write_dword(context, constants->value_count)) return E_OUTOFMEMORY;
return S_OK; }
static HRESULT shader_write_root_descriptor(struct root_signature_writer_context *context, - const D3D12_ROOT_DESCRIPTOR *descriptor) + const struct vkd3d_root_descriptor *descriptor) { - if (!write_dword(context, descriptor->ShaderRegister)) + if (!write_dword(context, descriptor->shader_register)) return E_OUTOFMEMORY; - if (!write_dword(context, descriptor->RegisterSpace)) + if (!write_dword(context, descriptor->register_space)) return E_OUTOFMEMORY;
return S_OK; }
static HRESULT shader_write_root_parameters(struct root_signature_writer_context *context, - const D3D12_ROOT_SIGNATURE_DESC *desc) + const struct vkd3d_root_signature_desc *desc) { - const D3D12_ROOT_PARAMETER *parameters = desc->pParameters; + const struct vkd3d_root_parameter *parameters = desc->parameters; size_t parameters_position; unsigned int i; HRESULT hr;
parameters_position = context->position; - for (i = 0; i < desc->NumParameters; ++i) + for (i = 0; i < desc->parameter_count; ++i) { - if (!write_dword(context, parameters[i].ParameterType)) + if (!write_dword(context, parameters[i].parameter_type)) return E_OUTOFMEMORY; - if (!write_dword(context, parameters[i].ShaderVisibility)) + if (!write_dword(context, parameters[i].shader_visibility)) return E_OUTOFMEMORY; if (!write_dword(context, 0xffffffff)) /* offset */ return E_OUTOFMEMORY; }
- for (i = 0; i < desc->NumParameters; ++i) + for (i = 0; i < desc->parameter_count; ++i) { context->data[parameters_position + 3 * i + 2] = get_chunk_offset(context); /* offset */
- switch (parameters[i].ParameterType) + switch (parameters[i].parameter_type) { - case D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE: - hr = shader_write_descriptor_table(context, ¶meters[i].u.DescriptorTable); + case VKD3D_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE: + hr = shader_write_descriptor_table(context, ¶meters[i].u.descriptor_table); break; - case D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS: - hr = shader_write_root_constants(context, ¶meters[i].u.Constants); + case VKD3D_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS: + hr = shader_write_root_constants(context, ¶meters[i].u.constants); break; - case D3D12_ROOT_PARAMETER_TYPE_CBV: - case D3D12_ROOT_PARAMETER_TYPE_SRV: - case D3D12_ROOT_PARAMETER_TYPE_UAV: - hr = shader_write_root_descriptor(context, ¶meters[i].u.Descriptor); + case VKD3D_ROOT_PARAMETER_TYPE_CBV: + case VKD3D_ROOT_PARAMETER_TYPE_SRV: + case VKD3D_ROOT_PARAMETER_TYPE_UAV: + hr = shader_write_root_descriptor(context, ¶meters[i].u.descriptor); break; default: - FIXME("Unrecognized type %#x.\n", parameters[i].ParameterType); + FIXME("Unrecognized type %#x.\n", parameters[i].parameter_type); return E_INVALIDARG; }
@@ -2506,38 +2506,38 @@ static HRESULT shader_write_root_parameters(struct root_signature_writer_context }
static HRESULT shader_write_static_samplers(struct root_signature_writer_context *context, - const D3D12_ROOT_SIGNATURE_DESC *desc) + const struct vkd3d_root_signature_desc *desc) { - const D3D12_STATIC_SAMPLER_DESC *samplers = desc->pStaticSamplers; + const struct vkd3d_static_sampler_desc *samplers = desc->static_samplers; unsigned int i;
- for (i = 0; i < desc->NumStaticSamplers; ++i) + for (i = 0; i < desc->static_sampler_count; ++i) { - if (!write_dword(context, samplers[i].Filter)) + if (!write_dword(context, samplers[i].filter)) return E_OUTOFMEMORY; - if (!write_dword(context, samplers[i].AddressU)) + if (!write_dword(context, samplers[i].address_u)) return E_OUTOFMEMORY; - if (!write_dword(context, samplers[i].AddressV)) + if (!write_dword(context, samplers[i].address_v)) return E_OUTOFMEMORY; - if (!write_dword(context, samplers[i].AddressW)) + if (!write_dword(context, samplers[i].address_w)) return E_OUTOFMEMORY; - if (!write_float(context, samplers[i].MipLODBias)) + if (!write_float(context, samplers[i].mip_lod_bias)) return E_OUTOFMEMORY; - if (!write_dword(context, samplers[i].MaxAnisotropy)) + if (!write_dword(context, samplers[i].max_anisotropy)) return E_OUTOFMEMORY; - if (!write_dword(context, samplers[i].ComparisonFunc)) + if (!write_dword(context, samplers[i].comparison_func)) return E_OUTOFMEMORY; - if (!write_dword(context, samplers[i].BorderColor)) + if (!write_dword(context, samplers[i].border_color)) return E_OUTOFMEMORY; - if (!write_float(context, samplers[i].MinLOD)) + if (!write_float(context, samplers[i].min_lod)) return E_OUTOFMEMORY; - if (!write_float(context, samplers[i].MaxLOD)) + if (!write_float(context, samplers[i].max_lod)) return E_OUTOFMEMORY; - if (!write_dword(context, samplers[i].ShaderRegister)) + if (!write_dword(context, samplers[i].shader_register)) return E_OUTOFMEMORY; - if (!write_dword(context, samplers[i].RegisterSpace)) + if (!write_dword(context, samplers[i].register_space)) return E_OUTOFMEMORY; - if (!write_dword(context, samplers[i].ShaderVisibility)) + if (!write_dword(context, samplers[i].shader_visibility)) return E_OUTOFMEMORY; }
@@ -2545,7 +2545,7 @@ static HRESULT shader_write_static_samplers(struct root_signature_writer_context }
static HRESULT shader_write_root_signature(struct root_signature_writer_context *context, - const D3D12_ROOT_SIGNATURE_DESC *desc) + const struct vkd3d_root_signature_desc *desc) { size_t samplers_offset_position; HRESULT hr; @@ -2553,18 +2553,18 @@ static HRESULT shader_write_root_signature(struct root_signature_writer_context if (!write_dword(context, 0x00000001)) return E_OUTOFMEMORY;
- if (!write_dword(context, desc->NumParameters)) + if (!write_dword(context, desc->parameter_count)) return E_OUTOFMEMORY; if (!write_dword(context, get_chunk_offset(context) + 4 * sizeof(DWORD))) /* offset */ return E_OUTOFMEMORY;
- if (!write_dword(context, desc->NumStaticSamplers)) + if (!write_dword(context, desc->static_sampler_count)) return E_OUTOFMEMORY; samplers_offset_position = context->position; if (!write_dword(context, 0xffffffff)) /* offset */ return E_OUTOFMEMORY;
- if (!write_dword(context, desc->Flags)) + if (!write_dword(context, desc->flags)) return E_OUTOFMEMORY;
if (FAILED(hr = shader_write_root_parameters(context, desc))) @@ -2574,7 +2574,7 @@ static HRESULT shader_write_root_signature(struct root_signature_writer_context return shader_write_static_samplers(context, desc); }
-HRESULT vkd3d_shader_serialize_root_signature(const D3D12_ROOT_SIGNATURE_DESC *root_signature, +HRESULT vkd3d_shader_serialize_root_signature(const struct vkd3d_root_signature_desc *root_signature, enum vkd3d_root_signature_version version, struct vkd3d_shader_code *dxbc) { struct root_signature_writer_context context; diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index bf1a3916888d..3578b053df8c 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -200,19 +200,19 @@ void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *shader_code) vkd3d_free((void *)shader_code->code); }
-void vkd3d_shader_free_root_signature(D3D12_ROOT_SIGNATURE_DESC *root_signature) +void vkd3d_shader_free_root_signature(struct vkd3d_root_signature_desc *root_signature) { unsigned int i;
- for (i = 0; i < root_signature->NumParameters; ++i) + for (i = 0; i < root_signature->parameter_count; ++i) { - const D3D12_ROOT_PARAMETER *parameter = &root_signature->pParameters[i]; + const struct vkd3d_root_parameter *parameter = &root_signature->parameters[i];
- if (parameter->ParameterType == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE) - vkd3d_free((void *)parameter->u.DescriptorTable.pDescriptorRanges); + if (parameter->parameter_type == VKD3D_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE) + vkd3d_free((void *)parameter->u.descriptor_table.descriptor_ranges); } - vkd3d_free((void *)root_signature->pParameters); - vkd3d_free((void *)root_signature->pStaticSamplers); + vkd3d_free((void *)root_signature->parameters); + vkd3d_free((void *)root_signature->static_samplers);
memset(root_signature, 0, sizeof(*root_signature)); } diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 6bbba1bb7859..befc44d6aee6 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -1006,11 +1006,15 @@ HRESULT d3d12_root_signature_create(struct d3d12_device *device, const void *bytecode, size_t bytecode_length, struct d3d12_root_signature **root_signature) { const struct vkd3d_shader_code dxbc = {bytecode, bytecode_length}; - D3D12_ROOT_SIGNATURE_DESC root_signature_desc; + union + { + D3D12_ROOT_SIGNATURE_DESC d3d12; + struct vkd3d_root_signature_desc vkd3d; + } root_signature_desc; struct d3d12_root_signature *object; HRESULT hr;
- if (FAILED(hr = vkd3d_shader_parse_root_signature(&dxbc, &root_signature_desc))) + if (FAILED(hr = vkd3d_shader_parse_root_signature(&dxbc, &root_signature_desc.vkd3d))) { WARN("Failed to parse root signature, hr %#x.\n", hr); return hr; @@ -1018,12 +1022,12 @@ HRESULT d3d12_root_signature_create(struct d3d12_device *device,
if (!(object = vkd3d_malloc(sizeof(*object)))) { - vkd3d_shader_free_root_signature(&root_signature_desc); + vkd3d_shader_free_root_signature(&root_signature_desc.vkd3d); return E_OUTOFMEMORY; }
- hr = d3d12_root_signature_init(object, device, &root_signature_desc); - vkd3d_shader_free_root_signature(&root_signature_desc); + hr = d3d12_root_signature_init(object, device, &root_signature_desc.d3d12); + vkd3d_shader_free_root_signature(&root_signature_desc.vkd3d); if (FAILED(hr)) { vkd3d_free(object); diff --git a/libs/vkd3d/vkd3d_main.c b/libs/vkd3d/vkd3d_main.c index 7dd7a1d915ac..d4d660dc727d 100644 --- a/libs/vkd3d/vkd3d_main.c +++ b/libs/vkd3d/vkd3d_main.c @@ -79,7 +79,11 @@ struct d3d12_root_signature_deserializer ID3D12RootSignatureDeserializer ID3D12RootSignatureDeserializer_iface; LONG refcount;
- D3D12_ROOT_SIGNATURE_DESC desc; + union + { + D3D12_ROOT_SIGNATURE_DESC d3d12; + struct vkd3d_root_signature_desc vkd3d; + } desc; };
static struct d3d12_root_signature_deserializer *impl_from_ID3D12RootSignatureDeserializer( @@ -128,7 +132,7 @@ static ULONG STDMETHODCALLTYPE d3d12_root_signature_deserializer_Release(ID3D12R
if (!refcount) { - vkd3d_shader_free_root_signature(&deserializer->desc); + vkd3d_shader_free_root_signature(&deserializer->desc.vkd3d); vkd3d_free(deserializer); }
@@ -142,7 +146,7 @@ static const D3D12_ROOT_SIGNATURE_DESC * STDMETHODCALLTYPE d3d12_root_signature_
TRACE("iface %p.\n", iface);
- return &deserializer->desc; + return &deserializer->desc.d3d12; }
static const struct ID3D12RootSignatureDeserializerVtbl d3d12_root_signature_deserializer_vtbl = @@ -163,7 +167,7 @@ static HRESULT d3d12_root_signature_deserializer_init(struct d3d12_root_signatur deserializer->ID3D12RootSignatureDeserializer_iface.lpVtbl = &d3d12_root_signature_deserializer_vtbl; deserializer->refcount = 1;
- if (FAILED(hr = vkd3d_shader_parse_root_signature(dxbc, &deserializer->desc))) + if (FAILED(hr = vkd3d_shader_parse_root_signature(dxbc, &deserializer->desc.vkd3d))) { WARN("Failed to parse root signature, hr %#x.\n", hr); return hr; @@ -331,7 +335,8 @@ HRESULT vkd3d_serialize_root_signature(const D3D12_ROOT_SIGNATURE_DESC *root_sig *error_blob = NULL; }
- if (FAILED(hr = vkd3d_shader_serialize_root_signature(root_signature_desc, + if (FAILED(hr = vkd3d_shader_serialize_root_signature( + (const struct vkd3d_root_signature_desc *)root_signature_desc, (enum vkd3d_root_signature_version)version, &dxbc))) { WARN("Failed to serialize root signature, hr %#x.\n", hr);