|
@@ -59,8 +59,8 @@ bool Texture::loadVolatile() {
|
|
|
|
|
|
auto commandBuffer = vgfx->getDataTransferCommandBuffer();
|
|
auto commandBuffer = vgfx->getDataTransferCommandBuffer();
|
|
|
|
|
|
- // fixme: we should use VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL as the default image layout instead of VK_IMAGE_LAYOUT_GENERAL.
|
|
|
|
- Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, 0, 1, 0, layerCount);
|
|
|
|
|
|
+ // fixme: we probably should select a different default layout when the texture is not readable, instead of VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
|
|
|
+ Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, 1, 0, layerCount);
|
|
|
|
|
|
if (data) {
|
|
if (data) {
|
|
for (int slice = 0; slice < layerCount; slice++) {
|
|
for (int slice = 0; slice < layerCount; slice++) {
|
|
@@ -139,7 +139,7 @@ void Texture::createTextureImageView() {
|
|
}
|
|
}
|
|
|
|
|
|
void Texture::clear(bool white) {
|
|
void Texture::clear(bool white) {
|
|
- auto commandBuffer = vgfx->beginSingleTimeCommands();
|
|
|
|
|
|
+ auto commandBuffer = vgfx->getDataTransferCommandBuffer();
|
|
|
|
|
|
auto clearColor = getClearValue(white);
|
|
auto clearColor = getClearValue(white);
|
|
|
|
|
|
@@ -148,9 +148,11 @@ void Texture::clear(bool white) {
|
|
range.layerCount = layerCount;
|
|
range.layerCount = layerCount;
|
|
range.levelCount = 1;
|
|
range.levelCount = 1;
|
|
|
|
|
|
- vkCmdClearColorImage(commandBuffer, textureImage, VK_IMAGE_LAYOUT_GENERAL, &clearColor, 1, &range);
|
|
|
|
|
|
+ Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, 1, 0, layerCount);
|
|
|
|
+
|
|
|
|
+ vkCmdClearColorImage(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColor, 1, &range);
|
|
|
|
|
|
- vgfx->endSingleTimeCommands(commandBuffer);
|
|
|
|
|
|
+ Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, 1, 0, layerCount);
|
|
}
|
|
}
|
|
|
|
|
|
VkClearColorValue Texture::getClearValue(bool white) {
|
|
VkClearColorValue Texture::getClearValue(bool white) {
|
|
@@ -240,7 +242,7 @@ void Texture::uploadByteData(PixelFormat pixelformat, const void* data, size_t s
|
|
|
|
|
|
auto commandBuffer = vgfx->getDataTransferCommandBuffer();
|
|
auto commandBuffer = vgfx->getDataTransferCommandBuffer();
|
|
|
|
|
|
- Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, level, 1, slice, 1);
|
|
|
|
|
|
+ Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, level, 1, slice, 1);
|
|
|
|
|
|
vkCmdCopyBufferToImage(
|
|
vkCmdCopyBufferToImage(
|
|
commandBuffer,
|
|
commandBuffer,
|
|
@@ -251,7 +253,7 @@ void Texture::uploadByteData(PixelFormat pixelformat, const void* data, size_t s
|
|
®ion
|
|
®ion
|
|
);
|
|
);
|
|
|
|
|
|
- Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, level, 1, slice, 1);
|
|
|
|
|
|
+ Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, level, 1, slice, 1);
|
|
|
|
|
|
vgfx->queueCleanUp([allocator = allocator, stagingBuffer, vmaAllocation]() {
|
|
vgfx->queueCleanUp([allocator = allocator, stagingBuffer, vmaAllocation]() {
|
|
vmaDestroyBuffer(allocator, stagingBuffer, vmaAllocation);
|
|
vmaDestroyBuffer(allocator, stagingBuffer, vmaAllocation);
|
|
@@ -275,11 +277,11 @@ void Texture::copyFromBuffer(graphics::Buffer* source, size_t sourceoffset, int
|
|
region.imageExtent.width = static_cast<uint32_t>(rect.w);
|
|
region.imageExtent.width = static_cast<uint32_t>(rect.w);
|
|
region.imageExtent.height = static_cast<uint32_t>(rect.h);
|
|
region.imageExtent.height = static_cast<uint32_t>(rect.h);
|
|
|
|
|
|
- Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
|
|
|
|
|
+ Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
|
|
|
|
|
vkCmdCopyBufferToImage(commandBuffer, (VkBuffer)source->getHandle(), textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
|
vkCmdCopyBufferToImage(commandBuffer, (VkBuffer)source->getHandle(), textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
|
|
|
|
|
- Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL);
|
|
|
|
|
|
+ Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
}
|
|
}
|
|
|
|
|
|
void Texture::copyToBuffer(graphics::Buffer* dest, int slice, int mipmap, const Rect& rect, size_t destoffset, int destwidth, size_t size) {
|
|
void Texture::copyToBuffer(graphics::Buffer* dest, int slice, int mipmap, const Rect& rect, size_t destoffset, int destwidth, size_t size) {
|
|
@@ -299,11 +301,11 @@ void Texture::copyToBuffer(graphics::Buffer* dest, int slice, int mipmap, const
|
|
region.imageExtent.width = static_cast<uint32_t>(rect.w);
|
|
region.imageExtent.width = static_cast<uint32_t>(rect.w);
|
|
region.imageExtent.height = static_cast<uint32_t>(rect.h);
|
|
region.imageExtent.height = static_cast<uint32_t>(rect.h);
|
|
|
|
|
|
- Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
|
|
|
|
|
+ Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
|
|
|
|
|
vkCmdCopyImageToBuffer(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, (VkBuffer) dest->getHandle(), 1, ®ion);
|
|
vkCmdCopyImageToBuffer(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, (VkBuffer) dest->getHandle(), 1, ®ion);
|
|
|
|
|
|
- Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL);
|
|
|
|
|
|
+ Vulkan::cmdTransitionImageLayout(commandBuffer, textureImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
}
|
|
}
|
|
|
|
|
|
} // vulkan
|
|
} // vulkan
|