From a0de90861c8b191e24d48e06d37d81183e110060 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 13 Dec 2018 14:40:38 +0100 Subject: [PATCH] [dxvk] Store access flags in resource slots Makes distinguishing read-only resources from read-write resources significantly easier. --- src/dxbc/dxbc_compiler.cpp | 11 +++++++++++ src/dxvk/dxvk_pipelayout.cpp | 5 ++++- src/dxvk/dxvk_pipelayout.h | 14 ++++++-------- src/dxvk/dxvk_shader.cpp | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp index 051d20c1..5ba84375 100644 --- a/src/dxbc/dxbc_compiler.cpp +++ b/src/dxbc/dxbc_compiler.cpp @@ -800,6 +800,7 @@ namespace dxvk { resource.slot = bindingId; resource.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; resource.view = VK_IMAGE_VIEW_TYPE_MAX_ENUM; + resource.access = VK_ACCESS_UNIFORM_READ_BIT; m_resourceSlots.push_back(resource); } @@ -836,6 +837,7 @@ namespace dxvk { resource.slot = bindingId; resource.type = VK_DESCRIPTOR_TYPE_SAMPLER; resource.view = VK_IMAGE_VIEW_TYPE_MAX_ENUM; + resource.access = 0; m_resourceSlots.push_back(resource); } @@ -1008,11 +1010,13 @@ namespace dxvk { DxvkResourceSlot resource; resource.slot = bindingId; resource.view = typeInfo.vtype; + resource.access = VK_ACCESS_SHADER_READ_BIT; if (isUav) { resource.type = resourceType == DxbcResourceDim::Buffer ? VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER : VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + resource.access |= VK_ACCESS_SHADER_WRITE_BIT; } else { resource.type = resourceType == DxbcResourceDim::Buffer ? VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER @@ -1121,6 +1125,11 @@ namespace dxvk { ? VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; resource.view = VK_IMAGE_VIEW_TYPE_MAX_ENUM; + resource.access = VK_ACCESS_SHADER_READ_BIT; + + if (isUav) + resource.access |= VK_ACCESS_SHADER_WRITE_BIT; + m_resourceSlots.push_back(resource); } @@ -1357,6 +1366,8 @@ namespace dxvk { resource.slot = bindingId; resource.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; resource.view = VK_IMAGE_VIEW_TYPE_MAX_ENUM; + resource.access = VK_ACCESS_SHADER_READ_BIT + | VK_ACCESS_SHADER_WRITE_BIT; m_resourceSlots.push_back(resource); return varId; diff --git a/src/dxvk/dxvk_pipelayout.cpp b/src/dxvk/dxvk_pipelayout.cpp index 8b8a4c16..1fbd0d34 100644 --- a/src/dxvk/dxvk_pipelayout.cpp +++ b/src/dxvk/dxvk_pipelayout.cpp @@ -13,17 +13,20 @@ namespace dxvk { uint32_t slot, VkDescriptorType type, VkImageViewType view, - VkShaderStageFlagBits stage) { + VkShaderStageFlagBits stage, + VkAccessFlags access) { uint32_t bindingId = this->getBindingId(slot); if (bindingId != InvalidBinding) { m_descriptorSlots[bindingId].stages |= stage; + m_descriptorSlots[bindingId].access |= access; } else { DxvkDescriptorSlot slotInfo; slotInfo.slot = slot; slotInfo.type = type; slotInfo.view = view; slotInfo.stages = stage; + slotInfo.access = access; m_descriptorSlots.push_back(slotInfo); } } diff --git a/src/dxvk/dxvk_pipelayout.h b/src/dxvk/dxvk_pipelayout.h index ddea8a6f..4c597886 100644 --- a/src/dxvk/dxvk_pipelayout.h +++ b/src/dxvk/dxvk_pipelayout.h @@ -16,6 +16,7 @@ namespace dxvk { uint32_t slot; VkDescriptorType type; VkImageViewType view; + VkAccessFlags access; }; /** @@ -30,6 +31,7 @@ namespace dxvk { VkDescriptorType type; ///< Descriptor type (aka resource type) VkImageViewType view; ///< Compatible image view type VkShaderStageFlags stages; ///< Stages that can use the resource + VkAccessFlags access; ///< Access flags }; @@ -75,12 +77,14 @@ namespace dxvk { * \param [in] type Resource type * \param [in] view Image view type * \param [in] stage Shader stage + * \param [in] access Access flags */ void defineSlot( uint32_t slot, VkDescriptorType type, VkImageViewType view, - VkShaderStageFlagBits stage); + VkShaderStageFlagBits stage, + VkAccessFlags access); /** * \brief Gets binding ID for a slot @@ -230,13 +234,7 @@ namespace dxvk { VkShaderStageFlags stages = 0; for (const auto& slot : m_bindingSlots) { - bool isStorageDescriptor = - slot.type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER || - slot.type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC || - slot.type == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER || - slot.type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; - - if (isStorageDescriptor) + if (slot.access & VK_ACCESS_SHADER_WRITE_BIT) stages |= slot.stages; } diff --git a/src/dxvk/dxvk_shader.cpp b/src/dxvk/dxvk_shader.cpp index 21af222c..6e9a0630 100644 --- a/src/dxvk/dxvk_shader.cpp +++ b/src/dxvk/dxvk_shader.cpp @@ -133,7 +133,7 @@ namespace dxvk { void DxvkShader::defineResourceSlots( DxvkDescriptorSlotMapping& mapping) const { for (const auto& slot : m_slots) - mapping.defineSlot(slot.slot, slot.type, slot.view, m_stage); + mapping.defineSlot(slot.slot, slot.type, slot.view, m_stage, slot.access); }