mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-26 09:21:04 +01:00
[spv-out] Move BlockContext into its own file.
Rearrange some code for easier visibility. `make_local` doesn't need a PhysicalLayout `self`; make it a free function.
This commit is contained in:
1 parent
f878a9dcaf
commit
3a1a2ed8b3
3 files changed
+1668
-1662
No files matched your search
File diff suppressed because it is too large.
Load diff
+79
-1
@@ -1,6 +1,7 @@
|
||||
/*! Standard Portable Intermediate Representation (SPIR-V) backend
|
||||
!*/
|
||||
|
||||
mod block;
|
||||
mod helpers;
|
||||
mod index;
|
||||
mod instructions;
|
||||
@@ -10,7 +11,7 @@ mod writer;
|
||||
|
||||
pub use spirv::Capability;
|
||||
|
||||
use crate::{arena::Handle, back::IndexBoundsCheckPolicy};
|
||||
use crate::{arena::Handle, back::IndexBoundsCheckPolicy, proc::TypeResolution};
|
||||
|
||||
use spirv::Word;
|
||||
use std::ops;
|
||||
@@ -205,6 +206,58 @@ struct LookupFunctionType {
|
||||
return_type_id: Word,
|
||||
}
|
||||
|
||||
fn make_local(inner: &crate::TypeInner) -> Option<LocalType> {
|
||||
Some(match *inner {
|
||||
crate::TypeInner::Scalar { kind, width } => LocalType::Value {
|
||||
vector_size: None,
|
||||
kind,
|
||||
width,
|
||||
pointer_class: None,
|
||||
},
|
||||
crate::TypeInner::Vector { size, kind, width } => LocalType::Value {
|
||||
vector_size: Some(size),
|
||||
kind,
|
||||
width,
|
||||
pointer_class: None,
|
||||
},
|
||||
crate::TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
width,
|
||||
} => LocalType::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
width,
|
||||
},
|
||||
crate::TypeInner::Pointer { base, class } => LocalType::Pointer {
|
||||
base,
|
||||
class: helpers::map_storage_class(class),
|
||||
},
|
||||
crate::TypeInner::ValuePointer {
|
||||
size,
|
||||
kind,
|
||||
width,
|
||||
class,
|
||||
} => LocalType::Value {
|
||||
vector_size: size,
|
||||
kind,
|
||||
width,
|
||||
pointer_class: Some(helpers::map_storage_class(class)),
|
||||
},
|
||||
crate::TypeInner::Image {
|
||||
dim,
|
||||
arrayed,
|
||||
class,
|
||||
} => LocalType::Image {
|
||||
dim,
|
||||
arrayed,
|
||||
class,
|
||||
},
|
||||
crate::TypeInner::Sampler { comparison: _ } => LocalType::Sampler,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Dimension {
|
||||
Scalar,
|
||||
@@ -280,6 +333,31 @@ struct BlockContext<'w> {
|
||||
temp_list: Vec<Word>,
|
||||
}
|
||||
|
||||
impl BlockContext<'_> {
|
||||
fn gen_id(&mut self) -> Word {
|
||||
self.writer.id_gen.next()
|
||||
}
|
||||
|
||||
fn get_expression_type_id(&mut self, tr: &TypeResolution) -> Result<Word, Error> {
|
||||
self.writer.get_expression_type_id(tr)
|
||||
}
|
||||
|
||||
fn get_index_constant(&mut self, index: Word) -> Result<Word, Error> {
|
||||
self.writer
|
||||
.get_constant_scalar(crate::ScalarValue::Uint(index as _), 4)
|
||||
}
|
||||
|
||||
fn cached(&self, expression: Handle<crate::Expression>) -> Word {
|
||||
self.writer.cached[expression]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Default)]
|
||||
struct LoopContext {
|
||||
continuing_id: Option<Word>,
|
||||
break_id: Option<Word>,
|
||||
}
|
||||
|
||||
pub struct Writer {
|
||||
physical_layout: PhysicalLayout,
|
||||
logical_layout: LogicalLayout,
|
||||
|
||||
+8
-1661
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user