Skip to content

Commit 2527383

Browse files
committed
fixup! [naga hlsl-out] Implement external texture support
1 parent 49330ad commit 2527383

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

naga/src/back/hlsl/help.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl<W: Write> super::Writer<'_, W> {
294294
// If params.size is zero then clamp to the actual size of the texture.
295295
writeln!(
296296
self.out,
297-
"{l1}uint2 cropped_size = params.size != 0 ? params.size : plane0_size;"
297+
"{l1}uint2 cropped_size = any(params.size) ? params.size : plane0_size;"
298298
)?;
299299
writeln!(self.out, "{l1}coords = min(coords, cropped_size - 1);")?;
300300

@@ -342,7 +342,7 @@ impl<W: Write> super::Writer<'_, W> {
342342
self.out,
343343
"{l3}plane2.GetDimensions(plane2_size.x, plane2_size.y);"
344344
)?;
345-
writeln!(self.out, "{l2}uint2 plane2_coords = uint2(floor(float2(plane0_coords) * float2(plane2_size) / float2(plane0_size)));")?;
345+
writeln!(self.out, "{l3}uint2 plane2_coords = uint2(floor(float2(plane0_coords) * float2(plane2_size) / float2(plane0_size)));")?;
346346
writeln!(self.out, "{l3}uv = float2(plane1.Load(uint3(plane1_coords, 0u)).x, plane2.Load(uint3(plane2_coords, 0u)).x);")?;
347347
writeln!(self.out, "{l2}}}")?;
348348

@@ -405,10 +405,13 @@ impl<W: Write> super::Writer<'_, W> {
405405
self.out,
406406
"{l1}coords = mul(float3(coords, 1.0), sample_transform);"
407407
)?;
408-
// Calculate the sample bounds taking in to account the transform,
409-
// bearing in mind that it may contain a flip on either axis. We must
410-
// calculate and adjust for the half-texel separately for each plane as
411-
// it depends on the texture size which may vary between planes.
408+
// Calculate the sample bounds. The purported size of the texture
409+
// (params.size) is irrelevant here as we are dealing with normalized
410+
// coordinates. Usually we would clamp to (0,0)..(1,1). However, we must
411+
// apply the sample transformation to that, also bearing in mind that it
412+
// may contain a flip on either axis. We calculate and adjust for the
413+
// half-texel separately for each plane as it depends on the actual
414+
// texture size which may vary between planes.
412415
writeln!(
413416
self.out,
414417
"{l1}float2 bounds_min = mul(float3(0.0, 0.0, 1.0), sample_transform);"

naga/tests/out/hlsl/wgsl-texture-external.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ float4 nagaTextureLoadExternal(
6868
{
6969
uint2 plane0_size;
7070
plane0.GetDimensions(plane0_size.x, plane0_size.y);
71-
uint2 cropped_size = params.size != 0 ? params.size : plane0_size;
71+
uint2 cropped_size = any(params.size) ? params.size : plane0_size;
7272
coords = min(coords, cropped_size - 1);
7373
float3x2 load_transform = float3x2(
7474
params.load_transform_0,
@@ -89,7 +89,7 @@ float4 nagaTextureLoadExternal(
8989
} else {
9090
uint2 plane2_size;
9191
plane2.GetDimensions(plane2_size.x, plane2_size.y);
92-
uint2 plane2_coords = uint2(floor(float2(plane0_coords) * float2(plane2_size) / float2(plane0_size)));
92+
uint2 plane2_coords = uint2(floor(float2(plane0_coords) * float2(plane2_size) / float2(plane0_size)));
9393
uv = float2(plane1.Load(uint3(plane1_coords, 0u)).x, plane2.Load(uint3(plane2_coords, 0u)).x);
9494
}
9595
return mul(float4(y, uv, 1.0), params.yuv_conversion_matrix);

0 commit comments

Comments
 (0)