Skip to content

Commit 98b2f3a

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 98b2f3a

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

source/d3d12/d3d12_device.cpp

Lines changed: 3 additions & 1 deletion
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

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,8 @@ bool reshade::d3d12::device_impl::create_pipeline(api::pipeline_layout layout, u
852852
uint32_t max_recursion_depth = 1;
853853
api::pipeline_flags flags = api::pipeline_flags::none;
854854

855+
bool has_raygen_option = false;
856+
855857
for (uint32_t i = 0; i < subobject_count; ++i)
856858
{
857859
if (subobjects[i].count == 0)
@@ -986,14 +988,17 @@ bool reshade::d3d12::device_impl::create_pipeline(api::pipeline_layout layout, u
986988
case api::pipeline_subobject_type::max_payload_size:
987989
assert(subobjects[i].count == 1);
988990
max_payload_size = *static_cast<const uint32_t *>(subobjects[i].data);
991+
has_raygen_option = true;
989992
break;
990993
case api::pipeline_subobject_type::max_attribute_size:
991994
assert(subobjects[i].count == 1);
992995
max_attribute_size = *static_cast<const uint32_t *>(subobjects[i].data);
996+
has_raygen_option = true;
993997
break;
994998
case api::pipeline_subobject_type::max_recursion_depth:
995999
assert(subobjects[i].count == 1);
9961000
max_recursion_depth = *static_cast<const uint32_t *>(subobjects[i].data);
1001+
has_raygen_option = true;
9971002
break;
9981003
case api::pipeline_subobject_type::flags:
9991004
assert(subobjects[i].count == 1);
@@ -1005,7 +1010,7 @@ bool reshade::d3d12::device_impl::create_pipeline(api::pipeline_layout layout, u
10051010
}
10061011
}
10071012

1008-
if (!raygen_desc.empty() || !shader_groups.empty())
1013+
if (has_raygen_option || !raygen_desc.empty() || !shader_groups.empty())
10091014
{
10101015
com_ptr<ID3D12Device5> device5;
10111016
if (SUCCEEDED(_orig->QueryInterface(&device5)))
@@ -1316,7 +1321,7 @@ void reshade::d3d12::device_impl::destroy_pipeline(api::pipeline pipeline)
13161321
reinterpret_cast<IUnknown *>(pipeline.handle)->Release();
13171322
}
13181323

1319-
bool reshade::d3d12::device_impl::create_pipeline_layout(uint32_t param_count, const api::pipeline_layout_param *params, api::pipeline_layout *out_layout)
1324+
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)
13201325
{
13211326
*out_layout = { 0 };
13221327

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

14971507
com_ptr<ID3DBlob> signature_blob, error_blob;
14981508
com_ptr<ID3D12RootSignature> signature;
@@ -1532,6 +1542,10 @@ bool reshade::d3d12::device_impl::create_pipeline_layout(uint32_t param_count, c
15321542
return false;
15331543
}
15341544
}
1545+
bool reshade::d3d12::device_impl::create_pipeline_layout(uint32_t param_count, const api::pipeline_layout_param *params, api::pipeline_layout *out_layout)
1546+
{
1547+
return create_pipeline_layout(param_count, params, out_layout, D3D12_ROOT_SIGNATURE_FLAG_NONE);
1548+
}
15351549
void reshade::d3d12::device_impl::destroy_pipeline_layout(api::pipeline_layout layout)
15361550
{
15371551
if (layout == 0)

source/d3d12/d3d12_impl_device.hpp

Lines changed: 1 addition & 0 deletions
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)