Vulkan: fix block-compressed texture upload#11
Open
Monstrofil wants to merge 1 commit into
Open
Conversation
MappedTexture::Map and Unmap sized the staging buffer and ImagePlane
pitch with (width * height * BytesPerPixel). For block-compressed
formats (DXT/BC) the mapping table sets BytesPerPixel = 0, so the
multiplication produced a 0-byte staging buffer and Map() also bailed
out at the BytesPerPixel == 0 gate. Net effect: every BC upload was
silently dropped, the VkImage stayed at VK_IMAGE_LAYOUT_UNDEFINED,
and the bitmap sampled as black.
Add VkUploadPitch / VkUploadLevelSize helpers that branch on the
mapping's BytesPerPixel:
- BytesPerPixel != 0 (uncompressed): keep the original
width * BytesPerPixel math. This is the *destination* (Vulkan)
bytes per pixel, which matters when a format conversion happens
in the scanline copy -- e.g. Image_R8G8B8 maps to
VK_FORMAT_R8G8B8A8_UNORM via Image_CopyScanline24_Extend_RGB_RGBA,
so the staging buffer holds 4 bpp even though the source is 3 bpp.
Switching this site to ImageData::GetFormatPitch (which returns
*source* pitch) undersizes the staging buffer for these
expanding-conversion formats and the scanline copy runs off the
end -- crash on embedded JPEG decode.
- BytesPerPixel == 0 (compressed): fall back to
ImageData::GetMipLevelSize / GetFormatPitch, which already do the
correct 4x4 block math for BC/ATC and don't need any conversion
(BC scanlines are copied verbatim).
Replace the BytesPerPixel == 0 early-exit in Map() with a
totalSize == 0 guard so BC formats now pass through.
D3D11 doesn't have this issue because it uses USAGE_STAGING textures
and trusts D3D11_MAPPED_TEXTURE2D::RowPitch from the driver; Vulkan
uses staging *buffers* + vkCmdCopyBufferToImage where buffer layout
is the application's responsibility.
Reproducer: load any DXT5 .dds via flash.display.Loader.load on the
Vulkan backend (e.g. WoWP loading.swf's logoLogIn_*.dds backgrounds).
Pre-fix: black background. Post-fix: image renders. Verified: SWFs
with embedded 24-bit JPEGs (e.g. login.swf) still load without
regression.
0956c49 to
027d963
Compare
Author
|
Updated the patch after a regression: my first version replaced The amended commit branches on the mapping's
Verified: WoWP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MappedTexture::Map/Unmapsized the staging buffer andImagePlanepitch withwidth * height * BytesPerPixel. The format mapping table listsBytesPerPixel = 0for DXT/BC formats, so the multiplication gave a 0-byte staging buffer andMap()also bailed at theBytesPerPixel == 0gate. Every BC-format upload was silently dropped -- theVkImagestayed atVK_IMAGE_LAYOUT_UNDEFINEDand sampled as black.Vulkan_Texture.cpptoImageData::GetMipLevelSize/GetFormatPitch, which already do the right block math for BC/ATC and pixel math for everything else. Replace theBytesPerPixel == 0early-exit with atotalSize == 0guard.USAGE_STAGINGtextures and trustsD3D11_MAPPED_TEXTURE2D::RowPitchfrom the driver. Vulkan uses staging buffers +vkCmdCopyBufferToImage, where buffer layout is the application's responsibility.Reproducer
Load any DXT5 .dds via
flash.display.Loader.loadon the Vulkan backend (e.g. WoWPloading.swf'sgui/flash/login/backgrounds/logoLogIn_*.dds). Pre-fix: black background. Post-fix: image renders.Test plan
loading.swfbackground DDS now renders correctly under the Vulkan backend.