1414#define OFFLOADTEST_SUPPORT_PIPELINE_H
1515
1616#include " API/Enums.h"
17+ #include " API/Resources.h"
1718#include " llvm/ADT/SmallVector.h"
1819#include " llvm/ADT/StringRef.h"
1920#include " llvm/Support/Error.h"
@@ -92,6 +93,8 @@ static inline DescriptorKind getDescriptorKind(ResourceKind RK) {
9293 return DescriptorKind::SAMPLER ;
9394 case ResourceKind::SampledTexture2D:
9495 llvm_unreachable (" Sampled textures aren't supported!" );
96+ case ResourceKind::AccelerationStructure:
97+ return DescriptorKind::SRV ;
9598 }
9699 llvm_unreachable (" All cases handled" );
97100}
@@ -218,6 +221,8 @@ struct Result {
218221 double Epsilon;
219222};
220223
224+ struct TLASDesc ;
225+
221226struct Resource {
222227 ResourceKind Kind;
223228 std::string Name;
@@ -228,6 +233,11 @@ struct Resource {
228233 bool HasCounter;
229234 std::optional<uint32_t > TilesMapped;
230235 bool IsReserved = false ;
236+ TLASDesc *TLASPtr = nullptr ;
237+
238+ bool isAccelerationStructure () const {
239+ return Kind == ResourceKind::AccelerationStructure;
240+ }
231241
232242 bool isRaw () const {
233243 switch (Kind) {
@@ -237,6 +247,7 @@ struct Resource {
237247 case ResourceKind::RWTexture2D:
238248 case ResourceKind::Sampler:
239249 case ResourceKind::SampledTexture2D:
250+ case ResourceKind::AccelerationStructure:
240251 return false ;
241252 case ResourceKind::StructuredBuffer:
242253 case ResourceKind::RWStructuredBuffer:
@@ -262,6 +273,7 @@ struct Resource {
262273 case ResourceKind::Texture2D:
263274 case ResourceKind::RWTexture2D:
264275 case ResourceKind::SampledTexture2D:
276+ case ResourceKind::AccelerationStructure:
265277 return false ;
266278 }
267279 llvm_unreachable (" All cases handled" );
@@ -277,6 +289,7 @@ struct Resource {
277289 case ResourceKind::RWByteAddressBuffer:
278290 case ResourceKind::ConstantBuffer:
279291 case ResourceKind::Sampler:
292+ case ResourceKind::AccelerationStructure:
280293 return false ;
281294 case ResourceKind::Texture2D:
282295 case ResourceKind::RWTexture2D:
@@ -316,18 +329,22 @@ struct Resource {
316329 }
317330
318331 uint32_t getElementSize () const {
319- assert (!isSampler () && " Samplers do not have element size" );
332+ assert (!isSampler () && !isAccelerationStructure () &&
333+ " Samplers and AS do not have element size" );
320334 // ByteAddressBuffers are treated as 4-byte elements to match their memory
321335 // format.
322336 return isByteAddressBuffer () ? 4 : BufferPtr->getElementSize ();
323337 }
324338
325339 uint32_t getArraySize () const {
326- return isSampler () ? 1 : BufferPtr->ArraySize ;
340+ if (isSampler () || isAccelerationStructure ())
341+ return 1 ;
342+ return BufferPtr->ArraySize ;
327343 }
328344
329345 uint32_t size () const {
330- assert (!isSampler () && " Samplers do not have size" );
346+ assert (!isSampler () && !isAccelerationStructure () &&
347+ " Samplers and AS do not have size" );
331348 return BufferPtr->size ();
332349 }
333350
@@ -340,6 +357,7 @@ struct Resource {
340357 case ResourceKind::ConstantBuffer:
341358 case ResourceKind::Sampler:
342359 case ResourceKind::SampledTexture2D:
360+ case ResourceKind::AccelerationStructure:
343361 return false ;
344362 case ResourceKind::RWBuffer:
345363 case ResourceKind::RWStructuredBuffer:
@@ -456,6 +474,53 @@ struct DispatchParametersSet {
456474 std::optional<uint32_t > VertexCount;
457475};
458476
477+ enum class IndexFormat { Uint16, Uint32 };
478+
479+ struct TriangleGeometry {
480+ std::string VertexBuffer;
481+ CPUBuffer *VertexBufferPtr = nullptr ;
482+ Format VertexFormat = Format::RGB32Float;
483+ uint32_t VertexStride = 12 ;
484+ uint32_t VertexCount = 0 ;
485+ std::string IndexBuffer;
486+ CPUBuffer *IndexBufferPtr = nullptr ;
487+ IndexFormat IdxFormat = IndexFormat::Uint32;
488+ uint32_t IndexCount = 0 ;
489+ bool Opaque = true ;
490+ };
491+
492+ struct AABBGeometry {
493+ std::string AABBBuffer;
494+ CPUBuffer *AABBBufferPtr = nullptr ;
495+ uint32_t AABBCount = 0 ;
496+ uint32_t AABBStride = 24 ;
497+ bool Opaque = true ;
498+ };
499+
500+ struct BLASDesc {
501+ std::string Name;
502+ llvm::SmallVector<TriangleGeometry> Triangles;
503+ llvm::SmallVector<AABBGeometry> AABBs;
504+ };
505+
506+ struct InstanceDesc {
507+ std::string BLAS ;
508+ int BLASIdx = -1 ;
509+ float Transform[12 ] = {1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 };
510+ uint32_t InstanceID = 0 ;
511+ uint8_t InstanceMask = 0xFF ;
512+ };
513+
514+ struct TLASDesc {
515+ std::string Name;
516+ llvm::SmallVector<InstanceDesc> Instances;
517+ };
518+
519+ struct AccelerationStructureDescs {
520+ llvm::SmallVector<BLASDesc> BLAS ;
521+ llvm::SmallVector<TLASDesc> TLAS ;
522+ };
523+
459524struct Pipeline {
460525 ShaderPipelineKind Kind;
461526 llvm::SmallVector<Shader> Shaders;
@@ -468,6 +533,7 @@ struct Pipeline {
468533 llvm::SmallVector<Result> Results;
469534 llvm::SmallVector<DescriptorSet> Sets;
470535 DispatchParametersSet DispatchParameters;
536+ AccelerationStructureDescs AccelStructs;
471537
472538 uint32_t getVertexCount () const {
473539 if (DispatchParameters.VertexCount )
@@ -508,6 +574,20 @@ struct Pipeline {
508574 return nullptr ;
509575 }
510576
577+ BLASDesc *getBLAS (llvm::StringRef Name) {
578+ for (auto &B : AccelStructs.BLAS )
579+ if (Name == B.Name )
580+ return &B;
581+ return nullptr ;
582+ }
583+
584+ TLASDesc *getTLAS (llvm::StringRef Name) {
585+ for (auto &T : AccelStructs.TLAS )
586+ if (Name == T.Name )
587+ return &T;
588+ return nullptr ;
589+ }
590+
511591 llvm::Error validatePipelineKind ();
512592 llvm::Error validateDispatchParameters ();
513593
@@ -536,6 +616,11 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::SpecializationConstant)
536616LLVM_YAML_IS_SEQUENCE_VECTOR (offloadtest::PushConstantBlock)
537617LLVM_YAML_IS_SEQUENCE_VECTOR (offloadtest::PushConstantValue)
538618LLVM_YAML_IS_SEQUENCE_VECTOR (offloadtest::DispatchParametersSet)
619+ LLVM_YAML_IS_SEQUENCE_VECTOR (offloadtest::TriangleGeometry)
620+ LLVM_YAML_IS_SEQUENCE_VECTOR (offloadtest::AABBGeometry)
621+ LLVM_YAML_IS_SEQUENCE_VECTOR (offloadtest::BLASDesc)
622+ LLVM_YAML_IS_SEQUENCE_VECTOR (offloadtest::InstanceDesc)
623+ LLVM_YAML_IS_SEQUENCE_VECTOR (offloadtest::TLASDesc)
539624
540625namespace llvm {
541626namespace yaml {
@@ -620,6 +705,30 @@ template <> struct MappingTraits<offloadtest::SpecializationConstant> {
620705 static void mapping (IO &I, offloadtest::SpecializationConstant &C);
621706};
622707
708+ template <> struct MappingTraits <offloadtest::TriangleGeometry> {
709+ static void mapping (IO &I, offloadtest::TriangleGeometry &G);
710+ };
711+
712+ template <> struct MappingTraits <offloadtest::AABBGeometry> {
713+ static void mapping (IO &I, offloadtest::AABBGeometry &G);
714+ };
715+
716+ template <> struct MappingTraits <offloadtest::BLASDesc> {
717+ static void mapping (IO &I, offloadtest::BLASDesc &D);
718+ };
719+
720+ template <> struct MappingTraits <offloadtest::InstanceDesc> {
721+ static void mapping (IO &I, offloadtest::InstanceDesc &D);
722+ };
723+
724+ template <> struct MappingTraits <offloadtest::TLASDesc> {
725+ static void mapping (IO &I, offloadtest::TLASDesc &D);
726+ };
727+
728+ template <> struct MappingTraits <offloadtest::AccelerationStructureDescs> {
729+ static void mapping (IO &I, offloadtest::AccelerationStructureDescs &D);
730+ };
731+
623732template <> struct ScalarEnumerationTraits <offloadtest::Rule> {
624733 static void enumeration (IO &I, offloadtest::Rule &V) {
625734#define ENUM_CASE (Val ) I.enumCase(V, #Val, offloadtest::Rule::Val)
@@ -721,6 +830,41 @@ template <> struct ScalarEnumerationTraits<offloadtest::ResourceKind> {
721830 ENUM_CASE (ConstantBuffer);
722831 ENUM_CASE (Sampler);
723832 ENUM_CASE (SampledTexture2D);
833+ ENUM_CASE (AccelerationStructure);
834+ #undef ENUM_CASE
835+ }
836+ };
837+
838+ template <> struct ScalarEnumerationTraits <offloadtest::Format> {
839+ static void enumeration (IO &I, offloadtest::Format &V) {
840+ #define ENUM_CASE (Val ) I.enumCase(V, #Val, offloadtest::Format::Val)
841+ ENUM_CASE (R16Sint);
842+ ENUM_CASE (R16Uint);
843+ ENUM_CASE (RG16Sint);
844+ ENUM_CASE (RG16Uint);
845+ ENUM_CASE (RGBA16Sint);
846+ ENUM_CASE (RGBA16Uint);
847+ ENUM_CASE (R32Sint);
848+ ENUM_CASE (R32Uint);
849+ ENUM_CASE (R32Float);
850+ ENUM_CASE (RG32Sint);
851+ ENUM_CASE (RG32Uint);
852+ ENUM_CASE (RG32Float);
853+ ENUM_CASE (RGB32Float);
854+ ENUM_CASE (RGBA32Sint);
855+ ENUM_CASE (RGBA32Uint);
856+ ENUM_CASE (RGBA32Float);
857+ ENUM_CASE (D32Float);
858+ ENUM_CASE (D32FloatS8Uint);
859+ #undef ENUM_CASE
860+ }
861+ };
862+
863+ template <> struct ScalarEnumerationTraits <offloadtest::IndexFormat> {
864+ static void enumeration (IO &I, offloadtest::IndexFormat &V) {
865+ #define ENUM_CASE (Val ) I.enumCase(V, #Val, offloadtest::IndexFormat::Val)
866+ ENUM_CASE (Uint16);
867+ ENUM_CASE (Uint32);
724868#undef ENUM_CASE
725869 }
726870};
0 commit comments