From ffead800346d9ddd9f45abaa96b6f8333b5e5684 Mon Sep 17 00:00:00 2001 From: stefan Date: Fri, 4 Feb 2022 22:19:11 +0200 Subject: [PATCH 1/3] Fix for : error C2248: 'Microsoft::WRL::ComPtr::ptr_': cannot access protected member declared in class 'Microsoft::WRL::ComPtr' --- .../SampleCore/util/GpuResourceStateTracker.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingRealTimeDenoisedAmbientOcclusion/SampleCore/util/GpuResourceStateTracker.h b/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingRealTimeDenoisedAmbientOcclusion/SampleCore/util/GpuResourceStateTracker.h index fbac0142e..c6092ccee 100644 --- a/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingRealTimeDenoisedAmbientOcclusion/SampleCore/util/GpuResourceStateTracker.h +++ b/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingRealTimeDenoisedAmbientOcclusion/SampleCore/util/GpuResourceStateTracker.h @@ -15,7 +15,7 @@ class GpuResourceStateTracker { public: - void Bind(Microsoft::WRL::ComPtr commandList) { m_commandList = commandList; } + void Bind(Microsoft::WRL::ComPtr commandList) { m_commandList = commandList; } void Reset(); void TransitionResource(GpuResource* Resource, D3D12_RESOURCE_STATES NewState, bool FlushImmediate = false); @@ -25,7 +25,7 @@ class GpuResourceStateTracker protected: - Microsoft::WRL::ComPtr m_commandList; + Microsoft::WRL::ComPtr m_commandList; static const UINT c_MaxNumBarriers = 16; D3D12_RESOURCE_BARRIER m_ResourceBarrierBuffer[c_MaxNumBarriers]; UINT m_NumBarriersToFlush = 0; From 1f429b33a8d0e46d4c685462e2151e8cc1f73655 Mon Sep 17 00:00:00 2001 From: stefan Date: Fri, 4 Feb 2022 22:31:15 +0200 Subject: [PATCH 2/3] fix crash in the ray tracing miniengine example on a case where one has several gpus and the first one of them does not support dxr --- MiniEngine/Core/GraphicsCore.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MiniEngine/Core/GraphicsCore.cpp b/MiniEngine/Core/GraphicsCore.cpp index 522aa9ff3..00c7e6337 100644 --- a/MiniEngine/Core/GraphicsCore.cpp +++ b/MiniEngine/Core/GraphicsCore.cpp @@ -147,6 +147,17 @@ namespace Graphics { return GetVendorIdFromDevice(pDevice) == vendorID_Intel; } + + // Returns bool whether the device supports DirectX Raytracing tier. + bool IsDirectXRaytracingSupported(IDXGIAdapter1* adapter) + { + ComPtr testDevice; + D3D12_FEATURE_DATA_D3D12_OPTIONS5 featureSupportData = {}; + + return SUCCEEDED(D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&testDevice))) + && SUCCEEDED(testDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &featureSupportData, sizeof(featureSupportData))) + && featureSupportData.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED; + } } // Initialize the DirectX resources required to run. @@ -239,6 +250,7 @@ void Graphics::Initialize(void) continue; if ((desc.DedicatedVideoMemory > MaxSize || (desc.VendorId == desiredVendor)) && + IsDirectXRaytracingSupported(pAdapter.Get()) && SUCCEEDED(D3D12CreateDevice(pAdapter.Get(), D3D_FEATURE_LEVEL_11_0, MY_IID_PPV_ARGS(&pDevice)))) { pAdapter->GetDesc1(&desc); From 8b300ef96faf2dc5ba8863214b24833657781426 Mon Sep 17 00:00:00 2001 From: stefan Date: Sun, 30 Apr 2023 15:31:29 +0300 Subject: [PATCH 3/3] intel recommend tail call optimization, which means roughly that TraceRay should be the last call in the ray gen. it saves context and calling back to the raygen shader. --- .../src/D3D12RaytracingHelloWorld/Raytracing.hlsl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/Raytracing.hlsl b/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/Raytracing.hlsl index d42565687..cc77e5af2 100644 --- a/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/Raytracing.hlsl +++ b/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/Raytracing.hlsl @@ -21,7 +21,7 @@ ConstantBuffer g_rayGenCB : register(b0); typedef BuiltInTriangleIntersectionAttributes MyAttributes; struct RayPayload { - float4 color; + uint2 dispatchRayIndex; }; bool IsInsideViewport(float2 p, Viewport viewport) @@ -53,11 +53,8 @@ void MyRaygenShader() // TMin should be kept small to prevent missing geometry at close contact areas. ray.TMin = 0.001; ray.TMax = 10000.0; - RayPayload payload = { float4(0, 0, 0, 0) }; + RayPayload payload = { uint2(DispatchRaysIndex().xy) }; TraceRay(Scene, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, ~0, 0, 1, 0, ray, payload); - - // Write the raytraced color to the output texture. - RenderTarget[DispatchRaysIndex().xy] = payload.color; } else { @@ -70,13 +67,15 @@ void MyRaygenShader() void MyClosestHitShader(inout RayPayload payload, in MyAttributes attr) { float3 barycentrics = float3(1 - attr.barycentrics.x - attr.barycentrics.y, attr.barycentrics.x, attr.barycentrics.y); - payload.color = float4(barycentrics, 1); + // Write the raytraced color to the output texture. + RenderTarget[payload.dispatchRayIndex.xy] = float4(barycentrics, 1); } [shader("miss")] void MyMissShader(inout RayPayload payload) { - payload.color = float4(0, 0, 0, 1); + // Write the raytraced color to the output texture. + RenderTarget[payload.dispatchRayIndex.xy] = float4(0.0, 0.0, 0.0, 1.0); } #endif // RAYTRACING_HLSL \ No newline at end of file