Skip to content

Commit 8b36a4f

Browse files
clshortfusecrosire
authored andcommitted
Add workaround for local root signature override and handle empty D3D12 ray tracing pipeline creation (#342)
1 parent 6ef240f commit 8b36a4f

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

source/d3d12/d3d12_device.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,7 @@ bool D3D12Device::invoke_create_and_init_pipeline_layout_event(UINT node_mask, c
26722672
std::vector<std::vector<reshade::api::descriptor_range>> ranges;
26732673
std::vector<reshade::api::descriptor_range_with_static_samplers> ranges_with_static_samplers;
26742674
std::vector<reshade::api::sampler_desc> static_samplers;
2675+
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE;
26752676

26762677
if (const auto part = static_cast<uint32_t *>(const_cast<void *>(
26772678
find_dxbc_part(
@@ -2682,6 +2683,7 @@ bool D3D12Device::invoke_create_and_init_pipeline_layout_event(UINT node_mask, c
26822683
const bool has_pipeline_layout_event = reshade::has_addon_event<reshade::addon_event::create_pipeline_layout>() || reshade::has_addon_event<reshade::addon_event::init_pipeline_layout>();
26832684

26842685
const uint32_t version = part[0];
2686+
flags = static_cast<D3D12_ROOT_SIGNATURE_FLAGS>(part[5]);
26852687

26862688
if (has_pipeline_layout_event &&
26872689
(version == D3D_ROOT_SIGNATURE_VERSION_1_0 || version == D3D_ROOT_SIGNATURE_VERSION_1_1 || version == D3D_ROOT_SIGNATURE_VERSION_1_2))
@@ -2864,7 +2866,7 @@ bool D3D12Device::invoke_create_and_init_pipeline_layout_event(UINT node_mask, c
28642866
reshade::invoke_addon_event<reshade::addon_event::create_pipeline_layout>(this, param_count, param_data) || modified))
28652867
{
28662868
reshade::api::pipeline_layout layout;
2867-
hr = device_impl::create_pipeline_layout(param_count, param_data, &layout) ? S_OK : E_FAIL;
2869+
hr = device_impl::create_pipeline_layout(param_count, param_data, &layout, flags) ? S_OK : E_FAIL;
28682870
root_signature = reinterpret_cast<ID3D12RootSignature *>(layout.handle);
28692871
}
28702872
else

source/d3d12/d3d12_impl_device.cpp

+38-25
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ bool reshade::d3d12::device_impl::create_pipeline(api::pipeline_layout layout, u
851851
uint32_t max_attribute_size = 2 * sizeof(float); // Default triangle attributes
852852
uint32_t max_recursion_depth = 1;
853853
api::pipeline_flags flags = api::pipeline_flags::none;
854+
bool ray_tracing = false;
854855

855856
for (uint32_t i = 0; i < subobject_count; ++i)
856857
{
@@ -986,14 +987,17 @@ bool reshade::d3d12::device_impl::create_pipeline(api::pipeline_layout layout, u
986987
case api::pipeline_subobject_type::max_payload_size:
987988
assert(subobjects[i].count == 1);
988989
max_payload_size = *static_cast<const uint32_t *>(subobjects[i].data);
990+
ray_tracing = true;
989991
break;
990992
case api::pipeline_subobject_type::max_attribute_size:
991993
assert(subobjects[i].count == 1);
992994
max_attribute_size = *static_cast<const uint32_t *>(subobjects[i].data);
995+
ray_tracing = true;
993996
break;
994997
case api::pipeline_subobject_type::max_recursion_depth:
995998
assert(subobjects[i].count == 1);
996999
max_recursion_depth = *static_cast<const uint32_t *>(subobjects[i].data);
1000+
ray_tracing = true;
9971001
break;
9981002
case api::pipeline_subobject_type::flags:
9991003
assert(subobjects[i].count == 1);
@@ -1005,7 +1009,7 @@ bool reshade::d3d12::device_impl::create_pipeline(api::pipeline_layout layout, u
10051009
}
10061010
}
10071011

1008-
if (!raygen_desc.empty() || !shader_groups.empty())
1012+
if (ray_tracing || !raygen_desc.empty() || !shader_groups.empty())
10091013
{
10101014
com_ptr<ID3D12Device5> device5;
10111015
if (SUCCEEDED(_orig->QueryInterface(&device5)))
@@ -1316,7 +1320,7 @@ void reshade::d3d12::device_impl::destroy_pipeline(api::pipeline pipeline)
13161320
reinterpret_cast<IUnknown *>(pipeline.handle)->Release();
13171321
}
13181322

1319-
bool reshade::d3d12::device_impl::create_pipeline_layout(uint32_t param_count, const api::pipeline_layout_param *params, api::pipeline_layout *out_layout)
1323+
bool reshade::d3d12::device_impl::create_pipeline_layout(uint32_t param_count, const api::pipeline_layout_param *params, api::pipeline_layout *out_layout, D3D12_ROOT_SIGNATURE_FLAGS flags)
13201324
{
13211325
*out_layout = { 0 };
13221326

@@ -1470,29 +1474,34 @@ bool reshade::d3d12::device_impl::create_pipeline_layout(uint32_t param_count, c
14701474
internal_desc.pParameters = internal_params.data();
14711475
internal_desc.NumStaticSamplers = static_cast<uint32_t>(internal_static_samplers.size());
14721476
internal_desc.pStaticSamplers = internal_static_samplers.data();
1473-
internal_desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
1474-
1475-
if ((global_visibility_mask & api::shader_stage::vertex) == 0)
1476-
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS;
1477-
if ((global_visibility_mask & api::shader_stage::hull) == 0)
1478-
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
1479-
if ((global_visibility_mask & api::shader_stage::domain) == 0)
1480-
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS;
1481-
if ((global_visibility_mask & api::shader_stage::geometry) == 0)
1482-
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS;
1483-
if ((global_visibility_mask & api::shader_stage::pixel) == 0)
1484-
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS;
1485-
if ((global_visibility_mask & api::shader_stage::amplification) == 0)
1486-
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_AMPLIFICATION_SHADER_ROOT_ACCESS;
1487-
if ((global_visibility_mask & api::shader_stage::mesh) == 0)
1488-
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_MESH_SHADER_ROOT_ACCESS;
1489-
1490-
if (std::pair<D3D12_FEATURE_DATA_SHADER_MODEL, D3D12_FEATURE_DATA_D3D12_OPTIONS> options = { { D3D_SHADER_MODEL_6_6 }, {} };
1491-
SUCCEEDED(_orig->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &options.first, sizeof(options.first))) &&
1492-
SUCCEEDED(_orig->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options.second, sizeof(options.second))) &&
1493-
options.first.HighestShaderModel >= D3D_SHADER_MODEL_6_6 &&
1494-
options.second.ResourceBindingTier >= D3D12_RESOURCE_BINDING_TIER_3)
1495-
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED;
1477+
internal_desc.Flags = flags;
1478+
1479+
if (flags == D3D12_ROOT_SIGNATURE_FLAG_NONE)
1480+
{
1481+
internal_desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
1482+
1483+
if ((global_visibility_mask & api::shader_stage::vertex) == 0)
1484+
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS;
1485+
if ((global_visibility_mask & api::shader_stage::hull) == 0)
1486+
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;
1487+
if ((global_visibility_mask & api::shader_stage::domain) == 0)
1488+
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS;
1489+
if ((global_visibility_mask & api::shader_stage::geometry) == 0)
1490+
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS;
1491+
if ((global_visibility_mask & api::shader_stage::pixel) == 0)
1492+
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS;
1493+
if ((global_visibility_mask & api::shader_stage::amplification) == 0)
1494+
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_AMPLIFICATION_SHADER_ROOT_ACCESS;
1495+
if ((global_visibility_mask & api::shader_stage::mesh) == 0)
1496+
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_DENY_MESH_SHADER_ROOT_ACCESS;
1497+
1498+
if (std::pair<D3D12_FEATURE_DATA_SHADER_MODEL, D3D12_FEATURE_DATA_D3D12_OPTIONS> options = { { D3D_SHADER_MODEL_6_6 }, {} };
1499+
SUCCEEDED(_orig->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &options.first, sizeof(options.first))) &&
1500+
SUCCEEDED(_orig->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options.second, sizeof(options.second))) &&
1501+
options.first.HighestShaderModel >= D3D_SHADER_MODEL_6_6 &&
1502+
options.second.ResourceBindingTier >= D3D12_RESOURCE_BINDING_TIER_3)
1503+
internal_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED;
1504+
}
14961505

14971506
com_ptr<ID3DBlob> signature_blob, error_blob;
14981507
com_ptr<ID3D12RootSignature> signature;
@@ -1532,6 +1541,10 @@ bool reshade::d3d12::device_impl::create_pipeline_layout(uint32_t param_count, c
15321541
return false;
15331542
}
15341543
}
1544+
bool reshade::d3d12::device_impl::create_pipeline_layout(uint32_t param_count, const api::pipeline_layout_param *params, api::pipeline_layout *out_layout)
1545+
{
1546+
return create_pipeline_layout(param_count, params, out_layout, D3D12_ROOT_SIGNATURE_FLAG_NONE);
1547+
}
15351548
void reshade::d3d12::device_impl::destroy_pipeline_layout(api::pipeline_layout layout)
15361549
{
15371550
if (layout == 0)

source/d3d12/d3d12_impl_device.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace reshade::d3d12
5858
bool create_pipeline(api::pipeline_layout layout, uint32_t subobject_count, const api::pipeline_subobject *subobjects, api::pipeline *out_pipeline) final;
5959
void destroy_pipeline(api::pipeline pipeline) final;
6060

61+
bool create_pipeline_layout(uint32_t param_count, const api::pipeline_layout_param *params, api::pipeline_layout *out_layout, D3D12_ROOT_SIGNATURE_FLAGS flags);
6162
bool create_pipeline_layout(uint32_t param_count, const api::pipeline_layout_param *params, api::pipeline_layout *out_layout) final;
6263
void destroy_pipeline_layout(api::pipeline_layout layout) final;
6364

0 commit comments

Comments
 (0)