diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-02-09 01:28:02 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-02-09 01:28:02 +0000 |
| commit | 26a81f5d5aef3e8d367c7e91870becce7c21e1f9 (patch) | |
| tree | 47a80be0a9f5d26ac632785825aa0b6dc524a6a6 /Graphics/GraphicsEngineD3D12 | |
| parent | Defined constructos to fix build errors on Apple's clang (diff) | |
| download | DiligentCore-26a81f5d5aef3e8d367c7e91870becce7c21e1f9.tar.gz DiligentCore-26a81f5d5aef3e8d367c7e91870becce7c21e1f9.zip | |
Updated IRenderDevice::CreateTexture and IRenderDevice::CreateBuffer to take pointers to initial data rather than references
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
7 files changed, 32 insertions, 32 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h index 3caff1e2..708a65ea 100644 --- a/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h @@ -49,7 +49,7 @@ public: FixedBlockMemoryAllocator& BuffViewObjMemAllocator, class RenderDeviceD3D12Impl* pDeviceD3D12, const BufferDesc& BuffDesc, - const BufferData& BuffData = BufferData()); + const BufferData* pBuffData = nullptr); BufferD3D12Impl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& BuffViewObjMemAllocator, class RenderDeviceD3D12Impl* pDeviceD3D12, diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h index fca1d58c..3fe6b9f3 100644 --- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h @@ -57,13 +57,13 @@ public: virtual void CreatePipelineState( const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState )override final; - virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData &BuffData, IBuffer **ppBuffer)override final; + virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer **ppBuffer)override final; - virtual void CreateShader(const ShaderCreationAttribs &ShaderCreationAttribs, IShader **ppShader)override final; + virtual void CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader **ppShader)override final; - virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData &Data, ITexture **ppTexture)override final; + virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture **ppTexture)override final; - void CreateTexture(const TextureDesc& TexDesc, ID3D12Resource *pd3d12Texture, RESOURCE_STATE InitialState, class TextureD3D12Impl **ppTexture); + void CreateTexture(const TextureDesc& TexDesc, ID3D12Resource* pd3d12Texture, RESOURCE_STATE InitialState, class TextureD3D12Impl **ppTexture); virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler **ppSampler)override final; @@ -71,9 +71,9 @@ public: virtual ID3D12Device* GetD3D12Device()override final{return m_pd3d12Device;} - virtual void CreateTextureFromD3DResource(ID3D12Resource *pd3d12Texture, RESOURCE_STATE InitialState, ITexture **ppTexture)override final; + virtual void CreateTextureFromD3DResource(ID3D12Resource* pd3d12Texture, RESOURCE_STATE InitialState, ITexture** ppTexture)override final; - virtual void CreateBufferFromD3DResource(ID3D12Resource *pd3d12Buffer, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer **ppBuffer)override final; + virtual void CreateBufferFromD3DResource(ID3D12Resource* pd3d12Buffer, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer **ppBuffer)override final; DescriptorHeapAllocation AllocateDescriptor( D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count = 1 ); DescriptorHeapAllocation AllocateGPUDescriptors( D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count = 1 ); diff --git a/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h index ad50ab68..b205f843 100644 --- a/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h @@ -50,7 +50,7 @@ public: FixedBlockMemoryAllocator& TexViewObjAllocator, RenderDeviceD3D12Impl* pDeviceD3D12, const TextureDesc& TexDesc, - const TextureData& InitData = TextureData()); + const TextureData* pInitData = nullptr); // Attaches to an existing D3D12 resource TextureD3D12Impl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& TexViewObjAllocator, diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp index 6eb2baeb..eaf96a64 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp @@ -39,7 +39,7 @@ BufferD3D12Impl :: BufferD3D12Impl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& BuffViewObjMemAllocator, RenderDeviceD3D12Impl* pRenderDeviceD3D12, const BufferDesc& BuffDesc, - const BufferData& BuffData /*= BufferData()*/) : + const BufferData* pBuffData /*= nullptr*/) : TBufferBase { pRefCounters, @@ -57,10 +57,10 @@ BufferD3D12Impl :: BufferD3D12Impl(IReferenceCounters* pRefCounters, { #define LOG_BUFFER_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Buffer \"", BuffDesc.Name ? BuffDesc.Name : "", "\": ", ##__VA_ARGS__); - if( m_Desc.Usage == USAGE_STATIC && BuffData.pData == nullptr ) + if( m_Desc.Usage == USAGE_STATIC && (pBuffData == nullptr || pBuffData->pData == nullptr)) LOG_BUFFER_ERROR_AND_THROW("Static buffer must be initialized with data at creation time") - if( m_Desc.Usage == USAGE_DYNAMIC && BuffData.pData != nullptr ) + if( m_Desc.Usage == USAGE_DYNAMIC && pBuffData != nullptr && pBuffData->pData != nullptr ) LOG_BUFFER_ERROR_AND_THROW("Dynamic buffer must be initialized via Map()") Uint32 AlignmentMask = 1; @@ -74,7 +74,7 @@ BufferD3D12Impl :: BufferD3D12Impl(IReferenceCounters* pRefCounters, if (m_Desc.CPUAccessFlags == CPU_ACCESS_WRITE) { - if(BuffData.pData != nullptr ) + if (pBuffData != nullptr && pBuffData->pData != nullptr) LOG_BUFFER_ERROR_AND_THROW("CPU-writable staging buffers must be updated via map") AlignmentMask = D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1; @@ -131,7 +131,7 @@ BufferD3D12Impl :: BufferD3D12Impl(IReferenceCounters* pRefCounters, HeapProps.CreationNodeMask = 1; HeapProps.VisibleNodeMask = 1; - bool bInitializeBuffer = (BuffData.pData != nullptr && BuffData.DataSize > 0); + bool bInitializeBuffer = (pBuffData != nullptr && pBuffData->pData != nullptr && pBuffData->DataSize > 0); if(bInitializeBuffer) SetState(RESOURCE_STATE_COPY_DEST); @@ -168,7 +168,7 @@ BufferD3D12Impl :: BufferD3D12Impl(IReferenceCounters* pRefCounters, hr = UploadBuffer->Map(0, nullptr, &DestAddress); if(FAILED(hr)) LOG_ERROR_AND_THROW("Failed to map uload buffer"); - memcpy(DestAddress, BuffData.pData, BuffData.DataSize); + memcpy(DestAddress, pBuffData->pData, pBuffData->DataSize); UploadBuffer->Unmap(0, nullptr); auto InitContext = pRenderDeviceD3D12->AllocateCommandContext(); diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index b14e13b2..3d73cbdb 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -303,12 +303,12 @@ void RenderDeviceD3D12Impl :: CreateBufferFromD3DResource(ID3D12Resource* pd3d12 ); } -void RenderDeviceD3D12Impl :: CreateBuffer(const BufferDesc& BuffDesc, const BufferData& BuffData, IBuffer** ppBuffer) +void RenderDeviceD3D12Impl :: CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer) { CreateDeviceObject("buffer", BuffDesc, ppBuffer, [&]() { - BufferD3D12Impl *pBufferD3D12( NEW_RC_OBJ(m_BufObjAllocator, "BufferD3D12Impl instance", BufferD3D12Impl)(m_BuffViewObjAllocator, this, BuffDesc, BuffData ) ); + BufferD3D12Impl *pBufferD3D12( NEW_RC_OBJ(m_BufObjAllocator, "BufferD3D12Impl instance", BufferD3D12Impl)(m_BuffViewObjAllocator, this, BuffDesc, pBuffData ) ); pBufferD3D12->QueryInterface( IID_Buffer, reinterpret_cast<IObject**>(ppBuffer) ); pBufferD3D12->CreateDefaultViews(); OnCreateDeviceObject( pBufferD3D12 ); @@ -351,18 +351,18 @@ void RenderDeviceD3D12Impl::CreateTexture(const TextureDesc& TexDesc, ID3D12Reso CreateDeviceObject( "texture", TexDesc, ppTexture, [&]() { - TextureD3D12Impl *pTextureD3D12 = NEW_RC_OBJ(m_TexObjAllocator, "TextureD3D12Impl instance", TextureD3D12Impl)(m_TexViewObjAllocator, this, TexDesc, InitialState, pd3d12Texture); + TextureD3D12Impl* pTextureD3D12 = NEW_RC_OBJ(m_TexObjAllocator, "TextureD3D12Impl instance", TextureD3D12Impl)(m_TexViewObjAllocator, this, TexDesc, InitialState, pd3d12Texture); pTextureD3D12->QueryInterface( IID_TextureD3D12, reinterpret_cast<IObject**>(ppTexture) ); } ); } -void RenderDeviceD3D12Impl :: CreateTexture(const TextureDesc& TexDesc, const TextureData& Data, ITexture** ppTexture) +void RenderDeviceD3D12Impl :: CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture) { CreateDeviceObject( "texture", TexDesc, ppTexture, [&]() { - TextureD3D12Impl *pTextureD3D12 = NEW_RC_OBJ(m_TexObjAllocator, "TextureD3D12Impl instance", TextureD3D12Impl)(m_TexViewObjAllocator, this, TexDesc, Data ); + TextureD3D12Impl* pTextureD3D12 = NEW_RC_OBJ(m_TexObjAllocator, "TextureD3D12Impl instance", TextureD3D12Impl)(m_TexViewObjAllocator, this, TexDesc, pData ); pTextureD3D12->QueryInterface( IID_Texture, reinterpret_cast<IObject**>(ppTexture) ); pTextureD3D12->CreateDefaultViews(); diff --git a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp index aa61a2f0..c9e986b4 100644 --- a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp @@ -96,7 +96,7 @@ void SwapChainD3D12Impl::InitBuffersAndViews() DepthBufferDesc.ClearValue.DepthStencil.Stencil = m_SwapChainDesc.DefaultStencilValue; DepthBufferDesc.Name = "Main depth buffer"; RefCntAutoPtr<ITexture> pDepthBufferTex; - m_pRenderDevice->CreateTexture(DepthBufferDesc, TextureData(), static_cast<ITexture**>(&pDepthBufferTex) ); + m_pRenderDevice->CreateTexture(DepthBufferDesc, nullptr, static_cast<ITexture**>(&pDepthBufferTex) ); auto pDSV = pDepthBufferTex->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL); m_pDepthBufferDSV = RefCntAutoPtr<ITextureViewD3D12>(pDSV, IID_TextureViewD3D12); } diff --git a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp index 020a8830..736189f5 100644 --- a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp @@ -75,11 +75,11 @@ TextureD3D12Impl :: TextureD3D12Impl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& TexViewObjAllocator, RenderDeviceD3D12Impl* pRenderDeviceD3D12, const TextureDesc& TexDesc, - const TextureData& InitData /*= TextureData()*/) : + const TextureData* pInitData /*= nullptr*/) : TTextureBase(pRefCounters, TexViewObjAllocator, pRenderDeviceD3D12, TexDesc) { - if( m_Desc.Usage == USAGE_STATIC && InitData.pSubResources == nullptr ) - LOG_ERROR_AND_THROW("Static Texture must be initialized with data at creation time"); + if( m_Desc.Usage == USAGE_STATIC && (pInitData == nullptr || pInitData->pSubResources == nullptr)) + LOG_ERROR_AND_THROW("Static textures must be initialized with data at creation time"); D3D12_RESOURCE_DESC Desc = {}; Desc.Alignment = 0; @@ -155,7 +155,7 @@ TextureD3D12Impl :: TextureD3D12Impl(IReferenceCounters* pRefCounters, pClearValue = &ClearValue; } - bool bInitializeTexture = (InitData.pSubResources != nullptr && InitData.NumSubresources > 0); + bool bInitializeTexture = (pInitData != nullptr && pInitData->pSubResources != nullptr && pInitData->NumSubresources > 0); auto InitialState = bInitializeTexture ? RESOURCE_STATE_COPY_DEST : RESOURCE_STATE_UNDEFINED; SetState(InitialState); auto D3D12State = ResourceStateFlagsToD3D12ResourceStates(InitialState); @@ -170,10 +170,10 @@ TextureD3D12Impl :: TextureD3D12Impl(IReferenceCounters* pRefCounters, if(bInitializeTexture) { Uint32 ExpectedNumSubresources = static_cast<Uint32>(Desc.MipLevels * (Desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? 1 : Desc.DepthOrArraySize) ); - if( InitData.NumSubresources != ExpectedNumSubresources ) - LOG_ERROR_AND_THROW("Incorrect number of subresources in init data. ", ExpectedNumSubresources, " expected, while ", InitData.NumSubresources, " provided"); + if( pInitData->NumSubresources != ExpectedNumSubresources ) + LOG_ERROR_AND_THROW("Incorrect number of subresources in init data. ", ExpectedNumSubresources, " expected, while ", pInitData->NumSubresources, " provided"); - UINT64 uploadBufferSize = GetRequiredIntermediateSize(m_pd3d12Resource, 0, InitData.NumSubresources); + UINT64 uploadBufferSize = GetRequiredIntermediateSize(m_pd3d12Resource, 0, pInitData->NumSubresources); D3D12_HEAP_PROPERTIES UploadHeapProps; UploadHeapProps.Type = D3D12_HEAP_TYPE_UPLOAD; @@ -205,14 +205,14 @@ TextureD3D12Impl :: TextureD3D12Impl(IReferenceCounters* pRefCounters, auto InitContext = pRenderDeviceD3D12->AllocateCommandContext(); // copy data to the intermediate upload heap and then schedule a copy from the upload heap to the default texture VERIFY_EXPR(CheckState(RESOURCE_STATE_COPY_DEST)); - std::vector<D3D12_SUBRESOURCE_DATA, STDAllocatorRawMem<D3D12_SUBRESOURCE_DATA> > D3D12SubResData(InitData.NumSubresources, D3D12_SUBRESOURCE_DATA(), STD_ALLOCATOR_RAW_MEM(D3D12_SUBRESOURCE_DATA, GetRawAllocator(), "Allocator for vector<D3D12_SUBRESOURCE_DATA>") ); + std::vector<D3D12_SUBRESOURCE_DATA, STDAllocatorRawMem<D3D12_SUBRESOURCE_DATA> > D3D12SubResData(pInitData->NumSubresources, D3D12_SUBRESOURCE_DATA(), STD_ALLOCATOR_RAW_MEM(D3D12_SUBRESOURCE_DATA, GetRawAllocator(), "Allocator for vector<D3D12_SUBRESOURCE_DATA>") ); for(size_t subres=0; subres < D3D12SubResData.size(); ++subres) { - D3D12SubResData[subres].pData = InitData.pSubResources[subres].pData; - D3D12SubResData[subres].RowPitch = InitData.pSubResources[subres].Stride; - D3D12SubResData[subres].SlicePitch = InitData.pSubResources[subres].DepthStride; + D3D12SubResData[subres].pData = pInitData->pSubResources[subres].pData; + D3D12SubResData[subres].RowPitch = pInitData->pSubResources[subres].Stride; + D3D12SubResData[subres].SlicePitch = pInitData->pSubResources[subres].DepthStride; } - auto UploadedSize = UpdateSubresources(InitContext->GetCommandList(), m_pd3d12Resource, UploadBuffer, 0, 0, InitData.NumSubresources, D3D12SubResData.data()); + auto UploadedSize = UpdateSubresources(InitContext->GetCommandList(), m_pd3d12Resource, UploadBuffer, 0, 0, pInitData->NumSubresources, D3D12SubResData.data()); VERIFY(UploadedSize == uploadBufferSize, "Incorrect uploaded data size (", UploadedSize, "). ", uploadBufferSize, " is expected"); // Command list fence should only be signaled when submitting cmd list |
