mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Address more comments
This commit is contained in:
committed by
Dzmitry Malyshau
parent
a1749ab9c5
commit
8880faf360
@@ -136,7 +136,7 @@ impl<I: Iterator<Item = u32>> super::Parser<I> {
|
||||
let mut flow_graph = FlowGraph::new();
|
||||
|
||||
let mut function_info = FunctionInfo {
|
||||
parameters_sampling: vec![None; fun.arguments.len()],
|
||||
parameters_sampling: vec![super::image::SamplingFlags::empty(); fun.arguments.len()],
|
||||
};
|
||||
|
||||
// Scan the blocks and add them as nodes
|
||||
|
||||
@@ -456,8 +456,7 @@ impl<I: Iterator<Item = u32>> super::Parser<I> {
|
||||
global_arena[handle].ty
|
||||
}
|
||||
crate::Expression::FunctionArgument(i) => {
|
||||
let flags = function_info.parameters_sampling[i as usize]
|
||||
.get_or_insert(SamplingFlags::empty());
|
||||
let flags = &mut function_info.parameters_sampling[i as usize];
|
||||
*flags |= sampling_bit;
|
||||
|
||||
arguments[i as usize].ty
|
||||
@@ -469,8 +468,7 @@ impl<I: Iterator<Item = u32>> super::Parser<I> {
|
||||
*self.handle_sampling.get_mut(&handle).unwrap() |= sampling_bit
|
||||
}
|
||||
crate::Expression::FunctionArgument(i) => {
|
||||
let flags = function_info.parameters_sampling[i as usize]
|
||||
.get_or_insert(SamplingFlags::empty());
|
||||
let flags = &mut function_info.parameters_sampling[i as usize];
|
||||
*flags |= sampling_bit;
|
||||
}
|
||||
ref other => return Err(Error::InvalidGlobalVar(other.clone())),
|
||||
|
||||
@@ -372,7 +372,7 @@ impl Default for Options {
|
||||
}
|
||||
|
||||
struct FunctionInfo {
|
||||
parameters_sampling: Vec<Option<image::SamplingFlags>>,
|
||||
parameters_sampling: Vec<image::SamplingFlags>,
|
||||
}
|
||||
|
||||
pub struct Parser<I> {
|
||||
@@ -2314,24 +2314,29 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
for (i, arg) in arguments.iter().enumerate() {
|
||||
let callee_info = &self.function_info[handle.index()];
|
||||
|
||||
if let Some(flags) = callee_info.parameters_sampling.get(i).and_then(|e| *e)
|
||||
{
|
||||
match expressions[*arg] {
|
||||
crate::Expression::GlobalVariable(handle) => {
|
||||
*self.handle_sampling.get_mut(&handle).unwrap() |= flags
|
||||
let flags = match callee_info.parameters_sampling.get(i) {
|
||||
Some(&flags) => flags,
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
if flags.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
match expressions[*arg] {
|
||||
crate::Expression::GlobalVariable(handle) => {
|
||||
if let Some(sampling) = self.handle_sampling.get_mut(&handle) {
|
||||
*sampling |= flags
|
||||
}
|
||||
crate::Expression::FunctionArgument(i) => {
|
||||
if let Some(handle) = function {
|
||||
let function_info =
|
||||
self.function_info.get_mut(handle.index()).unwrap();
|
||||
let caller_flags = function_info.parameters_sampling
|
||||
[i as usize]
|
||||
.get_or_insert(image::SamplingFlags::empty());
|
||||
*caller_flags |= flags;
|
||||
}
|
||||
}
|
||||
ref other => return Err(Error::InvalidGlobalVar(other.clone())),
|
||||
}
|
||||
crate::Expression::FunctionArgument(i) => {
|
||||
if let Some(handle) = function {
|
||||
let function_info =
|
||||
self.function_info.get_mut(handle.index()).unwrap();
|
||||
function_info.parameters_sampling[i as usize] |= flags;
|
||||
}
|
||||
}
|
||||
ref other => return Err(Error::InvalidGlobalVar(other.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,11 +168,11 @@ enum GlobalOrArgument {
|
||||
}
|
||||
|
||||
impl crate::Expression {
|
||||
fn to_global_or_argument(&self) -> Option<GlobalOrArgument> {
|
||||
Some(match *self {
|
||||
fn to_global_or_argument(&self) -> Result<GlobalOrArgument, ExpressionError> {
|
||||
Ok(match *self {
|
||||
crate::Expression::GlobalVariable(var) => GlobalOrArgument::Global(var),
|
||||
crate::Expression::FunctionArgument(i) => GlobalOrArgument::Argument(i),
|
||||
_ => return None,
|
||||
_ => return Err(ExpressionError::ExpectedGlobalOrArgument),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -315,12 +315,9 @@ impl FunctionInfo {
|
||||
GlobalOrArgument::Global(var) => GlobalOrArgument::Global(var),
|
||||
GlobalOrArgument::Argument(i) => {
|
||||
let handle = arguments[i as usize];
|
||||
expression_arena[handle].to_global_or_argument().ok_or(
|
||||
FunctionError::Expression {
|
||||
handle,
|
||||
error: ExpressionError::ExpectedGlobalOrArgument,
|
||||
},
|
||||
)?
|
||||
expression_arena[handle]
|
||||
.to_global_or_argument()
|
||||
.map_err(|error| FunctionError::Expression { handle, error })?
|
||||
}
|
||||
};
|
||||
|
||||
@@ -328,12 +325,9 @@ impl FunctionInfo {
|
||||
GlobalOrArgument::Global(var) => GlobalOrArgument::Global(var),
|
||||
GlobalOrArgument::Argument(i) => {
|
||||
let handle = arguments[i as usize];
|
||||
expression_arena[handle].to_global_or_argument().ok_or(
|
||||
FunctionError::Expression {
|
||||
handle,
|
||||
error: ExpressionError::ExpectedGlobalOrArgument,
|
||||
},
|
||||
)?
|
||||
expression_arena[handle]
|
||||
.to_global_or_argument()
|
||||
.map_err(|error| FunctionError::Expression { handle, error })?
|
||||
}
|
||||
};
|
||||
|
||||
@@ -466,24 +460,14 @@ impl FunctionInfo {
|
||||
level,
|
||||
depth_ref,
|
||||
} => {
|
||||
let image_storage = expression_arena[image]
|
||||
.to_global_or_argument()
|
||||
.ok_or(ExpressionError::ExpectedGlobalOrArgument)?;
|
||||
let sampler_storage = expression_arena[sampler]
|
||||
.to_global_or_argument()
|
||||
.ok_or(ExpressionError::ExpectedGlobalOrArgument)?;
|
||||
let image_storage = expression_arena[image].to_global_or_argument()?;
|
||||
let sampler_storage = expression_arena[sampler].to_global_or_argument()?;
|
||||
|
||||
match (image_storage, sampler_storage) {
|
||||
(GlobalOrArgument::Global(image), GlobalOrArgument::Global(sampler)) => {
|
||||
self.sampling_set.insert(SamplingKey { image, sampler });
|
||||
}
|
||||
(GlobalOrArgument::Argument(_), _) => {
|
||||
self.sampling.insert(Sampling {
|
||||
image: image_storage,
|
||||
sampler: sampler_storage,
|
||||
});
|
||||
}
|
||||
(_, GlobalOrArgument::Argument(_)) => {
|
||||
_ => {
|
||||
self.sampling.insert(Sampling {
|
||||
image: image_storage,
|
||||
sampler: sampler_storage,
|
||||
|
||||
Reference in New Issue
Block a user