mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-12-04 20:53:57 +00:00
[hlsl-out] Remove MipLevelCoordinate
type.
Validation insures that `ImageLoad` expressions always have an `index` operand when the image's type requires it, so there is no need for `MipLevelCoordinate::Zero`. This means that `Option<Handle<Expression>>` serves adequately for this case.
This commit is contained in:
parent
771d62710c
commit
7d06445897
@ -101,13 +101,6 @@ impl From<crate::ImageQuery> for ImageQuery {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub(super) enum MipLevelCoordinate {
|
||||
NotApplicable,
|
||||
Zero,
|
||||
Expression(Handle<crate::Expression>),
|
||||
}
|
||||
|
||||
impl<'a, W: Write> super::Writer<'a, W> {
|
||||
pub(super) fn write_image_type(
|
||||
&mut self,
|
||||
@ -497,13 +490,12 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
kind: &str,
|
||||
coordinate: Handle<crate::Expression>,
|
||||
array_index: Option<Handle<crate::Expression>>,
|
||||
mip_level: MipLevelCoordinate,
|
||||
mip_level: Option<Handle<crate::Expression>>,
|
||||
module: &crate::Module,
|
||||
func_ctx: &FunctionCtx,
|
||||
) -> BackendResult {
|
||||
// HLSL expects the array index to be merged with the coordinate
|
||||
let extra = array_index.is_some() as usize
|
||||
+ (mip_level != MipLevelCoordinate::NotApplicable) as usize;
|
||||
let extra = array_index.is_some() as usize + (mip_level.is_some()) as usize;
|
||||
if extra == 0 {
|
||||
self.write_expr(module, coordinate, func_ctx)?;
|
||||
} else {
|
||||
@ -518,15 +510,9 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
write!(self.out, ", ")?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
}
|
||||
match mip_level {
|
||||
MipLevelCoordinate::NotApplicable => {}
|
||||
MipLevelCoordinate::Zero => {
|
||||
write!(self.out, ", 0")?;
|
||||
}
|
||||
MipLevelCoordinate::Expression(expr) => {
|
||||
write!(self.out, ", ")?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
}
|
||||
if let Some(expr) = mip_level {
|
||||
write!(self.out, ", ")?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
}
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::{
|
||||
help::{MipLevelCoordinate, WrappedArrayLength, WrappedConstructor, WrappedImageQuery},
|
||||
help::{WrappedArrayLength, WrappedConstructor, WrappedImageQuery},
|
||||
storage::StoreValue,
|
||||
BackendResult, Error, Options,
|
||||
};
|
||||
@ -1629,7 +1629,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
"float",
|
||||
coordinate,
|
||||
array_index,
|
||||
MipLevelCoordinate::NotApplicable,
|
||||
None,
|
||||
module,
|
||||
func_ctx,
|
||||
)?;
|
||||
@ -1697,27 +1697,19 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
index,
|
||||
} => {
|
||||
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-load
|
||||
let (ms, storage) = match *func_ctx.info[image].ty.inner_with(&module.types) {
|
||||
let (sample, mip_level) = match *func_ctx.info[image].ty.inner_with(&module.types) {
|
||||
TypeInner::Image { class, .. } => match class {
|
||||
crate::ImageClass::Sampled { multi, .. }
|
||||
| crate::ImageClass::Depth { multi } => (multi, false),
|
||||
crate::ImageClass::Storage { .. } => (false, true),
|
||||
crate::ImageClass::Sampled { multi: true, .. }
|
||||
| crate::ImageClass::Depth { multi: true } => (index, None),
|
||||
crate::ImageClass::Storage { .. } => (None, None),
|
||||
_ => (None, index),
|
||||
},
|
||||
_ => (false, false),
|
||||
_ => (None, None),
|
||||
};
|
||||
|
||||
self.write_expr(module, image, func_ctx)?;
|
||||
write!(self.out, ".Load(")?;
|
||||
|
||||
let mip_level = if ms || storage {
|
||||
MipLevelCoordinate::NotApplicable
|
||||
} else {
|
||||
match index {
|
||||
Some(expr) => MipLevelCoordinate::Expression(expr),
|
||||
None => MipLevelCoordinate::Zero,
|
||||
}
|
||||
};
|
||||
|
||||
self.write_texture_coordinates(
|
||||
"int",
|
||||
coordinate,
|
||||
@ -1727,9 +1719,9 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
func_ctx,
|
||||
)?;
|
||||
|
||||
if ms {
|
||||
if let Some(sample) = sample {
|
||||
write!(self.out, ", ")?;
|
||||
self.write_expr(module, index.unwrap(), func_ctx)?;
|
||||
self.write_expr(module, sample, func_ctx)?;
|
||||
}
|
||||
|
||||
// close bracket for Load function
|
||||
|
Loading…
Reference in New Issue
Block a user