From bdbb57ea1fc2f1e8ec3dc36d44bb067b43a0aab5 Mon Sep 17 00:00:00 2001 From: Alexander Gauggel <agauggel@uni-koblenz.de> Date: Fri, 18 Jun 2021 21:42:08 +0200 Subject: [PATCH] [#81] Avoid loading textures multiple times --- projects/voxelization/src/main.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/projects/voxelization/src/main.cpp b/projects/voxelization/src/main.cpp index 1899a3b1..684e7811 100644 --- a/projects/voxelization/src/main.cpp +++ b/projects/voxelization/src/main.cpp @@ -178,26 +178,25 @@ int main(int argc, const char** argv) { vkcv::SamplerAddressMode::REPEAT ); - // prepare per mesh descriptor sets - std::vector<vkcv::DescriptorSetHandle> perMeshDescriptorSets; + // create descriptor sets + std::vector<vkcv::DescriptorSetHandle> materialDescriptorSets; std::vector<vkcv::Image> sceneImages; - for (const auto& vertexGroup : scene.vertexGroups) { - perMeshDescriptorSets.push_back(core.createDescriptorSet(forwardProgram.getReflectedDescriptors()[1])); - - const auto& material = scene.materials[vertexGroup.materialIndex]; + for (const auto& material : scene.materials) { int baseColorIndex = material.baseColor; if (baseColorIndex < 0) { vkcv_log(vkcv::LogLevel::WARNING, "Material lacks base color"); baseColorIndex = 0; } + materialDescriptorSets.push_back(core.createDescriptorSet(forwardProgram.getReflectedDescriptors()[1])); + vkcv::asset::Texture& sceneTexture = scene.textures[baseColorIndex]; sceneImages.push_back(core.createImage(vk::Format::eR8G8B8A8Srgb, sceneTexture.w, sceneTexture.h, 1, true)); sceneImages.back().fill(sceneTexture.data.data()); sceneImages.back().generateMipChainImmediate(); - sceneImages.back().switchLayout(vk::ImageLayout::eShaderReadOnlyOptimal); + sceneImages.back().switchLayout(vk::ImageLayout::eShaderReadOnlyOptimal); vkcv::DescriptorWrites setWrites; setWrites.sampledImageWrites = { @@ -206,7 +205,12 @@ int main(int argc, const char** argv) { setWrites.samplerWrites = { vkcv::SamplerDescriptorWrite(1, colorSampler), }; - core.writeDescriptorSet(perMeshDescriptorSets.back(), setWrites); + core.writeDescriptorSet(materialDescriptorSets.back(), setWrites); + } + + std::vector<vkcv::DescriptorSetHandle> perMeshDescriptorSets; + for (const auto& vertexGroup : scene.vertexGroups) { + perMeshDescriptorSets.push_back(materialDescriptorSets[vertexGroup.materialIndex]); } const vkcv::PipelineConfig forwardPipelineConfig { -- GitLab