diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-07-23 09:37:58 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-23 09:37:58 -0400 |
| commit | cf503553eb44f104072d8add4069f8352f7bad22 (patch) | |
| tree | 0fc7cfadd2f5ff10b9c10d5f4861efec22834a7a /tools | |
| parent | 115920406ebd747e02e1e6a8e4595f7d88eef0d9 (diff) | |
Fix for vulkan tests failing (#1456)
* Clean up device when VKRenderer dtor is run.
Added destroy methods to VulkanSwapChain & VulkanDeviceQueue
* Small fixes around testing if DeviceQueue is valid.
* Disable active-mask tests. Different drivers appear to change the results.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/gfx/vulkan/render-vk.cpp | 73 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-api.h | 1 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-device-queue.cpp | 12 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-device-queue.h | 6 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-swap-chain.cpp | 8 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-swap-chain.h | 2 |
6 files changed, 53 insertions, 49 deletions
diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp index 2221187ed..53c210a20 100644 --- a/tools/gfx/vulkan/render-vk.cpp +++ b/tools/gfx/vulkan/render-vk.cpp @@ -356,49 +356,6 @@ public: List<Binding> m_bindings; ///< Records entities are bound to this descriptor set, and keeps the associated resources/views/state in scope }; -#if 0 - struct BindingDetail - { - VkImageView m_srv = VK_NULL_HANDLE; - VkBufferView m_uav = VK_NULL_HANDLE; - VkSampler m_sampler = VK_NULL_HANDLE; - }; - - class BindingStateImpl: public BindingState - { - public: - typedef BindingState Parent; - - BindingStateImpl(const Desc& desc, const VulkanApi* api): - Parent(desc), - m_api(api) - { - } - ~BindingStateImpl() - { - for (int i = 0; i < int(m_bindingDetails.Count()); ++i) - { - BindingDetail& detail = m_bindingDetails[i]; - if (detail.m_sampler != VK_NULL_HANDLE) - { - m_api->vkDestroySampler(m_api->m_device, detail.m_sampler, nullptr); - } - if (detail.m_srv != VK_NULL_HANDLE) - { - m_api->vkDestroyImageView(m_api->m_device, detail.m_srv, nullptr); - } - if (detail.m_uav != VK_NULL_HANDLE) - { - m_api->vkDestroyBufferView(m_api->m_device, detail.m_uav, nullptr); - } - } - } - - const VulkanApi* m_api; - List<BindingDetail> m_bindingDetails; - }; -#endif - struct BoundVertexBuffer { RefPtr<BufferResourceImpl> m_buffer; @@ -423,11 +380,8 @@ public: const VulkanApi* m_api; -// VkPrimitiveTopology m_primitiveTopology; - RefPtr<PipelineLayoutImpl> m_pipelineLayout; -// RefPtr<InputLayoutImpl> m_inputLayout; RefPtr<ShaderProgramImpl> m_shaderProgram; VkPipeline m_pipeline = VK_NULL_HANDLE; @@ -804,11 +758,38 @@ Renderer* createVKRenderer() VKRenderer::~VKRenderer() { + // Check the device queue is valid else, we can't wait on it.. + if (m_deviceQueue.isValid()) + { + waitForGpu(); + } + + m_currentPipeline.setNull(); + + // Same as clear but, also dtors all elements, which clear does not + m_boundVertexBuffers = List<BoundVertexBuffer>(); + + m_currentPipelineLayout.setNull(); + for (auto& impl : m_currentDescriptorSetImpls) + { + impl.setNull(); + } + if (m_renderPass != VK_NULL_HANDLE) { m_api.vkDestroyRenderPass(m_device, m_renderPass, nullptr); m_renderPass = VK_NULL_HANDLE; } + + m_swapChain.destroy(); + + m_deviceQueue.destroy(); + + if (m_device != VK_NULL_HANDLE) + { + m_api.vkDestroyDevice(m_device, nullptr); + m_device = VK_NULL_HANDLE; + } } diff --git a/tools/gfx/vulkan/vk-api.h b/tools/gfx/vulkan/vk-api.h index 001f44d19..6f12d5ddb 100644 --- a/tools/gfx/vulkan/vk-api.h +++ b/tools/gfx/vulkan/vk-api.h @@ -17,6 +17,7 @@ namespace gfx { #define VK_API_INSTANCE_PROCS(x) \ x(vkCreateDevice) \ + x(vkDestroyDevice) \ x(vkCreateDebugReportCallbackEXT) \ x(vkDestroyDebugReportCallbackEXT) \ x(vkDebugReportMessageEXT) \ diff --git a/tools/gfx/vulkan/vk-device-queue.cpp b/tools/gfx/vulkan/vk-device-queue.cpp index 3b9e6cbcd..0cc9a0a0d 100644 --- a/tools/gfx/vulkan/vk-device-queue.cpp +++ b/tools/gfx/vulkan/vk-device-queue.cpp @@ -10,6 +10,11 @@ using namespace Slang; VulkanDeviceQueue::~VulkanDeviceQueue() { + destroy(); +} + +void VulkanDeviceQueue::destroy() +{ if (m_api) { for (int i = 0; i < int(EventType::CountOf); ++i) @@ -23,14 +28,14 @@ VulkanDeviceQueue::~VulkanDeviceQueue() m_api->vkDestroyFence(m_api->m_device, m_fences[i].fence, nullptr); } m_api->vkDestroyCommandPool(m_api->m_device, m_commandPool, nullptr); + m_api = nullptr; } } SlangResult VulkanDeviceQueue::init(const VulkanApi& api, VkQueue queue, int queueIndex) { assert(m_api == nullptr); - m_api = &api; - + for (int i = 0; i < int(EventType::CountOf); ++i) { m_semaphores[i] = VK_NULL_HANDLE; @@ -79,6 +84,9 @@ SlangResult VulkanDeviceQueue::init(const VulkanApi& api, VkQueue queue, int que api.vkCreateSemaphore(api.m_device, &semaphoreCreateInfo, nullptr, &m_semaphores[i]); } + // Set the api - also marks that the queue appears to be valid + m_api = &api; + // Second step of flush to prime command buffer flushStepB(); diff --git a/tools/gfx/vulkan/vk-device-queue.h b/tools/gfx/vulkan/vk-device-queue.h index d57483ec0..cd53b6b9d 100644 --- a/tools/gfx/vulkan/vk-device-queue.h +++ b/tools/gfx/vulkan/vk-device-queue.h @@ -54,6 +54,12 @@ struct VulkanDeviceQueue /// Steps to next command buffer and opens. May block if command buffer is still in use void flushStepB(); + /// Destroy the device queue + void destroy(); + + /// True if the queue appears to be valid and has been initialized + bool isValid() const { return m_api != nullptr; } + /// Dtor ~VulkanDeviceQueue(); diff --git a/tools/gfx/vulkan/vk-swap-chain.cpp b/tools/gfx/vulkan/vk-swap-chain.cpp index 5cf2e96ae..d9b3a495d 100644 --- a/tools/gfx/vulkan/vk-swap-chain.cpp +++ b/tools/gfx/vulkan/vk-swap-chain.cpp @@ -348,7 +348,7 @@ void VulkanSwapChain::_destroySwapChain() m_images.clear(); } -VulkanSwapChain::~VulkanSwapChain() +void VulkanSwapChain::destroy() { _destroySwapChain(); @@ -359,6 +359,12 @@ VulkanSwapChain::~VulkanSwapChain() } } + +VulkanSwapChain::~VulkanSwapChain() +{ + destroy(); +} + int VulkanSwapChain::nextFrontImageIndex() { if (!hasValidSwapChain()) diff --git a/tools/gfx/vulkan/vk-swap-chain.h b/tools/gfx/vulkan/vk-swap-chain.h index 57d1173b8..9b4dfc2c1 100644 --- a/tools/gfx/vulkan/vk-swap-chain.h +++ b/tools/gfx/vulkan/vk-swap-chain.h @@ -94,6 +94,8 @@ struct VulkanSwapChain /// Get the next front render image index. Returns -1, if image couldn't be found int nextFrontImageIndex(); + void destroy(); + /// Dtor ~VulkanSwapChain(); |
