mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader: Pass the target info as part of the vkd3d_shader_compile_info structure chain.
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
c4e6657c11
commit
9312979b56
@ -245,6 +245,7 @@ enum vkd3d_shader_spirv_extension
|
||||
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_SPIRV_EXTENSION),
|
||||
};
|
||||
|
||||
/* Extends vkd3d_shader_compile_info. */
|
||||
struct vkd3d_shader_spirv_target_info
|
||||
{
|
||||
enum vkd3d_shader_structure_type type;
|
||||
@ -644,8 +645,7 @@ struct vkd3d_shader_signature
|
||||
#ifndef VKD3D_SHADER_NO_PROTOTYPES
|
||||
|
||||
int vkd3d_shader_compile_dxbc(const struct vkd3d_shader_compile_info *compile_info,
|
||||
struct vkd3d_shader_code *spirv, unsigned int compiler_options,
|
||||
const struct vkd3d_shader_spirv_target_info *target_info);
|
||||
struct vkd3d_shader_code *spirv, unsigned int compiler_options);
|
||||
void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *code);
|
||||
|
||||
int vkd3d_shader_parse_root_signature(const struct vkd3d_shader_code *dxbc,
|
||||
@ -675,8 +675,7 @@ void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature
|
||||
* Function pointer typedefs for vkd3d-shader functions.
|
||||
*/
|
||||
typedef int (*PFN_vkd3d_shader_compile_dxbc)(const struct vkd3d_shader_compile_info *compile_info,
|
||||
struct vkd3d_shader_code *spirv, unsigned int compiler_options,
|
||||
const struct vkd3d_shader_spirv_target_info *target_info);
|
||||
struct vkd3d_shader_code *spirv, unsigned int compiler_options);
|
||||
typedef void (*PFN_vkd3d_shader_free_shader_code)(struct vkd3d_shader_code *code);
|
||||
|
||||
typedef int (*PFN_vkd3d_shader_parse_root_signature)(const struct vkd3d_shader_code *dxbc,
|
||||
|
@ -2125,12 +2125,12 @@ static void vkd3d_dxbc_compiler_emit_initial_declarations(struct vkd3d_dxbc_comp
|
||||
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_compile_info *compile_info,
|
||||
const struct vkd3d_shader_spirv_target_info *target_info,
|
||||
const struct vkd3d_shader_scan_info *scan_info)
|
||||
{
|
||||
const struct vkd3d_shader_signature *patch_constant_signature = &shader_desc->patch_constant_signature;
|
||||
const struct vkd3d_shader_signature *output_signature = &shader_desc->output_signature;
|
||||
const struct vkd3d_shader_interface_info *shader_interface;
|
||||
const struct vkd3d_shader_spirv_target_info *target_info;
|
||||
struct vkd3d_dxbc_compiler *compiler;
|
||||
unsigned int max_element_count;
|
||||
unsigned int i;
|
||||
@ -2140,6 +2140,22 @@ struct vkd3d_dxbc_compiler *vkd3d_dxbc_compiler_create(const struct vkd3d_shader
|
||||
|
||||
memset(compiler, 0, sizeof(*compiler));
|
||||
|
||||
if ((target_info = vkd3d_find_struct(compile_info->next, SPIRV_TARGET_INFO)))
|
||||
{
|
||||
switch (target_info->environment)
|
||||
{
|
||||
case VKD3D_SHADER_SPIRV_ENVIRONMENT_OPENGL_4_5:
|
||||
case VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_0:
|
||||
break;
|
||||
default:
|
||||
WARN("Invalid target environment %#x.\n", target_info->environment);
|
||||
vkd3d_free(compiler);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
compiler->spirv_target_info = target_info;
|
||||
}
|
||||
|
||||
max_element_count = max(output_signature->element_count, patch_constant_signature->element_count);
|
||||
if (!(compiler->output_info = vkd3d_calloc(max_element_count, sizeof(*compiler->output_info))))
|
||||
{
|
||||
@ -2175,7 +2191,6 @@ struct vkd3d_dxbc_compiler *vkd3d_dxbc_compiler_create(const struct vkd3d_shader
|
||||
compiler->push_constants[i].pc = shader_interface->push_constant_buffers[i];
|
||||
}
|
||||
}
|
||||
compiler->spirv_target_info = target_info;
|
||||
|
||||
compiler->scan_info = scan_info;
|
||||
|
||||
|
@ -103,33 +103,8 @@ static void vkd3d_shader_parser_destroy(struct vkd3d_shader_parser *parser)
|
||||
free_shader_desc(&parser->shader_desc);
|
||||
}
|
||||
|
||||
static int vkd3d_shader_validate_spirv_target_info(const struct vkd3d_shader_spirv_target_info *info)
|
||||
{
|
||||
if (!info)
|
||||
return VKD3D_OK;
|
||||
|
||||
if (info->type != VKD3D_SHADER_STRUCTURE_TYPE_SPIRV_TARGET_INFO)
|
||||
{
|
||||
WARN("Invalid structure type %#x.\n", info->type);
|
||||
return VKD3D_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
switch (info->environment)
|
||||
{
|
||||
case VKD3D_SHADER_SPIRV_ENVIRONMENT_OPENGL_4_5:
|
||||
case VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_0:
|
||||
break;
|
||||
default:
|
||||
WARN("Invalid target environment %#x.\n", info->environment);
|
||||
return VKD3D_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
return VKD3D_OK;
|
||||
}
|
||||
|
||||
int vkd3d_shader_compile_dxbc(const struct vkd3d_shader_compile_info *compile_info,
|
||||
struct vkd3d_shader_code *spirv, unsigned int compiler_options,
|
||||
const struct vkd3d_shader_spirv_target_info *info)
|
||||
struct vkd3d_shader_code *spirv, unsigned int compiler_options)
|
||||
{
|
||||
struct vkd3d_shader_instruction instruction;
|
||||
struct vkd3d_dxbc_compiler *spirv_compiler;
|
||||
@ -137,8 +112,8 @@ int vkd3d_shader_compile_dxbc(const struct vkd3d_shader_compile_info *compile_in
|
||||
struct vkd3d_shader_parser parser;
|
||||
int ret;
|
||||
|
||||
TRACE("compile_info %p, spirv %p, compiler_options %#x, info %p.\n",
|
||||
compile_info, spirv, compiler_options, info);
|
||||
TRACE("compile_info %p, spirv %p, compiler_options %#x.\n",
|
||||
compile_info, spirv, compiler_options);
|
||||
|
||||
if (compile_info->type != VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO)
|
||||
{
|
||||
@ -146,9 +121,6 @@ int vkd3d_shader_compile_dxbc(const struct vkd3d_shader_compile_info *compile_in
|
||||
return VKD3D_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if ((ret = vkd3d_shader_validate_spirv_target_info(info)) < 0)
|
||||
return ret;
|
||||
|
||||
scan_info.type = VKD3D_SHADER_STRUCTURE_TYPE_SCAN_INFO;
|
||||
scan_info.next = NULL;
|
||||
if ((ret = vkd3d_shader_scan_dxbc(&compile_info->source, &scan_info)) < 0)
|
||||
@ -163,7 +135,7 @@ int vkd3d_shader_compile_dxbc(const struct vkd3d_shader_compile_info *compile_in
|
||||
vkd3d_shader_trace(parser.data);
|
||||
|
||||
if (!(spirv_compiler = vkd3d_dxbc_compiler_create(&parser.shader_version,
|
||||
&parser.shader_desc, compiler_options, compile_info, info, &scan_info)))
|
||||
&parser.shader_desc, compiler_options, compile_info, &scan_info)))
|
||||
{
|
||||
ERR("Failed to create DXBC compiler.\n");
|
||||
vkd3d_shader_parser_destroy(&parser);
|
||||
|
@ -822,7 +822,6 @@ 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_compile_info *compile_info,
|
||||
const struct vkd3d_shader_spirv_target_info *target_info,
|
||||
const struct vkd3d_shader_scan_info *scan_info) DECLSPEC_HIDDEN;
|
||||
int vkd3d_dxbc_compiler_handle_instruction(struct vkd3d_dxbc_compiler *compiler,
|
||||
const struct vkd3d_shader_instruction *instruction) DECLSPEC_HIDDEN;
|
||||
|
@ -1326,8 +1326,7 @@ struct d3d12_pipeline_state *unsafe_impl_from_ID3D12PipelineState(ID3D12Pipeline
|
||||
|
||||
static HRESULT create_shader_stage(struct d3d12_device *device,
|
||||
struct VkPipelineShaderStageCreateInfo *stage_desc, enum VkShaderStageFlagBits stage,
|
||||
const D3D12_SHADER_BYTECODE *code, const struct vkd3d_shader_interface_info *shader_interface,
|
||||
const struct vkd3d_shader_spirv_target_info *target_info)
|
||||
const D3D12_SHADER_BYTECODE *code, const struct vkd3d_shader_interface_info *shader_interface)
|
||||
{
|
||||
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
|
||||
struct vkd3d_shader_compile_info compile_info;
|
||||
@ -1352,7 +1351,7 @@ static HRESULT create_shader_stage(struct d3d12_device *device,
|
||||
compile_info.source.code = code->pShaderBytecode;
|
||||
compile_info.source.size = code->BytecodeLength;
|
||||
|
||||
if ((ret = vkd3d_shader_compile_dxbc(&compile_info, &spirv, 0, target_info)) < 0)
|
||||
if ((ret = vkd3d_shader_compile_dxbc(&compile_info, &spirv, 0)) < 0)
|
||||
{
|
||||
WARN("Failed to compile shader, vkd3d result %d.\n", ret);
|
||||
return hresult_from_vkd3d_result(ret);
|
||||
@ -1384,7 +1383,7 @@ static HRESULT vkd3d_create_compute_pipeline(struct d3d12_device *device,
|
||||
pipeline_info.pNext = NULL;
|
||||
pipeline_info.flags = 0;
|
||||
if (FAILED(hr = create_shader_stage(device, &pipeline_info.stage,
|
||||
VK_SHADER_STAGE_COMPUTE_BIT, code, shader_interface, NULL)))
|
||||
VK_SHADER_STAGE_COMPUTE_BIT, code, shader_interface)))
|
||||
return hr;
|
||||
pipeline_info.layout = vk_pipeline_layout;
|
||||
pipeline_info.basePipelineHandle = VK_NULL_HANDLE;
|
||||
@ -1996,12 +1995,12 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s
|
||||
VkVertexInputBindingDivisorDescriptionEXT *binding_divisor;
|
||||
const struct vkd3d_vulkan_info *vk_info = &device->vk_info;
|
||||
uint32_t instance_divisors[D3D12_VS_INPUT_REGISTER_COUNT];
|
||||
const struct vkd3d_shader_spirv_target_info *target_info;
|
||||
uint32_t aligned_offsets[D3D12_VS_INPUT_REGISTER_COUNT];
|
||||
struct vkd3d_shader_parameter ps_shader_parameters[1];
|
||||
struct vkd3d_shader_transform_feedback_info xfb_info;
|
||||
struct vkd3d_shader_spirv_target_info ps_target_info;
|
||||
struct vkd3d_shader_interface_info shader_interface;
|
||||
struct vkd3d_shader_spirv_target_info *target_info;
|
||||
const struct d3d12_root_signature *root_signature;
|
||||
struct vkd3d_shader_signature input_signature;
|
||||
bool have_attachment, is_dsv_format_unknown;
|
||||
@ -2157,7 +2156,7 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s
|
||||
if (!desc->PS.pShaderBytecode)
|
||||
{
|
||||
if (FAILED(hr = create_shader_stage(device, &graphics->stages[graphics->stage_count],
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT, &default_ps, NULL, NULL)))
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT, &default_ps, NULL)))
|
||||
goto fail;
|
||||
|
||||
++graphics->stage_count;
|
||||
@ -2298,9 +2297,14 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s
|
||||
}
|
||||
|
||||
shader_interface.next = shader_stages[i].stage == xfb_stage ? &xfb_info : NULL;
|
||||
if (target_info)
|
||||
{
|
||||
target_info->next = shader_interface.next;
|
||||
shader_interface.next = target_info;
|
||||
}
|
||||
|
||||
if (FAILED(hr = create_shader_stage(device, &graphics->stages[graphics->stage_count],
|
||||
shader_stages[i].stage, b, &shader_interface, target_info)))
|
||||
shader_stages[i].stage, b, &shader_interface)))
|
||||
goto fail;
|
||||
|
||||
++graphics->stage_count;
|
||||
|
@ -168,7 +168,7 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = vkd3d_shader_compile_dxbc(&info, &spirv, options.compiler_options, NULL);
|
||||
ret = vkd3d_shader_compile_dxbc(&info, &spirv, options.compiler_options);
|
||||
vkd3d_shader_free_shader_code(&info.source);
|
||||
if (ret < 0)
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ static void test_invalid_shaders(void)
|
||||
info.source.code = ps_break_code;
|
||||
info.source.size = sizeof(ps_break_code);
|
||||
|
||||
rc = vkd3d_shader_compile_dxbc(&info, &spirv, VKD3D_SHADER_STRIP_DEBUG, NULL);
|
||||
rc = vkd3d_shader_compile_dxbc(&info, &spirv, VKD3D_SHADER_STRIP_DEBUG);
|
||||
ok(rc == VKD3D_ERROR_INVALID_SHADER, "Got unexpected error code %d.\n", rc);
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ static void test_vkd3d_shader_pfns(void)
|
||||
compile_info.next = NULL;
|
||||
compile_info.source = vs;
|
||||
|
||||
rc = pfn_vkd3d_shader_compile_dxbc(&compile_info, &spirv, 0, NULL);
|
||||
rc = pfn_vkd3d_shader_compile_dxbc(&compile_info, &spirv, 0);
|
||||
ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc);
|
||||
pfn_vkd3d_shader_free_shader_code(&spirv);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user