From 5046c0ae9c0c951d47a3396791c71e94d193c1ce Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 16 Dec 2019 22:37:13 -0800 Subject: Enabled draw command reference in Vulkan --- .../include/RenderDeviceVkImpl.h | 16 ++++++--- .../interface/RenderDeviceVk.h | 3 ++ .../src/PipelineStateVkImpl.cpp | 6 ++-- Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp | 9 +++-- .../GraphicsEngineVulkan/src/TextureVkImpl.cpp | 42 +++++++++++----------- 5 files changed, 45 insertions(+), 31 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h index 52051652..8fd3c38a 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h @@ -91,6 +91,9 @@ public: /// Implementation of IRenderDeviceVk::GetVkDevice(). virtual VkDevice GetVkDevice() override final { return m_LogicalVkDevice->GetVkDevice(); } + /// Implementation of IRenderDeviceVk::GetVkPhysicalDevice(). + virtual VkPhysicalDevice GetVkPhysicalDevice() override final { return m_PhysicalDevice->GetVkDeviceHandle(); } + /// Implementation of IRenderDeviceVk::CreateTextureFromVulkanImage(). virtual void CreateTextureFromVulkanImage(VkImage vkImage, const TextureDesc& TexDesc, RESOURCE_STATE InitialState, ITexture** ppTexture) override final; @@ -117,10 +120,12 @@ public: DescriptorPoolManager& GetDynamicDescriptorPool() { return m_DynamicDescriptorPool; } std::shared_ptr GetVulkanInstance() const { return m_VulkanInstance; } - const VulkanUtilities::VulkanPhysicalDevice& GetPhysicalDevice() const { return *m_PhysicalDevice; } - const VulkanUtilities::VulkanLogicalDevice& GetLogicalDevice() { return *m_LogicalVkDevice; } - FramebufferCache& GetFramebufferCache() { return m_FramebufferCache; } - RenderPassCache& GetRenderPassCache() { return m_RenderPassCache; } + + const VulkanUtilities::VulkanPhysicalDevice& GetPhysicalDevice() const { return *m_PhysicalDevice; } + const VulkanUtilities::VulkanLogicalDevice& GetLogicalDevice() { return *m_LogicalVkDevice; } + + FramebufferCache& GetFramebufferCache() { return m_FramebufferCache; } + RenderPassCache& GetRenderPassCache() { return m_RenderPassCache; } VulkanUtilities::VulkanMemoryAllocation AllocateMemory(const VkMemoryRequirements& MemReqs, VkMemoryPropertyFlags MemoryProperties) { @@ -129,7 +134,8 @@ public: VulkanUtilities::VulkanMemoryManager& GetGlobalMemoryManager() { return m_MemoryMgr; } VulkanDynamicMemoryManager& GetDynamicMemoryManager() { return m_DynamicMemoryManager; } - void FlushStaleResources(Uint32 CmdQueueIndex); + + void FlushStaleResources(Uint32 CmdQueueIndex); private: virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final; diff --git a/Graphics/GraphicsEngineVulkan/interface/RenderDeviceVk.h b/Graphics/GraphicsEngineVulkan/interface/RenderDeviceVk.h index 785950a3..bf216af3 100644 --- a/Graphics/GraphicsEngineVulkan/interface/RenderDeviceVk.h +++ b/Graphics/GraphicsEngineVulkan/interface/RenderDeviceVk.h @@ -42,6 +42,9 @@ public: /// Returns logical Vulkan device handle virtual VkDevice GetVkDevice() = 0; + /// Returns physical Vulkan device + virtual VkPhysicalDevice GetVkPhysicalDevice() = 0; + /// Returns the fence value that will be signaled by the GPU command queue next virtual Uint64 GetNextFenceValue(Uint32 QueueIndex) = 0; diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 3eb7851d..23315a6a 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -145,9 +145,9 @@ static std::vector StripReflection(const std::vector& Origin return StrippedSPIRV; } -PipelineStateVkImpl ::PipelineStateVkImpl(IReferenceCounters* pRefCounters, - RenderDeviceVkImpl* pDeviceVk, - const PipelineStateDesc& PipelineDesc) : +PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCounters, + RenderDeviceVkImpl* pDeviceVk, + const PipelineStateDesc& PipelineDesc) : TPipelineStateBase{pRefCounters, pDeviceVk, PipelineDesc}, m_SRBMemAllocator{GetRawAllocator()} { diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index 8ad01c6b..2fb5e2d6 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -63,8 +63,13 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, } else { - auto GLSLSource = BuildGLSLSourceString(CreationAttribs, pRenderDeviceVk->GetDeviceCaps(), TargetGLSLCompiler::glslang, "#define TARGET_API_VULKAN 1\n"); - m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str(), static_cast(GLSLSource.length()), CreationAttribs.ppCompilerOutput); + auto GLSLSource = BuildGLSLSourceString(CreationAttribs, pRenderDeviceVk->GetDeviceCaps(), + TargetGLSLCompiler::glslang, + "#define TARGET_API_VULKAN 1\n"); + + m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str(), + static_cast(GLSLSource.length()), + CreationAttribs.ppCompilerOutput); } if (m_SPIRV.empty()) diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp index 13c090e0..3ebe8579 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp @@ -276,20 +276,20 @@ TextureVkImpl ::TextureVkImpl(IReferenceCounters* pRefCounters, } VERIFY_EXPR(subres == pInitData->NumSubresources); - VkBufferCreateInfo VkStaginBuffCI = {}; - VkStaginBuffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; - VkStaginBuffCI.pNext = nullptr; - VkStaginBuffCI.flags = 0; - VkStaginBuffCI.size = uploadBufferSize; - VkStaginBuffCI.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; - VkStaginBuffCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - VkStaginBuffCI.queueFamilyIndexCount = 0; - VkStaginBuffCI.pQueueFamilyIndices = nullptr; + VkBufferCreateInfo VkStagingBuffCI = {}; + VkStagingBuffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + VkStagingBuffCI.pNext = nullptr; + VkStagingBuffCI.flags = 0; + VkStagingBuffCI.size = uploadBufferSize; + VkStagingBuffCI.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + VkStagingBuffCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + VkStagingBuffCI.queueFamilyIndexCount = 0; + VkStagingBuffCI.pQueueFamilyIndices = nullptr; std::string StagingBufferName = "Upload buffer for '"; StagingBufferName += m_Desc.Name; StagingBufferName += '\''; - VulkanUtilities::BufferWrapper StagingBuffer = LogicalDevice.CreateBuffer(VkStaginBuffCI, StagingBufferName.c_str()); + VulkanUtilities::BufferWrapper StagingBuffer = LogicalDevice.CreateBuffer(VkStagingBuffCI, StagingBufferName.c_str()); VkMemoryRequirements StagingBufferMemReqs = LogicalDevice.GetBufferMemoryRequirements(StagingBuffer); VERIFY(IsPowerOfTwo(StagingBufferMemReqs.alignment), "Alignment is not power of 2!"); @@ -395,12 +395,12 @@ TextureVkImpl ::TextureVkImpl(IReferenceCounters* pRefCounters, } else if (m_Desc.Usage == USAGE_STAGING) { - VkBufferCreateInfo VkStaginBuffCI = {}; + VkBufferCreateInfo VkStagingBuffCI = {}; - VkStaginBuffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; - VkStaginBuffCI.pNext = nullptr; - VkStaginBuffCI.flags = 0; - VkStaginBuffCI.size = GetStagingDataOffset(m_Desc, m_Desc.ArraySize, 0); + VkStagingBuffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + VkStagingBuffCI.pNext = nullptr; + VkStagingBuffCI.flags = 0; + VkStagingBuffCI.size = GetStagingDataOffset(m_Desc, m_Desc.ArraySize, 0); // clang-format off DEV_CHECK_ERR((m_Desc.CPUAccessFlags & (CPU_ACCESS_READ | CPU_ACCESS_WRITE)) == CPU_ACCESS_READ || @@ -410,13 +410,13 @@ TextureVkImpl ::TextureVkImpl(IReferenceCounters* pRefCounters, VkMemoryPropertyFlags MemProperties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; if (m_Desc.CPUAccessFlags & CPU_ACCESS_READ) { - VkStaginBuffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; + VkStagingBuffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; MemProperties |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT; SetState(RESOURCE_STATE_COPY_DEST); } else if (m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE) { - VkStaginBuffCI.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + VkStagingBuffCI.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; // VK_MEMORY_PROPERTY_HOST_COHERENT_BIT bit specifies that the host cache management commands vkFlushMappedMemoryRanges // and vkInvalidateMappedMemoryRanges are NOT needed to flush host writes to the device or make device writes visible // to the host (10.2) @@ -426,14 +426,14 @@ TextureVkImpl ::TextureVkImpl(IReferenceCounters* pRefCounters, else UNEXPECTED("Unexpected CPU access"); - VkStaginBuffCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - VkStaginBuffCI.queueFamilyIndexCount = 0; - VkStaginBuffCI.pQueueFamilyIndices = nullptr; + VkStagingBuffCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + VkStagingBuffCI.queueFamilyIndexCount = 0; + VkStagingBuffCI.pQueueFamilyIndices = nullptr; std::string StagingBufferName = "Staging buffer for '"; StagingBufferName += m_Desc.Name; StagingBufferName += '\''; - m_StagingBuffer = LogicalDevice.CreateBuffer(VkStaginBuffCI, StagingBufferName.c_str()); + m_StagingBuffer = LogicalDevice.CreateBuffer(VkStagingBuffCI, StagingBufferName.c_str()); VkMemoryRequirements StagingBufferMemReqs = LogicalDevice.GetBufferMemoryRequirements(m_StagingBuffer); VERIFY(IsPowerOfTwo(StagingBufferMemReqs.alignment), "Alignment is not power of 2!"); -- cgit v1.2.3