Skip to content

Commit

Permalink
Fix upload and sampling bug for array textures in the vulkan backend
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Nov 14, 2021
1 parent f5c8953 commit 8c54015
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/common/rendering/vulkan/system/vk_builders.h
Expand Up @@ -449,7 +449,7 @@ inline std::unique_ptr<VulkanImage> ImageBuilder::create(VulkanDevice *device, V
*allocatedBytes = allocatedInfo.size;
}

return std::make_unique<VulkanImage>(device, image, allocation, imageInfo.extent.width, imageInfo.extent.height, imageInfo.mipLevels);
return std::make_unique<VulkanImage>(device, image, allocation, imageInfo.extent.width, imageInfo.extent.height, imageInfo.mipLevels, imageInfo.arrayLayers);
}

inline std::unique_ptr<VulkanImage> ImageBuilder::tryCreate(VulkanDevice *device)
Expand All @@ -461,7 +461,7 @@ inline std::unique_ptr<VulkanImage> ImageBuilder::tryCreate(VulkanDevice *device
if (result != VK_SUCCESS)
return nullptr;

return std::make_unique<VulkanImage>(device, image, allocation, imageInfo.extent.width, imageInfo.extent.height, imageInfo.mipLevels);
return std::make_unique<VulkanImage>(device, image, allocation, imageInfo.extent.width, imageInfo.extent.height, imageInfo.mipLevels, imageInfo.arrayLayers);
}

/////////////////////////////////////////////////////////////////////////////
Expand All @@ -487,6 +487,7 @@ inline void ImageViewBuilder::setImage(VulkanImage *image, VkFormat format, VkIm
viewInfo.format = format;
viewInfo.subresourceRange.levelCount = image->mipLevels;
viewInfo.subresourceRange.aspectMask = aspectMask;
viewInfo.subresourceRange.layerCount = image->layerCount;
}

inline std::unique_ptr<VulkanImageView> ImageViewBuilder::create(VulkanDevice *device)
Expand Down
4 changes: 2 additions & 2 deletions src/common/rendering/vulkan/system/vk_framebuffer.cpp
Expand Up @@ -635,7 +635,7 @@ void VulkanFrameBuffer::InitLightmap(FLevelLocals* Level)
stagingBuffer->Unmap();

VkImageTransition imageTransition;
imageTransition.addImage(&lightmap, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, true);
imageTransition.addImage(&lightmap, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, true, 0, count);
imageTransition.execute(cmdbuffer);

VkBufferImageCopy region = {};
Expand All @@ -647,7 +647,7 @@ void VulkanFrameBuffer::InitLightmap(FLevelLocals* Level)
cmdbuffer->copyBufferToImage(stagingBuffer->buffer, lightmap.Image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);

VkImageTransition barrier;
barrier.addImage(&lightmap, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, true);
barrier.addImage(&lightmap, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, false, 0, count);
barrier.execute(cmdbuffer);

FrameTextureUpload.Buffers.push_back(std::move(stagingBuffer));
Expand Down
5 changes: 3 additions & 2 deletions src/common/rendering/vulkan/system/vk_objects.h
Expand Up @@ -79,7 +79,7 @@ class VulkanFramebuffer
class VulkanImage
{
public:
VulkanImage(VulkanDevice *device, VkImage image, VmaAllocation allocation, int width, int height, int mipLevels);
VulkanImage(VulkanDevice *device, VkImage image, VmaAllocation allocation, int width, int height, int mipLevels, int layerCount);
~VulkanImage();

void SetDebugName(const char *name) { device->SetDebugObjectName(name, (uint64_t)image, VK_OBJECT_TYPE_IMAGE); }
Expand All @@ -88,6 +88,7 @@ class VulkanImage
int width = 0;
int height = 0;
int mipLevels = 1;
int layerCount = 1;

void *Map(size_t offset, size_t size);
void Unmap();
Expand Down Expand Up @@ -989,7 +990,7 @@ inline VulkanFramebuffer::~VulkanFramebuffer()

/////////////////////////////////////////////////////////////////////////////

inline VulkanImage::VulkanImage(VulkanDevice *device, VkImage image, VmaAllocation allocation, int width, int height, int mipLevels) : image(image), width(width), height(height), mipLevels(mipLevels), device(device), allocation(allocation)
inline VulkanImage::VulkanImage(VulkanDevice *device, VkImage image, VmaAllocation allocation, int width, int height, int mipLevels, int layerCount) : image(image), width(width), height(height), mipLevels(mipLevels), layerCount(layerCount), device(device), allocation(allocation)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/rendering/vulkan/textures/vk_imagetransition.cpp
Expand Up @@ -22,7 +22,7 @@

#include "vk_imagetransition.h"

void VkImageTransition::addImage(VkTextureImage *image, VkImageLayout targetLayout, bool undefinedSrcLayout)
void VkImageTransition::addImage(VkTextureImage *image, VkImageLayout targetLayout, bool undefinedSrcLayout, int baseMipLevel, int levelCount)
{
if (image->Layout == targetLayout)
return;
Expand Down Expand Up @@ -91,7 +91,7 @@ void VkImageTransition::addImage(VkTextureImage *image, VkImageLayout targetLayo
I_FatalError("Unimplemented dst image layout transition\n");
}

barrier.addImage(image->Image.get(), undefinedSrcLayout ? VK_IMAGE_LAYOUT_UNDEFINED : image->Layout, targetLayout, srcAccess, dstAccess, aspectMask);
barrier.addImage(image->Image.get(), undefinedSrcLayout ? VK_IMAGE_LAYOUT_UNDEFINED : image->Layout, targetLayout, srcAccess, dstAccess, aspectMask, baseMipLevel, levelCount);
needbarrier = true;
image->Layout = targetLayout;
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/rendering/vulkan/textures/vk_imagetransition.h
Expand Up @@ -33,7 +33,7 @@ class VkTextureImage
class VkImageTransition
{
public:
void addImage(VkTextureImage *image, VkImageLayout targetLayout, bool undefinedSrcLayout);
void addImage(VkTextureImage *image, VkImageLayout targetLayout, bool undefinedSrcLayout, int baseMipLevel = 0, int levelCount = 1);
void execute(VulkanCommandBuffer *cmdbuffer);

private:
Expand Down

0 comments on commit 8c54015

Please sign in to comment.