Skip to content

Commit 6414a66

Browse files
EngineCreateInfo: replace pRawMemAllocator member with IEngineFactory::SetMemoryAllocator() (API256011)
Added SetMemoryAllocator method to IArchiverFactory (close #703)
1 parent c0903bf commit 6414a66

File tree

12 files changed

+58
-17
lines changed

12 files changed

+58
-17
lines changed

Graphics/Archiver/interface/ArchiverFactory.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,20 @@ DILIGENT_BEGIN_INTERFACE(IArchiverFactory, IObject)
338338
/// \param [in] BreakOnError - Whether to break on assertion failure.
339339
VIRTUAL void METHOD(SetBreakOnError)(THIS_
340340
bool BreakOnError) CONST PURE;
341+
342+
/// Sets the memory allocator to be used by the archiver.
343+
344+
/// \param [in] pAllocator - Pointer to the memory allocator.
345+
///
346+
/// The allocator is a global setting that applies to the entire execution unit
347+
/// (executable or shared library that contains the archiver implementation).
348+
///
349+
/// The allocator should be set before any other factory method is called and
350+
/// should not be changed afterwards.
351+
/// The allocator object must remain valid until all objects created by the factory
352+
/// are destroyed.
353+
VIRTUAL void METHOD(SetMemoryAllocator)(THIS_
354+
IMemoryAllocator* pAllocator) CONST PURE;
341355
};
342356
DILIGENT_END_INTERFACE
343357

@@ -353,7 +367,8 @@ DILIGENT_END_INTERFACE
353367
# define IArchiverFactory_MergeArchives(This, ...) CALL_IFACE_METHOD(ArchiverFactory, MergeArchives, This, __VA_ARGS__)
354368
# define IArchiverFactory_PrintArchiveContent(This, ...) CALL_IFACE_METHOD(ArchiverFactory, PrintArchiveContent, This, __VA_ARGS__)
355369
# define IArchiverFactory_SetMessageCallback(This, ...) CALL_IFACE_METHOD(ArchiverFactory, SetMessageCallback, This, __VA_ARGS__)
356-
# define IEngineFactory_SetBreakOnError(This, ...) CALL_IFACE_METHOD(EngineFactory, SetBreakOnError, This, __VA_ARGS__)
370+
# define IArchiverFactory_SetBreakOnError(This, ...) CALL_IFACE_METHOD(ArchiverFactory, SetBreakOnError, This, __VA_ARGS__)
371+
# define IArchiverFactory_SetMemoryAllocator(This, ...) CALL_IFACE_METHOD(ArchiverFactory, SetMemoryAllocator, This, __VA_ARGS__)
357372

358373
#endif
359374

Graphics/Archiver/src/ArchiverFactory.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class ArchiverFactoryImpl final : public IArchiverFactory
143143

144144
virtual void DILIGENT_CALL_TYPE SetBreakOnError(bool BreakOnError) const override final;
145145

146+
virtual void DILIGENT_CALL_TYPE SetMemoryAllocator(IMemoryAllocator* pAllocator) const override final;
147+
146148
private:
147149
DummyReferenceCounters<ArchiverFactoryImpl> m_RefCounters;
148150
};
@@ -349,6 +351,11 @@ void ArchiverFactoryImpl::SetBreakOnError(bool BreakOnError) const
349351
PlatformDebug::SetBreakOnError(BreakOnError);
350352
}
351353

354+
void ArchiverFactoryImpl::SetMemoryAllocator(IMemoryAllocator* pAllocator) const
355+
{
356+
SetRawAllocator(pAllocator);
357+
}
358+
352359
} // namespace
353360

354361

Graphics/GraphicsEngine/include/EngineFactoryBase.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ class EngineFactoryBase : public BaseInterface
122122
PlatformDebug::SetBreakOnError(BreakOnError);
123123
}
124124

