diff --git a/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.cpp index 205f4d092..22471ed8c 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.cpp @@ -129,15 +129,13 @@ void CmdBufferVulkan::RefreshFenceStatus() { if (_state == State::Submitted) { - auto fenceManager = _fence->GetOwner(); - if (fenceManager->IsFenceSignaled(_fence)) + if (_device->FenceManager.IsFenceSignaled(_fence)) { _state = State::ReadyForBegin; - _submittedWaitSemaphores.Clear(); vkResetCommandBuffer(_commandBuffer, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); - _fence->GetOwner()->ResetFence(_fence); + _device->FenceManager.ResetFence(_fence); _fenceSignaledCounter++; if (_descriptorPoolSetContainer) @@ -149,7 +147,7 @@ void CmdBufferVulkan::RefreshFenceStatus() } else { - ASSERT(!_fence->IsSignaled()); + ASSERT(!_fence->IsSignaled); } } @@ -158,8 +156,8 @@ CmdBufferVulkan::CmdBufferVulkan(GPUDeviceVulkan* device, CmdBufferPoolVulkan* p , _commandBuffer(VK_NULL_HANDLE) , _state(State::ReadyForBegin) , _fence(nullptr) - , _fenceSignaledCounter(0) , _submittedFenceCounter(0) + , _fenceSignaledCounter(0) , _commandBufferPool(pool) { VkCommandBufferAllocateInfo createCmdBufInfo; @@ -167,7 +165,6 @@ CmdBufferVulkan::CmdBufferVulkan(GPUDeviceVulkan* device, CmdBufferPoolVulkan* p createCmdBufInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; createCmdBufInfo.commandBufferCount = 1; createCmdBufInfo.commandPool = _commandBufferPool->GetHandle(); - VALIDATE_VULKAN_RESULT(vkAllocateCommandBuffers(_device->Device, &createCmdBufInfo, &_commandBuffer)); _fence = _device->FenceManager.AllocateFence(); } @@ -217,17 +214,16 @@ CmdBufferPoolVulkan::~CmdBufferPoolVulkan() { for (int32 i = 0; i < _cmdBuffers.Count(); i++) { - Delete(_cmdBuffers[i]); + Delete(_cmdBuffers.Get()[i]); } - vkDestroyCommandPool(_device->Device, _handle, nullptr); } -void CmdBufferPoolVulkan::RefreshFenceStatus(CmdBufferVulkan* skipCmdBuffer) +void CmdBufferPoolVulkan::RefreshFenceStatus(const CmdBufferVulkan* skipCmdBuffer) { for (int32 i = 0; i < _cmdBuffers.Count(); i++) { - auto cmdBuffer = _cmdBuffers[i]; + const auto cmdBuffer = _cmdBuffers.Get()[i]; if (cmdBuffer != skipCmdBuffer) { cmdBuffer->RefreshFenceStatus(); @@ -250,9 +246,8 @@ void CmdBufferManagerVulkan::SubmitActiveCmdBuffer(SemaphoreVulkan* signalSemaph if (!_activeCmdBuffer->IsSubmitted() && _activeCmdBuffer->HasBegun()) { if (_activeCmdBuffer->IsInsideRenderPass()) - { _activeCmdBuffer->EndRenderPass(); - } + #if VULKAN_USE_QUERIES // Pause all active queries diff --git a/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.h index e54085ecd..6d0f7d83b 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/CmdBufferVulkan.h @@ -21,7 +21,6 @@ class CmdBufferVulkan friend QueueVulkan; public: - enum class State { ReadyForBegin, @@ -32,7 +31,6 @@ public: }; private: - GPUDeviceVulkan* _device; VkCommandBuffer _commandBuffer; State _state; @@ -57,13 +55,11 @@ private: DescriptorPoolSetContainerVulkan* _descriptorPoolSetContainer = nullptr; public: - CmdBufferVulkan(GPUDeviceVulkan* device, CmdBufferPoolVulkan* pool); ~CmdBufferVulkan(); public: - CmdBufferPoolVulkan* GetOwner() const { return _commandBufferPool; @@ -120,7 +116,6 @@ public: } public: - void AddWaitSemaphore(VkPipelineStageFlags waitFlags, SemaphoreVulkan* waitSemaphore); void Begin(); @@ -147,8 +142,8 @@ public: class CmdBufferPoolVulkan { friend class CmdBufferManagerVulkan; -private: +private: GPUDeviceVulkan* _device; VkCommandPool _handle; Array _cmdBuffers; @@ -158,25 +153,22 @@ private: void Create(uint32 queueFamilyIndex); public: - CmdBufferPoolVulkan(GPUDeviceVulkan* device); ~CmdBufferPoolVulkan(); public: - inline VkCommandPool GetHandle() const { ASSERT(_handle != VK_NULL_HANDLE); return _handle; } - void RefreshFenceStatus(CmdBufferVulkan* skipCmdBuffer = nullptr); + void RefreshFenceStatus(const CmdBufferVulkan* skipCmdBuffer = nullptr); }; class CmdBufferManagerVulkan { private: - GPUDeviceVulkan* _device; CmdBufferPoolVulkan _pool; QueueVulkan* _queue; @@ -184,11 +176,9 @@ private: Array _queriesInProgress; public: - CmdBufferManagerVulkan(GPUDeviceVulkan* device, GPUContextVulkan* context); public: - FORCE_INLINE VkCommandPool GetHandle() const { return _pool.GetHandle(); @@ -217,7 +207,6 @@ public: } public: - void SubmitActiveCmdBuffer(SemaphoreVulkan* signalSemaphore = nullptr); void WaitForCmdBuffer(CmdBufferVulkan* cmdBuffer, float timeInSecondsToWait = 1.0f); diff --git a/Source/Engine/GraphicsDevice/Vulkan/Config.h b/Source/Engine/GraphicsDevice/Vulkan/Config.h index 55ffb5d58..95162de9f 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/Config.h +++ b/Source/Engine/GraphicsDevice/Vulkan/Config.h @@ -23,7 +23,7 @@ /// /// Default amount of frames to wait until resource delete. /// -#define VULKAN_RESOURCE_DELETE_SAFE_FRAMES_COUNT 10 +#define VULKAN_RESOURCE_DELETE_SAFE_FRAMES_COUNT 20 #define VULKAN_ENABLE_API_DUMP 0 #define VULKAN_RESET_QUERY_POOLS 0 diff --git a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp index 2dad4bc9b..fdd844536 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp @@ -12,29 +12,12 @@ #include "Engine/Threading/Threading.h" #include "Engine/Engine/Engine.h" -void DescriptorSetLayoutInfoVulkan::CacheTypesUsageID() -{ - static CriticalSection locker; - static uint32 uniqueID = 1; - static Dictionary typesUsageHashMap; - - const uint32 typesUsageHash = Crc::MemCrc32(_layoutTypes, sizeof(_layoutTypes)); - ScopeLock lock(locker); - uint32 id; - if (!typesUsageHashMap.TryGet(typesUsageHash, id)) - { - id = uniqueID++; - typesUsageHashMap.Add(typesUsageHash, id); - } - _typesUsageID = id; -} - void DescriptorSetLayoutInfoVulkan::AddBindingsForStage(VkShaderStageFlagBits stageFlags, DescriptorSet::Stage descSet, const SpirvShaderDescriptorInfo* descriptorInfo) { const int32 descriptorSetIndex = descSet; - if (descriptorSetIndex >= _setLayouts.Count()) - _setLayouts.Resize(descriptorSetIndex + 1); - SetLayout& descSetLayout = _setLayouts[descriptorSetIndex]; + if (descriptorSetIndex >= SetLayouts.Count()) + SetLayouts.Resize(descriptorSetIndex + 1); + SetLayout& descSetLayout = SetLayouts[descriptorSetIndex]; VkDescriptorSetLayoutBinding binding; binding.stageFlags = stageFlags; @@ -46,25 +29,26 @@ void DescriptorSetLayoutInfoVulkan::AddBindingsForStage(VkShaderStageFlagBits st binding.descriptorType = descriptor.DescriptorType; binding.descriptorCount = descriptor.Count; - _layoutTypes[binding.descriptorType]++; - descSetLayout.LayoutBindings.Add(binding); - _hash = Crc::MemCrc32(&binding, sizeof(binding), _hash); + LayoutTypes[binding.descriptorType]++; + descSetLayout.Add(binding); + Hash = Crc::MemCrc32(&binding, sizeof(binding), Hash); } } bool DescriptorSetLayoutInfoVulkan::operator==(const DescriptorSetLayoutInfoVulkan& other) const { - if (other._setLayouts.Count() != _setLayouts.Count()) + if (other.SetLayouts.Count() != SetLayouts.Count()) return false; - if (other._typesUsageID != _typesUsageID) + if (other.TypesUsageID != TypesUsageID) return false; - for (int32 index = 0; index < other._setLayouts.Count(); index++) + for (int32 index = 0; index < other.SetLayouts.Count(); index++) { - const int32 bindingsCount = _setLayouts[index].LayoutBindings.Count(); - if (other._setLayouts[index].LayoutBindings.Count() != bindingsCount) + auto& setLayout = SetLayouts[index]; + auto& setLayoutOther = other.SetLayouts[index]; + if (setLayoutOther.Count() != setLayout.Count()) return false; - if (bindingsCount != 0 && Platform::MemoryCompare(other._setLayouts[index].LayoutBindings.Get(), _setLayouts[index].LayoutBindings.Get(), bindingsCount * sizeof(VkDescriptorSetLayoutBinding))) + if (setLayout.Count() != 0 && Platform::MemoryCompare(setLayoutOther.Get(), setLayout.Get(), setLayout.Count() * sizeof(VkDescriptorSetLayoutBinding))) return false; } @@ -72,51 +56,63 @@ bool DescriptorSetLayoutInfoVulkan::operator==(const DescriptorSetLayoutInfoVulk } DescriptorSetLayoutVulkan::DescriptorSetLayoutVulkan(GPUDeviceVulkan* device) - : _device(device) + : Device(device) { } DescriptorSetLayoutVulkan::~DescriptorSetLayoutVulkan() { - for (VkDescriptorSetLayout& handle : _handles) + for (VkDescriptorSetLayout& handle : Handles) { - _device->DeferredDeletionQueue.EnqueueResource(DeferredDeletionQueueVulkan::Type::DescriptorSetLayout, handle); + Device->DeferredDeletionQueue.EnqueueResource(DeferredDeletionQueueVulkan::Type::DescriptorSetLayout, handle); } } void DescriptorSetLayoutVulkan::Compile() { - ASSERT(_handles.IsEmpty()); + ASSERT(Handles.IsEmpty()); // Validate device limits for the engine - const VkPhysicalDeviceLimits& limits = _device->PhysicalDeviceLimits; - ASSERT(_layoutTypes[VK_DESCRIPTOR_TYPE_SAMPLER] + _layoutTypes[VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER] < limits.maxDescriptorSetSamplers); - ASSERT(_layoutTypes[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER]+ _layoutTypes[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC] < limits.maxDescriptorSetUniformBuffers); - ASSERT(_layoutTypes[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC] < limits.maxDescriptorSetUniformBuffersDynamic); - ASSERT(_layoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER] + _layoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC] < limits.maxDescriptorSetStorageBuffers); - ASSERT(_layoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC] < limits.maxDescriptorSetStorageBuffersDynamic); - ASSERT(_layoutTypes[VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER] + _layoutTypes[VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE] + _layoutTypes[VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER] < limits.maxDescriptorSetSampledImages); - ASSERT(_layoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_IMAGE] + _layoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER]< limits.maxDescriptorSetStorageImages); + const VkPhysicalDeviceLimits& limits = Device->PhysicalDeviceLimits; + ASSERT(LayoutTypes[VK_DESCRIPTOR_TYPE_SAMPLER] + LayoutTypes[VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER] < limits.maxDescriptorSetSamplers); + ASSERT(LayoutTypes[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER]+ LayoutTypes[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC] < limits.maxDescriptorSetUniformBuffers); + ASSERT(LayoutTypes[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC] < limits.maxDescriptorSetUniformBuffersDynamic); + ASSERT(LayoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER] + LayoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC] < limits.maxDescriptorSetStorageBuffers); + ASSERT(LayoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC] < limits.maxDescriptorSetStorageBuffersDynamic); + ASSERT(LayoutTypes[VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER] + LayoutTypes[VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE] + LayoutTypes[VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER] < limits.maxDescriptorSetSampledImages); + ASSERT(LayoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_IMAGE] + LayoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER]< limits.maxDescriptorSetStorageImages); - _handles.Resize(_setLayouts.Count()); - for (int32 i = 0; i < _setLayouts.Count(); i++) + Handles.Resize(SetLayouts.Count()); + for (int32 i = 0; i < SetLayouts.Count(); i++) { - auto& layout = _setLayouts[i]; + auto& layout = SetLayouts[i]; VkDescriptorSetLayoutCreateInfo layoutInfo; RenderToolsVulkan::ZeroStruct(layoutInfo, VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO); - layoutInfo.bindingCount = layout.LayoutBindings.Count(); - layoutInfo.pBindings = layout.LayoutBindings.Get(); - VALIDATE_VULKAN_RESULT(vkCreateDescriptorSetLayout(_device->Device, &layoutInfo, nullptr, &_handles[i])); + layoutInfo.bindingCount = layout.Count(); + layoutInfo.pBindings = layout.Get(); + VALIDATE_VULKAN_RESULT(vkCreateDescriptorSetLayout(Device->Device, &layoutInfo, nullptr, &Handles[i])); } - if (_typesUsageID == ~0) + if (TypesUsageID == ~0) { - CacheTypesUsageID(); + // Cache usage ID + static uint32 uniqueID = 1; + static Dictionary typesUsageHashMap; + const uint32 typesUsageHash = Crc::MemCrc32(LayoutTypes, sizeof(LayoutTypes)); + uint32 id; + Device->Locker.Lock(); + if (!typesUsageHashMap.TryGet(typesUsageHash, id)) + { + id = uniqueID++; + typesUsageHashMap.Add(typesUsageHash, id); + } + Device->Locker.Unlock(); + TypesUsageID = id; } - RenderToolsVulkan::ZeroStruct(_allocateInfo, VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO); - _allocateInfo.descriptorSetCount = _handles.Count(); - _allocateInfo.pSetLayouts = _handles.Get(); + RenderToolsVulkan::ZeroStruct(AllocateInfo, VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO); + AllocateInfo.descriptorSetCount = Handles.Count(); + AllocateInfo.pSetLayouts = Handles.Get(); } DescriptorPoolVulkan::DescriptorPoolVulkan(GPUDeviceVulkan* device, const DescriptorSetLayoutVulkan& layout) @@ -131,11 +127,11 @@ DescriptorPoolVulkan::DescriptorPoolVulkan(GPUDeviceVulkan* device, const Descri // The maximum amount of descriptor sets layout allocations to hold const uint32 MaxSetsAllocations = 256; - _descriptorSetsMax = MaxSetsAllocations * (VULKAN_HASH_POOLS_WITH_TYPES_USAGE_ID ? 1 : _layout.GetLayouts().Count()); + _descriptorSetsMax = MaxSetsAllocations * (VULKAN_HASH_POOLS_WITH_TYPES_USAGE_ID ? 1 : _layout.SetLayouts.Count()); for (uint32 typeIndex = VULKAN_DESCRIPTOR_TYPE_BEGIN; typeIndex <= VULKAN_DESCRIPTOR_TYPE_END; typeIndex++) { const VkDescriptorType descriptorType = (VkDescriptorType)typeIndex; - const uint32 typesUsed = _layout.GetTypesUsed(descriptorType); + const uint32 typesUsed = _layout.LayoutTypes[descriptorType]; if (typesUsed > 0) { VkDescriptorPoolSize& type = types.AddOne(); @@ -167,22 +163,22 @@ void DescriptorPoolVulkan::Track(const DescriptorSetLayoutVulkan& layout) #if !BUILD_RELEASE for (uint32 typeIndex = VULKAN_DESCRIPTOR_TYPE_BEGIN; typeIndex <= VULKAN_DESCRIPTOR_TYPE_END; typeIndex++) { - ASSERT(_layout.GetTypesUsed((VkDescriptorType)typeIndex) == layout.GetTypesUsed((VkDescriptorType)typeIndex)); + ASSERT(_layout.LayoutTypes[typeIndex] == layout.LayoutTypes[typeIndex]); } #endif - _allocatedDescriptorSetsCount += layout.GetLayouts().Count(); + _allocatedDescriptorSetsCount += layout.SetLayouts.Count(); _allocatedDescriptorSetsCountMax = Math::Max(_allocatedDescriptorSetsCount, _allocatedDescriptorSetsCountMax); } void DescriptorPoolVulkan::TrackRemoveUsage(const DescriptorSetLayoutVulkan& layout) { - // Check and increment our current type usage +#if !BUILD_RELEASE for (uint32 typeIndex = VULKAN_DESCRIPTOR_TYPE_BEGIN; typeIndex <= VULKAN_DESCRIPTOR_TYPE_END; typeIndex++) { - ASSERT(_layout.GetTypesUsed((VkDescriptorType)typeIndex) == layout.GetTypesUsed((VkDescriptorType)typeIndex)); + ASSERT(_layout.LayoutTypes[typeIndex] == layout.LayoutTypes[typeIndex]); } - - _allocatedDescriptorSetsCount -= layout.GetLayouts().Count(); +#endif + _allocatedDescriptorSetsCount -= layout.SetLayouts.Count(); } void DescriptorPoolVulkan::Reset() @@ -214,11 +210,10 @@ TypedDescriptorPoolSetVulkan::~TypedDescriptorPoolSetVulkan() bool TypedDescriptorPoolSetVulkan::AllocateDescriptorSets(const DescriptorSetLayoutVulkan& layout, VkDescriptorSet* outSets) { - const auto& layoutHandles = layout.GetHandles(); - if (layoutHandles.HasItems()) + if (layout.Handles.HasItems()) { auto* pool = _poolListCurrent->Element; - while (!pool->AllocateDescriptorSets(layout.GetAllocateInfo(), outSets)) + while (!pool->AllocateDescriptorSets(layout.AllocateInfo, outSets)) { pool = GetFreePool(true); } @@ -279,7 +274,7 @@ DescriptorPoolSetContainerVulkan::~DescriptorPoolSetContainerVulkan() TypedDescriptorPoolSetVulkan* DescriptorPoolSetContainerVulkan::AcquireTypedPoolSet(const DescriptorSetLayoutVulkan& layout) { - const uint32 hash = VULKAN_HASH_POOLS_WITH_TYPES_USAGE_ID ? layout.GetTypesUsageID() : GetHash(layout); + const uint32 hash = VULKAN_HASH_POOLS_WITH_TYPES_USAGE_ID ? layout.TypesUsageID : layout.Hash; TypedDescriptorPoolSetVulkan* typedPool; if (!_typedDescriptorPools.TryGet(hash, typedPool)) { @@ -361,12 +356,10 @@ PipelineLayoutVulkan::PipelineLayoutVulkan(GPUDeviceVulkan* device, const Descri _descriptorSetLayout.CopyFrom(layout); _descriptorSetLayout.Compile(); - const auto& layoutHandles = _descriptorSetLayout.GetHandles(); - VkPipelineLayoutCreateInfo createInfo; RenderToolsVulkan::ZeroStruct(createInfo, VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO); - createInfo.setLayoutCount = layoutHandles.Count(); - createInfo.pSetLayouts = layoutHandles.Get(); + createInfo.setLayoutCount = _descriptorSetLayout.Handles.Count(); + createInfo.pSetLayouts = _descriptorSetLayout.Handles.Get(); VALIDATE_VULKAN_RESULT(vkCreatePipelineLayout(_device->Device, &createInfo, nullptr, &_handle)); } diff --git a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h index d8d80b51e..c5ab265d2 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h @@ -54,106 +54,62 @@ namespace DescriptorSet class DescriptorSetLayoutInfoVulkan { public: + typedef Array SetLayout; - struct SetLayout - { - Array LayoutBindings; - }; - -protected: - - uint32 _layoutTypes[VULKAN_DESCRIPTOR_TYPE_END]; - Array _setLayouts; - uint32 _hash = 0; - uint32 _typesUsageID = ~0; + uint32 Hash = 0; + uint32 TypesUsageID = ~0; + Array SetLayouts; + uint32 LayoutTypes[VULKAN_DESCRIPTOR_TYPE_END]; void CacheTypesUsageID(); public: - DescriptorSetLayoutInfoVulkan() { - Platform::MemoryClear(_layoutTypes, sizeof(_layoutTypes)); + Platform::MemoryClear(LayoutTypes, sizeof(LayoutTypes)); } -public: - - inline uint32 GetTypesUsed(VkDescriptorType type) const - { - return _layoutTypes[type]; - } - - const Array& GetLayouts() const - { - return _setLayouts; - } - - inline uint32 GetTypesUsageID() const - { - return _typesUsageID; - } - -public: - void AddBindingsForStage(VkShaderStageFlagBits stageFlags, DescriptorSet::Stage descSet, const SpirvShaderDescriptorInfo* descriptorInfo); void CopyFrom(const DescriptorSetLayoutInfoVulkan& info) { - Platform::MemoryCopy(_layoutTypes, info._layoutTypes, sizeof(_layoutTypes)); - _hash = info._hash; - _typesUsageID = info._typesUsageID; - _setLayouts = info._setLayouts; + Platform::MemoryCopy(LayoutTypes, info.LayoutTypes, sizeof(LayoutTypes)); + Hash = info.Hash; + TypesUsageID = info.TypesUsageID; + SetLayouts = info.SetLayouts; } bool operator==(const DescriptorSetLayoutInfoVulkan& other) const; friend inline uint32 GetHash(const DescriptorSetLayoutInfoVulkan& key) { - return key._hash; + return key.Hash; } }; class DescriptorSetLayoutVulkan : public DescriptorSetLayoutInfoVulkan { public: + typedef Array> HandlesArray; - typedef Array> DescriptorSetLayoutHandlesArray; - -private: - - GPUDeviceVulkan* _device; - DescriptorSetLayoutHandlesArray _handles; - VkDescriptorSetAllocateInfo _allocateInfo; - -public: + GPUDeviceVulkan* Device; + HandlesArray Handles; + VkDescriptorSetAllocateInfo AllocateInfo; DescriptorSetLayoutVulkan(GPUDeviceVulkan* device); ~DescriptorSetLayoutVulkan(); -public: - - inline const DescriptorSetLayoutHandlesArray& GetHandles() const - { - return _handles; - } - - inline const VkDescriptorSetAllocateInfo& GetAllocateInfo() const - { - return _allocateInfo; - } + void Compile(); friend inline uint32 GetHash(const DescriptorSetLayoutVulkan& key) { - return key._hash; + return key.Hash; } - - void Compile(); }; class DescriptorPoolVulkan { private: - GPUDeviceVulkan* _device; VkDescriptorPool _handle; @@ -164,12 +120,10 @@ private: const DescriptorSetLayoutVulkan& _layout; public: - DescriptorPoolVulkan(GPUDeviceVulkan* device, const DescriptorSetLayoutVulkan& layout); ~DescriptorPoolVulkan(); public: - inline VkDescriptorPool GetHandle() const { return _handle; @@ -182,7 +136,7 @@ public: inline bool CanAllocate(const DescriptorSetLayoutVulkan& layout) const { - return _descriptorSetsMax > _allocatedDescriptorSetsCount + layout.GetLayouts().Count(); + return _descriptorSetsMax > _allocatedDescriptorSetsCount + layout.SetLayouts.Count(); } inline uint32 GetAllocatedDescriptorSetsCount() const @@ -191,7 +145,6 @@ public: } public: - void Track(const DescriptorSetLayoutVulkan& layout); void TrackRemoveUsage(const DescriptorSetLayoutVulkan& layout); void Reset(); @@ -205,7 +158,6 @@ class TypedDescriptorPoolSetVulkan friend DescriptorPoolSetContainerVulkan; private: - GPUDeviceVulkan* _device; const DescriptorPoolSetContainerVulkan* _owner; const DescriptorSetLayoutVulkan& _layout; @@ -213,7 +165,6 @@ private: class PoolList { public: - DescriptorPoolVulkan* Element; PoolList* Next; @@ -228,7 +179,6 @@ private: PoolList* _poolListCurrent = nullptr; public: - TypedDescriptorPoolSetVulkan(GPUDeviceVulkan* device, const DescriptorPoolSetContainerVulkan* owner, const DescriptorSetLayoutVulkan& layout) : _device(device) , _owner(owner) @@ -247,7 +197,6 @@ public: } private: - DescriptorPoolVulkan* GetFreePool(bool forceNewPool = false); DescriptorPoolVulkan* PushNewPool(); void Reset(); @@ -256,20 +205,16 @@ private: class DescriptorPoolSetContainerVulkan { private: - GPUDeviceVulkan* _device; Dictionary _typedDescriptorPools; uint64 _lastFrameUsed; bool _used; public: - DescriptorPoolSetContainerVulkan(GPUDeviceVulkan* device); - ~DescriptorPoolSetContainerVulkan(); public: - TypedDescriptorPoolSetVulkan* AcquireTypedPoolSet(const DescriptorSetLayoutVulkan& layout); void Reset(); void SetUsed(bool used); @@ -288,13 +233,11 @@ public: class DescriptorPoolsManagerVulkan { private: - GPUDeviceVulkan* _device = nullptr; CriticalSection _locker; Array _poolSets; public: - DescriptorPoolsManagerVulkan(GPUDeviceVulkan* device); ~DescriptorPoolsManagerVulkan(); @@ -306,25 +249,20 @@ public: class PipelineLayoutVulkan { private: - GPUDeviceVulkan* _device; VkPipelineLayout _handle; DescriptorSetLayoutVulkan _descriptorSetLayout; public: - PipelineLayoutVulkan(GPUDeviceVulkan* device, const DescriptorSetLayoutInfoVulkan& layout); ~PipelineLayoutVulkan(); public: - inline VkPipelineLayout GetHandle() const { return _handle; } -public: - inline const DescriptorSetLayoutVulkan& GetDescriptorSetLayout() const { return _descriptorSetLayout; @@ -332,7 +270,7 @@ public: inline bool HasDescriptors() const { - return _descriptorSetLayout.GetLayouts().HasItems(); + return _descriptorSetLayout.SetLayouts.HasItems(); } }; @@ -357,14 +295,12 @@ struct DescriptorSetWriteContainerVulkan class DescriptorSetWriterVulkan { public: - VkWriteDescriptorSet* WriteDescriptors = nullptr; byte* BindingToDynamicOffset = nullptr; uint32* DynamicOffsets = nullptr; uint32 WritesCount = 0; public: - uint32 SetupDescriptorWrites(const SpirvShaderDescriptorInfo& info, VkWriteDescriptorSet* writeDescriptors, VkDescriptorImageInfo* imageInfo, VkDescriptorBufferInfo* bufferInfo, VkBufferView* texelBufferView, byte* bindingToDynamicOffset); bool WriteUniformBuffer(uint32 descriptorIndex, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range, uint32 index = 0) const @@ -451,9 +387,7 @@ public: void SetDescriptorSet(VkDescriptorSet descriptorSet) const { for (uint32 i = 0; i < WritesCount; i++) - { WriteDescriptors[i].dstSet = descriptorSet; - } } }; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUAdapterVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUAdapterVulkan.h index b5b6f1dbc..c03676d9c 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUAdapterVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUAdapterVulkan.h @@ -14,7 +14,6 @@ class GPUAdapterVulkan : public GPUAdapter { public: - /// /// Initializes a new instance of the class. /// @@ -38,7 +37,6 @@ public: } public: - /// /// The GPU device handle. /// @@ -55,7 +53,6 @@ public: String Description; public: - // [GPUAdapter] bool IsValid() const override { diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUBufferVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUBufferVulkan.h index 3bcf0a978..716daf5e3 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUBufferVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUBufferVulkan.h @@ -13,7 +13,6 @@ class GPUBufferViewVulkan : public GPUBufferView, public DescriptorOwnerResourceVulkan { public: - GPUBufferViewVulkan() { } @@ -26,7 +25,6 @@ public: #endif public: - GPUDeviceVulkan* Device = nullptr; GPUBufferVulkan* Owner = nullptr; VkBuffer Buffer = VK_NULL_HANDLE; @@ -34,13 +32,10 @@ public: VkDeviceSize Size = 0; public: - void Init(GPUDeviceVulkan* device, GPUBufferVulkan* owner, VkBuffer buffer, VkDeviceSize size, VkBufferUsageFlags usage, PixelFormat format); - void Release(); public: - // [GPUResourceView] void* GetNativePtr() const override { @@ -59,13 +54,11 @@ public: class GPUBufferVulkan : public GPUResourceVulkan { private: - VkBuffer _buffer = VK_NULL_HANDLE; VmaAllocation _allocation = VK_NULL_HANDLE; GPUBufferViewVulkan _view; public: - /// /// Initializes a new instance of the class. /// @@ -77,7 +70,6 @@ public: } public: - /// /// Gets the Vulkan buffer handle. /// @@ -105,14 +97,12 @@ public: GPUBufferVulkan* Counter = nullptr; public: - // [GPUBuffer] GPUBufferView* View() const override; void* Map(GPUResourceMapMode mode) override; void Unmap() override; protected: - // [GPUBuffer] bool OnInit() override; void OnReleaseGPU() override; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp index 79e882f6d..138454e36 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp @@ -20,18 +20,18 @@ // Ensure to match the indirect commands arguments layout static_assert(sizeof(GPUDispatchIndirectArgs) == sizeof(VkDispatchIndirectCommand), "Wrong size of GPUDrawIndirectArgs."); static_assert(OFFSET_OF(GPUDispatchIndirectArgs, ThreadGroupCountX) == OFFSET_OF(VkDispatchIndirectCommand, x), "Wrong offset for GPUDrawIndirectArgs::ThreadGroupCountX"); -static_assert(OFFSET_OF(GPUDispatchIndirectArgs, ThreadGroupCountY) == OFFSET_OF(VkDispatchIndirectCommand, y),"Wrong offset for GPUDrawIndirectArgs::ThreadGroupCountY"); +static_assert(OFFSET_OF(GPUDispatchIndirectArgs, ThreadGroupCountY) == OFFSET_OF(VkDispatchIndirectCommand, y), "Wrong offset for GPUDrawIndirectArgs::ThreadGroupCountY"); static_assert(OFFSET_OF(GPUDispatchIndirectArgs, ThreadGroupCountZ) == OFFSET_OF(VkDispatchIndirectCommand, z), "Wrong offset for GPUDrawIndirectArgs::ThreadGroupCountZ"); // static_assert(sizeof(GPUDrawIndirectArgs) == sizeof(VkDrawIndirectCommand), "Wrong size of GPUDrawIndirectArgs."); static_assert(OFFSET_OF(GPUDrawIndirectArgs, VerticesCount) == OFFSET_OF(VkDrawIndirectCommand, vertexCount), "Wrong offset for GPUDrawIndirectArgs::VerticesCount"); -static_assert(OFFSET_OF(GPUDrawIndirectArgs, InstanceCount) == OFFSET_OF(VkDrawIndirectCommand, instanceCount),"Wrong offset for GPUDrawIndirectArgs::InstanceCount"); +static_assert(OFFSET_OF(GPUDrawIndirectArgs, InstanceCount) == OFFSET_OF(VkDrawIndirectCommand, instanceCount), "Wrong offset for GPUDrawIndirectArgs::InstanceCount"); static_assert(OFFSET_OF(GPUDrawIndirectArgs, StartVertex) == OFFSET_OF(VkDrawIndirectCommand, firstVertex), "Wrong offset for GPUDrawIndirectArgs::StartVertex"); static_assert(OFFSET_OF(GPUDrawIndirectArgs, StartInstance) == OFFSET_OF(VkDrawIndirectCommand, firstInstance), "Wrong offset for GPUDrawIndirectArgs::StartInstance"); // static_assert(sizeof(GPUDrawIndexedIndirectArgs) == sizeof(VkDrawIndexedIndirectCommand), "Wrong size of GPUDrawIndexedIndirectArgs."); static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, IndicesCount) == OFFSET_OF(VkDrawIndexedIndirectCommand, indexCount), "Wrong offset for GPUDrawIndexedIndirectArgs::IndicesCount"); -static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, InstanceCount) == OFFSET_OF(VkDrawIndexedIndirectCommand, instanceCount),"Wrong offset for GPUDrawIndexedIndirectArgs::InstanceCount"); +static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, InstanceCount) == OFFSET_OF(VkDrawIndexedIndirectCommand, instanceCount), "Wrong offset for GPUDrawIndexedIndirectArgs::InstanceCount"); static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, StartIndex) == OFFSET_OF(VkDrawIndexedIndirectCommand, firstIndex), "Wrong offset for GPUDrawIndexedIndirectArgs::StartIndex"); static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, StartVertex) == OFFSET_OF(VkDrawIndexedIndirectCommand, vertexOffset), "Wrong offset for GPUDrawIndexedIndirectArgs::StartVertex"); static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, StartInstance) == OFFSET_OF(VkDrawIndexedIndirectCommand, firstInstance), "Wrong offset for GPUDrawIndexedIndirectArgs::StartInstance"); @@ -337,7 +337,7 @@ DescriptorPoolVulkan* GPUContextVulkan::AllocateDescriptorSets(const VkDescripto VkDescriptorSetAllocateInfo allocateInfo = descriptorSetAllocateInfo; DescriptorPoolVulkan* pool = nullptr; - const uint32 hash = VULKAN_HASH_POOLS_WITH_TYPES_USAGE_ID ? layout.GetTypesUsageID() : GetHash(layout); + const uint32 hash = VULKAN_HASH_POOLS_WITH_TYPES_USAGE_ID ? layout.TypesUsageID : layout.Hash; DescriptorPoolArray* typedDescriptorPools = _descriptorPools.TryGet(hash); if (typedDescriptorPools != nullptr) diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h index 125bba8cf..c0968e742 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.h @@ -41,7 +41,6 @@ class DescriptorSetLayoutVulkan; struct PipelineBarrierVulkan { public: - VkPipelineStageFlags SourceStage = 0; VkPipelineStageFlags DestStage = 0; Array> ImageBarriers; @@ -51,7 +50,6 @@ public: #endif public: - inline void Reset() { SourceStage = 0; @@ -85,7 +83,6 @@ public: class GPUContextVulkan : public GPUContext { private: - GPUDeviceVulkan* _device; QueueVulkan* _queue; CmdBufferManagerVulkan* _cmdBufferManager; @@ -116,7 +113,6 @@ private: Dictionary _descriptorPools; public: - /// /// Initializes a new instance of the class. /// @@ -130,7 +126,6 @@ public: ~GPUContextVulkan(); public: - QueueVulkan* GetQueue() const { return _queue; @@ -157,14 +152,12 @@ public: void EndRenderPass(); private: - void UpdateDescriptorSets(const struct SpirvShaderDescriptorInfo& descriptorInfo, class DescriptorSetWriterVulkan& dsWriter, bool& needsWrite); void UpdateDescriptorSets(GPUPipelineStateVulkan* pipelineState); void UpdateDescriptorSets(ComputePipelineStateVulkan* pipelineState); void OnDrawCall(); public: - // [GPUContext] void FrameBegin() override; void FrameEnd() override; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp index 19578df89..7d8c3a46f 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp @@ -250,23 +250,18 @@ void SetupDebugLayerCallback() { default: createInfo.messageSeverity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT; - // Fall-through... case 4: createInfo.messageSeverity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT; - // Fall-through... case 3: createInfo.messageType |= VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; - // Fall-through... case 2: createInfo.messageSeverity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT; createInfo.messageType |= VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT; - // Fall-through... case 1: createInfo.messageSeverity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; createInfo.messageType |= VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT; break; case 0: - // Nothing to do break; } const VkResult result = vkCreateDebugUtilsMessengerEXT(GPUDeviceVulkan::Instance, &createInfo, nullptr, &Messenger); @@ -288,21 +283,16 @@ void SetupDebugLayerCallback() { default: createInfo.flags |= VK_DEBUG_REPORT_DEBUG_BIT_EXT; - // Fall-through... case 4: createInfo.flags |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT; - // Fall-through... case 3: createInfo.flags |= VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; - // Fall-through... case 2: createInfo.flags |= VK_DEBUG_REPORT_WARNING_BIT_EXT; - // Fall-through... case 1: createInfo.flags |= VK_DEBUG_REPORT_ERROR_BIT_EXT; break; case 0: - // Nothing to do break; } const VkResult result = vkCreateDebugReportCallbackEXT(GPUDeviceVulkan::Instance, &createInfo, nullptr, &MsgCallback); @@ -354,14 +344,14 @@ DeferredDeletionQueueVulkan::~DeferredDeletionQueueVulkan() ASSERT(_entries.IsEmpty()); } -void DeferredDeletionQueueVulkan::ReleaseResources(bool deleteImmediately) +void DeferredDeletionQueueVulkan::ReleaseResources(bool immediately) { const uint64 checkFrame = Engine::FrameCount - VULKAN_RESOURCE_DELETE_SAFE_FRAMES_COUNT; ScopeLock lock(_locker); for (int32 i = 0; i < _entries.Count(); i++) { Entry* e = &_entries.Get()[i]; - if (deleteImmediately || (checkFrame > e->FrameNumber && (e->CmdBuffer == nullptr || e->FenceCounter < e->CmdBuffer->GetFenceSignaledCounter()))) + if (immediately || (checkFrame > e->FrameNumber && (e->CmdBuffer == nullptr || e->FenceCounter < e->CmdBuffer->GetFenceSignaledCounter()))) { if (e->AllocationHandle == VK_NULL_HANDLE) { @@ -2077,7 +2067,6 @@ GPUConstantBuffer* GPUDeviceVulkan::CreateConstantBuffer(uint32 size, const Stri SemaphoreVulkan::SemaphoreVulkan(GPUDeviceVulkan* device) : _device(device) { - // Create semaphore VkSemaphoreCreateInfo info; RenderToolsVulkan::ZeroStruct(info, VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO); VALIDATE_VULKAN_RESULT(vkCreateSemaphore(device->Device, &info, nullptr, &_semaphoreHandle)); @@ -2090,21 +2079,6 @@ SemaphoreVulkan::~SemaphoreVulkan() _semaphoreHandle = VK_NULL_HANDLE; } -FenceVulkan::~FenceVulkan() -{ - ASSERT(_handle == VK_NULL_HANDLE); -} - -FenceVulkan::FenceVulkan(GPUDeviceVulkan* device, FenceManagerVulkan* owner, bool createSignaled) - : _signaled(createSignaled) - , _owner(owner) -{ - VkFenceCreateInfo info; - RenderToolsVulkan::ZeroStruct(info, VK_STRUCTURE_TYPE_FENCE_CREATE_INFO); - info.flags = createSignaled ? VK_FENCE_CREATE_SIGNALED_BIT : 0; - VALIDATE_VULKAN_RESULT(vkCreateFence(device->Device, &info, nullptr, &_handle)); -} - FenceManagerVulkan::~FenceManagerVulkan() { ASSERT(_usedFences.IsEmpty()); @@ -2113,68 +2087,63 @@ FenceManagerVulkan::~FenceManagerVulkan() void FenceManagerVulkan::Dispose() { ScopeLock lock(_device->_fenceLock); - ASSERT(_usedFences.IsEmpty()); for (FenceVulkan* fence : _freeFences) - { DestroyFence(fence); - } _freeFences.Clear(); } FenceVulkan* FenceManagerVulkan::AllocateFence(bool createSignaled) { ScopeLock lock(_device->_fenceLock); - FenceVulkan* fence; if (_freeFences.HasItems()) { fence = _freeFences.Last(); _freeFences.RemoveLast(); _usedFences.Add(fence); - if (createSignaled) - { - fence->_signaled = true; - } - - return fence; + fence->IsSignaled = true; + } + else + { + fence = New(); + fence->IsSignaled = createSignaled; + VkFenceCreateInfo info; + RenderToolsVulkan::ZeroStruct(info, VK_STRUCTURE_TYPE_FENCE_CREATE_INFO); + info.flags = createSignaled ? VK_FENCE_CREATE_SIGNALED_BIT : 0; + VALIDATE_VULKAN_RESULT(vkCreateFence(_device->Device, &info, nullptr, &fence->Handle)); + _usedFences.Add(fence); } - - fence = New(_device, this, createSignaled); - _usedFences.Add(fence); return fence; } -bool FenceManagerVulkan::WaitForFence(FenceVulkan* fence, uint64 timeInNanoseconds) +bool FenceManagerVulkan::WaitForFence(FenceVulkan* fence, uint64 timeInNanoseconds) const { ASSERT(_usedFences.Contains(fence)); - ASSERT(!fence->_signaled); - - const VkResult result = vkWaitForFences(_device->Device, 1, &fence->_handle, true, timeInNanoseconds); + ASSERT(!fence->IsSignaled); + const VkResult result = vkWaitForFences(_device->Device, 1, &fence->Handle, true, timeInNanoseconds); LOG_VULKAN_RESULT(result); if (result == VK_SUCCESS) { - fence->_signaled = true; + fence->IsSignaled = true; return false; } - return true; } -void FenceManagerVulkan::ResetFence(FenceVulkan* fence) +void FenceManagerVulkan::ResetFence(FenceVulkan* fence) const { - if (fence->_signaled) + if (fence->IsSignaled) { - VALIDATE_VULKAN_RESULT(vkResetFences(_device->Device, 1, &fence->_handle)); - fence->_signaled = false; + VALIDATE_VULKAN_RESULT(vkResetFences(_device->Device, 1, &fence->Handle)); + fence->IsSignaled = false; } } void FenceManagerVulkan::ReleaseFence(FenceVulkan*& fence) { ScopeLock lock(_device->_fenceLock); - ResetFence(fence); _usedFences.Remove(fence); _freeFences.Add(fence); @@ -2184,37 +2153,31 @@ void FenceManagerVulkan::ReleaseFence(FenceVulkan*& fence) void FenceManagerVulkan::WaitAndReleaseFence(FenceVulkan*& fence, uint64 timeInNanoseconds) { ScopeLock lock(_device->_fenceLock); - - if (!fence->IsSignaled()) - { + if (!fence->IsSignaled) WaitForFence(fence, timeInNanoseconds); - } - ResetFence(fence); _usedFences.Remove(fence); _freeFences.Add(fence); fence = nullptr; } -bool FenceManagerVulkan::CheckFenceState(FenceVulkan* fence) +bool FenceManagerVulkan::CheckFenceState(FenceVulkan* fence) const { ASSERT(_usedFences.Contains(fence)); - ASSERT(!fence->_signaled); - - const VkResult result = vkGetFenceStatus(_device->Device, fence->GetHandle()); + ASSERT(!fence->IsSignaled); + const VkResult result = vkGetFenceStatus(_device->Device, fence->Handle); if (result == VK_SUCCESS) { - fence->_signaled = true; + fence->IsSignaled = true; return true; } - return false; } -void FenceManagerVulkan::DestroyFence(FenceVulkan* fence) +void FenceManagerVulkan::DestroyFence(FenceVulkan* fence) const { - vkDestroyFence(_device->Device, fence->GetHandle(), nullptr); - fence->_handle = VK_NULL_HANDLE; + vkDestroyFence(_device->Device, fence->Handle, nullptr); + fence->Handle = VK_NULL_HANDLE; Delete(fence); } diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h index 3daefa1f3..c3664b438 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h @@ -18,7 +18,6 @@ class GPUAdapterVulkan; class GPUSwapChainVulkan; class CmdBufferVulkan; class QueueVulkan; -class FenceVulkan; class GPUTextureVulkan; class GPUBufferVulkan; class GPUTimerQueryVulkan; @@ -31,12 +30,10 @@ class DescriptorPoolsManagerVulkan; class SemaphoreVulkan { private: - GPUDeviceVulkan* _device; VkSemaphore _semaphoreHandle; public: - /// /// Initializes a new instance of the class. /// @@ -58,59 +55,23 @@ public: } }; -class FenceVulkan +struct FenceVulkan { - friend FenceManagerVulkan; - -private: - VkFence _handle; - bool _signaled; - FenceManagerVulkan* _owner; - -public: - FenceVulkan(GPUDeviceVulkan* device, FenceManagerVulkan* owner, bool createSignaled); - ~FenceVulkan(); - -public: - inline VkFence GetHandle() const - { - return _handle; - } - - inline bool IsSignaled() const - { - return _signaled; - } - - FenceManagerVulkan* GetOwner() const - { - return _owner; - } + VkFence Handle; + bool IsSignaled; }; class FenceManagerVulkan { private: - - GPUDeviceVulkan* _device; + GPUDeviceVulkan* _device = nullptr; Array _freeFences; Array _usedFences; public: - - FenceManagerVulkan() - : _device(nullptr) - { - } - ~FenceManagerVulkan(); public: - - /// - /// Initializes the specified device. - /// - /// The graphics device. void Init(GPUDeviceVulkan* device) { _device = device; @@ -120,20 +81,15 @@ public: FenceVulkan* AllocateFence(bool createSignaled = false); - inline bool IsFenceSignaled(FenceVulkan* fence) + FORCE_INLINE bool IsFenceSignaled(FenceVulkan* fence) const { - if (fence->IsSignaled()) - { - return true; - } - - return CheckFenceState(fence); + return fence->IsSignaled || CheckFenceState(fence); } // Returns true if waiting timed out or failed, false otherwise. - bool WaitForFence(FenceVulkan* fence, uint64 timeInNanoseconds); + bool WaitForFence(FenceVulkan* fence, uint64 timeInNanoseconds) const; - void ResetFence(FenceVulkan* fence); + void ResetFence(FenceVulkan* fence) const; // Sets the fence handle to null void ReleaseFence(FenceVulkan*& fence); @@ -142,17 +98,15 @@ public: void WaitAndReleaseFence(FenceVulkan*& fence, uint64 timeInNanoseconds); private: - // Returns true if fence was signaled, otherwise false. - bool CheckFenceState(FenceVulkan* fence); + bool CheckFenceState(FenceVulkan* fence) const; - void DestroyFence(FenceVulkan* fence); + void DestroyFence(FenceVulkan* fence) const; }; class DeferredDeletionQueueVulkan { public: - enum Type { RenderPass, @@ -172,7 +126,6 @@ public: }; private: - struct Entry { uint64 FenceCounter; @@ -188,7 +141,6 @@ private: Array _entries; public: - /// /// Initializes a new instance of the class. /// @@ -201,7 +153,6 @@ public: ~DeferredDeletionQueueVulkan(); public: - template inline void EnqueueResource(Type type, T handle) { @@ -216,17 +167,15 @@ public: EnqueueGenericResource(type, (uint64)handle, allocation); } - void ReleaseResources(bool deleteImmediately = false); + void ReleaseResources(bool immediately = false); private: - void EnqueueGenericResource(Type type, uint64 handle, VmaAllocation allocation); }; class RenderTargetLayoutVulkan { public: - int32 RTsCount; MSAALevel MSAA; bool ReadDepth; @@ -238,7 +187,6 @@ public: uint32 Layers; public: - bool operator==(const RenderTargetLayoutVulkan& other) const { return Platform::MemoryCompare(this, &other, sizeof(RenderTargetLayoutVulkan)) == 0; @@ -250,7 +198,6 @@ uint32 GetHash(const RenderTargetLayoutVulkan& key); class FramebufferVulkan { public: - struct Key { RenderPassVulkan* RenderPass; @@ -258,7 +205,6 @@ public: VkImageView Attachments[GPU_MAX_RT_BINDED + 1]; public: - bool operator==(const Key& other) const { return Platform::MemoryCompare(this, &other, sizeof(Key)) == 0; @@ -266,23 +212,19 @@ public: }; private: - GPUDeviceVulkan* _device; VkFramebuffer _handle; public: - FramebufferVulkan(GPUDeviceVulkan* device, Key& key, VkExtent2D& extent, uint32 layers); ~FramebufferVulkan(); public: - VkImageView Attachments[GPU_MAX_RT_BINDED + 1]; VkExtent2D Extent; uint32 Layers; public: - inline VkFramebuffer GetHandle() { return _handle; @@ -296,21 +238,17 @@ uint32 GetHash(const FramebufferVulkan::Key& key); class RenderPassVulkan { private: - GPUDeviceVulkan* _device; VkRenderPass _handle; public: - RenderTargetLayoutVulkan Layout; public: - RenderPassVulkan(GPUDeviceVulkan* device, const RenderTargetLayoutVulkan& layout); ~RenderPassVulkan(); public: - inline VkRenderPass GetHandle() const { return _handle; @@ -320,7 +258,6 @@ public: class QueryPoolVulkan { protected: - struct Range { uint32 Start; @@ -338,12 +275,10 @@ protected: #endif public: - QueryPoolVulkan(GPUDeviceVulkan* device, int32 capacity, VkQueryType type); ~QueryPoolVulkan(); public: - inline VkQueryPool GetHandle() const { return _handle; @@ -357,7 +292,6 @@ public: class BufferedQueryPoolVulkan : public QueryPoolVulkan { private: - Array _queryOutput; Array _usedQueryBits; Array _startedQueryBits; @@ -367,7 +301,6 @@ private: int32 _lastBeginIndex; public: - BufferedQueryPoolVulkan(GPUDeviceVulkan* device, int32 capacity, VkQueryType type); bool AcquireQuery(uint32& resultIndex); void ReleaseQuery(uint32 queryIndex); @@ -382,7 +315,6 @@ public: class HelperResourcesVulkan { private: - GPUDeviceVulkan* _device; GPUTextureVulkan* _dummyTextures[6]; GPUBufferVulkan* _dummyBuffer; @@ -390,11 +322,9 @@ private: VkSampler _staticSamplers[GPU_STATIC_SAMPLERS_COUNT]; public: - HelperResourcesVulkan(GPUDeviceVulkan* device); public: - VkSampler* GetStaticSamplers(); GPUTextureVulkan* GetDummyTexture(SpirvShaderResourceType type); GPUBufferVulkan* GetDummyBuffer(); @@ -408,7 +338,6 @@ public: class StagingManagerVulkan { private: - struct PendingEntry { GPUBuffer* Buffer; @@ -435,7 +364,6 @@ private: #endif public: - StagingManagerVulkan(GPUDeviceVulkan* device); GPUBuffer* AcquireBuffer(uint32 size, GPUResourceUsage usage); void ReleaseBuffer(CmdBufferVulkan* cmdBuffer, GPUBuffer*& buffer); @@ -453,7 +381,6 @@ class GPUDeviceVulkan : public GPUDevice friend FenceManagerVulkan; private: - CriticalSection _fenceLock; mutable void* _nativePtr[2]; @@ -463,7 +390,6 @@ private: // TODO: use mutex to protect those collections BUT use 2 pools per cache: one lock-free with lookup only and second protected with mutex synced on frame end! public: - static GPUDevice* Create(); /// @@ -479,7 +405,6 @@ public: ~GPUDeviceVulkan(); public: - struct OptionalVulkanDeviceExtensions { uint32 HasKHRMaintenance1 : 1; @@ -497,7 +422,6 @@ public: static OptionalVulkanDeviceExtensions OptionalDeviceExtensions; public: - /// /// The Vulkan instance. /// @@ -514,7 +438,6 @@ public: static Array InstanceLayers; public: - /// /// The main Vulkan commands context. /// @@ -652,7 +575,6 @@ public: void OnImageViewDestroy(VkImageView imageView); public: - /// /// Setups the present queue to be ready for the given window surface. /// @@ -667,7 +589,7 @@ public: /// If set to true the optimal tiling should be used, otherwise use linear tiling. /// The output format. PixelFormat GetClosestSupportedPixelFormat(PixelFormat format, GPUTextureFlags flags, bool optimalTiling); - + /// /// Saves the pipeline cache. /// @@ -683,11 +605,9 @@ public: #endif private: - bool IsVkFormatSupported(VkFormat vkFormat, VkFormatFeatureFlags wantedFeatureFlags, bool optimalTiling) const; public: - // [GPUDevice] GPUContext* GetMainContext() override; GPUAdapter* GetAdapter() const override; @@ -713,7 +633,6 @@ template class GPUResourceVulkan : public GPUResourceBase { public: - /// /// Initializes a new instance of the class. /// @@ -731,7 +650,6 @@ public: class DescriptorOwnerResourceVulkan { public: - /// /// Finalizes an instance of the class. /// @@ -740,7 +658,6 @@ public: } public: - /// /// Gets the sampler descriptor. /// diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp index c5c1970e0..e2568ce95 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp @@ -73,7 +73,7 @@ ComputePipelineStateVulkan* GPUShaderProgramCSVulkan::GetOrCreateState() _pipelineState = New(_device, pipeline, layout); _pipelineState->DescriptorInfo = &DescriptorInfo; _pipelineState->DescriptorSetsLayout = &layout->GetDescriptorSetLayout(); - _pipelineState->DescriptorSetHandles.AddZeroed(_pipelineState->DescriptorSetsLayout->GetHandles().Count()); + _pipelineState->DescriptorSetHandles.AddZeroed(_pipelineState->DescriptorSetsLayout->Handles.Count()); uint32 dynamicOffsetsCount = 0; if (DescriptorInfo.DescriptorTypesCount != 0) { @@ -136,9 +136,7 @@ PipelineLayoutVulkan* GPUPipelineStateVulkan::GetLayout() #define INIT_SHADER_STAGE(set, bit) \ if (DescriptorInfoPerStage[DescriptorSet::set]) \ - { \ - descriptorSetLayoutInfo.AddBindingsForStage(bit, DescriptorSet::set, DescriptorInfoPerStage[DescriptorSet::set]); \ - } + descriptorSetLayoutInfo.AddBindingsForStage(bit, DescriptorSet::set, DescriptorInfoPerStage[DescriptorSet::set]) INIT_SHADER_STAGE(Vertex, VK_SHADER_STAGE_VERTEX_BIT); INIT_SHADER_STAGE(Hull, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); INIT_SHADER_STAGE(Domain, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT); @@ -149,7 +147,7 @@ PipelineLayoutVulkan* GPUPipelineStateVulkan::GetLayout() _layout = _device->GetOrCreateLayout(descriptorSetLayoutInfo); ASSERT(_layout); DescriptorSetsLayout = &_layout->GetDescriptorSetLayout(); - DescriptorSetHandles.AddZeroed(DescriptorSetsLayout->GetHandles().Count()); + DescriptorSetHandles.AddZeroed(DescriptorSetsLayout->Handles.Count()); return _layout; } diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h index 0557d3d1c..392375224 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h @@ -14,28 +14,15 @@ class PipelineLayoutVulkan; class ComputePipelineStateVulkan { private: - GPUDeviceVulkan* _device; VkPipeline _handle; PipelineLayoutVulkan* _layout; public: - - /// - /// Initializes a new instance of the class. - /// - /// The graphics device. - /// The pipeline object. - /// The pipeline layout. ComputePipelineStateVulkan(GPUDeviceVulkan* device, VkPipeline pipeline, PipelineLayoutVulkan* layout); - - /// - /// Finalizes an instance of the class. - /// ~ComputePipelineStateVulkan(); public: - /// /// The cached shader descriptor infos for compute shader. /// @@ -71,7 +58,6 @@ public: Array DynamicOffsets; public: - void Bind(CmdBufferVulkan* cmdBuffer) { vkCmdBindDescriptorSets( @@ -86,7 +72,6 @@ public: } public: - VkPipeline GetHandle() const { return _handle; @@ -104,7 +89,6 @@ public: class GPUPipelineStateVulkan : public GPUResourceVulkan { private: - Dictionary _pipelines; VkGraphicsPipelineCreateInfo _desc; VkPipelineShaderStageCreateInfo _shaderStages[ShaderStage_Count - 1]; @@ -121,7 +105,6 @@ private: PipelineLayoutVulkan* _layout; public: - /// /// Initializes a new instance of the class. /// @@ -129,7 +112,6 @@ public: GPUPipelineStateVulkan(GPUDeviceVulkan* device); public: - /// /// The bitmask of stages that exist in this pipeline. /// @@ -187,7 +169,6 @@ public: Array DynamicOffsets; public: - void Bind(CmdBufferVulkan* cmdBuffer) { vkCmdBindDescriptorSets( @@ -215,13 +196,11 @@ public: VkPipeline GetState(RenderPassVulkan* renderPass); public: - // [GPUPipelineState] bool IsValid() const final override; bool Init(const Description& desc) final override; protected: - // [GPUResourceVulkan] void OnReleaseGPU() override; }; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUSamplerVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUSamplerVulkan.h index 89375d481..b30a54126 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUSamplerVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUSamplerVulkan.h @@ -13,7 +13,6 @@ class GPUSamplerVulkan : public GPUResourceVulkan { public: - GPUSamplerVulkan(GPUDeviceVulkan* device) : GPUResourceVulkan(device, StringView::Empty) { @@ -22,7 +21,6 @@ public: VkSampler Sampler = VK_NULL_HANDLE; protected: - // [GPUSamplerVulkan] bool OnInit() override; void OnReleaseGPU() override; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUShaderProgramVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUShaderProgramVulkan.h index faee4a64f..c630328e7 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUShaderProgramVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUShaderProgramVulkan.h @@ -18,11 +18,9 @@ template class GPUShaderProgramVulkan : public BaseType { protected: - GPUDeviceVulkan* _device; public: - /// /// Initializes a new instance of the class. /// @@ -50,7 +48,6 @@ public: } public: - /// /// The Vulkan shader module. /// @@ -62,7 +59,6 @@ public: SpirvShaderDescriptorInfo DescriptorInfo; public: - // [BaseType] uint32 GetBufferSize() const override { @@ -81,7 +77,6 @@ public: class GPUShaderProgramVSVulkan : public GPUShaderProgramVulkan { public: - /// /// Initializes a new instance of the class. /// @@ -95,13 +90,11 @@ public: } public: - VkPipelineVertexInputStateCreateInfo VertexInputState; VkVertexInputBindingDescription VertexBindingDescriptions[VERTEX_SHADER_MAX_INPUT_ELEMENTS]; VkVertexInputAttributeDescription VertexAttributeDescriptions[VERTEX_SHADER_MAX_INPUT_ELEMENTS]; public: - // [GPUShaderProgramVulkan] void* GetInputLayout() const override { @@ -120,7 +113,6 @@ public: class GPUShaderProgramHSVulkan : public GPUShaderProgramVulkan { public: - /// /// Initializes a new instance of the class. /// @@ -142,7 +134,6 @@ public: class GPUShaderProgramDSVulkan : public GPUShaderProgramVulkan { public: - /// /// Initializes a new instance of the class. /// @@ -162,7 +153,6 @@ public: class GPUShaderProgramGSVulkan : public GPUShaderProgramVulkan { public: - /// /// Initializes a new instance of the class. /// @@ -182,7 +172,6 @@ public: class GPUShaderProgramPSVulkan : public GPUShaderProgramVulkan { public: - /// /// Initializes a new instance of the class. /// @@ -202,11 +191,9 @@ public: class GPUShaderProgramCSVulkan : public GPUShaderProgramVulkan { private: - ComputePipelineStateVulkan* _pipelineState; public: - /// /// Initializes a new instance of the class. /// @@ -226,7 +213,6 @@ public: ~GPUShaderProgramCSVulkan(); public: - /// /// Gets the state of the pipeline for the compute shader execution or creates a new one if missing. /// diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.h index ebb5da204..4ff467984 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.h @@ -17,7 +17,6 @@ class UniformBufferUploaderVulkan : public GPUResourceVulkan, public ResourceOwnerVulkan { public: - struct Allocation { /// @@ -42,7 +41,6 @@ public: }; private: - VkBuffer _buffer; VmaAllocation _allocation; uint64 _size; @@ -53,7 +51,6 @@ private: uint64 _fenceCounter; public: - /// /// Initializes a new instance of the class. /// @@ -61,11 +58,9 @@ public: UniformBufferUploaderVulkan(GPUDeviceVulkan* device); public: - Allocation Allocate(uint64 size, uint32 alignment, GPUContextVulkan* context); public: - // [GPUResourceVulkan] GPUResourceType GetResourceType() const final override { @@ -79,7 +74,6 @@ public: } protected: - // [GPUResourceVulkan] void OnReleaseGPU() override; }; @@ -90,7 +84,6 @@ protected: class GPUConstantBufferVulkan : public GPUResourceVulkan, public DescriptorOwnerResourceVulkan { public: - /// /// Initializes a new instance of the class. /// @@ -103,14 +96,12 @@ public: } public: - /// /// The last uploaded data inside the shared uniforms uploading ring buffer. /// UniformBufferUploaderVulkan::Allocation Allocation; public: - // [DescriptorOwnerResourceVulkan] void DescriptorAsDynamicUniformBuffer(GPUContextVulkan* context, VkBuffer& buffer, VkDeviceSize& offset, VkDeviceSize& range, uint32& dynamicOffset) override { @@ -127,7 +118,6 @@ public: class GPUShaderVulkan : public GPUResourceVulkan { public: - /// /// Initializes a new instance of the class. /// @@ -139,7 +129,6 @@ public: } protected: - // [GPUShader] GPUShaderProgram* CreateGPUShaderProgram(ShaderStage type, const GPUShaderProgramInitializer& initializer, byte* cacheBytes, uint32 cacheSize, MemoryReadStream& stream) override; }; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.h index 0dd9528e1..2e20326bb 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.h @@ -14,7 +14,6 @@ class BackBufferVulkan : public ResourceOwnerVulkan { public: - /// /// The device. /// @@ -36,12 +35,10 @@ public: GPUTextureViewVulkan Handle; public: - void Setup(GPUSwapChainVulkan* window, VkImage backbuffer, PixelFormat format, VkExtent3D extent); void Release(); public: - // [ResourceOwnerVulkan] GPUResource* AsGPUResource() const override { @@ -58,7 +55,6 @@ class GPUSwapChainVulkan : public GPUResourceVulkan, public Resour friend GPUDeviceVulkan; private: - VkSurfaceKHR _surface; VkSwapchainKHR _swapChain; int32 _currentImageIndex; @@ -68,11 +64,9 @@ private: SemaphoreVulkan* _acquiredSemaphore; public: - GPUSwapChainVulkan(GPUDeviceVulkan* device, Window* window); public: - /// /// Gets the Vulkan surface. /// @@ -92,7 +86,6 @@ public: } public: - enum class Status { Ok = 0, @@ -108,12 +101,10 @@ public: int32 AcquireNextImage(SemaphoreVulkan** outSemaphore); private: - void ReleaseBackBuffer(); bool CreateSwapChain(int32 width, int32 height); public: - // [GPUSwapChain] bool IsFullscreen() override; void SetFullscreen(bool isFullscreen) override; @@ -129,7 +120,6 @@ public: } protected: - // [GPUResourceVulkan] void OnReleaseGPU() override; }; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.h index ec64eaac4..6180e08f0 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.h @@ -15,7 +15,6 @@ class GPUTextureViewVulkan : public GPUTextureView, public DescriptorOwnerResourceVulkan { public: - GPUTextureViewVulkan() { } @@ -44,7 +43,6 @@ public: #endif public: - GPUDeviceVulkan* Device = nullptr; ResourceOwnerVulkan* Owner = nullptr; VkImage Image = VK_NULL_HANDLE; @@ -58,7 +56,6 @@ public: VkImageLayout LayoutSRV; public: - void Init(GPUDeviceVulkan* device, ResourceOwnerVulkan* owner, VkImage image, int32 totalMipLevels, PixelFormat format, MSAALevel msaa, VkExtent3D extent, VkImageViewType viewType, int32 mipLevels = 1, int32 firstMipIndex = 0, int32 arraySize = 1, int32 firstArraySlice = 0, bool readOnlyDepth = false); VkImageView GetFramebufferView(); @@ -66,7 +63,6 @@ public: void Release(); public: - // [GPUResourceView] void* GetNativePtr() const override { @@ -84,7 +80,6 @@ public: class GPUTextureVulkan : public GPUResourceVulkan, public ResourceOwnerVulkan, public DescriptorOwnerResourceVulkan { private: - VkImage _image = VK_NULL_HANDLE; VmaAllocation _allocation = VK_NULL_HANDLE; GPUTextureViewVulkan _handleArray; @@ -95,7 +90,6 @@ private: Array> _handlesPerMip; // [slice][mip] public: - /// /// Initializes a new instance of the class. /// @@ -107,7 +101,6 @@ public: } public: - /// /// Gets the Vulkan image handle. /// @@ -127,11 +120,9 @@ public: VkImageAspectFlags DefaultAspectMask; private: - void initHandles(); public: - // [GPUTexture] GPUTextureView* View(int32 arrayOrDepthIndex) const override { @@ -178,7 +169,6 @@ public: void DescriptorAsStorageImage(GPUContextVulkan* context, VkImageView& imageView, VkImageLayout& layout) override; protected: - // [GPUTexture] bool OnInit() override; void OnResidentMipsChanged() override; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUTimerQueryVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUTimerQueryVulkan.h index ddf461b13..da9b45ceb 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUTimerQueryVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUTimerQueryVulkan.h @@ -13,7 +13,6 @@ class GPUTimerQueryVulkan : public GPUResourceVulkan { private: - struct Query { BufferedQueryPoolVulkan* Pool; @@ -35,7 +34,6 @@ private: Array> _queries; public: - /// /// Initializes a new instance of the class. /// @@ -43,7 +41,6 @@ public: GPUTimerQueryVulkan(GPUDeviceVulkan* device); public: - /// /// Interrupts an in-progress query, allowing the command buffer to submitted. Interrupted queries must be resumed using Resume(). /// @@ -57,14 +54,12 @@ public: void Resume(CmdBufferVulkan* cmdBuffer); private: - bool GetResult(Query& query); void WriteTimestamp(CmdBufferVulkan* cmdBuffer, Query& query, VkPipelineStageFlagBits stage) const; bool TryGetResult(); bool UseQueries(); public: - // [GPUTimerQuery] void Begin() override; void End() override; @@ -72,7 +67,6 @@ public: float GetResult() override; protected: - // [GPUResourceVulkan] void OnReleaseGPU() override; }; diff --git a/Source/Engine/GraphicsDevice/Vulkan/QueueVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/QueueVulkan.cpp index e77ad9d46..ce36a901a 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/QueueVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/QueueVulkan.cpp @@ -14,17 +14,16 @@ QueueVulkan::QueueVulkan(GPUDeviceVulkan* device, uint32 familyIndex) , _device(device) , _lastSubmittedCmdBuffer(nullptr) , _lastSubmittedCmdBufferFenceCounter(0) - , _submitCounter(0) { vkGetDeviceQueue(device->Device, familyIndex, 0, &_queue); } -void QueueVulkan::Submit(CmdBufferVulkan* cmdBuffer, uint32 numSignalSemaphores, VkSemaphore* signalSemaphores) +void QueueVulkan::Submit(CmdBufferVulkan* cmdBuffer, uint32 signalSemaphoresCount, const VkSemaphore* signalSemaphores) { ASSERT(cmdBuffer->HasEnded()); auto fence = cmdBuffer->GetFence(); - ASSERT(!fence->IsSignaled()); + ASSERT(!fence->IsSignaled); const VkCommandBuffer cmdBuffers[] = { cmdBuffer->GetHandle() }; @@ -32,7 +31,7 @@ void QueueVulkan::Submit(CmdBufferVulkan* cmdBuffer, uint32 numSignalSemaphores, RenderToolsVulkan::ZeroStruct(submitInfo, VK_STRUCTURE_TYPE_SUBMIT_INFO); submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = cmdBuffers; - submitInfo.signalSemaphoreCount = numSignalSemaphores; + submitInfo.signalSemaphoreCount = signalSemaphoresCount; submitInfo.pSignalSemaphores = signalSemaphores; Array> waitSemaphores; @@ -48,7 +47,7 @@ void QueueVulkan::Submit(CmdBufferVulkan* cmdBuffer, uint32 numSignalSemaphores, submitInfo.pWaitDstStageMask = cmdBuffer->_waitFlags.Get(); } - VALIDATE_VULKAN_RESULT(vkQueueSubmit(_queue, 1, &submitInfo, fence->GetHandle())); + VALIDATE_VULKAN_RESULT(vkQueueSubmit(_queue, 1, &submitInfo, fence->Handle)); // Mark semaphores as submitted cmdBuffer->_state = CmdBufferVulkan::State::Submitted; @@ -78,21 +77,16 @@ void QueueVulkan::Submit(CmdBufferVulkan* cmdBuffer, uint32 numSignalSemaphores, void QueueVulkan::GetLastSubmittedInfo(CmdBufferVulkan*& cmdBuffer, uint64& fenceCounter) const { _locker.Lock(); - cmdBuffer = _lastSubmittedCmdBuffer; fenceCounter = _lastSubmittedCmdBufferFenceCounter; - _locker.Unlock(); } void QueueVulkan::UpdateLastSubmittedCommandBuffer(CmdBufferVulkan* cmdBuffer) { _locker.Lock(); - _lastSubmittedCmdBuffer = cmdBuffer; _lastSubmittedCmdBufferFenceCounter = cmdBuffer->GetFenceSignaledCounter(); - _submitCounter++; - _locker.Unlock(); } diff --git a/Source/Engine/GraphicsDevice/Vulkan/QueueVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/QueueVulkan.h index 37d9e6a68..81fbefd9e 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/QueueVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/QueueVulkan.h @@ -17,7 +17,6 @@ class CmdBufferVulkan; class QueueVulkan { private: - VkQueue _queue; uint32 _familyIndex; uint32 _queueIndex; @@ -25,10 +24,8 @@ private: CriticalSection _locker; CmdBufferVulkan* _lastSubmittedCmdBuffer; uint64 _lastSubmittedCmdBufferFenceCounter; - uint64 _submitCounter; public: - QueueVulkan(GPUDeviceVulkan* device, uint32 familyIndex); inline uint32 GetFamilyIndex() const @@ -36,7 +33,7 @@ public: return _familyIndex; } - void Submit(CmdBufferVulkan* cmdBuffer, uint32 numSignalSemaphores = 0, VkSemaphore* signalSemaphores = nullptr); + void Submit(CmdBufferVulkan* cmdBuffer, uint32 signalSemaphoresCount = 0, const VkSemaphore* signalSemaphores = nullptr); inline void Submit(CmdBufferVulkan* cmdBuffer, VkSemaphore signalSemaphore) { @@ -50,13 +47,7 @@ public: void GetLastSubmittedInfo(CmdBufferVulkan*& cmdBuffer, uint64& fenceCounter) const; - inline uint64 GetSubmitCount() const - { - return _submitCounter; - } - private: - void UpdateLastSubmittedCommandBuffer(CmdBufferVulkan* cmdBuffer); }; diff --git a/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp index f9c9237f6..be801869b 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp @@ -6,6 +6,8 @@ #include "Engine/Core/Types/StringBuilder.h" #include "Engine/Core/Log.h" +// @formatter:off + VkFormat RenderToolsVulkan::PixelFormatToVkFormat[108] = { VK_FORMAT_UNDEFINED, @@ -163,6 +165,8 @@ VkCompareOp RenderToolsVulkan::ComparisonFuncToVkCompareOp[9] = VK_COMPARE_OP_ALWAYS, // Always }; +// @formatter:on + #define VKERR(x) case x: sb.Append(TEXT(#x)); break #if GPU_ENABLE_RESOURCE_NAMING diff --git a/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.h index 835ae883c..2f7eb88ee 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.h @@ -34,14 +34,12 @@ class RenderToolsVulkan { private: - static VkFormat PixelFormatToVkFormat[static_cast(PixelFormat::MAX)]; static VkBlendFactor BlendToVkBlendFactor[static_cast(BlendingMode::Blend::MAX)]; static VkBlendOp OperationToVkBlendOp[static_cast(BlendingMode::Operation::MAX)]; static VkCompareOp ComparisonFuncToVkCompareOp[static_cast(ComparisonFunc::MAX)]; public: - #if GPU_ENABLE_RESOURCE_NAMING static void SetObjectName(VkDevice device, uint64 objectHandle, VkObjectType objectType, const String& name); static void SetObjectName(VkDevice device, uint64 objectHandle, VkObjectType objectType, const char* name); @@ -80,13 +78,13 @@ public: stageFlags = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; break; #if VK_KHR_maintenance2 - case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT: - case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT: - stageFlags = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; - break; + case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT: + case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT: + stageFlags = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; + break; #endif default: - CRASH; + CRASH; break; } return stageFlags; @@ -130,17 +128,17 @@ public: stageFlags = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; break; #if VK_KHR_maintenance2 - case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL_KHR: - accessFlags = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; - stageFlags = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; - break; + case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL_KHR: + accessFlags = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + stageFlags = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; + break; #endif case VK_IMAGE_LAYOUT_GENERAL: accessFlags = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; stageFlags = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; break; default: - CRASH; + CRASH; break; } return stageFlags; @@ -213,7 +211,7 @@ public: result = VK_SAMPLER_MIPMAP_MODE_LINEAR; break; default: - CRASH; + CRASH; break; } return result; @@ -237,7 +235,7 @@ public: result = VK_FILTER_LINEAR; break; default: - CRASH; + CRASH; break; } return result; @@ -261,7 +259,7 @@ public: result = VK_FILTER_LINEAR; break; default: - CRASH; + CRASH; break; } return result; @@ -285,7 +283,7 @@ public: result = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; break; default: - CRASH; + CRASH; break; } return result; @@ -303,7 +301,7 @@ public: result = VK_COMPARE_OP_NEVER; break; default: - CRASH; + CRASH; break; } return result; diff --git a/Source/Engine/GraphicsDevice/Vulkan/ResourceOwnerVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/ResourceOwnerVulkan.h index 3fc0f2c9c..9047a5ada 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/ResourceOwnerVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/ResourceOwnerVulkan.h @@ -30,13 +30,11 @@ class ResourceOwnerVulkan friend GPUContextVulkan; public: - virtual ~ResourceOwnerVulkan() { } public: - /// /// The resource state tracking helper. Used for resource barriers. /// @@ -48,7 +46,6 @@ public: int32 ArraySlices; public: - /// /// Gets resource owner object as a GPUResource type or returns null if cannot perform cast. /// @@ -56,7 +53,6 @@ public: virtual GPUResource* AsGPUResource() const = 0; protected: - void initResource(VkImageLayout initialState, int32 mipLevels = 1, int32 arraySize = 1, bool usePerSubresourceTracking = false) { State.Initialize(mipLevels * arraySize, initialState, usePerSubresourceTracking); diff --git a/Source/Engine/GraphicsDevice/Vulkan/VulkanPlatformBase.h b/Source/Engine/GraphicsDevice/Vulkan/VulkanPlatformBase.h index 5519b7a2f..abdcf29ec 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/VulkanPlatformBase.h +++ b/Source/Engine/GraphicsDevice/Vulkan/VulkanPlatformBase.h @@ -23,7 +23,6 @@ enum class VulkanValidationLevel class VulkanPlatformBase { public: - static void GetInstanceExtensions(Array& extensions, Array& layers) { }