summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-05-06 01:00:06 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-05-06 01:00:06 +0000
commitf61a2f2e7812df47776868336aec4e9e4f560b0c (patch)
tree747221d09412f52de006c90efcfde4ae50f8b179 /Graphics/GraphicsEngineVulkan
parentAdded shader variable type parsing in Vulkan (diff)
downloadDiligentCore-f61a2f2e7812df47776868336aec4e9e4f560b0c.tar.gz
DiligentCore-f61a2f2e7812df47776868336aec4e9e4f560b0c.zip
Added stubs for shader resource layout initialization from pipeline layout
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h13
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.h64
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h34
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h19
-rw-r--r--Graphics/GraphicsEngineVulkan/interface/ShaderVk.h5
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp125
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp46
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp37
8 files changed, 152 insertions, 191 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h
index 5ec8d260..8e29dd30 100644
--- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h
@@ -26,6 +26,8 @@
/// \file
/// Declaration of Diligent::PipelineStateVkImpl class
+#include <array>
+
#include "RenderDeviceVk.h"
#include "PipelineStateVk.h"
#include "PipelineStateBase.h"
@@ -86,11 +88,8 @@ private:
void CreateRenderPass(const VulkanUtilities::VulkanLogicalDevice &LogicalDevice);
-#if 0
- void ParseShaderResourceLayout(IShader *pShader);
+ void ParseResourceLayoutAndCreateShader(IShader *pShader);
- /// Vk device
- RootSignature m_RootSig;
DummyShaderVariable m_DummyVar;
// Looks like there may be a bug in msvc: when allocators are declared as
@@ -121,15 +120,15 @@ private:
ShaderResourceLayoutVk* m_pShaderResourceLayouts[6] = {};
AdaptiveFixedBlockAllocator m_ResourceCacheDataAllocator; // Use separate allocator for every shader stage
+ std::array<VulkanUtilities::ShaderModuleWrapper, 6> m_ShaderModules;
// Do not use strong reference to avoid cyclic references
// Default SRB must be defined after allocators
- std::unique_ptr<class ShaderResourceBindingVkImpl, STDDeleter<ShaderResourceBindingVkImpl, FixedBlockMemoryAllocator> > m_pDefaultShaderResBinding;
-#endif
+ //std::unique_ptr<class ShaderResourceBindingVkImpl, STDDeleter<ShaderResourceBindingVkImpl, FixedBlockMemoryAllocator> > m_pDefaultShaderResBinding;
+
VulkanUtilities::RenderPassWrapper m_RenderPass;
VulkanUtilities::PipelineWrapper m_Pipeline;
PipelineLayout m_PipelineLayout;
- VulkanUtilities::PipelineLayoutWrapper m_TmpPipelineLayout;
};
}
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.h b/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.h
index 91f709b8..a32ae066 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.h
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.h
@@ -24,11 +24,11 @@
#pragma once
/// \file
-/// Declaration of Diligent::ShaderResourceCacheD3D12 class
+/// Declaration of Diligent::ShaderResourceCacheVk class
-// http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-cache/
+// http://diligentgraphics.com/diligent-engine/architecture/Vk/shader-resource-cache/
-// Shader resource cache stores D3D12 resources in a continuous chunk of memory:
+// Shader resource cache stores Vk resources in a continuous chunk of memory:
//
//
// __________________________________________________________
@@ -95,9 +95,10 @@ enum class CachedResourceType : Int32
Sampler,
NumTypes
};
-
-class ShaderResourceCacheD3D12
+#endif
+class ShaderResourceCacheVk
{
+#if 0
public:
// This enum is used for debug purposes only
enum DbgCacheContentType
@@ -106,26 +107,26 @@ public:
SRBResources
};
- ShaderResourceCacheD3D12(DbgCacheContentType dbgContentType)
+ ShaderResourceCacheVk(DbgCacheContentType dbgContentType)
#ifdef _DEBUG
: m_DbgContentType(dbgContentType)
#endif
{
}
- ~ShaderResourceCacheD3D12();
+ ~ShaderResourceCacheVk();
void Initialize(IMemoryAllocator &MemAllocator, Uint32 NumTables, Uint32 TableSizes[]);
static constexpr Uint32 InvalidDescriptorOffset = static_cast<Uint32>(-1);
- //http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-cache#Cache-Structure
+ //http://diligentgraphics.com/diligent-engine/architecture/Vk/shader-resource-cache#Cache-Structure
struct Resource
{
CachedResourceType Type = CachedResourceType::Unknown;
// CPU descriptor handle of a cached resource in CPU-only descriptor heap
// Note that for dynamic resources, this is the only available CPU descriptor handle
- D3D12_CPU_DESCRIPTOR_HANDLE CPUDescriptorHandle = {0};
+ Vk_CPU_DESCRIPTOR_HANDLE CPUDescriptorHandle = {0};
RefCntAutoPtr<IDeviceObject> pObject;
};
@@ -138,7 +139,7 @@ public:
{}
inline Resource& GetResource(Uint32 OffsetFromTableStart,
- const D3D12_DESCRIPTOR_HEAP_TYPE dbgDescriptorHeapType,
+ const Vk_DESCRIPTOR_HEAP_TYPE dbgDescriptorHeapType,
const SHADER_TYPE dbgRefShaderType)
{
VERIFY(m_dbgHeapType == dbgDescriptorHeapType, "Incosistent descriptor heap type" );
@@ -155,7 +156,7 @@ public:
#ifdef _DEBUG
void SetDebugAttribs(Uint32 MaxOffset,
- const D3D12_DESCRIPTOR_HEAP_TYPE dbgDescriptorHeapType,
+ const Vk_DESCRIPTOR_HEAP_TYPE dbgDescriptorHeapType,
const SHADER_TYPE dbgRefShaderType)
{
VERIFY_EXPR(m_NumResources == MaxOffset);
@@ -163,14 +164,14 @@ public:
m_dbgShaderType = dbgRefShaderType;
}
- D3D12_DESCRIPTOR_HEAP_TYPE DbgGetHeapType()const{return m_dbgHeapType;}
+ Vk_DESCRIPTOR_HEAP_TYPE DbgGetHeapType()const{return m_dbgHeapType;}
#endif
const Uint32 m_NumResources = 0;
private:
#ifdef _DEBUG
- D3D12_DESCRIPTOR_HEAP_TYPE m_dbgHeapType = D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES;
+ Vk_DESCRIPTOR_HEAP_TYPE m_dbgHeapType = Vk_DESCRIPTOR_HEAP_TYPE_NUM_TYPES;
SHADER_TYPE m_dbgShaderType = SHADER_TYPE_UNKNOWN;
#endif
@@ -195,7 +196,7 @@ public:
auto &Tbl = GetRootTable(rt);
if(Tbl.m_TableStartOffset != InvalidDescriptorOffset)
{
- if(Tbl.DbgGetHeapType() == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV)
+ if(Tbl.DbgGetHeapType() == Vk_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV)
{
VERIFY(Tbl.m_TableStartOffset == NumSrvCbvUavDescriptors, "Descriptor space allocation is not continuous");
NumSrvCbvUavDescriptors = std::max(NumSrvCbvUavDescriptors, Tbl.m_TableStartOffset + Tbl.GetSize());
@@ -215,29 +216,29 @@ public:
m_SamplerHeapSpace = std::move(SamplerHeapSpace);
}
- ID3D12DescriptorHeap* GetSrvCbvUavDescriptorHeap(){return m_CbvSrvUavHeapSpace.GetDescriptorHeap();}
- ID3D12DescriptorHeap* GetSamplerDescriptorHeap() {return m_SamplerHeapSpace.GetDescriptorHeap();}
+ IVkDescriptorHeap* GetSrvCbvUavDescriptorHeap(){return m_CbvSrvUavHeapSpace.GetDescriptorHeap();}
+ IVkDescriptorHeap* GetSamplerDescriptorHeap() {return m_SamplerHeapSpace.GetDescriptorHeap();}
// Returns CPU descriptor handle of a shader visible descriptor heap allocation
- template<D3D12_DESCRIPTOR_HEAP_TYPE HeapType>
- D3D12_CPU_DESCRIPTOR_HANDLE GetShaderVisibleTableCPUDescriptorHandle(Uint32 RootParamInd, Uint32 OffsetFromTableStart = 0)
+ template<Vk_DESCRIPTOR_HEAP_TYPE HeapType>
+ Vk_CPU_DESCRIPTOR_HANDLE GetShaderVisibleTableCPUDescriptorHandle(Uint32 RootParamInd, Uint32 OffsetFromTableStart = 0)
{
auto &RootParam = GetRootTable(RootParamInd);
VERIFY(HeapType == RootParam.DbgGetHeapType(), "Invalid descriptor heap type");
- D3D12_CPU_DESCRIPTOR_HANDLE CPUDescriptorHandle = {0};
+ Vk_CPU_DESCRIPTOR_HANDLE CPUDescriptorHandle = {0};
// Descriptor heap allocation is not assigned for dynamic resources or
// in a special case when resource cache is used to store static
// variable assignments for a shader. It is also not assigned to root views
if( RootParam.m_TableStartOffset != InvalidDescriptorOffset )
{
VERIFY(OffsetFromTableStart < RootParam.m_NumResources, "Offset is out of range");
- if( HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER )
+ if( HeapType == Vk_DESCRIPTOR_HEAP_TYPE_SAMPLER )
{
VERIFY_EXPR(!m_SamplerHeapSpace.IsNull());
CPUDescriptorHandle = m_SamplerHeapSpace.GetCpuHandle(RootParam.m_TableStartOffset + OffsetFromTableStart);
}
- else if( HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV )
+ else if( HeapType == Vk_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV )
{
VERIFY_EXPR(!m_CbvSrvUavHeapSpace.IsNull());
CPUDescriptorHandle = m_CbvSrvUavHeapSpace.GetCpuHandle(RootParam.m_TableStartOffset + OffsetFromTableStart);
@@ -252,21 +253,21 @@ public:
}
// Returns GPU descriptor handle of a shader visible descriptor table
- template<D3D12_DESCRIPTOR_HEAP_TYPE HeapType>
- D3D12_GPU_DESCRIPTOR_HANDLE GetShaderVisibleTableGPUDescriptorHandle(Uint32 RootParamInd, Uint32 OffsetFromTableStart = 0)
+ template<Vk_DESCRIPTOR_HEAP_TYPE HeapType>
+ Vk_GPU_DESCRIPTOR_HANDLE GetShaderVisibleTableGPUDescriptorHandle(Uint32 RootParamInd, Uint32 OffsetFromTableStart = 0)
{
auto &RootParam = GetRootTable(RootParamInd);
VERIFY(RootParam.m_TableStartOffset != InvalidDescriptorOffset, "GPU descriptor handle must never be requested for dynamic resources");
VERIFY(OffsetFromTableStart < RootParam.m_NumResources, "Offset is out of range");
- D3D12_GPU_DESCRIPTOR_HANDLE GPUDescriptorHandle = {0};
+ Vk_GPU_DESCRIPTOR_HANDLE GPUDescriptorHandle = {0};
VERIFY( HeapType == RootParam.DbgGetHeapType(), "Invalid descriptor heap type");
- if( HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER )
+ if( HeapType == Vk_DESCRIPTOR_HEAP_TYPE_SAMPLER )
{
VERIFY_EXPR(!m_SamplerHeapSpace.IsNull());
GPUDescriptorHandle = m_SamplerHeapSpace.GetGpuHandle(RootParam.m_TableStartOffset + OffsetFromTableStart);
}
- else if( HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV )
+ else if( HeapType == Vk_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV )
{
VERIFY_EXPR(!m_CbvSrvUavHeapSpace.IsNull());
GPUDescriptorHandle = m_CbvSrvUavHeapSpace.GetGpuHandle(RootParam.m_TableStartOffset + OffsetFromTableStart);
@@ -285,10 +286,10 @@ public:
#endif
private:
- ShaderResourceCacheD3D12(const ShaderResourceCacheD3D12&) = delete;
- ShaderResourceCacheD3D12(ShaderResourceCacheD3D12&&) = delete;
- ShaderResourceCacheD3D12& operator = (const ShaderResourceCacheD3D12&) = delete;
- ShaderResourceCacheD3D12& operator = (ShaderResourceCacheD3D12&&) = delete;
+ ShaderResourceCacheVk(const ShaderResourceCacheVk&) = delete;
+ ShaderResourceCacheVk(ShaderResourceCacheVk&&) = delete;
+ ShaderResourceCacheVk& operator = (const ShaderResourceCacheVk&) = delete;
+ ShaderResourceCacheVk& operator = (ShaderResourceCacheVk&&) = delete;
// Allocation in a GPU-visible sampler descriptor heap
DescriptorHeapAllocation m_SamplerHeapSpace;
@@ -304,6 +305,7 @@ private:
// Only for debug purposes: indicates what types of resources are stored in the cache
const DbgCacheContentType m_DbgContentType;
#endif
-};
#endif
+};
+
}
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h
index 151daba7..3ff225d7 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h
@@ -107,11 +107,11 @@
#include "unordered_map"
#include "ShaderBase.h"
-#include "ShaderBase.h"
#include "HashUtils.h"
#include "ShaderResourcesVk.h"
#include "ShaderResourceCacheVk.h"
-//#include "ShaderVariable.h"
+#include "SPIRVShaderResources.h"
+#include "VulkanUtilities/VulkanLogicalDevice.h"
#ifdef _DEBUG
# define VERIFY_SHADER_BINDINGS
@@ -125,17 +125,16 @@ namespace Diligent
class ShaderResourceLayoutVk
{
public:
-#if 0
ShaderResourceLayoutVk(IObject &Owner, IMemoryAllocator &ResourceLayoutDataAllocator);
// This constructor is used by ShaderResourceBindingVkImpl to clone layout from the reference layout in PipelineStateVkImpl.
// Root indices and descriptor table offsets must be correct. Resource cache is assigned, but not initialized.
- ShaderResourceLayoutVk(IObject &Owner,
- const ShaderResourceLayoutVk& SrcLayout,
- IMemoryAllocator &ResourceLayoutDataAllocator,
- const SHADER_VARIABLE_TYPE *AllowedVarTypes,
- Uint32 NumAllowedTypes,
- ShaderResourceCacheVk &ResourceCache);
+ //ShaderResourceLayoutVk(IObject &Owner,
+ // const ShaderResourceLayoutVk& SrcLayout,
+ // IMemoryAllocator &ResourceLayoutDataAllocator,
+ // const SHADER_VARIABLE_TYPE *AllowedVarTypes,
+ // Uint32 NumAllowedTypes,
+ // ShaderResourceCacheVk &ResourceCache);
ShaderResourceLayoutVk(const ShaderResourceLayoutVk&) = delete;
ShaderResourceLayoutVk(ShaderResourceLayoutVk&&) = delete;
@@ -150,14 +149,15 @@ public:
// - PipelineStateVkImpl class instance to reference all types of resources (static, mutable, dynamic).
// Root indices and descriptor table offsets are assigned during the initialization;
// no shader resource cache is provided
- void Initialize(IVkDevice *pVkDevice,
- const std::shared_ptr<const ShaderResourcesVk>& pSrcResources,
+ void Initialize(const VulkanUtilities::VulkanLogicalDevice &LogicalDevice,
+ const std::shared_ptr<const SPIRVShaderResources>& pSrcResources,
IMemoryAllocator &LayoutDataAllocator,
const SHADER_VARIABLE_TYPE *VarTypes,
Uint32 NumAllowedTypes,
ShaderResourceCacheVk *pResourceCache,
- class RootSignature *pRootSig);
-
+ std::vector<uint32_t> *pSPIRV,
+ class PipelineLayout *pPipelineLayout);
+#if 0
// sizeof(SRV_CBV_UAV) == 32 (x64)
struct SRV_CBV_UAV : ShaderVariableD3DBase<ShaderResourceLayoutVk>
{
@@ -213,9 +213,10 @@ public:
}
bool IsBound(Uint32 ArrayIndex);
-
+#endif
// Non-virtual function
void BindResource(IDeviceObject *pObject, Uint32 ArrayIndex, const ShaderResourceLayoutVk *dbgResLayout);
+#if 0
virtual void Set(IDeviceObject *pObject)override final{ BindResource(pObject, 0, nullptr); }
virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)override final
@@ -311,17 +312,16 @@ public:
void CopyStaticResourceDesriptorHandles(const ShaderResourceLayoutVk &SrcLayout);
-
+#endif
// dbgResourceCache is only used for sanity check and as a remainder that the resource cache must be alive
// while Layout is alive
void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags, const ShaderResourceCacheVk *dbgResourceCache );
-
IShaderVariable* GetShaderVariable( const Char* Name );
#ifdef VERIFY_SHADER_BINDINGS
void dbgVerifyBindings()const;
#endif
-
+#if 0
IObject& GetOwner(){return m_Owner;}
private:
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h
index d2541077..d7852c37 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h
@@ -30,7 +30,6 @@
#include "ShaderVk.h"
#include "ShaderBase.h"
#include "ShaderResourceLayoutVk.h"
-#include "VulkanUtilities/VulkanObjectWrappers.h"
#include "SPIRVShaderResources.h"
#ifdef _DEBUG
@@ -58,29 +57,29 @@ public:
virtual IShaderVariable* GetShaderVariable(const Char* Name)override;
- virtual VkShaderModule GetVkShaderModule()override final
+ virtual const std::vector<uint32_t>& GetSPIRV()const override final
{
- return m_VkShaderModule;
+ return m_SPIRV;
}
const std::shared_ptr<const SPIRVShaderResources>& GetShaderResources()const{return m_pShaderResources;}
- //const ShaderResourceLayoutVk& GetConstResLayout()const{return m_StaticResLayout;}
- /*
+ const ShaderResourceLayoutVk& GetConstResLayout()const{return m_StaticResLayout;}
+
#ifdef VERIFY_SHADER_BINDINGS
void DbgVerifyStaticResourceBindings();
#endif
-
+
private:
DummyShaderVariable m_DummyShaderVar; ///< Dummy shader variable
- */
+
// ShaderResources class instance must be referenced through the shared pointer, because
// it is referenced by ShaderResourceLayoutVk class instances
std::shared_ptr<const SPIRVShaderResources> m_pShaderResources;
- //ShaderResourceLayoutVk m_StaticResLayout;
- //ShaderResourceCacheVk m_ConstResCache;
+ ShaderResourceLayoutVk m_StaticResLayout;
+ ShaderResourceCacheVk m_ConstResCache;
- VulkanUtilities::ShaderModuleWrapper m_VkShaderModule;
+ std::vector<uint32_t> m_SPIRV;
};
}
diff --git a/Graphics/GraphicsEngineVulkan/interface/ShaderVk.h b/Graphics/GraphicsEngineVulkan/interface/ShaderVk.h
index 2f7acbda..08a3ef1b 100644
--- a/Graphics/GraphicsEngineVulkan/interface/ShaderVk.h
+++ b/Graphics/GraphicsEngineVulkan/interface/ShaderVk.h
@@ -26,6 +26,7 @@
/// \file
/// Definition of the Diligent::IShaderVk interface
+#include <vector>
#include "../../GraphicsEngine/interface/Shader.h"
namespace Diligent
@@ -40,8 +41,8 @@ class IShaderVk : public IShader
{
public:
- /// Returns Vulkan shader module handle
- virtual VkShaderModule GetVkShaderModule() = 0;
+ /// Returns SPIRV bytecode
+ virtual const std::vector<uint32_t>& GetSPIRV()const = 0;
};
}
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
index 17f4bcda..c9b90adc 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
@@ -34,8 +34,8 @@
namespace Diligent
{
-/*
-void PipelineStateVkImpl::ParseShaderResourceLayout(IShader *pShader)
+
+void PipelineStateVkImpl::ParseResourceLayoutAndCreateShader(IShader *pShader)
{
VERIFY_EXPR(pShader);
@@ -46,13 +46,23 @@ void PipelineStateVkImpl::ParseShaderResourceLayout(IShader *pShader)
VERIFY(m_pShaderResourceLayouts[ShaderInd] == nullptr, "Shader resource layout has already been initialized");
auto pDeviceVkImpl = ValidatedCast<RenderDeviceVkImpl>(pShaderVk->GetDevice());
+ const auto &LogicalDevice = pDeviceVkImpl->GetLogicalDevice();
auto &ShaderResLayoutAllocator = GetRawAllocator();
auto *pRawMem = ALLOCATE(ShaderResLayoutAllocator, "Raw memory for ShaderResourceLayoutVk", sizeof(ShaderResourceLayoutVk));
m_pShaderResourceLayouts[ShaderInd] = new (pRawMem) ShaderResourceLayoutVk(*this, GetRawAllocator());
- m_pShaderResourceLayouts[ShaderInd]->Initialize(pDeviceVkImpl->GetVkDevice(), pShaderVk->GetShaderResources(), GetRawAllocator(), nullptr, 0, nullptr, &m_RootSig);
+ std::vector<uint32_t> SPIRV = pShaderVk->GetSPIRV();
+ m_pShaderResourceLayouts[ShaderInd]->Initialize(LogicalDevice, pShaderVk->GetShaderResources(), GetRawAllocator(), nullptr, 0, nullptr, &SPIRV, &m_PipelineLayout);
+
+ VkShaderModuleCreateInfo ShaderModuleCI = {};
+ ShaderModuleCI.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
+ ShaderModuleCI.pNext = NULL;
+ ShaderModuleCI.flags = 0;
+ ShaderModuleCI.codeSize = SPIRV.size() * sizeof(uint32_t);
+ ShaderModuleCI.pCode = SPIRV.data();
+ m_ShaderModules[ShaderInd] = LogicalDevice.CreateShaderModule(ShaderModuleCI, m_Desc.Name);
}
-*/
+
void PipelineStateVkImpl::CreateRenderPass(const VulkanUtilities::VulkanLogicalDevice &LogicalDevice)
{
@@ -143,11 +153,10 @@ void PipelineStateVkImpl::CreateRenderPass(const VulkanUtilities::VulkanLogicalD
}
PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters *pRefCounters, RenderDeviceVkImpl *pDeviceVk, const PipelineStateDesc &PipelineDesc) :
- TPipelineStateBase(pRefCounters, pDeviceVk, PipelineDesc)/*,
- m_DummyVar(*this)
- m_ResourceCacheDataAllocator(GetRawAllocator(), PipelineDesc.SRBAllocationGranularity),
- m_pDefaultShaderResBinding(nullptr, STDDeleter<ShaderResourceBindingVkImpl, FixedBlockMemoryAllocator>(pDeviceVk->GetSRBAllocator()) )
-*/
+ TPipelineStateBase(pRefCounters, pDeviceVk, PipelineDesc),
+ m_DummyVar(*this),
+ m_ResourceCacheDataAllocator(GetRawAllocator(), PipelineDesc.SRBAllocationGranularity)/*,
+ m_pDefaultShaderResBinding(nullptr, STDDeleter<ShaderResourceBindingVkImpl, FixedBlockMemoryAllocator>(pDeviceVk->GetSRBAllocator()) )*/
{
const auto &LogicalDevice = pDeviceVk->GetLogicalDevice();
if (PipelineDesc.IsComputePipeline)
@@ -163,7 +172,6 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters *pRefCounters, Ren
#ifdef _DEBUG
PipelineCI.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
#endif
- PipelineCI.layout;
PipelineCI.basePipelineHandle = VK_NULL_HANDLE; // a pipeline to derive from
PipelineCI.basePipelineIndex = 0; // an index into the pCreateInfos parameter to use as a pipeline to derive from
@@ -172,17 +180,16 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters *pRefCounters, Ren
CSStage.pNext = nullptr;
CSStage.flags = 0; // reserved for future use
CSStage.stage = VK_SHADER_STAGE_COMPUTE_BIT;
- auto *pShaderVk = ValidatedCast<ShaderVkImpl>(ComputePipeline.pCS);
- CSStage.module = pShaderVk->GetVkShaderModule();
+
+ ParseResourceLayoutAndCreateShader(ComputePipeline.pCS);
+ CSStage.module = m_ShaderModules[CSInd];
+
+ m_PipelineLayout.Finalize(LogicalDevice);
+ PipelineCI.layout = m_PipelineLayout.GetVkPipelineLayout();
+
CSStage.pName = "main";
CSStage.pSpecializationInfo = nullptr;
-#if 0
- ParseShaderResourceLayout(ComputePipeline.pCS);
- m_RootSig.Finalize(pVkDevice);
- VkPSODesc.pRootSignature = m_RootSig.GetVkRootSignature();
-#endif
-
m_Pipeline = LogicalDevice.CreateComputePipeline(PipelineCI, VK_NULL_HANDLE, m_Desc.Name);
}
else
@@ -199,6 +206,11 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters *pRefCounters, Ren
#ifdef _DEBUG
PipelineCI.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
#endif
+
+#if 0
+ m_PipelineLayout.AllocateStaticSamplers(GetShaders(), GetNumShaders());
+#endif
+
PipelineCI.stageCount = m_NumShaders;
std::vector<VkPipelineShaderStageCreateInfo> Stages(PipelineCI.stageCount);
for (Uint32 s = 0; s < m_NumShaders; ++s)
@@ -220,12 +232,16 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters *pRefCounters, Ren
default: UNEXPECTED("Unknown shader type");
}
- auto *pShaderVk = ValidatedCast<ShaderVkImpl>(pShader);
- StageCI.module = pShaderVk->GetVkShaderModule();
+ ParseResourceLayoutAndCreateShader(pShader);
+
+ StageCI.module = m_ShaderModules[GetShaderTypeIndex(ShaderType)];
StageCI.pName = "main"; // entry point
StageCI.pSpecializationInfo = nullptr;
}
+ m_PipelineLayout.Finalize(LogicalDevice);
+ PipelineCI.layout = m_PipelineLayout.GetVkPipelineLayout();
+
PipelineCI.pStages = Stages.data();
VkPipelineVertexInputStateCreateInfo VertexInputStateCI = {};
@@ -344,72 +360,20 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters *pRefCounters, Ren
DynamicStateCI.pDynamicStates = DynamicStates.data();
PipelineCI.pDynamicState = &DynamicStateCI;
-
- VkPipelineLayoutCreateInfo PipelineLayoutCI = {};
- PipelineLayoutCI.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
- PipelineLayoutCI.pNext = nullptr;
- PipelineLayoutCI.flags = 0; // reserved for future use
- PipelineLayoutCI.setLayoutCount = 0;
- PipelineLayoutCI.pSetLayouts = nullptr;
- PipelineLayoutCI.pushConstantRangeCount = 0;
- PipelineLayoutCI.pPushConstantRanges = nullptr;
- m_TmpPipelineLayout = LogicalDevice.CreatePipelineLayout(PipelineLayoutCI);
- PipelineCI.layout = m_TmpPipelineLayout;
-
+
PipelineCI.renderPass = m_RenderPass;
PipelineCI.subpass = 0;
PipelineCI.basePipelineHandle = VK_NULL_HANDLE; // a pipeline to derive from
PipelineCI.basePipelineIndex = 0; // an index into the pCreateInfos parameter to use as a pipeline to derive from
m_Pipeline = LogicalDevice.CreateGraphicsPipeline(PipelineCI, VK_NULL_HANDLE, m_Desc.Name);
-
-#if 0
- m_RootSig.AllocateStaticSamplers( GetShaders(), GetNumShaders() );
-
-#define INIT_SHADER(VarName, ExpectedType)\
- if (GraphicsPipeline.p##VarName) \
- { \
- auto ShaderType = GraphicsPipeline.p##VarName->GetDesc().ShaderType; \
- if( ShaderType != ExpectedType ) \
- LOG_ERROR_AND_THROW( GetShaderTypeLiteralName(ShaderType), " shader is provided while ", GetShaderTypeLiteralName(ExpectedType), " is expected");\
- auto *pByteCode = ValidatedCast<ShaderVkImpl>(GraphicsPipeline.p##VarName)->GetShaderByteCode(); \
- VkPSODesc.VarName.pShaderBytecode = pByteCode->GetBufferPointer(); \
- VkPSODesc.VarName.BytecodeLength = pByteCode->GetBufferSize(); \
- ParseShaderResourceLayout(GraphicsPipeline.p##VarName); \
- } \
- else \
- { \
- VkPSODesc.VarName.pShaderBytecode = nullptr; \
- VkPSODesc.VarName.BytecodeLength = 0; \
- }
-
- INIT_SHADER(VS, SHADER_TYPE_VERTEX);
- INIT_SHADER(PS, SHADER_TYPE_PIXEL);
- INIT_SHADER(GS, SHADER_TYPE_GEOMETRY);
- INIT_SHADER(DS, SHADER_TYPE_DOMAIN);
- INIT_SHADER(HS, SHADER_TYPE_HULL);
-#undef INIT_SHADER
-
- m_RootSig.Finalize(pVkDevice);
- VkPSODesc.pRootSignature = m_RootSig.GetVkRootSignature();
-
- memset(&VkPSODesc.StreamOutput, 0, sizeof(VkPSODesc.StreamOutput));
-#endif
- }
-#if 0
- if (*m_Desc.Name != 0)
- {
- m_pVkPSO->SetName(WidenString(m_Desc.Name).c_str());
- String RootSignatureDesc("Root signature for PSO \"");
- RootSignatureDesc.append(m_Desc.Name);
- RootSignatureDesc.push_back('\"');
- m_RootSig.GetVkRootSignature()->SetName(WidenString(RootSignatureDesc).c_str());
}
if(PipelineDesc.SRBAllocationGranularity > 1)
m_ResLayoutDataAllocators.Init(m_NumShaders, PipelineDesc.SRBAllocationGranularity);
auto &SRBAllocator = pDeviceVk->GetSRBAllocator();
+#if 0
// Default shader resource binding must be initialized after resource layouts are parsed!
m_pDefaultShaderResBinding.reset( NEW_RC_OBJ(SRBAllocator, "ShaderResourceBindingVkImpl instance", ShaderResourceBindingVkImpl, this)(this, true) );
@@ -424,9 +388,15 @@ PipelineStateVkImpl::~PipelineStateVkImpl()
pDeviceVkImpl->SafeReleaseVkObject(std::move(m_RenderPass));
pDeviceVkImpl->SafeReleaseVkObject(std::move(m_Pipeline));
m_PipelineLayout.Release(pDeviceVkImpl);
- //pDeviceVkImpl->SafeReleaseVkObject(std::move(m_TmpPipelineLayout));
-#if 0
+ for(auto &ShaderModule : m_ShaderModules)
+ {
+ if(ShaderModule != VK_NULL_HANDLE)
+ {
+ pDeviceVkImpl->SafeReleaseVkObject(std::move(ShaderModule));
+ }
+ }
+
auto &ShaderResLayoutAllocator = GetRawAllocator();
for(Int32 l = 0; l < _countof(m_pShaderResourceLayouts); ++l)
{
@@ -436,14 +406,12 @@ PipelineStateVkImpl::~PipelineStateVkImpl()
ShaderResLayoutAllocator.Free(m_pShaderResourceLayouts[l]);
}
}
-#endif
}
IMPLEMENT_QUERY_INTERFACE( PipelineStateVkImpl, IID_PipelineStateVk, TPipelineStateBase )
void PipelineStateVkImpl::BindShaderResources(IResourceMapping *pResourceMapping, Uint32 Flags)
{
-#if 0
if( m_Desc.IsComputePipeline )
{
if(m_pCS)m_pCS->BindResources(pResourceMapping, Flags);
@@ -456,7 +424,6 @@ void PipelineStateVkImpl::BindShaderResources(IResourceMapping *pResourceMapping
if(m_pDS)m_pDS->BindResources(pResourceMapping, Flags);
if(m_pHS)m_pHS->BindResources(pResourceMapping, Flags);
}
-#endif
}
void PipelineStateVkImpl::CreateShaderResourceBinding(IShaderResourceBinding **ppShaderResourceBinding)
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp
index 4fc3a695..5493dcad 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp
@@ -37,19 +37,19 @@
namespace Diligent
{
-#if 0
ShaderResourceLayoutVk::ShaderResourceLayoutVk(IObject &Owner,
- IMemoryAllocator &ResourceLayoutDataAllocator) :
+ IMemoryAllocator &ResourceLayoutDataAllocator) /*:
m_Owner(Owner),
#if USE_VARIABLE_HASH_MAP
m_VariableHash(STD_ALLOCATOR_RAW_MEM(VariableHashElemType, GetRawAllocator(), "Allocator for unordered_map<HashMapStringKey, IShaderVariable*>")),
#endif
- m_ResourceBuffer(nullptr, STDDeleterRawMem<void>(ResourceLayoutDataAllocator))
+ m_ResourceBuffer(nullptr, STDDeleterRawMem<void>(ResourceLayoutDataAllocator))*/
{
}
ShaderResourceLayoutVk::~ShaderResourceLayoutVk()
{
+#if 0
// For some reason MS compiler generates this false warning:
// warning C4189: 'CbvSrvUav': local variable is initialized but not referenced
#pragma warning(push)
@@ -61,8 +61,10 @@ ShaderResourceLayoutVk::~ShaderResourceLayoutVk()
for(Uint32 s=0; s < GetTotalSamplerCount(); ++s)
m_Samplers[s].~Sampler();
+#endif
}
+#if 0
Vk_DESCRIPTOR_RANGE_TYPE GetDescriptorRangeType(CachedResourceType ResType)
{
static Vk_DESCRIPTOR_RANGE_TYPE RangeTypes[(size_t)CachedResourceType::NumTypes] = {};
@@ -169,17 +171,18 @@ ShaderResourceLayoutVk::ShaderResourceLayoutVk(IObject &Owner,
}
#endif
}
+#endif
-// http://diligentgraphics.com/diligent-engine/architecture/Vk/shader-resource-layout#Initializing-Shader-Resource-Layouts-and-Root-Signature-in-a-Pipeline-State-Object
-// http://diligentgraphics.com/diligent-engine/architecture/Vk/shader-resource-cache#Initializing-Shader-Resource-Layouts-in-a-Pipeline-State
-void ShaderResourceLayoutVk::Initialize(IVkDevice *pVkDevice,
- const std::shared_ptr<const ShaderResourcesVk>& pSrcResources,
- IMemoryAllocator &LayoutDataAllocator,
- const SHADER_VARIABLE_TYPE *AllowedVarTypes,
- Uint32 NumAllowedTypes,
- ShaderResourceCacheVk* pResourceCache,
- RootSignature *pRootSig)
+void ShaderResourceLayoutVk::Initialize(const VulkanUtilities::VulkanLogicalDevice &LogicalDevice,
+ const std::shared_ptr<const SPIRVShaderResources>& pSrcResources,
+ IMemoryAllocator &LayoutDataAllocator,
+ const SHADER_VARIABLE_TYPE *VarTypes,
+ Uint32 NumAllowedTypes,
+ ShaderResourceCacheVk *pResourceCache,
+ std::vector<uint32_t> *pSPIRV,
+ class PipelineLayout *pPipelineLayout)
{
+#if 0
m_pResources = pSrcResources;
m_pResourceCache = pResourceCache;
m_pVkDevice = pVkDevice;
@@ -376,9 +379,10 @@ void ShaderResourceLayoutVk::Initialize(IVkDevice *pVkDevice,
}
InitVariablesHashMap();
+#endif
}
-
+#if 0
void ShaderResourceLayoutVk::InitVariablesHashMap()
{
#if USE_VARIABLE_HASH_MAP
@@ -743,10 +747,11 @@ bool ShaderResourceLayoutVk::SRV_CBV_UAV::IsBound(Uint32 ArrayIndex)
return false;
}
-
+#endif
void ShaderResourceLayoutVk::BindResources( IResourceMapping* pResourceMapping, Uint32 Flags, const ShaderResourceCacheVk *dbgResourceCache )
{
+#if 0
VERIFY(dbgResourceCache == m_pResourceCache, "Resource cache does not match the cache provided at initialization");
if( !pResourceMapping )
@@ -783,11 +788,12 @@ void ShaderResourceLayoutVk::BindResources( IResourceMapping* pResourceMapping,
}
}
}
+#endif
}
-
IShaderVariable* ShaderResourceLayoutVk::GetShaderVariable(const Char* Name)
{
+#if 0
IShaderVariable* pVar = nullptr;
#if USE_VARIABLE_HASH_MAP
// Name will be implicitly converted to HashMapStringKey without making a copy
@@ -812,10 +818,12 @@ IShaderVariable* ShaderResourceLayoutVk::GetShaderVariable(const Char* Name)
LOG_ERROR_MESSAGE( "Shader variable \"", Name, "\" is not found in shader \"", GetShaderName(), "\" (", GetShaderTypeLiteralName(m_pResources->GetShaderType()), "). Attempts to set the variable will be silently ignored." );
}
return pVar;
+#endif
+ return nullptr;
}
-
+#if 0
void ShaderResourceLayoutVk::CopyStaticResourceDesriptorHandles(const ShaderResourceLayoutVk &SrcLayout)
{
if (!m_pResourceCache)
@@ -924,11 +932,12 @@ void ShaderResourceLayoutVk::CopyStaticResourceDesriptorHandles(const ShaderReso
}
}
}
-
+#endif
#ifdef VERIFY_SHADER_BINDINGS
void ShaderResourceLayoutVk::dbgVerifyBindings()const
{
+#if 0
VERIFY(m_pResourceCache, "Resource cache is null");
for(SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1))
@@ -1054,9 +1063,12 @@ void ShaderResourceLayoutVk::dbgVerifyBindings()const
}
}
}
+#endif
}
#endif
+#if 0
+
const Char* ShaderResourceLayoutVk::GetShaderName()const
{
RefCntAutoPtr<IShader> pShader(&m_Owner, IID_Shader);
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
index 64084135..100e859d 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
@@ -28,7 +28,6 @@
#include "DataBlobImpl.h"
#include "GLSLSourceBuilder.h"
#include "GLSL2SPIRV.h"
-//#include "D3DShaderResourceLoader.h"
using namespace Diligent;
@@ -37,73 +36,55 @@ namespace Diligent
ShaderVkImpl::ShaderVkImpl(IReferenceCounters *pRefCounters, RenderDeviceVkImpl *pRenderDeviceVk, const ShaderCreationAttribs &CreationAttribs) :
- TShaderBase(pRefCounters, pRenderDeviceVk, CreationAttribs.Desc)/*,
- ShaderD3DBase(ShaderCreationAttribs),
+ TShaderBase(pRefCounters, pRenderDeviceVk, CreationAttribs.Desc),
m_StaticResLayout(*this, GetRawAllocator()),
m_DummyShaderVar(*this),
- m_ConstResCache(ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources)*/
+ m_ConstResCache(/*ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources*/)
{
auto GLSLSource = BuildGLSLSourceString(CreationAttribs, TargetGLSLCompiler::glslang);
- auto SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str());
- if(SPIRV.empty())
+ m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str());
+ if(m_SPIRV.empty())
{
LOG_ERROR_AND_THROW("Failed to compile shader");
}
- const auto &LogicalDevice = pRenderDeviceVk->GetLogicalDevice();
- VkShaderModuleCreateInfo ShaderModuleCI = {};
- ShaderModuleCI.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
- ShaderModuleCI.pNext = NULL;
- ShaderModuleCI.flags = 0;
- ShaderModuleCI.codeSize = SPIRV.size() * sizeof(unsigned int);
- ShaderModuleCI.pCode = SPIRV.data();
- m_VkShaderModule = LogicalDevice.CreateShaderModule(ShaderModuleCI, m_Desc.Name);
-
+ // We cannot create shader module here because resource bindings are assigned when
+ // pipeline state is created
+
// Load shader resources
auto &Allocator = GetRawAllocator();
auto *pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(SPIRVShaderResources));
- auto *pResources = new (pRawMem) SPIRVShaderResources(Allocator, m_Desc.ShaderType, std::move(SPIRV), m_Desc.DefaultVariableType, m_Desc.VariableDesc, m_Desc.NumVariables);
+ auto *pResources = new (pRawMem) SPIRVShaderResources(Allocator, m_Desc.ShaderType, m_SPIRV, m_Desc.DefaultVariableType, m_Desc.VariableDesc, m_Desc.NumVariables);
m_pShaderResources.reset(pResources, STDDeleterRawMem<SPIRVShaderResources>(Allocator));
- /*
// Clone only static resources that will be set directly in the shader
// http://diligentgraphics.com/diligent-engine/architecture/Vk/shader-resource-layout#Initializing-Special-Resource-Layout-for-Managing-Static-Shader-Resources
SHADER_VARIABLE_TYPE VarTypes[] = {SHADER_VARIABLE_TYPE_STATIC};
- m_StaticResLayout.Initialize(pRenderDeviceVk->GetVkDevice(), m_pShaderResources, GetRawAllocator(), VarTypes, _countof(VarTypes), &m_ConstResCache, nullptr);
-*/
+ m_StaticResLayout.Initialize(pRenderDeviceVk->GetLogicalDevice(), m_pShaderResources, GetRawAllocator(), VarTypes, _countof(VarTypes), &m_ConstResCache, nullptr, nullptr);
}
ShaderVkImpl::~ShaderVkImpl()
{
- auto pDeviceVkImpl = ValidatedCast<RenderDeviceVkImpl>(GetDevice());
- pDeviceVkImpl->SafeReleaseVkObject(std::move(m_VkShaderModule));
}
void ShaderVkImpl::BindResources(IResourceMapping* pResourceMapping, Uint32 Flags)
{
-#if 0
m_StaticResLayout.BindResources(pResourceMapping, Flags, &m_ConstResCache);
-#endif
}
IShaderVariable* ShaderVkImpl::GetShaderVariable(const Char* Name)
{
-#if 0
auto *pVar = m_StaticResLayout.GetShaderVariable(Name);
if(pVar == nullptr)
pVar = &m_DummyShaderVar;
return pVar;
-#endif
- return nullptr;
}
-#if 0
#ifdef VERIFY_SHADER_BINDINGS
void ShaderVkImpl::DbgVerifyStaticResourceBindings()
{
m_StaticResLayout.dbgVerifyBindings();
}
#endif
-#endif
}