Skip to content

Commit 22e341b

Browse files
committed
wgsl: handle RayDesc/RayIntersection at the type decl level instead of an AST constructor
1 parent ab9c364 commit 22e341b

File tree

5 files changed

+38
-29
lines changed

5 files changed

+38
-29
lines changed

src/front/wgsl/lower/construction.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,6 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
660660
});
661661
ConcreteConstructorHandle::Type(ty)
662662
}
663-
ast::ConstructorType::RayDesc => {
664-
let ty = ctx.module.generate_ray_desc_type();
665-
ConcreteConstructorHandle::Type(ty)
666-
}
667663
ast::ConstructorType::Type(ty) => ConcreteConstructorHandle::Type(ty),
668664
};
669665

src/front/wgsl/lower/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,21 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
637637
module: &mut module,
638638
};
639639

640-
for decl in self.index.visit_ordered() {
641-
let span = tu.decls.get_span(decl);
642-
let decl = &tu.decls[decl];
640+
for decl_handle in self.index.visit_ordered() {
641+
let span = tu.decls.get_span(decl_handle);
642+
let decl = &tu.decls[decl_handle];
643+
644+
//TODO: find a nicer way?
645+
if let Some(dep) = decl.dependencies.iter().find(|dep| dep.ident == "RayDesc") {
646+
let ty_handle = ctx.module.generate_ray_desc_type();
647+
ctx.globals
648+
.insert(dep.ident, LoweredGlobalDecl::Type(ty_handle));
649+
}
643650

644651
match decl.kind {
645652
ast::GlobalDeclKind::Fn(ref f) => {
646-
let decl = self.function(f, span, ctx.reborrow())?;
647-
ctx.globals.insert(f.name.name, decl);
653+
let lowered_decl = self.function(f, span, ctx.reborrow())?;
654+
ctx.globals.insert(f.name.name, lowered_decl);
648655
}
649656
ast::GlobalDeclKind::Var(ref v) => {
650657
let ty = self.resolve_ast_type(v.ty, ctx.reborrow())?;
@@ -2302,6 +2309,12 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
23022309
},
23032310
}
23042311
}
2312+
ast::Type::RayDesc => {
2313+
return Ok(ctx.module.generate_ray_desc_type());
2314+
}
2315+
ast::Type::RayIntersection => {
2316+
return Ok(ctx.module.generate_ray_intersection_type());
2317+
}
23052318
ast::Type::User(ref ident) => {
23062319
return match ctx.globals.get(ident.name) {
23072320
Some(&LoweredGlobalDecl::Type(handle)) => Ok(handle),

src/front/wgsl/parse/ast.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ pub enum Type<'a> {
231231
},
232232
AccelerationStructure,
233233
RayQuery,
234+
RayDesc,
235+
RayIntersection,
234236
BindingArray {
235237
base: Handle<Type<'a>>,
236238
size: ArraySize<'a>,
@@ -370,9 +372,6 @@ pub enum ConstructorType<'a> {
370372
size: ArraySize<'a>,
371373
},
372374

373-
/// Ray description.
374-
RayDesc,
375-
376375
/// Constructing a value of a known Naga IR type.
377376
///
378377
/// This variant is produced only during lowering, when we have Naga types

src/front/wgsl/parse/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ impl Parser {
441441
}))
442442
}
443443
"array" => ast::ConstructorType::PartialArray,
444-
"RayDesc" => ast::ConstructorType::RayDesc,
445444
"atomic"
446445
| "binding_array"
447446
| "sampler"
@@ -1382,6 +1381,8 @@ impl Parser {
13821381
}
13831382
"acceleration_structure" => ast::Type::AccelerationStructure,
13841383
"ray_query" => ast::Type::RayQuery,
1384+
"RayDesc" => ast::Type::RayDesc,
1385+
"RayIntersection" => ast::Type::RayIntersection,
13851386
_ => return Ok(None),
13861387
}))
13871388
}

