Merges UID from different Vulkan device objects and unifies single type descriptor set creation.
Differential Revision: https://code.wildfiregames.com/D5140 This was SVN commit r27879.
This commit is contained in:
parent
5283ae98f2
commit
6ef27d2ffe
@ -212,23 +212,21 @@ size_t CDescriptorManager::SingleTypeCacheKeyHash::operator()(const SingleTypeCa
|
|||||||
{
|
{
|
||||||
size_t seed = 0;
|
size_t seed = 0;
|
||||||
hash_combine(seed, key.first);
|
hash_combine(seed, key.first);
|
||||||
for (CTexture::UID uid : key.second)
|
for (DeviceObjectUID uid : key.second)
|
||||||
hash_combine(seed, uid);
|
hash_combine(seed, uid);
|
||||||
return seed;
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkDescriptorSet CDescriptorManager::GetSingleTypeDescritorSet(
|
VkDescriptorSet CDescriptorManager::GetSingleTypeDescritorSetImpl(
|
||||||
VkDescriptorType type, VkDescriptorSetLayout layout,
|
VkDescriptorType type, VkDescriptorSetLayout layout,
|
||||||
const std::vector<CTexture::UID>& texturesUID,
|
const std::vector<DeviceObjectUID>& uids)
|
||||||
const std::vector<CTexture*>& textures)
|
|
||||||
{
|
{
|
||||||
ENSURE(texturesUID.size() == textures.size());
|
ENSURE(!uids.empty());
|
||||||
ENSURE(!texturesUID.empty());
|
const SingleTypeCacheKey key{layout, uids};
|
||||||
const SingleTypeCacheKey key{layout, texturesUID};
|
|
||||||
auto it = m_SingleTypeSets.find(key);
|
auto it = m_SingleTypeSets.find(key);
|
||||||
if (it == m_SingleTypeSets.end())
|
if (it == m_SingleTypeSets.end())
|
||||||
{
|
{
|
||||||
SingleTypePool& pool = GetSingleTypePool(type, texturesUID.size());
|
SingleTypePool& pool = GetSingleTypePool(type, uids.size());
|
||||||
const int16_t elementIndex = pool.firstFreeIndex;
|
const int16_t elementIndex = pool.firstFreeIndex;
|
||||||
ENSURE(elementIndex != SingleTypePool::INVALID_INDEX);
|
ENSURE(elementIndex != SingleTypePool::INVALID_INDEX);
|
||||||
SingleTypePool::Element& element = pool.elements[elementIndex];
|
SingleTypePool::Element& element = pool.elements[elementIndex];
|
||||||
@ -252,43 +250,58 @@ VkDescriptorSet CDescriptorManager::GetSingleTypeDescritorSet(
|
|||||||
|
|
||||||
it = m_SingleTypeSets.emplace(key, element.set).first;
|
it = m_SingleTypeSets.emplace(key, element.set).first;
|
||||||
|
|
||||||
for (const CTexture::UID uid : texturesUID)
|
for (const DeviceObjectUID uid : uids)
|
||||||
if (uid != CTexture::INVALID_UID)
|
if (uid != INVALID_DEVICE_OBJECT_UID)
|
||||||
m_TextureSingleTypePoolMap[uid].push_back({type, element.version, elementIndex, static_cast<uint8_t>(texturesUID.size())});
|
m_UIDToSingleTypePoolMap[uid].push_back({type, element.version, elementIndex, static_cast<uint8_t>(uids.size())});
|
||||||
|
|
||||||
PS::StaticVector<VkDescriptorImageInfo, 16> infos;
|
|
||||||
for (CTexture* texture : textures)
|
|
||||||
{
|
|
||||||
if (!texture)
|
|
||||||
{
|
|
||||||
// We can use a default texture only for read-only bindings.
|
|
||||||
ENSURE(type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER || type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
|
|
||||||
texture = m_ErrorTexture->As<CTexture>();
|
|
||||||
}
|
|
||||||
ENSURE(texture->GetUsage() & ITexture::Usage::SAMPLED);
|
|
||||||
|
|
||||||
VkDescriptorImageInfo descriptorImageInfo{};
|
|
||||||
descriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
||||||
descriptorImageInfo.imageView = texture->GetSamplerImageView();
|
|
||||||
descriptorImageInfo.sampler = texture->GetSampler();
|
|
||||||
infos.emplace_back(std::move(descriptorImageInfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
VkWriteDescriptorSet writeDescriptorSet{};
|
|
||||||
writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
|
||||||
writeDescriptorSet.dstSet = element.set;
|
|
||||||
writeDescriptorSet.dstBinding = 0;
|
|
||||||
writeDescriptorSet.dstArrayElement = 0;
|
|
||||||
writeDescriptorSet.descriptorType = type;
|
|
||||||
writeDescriptorSet.descriptorCount = static_cast<uint32_t>(infos.size());
|
|
||||||
writeDescriptorSet.pImageInfo = infos.data();
|
|
||||||
|
|
||||||
vkUpdateDescriptorSets(
|
|
||||||
m_Device->GetVkDevice(), 1, &writeDescriptorSet, 0, nullptr);
|
|
||||||
}
|
}
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkDescriptorSet CDescriptorManager::GetSingleTypeDescritorSet(
|
||||||
|
VkDescriptorType type, VkDescriptorSetLayout layout,
|
||||||
|
const std::vector<DeviceObjectUID>& texturesUID,
|
||||||
|
const std::vector<CTexture*>& textures)
|
||||||
|
{
|
||||||
|
ENSURE(texturesUID.size() == textures.size());
|
||||||
|
ENSURE(!texturesUID.empty());
|
||||||
|
VkDescriptorSet set = GetSingleTypeDescritorSetImpl(type, layout, texturesUID);
|
||||||
|
|
||||||
|
const VkImageLayout imageLayout = type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
|
||||||
|
? VK_IMAGE_LAYOUT_GENERAL
|
||||||
|
: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
PS::StaticVector<VkDescriptorImageInfo, 16> infos;
|
||||||
|
for (CTexture* texture : textures)
|
||||||
|
{
|
||||||
|
if (!texture)
|
||||||
|
{
|
||||||
|
// We can use a default texture only for read-only bindings.
|
||||||
|
ENSURE(type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER || type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
|
||||||
|
texture = m_ErrorTexture->As<CTexture>();
|
||||||
|
}
|
||||||
|
ENSURE(texture->GetUsage() & ITexture::Usage::SAMPLED);
|
||||||
|
|
||||||
|
VkDescriptorImageInfo descriptorImageInfo{};
|
||||||
|
descriptorImageInfo.imageLayout = imageLayout;
|
||||||
|
descriptorImageInfo.imageView = texture->GetSamplerImageView();
|
||||||
|
descriptorImageInfo.sampler = texture->GetSampler();
|
||||||
|
infos.emplace_back(std::move(descriptorImageInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
VkWriteDescriptorSet writeDescriptorSet{};
|
||||||
|
writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||||
|
writeDescriptorSet.dstSet = set;
|
||||||
|
writeDescriptorSet.dstBinding = 0;
|
||||||
|
writeDescriptorSet.dstArrayElement = 0;
|
||||||
|
writeDescriptorSet.descriptorType = type;
|
||||||
|
writeDescriptorSet.descriptorCount = static_cast<uint32_t>(infos.size());
|
||||||
|
writeDescriptorSet.pImageInfo = infos.data();
|
||||||
|
|
||||||
|
vkUpdateDescriptorSets(
|
||||||
|
m_Device->GetVkDevice(), 1, &writeDescriptorSet, 0, nullptr);
|
||||||
|
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t CDescriptorManager::GetUniformSet() const
|
uint32_t CDescriptorManager::GetUniformSet() const
|
||||||
{
|
{
|
||||||
return m_UseDescriptorIndexing ? 1 : 0;
|
return m_UseDescriptorIndexing ? 1 : 0;
|
||||||
@ -341,9 +354,9 @@ uint32_t CDescriptorManager::GetTextureDescriptor(CTexture* texture)
|
|||||||
return descriptorSetIndex;
|
return descriptorSetIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDescriptorManager::OnTextureDestroy(const CTexture::UID uid)
|
void CDescriptorManager::OnTextureDestroy(const DeviceObjectUID uid)
|
||||||
{
|
{
|
||||||
ENSURE(uid != CTexture::INVALID_UID);
|
ENSURE(uid != INVALID_DEVICE_OBJECT_UID);
|
||||||
if (m_UseDescriptorIndexing)
|
if (m_UseDescriptorIndexing)
|
||||||
{
|
{
|
||||||
DescriptorIndexingBindingMap& bindingMap =
|
DescriptorIndexingBindingMap& bindingMap =
|
||||||
@ -360,8 +373,8 @@ void CDescriptorManager::OnTextureDestroy(const CTexture::UID uid)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto it = m_TextureSingleTypePoolMap.find(uid);
|
auto it = m_UIDToSingleTypePoolMap.find(uid);
|
||||||
if (it == m_TextureSingleTypePoolMap.end())
|
if (it == m_UIDToSingleTypePoolMap.end())
|
||||||
return;
|
return;
|
||||||
for (const auto& entry : it->second)
|
for (const auto& entry : it->second)
|
||||||
{
|
{
|
||||||
@ -376,7 +389,7 @@ void CDescriptorManager::OnTextureDestroy(const CTexture::UID uid)
|
|||||||
pool.firstFreeIndex = entry.elementIndex;
|
pool.firstFreeIndex = entry.elementIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_TextureSingleTypePoolMap.erase(it);
|
m_UIDToSingleTypePoolMap.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,13 +56,14 @@ public:
|
|||||||
|
|
||||||
VkDescriptorSet GetSingleTypeDescritorSet(
|
VkDescriptorSet GetSingleTypeDescritorSet(
|
||||||
VkDescriptorType type, VkDescriptorSetLayout layout,
|
VkDescriptorType type, VkDescriptorSetLayout layout,
|
||||||
const std::vector<CTexture::UID>& texturesUID,
|
const std::vector<DeviceObjectUID>& texturesUID,
|
||||||
const std::vector<CTexture*>& textures);
|
const std::vector<CTexture*>& textures);
|
||||||
|
|
||||||
uint32_t GetUniformSet() const;
|
uint32_t GetUniformSet() const;
|
||||||
|
|
||||||
uint32_t GetTextureDescriptor(CTexture* texture);
|
uint32_t GetTextureDescriptor(CTexture* texture);
|
||||||
void OnTextureDestroy(const CTexture::UID uid);
|
|
||||||
|
void OnTextureDestroy(const DeviceObjectUID uid);
|
||||||
|
|
||||||
const VkDescriptorSetLayout& GetDescriptorIndexingSetLayout() const { return m_DescriptorIndexingSetLayout; }
|
const VkDescriptorSetLayout& GetDescriptorIndexingSetLayout() const { return m_DescriptorIndexingSetLayout; }
|
||||||
const VkDescriptorSetLayout& GetUniformDescriptorSetLayout() const { return m_UniformDescriptorSetLayout; }
|
const VkDescriptorSetLayout& GetUniformDescriptorSetLayout() const { return m_UniformDescriptorSetLayout; }
|
||||||
@ -87,6 +88,10 @@ private:
|
|||||||
};
|
};
|
||||||
SingleTypePool& GetSingleTypePool(const VkDescriptorType type, const uint32_t size);
|
SingleTypePool& GetSingleTypePool(const VkDescriptorType type, const uint32_t size);
|
||||||
|
|
||||||
|
VkDescriptorSet GetSingleTypeDescritorSetImpl(
|
||||||
|
VkDescriptorType type, VkDescriptorSetLayout layout,
|
||||||
|
const std::vector<DeviceObjectUID>& uids);
|
||||||
|
|
||||||
CDevice* m_Device = nullptr;
|
CDevice* m_Device = nullptr;
|
||||||
|
|
||||||
bool m_UseDescriptorIndexing = false;
|
bool m_UseDescriptorIndexing = false;
|
||||||
@ -105,11 +110,11 @@ private:
|
|||||||
static_assert(std::numeric_limits<int16_t>::max() >= DESCRIPTOR_INDEXING_BINDING_SIZE);
|
static_assert(std::numeric_limits<int16_t>::max() >= DESCRIPTOR_INDEXING_BINDING_SIZE);
|
||||||
int16_t firstFreeIndex = 0;
|
int16_t firstFreeIndex = 0;
|
||||||
std::vector<int16_t> elements;
|
std::vector<int16_t> elements;
|
||||||
std::unordered_map<CTexture::UID, int16_t> map;
|
std::unordered_map<DeviceObjectUID, int16_t> map;
|
||||||
};
|
};
|
||||||
std::array<DescriptorIndexingBindingMap, NUMBER_OF_BINDINGS_PER_DESCRIPTOR_INDEXING_SET>
|
std::array<DescriptorIndexingBindingMap, NUMBER_OF_BINDINGS_PER_DESCRIPTOR_INDEXING_SET>
|
||||||
m_DescriptorIndexingBindings;
|
m_DescriptorIndexingBindings;
|
||||||
std::unordered_map<CTexture::UID, uint32_t> m_TextureToBindingMap;
|
std::unordered_map<DeviceObjectUID, uint32_t> m_TextureToBindingMap;
|
||||||
|
|
||||||
std::unordered_map<VkDescriptorType, std::vector<SingleTypePool>> m_SingleTypePools;
|
std::unordered_map<VkDescriptorType, std::vector<SingleTypePool>> m_SingleTypePools;
|
||||||
struct SingleTypePoolReference
|
struct SingleTypePoolReference
|
||||||
@ -119,9 +124,9 @@ private:
|
|||||||
int16_t elementIndex = SingleTypePool::INVALID_INDEX;
|
int16_t elementIndex = SingleTypePool::INVALID_INDEX;
|
||||||
uint8_t size = 0;
|
uint8_t size = 0;
|
||||||
};
|
};
|
||||||
std::unordered_map<CTexture::UID, std::vector<SingleTypePoolReference>> m_TextureSingleTypePoolMap;
|
std::unordered_map<DeviceObjectUID, std::vector<SingleTypePoolReference>> m_UIDToSingleTypePoolMap;
|
||||||
|
|
||||||
using SingleTypeCacheKey = std::pair<VkDescriptorSetLayout, std::vector<CTexture::UID>>;
|
using SingleTypeCacheKey = std::pair<VkDescriptorSetLayout, std::vector<DeviceObjectUID>>;
|
||||||
struct SingleTypeCacheKeyHash
|
struct SingleTypeCacheKeyHash
|
||||||
{
|
{
|
||||||
size_t operator()(const SingleTypeCacheKey& key) const;
|
size_t operator()(const SingleTypeCacheKey& key) const;
|
||||||
|
@ -911,7 +911,7 @@ void CDevice::ScheduleObjectToDestroy(
|
|||||||
m_ObjectToDestroyQueue.push({m_FrameID, type, handle, allocation});
|
m_ObjectToDestroyQueue.push({m_FrameID, type, handle, allocation});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDevice::ScheduleTextureToDestroy(const CTexture::UID uid)
|
void CDevice::ScheduleTextureToDestroy(const DeviceObjectUID uid)
|
||||||
{
|
{
|
||||||
m_TextureToDestroyQueue.push({m_FrameID, uid});
|
m_TextureToDestroyQueue.push({m_FrameID, uid});
|
||||||
}
|
}
|
||||||
@ -1029,6 +1029,12 @@ CTexture* CDevice::GetOrCreateBackbufferReadbackTexture()
|
|||||||
return m_BackbufferReadbackTexture.get();
|
return m_BackbufferReadbackTexture.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeviceObjectUID CDevice::GenerateNextDeviceObjectUID()
|
||||||
|
{
|
||||||
|
ENSURE(m_LastAvailableUID < std::numeric_limits<DeviceObjectUID>::max());
|
||||||
|
return m_LastAvailableUID++;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<IDevice> CreateDevice(SDL_Window* window)
|
std::unique_ptr<IDevice> CreateDevice(SDL_Window* window)
|
||||||
{
|
{
|
||||||
return Vulkan::CDevice::Create(window);
|
return Vulkan::CDevice::Create(window);
|
||||||
|
@ -140,7 +140,7 @@ public:
|
|||||||
void ScheduleObjectToDestroy(
|
void ScheduleObjectToDestroy(
|
||||||
VkObjectType type, const uint64_t handle, const VmaAllocation allocation);
|
VkObjectType type, const uint64_t handle, const VmaAllocation allocation);
|
||||||
|
|
||||||
void ScheduleTextureToDestroy(const CTexture::UID uid);
|
void ScheduleTextureToDestroy(const DeviceObjectUID uid);
|
||||||
|
|
||||||
void SetObjectName(VkObjectType type, const void* handle, const char* name)
|
void SetObjectName(VkObjectType type, const void* handle, const char* name)
|
||||||
{
|
{
|
||||||
@ -163,6 +163,8 @@ public:
|
|||||||
|
|
||||||
CTexture* GetOrCreateBackbufferReadbackTexture();
|
CTexture* GetOrCreateBackbufferReadbackTexture();
|
||||||
|
|
||||||
|
DeviceObjectUID GenerateNextDeviceObjectUID();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CDevice();
|
CDevice();
|
||||||
|
|
||||||
@ -210,12 +212,14 @@ private:
|
|||||||
VmaAllocation allocation;
|
VmaAllocation allocation;
|
||||||
};
|
};
|
||||||
std::queue<ObjectToDestroy> m_ObjectToDestroyQueue;
|
std::queue<ObjectToDestroy> m_ObjectToDestroyQueue;
|
||||||
std::queue<std::pair<uint32_t, CTexture::UID>> m_TextureToDestroyQueue;
|
std::queue<std::pair<uint32_t, DeviceObjectUID>> m_TextureToDestroyQueue;
|
||||||
|
|
||||||
std::unique_ptr<CRenderPassManager> m_RenderPassManager;
|
std::unique_ptr<CRenderPassManager> m_RenderPassManager;
|
||||||
std::unique_ptr<CSamplerManager> m_SamplerManager;
|
std::unique_ptr<CSamplerManager> m_SamplerManager;
|
||||||
std::unique_ptr<CDescriptorManager> m_DescriptorManager;
|
std::unique_ptr<CDescriptorManager> m_DescriptorManager;
|
||||||
std::unique_ptr<CSubmitScheduler> m_SubmitScheduler;
|
std::unique_ptr<CSubmitScheduler> m_SubmitScheduler;
|
||||||
|
|
||||||
|
DeviceObjectUID m_LastAvailableUID{1};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
49
source/renderer/backend/vulkan/DeviceObjectUID.h
Normal file
49
source/renderer/backend/vulkan/DeviceObjectUID.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* Copyright (C) 2023 Wildfire Games.
|
||||||
|
* This file is part of 0 A.D.
|
||||||
|
*
|
||||||
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 0 A.D. is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INCLUDED_RENDERER_BACKEND_VULKAN_UID
|
||||||
|
#define INCLUDED_RENDERER_BACKEND_VULKAN_UID
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace Renderer
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Backend
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Vulkan
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unique identifier for a device object. It must be unique along all objects
|
||||||
|
* during a whole application run. We assume that 32bits should be enough, else
|
||||||
|
* we'd have a too big object flow.
|
||||||
|
* TODO: maybe it makes sense to add it for all backends. Also it might make
|
||||||
|
* sense to add categories/types. Several high bits might be for describing an
|
||||||
|
* object type, low bits for indexing.
|
||||||
|
*/
|
||||||
|
using DeviceObjectUID = uint32_t;
|
||||||
|
static constexpr DeviceObjectUID INVALID_DEVICE_OBJECT_UID = 0;
|
||||||
|
|
||||||
|
} // namespace Vulkan
|
||||||
|
|
||||||
|
} // namespace Backend
|
||||||
|
|
||||||
|
} // namespace Renderer
|
||||||
|
|
||||||
|
#endif // INCLUDED_RENDERER_BACKEND_VULKAN_UID
|
@ -57,6 +57,7 @@ std::unique_ptr<CFramebuffer> CFramebuffer::Create(
|
|||||||
|
|
||||||
std::unique_ptr<CFramebuffer> framebuffer(new CFramebuffer());
|
std::unique_ptr<CFramebuffer> framebuffer(new CFramebuffer());
|
||||||
framebuffer->m_Device = device;
|
framebuffer->m_Device = device;
|
||||||
|
framebuffer->m_UID = device->GenerateNextDeviceObjectUID();
|
||||||
if (colorAttachment)
|
if (colorAttachment)
|
||||||
framebuffer->m_ClearColor = colorAttachment->clearColor;
|
framebuffer->m_ClearColor = colorAttachment->clearColor;
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "ps/containers/StaticVector.h"
|
#include "ps/containers/StaticVector.h"
|
||||||
#include "renderer/backend/IFramebuffer.h"
|
#include "renderer/backend/IFramebuffer.h"
|
||||||
|
#include "renderer/backend/vulkan/DeviceObjectUID.h"
|
||||||
|
|
||||||
#include <glad/vulkan.h>
|
#include <glad/vulkan.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -61,8 +62,7 @@ public:
|
|||||||
AttachmentLoadOp GetDepthStencilAttachmentLoadOp() const { return m_DepthStencilAttachmentLoadOp; }
|
AttachmentLoadOp GetDepthStencilAttachmentLoadOp() const { return m_DepthStencilAttachmentLoadOp; }
|
||||||
AttachmentStoreOp GetDepthStencilAttachmentStoreOp() const { return m_DepthStencilAttachmentStoreOp; }
|
AttachmentStoreOp GetDepthStencilAttachmentStoreOp() const { return m_DepthStencilAttachmentStoreOp; }
|
||||||
|
|
||||||
using UID = uint32_t;
|
DeviceObjectUID GetUID() const { return m_UID; }
|
||||||
UID GetUID() const { return m_UID; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CDevice;
|
friend class CDevice;
|
||||||
@ -72,15 +72,11 @@ private:
|
|||||||
CDevice* device, const char* name,
|
CDevice* device, const char* name,
|
||||||
SColorAttachment* colorAttachment, SDepthStencilAttachment* depthStencilAttachment);
|
SColorAttachment* colorAttachment, SDepthStencilAttachment* depthStencilAttachment);
|
||||||
|
|
||||||
CFramebuffer()
|
CFramebuffer() = default;
|
||||||
{
|
|
||||||
static uint32_t m_LastAvailableUID = 1;
|
|
||||||
m_UID = m_LastAvailableUID++;
|
|
||||||
}
|
|
||||||
|
|
||||||
CDevice* m_Device = nullptr;
|
CDevice* m_Device = nullptr;
|
||||||
|
|
||||||
UID m_UID = 0;
|
DeviceObjectUID m_UID{INVALID_DEVICE_OBJECT_UID};
|
||||||
|
|
||||||
CColor m_ClearColor{};
|
CColor m_ClearColor{};
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@ std::unique_ptr<CGraphicsPipelineState> CGraphicsPipelineState::Create(
|
|||||||
ENSURE(desc.shaderProgram);
|
ENSURE(desc.shaderProgram);
|
||||||
std::unique_ptr<CGraphicsPipelineState> pipelineState{new CGraphicsPipelineState()};
|
std::unique_ptr<CGraphicsPipelineState> pipelineState{new CGraphicsPipelineState()};
|
||||||
pipelineState->m_Device = device;
|
pipelineState->m_Device = device;
|
||||||
|
pipelineState->m_UID = device->GenerateNextDeviceObjectUID();
|
||||||
pipelineState->m_Desc = desc;
|
pipelineState->m_Desc = desc;
|
||||||
return pipelineState;
|
return pipelineState;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "renderer/backend/PipelineState.h"
|
#include "renderer/backend/PipelineState.h"
|
||||||
#include "renderer/backend/vulkan/Framebuffer.h"
|
#include "renderer/backend/vulkan/Framebuffer.h"
|
||||||
#include "renderer/backend/vulkan/ShaderProgram.h"
|
#include "renderer/backend/vulkan/ShaderProgram.h"
|
||||||
|
#include "renderer/backend/vulkan/DeviceObjectUID.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <glad/vulkan.h>
|
#include <glad/vulkan.h>
|
||||||
@ -53,8 +54,7 @@ public:
|
|||||||
VkPipeline GetOrCreatePipeline(
|
VkPipeline GetOrCreatePipeline(
|
||||||
const CVertexInputLayout* vertexInputLayout, CFramebuffer* framebuffer);
|
const CVertexInputLayout* vertexInputLayout, CFramebuffer* framebuffer);
|
||||||
|
|
||||||
using UID = uint32_t;
|
DeviceObjectUID GetUID() const { return m_UID; }
|
||||||
UID GetUID() const { return m_UID; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CDevice;
|
friend class CDevice;
|
||||||
@ -62,23 +62,19 @@ private:
|
|||||||
static std::unique_ptr<CGraphicsPipelineState> Create(
|
static std::unique_ptr<CGraphicsPipelineState> Create(
|
||||||
CDevice* device, const SGraphicsPipelineStateDesc& desc);
|
CDevice* device, const SGraphicsPipelineStateDesc& desc);
|
||||||
|
|
||||||
CGraphicsPipelineState()
|
CGraphicsPipelineState() = default;
|
||||||
{
|
|
||||||
static uint32_t m_LastAvailableUID = 1;
|
|
||||||
m_UID = m_LastAvailableUID++;
|
|
||||||
}
|
|
||||||
|
|
||||||
CDevice* m_Device = nullptr;
|
CDevice* m_Device = nullptr;
|
||||||
|
|
||||||
UID m_UID = 0;
|
DeviceObjectUID m_UID{INVALID_DEVICE_OBJECT_UID};
|
||||||
|
|
||||||
SGraphicsPipelineStateDesc m_Desc{};
|
SGraphicsPipelineStateDesc m_Desc{};
|
||||||
|
|
||||||
struct CacheKey
|
struct CacheKey
|
||||||
{
|
{
|
||||||
CVertexInputLayout::UID vertexInputLayoutUID;
|
DeviceObjectUID vertexInputLayoutUID;
|
||||||
// TODO: try to replace the UID by the only required parameters.
|
// TODO: try to replace the UID by the only required parameters.
|
||||||
CFramebuffer::UID framebufferUID;
|
DeviceObjectUID framebufferUID;
|
||||||
};
|
};
|
||||||
struct CacheKeyHash
|
struct CacheKeyHash
|
||||||
{
|
{
|
||||||
|
@ -552,7 +552,7 @@ void CShaderProgram::Unbind()
|
|||||||
{
|
{
|
||||||
for (CTexture*& texture : m_BoundTextures)
|
for (CTexture*& texture : m_BoundTextures)
|
||||||
texture = nullptr;
|
texture = nullptr;
|
||||||
for (CTexture::UID& uid : m_BoundTexturesUID)
|
for (DeviceObjectUID& uid : m_BoundTexturesUID)
|
||||||
uid = 0;
|
uid = 0;
|
||||||
m_BoundTexturesOutdated = true;
|
m_BoundTexturesOutdated = true;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ private:
|
|||||||
|
|
||||||
VkDescriptorSetLayout m_TexturesDescriptorSetLayout = VK_NULL_HANDLE;
|
VkDescriptorSetLayout m_TexturesDescriptorSetLayout = VK_NULL_HANDLE;
|
||||||
std::vector<CTexture*> m_BoundTextures;
|
std::vector<CTexture*> m_BoundTextures;
|
||||||
std::vector<CTexture::UID> m_BoundTexturesUID;
|
std::vector<DeviceObjectUID> m_BoundTexturesUID;
|
||||||
VkDescriptorSet m_ActiveTexturesDescriptorSet = VK_NULL_HANDLE;
|
VkDescriptorSet m_ActiveTexturesDescriptorSet = VK_NULL_HANDLE;
|
||||||
std::unordered_map<CStrIntern, uint32_t> m_TextureMapping;
|
std::unordered_map<CStrIntern, uint32_t> m_TextureMapping;
|
||||||
|
|
||||||
|
@ -40,8 +40,7 @@ std::unique_ptr<CTexture> CTexture::Create(
|
|||||||
const Sampler::Desc& defaultSamplerDesc,
|
const Sampler::Desc& defaultSamplerDesc,
|
||||||
const uint32_t MIPLevelCount, const uint32_t sampleCount)
|
const uint32_t MIPLevelCount, const uint32_t sampleCount)
|
||||||
{
|
{
|
||||||
std::unique_ptr<CTexture> texture(new CTexture());
|
std::unique_ptr<CTexture> texture(new CTexture(device));
|
||||||
texture->m_Device = device;
|
|
||||||
|
|
||||||
texture->m_Format = format;
|
texture->m_Format = format;
|
||||||
texture->m_Type = type;
|
texture->m_Type = type;
|
||||||
@ -225,8 +224,7 @@ std::unique_ptr<CTexture> CTexture::WrapBackbufferImage(
|
|||||||
CDevice* device, const char* name, const VkImage image, const VkFormat format,
|
CDevice* device, const char* name, const VkImage image, const VkFormat format,
|
||||||
const VkImageUsageFlags usage, const uint32_t width, const uint32_t height)
|
const VkImageUsageFlags usage, const uint32_t width, const uint32_t height)
|
||||||
{
|
{
|
||||||
std::unique_ptr<CTexture> texture(new CTexture());
|
std::unique_ptr<CTexture> texture(new CTexture(device));
|
||||||
texture->m_Device = device;
|
|
||||||
|
|
||||||
if (format == VK_FORMAT_R8G8B8A8_UNORM)
|
if (format == VK_FORMAT_R8G8B8A8_UNORM)
|
||||||
texture->m_Format = Format::R8G8B8A8_UNORM;
|
texture->m_Format = Format::R8G8B8A8_UNORM;
|
||||||
@ -279,8 +277,7 @@ std::unique_ptr<CTexture> CTexture::CreateReadback(
|
|||||||
CDevice* device, const char* name, const Format format,
|
CDevice* device, const char* name, const Format format,
|
||||||
const uint32_t width, const uint32_t height)
|
const uint32_t width, const uint32_t height)
|
||||||
{
|
{
|
||||||
std::unique_ptr<CTexture> texture(new CTexture());
|
std::unique_ptr<CTexture> texture(new CTexture(device));
|
||||||
texture->m_Device = device;
|
|
||||||
|
|
||||||
texture->m_Format = format;
|
texture->m_Format = format;
|
||||||
texture->m_Type = Type::TEXTURE_2D;
|
texture->m_Type = Type::TEXTURE_2D;
|
||||||
@ -338,10 +335,9 @@ std::unique_ptr<CTexture> CTexture::CreateReadback(
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTexture::CTexture()
|
CTexture::CTexture(CDevice* device)
|
||||||
|
: m_Device(device), m_UID(device->GenerateNextDeviceObjectUID())
|
||||||
{
|
{
|
||||||
static uint32_t m_LastAvailableUID = 1;
|
|
||||||
m_UID = m_LastAvailableUID++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CTexture::~CTexture()
|
CTexture::~CTexture()
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "renderer/backend/ITexture.h"
|
#include "renderer/backend/ITexture.h"
|
||||||
#include "renderer/backend/Sampler.h"
|
#include "renderer/backend/Sampler.h"
|
||||||
|
#include "renderer/backend/vulkan/DeviceObjectUID.h"
|
||||||
#include "renderer/backend/vulkan/VMA.h"
|
#include "renderer/backend/vulkan/VMA.h"
|
||||||
|
|
||||||
#include <glad/vulkan.h>
|
#include <glad/vulkan.h>
|
||||||
@ -73,20 +74,13 @@ public:
|
|||||||
bool IsInitialized() const { return m_Initialized; }
|
bool IsInitialized() const { return m_Initialized; }
|
||||||
void SetInitialized() { m_Initialized = true; }
|
void SetInitialized() { m_Initialized = true; }
|
||||||
|
|
||||||
/**
|
DeviceObjectUID GetUID() const { return m_UID; }
|
||||||
* @return UID of the texture. It's unique along all textures during a whole
|
|
||||||
* application run. We assume that 32bits should be enough, else we'd have
|
|
||||||
* a too big texture flow.
|
|
||||||
*/
|
|
||||||
using UID = uint32_t;
|
|
||||||
static constexpr UID INVALID_UID = 0;
|
|
||||||
UID GetUID() const { return m_UID; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CDevice;
|
friend class CDevice;
|
||||||
friend class CSwapChain;
|
friend class CSwapChain;
|
||||||
|
|
||||||
CTexture();
|
CTexture(CDevice* device);
|
||||||
|
|
||||||
static std::unique_ptr<CTexture> Create(
|
static std::unique_ptr<CTexture> Create(
|
||||||
CDevice* device, const char* name, const Type type, const uint32_t usage,
|
CDevice* device, const char* name, const Type type, const uint32_t usage,
|
||||||
@ -122,7 +116,7 @@ private:
|
|||||||
VmaAllocation m_Allocation{};
|
VmaAllocation m_Allocation{};
|
||||||
VmaAllocationInfo m_AllocationInfo{};
|
VmaAllocationInfo m_AllocationInfo{};
|
||||||
|
|
||||||
UID m_UID = 0;
|
DeviceObjectUID m_UID{INVALID_DEVICE_OBJECT_UID};
|
||||||
|
|
||||||
// Sampler image aspect mask is submask of the attachment one. As we can't
|
// Sampler image aspect mask is submask of the attachment one. As we can't
|
||||||
// have both VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT for
|
// have both VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT for
|
||||||
|
Loading…
Reference in New Issue
Block a user