summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-12-02 17:39:49 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-12-02 17:39:49 +0000
commit466dff5b223bd3f4af7963fec546ff179a745556 (patch)
treebfb10a46716aec66eb38e67574718c4c230d419c /Graphics/GraphicsEngineVulkan
parentAdded explicit state transition control flags to CLEAR_DEPTH_STENCIL_FLAGS (diff)
downloadDiligentCore-466dff5b223bd3f4af7963fec546ff179a745556.tar.gz
DiligentCore-466dff5b223bd3f4af7963fec546ff179a745556.zip
Added explicit state transition control to UpdateBuffer and UpdateTexture commands
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h63
-rw-r--r--Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h1
-rw-r--r--Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp185
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp2
4 files changed, 133 insertions, 118 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h
index 28a6f10e..978c374b 100644
--- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h
@@ -39,7 +39,7 @@
#include "PipelineLayout.h"
#include "GenerateMipsVkHelper.h"
#include "BufferVkImpl.h"
-#include "TextureViewVkImpl.h"
+#include "TextureVkImpl.h"
#include "PipelineStateVkImpl.h"
#include "HashUtils.h"
@@ -47,10 +47,10 @@ namespace Diligent
{
/// Implementation of the Diligent::IDeviceContext interface
-class DeviceContextVkImpl final : public DeviceContextNextGenBase< DeviceContextBase<IDeviceContextVk, BufferVkImpl, TextureViewVkImpl, PipelineStateVkImpl> >
+class DeviceContextVkImpl final : public DeviceContextNextGenBase< DeviceContextBase<IDeviceContextVk, BufferVkImpl, TextureVkImpl, PipelineStateVkImpl> >
{
public:
- using TDeviceContextBase = DeviceContextNextGenBase< DeviceContextBase<IDeviceContextVk, BufferVkImpl, TextureViewVkImpl, PipelineStateVkImpl> >;
+ using TDeviceContextBase = DeviceContextNextGenBase< DeviceContextBase<IDeviceContextVk, BufferVkImpl, TextureVkImpl, PipelineStateVkImpl> >;
DeviceContextVkImpl(IReferenceCounters* pRefCounters,
class RenderDeviceVkImpl* pDevice,
@@ -102,7 +102,11 @@ public:
virtual void Flush()override final;
- virtual void UpdateBuffer(IBuffer *pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData)override final;
+ virtual void UpdateBuffer(IBuffer* pBuffer,
+ Uint32 Offset,
+ Uint32 Size,
+ const PVoid pData,
+ RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final;
virtual void CopyBuffer(IBuffer* pSrcBuffer, Uint32 SrcOffset, IBuffer* pDstBuffer, Uint32 DstOffset, Uint32 Size)override final;
@@ -110,11 +114,13 @@ public:
virtual void UnmapBuffer(IBuffer* pBuffer)override final;
- virtual void UpdateTexture(ITexture* pTexture,
- Uint32 MipLevel,
- Uint32 Slice,
- const Box& DstBox,
- const TextureSubResData& SubresData)override final;
+ virtual void UpdateTexture(ITexture* pTexture,
+ Uint32 MipLevel,
+ Uint32 Slice,
+ const Box& DstBox,
+ const TextureSubResData& SubresData,
+ RESOURCE_STATE_TRANSITION_MODE SrcBufferStateTransitionMode,
+ RESOURCE_STATE_TRANSITION_MODE TextureStateTransitionModee)override final;
virtual void CopyTexture(ITexture* pSrcTexture,
Uint32 SrcMipLevel,
@@ -152,7 +158,7 @@ public:
RESOURCE_STATE NewState,
bool UpdateTextureState,
VkImageSubresourceRange* pSubresRange = nullptr);
-
+
void TransitionImageLayout(TextureVkImpl& TextureVk,
VkImageLayout OldLayout,
VkImageLayout NewLayout,
@@ -182,18 +188,24 @@ public:
m_SignalSemaphores.push_back(Semaphore);
}
- void UpdateBufferRegion(BufferVkImpl* pBuffVk, Uint64 DstOffset, Uint64 NumBytes, VkBuffer vkSrcBuffer, Uint64 SrcOffset);
+ void UpdateBufferRegion(BufferVkImpl* pBuffVk,
+ Uint64 DstOffset,
+ Uint64 NumBytes,
+ VkBuffer vkSrcBuffer,
+ Uint64 SrcOffset,
+ RESOURCE_STATE_TRANSITION_MODE TransitionMode);
void CopyBufferRegion(BufferVkImpl* pSrcBuffVk, BufferVkImpl* pDstBuffVk, Uint64 SrcOffset, Uint64 DstOffset, Uint64 NumBytes);
void CopyTextureRegion(TextureVkImpl* pSrcTexture, TextureVkImpl* pDstTexture, const VkImageCopy &CopyRegion);
- void UpdateTextureRegion(const void* pSrcData,
- Uint32 SrcStride,
- Uint32 SrcDepthStride,
- TextureVkImpl& TextureVk,
- Uint32 MipLevel,
- Uint32 Slice,
- const Box& DstBox);
+ void UpdateTextureRegion(const void* pSrcData,
+ Uint32 SrcStride,
+ Uint32 SrcDepthStride,
+ TextureVkImpl& TextureVk,
+ Uint32 MipLevel,
+ Uint32 Slice,
+ const Box& DstBox,
+ RESOURCE_STATE_TRANSITION_MODE TextureTransitionMode);
virtual void GenerateMips(ITextureView* pTexView)override final;
@@ -260,13 +272,14 @@ private:
Uint32 MipLevel,
const Box& Region)const;
- void CopyBufferToTexture(VkBuffer vkBuffer,
- Uint32 BufferOffset,
- Uint32 BufferRowStrideInTexels,
- const Box& Region,
- TextureVkImpl& TextureVk,
- Uint32 MipLevel,
- Uint32 ArraySlice);
+ void CopyBufferToTexture(VkBuffer vkBuffer,
+ Uint32 BufferOffset,
+ Uint32 BufferRowStrideInTexels,
+ const Box& Region,
+ TextureVkImpl& TextureVk,
+ Uint32 MipLevel,
+ Uint32 ArraySlice,
+ RESOURCE_STATE_TRANSITION_MODE TextureTransitionMode);
void DvpLogRenderPass_PSOMismatch();
diff --git a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h
index bfddb2cb..5cf5a8a5 100644
--- a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h
@@ -43,6 +43,7 @@ class TextureVkImpl final : public TextureBase<ITextureVk, RenderDeviceVkImpl, T
{
public:
using TTextureBase = TextureBase<ITextureVk, RenderDeviceVkImpl, TextureViewVkImpl, FixedBlockMemoryAllocator>;
+ using ViewImplType = TextureViewVkImpl;
// Creates a new Vk resource
TextureVkImpl(IReferenceCounters* pRefCounters,
diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
index 1be1f045..226faf1a 100644
--- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
@@ -344,13 +344,7 @@ namespace Diligent
#ifdef DEVELOPMENT
else if (VerifyStates)
{
- if (pBufferVk->IsInKnownState() && !pBufferVk->CheckState(RESOURCE_STATE_VERTEX_BUFFER))
- {
- LOG_ERROR_MESSAGE("Buffer '", pBufferVk->GetDesc().Name, "' used as vertex buffer at slot ", slot, " must be in "
- "RESOURCE_STATE_VERTEX_BUFFER state. Actual buffer state: ", GetResourceStateString(pBufferVk->GetState()),
- ". Use DRAW_FLAG_TRANSITION_VERTEX_BUFFERS flag or explicitly transition the buffer to the required state.");
-
- }
+ DvpVerifyBufferState(*pBufferVk, RESOURCE_STATE_VERTEX_BUFFER, "Binding vertex buffers (DeviceContextVkImpl::CommitVkVertexBuffers)");
}
#endif
@@ -451,12 +445,7 @@ namespace Diligent
#ifdef DEVELOPMENT
else if (VerifyStates)
{
- if (pBuffVk->IsInKnownState() && !pBuffVk->CheckState(RESOURCE_STATE_INDEX_BUFFER))
- {
- LOG_ERROR_MESSAGE("Buffer '", pBuffVk->GetDesc().Name, "' used as index buffer must be in RESOURCE_STATE_INDEX_BUFFER "
- "state. Actual buffer state: ", GetResourceStateString(pBuffVk->GetState()),
- ". Use DRAW_FLAG_TRANSITION_INDEX_BUFFER flag or explicitly transition the buffer to the required state.");
- }
+ DvpVerifyBufferState(*pBuffVk, RESOURCE_STATE_INDEX_BUFFER, "Indexed draw call (DeviceContextVkImpl::Draw)");
}
#endif
@@ -479,11 +468,9 @@ namespace Diligent
{
auto& CurrStream = m_VertexStreams[slot];
auto* pBufferVk = CurrStream.pBuffer.RawPtr();
- if (pBufferVk != nullptr && pBufferVk->IsInKnownState() && !pBufferVk->CheckState(RESOURCE_STATE_VERTEX_BUFFER))
+ if (pBufferVk != nullptr)
{
- LOG_ERROR_MESSAGE("Buffer '", pBufferVk->GetDesc().Name, "' used as vertex buffer at slot ", slot, " must be in "
- "RESOURCE_STATE_VERTEX_BUFFER state. Actual buffer state: ", GetResourceStateString(pBufferVk->GetState()),
- ". Use DRAW_FLAG_TRANSITION_VERTEX_BUFFERS flag or explicitly transition the buffer to the required state.");
+ DvpVerifyBufferState(*pBufferVk, RESOURCE_STATE_VERTEX_BUFFER, "Using vertex buffers (DeviceContextVkImpl::Draw)");
}
}
}
@@ -523,12 +510,7 @@ namespace Diligent
#ifdef DEVELOPMENT
else if (VerifyStates)
{
- if (pIndirectDrawAttribsVk->IsInKnownState() && !pIndirectDrawAttribsVk->CheckState(RESOURCE_STATE_INDIRECT_ARGUMENT))
- {
- LOG_ERROR_MESSAGE("Buffer '", pIndirectDrawAttribsVk->GetDesc().Name, "' used as indirect draw arguments buffer must be in RESOURCE_STATE_INDIRECT_ARGUMENT "
- "state. Actual buffer state: ", GetResourceStateString(pIndirectDrawAttribsVk->GetState()),
- ". Use DRAW_FLAG_TRANSITION_INDIRECT_ARGS_BUFFER flag or explicitly transition the buffer to the required state.");
- }
+ DvpVerifyBufferState(*pIndirectDrawAttribsVk, RESOURCE_STATE_INDIRECT_ARGUMENT, "Indirect draw (DeviceContextVkImpl::Draw)");
}
#endif
}
@@ -614,12 +596,7 @@ namespace Diligent
#ifdef DEVELOPMENT
else if (DispatchAttrs.Flags & DISPATCH_FLAG_VERIFY_STATES)
{
- if (pBufferVk->IsInKnownState() && !pBufferVk->CheckState(RESOURCE_STATE_INDIRECT_ARGUMENT))
- {
- LOG_ERROR_MESSAGE("Buffer '", pBufferVk->GetDesc().Name, "' used as indirect dispatch arguments buffer must be in RESOURCE_STATE_INDIRECT_ARGUMENT "
- "state. Actual buffer state: ", GetResourceStateString(pBufferVk->GetState()),
- ". Use DISPATCH_FLAG_TRANSITION_INDIRECT_ARGS_BUFFER flag or explicitly transition the buffer to the required state.");
- }
+ DvpVerifyBufferState(*pBufferVk, RESOURCE_STATE_INDIRECT_ARGUMENT, "Indirect dispatch (DeviceContextVkImpl::DispatchCompute)");
}
#endif
@@ -718,12 +695,7 @@ namespace Diligent
#ifdef DEVELOPMENT
else if(ClearFlags & CLEAR_DEPTH_STENCIL_VERIFY_STATE_FLAG)
{
- if (pTextureVk->IsInKnownState() && !pTextureVk->CheckState(RESOURCE_STATE_COPY_DEST))
- {
- LOG_ERROR_MESSAGE("Depth-stencil buffer '", pTextureVk->GetDesc().Name, "' being cleared outside of render pass not transitioned to RESOURCE_STATE_COPY_DEST state. "
- "Actual texture state: ", GetResourceStateString(pTexture->GetState()), ". "
- "Use CLEAR_DEPTH_STENCIL_TRANSITION_STATE_FLAG flag or explicitly transition the resource using IDeviceContext::TransitionResourceStates() method.");
- }
+ DvpVerifyTextureState(*pTextureVk, RESOURCE_STATE_COPY_DEST, "Clearing depth-stencil buffer outside of render pass (DeviceContextVkImpl::ClearDepthStencil)");
}
#endif
@@ -868,12 +840,7 @@ namespace Diligent
#ifdef DEVELOPMENT
else if (StateTransitionMode == CLEAR_RENDER_TARGET_VERIFY_STATE)
{
- if (pTextureVk->IsInKnownState() && !pTextureVk->CheckState(RESOURCE_STATE_COPY_DEST))
- {
- LOG_ERROR_MESSAGE("Render target '", pTextureVk->GetDesc().Name, "' being cleared outside of render pass not transitioned to RESOURCE_STATE_COPY_DEST state. "
- "Actual texture state: ", GetResourceStateString(pTexture->GetState()), ". "
- "Use CLEAR_RENDER_TARGET_TRANSITION_STATE mode or explicitly transition the resource using IDeviceContext::TransitionResourceStates() method.");
- }
+ DvpVerifyTextureState(*pTextureVk, RESOURCE_STATE_COPY_DEST, "Clearing render target outside of render pass (DeviceContextVkImpl::ClearRenderTarget)");
}
#endif
auto ClearValue = ClearValueToVkClearValue(RGBA, ViewDesc.Format);
@@ -1133,12 +1100,7 @@ namespace Diligent
#ifdef DEVELOPMENT
else if (Flags & SET_RENDER_TARGETS_FLAG_VERIFY_STATES)
{
- if (pDepthBufferVk->IsInKnownState() && !pDepthBufferVk->CheckState(RESOURCE_STATE_DEPTH_WRITE))
- {
- LOG_ERROR_MESSAGE("Texture '", pDepthBufferVk->GetDesc().Name, "' being set as depth-stencil buffer is not transitioned to RESOURCE_STATE_DEPTH_WRITE state. "
- "Actual texture state: ", GetResourceStateString(pDepthBufferVk->GetState()), ". "
- "Use SET_RENDER_TARGETS_FLAG_TRANSITION_DEPTH flag or explicitly transition the resource using IDeviceContext::TransitionResourceStates() method.");
- }
+ DvpVerifyTextureState(*pDepthBufferVk, RESOURCE_STATE_DEPTH_WRITE, "Binding depth-stencil buffer (DeviceContextVkImpl::TransitionRenderTargets)");
}
#endif
}
@@ -1163,12 +1125,7 @@ namespace Diligent
#ifdef DEVELOPMENT
else if (Flags & SET_RENDER_TARGETS_FLAG_VERIFY_STATES)
{
- if (pRenderTargetVk->IsInKnownState() && !pRenderTargetVk->CheckState(RESOURCE_STATE_RENDER_TARGET))
- {
- LOG_ERROR_MESSAGE("Texture '", pRenderTargetVk->GetDesc().Name, "' being set as render target at slot ", rt, " is not transitioned to RESOURCE_STATE_RENDER_TARGET state. "
- "Actual texture state: ", GetResourceStateString(pRenderTargetVk->GetState()), ". "
- "Use SET_RENDER_TARGETS_FLAG_TRANSITION_COLOR flag or explicitly transition the resource using IDeviceContext::TransitionResourceStates() method.");
- }
+ DvpVerifyTextureState(*pRenderTargetVk, RESOURCE_STATE_RENDER_TARGET, "Binding render targets (DeviceContextVkImpl::TransitionRenderTargets)");
}
#endif
}
@@ -1264,7 +1221,12 @@ namespace Diligent
m_Framebuffer = VK_NULL_HANDLE;
}
- void DeviceContextVkImpl::UpdateBufferRegion(BufferVkImpl* pBuffVk, Uint64 DstOffset, Uint64 NumBytes, VkBuffer vkSrcBuffer, Uint64 SrcOffset)
+ void DeviceContextVkImpl::UpdateBufferRegion(BufferVkImpl* pBuffVk,
+ Uint64 DstOffset,
+ Uint64 NumBytes,
+ VkBuffer vkSrcBuffer,
+ Uint64 SrcOffset,
+ RESOURCE_STATE_TRANSITION_MODE TransitionMode)
{
#ifdef DEVELOPMENT
if (DstOffset + NumBytes > pBuffVk->GetDesc().uiSizeInBytes)
@@ -1274,14 +1236,23 @@ namespace Diligent
#endif
EnsureVkCmdBuffer();
- if (pBuffVk->IsInKnownState())
+ if (TransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION)
{
- if (!pBuffVk->CheckState(RESOURCE_STATE_COPY_DEST))
+ if (pBuffVk->IsInKnownState())
{
- TransitionBufferState(*pBuffVk, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_COPY_DEST, true);
+ if (!pBuffVk->CheckState(RESOURCE_STATE_COPY_DEST))
+ {
+ TransitionBufferState(*pBuffVk, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_COPY_DEST, true);
+ }
+ VERIFY_EXPR(pBuffVk->CheckAccessFlags(VK_ACCESS_TRANSFER_WRITE_BIT));
}
- VERIFY_EXPR(pBuffVk->CheckAccessFlags(VK_ACCESS_TRANSFER_WRITE_BIT));
}
+#ifdef DEVELOPMENT
+ else if (TransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
+ {
+ DvpVerifyBufferState(*pBuffVk, RESOURCE_STATE_COPY_DEST, "Updating buffer (DeviceContextVkImpl::UpdateBufferRegion)");
+ }
+#endif
VkBufferCopy CopyRegion;
CopyRegion.srcOffset = SrcOffset;
CopyRegion.dstOffset = DstOffset;
@@ -1291,9 +1262,13 @@ namespace Diligent
++m_State.NumCommands;
}
- void DeviceContextVkImpl::UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData)
+ void DeviceContextVkImpl::UpdateBuffer(IBuffer* pBuffer,
+ Uint32 Offset,
+ Uint32 Size,
+ const PVoid pData,
+ RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)
{
- TDeviceContextBase::UpdateBuffer(pBuffer, Offset, Size, pData);
+ TDeviceContextBase::UpdateBuffer(pBuffer, Offset, Size, pData, StateTransitionMode);
// We must use cmd context from the device context provided, otherwise there will
// be resource barrier issues in the cmd list in the device context
@@ -1311,7 +1286,7 @@ namespace Diligent
// Source buffer offset must be multiple of 4 (18.4)
auto TmpSpace = m_UploadHeap.Allocate(Size, Alignment);
memcpy(TmpSpace.CPUAddress, pData, Size);
- UpdateBufferRegion(pBuffVk, Offset, Size, TmpSpace.vkBuffer, TmpSpace.AlignedOffset);
+ UpdateBufferRegion(pBuffVk, Offset, Size, TmpSpace.vkBuffer, TmpSpace.AlignedOffset, StateTransitionMode);
// The allocation will stay in the upload heap until the end of the frame at which point all upload
// pages will be discarded
}
@@ -1459,7 +1434,7 @@ namespace Diligent
{
auto& DynAlloc = pBufferVk->m_DynamicAllocations[m_ContextId];
auto vkSrcBuff = DynAlloc.pDynamicMemMgr->GetVkBuffer();
- UpdateBufferRegion(pBufferVk, 0, BuffDesc.uiSizeInBytes, vkSrcBuff, DynAlloc.AlignedOffset);
+ UpdateBufferRegion(pBufferVk, 0, BuffDesc.uiSizeInBytes, vkSrcBuff, DynAlloc.AlignedOffset, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
}
}
}
@@ -1467,16 +1442,29 @@ namespace Diligent
m_MappedBuffers.erase(MappedBufferIt);
}
- void DeviceContextVkImpl::UpdateTexture(ITexture* pTexture, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData)
+ void DeviceContextVkImpl::UpdateTexture(ITexture* pTexture,
+ Uint32 MipLevel,
+ Uint32 Slice,
+ const Box& DstBox,
+ const TextureSubResData& SubresData,
+ RESOURCE_STATE_TRANSITION_MODE SrcBufferStateTransitionMode,
+ RESOURCE_STATE_TRANSITION_MODE TextureStateTransitionModee)
{
- TDeviceContextBase::UpdateTexture( pTexture, MipLevel, Slice, DstBox, SubresData );
+ TDeviceContextBase::UpdateTexture( pTexture, MipLevel, Slice, DstBox, SubresData, SrcBufferStateTransitionMode, TextureStateTransitionModee );
auto* pTexVk = ValidatedCast<TextureVkImpl>(pTexture);
// OpenGL backend uses UpdateData() to initialize textures, so we can't check the usage in ValidateUpdateTextureParams()
DEV_CHECK_ERR( pTexVk->GetDesc().Usage == USAGE_DEFAULT, "Only USAGE_DEFAULT textures should be updated with UpdateData()" );
- //pCtxVk->CopyTextureRegion(SubresData.pSrcBuffer, SubresData.Stride, SubresData.DepthStride, this, DstSubResIndex, DstBox);
- UpdateTextureRegion(SubresData.pData, SubresData.Stride, SubresData.DepthStride, *pTexVk, MipLevel, Slice, DstBox);
+ if (SubresData.pSrcBuffer != nullptr)
+ {
+ UNSUPPORTED("Copying buffer to texture is not implemented");
+ }
+ else
+ {
+ UpdateTextureRegion(SubresData.pData, SubresData.Stride, SubresData.DepthStride, *pTexVk,
+ MipLevel, Slice, DstBox, TextureStateTransitionModee);
+ }
}
void DeviceContextVkImpl::CopyTexture(ITexture* pSrcTexture,
@@ -1628,13 +1616,14 @@ namespace Diligent
}
- void DeviceContextVkImpl::UpdateTextureRegion(const void* pSrcData,
- Uint32 SrcStride,
- Uint32 SrcDepthStride,
- TextureVkImpl& TextureVk,
- Uint32 MipLevel,
- Uint32 Slice,
- const Box& DstBox)
+ void DeviceContextVkImpl::UpdateTextureRegion(const void* pSrcData,
+ Uint32 SrcStride,
+ Uint32 SrcDepthStride,
+ TextureVkImpl& TextureVk,
+ Uint32 MipLevel,
+ Uint32 Slice,
+ const Box& DstBox,
+ RESOURCE_STATE_TRANSITION_MODE TextureTransitionMode)
{
const auto& TexDesc = TextureVk.GetDesc();
VERIFY(TexDesc.SampleCount == 1, "Only single-sample textures can be updated with vkCmdCopyBufferToImage()");
@@ -1686,7 +1675,8 @@ namespace Diligent
CopyInfo.Region,
TextureVk,
MipLevel,
- Slice);
+ Slice,
+ TextureTransitionMode);
}
void DeviceContextVkImpl::GenerateMips(ITextureView* pTexView)
@@ -1695,23 +1685,33 @@ namespace Diligent
m_GenerateMipsHelper->GenerateMips(*ValidatedCast<TextureViewVkImpl>(pTexView), *this, *m_GenerateMipsSRB);
}
- void DeviceContextVkImpl::CopyBufferToTexture(VkBuffer vkBuffer,
- Uint32 BufferOffset,
- Uint32 BufferRowStrideInTexels,
- const Box& Region,
- TextureVkImpl& TextureVk,
- Uint32 MipLevel,
- Uint32 ArraySlice)
+ void DeviceContextVkImpl::CopyBufferToTexture(VkBuffer vkBuffer,
+ Uint32 BufferOffset,
+ Uint32 BufferRowStrideInTexels,
+ const Box& Region,
+ TextureVkImpl& TextureVk,
+ Uint32 MipLevel,
+ Uint32 ArraySlice,
+ RESOURCE_STATE_TRANSITION_MODE TextureTransitionMode)
{
EnsureVkCmdBuffer();
- if (TextureVk.IsInKnownState())
+ if (TextureTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION)
{
- if (!TextureVk.CheckState(RESOURCE_STATE_COPY_DEST))
+ if (TextureVk.IsInKnownState())
{
- TransitionTextureState(TextureVk, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_COPY_DEST, true);
+ if (!TextureVk.CheckState(RESOURCE_STATE_COPY_DEST))
+ {
+ TransitionTextureState(TextureVk, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_COPY_DEST, true);
+ }
+ VERIFY_EXPR(TextureVk.GetLayout() == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
}
- VERIFY_EXPR(TextureVk.GetLayout() == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
}
+#ifdef DEVELOPMENT
+ else if (TextureTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
+ {
+ DvpVerifyTextureState(TextureVk, RESOURCE_STATE_COPY_DEST, "Using texture as copy destination (DeviceContextVkImpl::CopyBufferToTexture)");
+ }
+#endif
VkBufferImageCopy CopyRegion = {};
VERIFY( (BufferOffset % 4) == 0, "Source buffer offset must be multiple of 4 (18.4)");
@@ -1845,7 +1845,8 @@ namespace Diligent
MappedTex.CopyInfo.Region,
TextureVk,
MipLevel,
- ArraySlice);
+ ArraySlice,
+ RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
m_MappedTextures.erase(UploadSpaceIt);
}
else
@@ -1933,7 +1934,7 @@ namespace Diligent
TransitionTextureState(*pTextureVk, RESOURCE_STATE_UNKNOWN, NewState, true);
}
}
-
+
void DeviceContextVkImpl::TransitionTextureState(TextureVkImpl& TextureVk,
RESOURCE_STATE OldState,
RESOURCE_STATE NewState,
@@ -1948,7 +1949,7 @@ namespace Diligent
}
else
{
- LOG_ERROR_MESSAGE("Failed to transition the state of texture '", TextureVk.GetDesc().Name, "' because the texture state is unknown and is not explicitly specified");
+ LOG_ERROR_MESSAGE("Failed to transition the state of texture '", TextureVk.GetDesc().Name, "' because the state is unknown and is not explicitly specified.");
return;
}
}
@@ -1957,8 +1958,8 @@ namespace Diligent
if (TextureVk.IsInKnownState() && TextureVk.GetState() != OldState)
{
LOG_ERROR_MESSAGE("The state ", GetResourceStateString(TextureVk.GetState()), " of texture '",
- TextureVk.GetDesc().Name, "' does not match the old state ", GetResourceStateString(OldState),
- " specified by the barrier");
+ TextureVk.GetDesc().Name, "' does not match the old state ", GetResourceStateString(OldState),
+ " specified by the barrier");
}
}
@@ -2047,8 +2048,8 @@ namespace Diligent
if (BufferVk.IsInKnownState() && BufferVk.GetState() != OldState)
{
LOG_ERROR_MESSAGE("The state ", GetResourceStateString(BufferVk.GetState()), " of buffer '",
- BufferVk.GetDesc().Name, "' does not match the old state ", GetResourceStateString(OldState),
- " specified by the barrier");
+ BufferVk.GetDesc().Name, "' does not match the old state ", GetResourceStateString(OldState),
+ " specified by the barrier");
}
}
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp
index 888e4d00..43643fad 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp
@@ -100,7 +100,7 @@ ShaderResourceCacheVk::~ShaderResourceCacheVk()
}
template<bool VerifyOnly>
-void ShaderResourceCacheVk::TransitionResources(DeviceContextVkImpl *pCtxVkImpl)
+void ShaderResourceCacheVk::TransitionResources(DeviceContextVkImpl* pCtxVkImpl)
{
auto *pResources = GetFirstResourcePtr();
for (Uint32 res = 0; res < m_TotalResources; ++res)