Skip to content

Commit 70bdd5b

Browse files
Do not pass EngineCI do device context constructors
1 parent 2c205ba commit 70bdd5b

18 files changed

+102
-69
lines changed

Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -54,12 +54,11 @@ class DeviceContextD3D11Impl final : public DeviceContextBase<EngineD3D11ImplTra
5454
public:
5555
using TDeviceContextBase = DeviceContextBase<EngineD3D11ImplTraits>;
5656

57-
DeviceContextD3D11Impl(IReferenceCounters* pRefCounters,
58-
IMemoryAllocator& Allocator,
59-
RenderDeviceD3D11Impl* pDevice,
60-
ID3D11DeviceContext1* pd3d11DeviceContext,
61-
const EngineD3D11CreateInfo& EngineCI,
62-
const DeviceContextDesc& Desc);
57+
DeviceContextD3D11Impl(IReferenceCounters* pRefCounters,
58+
IMemoryAllocator& Allocator,
59+
RenderDeviceD3D11Impl* pDevice,
60+
ID3D11DeviceContext1* pd3d11DeviceContext,
61+
const DeviceContextDesc& Desc);
6362
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
6463

6564
/// Implementation of IDeviceContext::Begin() in Direct3D11 backend.

Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -190,9 +190,19 @@ class RenderDeviceD3D11Impl final : public RenderDeviceD3DBase<EngineD3D11ImplTr
190190
#endif
191191
#undef GET_D3D11_DEVICE
192192

193+
struct Properties
194+
{
195+
D3D11_VALIDATION_FLAGS D3D11ValidationFlags = D3D11_VALIDATION_FLAG_NONE;
196+
};
197+
198+
const Properties& GetProperties() const { return m_Properties; }
199+
193200
private:
194201
virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final;
195202

