Browse Source

vulkan: fix cube textures

niki 3 years ago
parent
commit
b2771dd111

+ 1 - 1
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 {

+ 3 - 2
src/modules/graphics/vulkan/Shader.cpp

@@ -254,7 +254,8 @@ void Shader::cmdPushDescriptorSets(VkCommandBuffer commandBuffer, uint32_t frame
 	
 	std::vector<VkWriteDescriptorSet> 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);
 	}

+ 17 - 4
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<uint32_t>(width);
 	imageInfo.extent.height = static_cast<uint32_t>(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);

+ 1 - 1
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");