Skip to content

Commit

Permalink
[naga] Make compaction preserve named types, even if unused.
Browse files Browse the repository at this point in the history
Have `compact::compact` preserve entries in the `Module::types` arena
if they have names.

Future abstract type support will require the WGSL front end to
compact the module before validation. Without this change, that will
drop `alias` declarations, making it harder to test type validation.
  • Loading branch information
jimblandy committed Nov 21, 2023
1 parent 42058cf commit bf5dc64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions naga/src/compact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ pub fn compact(module: &mut crate::Module) {
}
}

// Treat all named types as used.
for (handle, ty) in module.types.iter() {
log::trace!("tracing type {:?}, name {:?}", handle, ty.name);
if ty.name.is_some() {
module_tracer.types_used.insert(handle);
}
}

// Propagate usage through types.
module_tracer.as_type().trace_types();

Expand Down
19 changes: 17 additions & 2 deletions naga/tests/out/spv/runtime-array-in-unused-struct.spvasm
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
; SPIR-V
; Version: 1.1
; Generator: rspirv
; Bound: 3
; Bound: 10
OpCapability Shader
OpCapability Linkage
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
%2 = OpTypeVoid
OpMemberDecorate %5 0 Offset 0
OpMemberDecorate %5 1 Offset 16
OpDecorate %6 ArrayStride 32
OpMemberDecorate %7 0 Offset 0
OpDecorate %7 Block
OpDecorate %8 ArrayStride 4
OpMemberDecorate %9 0 Offset 0
OpDecorate %9 Block
%2 = OpTypeVoid
%3 = OpTypeFloat 32
%4 = OpTypeVector %3 4
%5 = OpTypeStruct %3 %4
%6 = OpTypeRuntimeArray %5
%7 = OpTypeStruct %6
%8 = OpTypeRuntimeArray %3
%9 = OpTypeStruct %8

0 comments on commit bf5dc64

Please sign in to comment.