tests/out/spv/ray-query.spvasm

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ OpMemoryModel Logical GLSL450
1010
OpEntryPoint GLCompute %29 "main" %21 %23
1111
OpExecutionMode %29 LocalSize 1 1 1
1212
OpMemberDecorate %13 0 Offset 0
13-
OpMemberDecorate %16 0 Offset 0
14-
OpMemberDecorate %16 1 Offset 4
15-
OpMemberDecorate %16 2 Offset 8
16-
OpMemberDecorate %16 3 Offset 12
17-
OpMemberDecorate %16 4 Offset 16
18-
OpMemberDecorate %16 5 Offset 32
13+
OpMemberDecorate %15 0 Offset 0
14+
OpMemberDecorate %15 1 Offset 4
15+
OpMemberDecorate %15 2 Offset 8
16+
OpMemberDecorate %15 3 Offset 12
17+
OpMemberDecorate %15 4 Offset 16
18+
OpMemberDecorate %15 5 Offset 32
1919
OpMemberDecorate %20 0 Offset 0
2020
OpMemberDecorate %20 1 Offset 4
2121
OpMemberDecorate %20 2 Offset 8
@@ -49,19 +49,19 @@ OpMemberDecorate %24 0 Offset 0
4949
%11 = OpConstant %4 0
5050
%12 = OpTypeAccelerationStructureNV
5151
%13 = OpTypeStruct %4
52-
%14 = OpTypeRayQueryKHR
53-
%15 = OpTypeVector %7 3
54-
%16 = OpTypeStruct %4 %4 %7 %7 %15 %15
52+
%14 = OpTypeVector %7 3
53+
%15 = OpTypeStruct %4 %4 %7 %7 %14 %14
54+
%16 = OpTypeRayQueryKHR
5555
%17 = OpTypeVector %7 2
5656
%18 = OpTypeBool
57-
%19 = OpTypeMatrix %15 4
57+
%19 = OpTypeMatrix %14 4
5858
%20 = OpTypeStruct %4 %7 %4 %4 %4 %4 %4 %17 %18 %19 %19
5959
%22 = OpTypePointer UniformConstant %12
6060
%21 = OpVariable %22 UniformConstant
6161
%24 = OpTypeStruct %13
6262
%25 = OpTypePointer StorageBuffer %24
6363
%23 = OpVariable %25 StorageBuffer
64-
%27 = OpTypePointer Function %14
64+
%27 = OpTypePointer Function %16
6565
%30 = OpTypeFunction %2
6666
%32 = OpTypePointer StorageBuffer %13
6767
%45 = OpConstant %4 1
@@ -73,15 +73,15 @@ OpMemberDecorate %24 0 Offset 0
7373
%33 = OpAccessChain %32 %23 %11
7474
OpBranch %34
7575
%34 = OpLabel
76-
%35 = OpCompositeConstruct %15 %9 %9 %9
77-
%36 = OpCompositeConstruct %15 %9 %10 %9
78-
%37 = OpCompositeConstruct %16 %3 %5 %6 %8 %35 %36
76+
%35 = OpCompositeConstruct %14 %9 %9 %9
77+
%36 = OpCompositeConstruct %14 %9 %10 %9
78+
%37 = OpCompositeConstruct %15 %3 %5 %6 %8 %35 %36
7979
%38 = OpCompositeExtract %4 %37 0
8080
%39 = OpCompositeExtract %4 %37 1
8181
%40 = OpCompositeExtract %7 %37 2
8282
%41 = OpCompositeExtract %7 %37 3
83-
%42 = OpCompositeExtract %15 %37 4
84-
%43 = OpCompositeExtract %15 %37 5
83+
%42 = OpCompositeExtract %14 %37 4
84+
%43 = OpCompositeExtract %14 %37 5
8585
OpRayQueryInitializeKHR %26 %31 %38 %39 %42 %40 %43 %41
8686
%44 = OpRayQueryProceedKHR %18 %26
8787
%46 = OpRayQueryGetIntersectionTypeKHR %4 %26 %45

0 commit comments

Comments
 (0)