125+
virtual void DILIGENT_CALL_TYPE SetMemoryAllocator(IMemoryAllocator* pAllocator) const override final
126+
{
127+
SetRawAllocator(pAllocator);
128+
}
129+
125130
protected:
126131
template <typename DearchiverImplType>
127132
void CreateDearchiver(const DearchiverCreateInfo& CreateInfo,

Graphics/GraphicsEngine/interface/APIInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/// \file
3131
/// Diligent API information
3232

33-
#define DILIGENT_API_VERSION 256010
33+
#define DILIGENT_API_VERSION 256011
3434

3535
#include "../../../Primitives/interface/BasicTypes.h"
3636

Graphics/GraphicsEngine/interface/EngineFactory.h

Lines changed: 27 additions & 3 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");
@@ -33,6 +33,7 @@
3333
#include "../../../Primitives/interface/Object.h"
3434
#include "../../../Primitives/interface/DebugOutput.h"
3535
#include "../../../Primitives/interface/DataBlob.h"
36+
#include "../../../Primitives/interface/MemoryAllocator.h"
3637
#include "GraphicsTypes.h"
3738

3839

@@ -128,16 +129,38 @@ DILIGENT_BEGIN_INTERFACE(IEngineFactory, IObject)
128129

129130
/// Sets a user-provided debug message callback.
130131

131-
/// \param [in] MessageCallback - Debug message callback function to use instead of the default one.
132+
/// \param [in] MessageCallback - Debug message callback function to use instead of the default one.
133+
///
134+
/// MessageCallback is a global setting that applies to the entire execution unit
135+
/// (executable or shared library that contains the engine implementation).
132136
VIRTUAL void METHOD(SetMessageCallback)(THIS_
133137
DebugMessageCallbackType MessageCallback) CONST PURE;
134138

139+
135140
/// Sets whether to break program execution on assertion failure.
136141

137-
/// \param [in] BreakOnError - Whether to break on assertion failure.
142+
/// \param [in] BreakOnError - Whether to break on assertion failure.
143+
///
144+
/// BreakOnError is a global setting that applies to the entire execution unit
145+
/// (executable or shared library that contains the engine implementation).
138146
VIRTUAL void METHOD(SetBreakOnError)(THIS_
139147
bool BreakOnError) CONST PURE;
140148

149+
150+
/// Sets the memory allocator to be used by the engine.
151+
152+
/// \param [in] pAllocator - Pointer to the memory allocator.
153+
///
154+
/// The allocator is a global setting that applies to the entire execution unit
155+
/// (executable or shared library that contains the engine implementation).
156+
///
157+
/// The allocator should be set before any other factory method is called and
158+
/// should not be changed afterwards.
159+
/// The allocator object must remain valid for the lifetime of the
160+
/// engine until all engine objects are destroyed.
161+
VIRTUAL void METHOD(SetMemoryAllocator)(THIS_
162+
IMemoryAllocator* pAllocator) CONST PURE;
163+
141164
#if PLATFORM_ANDROID
142165
/// On Android platform, it is necessary to initialize the file system before
143166
/// CreateDefaultShaderSourceStreamFactory() method can be called.
@@ -171,6 +194,7 @@ DILIGENT_END_INTERFACE
171194
# define IEngineFactory_CreateDearchiver(This, ...) CALL_IFACE_METHOD(EngineFactory, CreateDearchiver, This, __VA_ARGS__)
172195
# define IEngineFactory_SetMessageCallback(This, ...) CALL_IFACE_METHOD(EngineFactory, SetMessageCallback, This, __VA_ARGS__)
173196
# define IEngineFactory_SetBreakOnError(This, ...) CALL_IFACE_METHOD(EngineFactory, SetBreakOnError, This, __VA_ARGS__)
197+
# define IEngineFactory_SetMemoryAllocator(This, ...) CALL_IFACE_METHOD(EngineFactory, SetMemoryAllocator, This, __VA_ARGS__)
174198
// clang-format on
175199

176200
#endif

Graphics/GraphicsEngine/interface/GraphicsTypes.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3517,10 +3517,6 @@ struct EngineCreateInfo
35173517
/// Validation options, see Diligent::VALIDATION_FLAGS.
35183518
VALIDATION_FLAGS ValidationFlags DEFAULT_INITIALIZER(VALIDATION_FLAG_NONE);
35193519

3520-
/// Pointer to the raw memory allocator that will be used for all memory allocation/deallocation
3521-
/// operations in the engine
3522-
struct IMemoryAllocator* pRawMemAllocator DEFAULT_INITIALIZER(nullptr);
3523-
35243520
/// An optional thread pool for asynchronous shader and pipeline state compilation.
35253521
///
35263522
/// When AsyncShaderCompilation device feature is enabled, the engine will use

Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd
374374
const GraphicsAdapterInfo AdapterInfo = GetGraphicsAdapterInfo(pd3d11NativeDevice, pDXGIAdapter1);
375375
VerifyEngineCreateInfo(EngineCI, AdapterInfo);
376376

377-
SetRawAllocator(EngineCI.pRawMemAllocator);
378377
IMemoryAllocator& RawAllocator = GetRawAllocator();
379378

380379
RenderDeviceD3D11Impl* pRenderDeviceD3D11{

Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12(const EngineD3D12Creat
309309
try
310310
{
311311
ValidateD3D12CreateInfo(EngineCI);
312-
SetRawAllocator(EngineCI.pRawMemAllocator);
313312

314313
// Enable the D3D12 debug layer.
315314
if (EngineCI.EnableValidation)
@@ -601,7 +600,6 @@ void EngineFactoryD3D12Impl::AttachToD3D12Device(void* pd
601600

602601
try
603602
{
604-
SetRawAllocator(EngineCI.pRawMemAllocator);
605603
IMemoryAllocator& RawMemAllocator = GetRawAllocator();
606604
ID3D12Device* d3d12Device = reinterpret_cast<ID3D12Device*>(pd3d12NativeDevice);
607605
CComPtr<IDXGIAdapter1> pDXGIAdapter1 = DXGIAdapterFromD3D12Device(d3d12Device);

Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineGLCreateInf
235235
SetDefaultGraphicsAdapterInfo(AdapterInfo);
236236
VerifyEngineCreateInfo(EngineCI, AdapterInfo);
237237

238-
SetRawAllocator(EngineCI.pRawMemAllocator);
239238
IMemoryAllocator& RawMemAllocator = GetRawAllocator();
240239

241240
SetPreferredAdapter(EngineCI);
@@ -334,7 +333,6 @@ void EngineFactoryOpenGLImpl::AttachToActiveGLContext(const EngineGLCreateInfo&
334333
SetDefaultGraphicsAdapterInfo(AdapterInfo);
335334
VerifyEngineCreateInfo(EngineCI, AdapterInfo);
336335

337-
SetRawAllocator(EngineCI.pRawMemAllocator);
338336
IMemoryAllocator& RawMemAllocator = GetRawAllocator();
339337

340338
SetPreferredAdapter(EngineCI);

Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,6 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& En
695695
return;
696696
}
697697

698-
SetRawAllocator(EngineCI.pRawMemAllocator);
699-
700698
try
701699
{
702700
const Version GraphicsAPIVersion = EngineCI.GraphicsAPIVersion == Version{0, 0} ?

0 commit comments

Comments
 (0)