summaryrefslogtreecommitdiff
path: root/engine/src/rendering/shader.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/rendering/shader.rs')
-rw-r--r--engine/src/rendering/shader.rs78
1 files changed, 61 insertions, 17 deletions
diff --git a/engine/src/rendering/shader.rs b/engine/src/rendering/shader.rs
index 3f07381..085773b 100644
--- a/engine/src/rendering/shader.rs
+++ b/engine/src/rendering/shader.rs
@@ -70,6 +70,7 @@ pub struct Module
impl Module
{
+ #[must_use]
pub fn entry_points(&self) -> impl ExactSizeIterator<Item = EntryPoint> + use<'_>
{
self.inner
@@ -77,6 +78,7 @@ impl Module
.map(|entry_point| EntryPoint { inner: entry_point })
}
+ #[must_use]
pub fn get_entry_point(&self, entry_point: &str) -> Option<EntryPoint>
{
let entry_point = self.inner.find_entry_point_by_name(entry_point)?;
@@ -84,6 +86,7 @@ impl Module
Some(EntryPoint { inner: entry_point })
}
+ #[must_use]
pub fn file_path(&self) -> &str
{
self.inner.file_path()
@@ -97,6 +100,7 @@ pub struct EntryPoint
impl EntryPoint
{
+ #[must_use]
pub fn function(&self) -> FunctionReflection<'_>
{
FunctionReflection {
@@ -110,8 +114,9 @@ pub struct FunctionReflection<'a>
inner: &'a shader_slang::reflection::Function,
}
-impl<'a> FunctionReflection<'a>
+impl FunctionReflection<'_>
{
+ #[must_use]
pub fn name(&self) -> Option<&str>
{
self.inner.name()
@@ -125,21 +130,25 @@ pub struct EntryPointReflection<'a>
impl<'a> EntryPointReflection<'a>
{
+ #[must_use]
pub fn name(&self) -> Option<&str>
{
self.inner.name()
}
+ #[must_use]
pub fn name_override(&self) -> Option<&str>
{
self.inner.name_override()
}
+ #[must_use]
pub fn stage(&self) -> Stage
{
Stage::from_slang_stage(self.inner.stage())
}
+ #[must_use]
pub fn parameters(&self) -> impl ExactSizeIterator<Item = VariableLayout<'a>>
{
self.inner
@@ -147,6 +156,7 @@ impl<'a> EntryPointReflection<'a>
.map(|param| VariableLayout { inner: param })
}
+ #[must_use]
pub fn var_layout(&self) -> Option<VariableLayout<'a>>
{
Some(VariableLayout { inner: self.inner.var_layout()? })
@@ -172,6 +182,7 @@ impl Program
})
}
+ #[must_use]
pub fn metadata(&self) -> &ProgramMetadata
{
&self.metadata
@@ -186,7 +197,7 @@ impl Program
pub fn reflection(&self, target: u32) -> Result<ProgramReflection<'_>, Error>
{
- let reflection = self.inner.layout(target as i64)?;
+ let reflection = self.inner.layout(i64::from(target))?;
Ok(ProgramReflection { inner: reflection })
}
@@ -209,6 +220,7 @@ pub struct ProgramReflection<'a>
impl<'a> ProgramReflection<'a>
{
+ #[must_use]
pub fn get_entry_point_by_index(&self, index: u32)
-> Option<EntryPointReflection<'a>>
{
@@ -217,6 +229,7 @@ impl<'a> ProgramReflection<'a>
})
}
+ #[must_use]
pub fn get_entry_point_by_name(&self, name: &str)
-> Option<EntryPointReflection<'a>>
{
@@ -225,6 +238,7 @@ impl<'a> ProgramReflection<'a>
})
}
+ #[must_use]
pub fn entry_points(
&self,
) -> impl ExactSizeIterator<Item = EntryPointReflection<'a>> + use<'a>
@@ -234,6 +248,7 @@ impl<'a> ProgramReflection<'a>
.map(|entry_point| EntryPointReflection { inner: entry_point })
}
+ #[must_use]
pub fn global_params_type_layout(&self) -> Option<TypeLayout<'a>>
{
Some(TypeLayout {
@@ -241,6 +256,7 @@ impl<'a> ProgramReflection<'a>
})
}
+ #[must_use]
pub fn global_params_var_layout(&self) -> Option<VariableLayout<'a>>
{
Some(VariableLayout {
@@ -248,6 +264,7 @@ impl<'a> ProgramReflection<'a>
})
}
+ #[must_use]
pub fn get_type(&self, name: &str) -> Option<TypeReflection<'a>>
{
Some(TypeReflection {
@@ -255,12 +272,13 @@ impl<'a> ProgramReflection<'a>
})
}
+ #[must_use]
pub fn get_type_layout(&self, ty: &TypeReflection<'a>) -> Option<TypeLayout<'a>>
{
Some(TypeLayout {
inner: self
.inner
- .type_layout(&ty.inner, shader_slang::LayoutRules::Default)?,
+ .type_layout(ty.inner, shader_slang::LayoutRules::Default)?,
})
}
}
@@ -273,16 +291,19 @@ pub struct VariableLayout<'a>
impl<'a> VariableLayout<'a>
{
+ #[must_use]
pub fn name(&self) -> Option<&'a str>
{
self.inner.name()
}
+ #[must_use]
pub fn semantic_name(&self) -> Option<&str>
{
self.inner.semantic_name()
}
+ #[must_use]
pub fn binding_index(&self) -> u32
{
self.inner
@@ -291,6 +312,7 @@ impl<'a> VariableLayout<'a>
// self.inner.binding_index()
}
+ #[must_use]
pub fn varying_input_offset(&self) -> Option<usize>
{
if !self
@@ -304,26 +326,31 @@ impl<'a> VariableLayout<'a>
Some(self.inner.offset(SlangParameterCategory::VaryingInput))
}
+ #[must_use]
pub fn binding_space(&self) -> u32
{
self.inner.binding_space()
}
+ #[must_use]
pub fn semantic_index(&self) -> usize
{
self.inner.semantic_index()
}
+ #[must_use]
pub fn offset(&self) -> usize
{
self.inner.offset(shader_slang::ParameterCategory::Uniform)
}
+ #[must_use]
pub fn ty(&self) -> Option<TypeReflection<'a>>
{
self.inner.ty().map(|ty| TypeReflection { inner: ty })
}
+ #[must_use]
pub fn type_layout(&self) -> Option<TypeLayout<'a>>
{
Some(TypeLayout { inner: self.inner.type_layout()? })
@@ -338,11 +365,13 @@ pub struct TypeLayout<'a>
impl<'a> TypeLayout<'a>
{
+ #[must_use]
pub fn kind(&self) -> TypeKind
{
TypeKind::from_slang_type_kind(self.inner.kind())
}
+ #[must_use]
pub fn scalar_type(&self) -> Option<ScalarType>
{
Some(ScalarType::from_slang_scalar_type(
@@ -350,6 +379,7 @@ impl<'a> TypeLayout<'a>
))
}
+ #[must_use]
pub fn resource_shape(&self) -> Option<ResourceShape>
{
Some(ResourceShape::from_bits_retain(
@@ -357,6 +387,7 @@ impl<'a> TypeLayout<'a>
))
}
+ #[must_use]
pub fn get_field_by_name(&self, name: &str) -> Option<VariableLayout<'a>>
{
let index = self.inner.find_field_index_by_name(name);
@@ -372,16 +403,19 @@ impl<'a> TypeLayout<'a>
Some(VariableLayout { inner: field })
}
+ #[must_use]
pub fn parameter_category(&self) -> ParameterCategory
{
ParameterCategory::from_slang_parameter_category(self.inner.parameter_category())
}
+ #[must_use]
pub fn binding_range_descriptor_set_index(&self, index: i64) -> i64
{
self.inner.binding_range_descriptor_set_index(index)
}
+ #[must_use]
pub fn get_field_binding_range_offset_by_name(&self, name: &str) -> Option<u64>
{
let field_index = self.inner.find_field_index_by_name(name);
@@ -400,40 +434,47 @@ impl<'a> TypeLayout<'a>
Some(field_binding_range_offset.cast_unsigned())
}
+ #[must_use]
pub fn ty(&self) -> Option<TypeReflection<'a>>
{
self.inner.ty().map(|ty| TypeReflection { inner: ty })
}
+ #[must_use]
pub fn fields(&self) -> FieldIter<'a>
{
FieldIter {
- type_layout: self.clone(),
+ type_layout: *self,
cnt: self.field_cnt(),
index: 0,
}
}
+ #[must_use]
pub fn field_cnt(&self) -> u32
{
self.inner.field_count()
}
+ #[must_use]
pub fn element_cnt(&self) -> Option<usize>
{
self.inner.element_count()
}
+ #[must_use]
pub fn row_cnt(&self) -> Option<u32>
{
self.inner.row_count()
}
+ #[must_use]
pub fn column_cnt(&self) -> Option<u32>
{
self.inner.column_count()
}
+ #[must_use]
pub fn element_type_layout(&self) -> Option<TypeLayout<'a>>
{
self.inner
@@ -441,6 +482,7 @@ impl<'a> TypeLayout<'a>
.map(|type_layout| TypeLayout { inner: type_layout })
}
+ #[must_use]
pub fn element_var_layout(&self) -> Option<VariableLayout<'a>>
{
self.inner
@@ -448,6 +490,7 @@ impl<'a> TypeLayout<'a>
.map(|var_layout| VariableLayout { inner: var_layout })
}
+ #[must_use]
pub fn container_var_layout(&self) -> Option<VariableLayout<'a>>
{
self.inner
@@ -455,6 +498,7 @@ impl<'a> TypeLayout<'a>
.map(|var_layout| VariableLayout { inner: var_layout })
}
+ #[must_use]
pub fn uniform_size(&self) -> Option<usize>
{
// tracing::debug!(
@@ -483,6 +527,7 @@ impl<'a> TypeLayout<'a>
Some(self.inner.size(SlangParameterCategory::Uniform))
}
+ #[must_use]
pub fn stride(&self) -> usize
{
self.inner.stride(self.inner.categories().next().unwrap())
@@ -556,6 +601,7 @@ pub struct TypeReflection<'a>
impl TypeReflection<'_>
{
+ #[must_use]
pub fn kind(&self) -> TypeKind
{
TypeKind::from_slang_type_kind(self.inner.kind())
@@ -787,6 +833,7 @@ pub struct Blob
impl Blob
{
+ #[must_use]
pub fn as_bytes(&self) -> &[u8]
{
self.inner.as_slice()
@@ -868,11 +915,13 @@ pub struct Context
impl Context
{
+ #[must_use]
pub fn get_module(&self, asset_id: &AssetId) -> Option<&Module>
{
self.modules.get(asset_id)
}
+ #[must_use]
pub fn get_program(&self, asset_id: &AssetId) -> Option<&Program>
{
self.programs.get(asset_id)
@@ -1008,19 +1057,13 @@ impl VertexDescription
);
}
- let scalar_type = match (
+ let (TypeKind::Scalar | TypeKind::Vector, Some(scalar_type)) = (
var_input.type_layout.kind(),
var_input.type_layout.scalar_type(),
- ) {
- (TypeKind::Scalar, Some(scalar_type)) => scalar_type,
- (TypeKind::Vector, Some(scalar_type)) => scalar_type,
- _ => {
- return Err(
- VertexDescriptionError::UnsupportedVertexInputType {
- name: name.to_owned(),
- },
- );
- }
+ ) else {
+ return Err(VertexDescriptionError::UnsupportedVertexInputType {
+ name: name.to_owned(),
+ });
};
seen_inputs.insert(semantic_name.clone());
@@ -1072,6 +1115,7 @@ impl VertexInputSemName
}
}
+ #[must_use]
pub fn matches_vertex_label(&self, vertex_label: &VertexLabel) -> bool
{
match (self, vertex_label) {
@@ -1291,7 +1335,7 @@ pub(super) fn prepare(collector: &mut crate::ecs::extension::Collector<'_>)
let session_desc = shader_slang::SessionDesc::default()
.targets(&targets)
- .search_paths(&[""])
+ .search_paths([""])
.options(&session_options);
let Some(session) = global_session.create_session(&session_desc) else {
@@ -1359,7 +1403,7 @@ fn load_modules(
context.modules.insert(*asset_id, module.clone());
if !module_source.link_entrypoints.is_empty() {
- assert!(context.programs.get(asset_id).is_none());
+ assert!(!context.programs.contains_key(asset_id));
let shader_program = match context
.compose_into_program(module, module_source.link_entrypoints)