summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsTools
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-11-24 02:58:46 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-11-24 02:58:46 +0000
commita58331fa11bf4db7f5aec29f14852730e9f53f2f (patch)
treee07a5b66129a1bc4246adb4fcd11d49c5555ab11 /Graphics/GraphicsTools
parentclang-formatted GraphicsEngineNextGenBase project (diff)
downloadDiligentCore-a58331fa11bf4db7f5aec29f14852730e9f53f2f.tar.gz
DiligentCore-a58331fa11bf4db7f5aec29f14852730e9f53f2f.zip
clang-formatted GraphicsTools project
Diffstat (limited to 'Graphics/GraphicsTools')
-rw-r--r--Graphics/GraphicsTools/include/CommonlyUsedStates.h352
-rw-r--r--Graphics/GraphicsTools/include/GraphicsUtilities.h20
-rw-r--r--Graphics/GraphicsTools/include/ScreenCapture.h19
-rw-r--r--Graphics/GraphicsTools/include/ShaderMacroHelper.h84
-rw-r--r--Graphics/GraphicsTools/include/TextureUploader.h93
-rw-r--r--Graphics/GraphicsTools/include/TextureUploaderBase.h108
-rw-r--r--Graphics/GraphicsTools/include/TextureUploaderD3D11.h55
-rw-r--r--Graphics/GraphicsTools/include/TextureUploaderD3D12_Vk.h55
-rw-r--r--Graphics/GraphicsTools/include/TextureUploaderGL.h55
-rw-r--r--Graphics/GraphicsTools/include/pch.h2
-rw-r--r--Graphics/GraphicsTools/src/GraphicsUtilities.cpp113
-rw-r--r--Graphics/GraphicsTools/src/ScreenCapture.cpp21
-rw-r--r--Graphics/GraphicsTools/src/TextureUploader.cpp44
-rw-r--r--Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp121
-rw-r--r--Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp99
-rw-r--r--Graphics/GraphicsTools/src/TextureUploaderGL.cpp133
16 files changed, 715 insertions, 659 deletions
diff --git a/Graphics/GraphicsTools/include/CommonlyUsedStates.h b/Graphics/GraphicsTools/include/CommonlyUsedStates.h
index 77514652..f52bd34d 100644
--- a/Graphics/GraphicsTools/include/CommonlyUsedStates.h
+++ b/Graphics/GraphicsTools/include/CommonlyUsedStates.h
@@ -34,186 +34,190 @@
namespace Diligent
{
- // Common depth-stencil states
- static const DepthStencilStateDesc DSS_Default{};
- static const DepthStencilStateDesc DSS_DisableDepth
- {
- False, // DepthEnable
- False // DepthWriteEnable
- };
+// clang-format off
+
+// Common depth-stencil states
+static const DepthStencilStateDesc DSS_Default{};
+
+static const DepthStencilStateDesc DSS_DisableDepth
+{
+ False, // DepthEnable
+ False // DepthWriteEnable
+};
- // Common rasterizer states
- static const RasterizerStateDesc RS_Default{};
+// Common rasterizer states
+static const RasterizerStateDesc RS_Default{};
- static const RasterizerStateDesc RS_SolidFillNoCull
- {
- FILL_MODE_SOLID,
- CULL_MODE_NONE
- };
+static const RasterizerStateDesc RS_SolidFillNoCull
+{
+ FILL_MODE_SOLID,
+ CULL_MODE_NONE
+};
- static const RasterizerStateDesc RS_WireFillNoCull
- {
- FILL_MODE_WIREFRAME,
- CULL_MODE_NONE
- };
+static const RasterizerStateDesc RS_WireFillNoCull
+{
+ FILL_MODE_WIREFRAME,
+ CULL_MODE_NONE
+};
- // Blend states
- static const BlendStateDesc BS_Default{};
+// Blend states
+static const BlendStateDesc BS_Default{};
+
+static const BlendStateDesc BS_AlphaBlend =
+{
+ False, // AlphaToCoverageEnable
+ False, // IndependentBlendEnable
+ RenderTargetBlendDesc // Render Target 0
+ {
+ True, // BlendEnable
+ False, // LogicOperationEnable
+ BLEND_FACTOR_SRC_ALPHA, // SrcBlend
+ BLEND_FACTOR_INV_SRC_ALPHA, // DestBlend
+ BLEND_OPERATION_ADD, // BlendOp
+ BLEND_FACTOR_SRC_ALPHA, // SrcBlendAlpha
+ BLEND_FACTOR_INV_SRC_ALPHA, // DestBlendAlpha
+ BLEND_OPERATION_ADD // BlendOpAlpha
+ }
+};
+
+
+// Common sampler states
+static const SamplerDesc Sam_LinearClamp
+{
+ FILTER_TYPE_LINEAR,
+ FILTER_TYPE_LINEAR,
+ FILTER_TYPE_LINEAR,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP
+};
+
+static const SamplerDesc Sam_PointClamp
+{
+ FILTER_TYPE_POINT,
+ FILTER_TYPE_POINT,
+ FILTER_TYPE_POINT,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP
+};
+
+static const SamplerDesc Sam_LinearMirror
+{
+ FILTER_TYPE_LINEAR,
+ FILTER_TYPE_LINEAR,
+ FILTER_TYPE_LINEAR,
+ TEXTURE_ADDRESS_MIRROR,
+ TEXTURE_ADDRESS_MIRROR,
+ TEXTURE_ADDRESS_MIRROR
+};
+
+static const SamplerDesc Sam_PointWrap
+{
+ FILTER_TYPE_POINT,
+ FILTER_TYPE_POINT,
+ FILTER_TYPE_POINT,
+ TEXTURE_ADDRESS_WRAP,
+ TEXTURE_ADDRESS_WRAP,
+ TEXTURE_ADDRESS_WRAP
+};
+
+static const SamplerDesc Sam_LinearWrap
+{
+ FILTER_TYPE_LINEAR,
+ FILTER_TYPE_LINEAR,
+ FILTER_TYPE_LINEAR,
+ TEXTURE_ADDRESS_WRAP,
+ TEXTURE_ADDRESS_WRAP,
+ TEXTURE_ADDRESS_WRAP
+};
+
+static const SamplerDesc Sam_ComparsionLinearClamp
+{
+ FILTER_TYPE_COMPARISON_LINEAR,
+ FILTER_TYPE_COMPARISON_LINEAR,
+ FILTER_TYPE_COMPARISON_LINEAR,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ SamplerDesc{}.MipLODBias,
+ SamplerDesc{}.MaxAnisotropy,
+ COMPARISON_FUNC_LESS
+};
+
+static const SamplerDesc Sam_Aniso2xClamp
+{
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ 0.f, // MipLODBias
+ 2 // MaxAnisotropy
+};
+
+static const SamplerDesc Sam_Aniso4xClamp
+{
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ 0.f, // MipLODBias
+ 4 // MaxAnisotropy
+};
+
+static const SamplerDesc Sam_Aniso8xClamp
+{
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ 0.f, // MipLODBias
+ 8 // MaxAnisotropy
+};
+
+static const SamplerDesc Sam_Aniso16xClamp
+{
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ TEXTURE_ADDRESS_CLAMP,
+ 0.f, // MipLODBias
+ 16 // MaxAnisotropy
+};
+
+static const SamplerDesc Sam_Aniso4xWrap
+{
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ TEXTURE_ADDRESS_WRAP,
+ TEXTURE_ADDRESS_WRAP,
+ TEXTURE_ADDRESS_WRAP,
+ 0.f, // MipLODBias
+ 4 // MaxAnisotropy
+};
+
+static const SamplerDesc Sam_Aniso8xWrap
+{
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ FILTER_TYPE_ANISOTROPIC,
+ TEXTURE_ADDRESS_WRAP,
+ TEXTURE_ADDRESS_WRAP,
+ TEXTURE_ADDRESS_WRAP,
+ 0.f, // MipLODBias
+ 8 // MaxAnisotropy
+};
- static const BlendStateDesc BS_AlphaBlend =
- {
- False, // AlphaToCoverageEnable
- False, // IndependentBlendEnable
- RenderTargetBlendDesc // Render Target 0
- {
- True, // BlendEnable
- False, // LogicOperationEnable
- BLEND_FACTOR_SRC_ALPHA, // SrcBlend
- BLEND_FACTOR_INV_SRC_ALPHA, // DestBlend
- BLEND_OPERATION_ADD, // BlendOp
- BLEND_FACTOR_SRC_ALPHA, // SrcBlendAlpha
- BLEND_FACTOR_INV_SRC_ALPHA, // DestBlendAlpha
- BLEND_OPERATION_ADD // BlendOpAlpha
- }
- };
-
-
- // Common sampler states
- static const SamplerDesc Sam_LinearClamp
- {
- FILTER_TYPE_LINEAR,
- FILTER_TYPE_LINEAR,
- FILTER_TYPE_LINEAR,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP
- };
-
- static const SamplerDesc Sam_PointClamp
- {
- FILTER_TYPE_POINT,
- FILTER_TYPE_POINT,
- FILTER_TYPE_POINT,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP
- };
-
- static const SamplerDesc Sam_LinearMirror
- {
- FILTER_TYPE_LINEAR,
- FILTER_TYPE_LINEAR,
- FILTER_TYPE_LINEAR,
- TEXTURE_ADDRESS_MIRROR,
- TEXTURE_ADDRESS_MIRROR,
- TEXTURE_ADDRESS_MIRROR
- };
-
- static const SamplerDesc Sam_PointWrap
- {
- FILTER_TYPE_POINT,
- FILTER_TYPE_POINT,
- FILTER_TYPE_POINT,
- TEXTURE_ADDRESS_WRAP,
- TEXTURE_ADDRESS_WRAP,
- TEXTURE_ADDRESS_WRAP
- };
-
- static const SamplerDesc Sam_LinearWrap
- {
- FILTER_TYPE_LINEAR,
- FILTER_TYPE_LINEAR,
- FILTER_TYPE_LINEAR,
- TEXTURE_ADDRESS_WRAP,
- TEXTURE_ADDRESS_WRAP,
- TEXTURE_ADDRESS_WRAP
- };
-
- static const SamplerDesc Sam_ComparsionLinearClamp
- {
- FILTER_TYPE_COMPARISON_LINEAR,
- FILTER_TYPE_COMPARISON_LINEAR,
- FILTER_TYPE_COMPARISON_LINEAR,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- SamplerDesc{}.MipLODBias,
- SamplerDesc{}.MaxAnisotropy,
- COMPARISON_FUNC_LESS
- };
-
- static const SamplerDesc Sam_Aniso2xClamp
- {
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- 0.f, // MipLODBias
- 2 // MaxAnisotropy
- };
-
- static const SamplerDesc Sam_Aniso4xClamp
- {
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- 0.f, // MipLODBias
- 4 // MaxAnisotropy
- };
-
- static const SamplerDesc Sam_Aniso8xClamp
- {
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- 0.f, // MipLODBias
- 8 // MaxAnisotropy
- };
-
- static const SamplerDesc Sam_Aniso16xClamp
- {
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- TEXTURE_ADDRESS_CLAMP,
- 0.f, // MipLODBias
- 16 // MaxAnisotropy
- };
-
- static const SamplerDesc Sam_Aniso4xWrap
- {
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- TEXTURE_ADDRESS_WRAP,
- TEXTURE_ADDRESS_WRAP,
- TEXTURE_ADDRESS_WRAP,
- 0.f, // MipLODBias
- 4 // MaxAnisotropy
- };
-
- static const SamplerDesc Sam_Aniso8xWrap
- {
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- FILTER_TYPE_ANISOTROPIC,
- TEXTURE_ADDRESS_WRAP,
- TEXTURE_ADDRESS_WRAP,
- TEXTURE_ADDRESS_WRAP,
- 0.f, // MipLODBias
- 8 // MaxAnisotropy
- };
}
diff --git a/Graphics/GraphicsTools/include/GraphicsUtilities.h b/Graphics/GraphicsTools/include/GraphicsUtilities.h
index 335f6c32..8638d211 100644
--- a/Graphics/GraphicsTools/include/GraphicsUtilities.h
+++ b/Graphics/GraphicsTools/include/GraphicsUtilities.h
@@ -32,14 +32,15 @@
namespace Diligent
{
-void CreateUniformBuffer(IRenderDevice* pDevice,
- Uint32 Size,
- const Char* Name,
- IBuffer** ppBuffer,
- USAGE Usage = USAGE_DYNAMIC,
- BIND_FLAGS BindFlags = BIND_UNIFORM_BUFFER,
- CPU_ACCESS_FLAGS CPUAccessFlags = CPU_ACCESS_WRITE,
- void* pInitialData = nullptr);
+
+void CreateUniformBuffer(IRenderDevice* pDevice,
+ Uint32 Size,
+ const Char* Name,
+ IBuffer** ppBuffer,
+ USAGE Usage = USAGE_DYNAMIC,
+ BIND_FLAGS BindFlags = BIND_UNIFORM_BUFFER,
+ CPU_ACCESS_FLAGS CPUAccessFlags = CPU_ACCESS_WRITE,
+ void* pInitialData = nullptr);
void GenerateCheckerBoardPattern(Uint32 Width,
Uint32 Height,
@@ -48,4 +49,5 @@ void GenerateCheckerBoardPattern(Uint32 Width,
Uint32 VertCells,
Uint8* pData,
Uint32 StrideInBytes);
-}
+
+} // namespace Diligent
diff --git a/Graphics/GraphicsTools/include/ScreenCapture.h b/Graphics/GraphicsTools/include/ScreenCapture.h
index d4f8533f..b49eedab 100644
--- a/Graphics/GraphicsTools/include/ScreenCapture.h
+++ b/Graphics/GraphicsTools/include/ScreenCapture.h
@@ -34,18 +34,18 @@
namespace Diligent
{
-
+
class ScreenCapture
{
public:
ScreenCapture(IRenderDevice* pDevice);
void Capture(ISwapChain* pSwapChain, IDeviceContext* pContext, Uint32 FrameId);
-
+
struct CaptureInfo
{
RefCntAutoPtr<ITexture> pTexture;
- Uint32 Id = 0;
+ Uint32 Id = 0;
operator bool() const
{
@@ -54,6 +54,7 @@ public:
};
CaptureInfo GetCapture();
+
void RecycleStagingTexture(RefCntAutoPtr<ITexture>&& pTexture);
size_t GetNumPendingCaptures()
@@ -69,13 +70,15 @@ private:
std::mutex m_AvailableTexturesMtx;
std::vector<RefCntAutoPtr<ITexture>> m_AvailableTextures;
- std::mutex m_PendingTexturesMtx;
+ std::mutex m_PendingTexturesMtx;
struct PendingTextureInfo
{
PendingTextureInfo(RefCntAutoPtr<ITexture>&& _pTex, Uint32 _Id, Uint64 _Fence) :
- pTex (std::move(_pTex)),
- Id (_Id),
- Fence (_Fence)
+ // clang-format off
+ pTex {std::move(_pTex)},
+ Id {_Id },
+ Fence {_Fence }
+ // clang-format on
{
}
@@ -88,4 +91,4 @@ private:
Uint64 m_CurrentFenceValue = 1;
};
-}
+} // namespace Diligent
diff --git a/Graphics/GraphicsTools/include/ShaderMacroHelper.h b/Graphics/GraphicsTools/include/ShaderMacroHelper.h
index 45e85ff7..44ea1290 100644
--- a/Graphics/GraphicsTools/include/ShaderMacroHelper.h
+++ b/Graphics/GraphicsTools/include/ShaderMacroHelper.h
@@ -52,23 +52,22 @@ namespace Diligent
class ShaderMacroHelper
{
public:
+ template <typename DefintionType>
+ void AddShaderMacro(const Char* Name, DefintionType Definition)
+ {
+ std::ostringstream ss;
+ ss << Definition;
+ AddShaderMacro<const Char*>(Name, ss.str().c_str());
+ }
- template<typename DefintionType>
- void AddShaderMacro( const Char* Name, DefintionType Definition )
- {
- std::ostringstream ss;
- ss << Definition;
- AddShaderMacro<const Char*>( Name, ss.str().c_str() );
- }
-
void Finalize()
- {
+ {
if (!m_bIsFinalized)
{
m_Macros.emplace_back(nullptr, nullptr);
m_bIsFinalized = true;
}
- }
+ }
void Reopen()
{
@@ -87,16 +86,16 @@ public:
m_bIsFinalized = false;
}
- operator const ShaderMacro* ()
- {
+ operator const ShaderMacro*()
+ {
if (m_Macros.size() > 0 && !m_bIsFinalized)
Finalize();
return m_Macros.size() ? m_Macros.data() : nullptr;
- }
-
+ }
+
void RemoveMacro(const Char* Name)
{
- size_t i=0;
+ size_t i = 0;
while (i < m_Macros.size() && m_Macros[i].Definition != nullptr)
{
if (strcmp(m_Macros[i].Name, Name) == 0)
@@ -111,56 +110,55 @@ public:
}
}
- template<typename DefintionType>
- void UpdateMacro( const Char* Name, DefintionType Definition )
- {
+ template <typename DefintionType>
+ void UpdateMacro(const Char* Name, DefintionType Definition)
+ {
RemoveMacro(Name);
AddShaderMacro(Name, Definition);
}
private:
-
- std::vector< ShaderMacro > m_Macros;
- std::set< std::string > m_DefinitionsPool;
- bool m_bIsFinalized = false;
+ std::vector<ShaderMacro> m_Macros;
+ std::set<std::string> m_DefinitionsPool;
+ bool m_bIsFinalized = false;
};
-template<>
-inline void ShaderMacroHelper::AddShaderMacro( const Char* Name, const Char* Definition )
+template <>
+inline void ShaderMacroHelper::AddShaderMacro(const Char* Name, const Char* Definition)
{
Reopen();
- auto *PooledDefinition = m_DefinitionsPool.insert(Definition).first->c_str();
- m_Macros.emplace_back(Name, PooledDefinition);
+ auto* PooledDefinition = m_DefinitionsPool.insert(Definition).first->c_str();
+ m_Macros.emplace_back(Name, PooledDefinition);
}
-template<>
-inline void ShaderMacroHelper::AddShaderMacro( const Char* Name, bool Definition )
+template <>
+inline void ShaderMacroHelper::AddShaderMacro(const Char* Name, bool Definition)
{
- AddShaderMacro( Name, Definition ? "1" : "0");
+ AddShaderMacro(Name, Definition ? "1" : "0");
}
-template<>
-inline void ShaderMacroHelper::AddShaderMacro( const Char* Name, float Definition )
+template <>
+inline void ShaderMacroHelper::AddShaderMacro(const Char* Name, float Definition)
{
- std::ostringstream ss;
-
+ std::ostringstream ss;
+
// Make sure that when floating point represents integer, it is still
// written as float: 1024.0, but not 1024. This is essnetial to
// avoid type conversion issues in GLES.
- if( Definition == static_cast<float>(static_cast<int>(Definition)) )
- ss << std::fixed << std::setprecision( 1 );
+ if (Definition == static_cast<float>(static_cast<int>(Definition)))
+ ss << std::fixed << std::setprecision(1);
- ss << Definition;
- AddShaderMacro<const Char*>( Name, ss.str().c_str() );
+ ss << Definition;
+ AddShaderMacro<const Char*>(Name, ss.str().c_str());
}
-template<>
-inline void ShaderMacroHelper::AddShaderMacro( const Char* Name, Uint32 Definition )
+template <>
+inline void ShaderMacroHelper::AddShaderMacro(const Char* Name, Uint32 Definition)
{
// Make sure that uint constants have the 'u' suffix to avoid problems in GLES.
- std::ostringstream ss;
- ss << Definition << 'u';
- AddShaderMacro<const Char*>( Name, ss.str().c_str() );
+ std::ostringstream ss;
+ ss << Definition << 'u';
+ AddShaderMacro<const Char*>(Name, ss.str().c_str());
}
-}
+} // namespace Diligent
diff --git a/Graphics/GraphicsTools/include/TextureUploader.h b/Graphics/GraphicsTools/include/TextureUploader.h
index 5da9f2d8..a67c7b9b 100644
--- a/Graphics/GraphicsTools/include/TextureUploader.h
+++ b/Graphics/GraphicsTools/include/TextureUploader.h
@@ -28,58 +28,61 @@
namespace Diligent
{
- struct UploadBufferDesc
- {
- Uint32 Width = 0;
- Uint32 Height = 0;
- Uint32 Depth = 1;
- Uint32 MipLevels = 1;
- Uint32 ArraySize = 1;
- TEXTURE_FORMAT Format = TEX_FORMAT_UNKNOWN;
- bool operator == (const UploadBufferDesc &rhs) const
- {
- return Width == rhs.Width &&
- Height == rhs.Height &&
- Depth == rhs.Depth &&
- Format == rhs.Format;
- }
- };
+// clang-format off
+struct UploadBufferDesc
+{
+ Uint32 Width = 0;
+ Uint32 Height = 0;
+ Uint32 Depth = 1;
+ Uint32 MipLevels = 1;
+ Uint32 ArraySize = 1;
+ TEXTURE_FORMAT Format = TEX_FORMAT_UNKNOWN;
- class IUploadBuffer : public IObject
+ bool operator == (const UploadBufferDesc &rhs) const
{
- public:
- virtual void WaitForCopyScheduled() = 0;
- virtual MappedTextureSubresource GetMappedData(Uint32 Mip, Uint32 Slice) = 0;
- virtual const UploadBufferDesc& GetDesc()const = 0;
- };
+ return Width == rhs.Width &&
+ Height == rhs.Height &&
+ Depth == rhs.Depth &&
+ Format == rhs.Format;
+ }
+};
+// clang-format on
- struct TextureUploaderDesc
- {
+class IUploadBuffer : public IObject
+{
+public:
+ virtual void WaitForCopyScheduled() = 0;
+ virtual MappedTextureSubresource GetMappedData(Uint32 Mip, Uint32 Slice) = 0;
+ virtual const UploadBufferDesc& GetDesc() const = 0;
+};
+
+struct TextureUploaderDesc
+{
+};
- };
+struct TextureUploaderStats
+{
+ Uint32 NumPendingOperations = 0;
+};
- struct TextureUploaderStats
- {
- Uint32 NumPendingOperations = 0;
- };
+class ITextureUploader : public IObject
+{
+public:
+ virtual void RenderThreadUpdate(IDeviceContext* pContext) = 0;
- class ITextureUploader : public IObject
- {
- public:
- virtual void RenderThreadUpdate(IDeviceContext* pContext) = 0;
+ virtual void AllocateUploadBuffer(const UploadBufferDesc& Desc,
+ bool IsRenderThread,
+ IUploadBuffer** ppBuffer) = 0;
+ virtual void ScheduleGPUCopy(ITexture* pDstTexture,
+ Uint32 ArraySlice,
+ Uint32 MipLevel,
+ IUploadBuffer* pUploadBuffer) = 0;
+ virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer) = 0;
- virtual void AllocateUploadBuffer(const UploadBufferDesc& Desc,
- bool IsRenderThread,
- IUploadBuffer** ppBuffer) = 0;
- virtual void ScheduleGPUCopy(ITexture* pDstTexture,
- Uint32 ArraySlice,
- Uint32 MipLevel,
- IUploadBuffer* pUploadBuffer) = 0;
- virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer) = 0;
+ virtual TextureUploaderStats GetStats() = 0;
+};
- virtual TextureUploaderStats GetStats() = 0;
- };
+void CreateTextureUploader(IRenderDevice* pDevice, const TextureUploaderDesc& Desc, ITextureUploader** ppUploader);
- void CreateTextureUploader(IRenderDevice* pDevice, const TextureUploaderDesc& Desc, ITextureUploader** ppUploader);
-}
+} // namespace Diligent
diff --git a/Graphics/GraphicsTools/include/TextureUploaderBase.h b/Graphics/GraphicsTools/include/TextureUploaderBase.h
index 21d7174a..5481b1a2 100644
--- a/Graphics/GraphicsTools/include/TextureUploaderBase.h
+++ b/Graphics/GraphicsTools/include/TextureUploaderBase.h
@@ -32,68 +32,72 @@
namespace std
{
- template<>
- struct hash<Diligent::UploadBufferDesc>
+
+template <>
+struct hash<Diligent::UploadBufferDesc>
+{
+ size_t operator()(const Diligent::UploadBufferDesc& Desc) const
{
- size_t operator()(const Diligent::UploadBufferDesc &Desc) const
- {
- return Diligent::ComputeHash(Desc.Width, Desc.Height, Desc.Depth, static_cast<Diligent::Int32>(Desc.Format));
- }
- };
-}
+ return Diligent::ComputeHash(Desc.Width, Desc.Height, Desc.Depth, static_cast<Diligent::Int32>(Desc.Format));
+ }
+};
+
+} // namespace std
namespace Diligent
{
- class UploadBufferBase : public ObjectBase<IUploadBuffer>
+class UploadBufferBase : public ObjectBase<IUploadBuffer>
+{
+public:
+ UploadBufferBase(IReferenceCounters* pRefCounters, const UploadBufferDesc& Desc) :
+ // clang-format off
+ ObjectBase<IUploadBuffer>{pRefCounters},
+ m_Desc {Desc},
+ m_MappedData {m_Desc.ArraySize * m_Desc.MipLevels}
+ // clang-format on
{
- public:
- UploadBufferBase(IReferenceCounters *pRefCounters, const UploadBufferDesc &Desc) :
- ObjectBase<IUploadBuffer>(pRefCounters),
- m_Desc(Desc),
- m_MappedData(m_Desc.ArraySize * m_Desc.MipLevels)
- {
- }
+ }
- virtual MappedTextureSubresource GetMappedData(Uint32 Mip, Uint32 Slice)override final
- {
- VERIFY_EXPR(Mip < m_Desc.MipLevels && Slice < m_Desc.ArraySize);
- return m_MappedData[m_Desc.MipLevels * Slice + Mip];
- }
- virtual const UploadBufferDesc& GetDesc()const override final{ return m_Desc; }
+ virtual MappedTextureSubresource GetMappedData(Uint32 Mip, Uint32 Slice) override final
+ {
+ VERIFY_EXPR(Mip < m_Desc.MipLevels && Slice < m_Desc.ArraySize);
+ return m_MappedData[m_Desc.MipLevels * Slice + Mip];
+ }
+ virtual const UploadBufferDesc& GetDesc() const override final { return m_Desc; }
- void SetMappedData(Uint32 Mip, Uint32 Slice, const MappedTextureSubresource& MappedData)
- {
- VERIFY_EXPR(Mip < m_Desc.MipLevels && Slice < m_Desc.ArraySize);
- m_MappedData[m_Desc.MipLevels * Slice + Mip] = MappedData;
- }
+ void SetMappedData(Uint32 Mip, Uint32 Slice, const MappedTextureSubresource& MappedData)
+ {
+ VERIFY_EXPR(Mip < m_Desc.MipLevels && Slice < m_Desc.ArraySize);
+ m_MappedData[m_Desc.MipLevels * Slice + Mip] = MappedData;
+ }
- bool IsMapped(Uint32 Mip, Uint32 Slice)const
- {
- VERIFY_EXPR(Mip < m_Desc.MipLevels && Slice < m_Desc.ArraySize);
- return m_MappedData[m_Desc.MipLevels * Slice + Mip].pData != nullptr;
- }
+ bool IsMapped(Uint32 Mip, Uint32 Slice) const
+ {
+ VERIFY_EXPR(Mip < m_Desc.MipLevels && Slice < m_Desc.ArraySize);
+ return m_MappedData[m_Desc.MipLevels * Slice + Mip].pData != nullptr;
+ }
- void Reset()
- {
- for (auto& MappedData : m_MappedData)
- MappedData = MappedTextureSubresource{};
- }
+ void Reset()
+ {
+ for (auto& MappedData : m_MappedData)
+ MappedData = MappedTextureSubresource{};
+ }
- protected:
- const UploadBufferDesc m_Desc;
- std::vector<MappedTextureSubresource> m_MappedData;
- };
+protected:
+ const UploadBufferDesc m_Desc;
+ std::vector<MappedTextureSubresource> m_MappedData;
+};
- class TextureUploaderBase : public ObjectBase<ITextureUploader>
- {
- public:
- TextureUploaderBase(IReferenceCounters* pRefCounters, IRenderDevice* pDevice, const TextureUploaderDesc Desc) :
- ObjectBase<ITextureUploader>(pRefCounters),
- m_pDevice(pDevice)
- {}
+class TextureUploaderBase : public ObjectBase<ITextureUploader>
+{
+public:
+ TextureUploaderBase(IReferenceCounters* pRefCounters, IRenderDevice* pDevice, const TextureUploaderDesc Desc) :
+ ObjectBase<ITextureUploader>{pRefCounters},
+ m_pDevice{pDevice}
+ {}
- protected:
- RefCntAutoPtr<IRenderDevice> m_pDevice;
- };
+protected:
+ RefCntAutoPtr<IRenderDevice> m_pDevice;
+};
-}
+} // namespace Diligent
diff --git a/Graphics/GraphicsTools/include/TextureUploaderD3D11.h b/Graphics/GraphicsTools/include/TextureUploaderD3D11.h
index f03d3f01..9de6d84e 100644
--- a/Graphics/GraphicsTools/include/TextureUploaderD3D11.h
+++ b/Graphics/GraphicsTools/include/TextureUploaderD3D11.h
@@ -27,28 +27,33 @@
namespace Diligent
{
- class TextureUploaderD3D11 : public TextureUploaderBase
- {
- public:
- TextureUploaderD3D11(IReferenceCounters* pRefCounters,
- IRenderDevice* pDevice,
- const TextureUploaderDesc Desc);
- ~TextureUploaderD3D11();
- virtual void RenderThreadUpdate(IDeviceContext* pContext)override final;
-
- virtual void AllocateUploadBuffer(const UploadBufferDesc& Desc,
- bool IsRenderThread,
- IUploadBuffer** ppBuffer)override final;
- virtual void ScheduleGPUCopy(ITexture* pDstTexture,
- Uint32 ArraySlice,
- Uint32 MipLevel,
- IUploadBuffer* pUploadBuffer)override final;
- virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer)override final;
-
- virtual TextureUploaderStats GetStats()override final;
-
- private:
- struct InternalData;
- std::unique_ptr<InternalData> m_pInternalData;
- };
-} \ No newline at end of file
+
+class TextureUploaderD3D11 : public TextureUploaderBase
+{
+public:
+ TextureUploaderD3D11(IReferenceCounters* pRefCounters,
+ IRenderDevice* pDevice,
+ const TextureUploaderDesc Desc);
+ ~TextureUploaderD3D11();
+
+ virtual void RenderThreadUpdate(IDeviceContext* pContext) override final;
+
+ virtual void AllocateUploadBuffer(const UploadBufferDesc& Desc,
+ bool IsRenderThread,
+ IUploadBuffer** ppBuffer) override final;
+
+ virtual void ScheduleGPUCopy(ITexture* pDstTexture,
+ Uint32 ArraySlice,
+ Uint32 MipLevel,
+ IUploadBuffer* pUploadBuffer) override final;
+
+ virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer) override final;
+
+ virtual TextureUploaderStats GetStats() override final;
+
+private:
+ struct InternalData;
+ std::unique_ptr<InternalData> m_pInternalData;
+};
+
+} // namespace Diligent \ No newline at end of file
diff --git a/Graphics/GraphicsTools/include/TextureUploaderD3D12_Vk.h b/Graphics/GraphicsTools/include/TextureUploaderD3D12_Vk.h
index 2b55c116..b3ca4bef 100644
--- a/Graphics/GraphicsTools/include/TextureUploaderD3D12_Vk.h
+++ b/Graphics/GraphicsTools/include/TextureUploaderD3D12_Vk.h
@@ -27,28 +27,33 @@
namespace Diligent
{
- class TextureUploaderD3D12_Vk : public TextureUploaderBase
- {
- public:
- TextureUploaderD3D12_Vk(IReferenceCounters* pRefCounters,
- IRenderDevice* pDevice,
- const TextureUploaderDesc Desc);
- ~TextureUploaderD3D12_Vk();
- virtual void RenderThreadUpdate(IDeviceContext* pContext)override final;
-
- virtual void AllocateUploadBuffer(const UploadBufferDesc& Desc,
- bool IsRenderThread,
- IUploadBuffer** ppBuffer)override final;
- virtual void ScheduleGPUCopy(ITexture* pDstTexture,
- Uint32 ArraySlice,
- Uint32 MipLevel,
- IUploadBuffer* pUploadBuffer)override final;
- virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer)override final;
-
- virtual TextureUploaderStats GetStats()override final;
-
- private:
- struct InternalData;
- std::unique_ptr<InternalData> m_pInternalData;
- };
-}
+
+class TextureUploaderD3D12_Vk : public TextureUploaderBase
+{
+public:
+ TextureUploaderD3D12_Vk(IReferenceCounters* pRefCounters,
+ IRenderDevice* pDevice,
+ const TextureUploaderDesc Desc);
+ ~TextureUploaderD3D12_Vk();
+
+ virtual void RenderThreadUpdate(IDeviceContext* pContext) override final;
+
+ virtual void AllocateUploadBuffer(const UploadBufferDesc& Desc,
+ bool IsRenderThread,
+ IUploadBuffer** ppBuffer) override final;
+
+ virtual void ScheduleGPUCopy(ITexture* pDstTexture,
+ Uint32 ArraySlice,
+ Uint32 MipLevel,
+ IUploadBuffer* pUploadBuffer) override final;
+
+ virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer) override final;
+
+ virtual TextureUploaderStats GetStats() override final;
+
+private:
+ struct InternalData;
+ std::unique_ptr<InternalData> m_pInternalData;
+};
+
+} // namespace Diligent
diff --git a/Graphics/GraphicsTools/include/TextureUploaderGL.h b/Graphics/GraphicsTools/include/TextureUploaderGL.h
index 40758f72..8d4fb3b2 100644
--- a/Graphics/GraphicsTools/include/TextureUploaderGL.h
+++ b/Graphics/GraphicsTools/include/TextureUploaderGL.h
@@ -27,28 +27,33 @@
namespace Diligent
{
- class TextureUploaderGL : public TextureUploaderBase
- {
- public:
- TextureUploaderGL(IReferenceCounters* pRefCounters,
- IRenderDevice* pDevice,
- const TextureUploaderDesc Desc);
- ~TextureUploaderGL();
- virtual void RenderThreadUpdate(IDeviceContext* pContext)override final;
-
- virtual void AllocateUploadBuffer(const UploadBufferDesc& Desc,
- bool IsRenderThread,
- IUploadBuffer** ppBuffer)override final;
- virtual void ScheduleGPUCopy(ITexture* pDstTexture,
- Uint32 ArraySlice,
- Uint32 MipLevel,
- IUploadBuffer* pUploadBuffer)override final;
- virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer)override final;
-
- virtual TextureUploaderStats GetStats()override final;
-
- private:
- struct InternalData;
- std::unique_ptr<InternalData> m_pInternalData;
- };
-}
+
+class TextureUploaderGL : public TextureUploaderBase
+{
+public:
+ TextureUploaderGL(IReferenceCounters* pRefCounters,
+ IRenderDevice* pDevice,
+ const TextureUploaderDesc Desc);
+ ~TextureUploaderGL();
+
+ virtual void RenderThreadUpdate(IDeviceContext* pContext) override final;
+
+ virtual void AllocateUploadBuffer(const UploadBufferDesc& Desc,
+ bool IsRenderThread,
+ IUploadBuffer** ppBuffer) override final;
+
+ virtual void ScheduleGPUCopy(ITexture* pDstTexture,
+ Uint32 ArraySlice,
+ Uint32 MipLevel,
+ IUploadBuffer* pUploadBuffer) override final;
+
+ virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer) override final;
+
+ virtual TextureUploaderStats GetStats() override final;
+
+private:
+ struct InternalData;
+ std::unique_ptr<InternalData> m_pInternalData;
+};
+
+} // namespace Diligent
diff --git a/Graphics/GraphicsTools/include/pch.h b/Graphics/GraphicsTools/include/pch.h
index 71992bee..e8997cc7 100644
--- a/Graphics/GraphicsTools/include/pch.h
+++ b/Graphics/GraphicsTools/include/pch.h
@@ -22,5 +22,3 @@
*/
#pragma once
-
-
diff --git a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp
index 62e10ab6..5c127ec9 100644
--- a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp
+++ b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp
@@ -35,21 +35,21 @@
namespace Diligent
{
-void CreateUniformBuffer(IRenderDevice* pDevice,
- Uint32 Size,
- const Char* Name,
- IBuffer** ppBuffer,
- USAGE Usage,
- BIND_FLAGS BindFlags,
- CPU_ACCESS_FLAGS CPUAccessFlags,
- void* pInitialData)
+void CreateUniformBuffer(IRenderDevice* pDevice,
+ Uint32 Size,
+ const Char* Name,
+ IBuffer** ppBuffer,
+ USAGE Usage,
+ BIND_FLAGS BindFlags,
+ CPU_ACCESS_FLAGS CPUAccessFlags,
+ void* pInitialData)
{
BufferDesc CBDesc;
- CBDesc.Name = Name;
- CBDesc.uiSizeInBytes = Size;
- CBDesc.Usage = Usage;
- CBDesc.BindFlags = BindFlags;
- CBDesc.CPUAccessFlags = CPUAccessFlags;
+ CBDesc.Name = Name;
+ CBDesc.uiSizeInBytes = Size;
+ CBDesc.Usage = Usage;
+ CBDesc.BindFlags = BindFlags;
+ CBDesc.CPUAccessFlags = CPUAccessFlags;
BufferData InitialData;
if (pInitialData != nullptr)
@@ -57,10 +57,10 @@ void CreateUniformBuffer(IRenderDevice* pDevice,
InitialData.pData = pInitialData;
InitialData.DataSize = Size;
}
- pDevice->CreateBuffer( CBDesc, pInitialData != nullptr ? &InitialData : nullptr, ppBuffer );
+ pDevice->CreateBuffer(CBDesc, pInitialData != nullptr ? &InitialData : nullptr, ppBuffer);
}
-template<class TConverter>
+template <class TConverter>
void GenerateCheckerBoardPatternInternal(Uint32 Width, Uint32 Height, TEXTURE_FORMAT Fmt, Uint32 HorzCells, Uint32 VertCells, Uint8* pData, Uint32 StrideInBytes, TConverter Converter)
{
const auto& FmtAttribs = GetTextureFormatAttribs(Fmt);
@@ -68,13 +68,13 @@ void GenerateCheckerBoardPatternInternal(Uint32 Width, Uint32 Height, TEXTURE_FO
{
for (Uint32 x = 0; x < Width; ++x)
{
- float horzWave = sin((static_cast<float>(x) + 0.5f) / static_cast<float>(Width) * PI_F * static_cast<float>(HorzCells));
- float vertWave = sin((static_cast<float>(y) + 0.5f) / static_cast<float>(Height) * PI_F * static_cast<float>(VertCells));
- float val = horzWave * vertWave;
- val = std::max( std::min( val*20.f, +1.f), -1.f );
- val = val * 0.5f + 1.f;
- val = val * 0.5f + 0.25f;
- Uint8 *pDstTexel = pData + x * Uint32{FmtAttribs.NumComponents} * Uint32{FmtAttribs.ComponentSize} + y * StrideInBytes;
+ float horzWave = sin((static_cast<float>(x) + 0.5f) / static_cast<float>(Width) * PI_F * static_cast<float>(HorzCells));
+ float vertWave = sin((static_cast<float>(y) + 0.5f) / static_cast<float>(Height) * PI_F * static_cast<float>(VertCells));
+ float val = horzWave * vertWave;
+ val = std::max(std::min(val * 20.f, +1.f), -1.f);
+ val = val * 0.5f + 1.f;
+ val = val * 0.5f + 0.25f;
+ Uint8* pDstTexel = pData + x * Uint32{FmtAttribs.NumComponents} * Uint32{FmtAttribs.ComponentSize} + y * StrideInBytes;
Converter(pDstTexel, Uint32{FmtAttribs.NumComponents}, val);
}
}
@@ -85,39 +85,46 @@ void GenerateCheckerBoardPattern(Uint32 Width, Uint32 Height, TEXTURE_FORMAT Fmt
const auto& FmtAttribs = GetTextureFormatAttribs(Fmt);
switch (FmtAttribs.ComponentType)
{
- case COMPONENT_TYPE_UINT:
- case COMPONENT_TYPE_UNORM:
- GenerateCheckerBoardPatternInternal(Width, Height, Fmt, HorzCells, VertCells, pData, StrideInBytes,
- [](Uint8 *pDstTexel, Uint32 NumComponents, float fVal)
- {
- Uint8 uVal = static_cast<Uint8>(fVal * 255.f);
- for (Uint32 c = 0; c < NumComponents; ++c)
- pDstTexel[c] = uVal;
- });
- break;
+ case COMPONENT_TYPE_UINT:
+ case COMPONENT_TYPE_UNORM:
+ GenerateCheckerBoardPatternInternal(
+ Width, Height, Fmt, HorzCells, VertCells, pData, StrideInBytes,
+ [](Uint8* pDstTexel, Uint32 NumComponents, float fVal) //
+ {
+ Uint8 uVal = static_cast<Uint8>(fVal * 255.f);
+ for (Uint32 c = 0; c < NumComponents; ++c)
+ pDstTexel[c] = uVal;
+ } //
+ );
+ break;
- case COMPONENT_TYPE_UNORM_SRGB:
- GenerateCheckerBoardPatternInternal(Width, Height, Fmt, HorzCells, VertCells, pData, StrideInBytes,
- [](Uint8 *pDstTexel, Uint32 NumComponents, float fVal)
- {
- Uint8 uVal = static_cast<Uint8>( FastLinearToSRGB(fVal) * 255.f);
- for (Uint32 c = 0; c < NumComponents; ++c)
- pDstTexel[c] = uVal;
- });
- break;
+ case COMPONENT_TYPE_UNORM_SRGB:
+ GenerateCheckerBoardPatternInternal(
+ Width, Height, Fmt, HorzCells, VertCells, pData, StrideInBytes,
+ [](Uint8* pDstTexel, Uint32 NumComponents, float fVal) //
+ {
+ Uint8 uVal = static_cast<Uint8>(FastLinearToSRGB(fVal) * 255.f);
+ for (Uint32 c = 0; c < NumComponents; ++c)
+ pDstTexel[c] = uVal;
+ } //
+ );
+ break;
- case COMPONENT_TYPE_FLOAT:
- GenerateCheckerBoardPatternInternal(Width, Height, Fmt, HorzCells, VertCells, pData, StrideInBytes,
- [](Uint8 *pDstTexel, Uint32 NumComponents, float fVal)
- {
- for (Uint32 c = 0; c < NumComponents; ++c)
- (reinterpret_cast<float*>(pDstTexel))[c] = fVal;
- });
- break;
+ case COMPONENT_TYPE_FLOAT:
+ GenerateCheckerBoardPatternInternal(
+ Width, Height, Fmt, HorzCells, VertCells, pData, StrideInBytes,
+ [](Uint8* pDstTexel, Uint32 NumComponents, float fVal) //
+ {
+ for (Uint32 c = 0; c < NumComponents; ++c)
+ (reinterpret_cast<float*>(pDstTexel))[c] = fVal;
+ } //
+ );
+ break;
- default:
- UNSUPPORTED("Unsupported component type");
- return;
+ default:
+ UNSUPPORTED("Unsupported component type");
+ return;
}
}
-}
+
+} // namespace Diligent
diff --git a/Graphics/GraphicsTools/src/ScreenCapture.cpp b/Graphics/GraphicsTools/src/ScreenCapture.cpp
index 20b8fd6a..bcd87495 100644
--- a/Graphics/GraphicsTools/src/ScreenCapture.cpp
+++ b/Graphics/GraphicsTools/src/ScreenCapture.cpp
@@ -28,7 +28,7 @@ namespace Diligent
{
ScreenCapture::ScreenCapture(IRenderDevice* pDevice) :
- m_pDevice(pDevice)
+ m_pDevice{pDevice}
{
FenceDesc fenceDesc;
fenceDesc.Name = "Screen capture fence";
@@ -37,9 +37,9 @@ ScreenCapture::ScreenCapture(IRenderDevice* pDevice) :
void ScreenCapture::Capture(ISwapChain* pSwapChain, IDeviceContext* pContext, Uint32 FrameId)
{
- auto* pCurrentRTV = pSwapChain->GetCurrentBackBufferRTV();
- auto* pCurrentBackBuffer = pCurrentRTV->GetTexture();
- const auto& SCDesc = pSwapChain->GetDesc();
+ auto* pCurrentRTV = pSwapChain->GetCurrentBackBufferRTV();
+ auto* pCurrentBackBuffer = pCurrentRTV->GetTexture();
+ const auto& SCDesc = pSwapChain->GetDesc();
RefCntAutoPtr<ITexture> pStagingTexture;
@@ -50,9 +50,9 @@ void ScreenCapture::Capture(ISwapChain* pSwapChain, IDeviceContext* pContext, Ui
pStagingTexture = std::move(m_AvailableTextures.back());
m_AvailableTextures.pop_back();
const auto& TexDesc = pStagingTexture->GetDesc();
- if ( !(TexDesc.Width == SCDesc.Width &&
- TexDesc.Height == SCDesc.Height &&
- TexDesc.Format == SCDesc.ColorBufferFormat) )
+ if (!(TexDesc.Width == SCDesc.Width &&
+ TexDesc.Height == SCDesc.Height &&
+ TexDesc.Format == SCDesc.ColorBufferFormat))
{
pStagingTexture.Release();
}
@@ -88,11 +88,12 @@ void ScreenCapture::Capture(ISwapChain* pSwapChain, IDeviceContext* pContext, Ui
ScreenCapture::CaptureInfo ScreenCapture::GetCapture()
{
CaptureInfo Capture;
+
std::lock_guard<std::mutex> Lock{m_PendingTexturesMtx};
if (!m_PendingTextures.empty())
{
- auto& OldestCapture = m_PendingTextures.front();
- auto CompletedFenceValue = m_pFence->GetCompletedValue();
+ auto& OldestCapture = m_PendingTextures.front();
+ auto CompletedFenceValue = m_pFence->GetCompletedValue();
if (OldestCapture.Fence <= CompletedFenceValue)
{
Capture.pTexture = std::move(OldestCapture.pTex);
@@ -109,4 +110,4 @@ void ScreenCapture::RecycleStagingTexture(RefCntAutoPtr<ITexture>&& pTexture)
m_AvailableTextures.emplace_back(std::move(pTexture));
}
-}
+} // namespace Diligent
diff --git a/Graphics/GraphicsTools/src/TextureUploader.cpp b/Graphics/GraphicsTools/src/TextureUploader.cpp
index 22760eeb..9b7e19ce 100644
--- a/Graphics/GraphicsTools/src/TextureUploader.cpp
+++ b/Graphics/GraphicsTools/src/TextureUploader.cpp
@@ -28,29 +28,31 @@
namespace Diligent
{
- void CreateTextureUploader(IRenderDevice *pDevice, const TextureUploaderDesc& Desc, ITextureUploader **ppUploader)
+
+void CreateTextureUploader(IRenderDevice* pDevice, const TextureUploaderDesc& Desc, ITextureUploader** ppUploader)
+{
+ *ppUploader = nullptr;
+ switch (pDevice->GetDeviceCaps().DevType)
{
- *ppUploader = nullptr;
- switch (pDevice->GetDeviceCaps().DevType)
- {
- case DeviceType::D3D11:
- *ppUploader = MakeNewRCObj<TextureUploaderD3D11>()( pDevice, Desc );
- break;
+ case DeviceType::D3D11:
+ *ppUploader = MakeNewRCObj<TextureUploaderD3D11>()(pDevice, Desc);
+ break;
- case DeviceType::D3D12:
- case DeviceType::Vulkan:
- *ppUploader = MakeNewRCObj<TextureUploaderD3D12_Vk>()( pDevice, Desc );
- break;
+ case DeviceType::D3D12:
+ case DeviceType::Vulkan:
+ *ppUploader = MakeNewRCObj<TextureUploaderD3D12_Vk>()(pDevice, Desc);
+ break;
- case DeviceType::OpenGLES:
- case DeviceType::OpenGL:
- *ppUploader = MakeNewRCObj<TextureUploaderGL>()( pDevice, Desc );
- break;
-
- default:
- UNEXPECTED("Unexpected device type");
- }
- if (*ppUploader != nullptr)
- (*ppUploader)->AddRef();
+ case DeviceType::OpenGLES:
+ case DeviceType::OpenGL:
+ *ppUploader = MakeNewRCObj<TextureUploaderGL>()(pDevice, Desc);
+ break;
+
+ default:
+ UNEXPECTED("Unexpected device type");
}
+ if (*ppUploader != nullptr)
+ (*ppUploader)->AddRef();
}
+
+} // namespace Diligent
diff --git a/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp b/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp
index 0f6d0ae0..55c4f755 100644
--- a/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp
+++ b/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp
@@ -48,9 +48,9 @@ namespace
class UploadBufferD3D11 : public UploadBufferBase
{
public:
- UploadBufferD3D11(IReferenceCounters *pRefCounters, const UploadBufferDesc &Desc, ID3D11Texture2D *pStagingTexture) :
- UploadBufferBase(pRefCounters, Desc),
- m_pStagingTexture(pStagingTexture)
+ UploadBufferD3D11(IReferenceCounters* pRefCounters, const UploadBufferDesc& Desc, ID3D11Texture2D* pStagingTexture) :
+ UploadBufferBase{pRefCounters, Desc},
+ m_pStagingTexture{pStagingTexture}
{}
~UploadBufferD3D11()
@@ -73,7 +73,7 @@ public:
m_CopyScheduledSignal.Trigger();
}
- virtual void WaitForCopyScheduled()override final
+ virtual void WaitForCopyScheduled() override final
{
m_CopyScheduledSignal.Wait();
}
@@ -96,9 +96,10 @@ public:
}
ID3D11Texture2D* GetStagingTex() { return m_pStagingTexture; }
+
private:
- ThreadingTools::Signal m_BufferMappedSignal;
- ThreadingTools::Signal m_CopyScheduledSignal;
+ ThreadingTools::Signal m_BufferMappedSignal;
+ ThreadingTools::Signal m_CopyScheduledSignal;
CComPtr<ID3D11Texture2D> m_pStagingTexture;
};
@@ -114,25 +115,27 @@ struct TextureUploaderD3D11::InternalData
Map,
Copy,
MapAndCache
- }operation;
+ } operation;
RefCntAutoPtr<UploadBufferD3D11> pUploadBuffer;
- CComPtr<ID3D11Resource> pd3d11NativeDstTexture;
- Uint32 DstMip = 0;
- Uint32 DstSlice = 0;
- Uint32 DstMipLevels = 0;
+ CComPtr<ID3D11Resource> pd3d11NativeDstTexture;
+ Uint32 DstMip = 0;
+ Uint32 DstSlice = 0;
+ Uint32 DstMipLevels = 0;
+ // clang-format off
PendingBufferOperation(Operation op, UploadBufferD3D11* pBuff) :
- operation (op),
- pUploadBuffer(pBuff)
+ operation {op },
+ pUploadBuffer{pBuff}
{}
PendingBufferOperation(Operation op, UploadBufferD3D11* pBuff, ID3D11Resource* pd3d11DstTex, Uint32 Mip, Uint32 Slice, Uint32 MipLevels) :
- operation (op),
- pUploadBuffer (pBuff),
- pd3d11NativeDstTexture(pd3d11DstTex),
- DstMip (Mip),
- DstSlice (Slice),
- DstMipLevels (MipLevels)
+ operation {op },
+ pUploadBuffer {pBuff },
+ pd3d11NativeDstTexture{pd3d11DstTex},
+ DstMip {Mip },
+ DstSlice {Slice },
+ DstMipLevels {MipLevels }
{}
+ // clang-format on
};
InternalData(IRenderDevice* pDevice)
@@ -155,29 +158,29 @@ struct TextureUploaderD3D11::InternalData
m_PendingOperations.emplace_back(PendingBufferOperation::Operation::Copy, pUploadBuffer, pd3d11DstTex, Mip, Slice, MipLevels);
}
- void EnqueMap(UploadBufferD3D11 *pUploadBuffer, PendingBufferOperation::Operation Op)
+ void EnqueMap(UploadBufferD3D11* pUploadBuffer, PendingBufferOperation::Operation Op)
{
std::lock_guard<std::mutex> QueueLock(m_PendingOperationsMtx);
m_PendingOperations.emplace_back(Op, pUploadBuffer);
}
- std::mutex m_PendingOperationsMtx;
- std::vector< PendingBufferOperation > m_PendingOperations;
- std::vector< PendingBufferOperation > m_InWorkOperations;
+ std::mutex m_PendingOperationsMtx;
+ std::vector<PendingBufferOperation> m_PendingOperations;
+ std::vector<PendingBufferOperation> m_InWorkOperations;
- std::mutex m_UploadBuffCacheMtx;
- std::unordered_map< UploadBufferDesc, std::deque< RefCntAutoPtr<UploadBufferD3D11> > > m_UploadBufferCache;
+ std::mutex m_UploadBuffCacheMtx;
+ std::unordered_map<UploadBufferDesc, std::deque<RefCntAutoPtr<UploadBufferD3D11>>> m_UploadBufferCache;
};
-TextureUploaderD3D11::TextureUploaderD3D11(IReferenceCounters *pRefCounters, IRenderDevice *pDevice, const TextureUploaderDesc Desc) :
- TextureUploaderBase(pRefCounters, pDevice, Desc),
- m_pInternalData(new InternalData(pDevice))
+TextureUploaderD3D11::TextureUploaderD3D11(IReferenceCounters* pRefCounters, IRenderDevice* pDevice, const TextureUploaderDesc Desc) :
+ TextureUploaderBase{pRefCounters, pDevice, Desc},
+ m_pInternalData{new InternalData(pDevice)}
{
}
TextureUploaderD3D11::~TextureUploaderD3D11()
{
- auto Stats = TextureUploaderD3D11::GetStats();
+ auto Stats = TextureUploaderD3D11::GetStats();
if (Stats.NumPendingOperations != 0)
{
LOG_WARNING_MESSAGE("TextureUploaderD3D11::~TextureUploaderD3D11(): there ", (Stats.NumPendingOperations > 1 ? "are " : "is "),
@@ -190,8 +193,8 @@ TextureUploaderD3D11::~TextureUploaderD3D11()
{
if (BuffQueueIt.second.size())
{
- const auto &desc = BuffQueueIt.first;
- auto &FmtInfo = m_pDevice->GetTextureFormatInfo(desc.Format);
+ const auto& desc = BuffQueueIt.first;
+ auto& FmtInfo = m_pDevice->GetTextureFormatInfo(desc.Format);
LOG_INFO_MESSAGE("TextureUploaderD3D11: releasing ", BuffQueueIt.second.size(), ' ', desc.Width, 'x', desc.Height, 'x', desc.Depth, ' ', FmtInfo.Name, " staging texture(s) ");
}
}
@@ -203,11 +206,12 @@ void TextureUploaderD3D11::RenderThreadUpdate(IDeviceContext* pContext)
if (!m_pInternalData->m_InWorkOperations.empty())
{
RefCntAutoPtr<IDeviceContextD3D11> pContextD3D11(pContext, IID_DeviceContextD3D11);
+
auto* pd3d11NativeCtx = pContextD3D11->GetD3D11DeviceContext();
- for (auto &OperationInfo : m_pInternalData->m_InWorkOperations)
+ for (auto& OperationInfo : m_pInternalData->m_InWorkOperations)
{
- auto& pBuffer = OperationInfo.pUploadBuffer;
+ auto& pBuffer = OperationInfo.pUploadBuffer;
const auto& UploadBuffDesc = pBuffer->GetDesc();
switch (OperationInfo.operation)
@@ -223,8 +227,9 @@ void TextureUploaderD3D11::RenderThreadUpdate(IDeviceContext* pContext)
if (!pBuffer->IsMapped(Mip, Slice))
{
D3D11_MAPPED_SUBRESOURCE MappedData;
+
UINT Subres = D3D11CalcSubresource(static_cast<UINT>(Mip), static_cast<UINT>(Slice), static_cast<UINT>(UploadBuffDesc.MipLevels));
- auto hr = pd3d11NativeCtx->Map(pBuffer->GetStagingTex(), Subres, D3D11_MAP_WRITE, D3D11_MAP_FLAG_DO_NOT_WAIT, &MappedData);
+ auto hr = pd3d11NativeCtx->Map(pBuffer->GetStagingTex(), Subres, D3D11_MAP_WRITE, D3D11_MAP_FLAG_DO_NOT_WAIT, &MappedData);
if (SUCCEEDED(hr))
{
pBuffer->SetMappedData(Mip, Slice, MappedTextureSubresource{MappedData.pData, MappedData.RowPitch, MappedData.DepthPitch});
@@ -250,8 +255,8 @@ void TextureUploaderD3D11::RenderThreadUpdate(IDeviceContext* pContext)
if (OperationInfo.operation == InternalData::PendingBufferOperation::MapAndCache)
{
std::lock_guard<std::mutex> CacheLock(m_pInternalData->m_UploadBuffCacheMtx);
- auto &Cache = m_pInternalData->m_UploadBufferCache;
- Cache[pBuffer->GetDesc()].emplace_back( std::move(pBuffer) );
+ auto& Cache = m_pInternalData->m_UploadBufferCache;
+ Cache[pBuffer->GetDesc()].emplace_back(std::move(pBuffer));
}
}
else
@@ -277,18 +282,16 @@ void TextureUploaderD3D11::RenderThreadUpdate(IDeviceContext* pContext)
UINT SrcSubres = D3D11CalcSubresource(
static_cast<UINT>(Mip),
static_cast<UINT>(Slice),
- static_cast<UINT>(UploadBuffDesc.MipLevels)
- );
+ static_cast<UINT>(UploadBuffDesc.MipLevels));
UINT DstSubres = D3D11CalcSubresource(
- static_cast<UINT>(OperationInfo.DstMip + Mip),
+ static_cast<UINT>(OperationInfo.DstMip + Mip),
static_cast<UINT>(OperationInfo.DstSlice + Slice),
- static_cast<UINT>(OperationInfo.DstMipLevels)
- );
+ static_cast<UINT>(OperationInfo.DstMipLevels));
pd3d11NativeCtx->CopySubresourceRegion(OperationInfo.pd3d11NativeDstTexture, DstSubres,
- 0, 0, 0, // DstX, DstY, DstZ
- pBuffer->GetStagingTex(),
- SrcSubres,
- nullptr // pSrcBox
+ 0, 0, 0, // DstX, DstY, DstZ
+ pBuffer->GetStagingTex(),
+ SrcSubres,
+ nullptr // pSrcBox
);
}
}
@@ -301,19 +304,20 @@ void TextureUploaderD3D11::RenderThreadUpdate(IDeviceContext* pContext)
}
}
-void TextureUploaderD3D11::AllocateUploadBuffer(const UploadBufferDesc& Desc, bool IsRenderThread, IUploadBuffer **ppBuffer)
+void TextureUploaderD3D11::AllocateUploadBuffer(const UploadBufferDesc& Desc, bool IsRenderThread, IUploadBuffer** ppBuffer)
{
*ppBuffer = nullptr;
{
std::lock_guard<std::mutex> CacheLock(m_pInternalData->m_UploadBuffCacheMtx);
- auto &Cache = m_pInternalData->m_UploadBufferCache;
+
+ auto& Cache = m_pInternalData->m_UploadBufferCache;
if (!Cache.empty())
{
auto DequeIt = Cache.find(Desc);
if (DequeIt != Cache.end())
{
- auto &Deque = DequeIt->second;
+ auto& Deque = DequeIt->second;
if (!Deque.empty())
{
*ppBuffer = Deque.front().Detach();
@@ -323,8 +327,9 @@ void TextureUploaderD3D11::AllocateUploadBuffer(const UploadBufferDesc& Desc, bo
}
}
- if( *ppBuffer == nullptr )
+ if (*ppBuffer == nullptr)
{
+ // clang-format off
D3D11_TEXTURE2D_DESC StagingTexDesc =
{
static_cast<UINT>(Desc.Width),
@@ -338,8 +343,10 @@ void TextureUploaderD3D11::AllocateUploadBuffer(const UploadBufferDesc& Desc, bo
D3D11_CPU_ACCESS_WRITE, // UINT CPUAccessFlags;
0, // UINT MiscFlags;
};
+ // clang-format on
CComPtr<ID3D11Texture2D> pStagingTex;
+
HRESULT hr = m_pInternalData->m_pd3d11NativeDevice->CreateTexture2D(&StagingTexDesc, nullptr, &pStagingTex);
if (FAILED(hr))
{
@@ -362,16 +369,16 @@ void TextureUploaderD3D11::ScheduleGPUCopy(ITexture* pDstTexture,
Uint32 MipLevel,
IUploadBuffer* pUploadBuffer)
{
- auto* pUploadBufferD3D11 = ValidatedCast<UploadBufferD3D11>(pUploadBuffer);
+ auto* pUploadBufferD3D11 = ValidatedCast<UploadBufferD3D11>(pUploadBuffer);
RefCntAutoPtr<ITextureD3D11> pDstTexD3D11(pDstTexture, IID_TextureD3D11);
- auto* pd3d11NativeDstTex = pDstTexD3D11->GetD3D11Texture();
- const auto& DstTexDesc = pDstTexture->GetDesc();
+ auto* pd3d11NativeDstTex = pDstTexD3D11->GetD3D11Texture();
+ const auto& DstTexDesc = pDstTexture->GetDesc();
m_pInternalData->EnqueCopy(pUploadBufferD3D11, pd3d11NativeDstTex, MipLevel, ArraySlice, DstTexDesc.MipLevels);
}
-void TextureUploaderD3D11::RecycleBuffer(IUploadBuffer *pUploadBuffer)
+void TextureUploaderD3D11::RecycleBuffer(IUploadBuffer* pUploadBuffer)
{
- auto *pUploadBufferD3D11 = ValidatedCast<UploadBufferD3D11>(pUploadBuffer);
+ auto* pUploadBufferD3D11 = ValidatedCast<UploadBufferD3D11>(pUploadBuffer);
VERIFY(pUploadBufferD3D11->DbgIsCopyScheduled(), "Upload buffer must be recycled only after copy operation has been scheduled on the GPU");
pUploadBufferD3D11->Reset();
@@ -380,11 +387,11 @@ void TextureUploaderD3D11::RecycleBuffer(IUploadBuffer *pUploadBuffer)
TextureUploaderStats TextureUploaderD3D11::GetStats()
{
- TextureUploaderStats Stats;
+ TextureUploaderStats Stats;
std::lock_guard<std::mutex> QueueLock(m_pInternalData->m_PendingOperationsMtx);
- for (auto &OperationInfo : m_pInternalData->m_PendingOperations)
+ for (auto& OperationInfo : m_pInternalData->m_PendingOperations)
{
- // Do not count MapAndCache operations as they are performed as part of the
+ // Do not count MapAndCache operations as they are performed as part of the
// buffer recycling.
if (OperationInfo.operation == InternalData::PendingBufferOperation::Map ||
OperationInfo.operation == InternalData::PendingBufferOperation::Copy)
diff --git a/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp b/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp
index b1b416ea..cb2e7ad7 100644
--- a/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp
+++ b/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp
@@ -39,11 +39,13 @@ namespace
class UploadTexture : public UploadBufferBase
{
public:
- UploadTexture(IReferenceCounters* pRefCounters,
- const UploadBufferDesc& Desc,
- ITexture* pStagingTexture) :
- UploadBufferBase (pRefCounters, Desc),
- m_pStagingTexture (pStagingTexture)
+ UploadTexture(IReferenceCounters* pRefCounters,
+ const UploadBufferDesc& Desc,
+ ITexture* pStagingTexture) :
+ // clang-format off
+ UploadBufferBase {pRefCounters, Desc},
+ m_pStagingTexture{pStagingTexture}
+ // clang-format on
{
}
@@ -97,24 +99,24 @@ public:
UploadBufferBase::Reset();
}
- virtual void WaitForCopyScheduled()override final
+ virtual void WaitForCopyScheduled() override final
{
m_CopyScheduledSignal.Wait();
}
ITexture* GetStagingTexture() { return m_pStagingTexture; }
- bool DbgIsCopyScheduled()const
+ bool DbgIsCopyScheduled() const
{
return m_CopyScheduledSignal.IsTriggered();
}
-
+
bool DbgIsMapped()
{
return m_TextureMappedSignal.IsTriggered();
}
- Uint64 GetCopyScheduledFenceValue()const
+ Uint64 GetCopyScheduledFenceValue() const
{
VERIFY(m_CopyScheduledFenceValue != 0, "Fence value has not been initialized");
return m_CopyScheduledFenceValue;
@@ -130,7 +132,7 @@ private:
} // namespace
-
+
struct TextureUploaderD3D12_Vk::InternalData
{
struct PendingBufferOperation
@@ -139,23 +141,25 @@ struct TextureUploaderD3D12_Vk::InternalData
{
Copy,
Map
- }operation;
+ } operation;
RefCntAutoPtr<UploadTexture> pUploadTexture;
RefCntAutoPtr<ITexture> pDstTexture;
- Uint32 DstSlice = 0;
- Uint32 DstMip = 0;
+ Uint32 DstSlice = 0;
+ Uint32 DstMip = 0;
+ // clang-format off
PendingBufferOperation(Operation op, UploadTexture* pUploadTex) :
- operation (op),
- pUploadTexture(pUploadTex)
+ operation {op },
+ pUploadTexture{pUploadTex}
{}
PendingBufferOperation(Operation op, UploadTexture* pUploadTex, ITexture* pDstTex, Uint32 dstSlice, Uint32 dstMip) :
- operation (op),
- pUploadTexture (pUploadTex),
- pDstTexture (pDstTex),
- DstSlice (dstSlice),
- DstMip (dstMip)
+ operation {op },
+ pUploadTexture {pUploadTex},
+ pDstTexture {pDstTex },
+ DstSlice {dstSlice },
+ DstMip {dstMip }
{}
+ // clang-format on
};
InternalData(IRenderDevice* pDevice)
@@ -171,8 +175,8 @@ struct TextureUploaderD3D12_Vk::InternalData
{
if (it.second.size())
{
- const auto& desc = it.first;
- auto& FmtInfo = GetTextureFormatAttribs(desc.Format);
+ const auto& desc = it.first;
+ auto& FmtInfo = GetTextureFormatAttribs(desc.Format);
LOG_INFO_MESSAGE("TextureUploaderD3D12_Vk: releasing ", it.second.size(), ' ', desc.Width, 'x', desc.Height, 'x', desc.Depth, ' ', FmtInfo.Name, " upload buffer(s) ");
}
}
@@ -216,8 +220,8 @@ struct TextureUploaderD3D12_Vk::InternalData
RefCntAutoPtr<UploadTexture> FindCachedUploadTexture(const UploadBufferDesc& Desc)
{
RefCntAutoPtr<UploadTexture> pUploadTexture;
- std::lock_guard<std::mutex> CacheLock(m_UploadTexturesCacheMtx);
- auto DequeIt = m_UploadTexturesCache.find(Desc);
+ std::lock_guard<std::mutex> CacheLock(m_UploadTexturesCacheMtx);
+ auto DequeIt = m_UploadTexturesCache.find(Desc);
if (DequeIt != m_UploadTexturesCache.end())
{
auto& Deque = DequeIt->second;
@@ -239,7 +243,7 @@ struct TextureUploaderD3D12_Vk::InternalData
void RecycleUploadTexture(UploadTexture* pUploadTexture)
{
std::lock_guard<std::mutex> CacheLock(m_UploadTexturesCacheMtx);
- auto& Deque = m_UploadTexturesCache[pUploadTexture->GetDesc()];
+ auto& Deque = m_UploadTexturesCache[pUploadTexture->GetDesc()];
Deque.emplace_back(pUploadTexture);
}
@@ -254,17 +258,17 @@ private:
std::vector<PendingBufferOperation> m_PendingOperations;
std::vector<PendingBufferOperation> m_InWorkOperations;
- std::mutex m_UploadTexturesCacheMtx;
- std::unordered_map< UploadBufferDesc, std::deque< RefCntAutoPtr<UploadTexture> > > m_UploadTexturesCache;
+ std::mutex m_UploadTexturesCacheMtx;
+ std::unordered_map<UploadBufferDesc, std::deque<RefCntAutoPtr<UploadTexture>>> m_UploadTexturesCache;
- RefCntAutoPtr<IFence> m_pFence;
- Uint64 m_NextFenceValue = 1;
- Uint64 m_CompletedFenceValue = 0;
+ RefCntAutoPtr<IFence> m_pFence;
+ Uint64 m_NextFenceValue = 1;
+ Uint64 m_CompletedFenceValue = 0;
};
TextureUploaderD3D12_Vk::TextureUploaderD3D12_Vk(IReferenceCounters* pRefCounters, IRenderDevice* pDevice, const TextureUploaderDesc Desc) :
- TextureUploaderBase(pRefCounters, pDevice, Desc),
- m_pInternalData(new InternalData(pDevice))
+ TextureUploaderBase{pRefCounters, pDevice, Desc},
+ m_pInternalData{new InternalData(pDevice)}
{
}
@@ -277,7 +281,6 @@ TextureUploaderD3D12_Vk::~TextureUploaderD3D12_Vk()
NumPendingOperations, (NumPendingOperations > 1 ? " pending operations" : " pending operation"),
" in the queue. If other threads wait for ", (NumPendingOperations > 1 ? "these operations" : "this operation"),
", they may deadlock.");
-
}
}
@@ -289,7 +292,7 @@ void TextureUploaderD3D12_Vk::RenderThreadUpdate(IDeviceContext* pContext)
Uint32 NumCopyOperations = 0;
for (auto& OperationInfo : InWorkOperations)
{
- auto& pUploadTex = OperationInfo.pUploadTexture;
+ auto& pUploadTex = OperationInfo.pUploadTexture;
const auto& StagingTexDesc = pUploadTex->GetDesc();
switch (OperationInfo.operation)
@@ -316,16 +319,16 @@ void TextureUploaderD3D12_Vk::RenderThreadUpdate(IDeviceContext* pContext)
{
pUploadTex->Unmap(pContext, Mip, Slice);
- CopyTextureAttribs CopyInfo
- {
- pUploadTex->GetStagingTexture(),
- RESOURCE_STATE_TRANSITION_MODE_TRANSITION,
- OperationInfo.pDstTexture,
- RESOURCE_STATE_TRANSITION_MODE_TRANSITION
- };
+ CopyTextureAttribs CopyInfo //
+ {
+ pUploadTex->GetStagingTexture(),
+ RESOURCE_STATE_TRANSITION_MODE_TRANSITION,
+ OperationInfo.pDstTexture,
+ RESOURCE_STATE_TRANSITION_MODE_TRANSITION //
+ };
CopyInfo.SrcMipLevel = Mip;
CopyInfo.SrcSlice = Slice;
- CopyInfo.DstMipLevel = OperationInfo.DstMip + Mip;
+ CopyInfo.DstMipLevel = OperationInfo.DstMip + Mip;
CopyInfo.DstSlice = OperationInfo.DstSlice + Slice;
pContext->CopyTexture(CopyInfo);
}
@@ -375,8 +378,8 @@ void TextureUploaderD3D12_Vk::AllocateUploadBuffer(const UploadBufferDesc& Desc,
RefCntAutoPtr<ITexture> pStagingTexture;
m_pDevice->CreateTexture(StagingTexDesc, nullptr, &pStagingTexture);
- LOG_INFO_MESSAGE("Created ", Desc.Width, "x", Desc.Height, 'x', Desc.Depth, ' ', Desc.MipLevels, "-mip ",
- GetTextureFormatAttribs(Desc.Format).Name, " staging texture");
+ LOG_INFO_MESSAGE("Created ", Desc.Width, "x", Desc.Height, 'x', Desc.Depth, ' ', Desc.MipLevels, "-mip ",
+ GetTextureFormatAttribs(Desc.Format).Name, " staging texture");
pUploadTexture = MakeNewRCObj<UploadTexture>()(Desc, pStagingTexture);
}
@@ -386,10 +389,10 @@ void TextureUploaderD3D12_Vk::AllocateUploadBuffer(const UploadBufferDesc& Desc,
*ppBuffer = pUploadTexture.Detach();
}
-void TextureUploaderD3D12_Vk::ScheduleGPUCopy(ITexture* pDstTexture,
- Uint32 ArraySlice,
- Uint32 MipLevel,
- IUploadBuffer* pUploadBuffer)
+void TextureUploaderD3D12_Vk::ScheduleGPUCopy(ITexture* pDstTexture,
+ Uint32 ArraySlice,
+ Uint32 MipLevel,
+ IUploadBuffer* pUploadBuffer)
{
auto* pUploadTexture = ValidatedCast<UploadTexture>(pUploadBuffer);
m_pInternalData->EnqueCopy(pUploadTexture, pDstTexture, ArraySlice, MipLevel);
diff --git a/Graphics/GraphicsTools/src/TextureUploaderGL.cpp b/Graphics/GraphicsTools/src/TextureUploaderGL.cpp
index 1b4f067a..2b5c3a7f 100644
--- a/Graphics/GraphicsTools/src/TextureUploaderGL.cpp
+++ b/Graphics/GraphicsTools/src/TextureUploaderGL.cpp
@@ -36,35 +36,37 @@
namespace Diligent
{
-namespace
+namespace
{
class UploadBufferGL : public UploadBufferBase
{
public:
- UploadBufferGL(IReferenceCounters *pRefCounters, const UploadBufferDesc &Desc) :
- UploadBufferBase(pRefCounters, Desc),
- m_SubresourceOffsets(Desc.MipLevels * Desc.ArraySize + 1),
- m_SubresourceStrides(Desc.MipLevels * Desc.ArraySize)
+ UploadBufferGL(IReferenceCounters* pRefCounters, const UploadBufferDesc& Desc) :
+ // clang-format off
+ UploadBufferBase{pRefCounters, Desc},
+ m_SubresourceOffsets{Desc.MipLevels * Desc.ArraySize + 1},
+ m_SubresourceStrides{Desc.MipLevels * Desc.ArraySize }
+ // clang-format on
{
const auto& FmtAttribs = GetTextureFormatAttribs(Desc.Format);
- Uint32 SubRes = 0;
+ Uint32 SubRes = 0;
for (Uint32 Slice = 0; Slice < Desc.ArraySize; ++Slice)
{
for (Uint32 Mip = 0; Mip < Desc.MipLevels; ++Mip)
{
- auto MipWidth = std::max(Desc.Width >> Mip, 1u);
+ auto MipWidth = std::max(Desc.Width >> Mip, 1u);
auto MipHeight = std::max(Desc.Height >> Mip, 1u);
if (FmtAttribs.ComponentType == COMPONENT_TYPE_COMPRESSED)
{
- MipWidth = Align(MipWidth, Uint32{FmtAttribs.BlockWidth});
+ MipWidth = Align(MipWidth, Uint32{FmtAttribs.BlockWidth});
MipHeight = Align(MipHeight, Uint32{FmtAttribs.BlockHeight});
}
- auto RowStride = MipWidth / Uint32{FmtAttribs.BlockWidth} * FmtAttribs.GetElementSize();
+ auto RowStride = MipWidth / Uint32{FmtAttribs.BlockWidth} * FmtAttribs.GetElementSize();
m_SubresourceStrides[SubRes] = RowStride;
- auto MipSize = MipHeight / Uint32{FmtAttribs.BlockHeight} * RowStride;
+ auto MipSize = MipHeight / Uint32{FmtAttribs.BlockHeight} * RowStride;
m_SubresourceOffsets[SubRes + 1] = m_SubresourceOffsets[SubRes] + MipSize;
++SubRes;
}
@@ -87,12 +89,12 @@ public:
m_CopyScheduledSignal.Trigger();
}
- virtual void WaitForCopyScheduled()override final
+ virtual void WaitForCopyScheduled() override final
{
m_CopyScheduledSignal.Wait();
}
- bool DbgIsCopyScheduled()const { return m_CopyScheduledSignal.IsTriggered(); }
+ bool DbgIsCopyScheduled() const { return m_CopyScheduledSignal.IsTriggered(); }
void SetDataPtr(Uint8* pBufferData)
{
@@ -100,7 +102,7 @@ public:
{
for (Uint32 Mip = 0; Mip < m_Desc.MipLevels; ++Mip)
{
- SetMappedData(Mip, Slice, MappedTextureSubresource{pBufferData + GetOffset(Mip,Slice), GetStride(Mip,Slice), 0});
+ SetMappedData(Mip, Slice, MappedTextureSubresource{pBufferData + GetOffset(Mip, Slice), GetStride(Mip, Slice), 0});
}
}
}
@@ -118,7 +120,7 @@ public:
UploadBufferBase::Reset();
}
- Uint32 GetTotalSize()const
+ Uint32 GetTotalSize() const
{
return m_SubresourceOffsets.back();
}
@@ -134,8 +136,8 @@ private:
ThreadingTools::Signal m_BufferMappedSignal;
ThreadingTools::Signal m_CopyScheduledSignal;
RefCntAutoPtr<IBuffer> m_pStagingBuffer;
- std::vector<Uint32> m_SubresourceOffsets;
- std::vector<Uint32> m_SubresourceStrides;
+ std::vector<Uint32> m_SubresourceOffsets;
+ std::vector<Uint32> m_SubresourceStrides;
};
} // namespace
@@ -149,61 +151,63 @@ struct TextureUploaderGL::InternalData
m_PendingOperations.swap(m_InWorkOperations);
}
- void EnqueCopy(UploadBufferGL *pUploadBuffer, ITexture *pDstTexture, Uint32 dstSlice, Uint32 dstMip)
+ void EnqueCopy(UploadBufferGL* pUploadBuffer, ITexture* pDstTexture, Uint32 dstSlice, Uint32 dstMip)
{
std::lock_guard<std::mutex> QueueLock(m_PendingOperationsMtx);
m_PendingOperations.emplace_back(PendingBufferOperation::Operation::Copy, pUploadBuffer, pDstTexture, dstSlice, dstMip);
}
- void EnqueMap(UploadBufferGL *pUploadBuffer)
+ void EnqueMap(UploadBufferGL* pUploadBuffer)
{
std::lock_guard<std::mutex> QueueLock(m_PendingOperationsMtx);
m_PendingOperations.emplace_back(PendingBufferOperation::Operation::Map, pUploadBuffer);
}
-
+
struct PendingBufferOperation
{
enum Operation
{
Map,
Copy
- }operation;
+ } operation;
RefCntAutoPtr<UploadBufferGL> pUploadBuffer;
- RefCntAutoPtr<ITexture> pDstTexture;
- Uint32 DstSlice = 0;
- Uint32 DstMip = 0;
+ RefCntAutoPtr<ITexture> pDstTexture;
+ Uint32 DstSlice = 0;
+ Uint32 DstMip = 0;
+ // clang-format off
PendingBufferOperation(Operation op, UploadBufferGL* pBuff) :
- operation(op),
- pUploadBuffer(pBuff)
+ operation {op },
+ pUploadBuffer{pBuff}
{}
PendingBufferOperation(Operation op, UploadBufferGL* pBuff, ITexture *pDstTex, Uint32 dstSlice, Uint32 dstMip) :
- operation(op),
- pUploadBuffer(pBuff),
- pDstTexture(pDstTex),
- DstSlice(dstSlice),
- DstMip(dstMip)
+ operation {op },
+ pUploadBuffer{pBuff },
+ pDstTexture {pDstTex },
+ DstSlice {dstSlice},
+ DstMip {dstMip }
{}
+ // clang-format on
};
- std::mutex m_PendingOperationsMtx;
- std::vector< PendingBufferOperation > m_PendingOperations;
- std::vector< PendingBufferOperation > m_InWorkOperations;
+ std::mutex m_PendingOperationsMtx;
+ std::vector<PendingBufferOperation> m_PendingOperations;
+ std::vector<PendingBufferOperation> m_InWorkOperations;
- std::mutex m_UploadBuffCacheMtx;
- std::unordered_map< UploadBufferDesc, std::deque<RefCntAutoPtr<UploadBufferGL> > > m_UploadBufferCache;
+ std::mutex m_UploadBuffCacheMtx;
+ std::unordered_map<UploadBufferDesc, std::deque<RefCntAutoPtr<UploadBufferGL>>> m_UploadBufferCache;
};
-TextureUploaderGL::TextureUploaderGL(IReferenceCounters *pRefCounters, IRenderDevice *pDevice, const TextureUploaderDesc Desc) :
- TextureUploaderBase(pRefCounters, pDevice, Desc),
- m_pInternalData(new InternalData())
+TextureUploaderGL::TextureUploaderGL(IReferenceCounters* pRefCounters, IRenderDevice* pDevice, const TextureUploaderDesc Desc) :
+ TextureUploaderBase{pRefCounters, pDevice, Desc},
+ m_pInternalData{new InternalData{}}
{
}
TextureUploaderGL::~TextureUploaderGL()
{
- auto Stats = TextureUploaderGL::GetStats();
+ auto Stats = TextureUploaderGL::GetStats();
if (Stats.NumPendingOperations != 0)
{
LOG_WARNING_MESSAGE("TextureUploaderGL::~TextureUploaderGL(): there ", (Stats.NumPendingOperations > 1 ? "are " : "is "),
@@ -216,21 +220,22 @@ TextureUploaderGL::~TextureUploaderGL()
{
if (BuffQueueIt.second.size())
{
- const auto &desc = BuffQueueIt.first;
- auto &FmtInfo = m_pDevice->GetTextureFormatInfo(desc.Format);
- LOG_INFO_MESSAGE("TextureUploaderGL: releasing ", BuffQueueIt.second.size(), ' ', desc.Width, 'x', desc.Height, 'x', desc.Depth, ' ', FmtInfo.Name, " upload buffer(s) ");
+ const auto& desc = BuffQueueIt.first;
+ auto& FmtInfo = m_pDevice->GetTextureFormatInfo(desc.Format);
+ LOG_INFO_MESSAGE("TextureUploaderGL: releasing ", BuffQueueIt.second.size(), ' ', desc.Width, 'x',
+ desc.Height, 'x', desc.Depth, ' ', FmtInfo.Name, " upload buffer(s) ");
}
}
}
-void TextureUploaderGL::RenderThreadUpdate(IDeviceContext *pContext)
+void TextureUploaderGL::RenderThreadUpdate(IDeviceContext* pContext)
{
m_pInternalData->SwapMapQueues();
if (!m_pInternalData->m_InWorkOperations.empty())
{
for (auto& OperationInfo : m_pInternalData->m_InWorkOperations)
{
- auto& pBuffer = OperationInfo.pUploadBuffer;
+ auto& pBuffer = OperationInfo.pUploadBuffer;
const auto& UploadBuffDesc = pBuffer->GetDesc();
switch (OperationInfo.operation)
@@ -258,7 +263,7 @@ void TextureUploaderGL::RenderThreadUpdate(IDeviceContext *pContext)
case InternalData::PendingBufferOperation::Copy:
{
- const auto& TexDesc = OperationInfo.pDstTexture->GetDesc();
+ const auto& TexDesc = OperationInfo.pDstTexture->GetDesc();
pContext->UnmapBuffer(pBuffer->m_pStagingBuffer, MAP_WRITE);
for (Uint32 Slice = 0; Slice < UploadBuffDesc.ArraySize; ++Slice)
{
@@ -266,9 +271,11 @@ void TextureUploaderGL::RenderThreadUpdate(IDeviceContext *pContext)
{
auto SrcOffset = pBuffer->GetOffset(Mip, Slice);
auto SrcStride = pBuffer->GetMappedData(Mip, Slice).Stride;
+
TextureSubResData SubResData(pBuffer->m_pStagingBuffer, SrcOffset, SrcStride);
+
auto MipLevelProps = GetMipLevelProperties(TexDesc, Mip);
- Box DstBox;
+ Box DstBox;
DstBox.MaxX = MipLevelProps.LogicalWidth;
DstBox.MaxY = MipLevelProps.LogicalHeight;
pContext->UpdateTexture(OperationInfo.pDstTexture, OperationInfo.DstMip + Mip, OperationInfo.DstSlice + Slice, DstBox,
@@ -284,20 +291,20 @@ void TextureUploaderGL::RenderThreadUpdate(IDeviceContext *pContext)
}
}
-void TextureUploaderGL::AllocateUploadBuffer(const UploadBufferDesc& Desc, bool IsRenderThread, IUploadBuffer **ppBuffer)
+void TextureUploaderGL::AllocateUploadBuffer(const UploadBufferDesc& Desc, bool IsRenderThread, IUploadBuffer** ppBuffer)
{
*ppBuffer = nullptr;
RefCntAutoPtr<UploadBufferGL> pUploadBuffer;
{
std::lock_guard<std::mutex> CacheLock(m_pInternalData->m_UploadBuffCacheMtx);
- auto &Cache = m_pInternalData->m_UploadBufferCache;
+ auto& Cache = m_pInternalData->m_UploadBufferCache;
if (!Cache.empty())
{
auto DequeIt = Cache.find(Desc);
if (DequeIt != Cache.end())
{
- auto &Deque = DequeIt->second;
+ auto& Deque = DequeIt->second;
if (!Deque.empty())
{
pUploadBuffer.Attach(Deque.front().Detach());
@@ -307,10 +314,11 @@ void TextureUploaderGL::AllocateUploadBuffer(const UploadBufferDesc& Desc, bool
}
}
- if( !pUploadBuffer )
+ if (!pUploadBuffer)
{
pUploadBuffer = MakeNewRCObj<UploadBufferGL>()(Desc);
- LOG_INFO_MESSAGE("TextureUploaderGL: created upload buffer for ", Desc.Width, 'x', Desc.Height, 'x', Desc.Depth, ' ', Desc.MipLevels, "-mip ",
+ LOG_INFO_MESSAGE("TextureUploaderGL: created upload buffer for ", Desc.Width, 'x', Desc.Height, 'x',
+ Desc.Depth, ' ', Desc.MipLevels, "-mip ",
m_pDevice->GetTextureFormatInfo(Desc.Format).Name, " texture");
}
@@ -319,30 +327,31 @@ void TextureUploaderGL::AllocateUploadBuffer(const UploadBufferDesc& Desc, bool
*ppBuffer = pUploadBuffer.Detach();
}
-void TextureUploaderGL::ScheduleGPUCopy(ITexture *pDstTexture,
- Uint32 ArraySlice,
- Uint32 MipLevel,
- IUploadBuffer *pUploadBuffer)
+void TextureUploaderGL::ScheduleGPUCopy(ITexture* pDstTexture,
+ Uint32 ArraySlice,
+ Uint32 MipLevel,
+ IUploadBuffer* pUploadBuffer)
{
- auto *pUploadBufferGL = ValidatedCast<UploadBufferGL>(pUploadBuffer);
+ auto* pUploadBufferGL = ValidatedCast<UploadBufferGL>(pUploadBuffer);
m_pInternalData->EnqueCopy(pUploadBufferGL, pDstTexture, ArraySlice, MipLevel);
}
-void TextureUploaderGL::RecycleBuffer(IUploadBuffer *pUploadBuffer)
+void TextureUploaderGL::RecycleBuffer(IUploadBuffer* pUploadBuffer)
{
- auto *pUploadBufferGL = ValidatedCast<UploadBufferGL>(pUploadBuffer);
+ auto* pUploadBufferGL = ValidatedCast<UploadBufferGL>(pUploadBuffer);
VERIFY(pUploadBufferGL->DbgIsCopyScheduled(), "Upload buffer must be recycled only after copy operation has been scheduled on the GPU");
pUploadBufferGL->Reset();
std::lock_guard<std::mutex> CacheLock(m_pInternalData->m_UploadBuffCacheMtx);
- auto &Cache = m_pInternalData->m_UploadBufferCache;
- auto &Deque = Cache[pUploadBufferGL->GetDesc()];
- Deque.emplace_back( pUploadBufferGL );
+
+ auto& Cache = m_pInternalData->m_UploadBufferCache;
+ auto& Deque = Cache[pUploadBufferGL->GetDesc()];
+ Deque.emplace_back(pUploadBufferGL);
}
TextureUploaderStats TextureUploaderGL::GetStats()
{
- TextureUploaderStats Stats;
+ TextureUploaderStats Stats;
std::lock_guard<std::mutex> QueueLock(m_pInternalData->m_PendingOperationsMtx);
Stats.NumPendingOperations = static_cast<Uint32>(m_pInternalData->m_PendingOperations.size());
return Stats;