203+
private:
204+
const Properties m_Properties;
205+
196206
/// D3D11 device
197207
CComPtr<ID3D11Device> m_pd3d11Device;
198208

Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@
4747
namespace Diligent
4848
{
4949

50-
DeviceContextD3D11Impl::DeviceContextD3D11Impl(IReferenceCounters* pRefCounters,
51-
IMemoryAllocator& Allocator,
52-
RenderDeviceD3D11Impl* pDevice,
53-
ID3D11DeviceContext1* pd3d11DeviceContext,
54-
const EngineD3D11CreateInfo& EngineCI,
55-
const DeviceContextDesc& Desc) :
50+
DeviceContextD3D11Impl::DeviceContextD3D11Impl(IReferenceCounters* pRefCounters,
51+
IMemoryAllocator& Allocator,
52+
RenderDeviceD3D11Impl* pDevice,
53+
ID3D11DeviceContext1* pd3d11DeviceContext,
54+
const DeviceContextDesc& Desc) :
5655
// clang-format off
5756
TDeviceContextBase
5857
{
@@ -62,7 +61,7 @@ DeviceContextD3D11Impl::DeviceContextD3D11Impl(IReferenceCounters* pRef
6261
},
6362
m_pd3d11DeviceContext {pd3d11DeviceContext },
6463
#ifdef DILIGENT_DEVELOPMENT
65-
m_D3D11ValidationFlags{EngineCI.D3D11ValidationFlags},
64+
m_D3D11ValidationFlags{pDevice->GetProperties().D3D11ValidationFlags},
6665
#endif
6766
m_CmdListAllocator {GetRawAllocator(), sizeof(CommandListD3D11Impl), 64}
6867
// clang-format on

Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd
389389

390390
RefCntAutoPtr<DeviceContextD3D11Impl> pDeviceContextD3D11{
391391
NEW_RC_OBJ(RawAllocator, "DeviceContextD3D11Impl instance", DeviceContextD3D11Impl)(
392-
RawAllocator, pRenderDeviceD3D11, pd3d11ImmediateCtx1, EngineCI,
392+
RawAllocator, pRenderDeviceD3D11, pd3d11ImmediateCtx1,
393393
DeviceContextDesc{
394394
EngineCI.pImmediateContextInfo ? EngineCI.pImmediateContextInfo[0].Name : nullptr,
395395
pRenderDeviceD3D11->GetAdapterInfo().Queues[0].QueueType,
@@ -416,7 +416,7 @@ void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd
416416

417417
RefCntAutoPtr<DeviceContextD3D11Impl> pDeferredCtxD3D11{
418418
NEW_RC_OBJ(RawAllocator, "DeviceContextD3D11Impl instance", DeviceContextD3D11Impl)(
419-
RawAllocator, pRenderDeviceD3D11, pd3d11DeferredCtx1, EngineCI,
419+
RawAllocator, pRenderDeviceD3D11, pd3d11DeferredCtx1,
420420
DeviceContextDesc{
421421
nullptr,
422422
COMMAND_QUEUE_TYPE_UNKNOWN,

Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -74,6 +74,10 @@ RenderDeviceD3D11Impl::RenderDeviceD3D11Impl(IReferenceCounters* pRefCo
7474
EngineCI,
7575
AdapterInfo
7676
},
77+
m_Properties
78+
{
79+
EngineCI.D3D11ValidationFlags,
80+
},
7781
m_pd3d11Device{pd3d11Device}
7882
// clang-format on
7983
{
@@ -135,13 +139,14 @@ RenderDeviceD3D11Impl::~RenderDeviceD3D11Impl()
135139

136140
void RenderDeviceD3D11Impl::TestTextureFormat(TEXTURE_FORMAT TexFormat)
137141
{
138-
auto& TexFormatInfo = m_TextureFormatsInfo[TexFormat];
142+
TextureFormatInfoExt& TexFormatInfo = m_TextureFormatsInfo[TexFormat];
139143
VERIFY(TexFormatInfo.Supported, "Texture format is not supported");
140144

141-
auto DXGIFormat = TexFormatToDXGI_Format(TexFormat);
145+
DXGI_FORMAT DXGIFormat = TexFormatToDXGI_Format(TexFormat);
142146

143147
UINT FormatSupport = 0;
144-
auto hr = m_pd3d11Device->CheckFormatSupport(DXGIFormat, &FormatSupport);
148+
149+
HRESULT hr = m_pd3d11Device->CheckFormatSupport(DXGIFormat, &FormatSupport);
145150
if (FAILED(hr))
146151
{
147152
LOG_ERROR_MESSAGE("CheckFormatSupport() failed for format ", DXGIFormat);
@@ -388,7 +393,7 @@ void RenderDeviceD3D11Impl::IdleGPU()
388393
{
389394
VERIFY_EXPR(m_wpImmediateContexts.size() == 1);
390395

391-
if (auto pImmediateCtx = m_wpImmediateContexts[0].Lock())
396+
if (RefCntAutoPtr<DeviceContextD3D11Impl> pImmediateCtx = m_wpImmediateContexts[0].Lock())
392397
{
393398
pImmediateCtx->WaitForIdle();
394399
}

Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ class DeviceContextD3D12Impl final : public DeviceContextNextGenBase<EngineD3D12
6161
public:
6262
using TDeviceContextBase = DeviceContextNextGenBase<EngineD3D12ImplTraits>;
6363

64-
DeviceContextD3D12Impl(IReferenceCounters* pRefCounters,
65-
RenderDeviceD3D12Impl* pDevice,
66-
const EngineD3D12CreateInfo& EngineCI,
67-
const DeviceContextDesc& Desc);
64+
DeviceContextD3D12Impl(IReferenceCounters* pRefCounters,
65+
RenderDeviceD3D12Impl* pDevice,
66+
const DeviceContextDesc& Desc);
6867
~DeviceContextD3D12Impl();
6968

7069
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_DeviceContextD3D12, TDeviceContextBase)

Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,6 +34,7 @@
3434
#include <vector>
3535
#include <memory>
3636
#include <unordered_map>
37+
#include <array>
3738

3839
#include "EngineD3D12ImplTraits.hpp"
3940
#include "RenderDeviceD3DBase.hpp"
@@ -275,13 +276,25 @@ class RenderDeviceD3D12Impl final : public RenderDeviceNextGenBase<RenderDeviceD
275276
return m_pNVApiHeap;
276277
}
277278

279+
struct Properties
280+
{
281+
Uint32 DynamicHeapPageSize = 0;
282+
283+
std::array<Uint32, _countof(EngineD3D12CreateInfo::DynamicDescriptorAllocationChunkSize)> DynamicDescriptorAllocationChunkSize = {};
284+
};
285+
286+
const Properties& GetProperties() const { return m_Properties; }
287+
278288
private:
279289
virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final;
280290
void FreeCommandContext(PooledCommandContext&& Ctx);
281291

282292
CommandListManager& GetCmdListManager(SoftwareQueueIndex CommandQueueId);
283293
CommandListManager& GetCmdListManager(D3D12_COMMAND_LIST_TYPE CmdListType);
284294

295+
private:
296+
const Properties m_Properties;
297+
285298
CComPtr<ID3D12Device> m_pd3d12Device;
286299

287300
CPUDescriptorHeap m_CPUDescriptorHeaps[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES];

Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ static std::string GetContextObjectName(const char* Object, bool bIsDeferred, Ui
6565
return ss.str();
6666
}
6767

68-
DeviceContextD3D12Impl::DeviceContextD3D12Impl(IReferenceCounters* pRefCounters,
69-
RenderDeviceD3D12Impl* pDeviceD3D12Impl,
70-
const EngineD3D12CreateInfo& EngineCI,
71-
const DeviceContextDesc& Desc) :
68+
DeviceContextD3D12Impl::DeviceContextD3D12Impl(IReferenceCounters* pRefCounters,
69+
RenderDeviceD3D12Impl* pDeviceD3D12Impl,
70+
const DeviceContextDesc& Desc) :
7271
// clang-format off
7372
TDeviceContextBase
7473
{
@@ -80,39 +79,39 @@ DeviceContextD3D12Impl::DeviceContextD3D12Impl(IReferenceCounters* pRef
8079
{
8180
pDeviceD3D12Impl->GetDynamicMemoryManager(),
8281
GetContextObjectName("Dynamic heap", Desc.IsDeferred, Desc.ContextId),
83-
EngineCI.DynamicHeapPageSize
82+
pDeviceD3D12Impl->GetProperties().DynamicHeapPageSize
8483
},
8584
m_DynamicGPUDescriptorAllocator
8685
{
8786
{
8887
GetRawAllocator(),
8988
pDeviceD3D12Impl->GetGPUDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV),
90-
EngineCI.DynamicDescriptorAllocationChunkSize[D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV],
89+
pDeviceD3D12Impl->GetProperties().DynamicDescriptorAllocationChunkSize[D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV],
9190
GetContextObjectName("CBV_SRV_UAV dynamic descriptor allocator", Desc.IsDeferred, Desc.ContextId)
9291
},
9392
{
9493
GetRawAllocator(),
9594
pDeviceD3D12Impl->GetGPUDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER),
96-
EngineCI.DynamicDescriptorAllocationChunkSize[D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER],
95+
pDeviceD3D12Impl->GetProperties().DynamicDescriptorAllocationChunkSize[D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER],
9796
GetContextObjectName("SAMPLER dynamic descriptor allocator", Desc.IsDeferred, Desc.ContextId)
9897
}
9998
},
10099
m_CmdListAllocator{GetRawAllocator(), sizeof(CommandListD3D12Impl), 64},
101100
m_NullRTV{pDeviceD3D12Impl->AllocateDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1)}
102101
// clang-format on
103102
{
104-
auto* pd3d12Device = pDeviceD3D12Impl->GetD3D12Device();
103+
ID3D12Device* pd3d12Device = pDeviceD3D12Impl->GetD3D12Device();
105104
if (!IsDeferred())
106105
{
107106
RequestCommandContext();
108107
m_QueryMgr = &pDeviceD3D12Impl->GetQueryMgr(GetCommandQueueId());
109108
}
110109

111-
auto* pDrawIndirectSignature = GetDrawIndirectSignature(sizeof(UINT) * 4);
110+
ID3D12CommandSignature* pDrawIndirectSignature = GetDrawIndirectSignature(sizeof(UINT) * 4);
112111
if (pDrawIndirectSignature == nullptr)
113112
LOG_ERROR_AND_THROW("Failed to create indirect draw command signature");
114113

115-
auto* pDrawIndexedIndirectSignature = GetDrawIndexedIndirectSignature(sizeof(UINT) * 5);
114+
ID3D12CommandSignature* pDrawIndexedIndirectSignature = GetDrawIndexedIndirectSignature(sizeof(UINT) * 5);
116115
if (pDrawIndexedIndirectSignature == nullptr)
117116
LOG_ERROR_AND_THROW("Failed to create draw indexed indirect command signature");
118117

@@ -125,7 +124,7 @@ DeviceContextD3D12Impl::DeviceContextD3D12Impl(IReferenceCounters* pRef
125124

126125
CmdSignatureDesc.ByteStride = sizeof(UINT) * 3;
127126
IndirectArg.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH;
128-
auto hr = pd3d12Device->CreateCommandSignature(&CmdSignatureDesc, nullptr, __uuidof(m_pDispatchIndirectSignature), reinterpret_cast<void**>(static_cast<ID3D12CommandSignature**>(&m_pDispatchIndirectSignature)));
127+
HRESULT hr = pd3d12Device->CreateCommandSignature(&CmdSignatureDesc, nullptr, __uuidof(m_pDispatchIndirectSignature), reinterpret_cast<void**>(static_cast<ID3D12CommandSignature**>(&m_pDispatchIndirectSignature)));
129128
CHECK_D3D_RESULT_THROW(hr, "Failed to create dispatch indirect command signature");
130129

131130
#ifdef D3D12_H_HAS_MESH_SHADER

Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ void EngineFactoryD3D12Impl::AttachToD3D12Device(void* pd
623623
RefCntAutoPtr<DeviceContextD3D12Impl> pImmediateCtxD3D12{
624624
NEW_RC_OBJ(RawMemAllocator, "DeviceContextD3D12Impl instance", DeviceContextD3D12Impl)(
625625
pRenderDeviceD3D12,
626-
EngineCI,
627626
DeviceContextDesc{
628627
pImmediateContextInfo[CtxInd].Name,
629628
AdapterInfo.Queues[QueueId].QueueType,
@@ -642,7 +641,6 @@ void EngineFactoryD3D12Impl::AttachToD3D12Device(void* pd
642641
RefCntAutoPtr<DeviceContextD3D12Impl> pDeferredCtxD3D12{
643642
NEW_RC_OBJ(RawMemAllocator, "DeviceContextD3D12Impl instance", DeviceContextD3D12Impl)(
644643
pRenderDeviceD3D12,
645-
EngineCI,
646644
DeviceContextDesc{
647645
nullptr,
648646
COMMAND_QUEUE_TYPE_UNKNOWN,

Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -142,7 +142,18 @@ RenderDeviceD3D12Impl::RenderDeviceD3D12Impl(IReferenceCounters* pRefCo
142142
EngineCI,
143143
AdapterInfo
144144
},
145-
m_pd3d12Device {pd3d12Device},
145+
m_Properties
146+
{
147+
EngineCI.DynamicHeapPageSize,
148+
[](const EngineD3D12CreateInfo& CI)
149+
{
150+
decltype(Properties::DynamicDescriptorAllocationChunkSize) ChunkSizeArr{};
151+
for (size_t i=0; i < ChunkSizeArr.size(); ++i)
152+
ChunkSizeArr[i] = CI.DynamicDescriptorAllocationChunkSize[i];
153+
return ChunkSizeArr;
154+
}(EngineCI),
155+
},
156+
m_pd3d12Device{pd3d12Device},
146157
m_CPUDescriptorHeaps
147158
{
148159
{RawMemAllocator, *this, EngineCI.CPUDescriptorHeapAllocationSize[0], D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE},

0 commit comments

Comments
 (0)