Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spv-in] sampling from depth textures returns a scalar and is splatted #6384

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ By @bradwerth [#6216](https://github.com/gfx-rs/wgpu/pull/6216).

#### Naga

- SPIR-V frontend splats depth texture sample and load results. Fixes [issue #4551](https://github.com/gfx-rs/wgpu/issues/4551). By @schell in [#6384](https://github.com/gfx-rs/wgpu/pull/6384).
- Accept only `vec3` (not `vecN`) for the `cross` built-in. By @ErichDonGubler in [#6171](https://github.com/gfx-rs/wgpu/pull/6171).
- Configure `SourceLanguage` when enabling debug info in SPV-out. By @kvark in [#6256](https://github.com/gfx-rs/wgpu/pull/6256).
- Per-polygon and flat inputs should not be considered subgroup uniform. By @magcius in [#6276](https://github.com/gfx-rs/wgpu/pull/6276).
Expand Down
67 changes: 49 additions & 18 deletions naga/src/front/spv/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,36 +377,54 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
let coord_handle =
self.get_expr_handle(coordinate_id, coord_lexp, ctx, emitter, block, body_idx);
let coord_type_handle = self.lookup_type.lookup(coord_lexp.type_id)?.handle;
let (coordinate, array_index) = match ctx.type_arena[image_ty].inner {
let (coordinate, array_index, is_depth) = match ctx.type_arena[image_ty].inner {
crate::TypeInner::Image {
dim,
arrayed,
class: _,
} => extract_image_coordinates(
dim,
if arrayed {
ExtraCoordinate::ArrayLayer
} else {
ExtraCoordinate::Garbage
},
coord_handle,
coord_type_handle,
ctx,
),
class,
} => {
let (coord, array_index) = extract_image_coordinates(
dim,
if arrayed {
ExtraCoordinate::ArrayLayer
} else {
ExtraCoordinate::Garbage
},
coord_handle,
coord_type_handle,
ctx,
);
(coord, array_index, class.is_depth())
}
_ => return Err(Error::InvalidImage(image_ty)),
};

let expr = crate::Expression::ImageLoad {
let image_load_expr = crate::Expression::ImageLoad {
image: image_lexp.handle,
coordinate,
array_index,
sample,
level,
};
let image_load_handle = ctx
.expressions
.append(image_load_expr, self.span_from_with_op(start));

let handle = if is_depth {
let splat_expr = crate::Expression::Splat {
size: crate::VectorSize::Quad,
value: image_load_handle,
};
teoxoy marked this conversation as resolved.
Show resolved Hide resolved
ctx.expressions
.append(splat_expr, self.span_from_with_op(start))
} else {
image_load_handle
};

self.lookup_expression.insert(
result_id,
LookupExpression {
handle: ctx.expressions.append(expr, self.span_from_with_op(start)),
handle,
type_id: result_type_id,
block_id,
},
Expand Down Expand Up @@ -593,11 +611,12 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
ref other => return Err(Error::InvalidGlobalVar(other.clone())),
}

let ((coordinate, array_index), depth_ref) = match ctx.type_arena[image_ty].inner {
let ((coordinate, array_index), depth_ref, is_depth) = match ctx.type_arena[image_ty].inner
{
crate::TypeInner::Image {
dim,
arrayed,
class: _,
class,
} => (
extract_image_coordinates(
dim,
Expand Down Expand Up @@ -642,6 +661,7 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
None => None,
}
},
class.is_depth(),
),
_ => return Err(Error::InvalidImage(image_ty)),
};
Expand All @@ -656,10 +676,21 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
level,
depth_ref,
};
let image_sample_handle = ctx.expressions.append(expr, self.span_from_with_op(start));
let handle = if is_depth && depth_ref.is_none() {
let splat_expr = crate::Expression::Splat {
size: crate::VectorSize::Quad,
value: image_sample_handle,
};
ctx.expressions
.append(splat_expr, self.span_from_with_op(start))
} else {
image_sample_handle
};
self.lookup_expression.insert(
result_id,
LookupExpression {
handle: ctx.expressions.append(expr, self.span_from_with_op(start)),
handle,
type_id: result_type_id,
block_id,
},
Expand Down
4 changes: 4 additions & 0 deletions naga/src/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ impl super::ImageClass {
crate::ImageClass::Storage { .. } => false,
}
}

pub const fn is_depth(self) -> bool {
matches!(self, crate::ImageClass::Depth { .. })
}
}

impl crate::Module {
Expand Down