summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-08-04 21:05:42 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-08-04 21:05:42 +0000
commit86bd2d7175d3e2d0f5c1c313a802a22c9f95b4ea (patch)
treee4d8d6f4f90a4805d6d230d6fd7f49390be4cdab /Graphics
parentAdded render pass MS resolve test (diff)
downloadDiligentCore-86bd2d7175d3e2d0f5c1c313a802a22c9f95b4ea.tar.gz
DiligentCore-86bd2d7175d3e2d0f5c1c313a802a22c9f95b4ea.zip
Implemented input attachments in Vulkan backend; added test
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GLSLTools/include/SPIRVShaderResources.hpp22
-rw-r--r--Graphics/GLSLTools/src/SPIRVShaderResources.cpp40
-rw-r--r--Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp2
-rw-r--r--Graphics/GraphicsEngine/include/TextureBase.hpp3
-rw-r--r--Graphics/GraphicsEngine/interface/GraphicsTypes.h15
-rw-r--r--Graphics/GraphicsEngine/interface/Shader.h11
-rw-r--r--Graphics/GraphicsEngine/src/RenderPassBase.cpp8
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp1
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp5
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp3
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp25
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp42
12 files changed, 154 insertions, 23 deletions
diff --git a/Graphics/GLSLTools/include/SPIRVShaderResources.hpp b/Graphics/GLSLTools/include/SPIRVShaderResources.hpp
index 96e778a0..7a1b93ce 100644
--- a/Graphics/GLSLTools/include/SPIRVShaderResources.hpp
+++ b/Graphics/GLSLTools/include/SPIRVShaderResources.hpp
@@ -70,6 +70,7 @@ struct SPIRVShaderResourceAttribs
AtomicCounter,
SeparateImage,
SeparateSampler,
+ InputAttachment,
NumResourceTypes
};
@@ -205,7 +206,8 @@ public:
Uint32 GetNumSmpldImgs()const noexcept{ return (m_AtomicCounterOffset - m_SampledImageOffset); }
Uint32 GetNumACs ()const noexcept{ return (m_SeparateSamplerOffset - m_AtomicCounterOffset); }
Uint32 GetNumSepSmplrs()const noexcept{ return (m_SeparateImageOffset - m_SeparateSamplerOffset);}
- Uint32 GetNumSepImgs ()const noexcept{ return (m_TotalResources - m_SeparateImageOffset); }
+ Uint32 GetNumSepImgs ()const noexcept{ return (m_InputAttachmentOffset - m_SeparateImageOffset); }
+ Uint32 GetNumInptAtts ()const noexcept{ return (m_TotalResources - m_InputAttachmentOffset);}
Uint32 GetTotalResources() const noexcept { return m_TotalResources; }
Uint32 GetNumShaderStageInputs()const noexcept { return m_NumShaderStageInputs; }
@@ -216,6 +218,7 @@ public:
const SPIRVShaderResourceAttribs& GetAC (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumACs(), m_AtomicCounterOffset ); }
const SPIRVShaderResourceAttribs& GetSepSmplr(Uint32 n)const noexcept{ return GetResAttribs(n, GetNumSepSmplrs(), m_SeparateSamplerOffset); }
const SPIRVShaderResourceAttribs& GetSepImg (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumSepImgs(), m_SeparateImageOffset ); }
+ const SPIRVShaderResourceAttribs& GetInptAtt (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumInptAtts(), m_InputAttachmentOffset); }
const SPIRVShaderResourceAttribs& GetResource(Uint32 n)const noexcept{ return GetResAttribs(n, GetTotalResources(), 0 ); }
// clang-format on
@@ -243,6 +246,7 @@ public:
Uint32 NumACs = 0;
Uint32 NumSepSmplrs = 0;
Uint32 NumSepImgs = 0;
+ Uint32 NumInptAtts = 0;
};
SHADER_TYPE GetShaderType() const noexcept { return m_ShaderType; }
@@ -254,14 +258,16 @@ public:
typename THandleSmplImg,
typename THandleAC,
typename THandleSepSmpl,
- typename THandleSepImg>
+ typename THandleSepImg,
+ typename THandleInptAtt>
void ProcessResources(THandleUB HandleUB,
THandleSB HandleSB,
THandleImg HandleImg,
THandleSmplImg HandleSmplImg,
THandleAC HandleAC,
THandleSepSmpl HandleSepSmpl,
- THandleSepImg HandleSepImg) const
+ THandleSepImg HandleSepImg,
+ THandleInptAtt HandleInptAtt) const
{
for (Uint32 n = 0; n < GetNumUBs(); ++n)
{
@@ -304,6 +310,14 @@ public:
const auto& SepImg = GetSepImg(n);
HandleSepImg(SepImg, n);
}
+
+ for (Uint32 n = 0; n < GetNumInptAtts(); ++n)
+ {
+ const auto& InptAtt = GetInptAtt(n);
+ HandleInptAtt(InptAtt, n);
+ }
+
+ static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please handle the new resource type here, if needed");
}
template <typename THandler>
@@ -359,6 +373,7 @@ private:
SPIRVShaderResourceAttribs& GetAC (Uint32 n)noexcept{ return GetResAttribs(n, GetNumACs(), m_AtomicCounterOffset ); }
SPIRVShaderResourceAttribs& GetSepSmplr(Uint32 n)noexcept{ return GetResAttribs(n, GetNumSepSmplrs(), m_SeparateSamplerOffset); }
SPIRVShaderResourceAttribs& GetSepImg (Uint32 n)noexcept{ return GetResAttribs(n, GetNumSepImgs(), m_SeparateImageOffset ); }
+ SPIRVShaderResourceAttribs& GetInptAtt (Uint32 n)noexcept{ return GetResAttribs(n, GetNumInptAtts(), m_InputAttachmentOffset); }
SPIRVShaderResourceAttribs& GetResource(Uint32 n)noexcept{ return GetResAttribs(n, GetTotalResources(), 0 ); }
// clang-format on
@@ -384,6 +399,7 @@ private:
OffsetType m_AtomicCounterOffset = 0;
OffsetType m_SeparateSamplerOffset = 0;
OffsetType m_SeparateImageOffset = 0;
+ OffsetType m_InputAttachmentOffset = 0;
OffsetType m_TotalResources = 0;
OffsetType m_NumShaderStageInputs = 0;
diff --git a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
index 46705ace..0dd3e4ae 100644
--- a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
+++ b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
@@ -91,7 +91,7 @@ ShaderResourceDesc SPIRVShaderResourceAttribs::GetResourceDesc() const
ResourceDesc.Name = Name;
ResourceDesc.ArraySize = ArraySize;
- static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 10, "Please update switch statement below");
+ static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please handle the new resource type below");
switch (Type)
{
case SPIRVShaderResourceAttribs::ResourceType::UniformBuffer:
@@ -137,6 +137,10 @@ ShaderResourceDesc SPIRVShaderResourceAttribs::GetResourceDesc() const
ResourceDesc.Type = SHADER_RESOURCE_TYPE_SAMPLER;
break;
+ case SPIRVShaderResourceAttribs::ResourceType::InputAttachment:
+ ResourceDesc.Type = SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT;
+ break;
+
default:
UNEXPECTED("Unknown SPIRV resource type");
}
@@ -245,6 +249,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
size_t ResourceNamesPoolSize = 0;
for (const auto& ub : resources.uniform_buffers)
ResourceNamesPoolSize += GetUBName(Compiler, ub, ParsedIRSource).length() + 1;
+ static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please account for the new resource type below");
for (auto* pResType :
{
&resources.storage_buffers,
@@ -252,10 +257,11 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
&resources.sampled_images,
&resources.atomic_counters,
&resources.separate_images,
- &resources.separate_samplers
- //clang-format off
+ &resources.separate_samplers,
+ &resources.subpass_inputs
+ // clang-format off
})
- //clang-format on
+ // clang-format on
{
for (const auto& res : *pResType)
ResourceNamesPoolSize += res.name.length() + 1;
@@ -322,6 +328,8 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
ResCounters.NumACs = static_cast<Uint32>(resources.atomic_counters.size());
ResCounters.NumSepSmplrs = static_cast<Uint32>(resources.separate_samplers.size());
ResCounters.NumSepImgs = static_cast<Uint32>(resources.separate_images.size());
+ ResCounters.NumInptAtts = static_cast<Uint32>(resources.subpass_inputs.size());
+ static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please set the new resource type counter here");
Initialize(Allocator, ResCounters, NumShaderStageInputs, ResourceNamesPoolSize);
{
@@ -469,6 +477,21 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
VERIFY_EXPR(CurrSepImg == GetNumSepImgs());
}
+ {
+ Uint32 CurrSubpassInput = 0;
+ for (const auto& SubpassInput : resources.subpass_inputs)
+ {
+ new (&GetInptAtt(CurrSubpassInput++))
+ SPIRVShaderResourceAttribs(Compiler,
+ SubpassInput,
+ m_ResourceNames.CopyString(SubpassInput.name),
+ SPIRVShaderResourceAttribs::ResourceType::InputAttachment);
+ }
+ VERIFY_EXPR(CurrSubpassInput == GetNumInptAtts());
+ }
+
+ static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please initialize SPIRVShaderResourceAttribs for the new resource type here");
+
if (CombinedSamplerSuffix != nullptr)
{
m_CombinedSamplerSuffix = m_ResourceNames.CopyString(CombinedSamplerSuffix);
@@ -531,7 +554,9 @@ void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator,
m_AtomicCounterOffset = AdvanceOffset(Counters.NumACs);
m_SeparateSamplerOffset = AdvanceOffset(Counters.NumSepSmplrs);
m_SeparateImageOffset = AdvanceOffset(Counters.NumSepImgs);
+ m_InputAttachmentOffset = AdvanceOffset(Counters.NumInptAtts);
m_TotalResources = AdvanceOffset(0);
+ static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please update the new resource type offset");
VERIFY(NumShaderStageInputs <= MaxOffset, "Max offset exceeded");
m_NumShaderStageInputs = static_cast<OffsetType>(NumShaderStageInputs);
@@ -692,6 +717,13 @@ std::string SPIRVShaderResources::DumpResources()
ss << std::endl
<< std::setw(3) << ResNum << " Separate Img ";
DumpResource(SepImg);
+ },
+ [&](const SPIRVShaderResourceAttribs& InptAtt, Uint32) //
+ {
+ VERIFY(InptAtt.Type == SPIRVShaderResourceAttribs::ResourceType::InputAttachment, "Unexpected resource type");
+ ss << std::endl
+ << std::setw(3) << ResNum << " Input Attachment ";
+ DumpResource(InptAtt);
} //
);
VERIFY_EXPR(ResNum == GetTotalResources());
diff --git a/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp b/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp
index 0a4afd54..5cefca34 100644
--- a/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp
+++ b/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp
@@ -1019,6 +1019,7 @@ String GetBufferDescString(const BufferDesc& Desc)
const Char* GetResourceStateFlagString(RESOURCE_STATE State)
{
VERIFY((State & (State - 1)) == 0, "Single state is expected");
+ static_assert(RESOURCE_STATE_MAX_BIT == 0x10000, "Please update this function to handle the new resource state");
switch (State)
{
// clang-format off
@@ -1038,6 +1039,7 @@ const Char* GetResourceStateFlagString(RESOURCE_STATE State)
case RESOURCE_STATE_COPY_SOURCE: return "COPY_SOURCE";
case RESOURCE_STATE_RESOLVE_DEST: return "RESOLVE_DEST";
case RESOURCE_STATE_RESOLVE_SOURCE: return "RESOLVE_SOURCE";
+ case RESOURCE_STATE_INPUT_ATTACHMENT: return "INPUT_ATTACHMENT";
case RESOURCE_STATE_PRESENT: return "PRESENT";
// clang-format on
default:
diff --git a/Graphics/GraphicsEngine/include/TextureBase.hpp b/Graphics/GraphicsEngine/include/TextureBase.hpp
index 38414be2..fd0256b6 100644
--- a/Graphics/GraphicsEngine/include/TextureBase.hpp
+++ b/Graphics/GraphicsEngine/include/TextureBase.hpp
@@ -123,6 +123,9 @@ public:
") correspond to one of ", pDevice->GetCommandQueueCount(), " available device command queues");
this->m_Desc.CommandQueueMask &= DeviceQueuesMask;
+ if ((this->m_Desc.BindFlags & BIND_INPUT_ATTACHMENT) != 0)
+ this->m_Desc.BindFlags |= BIND_SHADER_RESOURCE;
+
// Validate correctness of texture description
ValidateTextureDesc(this->m_Desc);
}
diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h
index 3c0ca99a..727888d9 100644
--- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h
+++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h
@@ -1644,6 +1644,7 @@ struct VulkanDescriptorPoolSize
Uint32 NumStorageBufferDescriptors DEFAULT_INITIALIZER(0);
Uint32 NumUniformTexelBufferDescriptors DEFAULT_INITIALIZER(0);
Uint32 NumStorageTexelBufferDescriptors DEFAULT_INITIALIZER(0);
+ Uint32 NumInputAttachmentDescriptors DEFAULT_INITIALIZER(0);
#if DILIGENT_CPP_INTERFACE
VulkanDescriptorPoolSize()noexcept {}
@@ -1656,7 +1657,8 @@ struct VulkanDescriptorPoolSize
Uint32 _NumUniformBufferDescriptors,
Uint32 _NumStorageBufferDescriptors,
Uint32 _NumUniformTexelBufferDescriptors,
- Uint32 _NumStorageTexelBufferDescriptors)noexcept :
+ Uint32 _NumStorageTexelBufferDescriptors,
+ Uint32 _NumInputAttachmentDescriptors)noexcept :
MaxDescriptorSets {_MaxDescriptorSets },
NumSeparateSamplerDescriptors {_NumSeparateSamplerDescriptors },
NumCombinedSamplerDescriptors {_NumCombinedSamplerDescriptors },
@@ -1665,7 +1667,8 @@ struct VulkanDescriptorPoolSize
NumUniformBufferDescriptors {_NumUniformBufferDescriptors },
NumStorageBufferDescriptors {_NumStorageBufferDescriptors },
NumUniformTexelBufferDescriptors{_NumUniformTexelBufferDescriptors},
- NumStorageTexelBufferDescriptors{_NumStorageTexelBufferDescriptors}
+ NumStorageTexelBufferDescriptors{_NumStorageTexelBufferDescriptors},
+ NumInputAttachmentDescriptors {_NumInputAttachmentDescriptors }
{
// On clang aggregate initialization fails to compile if
// structure members have default initializers
@@ -1700,8 +1703,8 @@ struct EngineVkCreateInfo DILIGENT_DERIVE(EngineCreateInfo)
/// the engine creates another one.
VulkanDescriptorPoolSize MainDescriptorPoolSize
#if DILIGENT_CPP_INTERFACE
- //Max SepSm CmbSm SmpImg StrImg UB SB UTxB StTxB
- {8192, 1024, 8192, 8192, 1024, 4096, 4096, 1024, 1024}
+ //Max SepSm CmbSm SmpImg StrImg UB SB UTxB StTxB InptAtt
+ {8192, 1024, 8192, 8192, 1024, 4096, 4096, 1024, 1024, 256}
#endif
;
@@ -1712,8 +1715,8 @@ struct EngineVkCreateInfo DILIGENT_DERIVE(EngineCreateInfo)
VulkanDescriptorPoolSize DynamicDescriptorPoolSize
#if DILIGENT_CPP_INTERFACE
- //Max SepSm CmbSm SmpImg StrImg UB SB UTxB StTxB
- {2048, 256, 2048, 2048, 256, 1024, 1024, 256, 256}
+ //Max SepSm CmbSm SmpImg StrImg UB SB UTxB StTxB InptAtt
+ {2048, 256, 2048, 2048, 256, 1024, 1024, 256, 256, 64}
#endif
;
diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h
index eacd35f0..f3df92d3 100644
--- a/Graphics/GraphicsEngine/interface/Shader.h
+++ b/Graphics/GraphicsEngine/interface/Shader.h
@@ -283,8 +283,10 @@ struct ShaderCreateInfo
};
typedef struct ShaderCreateInfo ShaderCreateInfo;
+// clang-format off
/// Describes shader resource type
-DILIGENT_TYPED_ENUM(SHADER_RESOURCE_TYPE, Uint8){
+DILIGENT_TYPED_ENUM(SHADER_RESOURCE_TYPE, Uint8)
+{
/// Shader resource type is unknown
SHADER_RESOURCE_TYPE_UNKNOWN = 0,
@@ -304,7 +306,12 @@ DILIGENT_TYPED_ENUM(SHADER_RESOURCE_TYPE, Uint8){
SHADER_RESOURCE_TYPE_BUFFER_UAV,
/// Sampler (separate sampler)
- SHADER_RESOURCE_TYPE_SAMPLER};
+ SHADER_RESOURCE_TYPE_SAMPLER,
+
+ /// Input attachment in a render pass
+ SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT
+};
+// clang-format on
/// Shader resource description
struct ShaderResourceDesc
diff --git a/Graphics/GraphicsEngine/src/RenderPassBase.cpp b/Graphics/GraphicsEngine/src/RenderPassBase.cpp
index a0548e4d..b6b38dd0 100644
--- a/Graphics/GraphicsEngine/src/RenderPassBase.cpp
+++ b/Graphics/GraphicsEngine/src/RenderPassBase.cpp
@@ -89,7 +89,8 @@ void ValidateRenderPassDesc(const RenderPassDesc& Desc)
Attachment.InitialState != RESOURCE_STATE_RESOLVE_DEST &&
Attachment.InitialState != RESOURCE_STATE_RESOLVE_SOURCE &&
Attachment.InitialState != RESOURCE_STATE_COPY_DEST &&
- Attachment.InitialState != RESOURCE_STATE_COPY_SOURCE)
+ Attachment.InitialState != RESOURCE_STATE_COPY_SOURCE &&
+ Attachment.InitialState != RESOURCE_STATE_INPUT_ATTACHMENT)
{
LOG_RENDER_PASS_ERROR_AND_THROW("the initial state of depth-stencil attachment ", i, " (", GetResourceStateString(Attachment.InitialState), ") is invalid.");
}
@@ -101,7 +102,8 @@ void ValidateRenderPassDesc(const RenderPassDesc& Desc)
Attachment.FinalState != RESOURCE_STATE_RESOLVE_DEST &&
Attachment.FinalState != RESOURCE_STATE_RESOLVE_SOURCE &&
Attachment.FinalState != RESOURCE_STATE_COPY_DEST &&
- Attachment.FinalState != RESOURCE_STATE_COPY_SOURCE)
+ Attachment.FinalState != RESOURCE_STATE_COPY_SOURCE &&
+ Attachment.FinalState != RESOURCE_STATE_INPUT_ATTACHMENT)
{
LOG_RENDER_PASS_ERROR_AND_THROW("the final state of depth-stencil attachment ", i, " (", GetResourceStateString(Attachment.FinalState), ") is invalid.");
}
@@ -114,6 +116,7 @@ void ValidateRenderPassDesc(const RenderPassDesc& Desc)
Attachment.InitialState != RESOURCE_STATE_RESOLVE_DEST &&
Attachment.InitialState != RESOURCE_STATE_RESOLVE_SOURCE &&
Attachment.InitialState != RESOURCE_STATE_COPY_SOURCE &&
+ Attachment.InitialState != RESOURCE_STATE_INPUT_ATTACHMENT &&
Attachment.InitialState != RESOURCE_STATE_PRESENT)
{
LOG_RENDER_PASS_ERROR_AND_THROW("the initial state of color attachment ", i, " (", GetResourceStateString(Attachment.InitialState), ") is invalid.");
@@ -125,6 +128,7 @@ void ValidateRenderPassDesc(const RenderPassDesc& Desc)
Attachment.FinalState != RESOURCE_STATE_RESOLVE_DEST &&
Attachment.FinalState != RESOURCE_STATE_RESOLVE_SOURCE &&
Attachment.FinalState != RESOURCE_STATE_COPY_SOURCE &&
+ Attachment.FinalState != RESOURCE_STATE_INPUT_ATTACHMENT &&
Attachment.FinalState != RESOURCE_STATE_PRESENT)
{
LOG_RENDER_PASS_ERROR_AND_THROW("the final state of color attachment ", i, " (", GetResourceStateString(Attachment.FinalState), ") is invalid.");
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp
index 172c82a8..a5278cb7 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp
@@ -117,6 +117,7 @@ public:
VkDescriptorImageInfo GetImageDescriptorWriteInfo (bool IsImmutableSampler)const;
VkBufferView GetBufferViewWriteInfo () const;
VkDescriptorImageInfo GetSamplerDescriptorWriteInfo() const;
+ VkDescriptorImageInfo GetInputAttachmentDescriptorWriteInfo() const;
// clang-format on
};
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp
index 07050821..a6d20641 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp
@@ -260,6 +260,11 @@ public:
VkDescriptorSet vkDescrSet,
Uint32 ArrayInd) const;
+ void CacheInputAttachment(IDeviceObject* pTexView,
+ ShaderResourceCacheVk::Resource& DstRes,
+ VkDescriptorSet vkDescrSet,
+ Uint32 ArrayInd) const;
+
template <typename ObjectType, typename TPreUpdateObject>
bool UpdateCachedResource(ShaderResourceCacheVk::Resource& DstRes,
RefCntAutoPtr<ObjectType>&& pObject,
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp
index 32a68780..aa027b25 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp
@@ -64,7 +64,7 @@ class ResourceTypeToVkDescriptorType
public:
ResourceTypeToVkDescriptorType()
{
- static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 10, "Please add corresponding decriptor type");
+ static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please add the corresponding decriptor type");
m_Map[SPIRVShaderResourceAttribs::ResourceType::UniformBuffer] = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
m_Map[SPIRVShaderResourceAttribs::ResourceType::ROStorageBuffer] = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
m_Map[SPIRVShaderResourceAttribs::ResourceType::RWStorageBuffer] = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
@@ -75,6 +75,7 @@ public:
m_Map[SPIRVShaderResourceAttribs::ResourceType::AtomicCounter] = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
m_Map[SPIRVShaderResourceAttribs::ResourceType::SeparateImage] = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
m_Map[SPIRVShaderResourceAttribs::ResourceType::SeparateSampler] = VK_DESCRIPTOR_TYPE_SAMPLER;
+ m_Map[SPIRVShaderResourceAttribs::ResourceType::InputAttachment] = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
}
VkDescriptorType operator[](SPIRVShaderResourceAttribs::ResourceType ResType) const
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp
index 06239703..caf8ffd2 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp
@@ -155,6 +155,7 @@ void ShaderResourceCacheVk::TransitionResources(DeviceContextVkImpl* pCtxVkImpl)
for (Uint32 res = 0; res < m_TotalResources; ++res)
{
auto& Res = pResources[res];
+ static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please handle the new resource type below");
switch (Res.Type)
{
case SPIRVShaderResourceAttribs::ResourceType::UniformBuffer:
@@ -312,6 +313,14 @@ void ShaderResourceCacheVk::TransitionResources(DeviceContextVkImpl* pCtxVkImpl)
}
break;
+ case SPIRVShaderResourceAttribs::ResourceType::InputAttachment:
+ {
+ // Nothing to do with input attachments - they are transitioned by the render pass.
+ // There is nothing we can validate here - a texture may be in different state at
+ // the beginning of the render pass before being transitioned to INPUT_ATTACHMENT state.
+ }
+ break;
+
default: UNEXPECTED("Unexpected resource type");
}
}
@@ -472,4 +481,20 @@ VkDescriptorImageInfo ShaderResourceCacheVk::Resource::GetSamplerDescriptorWrite
return DescrImgInfo;
}
+VkDescriptorImageInfo ShaderResourceCacheVk::Resource::GetInputAttachmentDescriptorWriteInfo() const
+{
+ VERIFY(Type == SPIRVShaderResourceAttribs::ResourceType::InputAttachment, "Input attachment resource is expected");
+ DEV_CHECK_ERR(pObject != nullptr, "Unable to get input attachment write info: cached object is null");
+
+ auto* pTexViewVk = pObject.RawPtr<const TextureViewVkImpl>();
+ VERIFY_EXPR(pTexViewVk->GetDesc().ViewType == TEXTURE_VIEW_SHADER_RESOURCE);
+
+ VkDescriptorImageInfo DescrImgInfo;
+ DescrImgInfo.sampler = VK_NULL_HANDLE;
+ DescrImgInfo.imageView = pTexViewVk->GetVulkanImageView();
+ DescrImgInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
+
+ return DescrImgInfo;
+}
+
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp
index a02cd8bb..4f28af80 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp
@@ -526,6 +526,11 @@ void ShaderResourceLayoutVk::Initialize(IRenderDevice*
{
VERIFY_EXPR(SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage || SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer);
AddResource(s, Layout, Resources, SepImg);
+ },
+ [&](const SPIRVShaderResourceAttribs& InputAtt, Uint32)
+ {
+ VERIFY_EXPR(InputAtt.Type == SPIRVShaderResourceAttribs::ResourceType::InputAttachment);
+ AddResource(s, Layout, Resources, InputAtt);
}
);
// clang-format on
@@ -640,7 +645,7 @@ void ShaderResourceLayoutVk::VkResource::CacheUniformBuffer(IDeviceObject*
Uint16& DynamicBuffersCounter) const
{
VERIFY(SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::UniformBuffer, "Uniform buffer resource is expected");
- RefCntAutoPtr<BufferVkImpl> pBufferVk(pBuffer, IID_BufferVk);
+ RefCntAutoPtr<BufferVkImpl> pBufferVk{pBuffer, IID_BufferVk};
#ifdef DILIGENT_DEVELOPMENT
VerifyConstantBufferBinding(SpirvAttribs, GetVariableType(), ArrayInd, pBuffer, pBufferVk.RawPtr(), DstRes.pObject.RawPtr(), ParentResLayout.GetShaderName());
#endif
@@ -681,7 +686,7 @@ void ShaderResourceLayoutVk::VkResource::CacheStorageBuffer(IDeviceObject*
"Storage buffer resource is expected");
// clang-format on
- RefCntAutoPtr<BufferViewVkImpl> pBufferViewVk(pBufferView, IID_BufferViewVk);
+ RefCntAutoPtr<BufferViewVkImpl> pBufferViewVk{pBufferView, IID_BufferViewVk};
#ifdef DILIGENT_DEVELOPMENT
{
// HLSL buffer SRVs are mapped to storge buffers in GLSL
@@ -727,7 +732,7 @@ void ShaderResourceLayoutVk::VkResource::CacheTexelBuffer(IDeviceObject*
"Uniform or storage buffer resource is expected");
// clang-format on
- RefCntAutoPtr<BufferViewVkImpl> pBufferViewVk(pBufferView, IID_BufferViewVk);
+ RefCntAutoPtr<BufferViewVkImpl> pBufferViewVk{pBufferView, IID_BufferViewVk};
#ifdef DILIGENT_DEVELOPMENT
{
// HLSL buffer SRVs are mapped to storge buffers in GLSL
@@ -776,7 +781,7 @@ void ShaderResourceLayoutVk::VkResource::CacheImage(IDeviceObject*
"Storage image, separate image or sampled image resource is expected");
// clang-format on
- RefCntAutoPtr<TextureViewVkImpl> pTexViewVk0(pTexView, IID_TextureViewVk);
+ RefCntAutoPtr<TextureViewVkImpl> pTexViewVk0{pTexView, IID_TextureViewVk};
#ifdef DILIGENT_DEVELOPMENT
{
// HLSL buffer SRVs are mapped to storge buffers in GLSL
@@ -840,7 +845,7 @@ void ShaderResourceLayoutVk::VkResource::CacheSeparateSampler(IDeviceObject*
VERIFY(SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler, "Separate sampler resource is expected");
VERIFY(!IsImmutableSamplerAssigned(), "This separate sampler is assigned an immutable sampler");
- RefCntAutoPtr<SamplerVkImpl> pSamplerVk(pSampler, IID_Sampler);
+ RefCntAutoPtr<SamplerVkImpl> pSamplerVk{pSampler, IID_Sampler};
#ifdef DILIGENT_DEVELOPMENT
if (pSampler != nullptr && pSamplerVk == nullptr)
{
@@ -868,6 +873,28 @@ void ShaderResourceLayoutVk::VkResource::CacheSeparateSampler(IDeviceObject*
}
}
+void ShaderResourceLayoutVk::VkResource::CacheInputAttachment(IDeviceObject* pTexView,
+ ShaderResourceCacheVk::Resource& DstRes,
+ VkDescriptorSet vkDescrSet,
+ Uint32 ArrayInd) const
+{
+ VERIFY(SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::InputAttachment, "Input attachment resource is expected");
+ RefCntAutoPtr<TextureViewVkImpl> pTexViewVk0{pTexView, IID_TextureViewVk};
+#ifdef DILIGENT_DEVELOPMENT
+ VerifyResourceViewBinding(SpirvAttribs, GetVariableType(), ArrayInd, pTexView, pTexViewVk0.RawPtr(), {TEXTURE_VIEW_SHADER_RESOURCE}, DstRes.pObject.RawPtr(), ParentResLayout.GetShaderName());
+#endif
+ if (UpdateCachedResource(DstRes, std::move(pTexViewVk0), [](const TextureViewVkImpl*, const TextureViewVkImpl*) {}))
+ {
+ // Do not update descriptor for a dynamic image. All dynamic resource descriptors
+ // are updated at once by CommitDynamicResources() when SRB is committed.
+ if (vkDescrSet != VK_NULL_HANDLE && GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
+ {
+ VkDescriptorImageInfo DescrImgInfo = DstRes.GetInputAttachmentDescriptorWriteInfo();
+ UpdateDescriptorHandle(vkDescrSet, ArrayInd, &DescrImgInfo, nullptr, nullptr);
+ }
+ //
+ }
+}
void ShaderResourceLayoutVk::VkResource::BindResource(IDeviceObject* pObj, Uint32 ArrayIndex, ShaderResourceCacheVk& ResourceCache) const
{
@@ -898,6 +925,7 @@ void ShaderResourceLayoutVk::VkResource::BindResource(IDeviceObject* pObj, Uint3
if (pObj)
{
+ static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please handle the new resource type below");
switch (SpirvAttribs.Type)
{
case SPIRVShaderResourceAttribs::ResourceType::UniformBuffer:
@@ -945,6 +973,10 @@ void ShaderResourceLayoutVk::VkResource::BindResource(IDeviceObject* pObj, Uint3
}
break;
+ case SPIRVShaderResourceAttribs::ResourceType::InputAttachment:
+ CacheInputAttachment(pObj, DstRes, vkDescrSet, ArrayIndex);
+ break;
+
default: UNEXPECTED("Unknown resource type ", static_cast<Int32>(SpirvAttribs.Type));
}
}