From 8507a947571267d539075e9c808b2aacb270233a Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Wed, 11 May 2022 15:34:31 +0200 Subject: [PATCH] vkd3d: Add workaround to allow identifiers to be queried from library. CP77 relies on this to work somehow ... The DXR spec seems to suggest this is allowed, but there is no direct concept for this in Vulkan. This seems to work on NVIDIA at least, but we're on very shaky ground here ... Signed-off-by: Hans-Kristian Arntzen --- include/vkd3d.h | 1 + libs/vkd3d/device.c | 2 ++ libs/vkd3d/raytracing_pipeline.c | 14 ++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/include/vkd3d.h b/include/vkd3d.h index a2bcd097..e7b6a820 100644 --- a/include/vkd3d.h +++ b/include/vkd3d.h @@ -87,6 +87,7 @@ extern "C" { #define VKD3D_CONFIG_FLAG_BREADCRUMBS (1ull << 25) #define VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_APP_CACHE_ONLY (1ull << 26) #define VKD3D_CONFIG_FLAG_SHADER_CACHE_SYNC (1ull << 27) +#define VKD3D_CONFIG_FLAG_ALLOW_SBT_COLLECTION (1ull << 28) typedef HRESULT (*PFN_vkd3d_signal_event)(HANDLE event); diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index be7a0c2a..6eea60ca 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -511,6 +511,8 @@ static const struct vkd3d_instance_application_meta application_override[] = { /* Serious Sam 4 (257420). * Invariant workarounds cause graphical glitches when rendering foliage on NV. */ { VKD3D_STRING_COMPARE_EXACT, "Sam4.exe", VKD3D_CONFIG_FLAG_FORCE_NO_INVARIANT_POSITION, 0 }, + /* Cyberpunk 2077 (1091500). */ + { VKD3D_STRING_COMPARE_EXACT, "Cyberpunk2077.exe", VKD3D_CONFIG_FLAG_ALLOW_SBT_COLLECTION, 0 }, { VKD3D_STRING_COMPARE_NEVER, NULL, 0, 0 } }; diff --git a/libs/vkd3d/raytracing_pipeline.c b/libs/vkd3d/raytracing_pipeline.c index 5fe27db9..2d739d0b 100644 --- a/libs/vkd3d/raytracing_pipeline.c +++ b/libs/vkd3d/raytracing_pipeline.c @@ -2143,6 +2143,20 @@ static HRESULT d3d12_state_object_init(struct d3d12_state_object *object, object->internal_refcount = 1; object->device = device; object->type = desc->Type; + + if (object->type == D3D12_STATE_OBJECT_TYPE_COLLECTION && + (vkd3d_config_flags & VKD3D_CONFIG_FLAG_ALLOW_SBT_COLLECTION)) + { + /* It seems to be valid to query shader identifiers from a COLLECTION which is pure insanity. + * We can fake this behavior if we pretend we have ALLOW_STATE_OBJECT_ADDITIONS and RTPSO. + * We will validate that the "COLLECTION" matches the consuming RTPSO. + * If the collection does not contain an RGEN shader, we're technically out of spec here, + * but there is nothing we can do for now without further spec improvements. */ + INFO("Promoting COLLECTION to RAYTRACING_PIPELINE as workaround.\n"); + object->type = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE; + object->flags |= D3D12_STATE_OBJECT_FLAG_ALLOW_STATE_OBJECT_ADDITIONS; + } + memset(&data, 0, sizeof(data)); if (FAILED(hr = d3d12_state_object_parse_subobjects(object, desc, parent, &data)))