Tests: the screen cell's loop writes its complement a quarter step above, so either rounding lands on it
On lavapipe the 2560x1600 BGR10A2Unorm screen's loop wrote red 250 where 251 was expected at 1,258,012 of 4,096,000 texels: 1 - 772/1023 is a hair under 251/1023 there, and lavapipe stores the lower of the two nearest values. Vulkan allows that: convertFloatToUint "returns one of the two unsigned binary integer values with exactly b bits which are closest to the floating-point value r. Implementations should round to nearest" (Conversion From Floating-Point to Normalized Fixed-Point). AMDVLK and RADV stored 251. The loop now takes 1 + 0.25 / (the channel's largest value) less what it read, the same quarter step the pattern's (k + 0.25) / largest takes, so the complement (largest - k + 0.25) / largest lands on largest - k whether the device rounds to the nearest value or down; at k = 0 it clamps to 1, the largest value. Verified: cargo fmt. The 780M under AMDVLK and RADV and lavapipe rerun on this commit, then the Windows host.
This commit is contained in:
1 parent
171d81e6f6
commit
b8ccc837a8
1 file changed
+12
-5
@@ -1393,6 +1393,13 @@ declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1), ptr a
|
||||
}
|
||||
}
|
||||
|
||||
/// What `loop_one` takes less what it reads: 1, and a quarter of a channel's step, so that
|
||||
/// the complement it writes lands on its value whether the device rounds a write to the
|
||||
/// nearest step or down.
|
||||
fn minuend(self) -> [f32; 4] {
|
||||
self.largest().map(|largest| 1.0 + 0.25 / largest as f32)
|
||||
}
|
||||
|
||||
/// The pattern's channels at `(x, y)`, or their complement, in shader order.
|
||||
fn channels(self, x: u32, y: u32, complemented: bool) -> [u32; 4] {
|
||||
let k = match self {
|
||||
@@ -1536,12 +1543,12 @@ declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1), ptr a
|
||||
|
||||
/// Draws `pattern` into `pass`'s one target, cut to [`drawn`] of `size`; then, where `looped`
|
||||
/// names one, after a memory barrier its loop over the whole target, sampling the texture it
|
||||
/// names through sampler `sampler` with the loop's constants, as its attachment.
|
||||
/// names through sampler `sampler` as its attachment, less the minuend it names.
|
||||
fn draw_one(
|
||||
name: &str,
|
||||
queue: &CommandQueue,
|
||||
(pass, pattern, size): (&RenderPassDescriptor, &RenderPipelineState, [u32; 2]),
|
||||
looped: Option<(&RenderPipelineState, &Texture, &SamplerState)>,
|
||||
looped: Option<(&RenderPipelineState, &Texture, &SamplerState, [f32; 4])>,
|
||||
) -> Result<(), String> {
|
||||
let [x, y, width, height] = drawn(size).map(u64::from);
|
||||
let command_buffer = queue.command_buffer().map_err(said)?;
|
||||
@@ -1554,8 +1561,8 @@ declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1), ptr a
|
||||
height,
|
||||
});
|
||||
(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0)).map_err(said)?;
|
||||
if let Some((state, texture, sampler)) = looped {
|
||||
let constants: Vec<u8> = [1.0; 4]
|
||||
if let Some((state, texture, sampler, minuend)) = looped {
|
||||
let constants: Vec<u8> = minuend
|
||||
.into_iter()
|
||||
.chain([1.0 / size[0] as f32, 1.0 / size[1] as f32, 0.0, 0.0])
|
||||
.flat_map(f32::to_le_bytes)
|
||||
@@ -1724,7 +1731,7 @@ declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1), ptr a
|
||||
target.store_action = StoreAction::Store;
|
||||
let counters = device.counters();
|
||||
let before = counters.metrics();
|
||||
let loops = Some((&looping, &view, &readers.sampler));
|
||||
let loops = Some((&looping, &view, &readers.sampler, layer.minuend()));
|
||||
let drew = draw_one(name, &queue, (&pass, &pattern, size), loops);
|
||||
let moved = counters.metrics();
|
||||
let what = format!(
|
||||
|
||||
Reference in new issue
Block a user