upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorQemmHD <stephenlethco2@gmail.com>2026-11-24 11:25:04 -0500
committerGitHub <noreply@github.com>2026-11-24 11:25:04 -0500
commitf5928c6b6bcedd4d5defe9a64cd58a0650a7d63d (patch)
tree490c806d6d7c78c30c9e32d38b2287fb150328b1 /runtime/src
parentfd635819cfa048e46c10046b35a0c212f2ad6f7a (diff)
parentcfb343636943adc40108c636951eadc95ef3490d (diff)
Merge pull request #434 from tahffo68hk-hash/fix/vk-tile-copy-align
Merging. **Why merged:** tile_footprint staging now follows the format's real alignment, block size and depth. Before, it assumed 2D RGBA8, which was wrong for 8- and 16-byte texels, BC formats and 3D. moffington showed 7 new asserts fail on the base, and Dezmonius passed it on Windows with an RTX 5070. **Why it's good:** replay_copy_offset, replay_texture_barrier and d3d12_texture_tiles all pass both plain and under validation. A possible follow-up, not a blocker: staging now triggers on offset % fmt.bytes, so an R8/R16 tile copy at an offset that isn't a multiple of 4 is no longer staged. On a transfer-only queue that would hit VUID-vkCmdCopyBufferToImage-commandBuffer-07737. main's non-tile path already behaves that way, and the old *4 staging was wrong for R8/R16 anyway; max(4, fmt.bytes) for colour formats would cover both. Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Alone on main, its tests passed both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #388, #418, #421, #434, #470, #484, #485, #486 and #488 merged onto main 1504c1af6 (a225e593e). There the repo-consistency set gives 566 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 306/308. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same skip set. git merge-tree against current main 98a977b4b: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/vulkan_replay.h55
1 files changed, 41 insertions, 14 deletions
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h
index 9f3d75c7d..d5a73b909 100644
--- a/runtime/src/vulkan_replay.h
+++ b/runtime/src/vulkan_replay.h
@@ -1879,27 +1879,48 @@ inline ReplayResult prepare_texture_copy(const CopyTexture& copy, Prepared& p) {
1879 return ReplayResult::success; 1879 return ReplayResult::success;
1880} 1880}
1881 1881
1882// RGBA8 CopyTiles accepts arbitrary byte offsets into its linear buffer, while VkBufferImageCopy requires texel 1882// CopyTiles accepts arbitrary byte offsets into its linear buffer, while VkBufferImageCopy requires texel/block
1883// alignment. Stage only the occupied texels through aligned transfer scratch; leave partial-tile padding alone. 1883// alignment (VUID-vkCmdCopyBufferToImage-dstImage-07975). Stage only the occupied texels/blocks through aligned
1884inline bool stage_unaligned_tile(const ReplayFunctions& vk, Prepared& p, bool upload) { 1884// transfer scratch; leave partial-tile padding alone.
1885inline bool stage_unaligned_tile(const ReplayFunctions& vk, Prepared& p, const ResourceBinding& image,
1886 const BlockFormat& fmt, bool upload) {
1885 auto& region = p.buffer_image_copies.front(); 1887 auto& region = p.buffer_image_copies.front();
1886 const VkDeviceSize row_bytes = VkDeviceSize(region.imageExtent.width) * 4; 1888 if (!fmt.bytes || !fmt.block || image.rgb96 ||
1887 const VkDeviceSize pitch = VkDeviceSize(region.bufferRowLength) * 4; 1889 (image.depth24_as_float && region.imageSubresource.aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT))
1888 const auto rows = region.imageExtent.height; 1890 return false;
1891 const VkDeviceSize blocks_w = (VkDeviceSize(region.imageExtent.width) + fmt.block - 1) / fmt.block;
1892 const VkDeviceSize rows = (VkDeviceSize(region.imageExtent.height) + fmt.block - 1) / fmt.block;
1893 const VkDeviceSize depth = region.imageExtent.depth;
1894 const VkDeviceSize row_bytes = blocks_w * fmt.bytes;
1895 const VkDeviceSize pitch =
1896 region.bufferRowLength ? VkDeviceSize(region.bufferRowLength / fmt.block) * fmt.bytes : row_bytes;
1897 const VkDeviceSize slice_rows =
1898 region.bufferImageHeight ? VkDeviceSize(region.bufferImageHeight / fmt.block) : rows;
1899 const VkDeviceSize slice_pitch = slice_rows * pitch;
1900 const VkDeviceSize slice_bytes = row_bytes * rows;
1901 const VkDeviceSize total_bytes = slice_bytes * depth;
1889 VkDeviceSize scratch_offset = 0; 1902 VkDeviceSize scratch_offset = 0;
1890 if (!vk.copy_scratch || !vk.copy_scratch(row_bytes * rows, p.tile_scratch, scratch_offset)) return false; 1903 if (!total_bytes || !vk.copy_scratch || !vk.copy_scratch(total_bytes, p.tile_scratch, scratch_offset)) return false;
1891 const auto app_offset = region.bufferOffset; 1904 const auto app_offset = region.bufferOffset;
1892 const auto add_copy = [&](VkDeviceSize linear, VkDeviceSize scratch, VkDeviceSize bytes) { 1905 const auto add_copy = [&](VkDeviceSize linear, VkDeviceSize scratch, VkDeviceSize bytes) {
1893 p.tile_rows.push_back(upload ? VkBufferCopy{linear, scratch, bytes} : VkBufferCopy{scratch, linear, bytes}); 1906 p.tile_rows.push_back(upload ? VkBufferCopy{linear, scratch, bytes} : VkBufferCopy{scratch, linear, bytes});
1894 }; 1907 };
1895 if (row_bytes == pitch) { 1908 if (row_bytes == pitch && (depth == 1 || slice_rows == rows)) {
1896 add_copy(app_offset, scratch_offset, row_bytes * rows); 1909 add_copy(app_offset, scratch_offset, total_bytes);
1910 } else if (row_bytes == pitch) {
1911 for (VkDeviceSize z = 0; z < depth; ++z)
1912 add_copy(app_offset + z * slice_pitch, scratch_offset + z * slice_bytes, slice_bytes);
1897 } else { 1913 } else {
1898 for (std::uint32_t row = 0; row < rows; ++row) 1914 for (VkDeviceSize z = 0; z < depth; ++z) {
1899 add_copy(app_offset + row * pitch, scratch_offset + row * row_bytes, row_bytes); 1915 const VkDeviceSize linear_slice = app_offset + z * slice_pitch;
1916 const VkDeviceSize scratch_slice = scratch_offset + z * slice_bytes;
1917 for (VkDeviceSize row = 0; row < rows; ++row)
1918 add_copy(linear_slice + row * pitch, scratch_slice + row * row_bytes, row_bytes);
1919 }
1900 } 1920 }
1901 region.bufferOffset = scratch_offset; 1921 region.bufferOffset = scratch_offset;
1902 region.bufferRowLength = 0; 1922 region.bufferRowLength = 0;
1923 region.bufferImageHeight = 0;
1903 return true; 1924 return true;
1904} 1925}
1905 1926
@@ -2813,9 +2834,15 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun
2813 // A depth plane footprint of a D24 texture stored as D32: words of 24-bit UNORM, floats in the image. 2834 // A depth plane footprint of a D24 texture stored as D32: words of 24-bit UNORM, floats in the image.
2814 const bool upload = texture_copy->src.footprint; 2835 const bool upload = texture_copy->src.footprint;
2815 const ResourceBinding& image = upload ? p.binding : p.source; 2836 const ResourceBinding& image = upload ? p.binding : p.source;
2816 if (result == ReplayResult::success && texture_copy->tile_footprint && !p.buffer_image_copies.empty() && 2837 if (result == ReplayResult::success && texture_copy->tile_footprint && !p.buffer_image_copies.empty()) {
2817 p.buffer_image_copies.front().bufferOffset % 4 && !detail::stage_unaligned_tile(vk, p, upload)) 2838 const auto& region = p.buffer_image_copies.front();
2818 return ReplayResult::unsupported; 2839 const BlockFormat fmt = copy_block_format(image, region.imageSubresource.aspectMask);
2840 const std::uint32_t alignment =
2841 (region.imageSubresource.aspectMask & depth_stencil_aspects) || image.rgb96 ? 4 : fmt.bytes;
2842 if (alignment > 1 && region.bufferOffset % alignment &&
2843 !detail::stage_unaligned_tile(vk, p, image, fmt, upload))
2844 return ReplayResult::unsupported;
2845 }
2819 const bool depth24_footprint = result == ReplayResult::success && image.depth24_as_float && 2846 const bool depth24_footprint = result == ReplayResult::success && image.depth24_as_float &&
2820 !p.buffer_image_copies.empty() && 2847 !p.buffer_image_copies.empty() &&
2821 p.buffer_image_copies[0].imageSubresource.aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT; 2848 p.buffer_image_copies[0].imageSubresource.aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT;