summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-07-05 22:17:18 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-07-05 22:17:18 +0000
commita029082a02e3e1046b7929f3e5ad75a5df930bac (patch)
treee83fd25dcd522791b46f4f6a8102a4a9d4467720 /Graphics/GraphicsEngineVulkan
parentAdded shader compiler error reporting in Vulkan (diff)
downloadDiligentCore-a029082a02e3e1046b7929f3e5ad75a5df930bac.tar.gz
DiligentCore-a029082a02e3e1046b7929f3e5ad75a5df930bac.zip
Implemented texture and buffer object creation from Vulkan resources
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h2
-rw-r--r--Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h4
-rw-r--r--Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h4
-rw-r--r--Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h5
-rw-r--r--Graphics/GraphicsEngineVulkan/interface/RenderDeviceVk.h27
-rw-r--r--Graphics/GraphicsEngineVulkan/interface/TextureVk.h9
-rw-r--r--Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp65
-rw-r--r--Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp26
-rw-r--r--Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp13
9 files changed, 54 insertions, 101 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h b/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h
index 716e722e..407eb4d7 100644
--- a/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h
@@ -56,7 +56,7 @@ public:
FixedBlockMemoryAllocator& BuffViewObjMemAllocator,
class RenderDeviceVkImpl* pDeviceVk,
const BufferDesc& BuffDesc,
- void* pVkBuffer);
+ VkBuffer vkBuffer);
~BufferVkImpl();
virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject** ppInterface )override;
diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h
index a4ed381d..b80a255c 100644
--- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h
@@ -83,9 +83,9 @@ public:
virtual VkDevice GetVkDevice()override final{ return m_LogicalVkDevice->GetVkDevice();}
- //virtual void CreateTextureFromD3DResource(IVkResource* pVkTexture, ITexture** ppTexture)override final;
+ virtual void CreateTextureFromVulkanImage(VkImage vkImage, const TextureDesc& TexDesc, ITexture** ppTexture)override final;
- //virtual void CreateBufferFromD3DResource(IVkResource* pVkBuffer, const BufferDesc& BuffDesc, IBuffer** ppBuffer)override final;
+ virtual void CreateBufferFromVulkanResource(VkBuffer vkBuffer, const BufferDesc& BuffDesc, IBuffer** ppBuffer)override final;
Uint64 GetCompletedFenceValue();
virtual Uint64 GetNextFenceValue() override final
diff --git a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h
index 11085b13..f2f186c6 100644
--- a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h
@@ -55,7 +55,7 @@ public:
FixedBlockMemoryAllocator& TexViewObjAllocator,
class RenderDeviceVkImpl* pDeviceVk,
const TextureDesc& TexDesc,
- VkImage&& VkImageHandle);
+ VkImage VkImageHandle);
~TextureVkImpl();
@@ -67,7 +67,7 @@ public:
virtual void Map( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource& MappedData )override;
virtual void Unmap( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags )override;
- virtual VkImage GetVkImage(){ return m_VulkanImage; }
+ virtual VkImage GetVkImage()const override final{ return m_VulkanImage; }
virtual void* GetNativeHandle()override final { return GetVkImage(); }
/*
virtual void SetVkResourceState(Vk_RESOURCE_STATES state)override final{ SetState(state); }
diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h
index 36a7b645..6029f489 100644
--- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h
+++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h
@@ -46,6 +46,11 @@ namespace VulkanUtilities
{
vkObject = VK_NULL_HANDLE;
}
+ // This constructor does not take ownership of the vulkan object
+ explicit VulkanObjectWrapper(VulkanObjectType vkObject) :
+ m_VkObject (vkObject)
+ {
+ }
VulkanObjectWrapper (const VulkanObjectWrapper&) = delete;
VulkanObjectWrapper& operator = (const VulkanObjectWrapper&) = delete;
diff --git a/Graphics/GraphicsEngineVulkan/interface/RenderDeviceVk.h b/Graphics/GraphicsEngineVulkan/interface/RenderDeviceVk.h
index 1b93ebfe..82199520 100644
--- a/Graphics/GraphicsEngineVulkan/interface/RenderDeviceVk.h
+++ b/Graphics/GraphicsEngineVulkan/interface/RenderDeviceVk.h
@@ -54,26 +54,35 @@ public:
/// Otherwise the method is automatically called before present
virtual void FinishFrame() = 0;
- /// Creates a texture object from native d3d12 resource
+ /// Creates a texture object from native Vulkan image
- /// \param [in] pd3d12Texture - pointer to the native D3D12 texture
+ /// \param [in] vkImage - Vulkan image handle
+ /// \param [in] TexDesc - Texture description. Vulkan provides no means to retrieve any
+ /// image properties from the image handle, so complete texture
+ /// description must be provided
/// \param [out] ppTexture - Address of the memory location where the pointer to the
/// texture interface will be stored.
/// The function calls AddRef(), so that the new object will contain
/// one refernce.
- //virtual void CreateTextureFromD3DResource(ID3D12Resource *pd3d12Texture, ITexture **ppTexture) = 0;
+ /// \note Created texture object does not take ownership of the Vulkan image and will not
+ /// destroy it once released. The application must not destroy the image while it is
+ /// in use by the engine.
+ virtual void CreateTextureFromVulkanImage(VkImage vkImage, const TextureDesc& TexDesc, ITexture** ppTexture) = 0;
- /// Creates a buffer object from native d3d12 resoruce
+ /// Creates a buffer object from native Vulkan resource
- /// \param [in] pd3d12Buffer - Pointer to the native d3d12 buffer resource
- /// \param [in] BuffDesc - Buffer description. The system can recover buffer size, but
- /// the rest of the fields need to be populated by the client
- /// as they cannot be recovered from d3d12 resource description
+ /// \param [in] vkBuffer - Vulkan buffer handle
+ /// \param [in] BuffDesc - Buffer description. Vulkan provides no means to retrieve any
+ /// buffer properties from the buffer handle, so complete buffer
+ /// description must be provided
/// \param [out] ppBuffer - Address of the memory location where the pointer to the
/// buffer interface will be stored.
/// The function calls AddRef(), so that the new object will contain
/// one reference.
- //virtual void CreateBufferFromD3DResource(ID3D12Resource *pd3d12Buffer, const BufferDesc& BuffDesc, IBuffer **ppBuffer) = 0;
+ /// \note Created buffer object does not take ownership of the Vulkan buffer and will not
+ /// destroy it once released. The application must not destroy Vulkan buffer while it is
+ /// in use by the engine.
+ virtual void CreateBufferFromVulkanResource(VkBuffer vkBuffer, const BufferDesc& BuffDesc, IBuffer** ppBuffer) = 0;
};
}
diff --git a/Graphics/GraphicsEngineVulkan/interface/TextureVk.h b/Graphics/GraphicsEngineVulkan/interface/TextureVk.h
index b2ffd803..43aca681 100644
--- a/Graphics/GraphicsEngineVulkan/interface/TextureVk.h
+++ b/Graphics/GraphicsEngineVulkan/interface/TextureVk.h
@@ -41,11 +41,10 @@ class ITextureVk : public ITexture
{
public:
- /// Returns a pointer to the ID3D12Resource interface of the internal Direct3D12 object.
-
- /// The method does *NOT* call AddRef() on the returned interface,
- /// so Release() must not be called.
- //virtual ID3D12Resource* GetD3D12Texture() = 0;
+ /// Returns Vulkan image handle.
+
+ /// The application must not release the returned image
+ virtual VkImage GetVkImage()const = 0;
/// Sets the texture usage state
diff --git a/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp
index 2f566d17..eedcac82 100644
--- a/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp
@@ -237,80 +237,29 @@ BufferVkImpl :: BufferVkImpl(IReferenceCounters* pRefCounters,
}
-static BufferDesc BufferDescFromVkResource(BufferDesc BuffDesc, void *pVkBuffer)
-{
-#if 0
- VERIFY(BuffDesc.Usage != USAGE_DYNAMIC, "Dynamic buffers cannot be attached to native Vk resource");
-
- auto VkBuffDesc = pVkBuffer->GetDesc();
- VERIFY(VkBuffDesc.Dimension == Vk_RESOURCE_DIMENSION_BUFFER, "Vk resource is not a buffer");
-
- VERIFY(BuffDesc.uiSizeInBytes == 0 || BuffDesc.uiSizeInBytes == VkBuffDesc.Width, "Buffer size specified by the BufferDesc (", BuffDesc.uiSizeInBytes,") does not match Vk resource size (", VkBuffDesc.Width, ")" );
- BuffDesc.uiSizeInBytes = static_cast<Uint32>( VkBuffDesc.Width );
-
- if (VkBuffDesc.Flags & Vk_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
- {
- VERIFY(BuffDesc.BindFlags == 0 || (BuffDesc.BindFlags & BIND_UNORDERED_ACCESS), "BIND_UNORDERED_ACCESS flag is not specified by the BufferDesc, while Vk resource was created with Vk_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS flag");
- BuffDesc.BindFlags |= BIND_UNORDERED_ACCESS;
- }
- if (VkBuffDesc.Flags & Vk_RESOURCE_FLAG_DENY_SHADER_RESOURCE)
- {
- VERIFY( !(BuffDesc.BindFlags & BIND_SHADER_RESOURCE), "BIND_SHADER_RESOURCE flag is specified by the BufferDesc, while Vk resource was created with Vk_RESOURCE_FLAG_DENY_SHADER_RESOURCE flag");
- BuffDesc.BindFlags &= ~BIND_SHADER_RESOURCE;
- }
-
- if( (BuffDesc.BindFlags & BIND_UNORDERED_ACCESS) || (BuffDesc.BindFlags & BIND_SHADER_RESOURCE) )
- {
- if(BuffDesc.Mode == BUFFER_MODE_STRUCTURED)
- {
- VERIFY(BuffDesc.ElementByteStride != 0, "Element byte stride cannot be 0 for a structured buffer");
- }
- else if(BuffDesc.Mode == BUFFER_MODE_FORMATTED)
- {
- VERIFY( BuffDesc.Format.ValueType != VT_UNDEFINED, "Value type is not specified for a formatted buffer" );
- VERIFY( BuffDesc.Format.NumComponents != 0, "Num components cannot be zero in a formated buffer" );
- }
- else
- {
- UNEXPECTED("Buffer mode must be structured or formatted");
- }
- }
-#endif
- return BuffDesc;
-}
-
BufferVkImpl :: BufferVkImpl(IReferenceCounters* pRefCounters,
FixedBlockMemoryAllocator& BuffViewObjMemAllocator,
RenderDeviceVkImpl* pRenderDeviceVk,
- const BufferDesc& BuffDesc,
- void* pVkBuffer) :
- TBufferBase(pRefCounters, BuffViewObjMemAllocator, pRenderDeviceVk, BufferDescFromVkResource(BuffDesc, pVkBuffer), false),
+ const BufferDesc& BuffDesc,
+ VkBuffer vkBuffer) :
+ TBufferBase(pRefCounters, BuffViewObjMemAllocator, pRenderDeviceVk, BuffDesc, false),
m_AccessFlags(0),
#ifdef _DEBUG
m_DbgMapType(1 + pRenderDeviceVk->GetNumDeferredContexts()),
#endif
- m_DynamicAllocations(STD_ALLOCATOR_RAW_MEM(VulkanDynamicAllocation, GetRawAllocator(), "Allocator for vector<VulkanDynamicAllocation>"))
+ m_DynamicAllocations(STD_ALLOCATOR_RAW_MEM(VulkanDynamicAllocation, GetRawAllocator(), "Allocator for vector<VulkanDynamicAllocation>")),
+ m_VulkanBuffer(vkBuffer)
{
-#if 0
- m_pVkResource = pVkBuffer;
-
- if (m_Desc.BindFlags & BIND_UNIFORM_BUFFER)
- {
- m_CBVDescriptorAllocation = pRenderDeviceVk->AllocateDescriptor(Vk_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
- CreateCBV(m_CBVDescriptorAllocation.GetCpuHandle());
- }
-#endif
}
BufferVkImpl :: ~BufferVkImpl()
{
auto *pDeviceVkImpl = GetDevice<RenderDeviceVkImpl>();
+ // Vk object can only be destroyed when it is no longer used by the GPU
if(m_VulkanBuffer != VK_NULL_HANDLE)
- {
- // Vk object can only be destroyed when it is no longer used by the GPU
pDeviceVkImpl->SafeReleaseVkObject(std::move(m_VulkanBuffer));
+ if(m_MemoryAllocation.Page != nullptr)
pDeviceVkImpl->SafeReleaseVkObject(std::move(m_MemoryAllocation));
- }
}
IMPLEMENT_QUERY_INTERFACE( BufferVkImpl, IID_BufferVk, TBufferBase )
diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
index 2cafc8f7..0c278c25 100644
--- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
@@ -450,27 +450,27 @@ void RenderDeviceVkImpl::CreatePipelineState(const PipelineStateDesc &PipelineDe
);
}
-#if 0
-void RenderDeviceVkImpl :: CreateBufferFromD3DResource(IVkResource *pVkBuffer, const BufferDesc& BuffDesc, IBuffer **ppBuffer)
+
+void RenderDeviceVkImpl :: CreateBufferFromVulkanResource(VkBuffer vkBuffer, const BufferDesc& BuffDesc, IBuffer** ppBuffer)
{
CreateDeviceObject("buffer", BuffDesc, ppBuffer,
[&]()
{
- BufferVkImpl *pBufferVk( NEW_RC_OBJ(m_BufObjAllocator, "BufferVkImpl instance", BufferVkImpl)(m_BuffViewObjAllocator, this, BuffDesc, pVkBuffer ) );
+ BufferVkImpl* pBufferVk( NEW_RC_OBJ(m_BufObjAllocator, "BufferVkImpl instance", BufferVkImpl)(m_BuffViewObjAllocator, this, BuffDesc, vkBuffer ) );
pBufferVk->QueryInterface( IID_Buffer, reinterpret_cast<IObject**>(ppBuffer) );
pBufferVk->CreateDefaultViews();
OnCreateDeviceObject( pBufferVk );
}
);
}
-#endif
+
void RenderDeviceVkImpl :: CreateBuffer(const BufferDesc& BuffDesc, const BufferData &BuffData, IBuffer **ppBuffer)
{
CreateDeviceObject("buffer", BuffDesc, ppBuffer,
[&]()
{
- BufferVkImpl *pBufferVk( NEW_RC_OBJ(m_BufObjAllocator, "BufferVkImpl instance", BufferVkImpl)(m_BuffViewObjAllocator, this, BuffDesc, BuffData ) );
+ BufferVkImpl* pBufferVk( NEW_RC_OBJ(m_BufObjAllocator, "BufferVkImpl instance", BufferVkImpl)(m_BuffViewObjAllocator, this, BuffDesc, BuffData ) );
pBufferVk->QueryInterface( IID_Buffer, reinterpret_cast<IObject**>(ppBuffer) );
pBufferVk->CreateDefaultViews();
OnCreateDeviceObject( pBufferVk );
@@ -492,15 +492,13 @@ void RenderDeviceVkImpl :: CreateShader(const ShaderCreationAttribs &ShaderCreat
);
}
-#if 0
-void RenderDeviceVkImpl::CreateTextureFromD3DResource(IVkResource *pVkTexture, ITexture **ppTexture)
+
+void RenderDeviceVkImpl::CreateTextureFromVulkanImage(VkImage vkImage, const TextureDesc& TexDesc, ITexture** ppTexture)
{
- TextureDesc TexDesc;
- TexDesc.Name = "Texture from Vk resource";
CreateDeviceObject( "texture", TexDesc, ppTexture,
[&]()
{
- TextureVkImpl *pTextureVk = NEW_RC_OBJ(m_TexObjAllocator, "TextureVkImpl instance", TextureVkImpl)(m_TexViewObjAllocator, this, TexDesc, pVkTexture );
+ TextureVkImpl* pTextureVk = NEW_RC_OBJ(m_TexObjAllocator, "TextureVkImpl instance", TextureVkImpl)(m_TexViewObjAllocator, this, TexDesc, vkImage );
pTextureVk->QueryInterface( IID_Texture, reinterpret_cast<IObject**>(ppTexture) );
pTextureVk->CreateDefaultViews();
@@ -508,14 +506,14 @@ void RenderDeviceVkImpl::CreateTextureFromD3DResource(IVkResource *pVkTexture, I
}
);
}
-#endif
+
void RenderDeviceVkImpl::CreateTexture(const TextureDesc& TexDesc, VkImage vkImgHandle, class TextureVkImpl **ppTexture)
{
CreateDeviceObject( "texture", TexDesc, ppTexture,
[&]()
{
- TextureVkImpl *pTextureVk = NEW_RC_OBJ(m_TexObjAllocator, "TextureVkImpl instance", TextureVkImpl)(m_TexViewObjAllocator, this, TexDesc, std::move(vkImgHandle));
+ TextureVkImpl* pTextureVk = NEW_RC_OBJ(m_TexObjAllocator, "TextureVkImpl instance", TextureVkImpl)(m_TexViewObjAllocator, this, TexDesc, std::move(vkImgHandle));
pTextureVk->QueryInterface( IID_TextureVk, reinterpret_cast<IObject**>(ppTexture) );
}
);
@@ -527,7 +525,7 @@ void RenderDeviceVkImpl :: CreateTexture(const TextureDesc& TexDesc, const Textu
CreateDeviceObject( "texture", TexDesc, ppTexture,
[&]()
{
- TextureVkImpl *pTextureVk = NEW_RC_OBJ(m_TexObjAllocator, "TextureVkImpl instance", TextureVkImpl)(m_TexViewObjAllocator, this, TexDesc, Data );
+ TextureVkImpl* pTextureVk = NEW_RC_OBJ(m_TexObjAllocator, "TextureVkImpl instance", TextureVkImpl)(m_TexViewObjAllocator, this, TexDesc, Data );
pTextureVk->QueryInterface( IID_Texture, reinterpret_cast<IObject**>(ppTexture) );
pTextureVk->CreateDefaultViews();
@@ -544,7 +542,7 @@ void RenderDeviceVkImpl :: CreateSampler(const SamplerDesc& SamplerDesc, ISample
m_SamplersRegistry.Find( SamplerDesc, reinterpret_cast<IDeviceObject**>(ppSampler) );
if( *ppSampler == nullptr )
{
- SamplerVkImpl *pSamplerVk( NEW_RC_OBJ(m_SamplerObjAllocator, "SamplerVkImpl instance", SamplerVkImpl)(this, SamplerDesc ) );
+ SamplerVkImpl* pSamplerVk( NEW_RC_OBJ(m_SamplerObjAllocator, "SamplerVkImpl instance", SamplerVkImpl)(this, SamplerDesc ) );
pSamplerVk->QueryInterface( IID_Sampler, reinterpret_cast<IObject**>(ppSampler) );
OnCreateDeviceObject( pSamplerVk );
m_SamplersRegistry.Add( SamplerDesc, *ppSampler );
diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
index 253e1300..16fb400d 100644
--- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
@@ -400,20 +400,13 @@ TextureVkImpl :: TextureVkImpl(IReferenceCounters* pRefCounters,
#endif
}
-static TextureDesc InitTexDescFromVkImage(VkImage vkImg, const TextureDesc& SrcTexDesc)
-{
- // There is no way to query any image attribute in Vulkan
- return SrcTexDesc;
-}
-
-
TextureVkImpl::TextureVkImpl(IReferenceCounters* pRefCounters,
FixedBlockMemoryAllocator& TexViewObjAllocator,
RenderDeviceVkImpl* pDeviceVk,
const TextureDesc& TexDesc,
- VkImage&& VkImageHandle) :
- TTextureBase(pRefCounters, TexViewObjAllocator, pDeviceVk, InitTexDescFromVkImage(VkImageHandle, TexDesc)),
- m_VulkanImage(nullptr, std::move(VkImageHandle))
+ VkImage VkImageHandle) :
+ TTextureBase(pRefCounters, TexViewObjAllocator, pDeviceVk, TexDesc),
+ m_VulkanImage(VkImageHandle)
{
}
IMPLEMENT_QUERY_INTERFACE( TextureVkImpl, IID_TextureVk, TTextureBase )