X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fvulkan%2Ftexture_backend.cpp;h=db420991ee1ebf17861c8b26c6aa4666f49b93fd;hb=60f288b3a6b5753702ed2b2c035f29778ae0b7d0;hp=217299bf26d2ffe878572b03b2a57d752f757bf5;hpb=33253bf6d6a330181fda83ba23a6ac0a756d9a8d;p=libs%2Fgl.git diff --git a/source/backends/vulkan/texture_backend.cpp b/source/backends/vulkan/texture_backend.cpp index 217299bf..db420991 100644 --- a/source/backends/vulkan/texture_backend.cpp +++ b/source/backends/vulkan/texture_backend.cpp @@ -49,9 +49,13 @@ void VulkanTexture::allocate() const Texture &self = *static_cast(this); const VulkanFunctions &vk = device.get_functions(); + VkFormat vk_format = static_cast(get_vulkan_pixelformat(self.storage_fmt)); + VkFormatProperties props; + vk.GetPhysicalDeviceFormatProperties(vk_format, props); + VkImageCreateInfo image_info = { }; image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - image_info.format = static_cast(get_vulkan_pixelformat(self.storage_fmt)); + image_info.format = vk_format; image_info.extent.width = 1; image_info.extent.height = 1; image_info.extent.depth = 1; @@ -63,6 +67,7 @@ void VulkanTexture::allocate() image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; image_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT; + PixelComponents comp = get_components(self.storage_fmt); if(comp==DEPTH_COMPONENT || comp==STENCIL_INDEX) image_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; @@ -71,6 +76,9 @@ void VulkanTexture::allocate() fill_image_info(&image_info); + if((props.optimalTilingFeatures&VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) && image_info.samples==VK_SAMPLE_COUNT_1_BIT) + image_info.usage |= VK_IMAGE_USAGE_STORAGE_BIT; + /* SwapChainTexture may have already provided the image. Create_info is filled anyway because some of its fields are used for view_info. */ if(!handle) @@ -134,43 +142,6 @@ void VulkanTexture::create_mip_views() const } } -void VulkanTexture::stage_pixels(void *staging, const void *data, size_t count) -{ - const Texture &self = *static_cast(this); - - if(self.swizzle==RGBA_TO_RGB) - { - const uint32_t *src = static_cast(data); - uint32_t *dst = static_cast(staging); - size_t i = 0; - for(; i+3>24)|(src[1]<<8)|0xFF000000; - dst[2] = (src[1]>>16)|(src[2]<<16)|0xFF000000; - dst[3] = (src[2]>>8)|0xFF000000; - src += 3; - dst += 4; - } - - if(i(src); - for(; i(data); - size_t data_size = count*get_pixel_size(self.storage_fmt); - copy(src, src+data_size, static_cast(staging)); - } -} - void VulkanTexture::generate_mipmap() { unsigned n_levels = static_cast(this)->n_levels; @@ -183,11 +154,11 @@ void VulkanTexture::generate_mipmap() change_layout(i, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, false); change_layout(i+1, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, true); }, - [this, i](VkCommandBuffer cmd_buf, VkBuffer, size_t){ - const VulkanFunctions &vk = device.get_functions(); + [this, i](const VulkanCommandRecorder &vkCmd, VkBuffer, size_t){ + const Texture &self = *static_cast(this); VkImageBlit region = { }; - region.srcSubresource.aspectMask = get_vulkan_aspect(get_components(static_cast(this)->storage_fmt)); + region.srcSubresource.aspectMask = get_vulkan_aspect(get_components(self.storage_fmt)); region.srcSubresource.mipLevel = i; region.srcSubresource.baseArrayLayer = 0; region.srcSubresource.layerCount = 1; @@ -196,7 +167,7 @@ void VulkanTexture::generate_mipmap() fill_mipmap_blit(i, ®ion); - vk.CmdBlitImage(cmd_buf, handle, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + vkCmd.BlitImage(handle, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion, VK_FILTER_LINEAR); }); }