From b2771dd1115781be49dceef17abe341ffc169f3f Mon Sep 17 00:00:00 2001 From: niki Date: Mon, 15 Aug 2022 00:06:50 +0200 Subject: [PATCH] vulkan: fix cube textures --- src/modules/graphics/vulkan/Graphics.cpp | 2 +- src/modules/graphics/vulkan/Shader.cpp | 5 +++-- src/modules/graphics/vulkan/Texture.cpp | 21 +++++++++++++++++---- src/modules/graphics/vulkan/Vulkan.cpp | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index ce73fd059..f6444ddd3 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -304,7 +304,7 @@ void Graphics::initCapabilities() { capabilities.textureTypes[TEXTURE_2D] = true; capabilities.textureTypes[TEXTURE_2D_ARRAY] = true; capabilities.textureTypes[TEXTURE_VOLUME] = false; - capabilities.textureTypes[TEXTURE_CUBE] = false; + capabilities.textureTypes[TEXTURE_CUBE] = true; } void Graphics::getAPIStats(int& shaderswitches) const { diff --git a/src/modules/graphics/vulkan/Shader.cpp b/src/modules/graphics/vulkan/Shader.cpp index 7f9ccc4b6..270cfe2f4 100644 --- a/src/modules/graphics/vulkan/Shader.cpp +++ b/src/modules/graphics/vulkan/Shader.cpp @@ -254,7 +254,8 @@ void Shader::cmdPushDescriptorSets(VkCommandBuffer commandBuffer, uint32_t frame std::vector descriptorWrite{}; - // uniform buffer update always happens. + // uniform buffer update always happens + // (are there cases without ubos at all?) VkWriteDescriptorSet uniformWrite{}; uniformWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; uniformWrite.dstSet = 0; @@ -623,7 +624,7 @@ void Shader::createDescriptorSetLayout() { layoutBinding.binding = val.location; layoutBinding.descriptorType = val.baseType == UNIFORM_SAMPLER ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; layoutBinding.descriptorCount = 1; // is this correct? - layoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT; // fixme: can we determine in what shader it got used? + layoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_COMPUTE_BIT; // fixme: can we determine in what shader it got used? bindings.push_back(layoutBinding); } diff --git a/src/modules/graphics/vulkan/Texture.cpp b/src/modules/graphics/vulkan/Texture.cpp index eeea2aa48..a300b280f 100644 --- a/src/modules/graphics/vulkan/Texture.cpp +++ b/src/modules/graphics/vulkan/Texture.cpp @@ -32,16 +32,23 @@ bool Texture::loadVolatile() { VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + VkImageCreateFlags createFlags = 0; + layerCount = 1; - if (texType == TEXTURE_VOLUME) + if (texType == TEXTURE_VOLUME) { layerCount = getDepth(); - else if (texType == TEXTURE_2D_ARRAY) + } + else if (texType == TEXTURE_2D_ARRAY) { layerCount = getLayerCount(); - else if (texType == TEXTURE_CUBE) + } + else if (texType == TEXTURE_CUBE) { layerCount = 6; + createFlags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; + } VkImageCreateInfo imageInfo{}; imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + imageInfo.flags = createFlags; imageInfo.imageType = Vulkan::getImageType(getTextureType()); imageInfo.extent.width = static_cast(width); imageInfo.extent.height = static_cast(height); @@ -75,7 +82,13 @@ bool Texture::loadVolatile() { for (int mip = 0; mip < layerCount; mip++) { // fixme: deal with compressed images. - for (int slice = 0; slice < slices.getSliceCount(mip); slice++) { + int sliceCount; + if (texType == TEXTURE_CUBE) { + sliceCount = 6; + } else { + sliceCount = slices.getSliceCount(); + } + for (int slice = 0; slice < sliceCount; slice++) { auto* id = slices.get(slice, mip); if (id != nullptr) { uploadImageData(id, mip, slice, 0, 0); diff --git a/src/modules/graphics/vulkan/Vulkan.cpp b/src/modules/graphics/vulkan/Vulkan.cpp index ba5d137e7..ad6cd8937 100644 --- a/src/modules/graphics/vulkan/Vulkan.cpp +++ b/src/modules/graphics/vulkan/Vulkan.cpp @@ -459,9 +459,9 @@ VkImageType Vulkan::getImageType(TextureType textureType) { switch (textureType) { case TEXTURE_2D: case TEXTURE_2D_ARRAY: + case TEXTURE_CUBE: return VK_IMAGE_TYPE_2D; case TEXTURE_VOLUME: - case TEXTURE_CUBE: return VK_IMAGE_TYPE_3D; default: throw love::Exception("unknown texture type");