mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-23 04:27:45 +00:00
Use uint64 for storing descriptor hashes
This commit is contained in:
parent
42cab361e0
commit
b96b2a86c2
2 changed files with 18 additions and 6 deletions
|
@ -95,7 +95,7 @@ public:
|
||||||
|
|
||||||
VkDescriptorSetLayout setLayout = VK_NULL_HANDLE;
|
VkDescriptorSetLayout setLayout = VK_NULL_HANDLE;
|
||||||
|
|
||||||
std::map<int, VkDescriptorSet> cachedDescriptors;
|
std::map<uint64_t, VkDescriptorSet> cachedDescriptors;
|
||||||
|
|
||||||
VkPipeline pipeline;
|
VkPipeline pipeline;
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout;
|
||||||
|
@ -120,7 +120,7 @@ public:
|
||||||
|
|
||||||
VkDescriptorSet createDescriptorFor(const RenderModel& model, const RenderMaterial& material);
|
VkDescriptorSet createDescriptorFor(const RenderModel& model, const RenderMaterial& material);
|
||||||
|
|
||||||
int hash(const RenderModel& model, const RenderMaterial& material);
|
uint64_t hash(const RenderModel& model, const RenderMaterial& material);
|
||||||
|
|
||||||
glm::mat4 view;
|
glm::mat4 view;
|
||||||
|
|
||||||
|
|
|
@ -491,12 +491,20 @@ void Renderer::render(std::vector<RenderModel> models) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for(const auto& part : model.parts) {
|
for(const auto& part : model.parts) {
|
||||||
|
if (part.materialIndex >= model.materials.size()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
RenderMaterial& material = model.materials[part.materialIndex];
|
RenderMaterial& material = model.materials[part.materialIndex];
|
||||||
|
|
||||||
int h = hash(model, material);
|
const auto h = hash(model, material);
|
||||||
if(!cachedDescriptors.count(h)) {
|
if(!cachedDescriptors.count(h)) {
|
||||||
fmt::print("Caching descriptor for hash {}\n", h);
|
fmt::print("Caching descriptor for hash {}\n", h);
|
||||||
cachedDescriptors[h] = createDescriptorFor(model, material);
|
if (auto descriptor = createDescriptorFor(model, material); descriptor != VK_NULL_HANDLE) {
|
||||||
|
cachedDescriptors[h] = descriptor;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &cachedDescriptors[h], 0, nullptr);
|
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &cachedDescriptors[h], 0, nullptr);
|
||||||
|
@ -1154,8 +1162,8 @@ void Renderer::inlineTransitionImageLayout(VkCommandBuffer commandBuffer, VkImag
|
||||||
nullptr, 0, nullptr, 1, &barrier);
|
nullptr, 0, nullptr, 1, &barrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Renderer::hash(const RenderModel& model, const RenderMaterial& material) {
|
uint64_t Renderer::hash(const RenderModel& model, const RenderMaterial& material) {
|
||||||
int hash = 0;
|
uint64_t hash = 0;
|
||||||
hash += reinterpret_cast<intptr_t>((void*)&model);
|
hash += reinterpret_cast<intptr_t>((void*)&model);
|
||||||
if (material.diffuseTexture)
|
if (material.diffuseTexture)
|
||||||
hash += reinterpret_cast<intptr_t>((void*)material.diffuseTexture);
|
hash += reinterpret_cast<intptr_t>((void*)material.diffuseTexture);
|
||||||
|
@ -1178,6 +1186,10 @@ VkDescriptorSet Renderer::createDescriptorFor(const RenderModel& model, const Re
|
||||||
allocateInfo.pSetLayouts = &setLayout;
|
allocateInfo.pSetLayouts = &setLayout;
|
||||||
|
|
||||||
vkAllocateDescriptorSets(device, &allocateInfo, &set);
|
vkAllocateDescriptorSets(device, &allocateInfo, &set);
|
||||||
|
if (set == VK_NULL_HANDLE) {
|
||||||
|
fmt::print("Failed to create descriptor set!");
|
||||||
|
return VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
const size_t bufferSize = sizeof(glm::mat4) * 128;
|
const size_t bufferSize = sizeof(glm::mat4) * 128;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue