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:
author73N1X <115502401+73N1X@users.noreply.github.com>2026-11-21 18:53:21 -0400
committer73N1X <115502401+73N1X@users.noreply.github.com>2026-11-21 18:53:21 -0400
commit75e666e6157e890dbff3302e4d4c3fc50118c01d (patch)
treeffd1f17bd3e725b8b67821810d2cee79e1c62bcb /runtime/src
parent8bd0087d2d0e45fc18fa78fb40b70ecfc6648854 (diff)
Runtime: convert UINT render-target clear values numerically
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/vulkan_replay.h30
1 files changed, 28 insertions, 2 deletions
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h
index 1bcee80a3..91b2d2d23 100644
--- a/runtime/src/vulkan_replay.h
+++ b/runtime/src/vulkan_replay.h
@@ -28,6 +28,7 @@
28#include <algorithm> 28#include <algorithm>
29#include <cstdint> 29#include <cstdint>
30#include <functional> 30#include <functional>
31#include <limits>
31#include <type_traits> 32#include <type_traits>
32#include <unordered_map> 33#include <unordered_map>
33#include <utility> 34#include <utility>
@@ -499,6 +500,32 @@ struct Prepared {
499 VkImageResolve resolve{}; // resolves 500 VkImageResolve resolve{}; // resolves
500}; 501};
501 502
503// ClearRenderTargetView takes FLOATs even for integer RTVs. For the UINT formats currently exposed by
504// the device, Windows D3D12 (WARP and AMD) clamps to the component range and truncates fractions. Vulkan
505// instead interprets the matching union member as an integer already; copying float bits changes the value.
506inline VkClearColorValue render_target_clear_color(VkFormat format, const ClearColor& input) {
507 std::uint32_t maximum = 0;
508 switch (format) {
509 case VK_FORMAT_R8G8B8A8_UINT: maximum = 255; break;
510 case VK_FORMAT_R32_UINT:
511 case VK_FORMAT_R32G32B32A32_UINT: maximum = std::numeric_limits<std::uint32_t>::max(); break;
512 default: break;
513 }
514 VkClearColorValue value{};
515 for (std::size_t i = 0; i < input.size(); ++i) {
516 if (!maximum) {
517 value.float32[i] = input[i];
518 } else if (!(input[i] > 0.0f)) {
519 value.uint32[i] = 0; // NaN, negative values and either zero; no out-of-range float-to-int cast.
520 } else if (double(input[i]) >= double(maximum)) {
521 value.uint32[i] = maximum; // Includes +infinity; UINT32_MAX itself is not representable as float.
522 } else {
523 value.uint32[i] = static_cast<std::uint32_t>(input[i]);
524 }
525 }
526 return value;
527}
528
502inline bool view_range(const ResourceBinding& resource, const TargetView& view, VkImageAspectFlags aspects, 529inline bool view_range(const ResourceBinding& resource, const TargetView& view, VkImageAspectFlags aspects,
503 VkImageSubresourceRange& out) { 530 VkImageSubresourceRange& out) {
504 if (view.mip >= resource.mip_levels) return false; 531 if (view.mip >= resource.mip_levels) return false;
@@ -1012,8 +1039,7 @@ inline void emit(const PreparedList& prepared, VkCommandBuffer command_buffer, c
1012 const VulkanAccess state = vulkan_access(d3d12_state::render_target, false); 1039 const VulkanAccess state = vulkan_access(d3d12_state::render_target, false);
1013 auto pieces = detail::current(tracker, id, p.range, image_layout(p.binding, state.layout)); 1040 auto pieces = detail::current(tracker, id, p.range, image_layout(p.binding, state.layout));
1014 detail::initialize(vk, command_buffer, p.binding, id, pieces, image_layout(p.binding, state.layout), tracker); 1041 detail::initialize(vk, command_buffer, p.binding, id, pieces, image_layout(p.binding, state.layout), tracker);
1015 VkClearColorValue color{}; 1042 const VkClearColorValue color = detail::render_target_clear_color(p.binding.format, color_clear->color);
1016 std::copy(color_clear->color.begin(), color_clear->color.end(), color.float32);
1017 if (p.rects.empty()) { 1043 if (p.rects.empty()) {
1018 detail::round_trip(vk, command_buffer, p.binding.image, pieces, image_layout(p.binding, transfer_dst.layout), 1044 detail::round_trip(vk, command_buffer, p.binding.image, pieces, image_layout(p.binding, transfer_dst.layout),
1019 state, transfer_dst.access, transfer_dst.stages, [&] { 1045 state, transfer_dst.access, transfer_dst.stages, [&] {