vkd3d: Move patch vertex count to meta struct.

Will make it easier to implement for DXIL.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
This commit is contained in:
Hans-Kristian Arntzen 2021-07-07 15:44:12 +02:00
parent d19821ba84
commit 37e8f42f4a
4 changed files with 14 additions and 64 deletions

View File

@ -58,6 +58,7 @@ struct vkd3d_shader_meta
{
vkd3d_shader_hash_t hash;
unsigned int cs_workgroup_size[3]; /* Only contains valid data if uses_subgroup_size is true. */
unsigned int patch_vertex_count; /* Relevant for HS. May be 0, in which case the patch vertex count is not known. */
bool replaced;
bool uses_subgroup_size;
};
@ -624,6 +625,7 @@ struct vkd3d_shader_scan_info
bool has_side_effects;
bool needs_late_zs;
bool discards;
unsigned int patch_vertex_count;
};
enum vkd3d_component_type
@ -729,10 +731,6 @@ int vkd3d_shader_convert_root_signature(struct vkd3d_versioned_root_signature_de
int vkd3d_shader_scan_dxbc(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_scan_info *scan_info);
/* If value cannot be determined, *patch_vertex_count returns 0. */
int vkd3d_shader_scan_patch_vertex_count(const struct vkd3d_shader_code *dxbc,
unsigned int *patch_vertex_count);
int vkd3d_shader_parse_input_signature(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_signature *signature);
struct vkd3d_shader_signature_element *vkd3d_shader_find_signature_element(
@ -788,8 +786,6 @@ typedef int (*PFN_vkd3d_shader_convert_root_signature)(struct vkd3d_versioned_ro
typedef int (*PFN_vkd3d_shader_scan_dxbc)(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_scan_info *scan_info);
typedef int (*PFN_vkd3d_shader_scan_patch_vertex_count)(const struct vkd3d_shader_code *dxbc,
unsigned int *patch_vertex_count);
typedef int (*PFN_vkd3d_shader_parse_input_signature)(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_signature *signature);

View File

@ -494,11 +494,9 @@ int vkd3d_shader_compile_dxil(const struct vkd3d_shader_code *dxbc,
dxil_spv_set_thread_log_callback(vkd3d_dxil_log_callback, NULL);
memset(&spirv->meta, 0, sizeof(spirv->meta));
hash = vkd3d_shader_hash(dxbc);
spirv->meta.replaced = false;
spirv->meta.hash = hash;
spirv->meta.uses_subgroup_size = false;
memset(spirv->meta.cs_workgroup_size, 0, sizeof(spirv->meta.cs_workgroup_size));
if (vkd3d_shader_replace(hash, &spirv->code, &spirv->size))
{
spirv->meta.replaced = true;
@ -827,11 +825,9 @@ int vkd3d_shader_compile_dxil_export(const struct vkd3d_shader_code *dxil,
dxil_spv_set_thread_log_callback(vkd3d_dxil_log_callback, NULL);
memset(&spirv->meta, 0, sizeof(spirv->meta));
hash = vkd3d_shader_hash(dxil);
spirv->meta.replaced = false;
spirv->meta.uses_subgroup_size = false;
spirv->meta.hash = hash;
memset(spirv->meta.cs_workgroup_size, 0, sizeof(spirv->meta.cs_workgroup_size));
demangled_export = vkd3d_dup_demangled_entry_point_ascii(export);
if (demangled_export)
{

View File

@ -343,11 +343,10 @@ int vkd3d_shader_compile_dxbc(const struct vkd3d_shader_code *dxbc,
return vkd3d_shader_compile_dxil(dxbc, spirv, shader_interface_info, compile_args);
}
memset(&spirv->meta, 0, sizeof(spirv->meta));
hash = vkd3d_shader_hash(dxbc);
spirv->meta.replaced = false;
spirv->meta.uses_subgroup_size = false;
spirv->meta.hash = hash;
memset(spirv->meta.cs_workgroup_size, 0, sizeof(spirv->meta.cs_workgroup_size));
if (vkd3d_shader_replace(hash, &spirv->code, &spirv->size))
{
spirv->meta.replaced = true;
@ -362,6 +361,8 @@ int vkd3d_shader_compile_dxbc(const struct vkd3d_shader_code *dxbc,
return ret;
}
spirv->meta.patch_vertex_count = scan_info.patch_vertex_count;
if ((ret = vkd3d_shader_parser_init(&parser, dxbc)) < 0)
{
vkd3d_shader_scan_destroy(&scan_info);
@ -523,6 +524,9 @@ static void vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_info *scan_in
if (instruction->flags & VKD3DSGF_FORCE_EARLY_DEPTH_STENCIL)
scan_info->early_fragment_tests = true;
break;
case VKD3DSIH_DCL_INPUT_CONTROL_POINT_COUNT:
scan_info->patch_vertex_count = instruction->declaration.count;
break;
default:
break;
}
@ -558,49 +562,6 @@ static void vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_info *scan_in
vkd3d_shader_scan_record_uav_counter(scan_info, &instruction->src[0].reg);
}
int vkd3d_shader_scan_patch_vertex_count(const struct vkd3d_shader_code *dxbc,
unsigned int *patch_vertex_count)
{
struct vkd3d_shader_instruction instruction;
struct vkd3d_shader_parser parser;
int ret;
if (shader_is_dxil(dxbc->code, dxbc->size))
{
/* TODO */
*patch_vertex_count = 0;
return VKD3D_OK;
}
else
{
if ((ret = vkd3d_shader_parser_init(&parser, dxbc)) < 0)
return ret;
*patch_vertex_count = 0;
while (!shader_sm4_is_end(parser.data, &parser.ptr))
{
shader_sm4_read_instruction(parser.data, &parser.ptr, &instruction);
if (instruction.handler_idx == VKD3DSIH_INVALID)
{
WARN("Encountered unrecognized or invalid instruction.\n");
vkd3d_shader_parser_destroy(&parser);
return VKD3D_ERROR_INVALID_ARGUMENT;
}
if (instruction.handler_idx == VKD3DSIH_DCL_INPUT_CONTROL_POINT_COUNT)
{
*patch_vertex_count = instruction.declaration.count;
break;
}
}
vkd3d_shader_parser_destroy(&parser);
return VKD3D_OK;
}
}
int vkd3d_shader_scan_dxbc(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_scan_info *scan_info)
{

View File

@ -3210,12 +3210,6 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s
break;
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
if ((ret = vkd3d_shader_scan_patch_vertex_count(&dxbc, &graphics->patch_vertex_count)) < 0)
{
hr = hresult_from_vkd3d_result(ret);
goto fail;
}
/* fallthrough */
case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
if (desc->primitive_topology_type != D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH)
{
@ -3242,6 +3236,9 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s
&graphics->stage_meta[graphics->stage_count])))
goto fail;
if (shader_stages[i].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT)
graphics->patch_vertex_count = graphics->stage_meta[graphics->stage_count].patch_vertex_count;
if (graphics->stage_meta[graphics->stage_count].replaced && device->debug_ring.active)
{
vkd3d_shader_debug_ring_init_spec_constant(device,