summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-08-06 15:30:25 +0200
committerHampusM <hampus@hampusmat.com>2026-08-06 15:30:25 +0200
commit6471a831e3a929a6922297d4b6176eb43c20b4bd (patch)
tree6545c605251a408da13b560de3ec76731b3d020b
parentcb43fefd72f97e4ee639968042fdba4bcb8c154c (diff)
fix(engine): prevent sometimes incorrect shader field binding indices
-rw-r--r--engine/src/rendering/shader/cursor.rs33
1 files changed, 20 insertions, 13 deletions
diff --git a/engine/src/rendering/shader/cursor.rs b/engine/src/rendering/shader/cursor.rs
index ba8bed7..0f985a7 100644
--- a/engine/src/rendering/shader/cursor.rs
+++ b/engine/src/rendering/shader/cursor.rs
@@ -53,18 +53,27 @@ impl<'a> Cursor<'a>
let field_type_kind = field_var_layout.ty().unwrap().kind();
- let field_var_layout = match field_type_kind {
- TypeKind::ConstantBuffer => field_var_layout
- .type_layout()
- .expect("Constant buffer field has no type layout")
- .element_var_layout()
- .expect("Constant buffer field type layout has no element var layout"),
+ let (new_var_layout, binding_index_offset) = match field_type_kind {
+ TypeKind::ConstantBuffer => {
+ let elem_var_layout = field_var_layout
+ .type_layout()
+ .expect("Constant buffer field has no type layout")
+ .element_var_layout()
+ .expect(
+ "Constant buffer field type layout has no element var layout",
+ );
+
+ (
+ elem_var_layout,
+ field_var_layout.binding_index() + elem_var_layout.binding_index(),
+ )
+ }
TypeKind::Array
| TypeKind::Matrix
| TypeKind::Scalar
| TypeKind::Vector
| TypeKind::Struct
- | TypeKind::Resource => field_var_layout,
+ | TypeKind::Resource => (field_var_layout, field_var_layout.binding_index()),
type_kind => unimplemented!("Type kind {type_kind:?} is not yet supported"),
};
@@ -73,12 +82,11 @@ impl<'a> Cursor<'a>
location_path.push(Location::Field(name));
Self {
- type_layout: field_var_layout.type_layout().unwrap(),
+ type_layout: new_var_layout.type_layout().unwrap(),
binding_location: BindingLocation {
- binding_index: self.binding_location.binding_index
- + field_var_layout.binding_index(),
+ binding_index: self.binding_location.binding_index + binding_index_offset,
binding_size: if field_type_kind == TypeKind::ConstantBuffer {
- field_var_layout
+ new_var_layout
.type_layout()
.unwrap()
.uniform_size()
@@ -86,8 +94,7 @@ impl<'a> Cursor<'a>
} else {
self.binding_location.binding_size
},
- byte_offset: self.binding_location.byte_offset
- + field_var_layout.offset(),
+ byte_offset: self.binding_location.byte_offset + new_var_layout.offset(),
},
location_path,
}