aboutsummaryrefslogtreecommitdiff
path: root/adapters/fparkan-render-vulkan/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-12 10:30:48 +0300
committerValentin Popov <valentin@popov.link>2026-11-12 10:30:48 +0300
commitefaafac18e04c1cfc23f6dd321f716c5cb3770f0 (patch)
tree7103418d845871d534e88f6db6ef87ef575865fe /adapters/fparkan-render-vulkan/src
parentb6c278d66e2a1324fd3d5460648c28fa22f71193 (diff)
downloadfparkan-efaafac18e04c1cfc23f6dd321f716c5cb3770f0.tar.xz
fparkan-efaafac18e04c1cfc23f6dd321f716c5cb3770f0.zip
fix(render): copy finished reflection color with native precision
Diffstat (limited to 'adapters/fparkan-render-vulkan/src')
-rw-r--r--adapters/fparkan-render-vulkan/src/ffi/reflection.rs46
-rw-r--r--adapters/fparkan-render-vulkan/src/ffi/smoke.rs1
-rw-r--r--adapters/fparkan-render-vulkan/src/ffi/swapchain_resources.rs1
3 files changed, 26 insertions, 22 deletions
diff --git a/adapters/fparkan-render-vulkan/src/ffi/reflection.rs b/adapters/fparkan-render-vulkan/src/ffi/reflection.rs
index 2a1291d6..7e2ceb55 100644
--- a/adapters/fparkan-render-vulkan/src/ffi/reflection.rs
+++ b/adapters/fparkan-render-vulkan/src/ffi/reflection.rs
@@ -6,11 +6,9 @@ use super::{
};
use ash::vk;
-fn reflection_color_format(features: [vk::FormatFeatureFlags; 2]) -> Option<vk::Format> {
- let required = vk::FormatFeatureFlags::COLOR_ATTACHMENT
- | vk::FormatFeatureFlags::COLOR_ATTACHMENT_BLEND
- | vk::FormatFeatureFlags::SAMPLED_IMAGE
- | vk::FormatFeatureFlags::SAMPLED_IMAGE_FILTER_LINEAR;
+fn reflection_copy_format(features: [vk::FormatFeatureFlags; 2]) -> Option<vk::Format> {
+ let required =
+ vk::FormatFeatureFlags::SAMPLED_IMAGE | vk::FormatFeatureFlags::SAMPLED_IMAGE_FILTER_LINEAR;
[
vk::Format::R5G6B5_UNORM_PACK16,
vk::Format::A1R5G5B5_UNORM_PACK16,
@@ -115,6 +113,7 @@ pub(super) struct ReflectionResources {
pub render_pass: vk::RenderPass,
depth: Option<VulkanDepthAttachment>,
pub framebuffer: vk::Framebuffer,
+ pub copy_material_mode: i32,
}
impl ReflectionResources {
@@ -137,6 +136,7 @@ impl ReflectionResources {
render_pass: vk::RenderPass::null(),
depth: None,
framebuffer: vk::Framebuffer::null(),
+ copy_material_mode: 0,
};
let bindings: Vec<_> = (0..2)
.map(|binding| {
@@ -258,7 +258,6 @@ impl ReflectionResources {
instance: &VulkanInstanceProbe,
device: &VulkanLogicalDeviceProbe,
extent: (u32, u32),
- format: i32,
depth_request: fparkan_platform::DepthStencilSupport,
) -> Result<(), VulkanSmokeRendererError> {
let side = fparkan_render::water::legacy_embm_reflection_size([extent.0, extent.1]);
@@ -276,13 +275,22 @@ impl ReflectionResources {
}
.optimal_tiling_features
});
- let native_format = reflection_color_format(features);
+ let native_format = reflection_copy_format(features);
if native_format.is_none() {
- eprintln!("render_coverage reflection_16bit_color_unsupported=1 (RGB565 and RGB555 lack required attachment/blend/sample/filter support; main color format fallback)");
+ eprintln!("render_coverage reflection_16bit_color_unsupported=1 (RGB565 and RGB555 lack texture/filter support; unquantized RGB8 copy fallback)");
}
- let format = native_format.unwrap_or(vk::Format::from_raw(format));
- eprintln!("render_coverage reflection_dither_approx=1 (native cached DITHERENABLE=1; Vulkan attachment conversion has no matching legacy dither pattern)");
- eprintln!("render_reflection color_format={}", format.as_raw());
+ self.copy_material_mode = match native_format {
+ Some(vk::Format::R5G6B5_UNORM_PACK16) => 512,
+ Some(vk::Format::A1R5G5B5_UNORM_PACK16) => 1024,
+ _ => 0,
+ };
+ // Native's 32-bit path blends RGB8 before GDI copies the finished image into the 16-bit texture.
+ let format = vk::Format::R8G8B8A8_UNORM;
+ eprintln!(
+ "render_reflection color_format={} copy_format={}",
+ format.as_raw(),
+ native_format.unwrap_or(format).as_raw()
+ );
eprintln!("render_reflection target_extent={side}x{side}");
let info = vk::ImageCreateInfo::default()
.image_type(vk::ImageType::TYPE_2D)
@@ -299,7 +307,7 @@ impl ReflectionResources {
.usage(vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::SAMPLED)
.sharing_mode(vk::SharingMode::EXCLUSIVE)
.initial_layout(vk::ImageLayout::UNDEFINED);
- // SAFETY: The validated swapchain format is retained; the square side is in 2..=1024.
+ // SAFETY: The device is live; this single-mip RGB8 target has a nonzero side in 2..=1024.
let image = unsafe { self.device.create_image(&info, None) }.map_err(|result| {
VulkanSmokeRendererError::VulkanOperation {
context: "vkCreateImage(reflection)",
@@ -499,26 +507,22 @@ mod tests {
}
#[test]
- fn reflection_prefers_native_565_then_555_and_requires_filterable_blending() {
- let required = vk::FormatFeatureFlags::COLOR_ATTACHMENT
- | vk::FormatFeatureFlags::COLOR_ATTACHMENT_BLEND
- | vk::FormatFeatureFlags::SAMPLED_IMAGE
+ fn reflection_copy_prefers_filterable_565_then_555_without_attachment_support() {
+ let required = vk::FormatFeatureFlags::SAMPLED_IMAGE
| vk::FormatFeatureFlags::SAMPLED_IMAGE_FILTER_LINEAR;
assert_eq!(
- reflection_color_format([required; 2]),
+ reflection_copy_format([required; 2]),
Some(vk::Format::R5G6B5_UNORM_PACK16)
);
for missing in [
- vk::FormatFeatureFlags::COLOR_ATTACHMENT,
- vk::FormatFeatureFlags::COLOR_ATTACHMENT_BLEND,
vk::FormatFeatureFlags::SAMPLED_IMAGE,
vk::FormatFeatureFlags::SAMPLED_IMAGE_FILTER_LINEAR,
] {
assert_eq!(
- reflection_color_format([required & !missing, required]),
+ reflection_copy_format([required & !missing, required]),
Some(vk::Format::A1R5G5B5_UNORM_PACK16)
);
- assert_eq!(reflection_color_format([required & !missing; 2]), None);
+ assert_eq!(reflection_copy_format([required & !missing; 2]), None);
}
}
diff --git a/adapters/fparkan-render-vulkan/src/ffi/smoke.rs b/adapters/fparkan-render-vulkan/src/ffi/smoke.rs
index 040468e9..028a686d 100644
--- a/adapters/fparkan-render-vulkan/src/ffi/smoke.rs
+++ b/adapters/fparkan-render-vulkan/src/ffi/smoke.rs
@@ -2110,6 +2110,7 @@ impl VulkanSmokeRenderer {
&& self.reflection_planes[range_index] == reflection_plane
{
64 | if shifted_reflection { 128 } else { 0 }
+ | resources.reflection.copy_material_mode
} else {
0
}) as f32;
diff --git a/adapters/fparkan-render-vulkan/src/ffi/swapchain_resources.rs b/adapters/fparkan-render-vulkan/src/ffi/swapchain_resources.rs
index ee194008..14c599a0 100644
--- a/adapters/fparkan-render-vulkan/src/ffi/swapchain_resources.rs
+++ b/adapters/fparkan-render-vulkan/src/ffi/swapchain_resources.rs
@@ -270,7 +270,6 @@ pub(super) fn create_swapchain_resources(
instance,
device,
swapchain.report.plan.extent,
- swapchain.report.plan.format.format,
depth_request,
)
{