Commit 7ea2d4a
committed
Handle GL_UNPACK_ROW_LENGTH == 0 in uploadSubTextureAsync
In GL, UNPACK_ROW_LENGTH defaults to 0, which means "rows are tightly
packed", i.e. the row stride equals the width of the transferred region.
VulkanImage took the 0 literally and used it as an actual stride.
With unpackRowLength == 0 the upload size collapsed to 0, so
StagingBuffer.copyBuffer staged nothing and left the staging offset
unchanged. The srcOffset handed to copyBufferToImageCmd therefore still
pointed at whatever previous upload occupied the shared staging buffer,
and bufferRowLength was passed as 0, which in Vulkan means "tightly
packed to imageExtent.width". The GPU then copied width * height *
formatSize bytes of stale staging memory into the target image, filling
the texture with unrelated data from earlier uploads.
VulkanMod's own callers never hit this because VkCommandEncoder issues
_pixelStore(3314, width) before each upload, so a nonzero row length is
always supplied. Mods that leave UNPACK_ROW_LENGTH at the GL default are
silently corrupted instead.
Normalize the row length to width when it is 0, and use the normalized
value for the source skip advance and as bufferRowLength. Passing
rowLength explicitly is valid since rowLength == width satisfies the
bufferRowLength == 0 || >= imageExtent.width rule.
Also correct the upload size. (rowLength * height - unpackSkipPixels)
mixed a row stride term with a pixel skip term, and because srcPtr has
already been advanced past the skip, it over-read the source by up to
unpackSkipRows * rowLength * formatSize bytes. The region actually read
spans rowLength * (height - 1) + width pixels.1 parent 7f69043 commit 7ea2d4a
1 file changed
Lines changed: 6 additions & 3 deletions
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
233 | 236 | | |
234 | 237 | | |
235 | 238 | | |
| |||
240 | 243 | | |
241 | 244 | | |
242 | 245 | | |
243 | | - | |
| 246 | + | |
244 | 247 | | |
245 | 248 | | |
246 | 249 | | |
| |||
255 | 258 | | |
256 | 259 | | |
257 | 260 | | |
258 | | - | |
| 261 | + | |
259 | 262 | | |
260 | 263 | | |
261 | 264 | | |
| |||
0 commit comments