yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
8f20632a0
master
1// render.h 2#pragma once 3 4#include "slang-com-ptr.h" 5#include "slang.h" 6 7#include <assert.h> 8#include <float.h> 9 10 11#if defined(SLANG_GFX_DYNAMIC ) 12#if defined(_MSC_VER ) 13#ifdef SLANG_GFX_DYNAMIC_EXPORT 14#define SLANG_GFX_API SLANG_DLL_EXPORT 15#else 16#define SLANG_GFX_API __declspec(dllimport) 17#endif 18#else 19// TODO: need to consider compiler capabilities 20// # ifdef SLANG_DYNAMIC_EXPORT 21#define SLANG_GFX_API SLANG_DLL_EXPORT 22// # endif 23#endif 24#endif 25 26#ifndef SLANG_GFX_API 27#define SLANG_GFX_API 28#endif 29 30// Needed for building on cygwin with gcc 31#undef Always 32#undef None 33 34// GLOBAL TODO: doc comments 35// GLOBAL TODO: Rationalize integer types (not a smush of uint/int/Uint/Int/etc) 36// - need typedefs in gfx namespace for Count, Index, Size, Offset (ex. DeviceAddress) 37// - Index and Count are for arrays, and indexing into array - like things(XY coordinates of 38// pixels, etc.) 39// - Count is also for anything where we need to measure how many of something there are. 40// This includes things like extents. 41// - Offset and Size are almost always for bytes and things measured in bytes. 42namespace gfx 43{ 44 45using Slang ::ComPtr ; 46 47typedef SlangResult Result ; 48 49// Had to move here, because Options needs types defined here 50typedef SlangInt Int ; 51typedef SlangUInt UInt ; 52typedef uint64_t DeviceAddress ; 53typedef int GfxIndex ; 54typedef int GfxCount ; 55typedef size_t Size ; 56typedef size_t Offset ; 57 58const uint64_t kTimeoutInfinite = 0xFFFFFFFFFFFFFFFF ; 59 60enum class StructType 61{ 62D3D12DeviceExtendedDesc , 63D3D12ExperimentalFeaturesDesc , 64SlangSessionExtendedDesc , 65RayTracingValidationDesc 66}; 67 68// TODO: Rename to Stage 69enum class StageType 70{ 71Unknown , 72Vertex , 73Hull , 74Domain , 75Geometry , 76Fragment , 77Compute , 78RayGeneration , 79Intersection , 80AnyHit , 81ClosestHit , 82Miss , 83Callable , 84Amplification , 85Mesh , 86CountOf , 87}; 88 89// TODO: Implementation or backend or something else? 90enum class DeviceType 91{ 92Unknown , 93Default , 94DirectX11 , 95DirectX12 , 96OpenGl , 97Vulkan , 98Metal , 99CPU , 100CUDA , 101WebGPU , 102CountOf , 103}; 104 105// TODO: Why does this exist it should go poof 106enum class ProjectionStyle 107{ 108Unknown , 109OpenGl , 110DirectX , 111Vulkan , 112Metal , 113CountOf , 114}; 115 116// TODO: This should also go poof 117/// The style of the binding 118enum class BindingStyle 119{ 120Unknown , 121DirectX , 122OpenGl , 123Vulkan , 124Metal , 125CPU , 126CUDA , 127CountOf , 128}; 129 130// TODO: Is this actually a flag when there are no bit fields? 131enum class AccessFlag 132{ 133None , 134Read , 135Write , 136}; 137 138// TODO: Needed? Shouldn't be hard-coded if so 139const GfxCount kMaxRenderTargetCount = 8 ; 140 141class ITransientResourceHeap ; 142 143enum class ShaderModuleSourceType 144{ 145SlangSource ,// a slang source string in memory. 146SlangModuleBinary ,// a slang module binary code in memory. 147SlangSourceFile ,// a slang source from file. 148SlangModuleBinaryFile ,// a slang module binary code from file. 149}; 150 151class IShaderProgram :public ISlangUnknown 152{ 153public : 154// Defines how linking should be performed for a shader program. 155enum class LinkingStyle 156 { 157// Compose all entry-points in a single program, then compile all entry-points together with 158// the same set of root shader arguments. 159SingleProgram , 160 161// Link and compile each entry-point individually, potentially with different 162// specializations. 163SeparateEntryPointCompilation 164 }; 165 166enum class DownstreamLinkMode 167 { 168None , 169Deferred , 170 }; 171 172struct Desc 173 { 174// TODO: Tess doesn't like this but doesn't know what to do about it 175// The linking style of this program. 176LinkingStyle linkingStyle = LinkingStyle ::SingleProgram ; 177 178// The global scope or a Slang composite component that represents the entire program. 179slang ::IComponentType * slangGlobalScope ; 180 181// Number of separate entry point components in the `slangEntryPoints` array to link in. 182// If set to 0, then `slangGlobalScope` must contain Slang EntryPoint components. 183// If not 0, then `slangGlobalScope` must not contain any EntryPoint components. 184GfxCount entryPointCount = 0 ; 185 186// An array of Slang entry points. The size of the array must be `entryPointCount`. 187// Each element must define only 1 Slang EntryPoint. 188slang ::IComponentType ** slangEntryPoints = nullptr; 189 190// Indicates whether the app is responsible for final downstream linking. 191DownstreamLinkMode downstreamLinkMode = DownstreamLinkMode ::None ; 192 }; 193 194struct CreateDesc2 195 { 196ShaderModuleSourceType sourceType ; 197void * sourceData ; 198Size sourceDataSize ; 199 200// Number of entry points to include in the shader program. 0 means include all entry points 201// defined in the module. 202GfxCount entryPointCount = 0 ; 203// Names of entry points to include in the shader program. The size of the array must be 204// `entryPointCount`. 205const char ** entryPointNames = nullptr; 206 }; 207 208virtual SLANG_NO_THROW slang ::TypeReflection * SLANG_MCALL findTypeByName (const char * name )= 0 ; 209}; 210#define SLANG_UUID_IShaderProgram \ 211{ \ 2120x9d32d0ad, 0x915c, 0x4ffd, \ 213{ \ 2140x91, 0xe2, 0x50, 0x85, 0x54, 0xa0, 0x4a, 0x76 \ 215} \ 216} 217 218// TODO: Confirm with Yong that we really want this naming convention 219// TODO: Rename to what? 220// Dont' change without keeping in sync with Format 221// clang-format off 222#define GFX_FORMAT (x) \ 223x( Unknown, 0, 0) \ 224\ 225x(R32G32B32A32_TYPELESS, 16, 1) \ 226x(R32G32B32_TYPELESS, 12, 1) \ 227x(R32G32_TYPELESS, 8, 1) \ 228x(R32_TYPELESS, 4, 1) \ 229\ 230x(R16G16B16A16_TYPELESS, 8, 1) \ 231x(R16G16_TYPELESS, 4, 1) \ 232x(R16_TYPELESS, 2, 1) \ 233\ 234x(R8G8B8A8_TYPELESS, 4, 1) \ 235x(R8G8_TYPELESS, 2, 1) \ 236x(R8_TYPELESS, 1, 1) \ 237x(B8G8R8A8_TYPELESS, 4, 1) \ 238\ 239x(R32G32B32A32_FLOAT, 16, 1) \ 240x(R32G32B32_FLOAT, 12, 1) \ 241x(R32G32_FLOAT, 8, 1) \ 242x(R32_FLOAT, 4, 1) \ 243\ 244x(R16G16B16A16_FLOAT, 8, 1) \ 245x(R16G16_FLOAT, 4, 1) \ 246x(R16_FLOAT, 2, 1) \ 247\ 248x(R32G32B32A32_UINT, 16, 1) \ 249x(R32G32B32_UINT, 12, 1) \ 250x(R32G32_UINT, 8, 1) \ 251x(R32_UINT, 4, 1) \ 252\ 253x(R16G16B16A16_UINT, 8, 1) \ 254x(R16G16_UINT, 4, 1) \ 255x(R16_UINT, 2, 1) \ 256\ 257x(R8G8B8A8_UINT, 4, 1) \ 258x(R8G8_UINT, 2, 1) \ 259x(R8_UINT, 1, 1) \ 260\ 261x(R32G32B32A32_SINT, 16, 1) \ 262x(R32G32B32_SINT, 12, 1) \ 263x(R32G32_SINT, 8, 1) \ 264x(R32_SINT, 4, 1) \ 265\ 266x(R16G16B16A16_SINT, 8, 1) \ 267x(R16G16_SINT, 4, 1) \ 268x(R16_SINT, 2, 1) \ 269\ 270x(R8G8B8A8_SINT, 4, 1) \ 271x(R8G8_SINT, 2, 1) \ 272x(R8_SINT, 1, 1) \ 273\ 274x(R16G16B16A16_UNORM, 8, 1) \ 275x(R16G16_UNORM, 4, 1) \ 276x(R16_UNORM, 2, 1) \ 277\ 278x(R8G8B8A8_UNORM, 4, 1) \ 279x(R8G8B8A8_UNORM_SRGB, 4, 1) \ 280x(R8G8_UNORM, 2, 1) \ 281x(R8_UNORM, 1, 1) \ 282x(B8G8R8A8_UNORM, 4, 1) \ 283x(B8G8R8A8_UNORM_SRGB, 4, 1) \ 284x(B8G8R8X8_UNORM, 4, 1) \ 285x(B8G8R8X8_UNORM_SRGB, 4, 1) \ 286\ 287x(R16G16B16A16_SNORM, 8, 1) \ 288x(R16G16_SNORM, 4, 1) \ 289x(R16_SNORM, 2, 1) \ 290\ 291x(R8G8B8A8_SNORM, 4, 1) \ 292x(R8G8_SNORM, 2, 1) \ 293x(R8_SNORM, 1, 1) \ 294\ 295x(D32_FLOAT, 4, 1) \ 296x(D16_UNORM, 2, 1) \ 297x(D32_FLOAT_S8_UINT, 8, 1) \ 298x(R32_FLOAT_X32_TYPELESS, 8, 1) \ 299\ 300x(B4G4R4A4_UNORM, 2, 1) \ 301x(B5G6R5_UNORM, 2, 1) \ 302x(B5G5R5A1_UNORM, 2, 1) \ 303\ 304x(R9G9B9E5_SHAREDEXP, 4, 1) \ 305x(R10G10B10A2_TYPELESS, 4, 1) \ 306x(R10G10B10A2_UNORM, 4, 1) \ 307x(R10G10B10A2_UINT, 4, 1) \ 308x(R11G11B10_FLOAT, 4, 1) \ 309\ 310x(BC1_UNORM, 8, 16) \ 311x(BC1_UNORM_SRGB, 8, 16) \ 312x(BC2_UNORM, 16, 16) \ 313x(BC2_UNORM_SRGB, 16, 16) \ 314x(BC3_UNORM, 16, 16) \ 315x(BC3_UNORM_SRGB, 16, 16) \ 316x(BC4_UNORM, 8, 16) \ 317x(BC4_SNORM, 8, 16) \ 318x(BC5_UNORM, 16, 16) \ 319x(BC5_SNORM, 16, 16) \ 320x(BC6H_UF16, 16, 16) \ 321x(BC6H_SF16, 16, 16) \ 322x(BC7_UNORM, 16, 16) \ 323x(BC7_UNORM_SRGB, 16, 16) \ 324\ 325x(R64_UINT, 8, 1) \ 326\ 327x(R64_SINT, 8, 1) 328// clang-format on 329 330// TODO: This should be generated from above 331// TODO: enum class should be explicitly uint32_t or whatever's appropriate 332/// Different formats of things like pixels or elements of vertices 333/// NOTE! Any change to this type (adding, removing, changing order) - must also be reflected in 334/// changes GFX_FORMAT 335enum class Format 336{ 337// D3D formats omitted: 19-22, 44-47, 65-66, 68-70, 73, 76, 79, 82, 88-89, 92-94, 97, 100-114 338// These formats are omitted due to lack of a corresponding Vulkan format. D24_UNORM_S8_UINT 339// (DXGI_FORMAT 45) has a matching Vulkan format but is also omitted as it is only supported by 340// Nvidia. 341Unknown, 342 343R32G32B32A32_TYPELESS , 344R32G32B32_TYPELESS , 345R32G32_TYPELESS , 346R32_TYPELESS , 347 348R16G16B16A16_TYPELESS , 349R16G16_TYPELESS , 350R16_TYPELESS , 351 352R8G8B8A8_TYPELESS , 353R8G8_TYPELESS , 354R8_TYPELESS , 355B8G8R8A8_TYPELESS , 356 357R32G32B32A32_FLOAT , 358R32G32B32_FLOAT , 359R32G32_FLOAT , 360R32_FLOAT , 361 362R16G16B16A16_FLOAT , 363R16G16_FLOAT , 364R16_FLOAT , 365 366R32G32B32A32_UINT , 367R32G32B32_UINT , 368R32G32_UINT , 369R32_UINT , 370 371R16G16B16A16_UINT , 372R16G16_UINT , 373R16_UINT , 374 375R8G8B8A8_UINT , 376R8G8_UINT , 377R8_UINT , 378 379R32G32B32A32_SINT , 380R32G32B32_SINT , 381R32G32_SINT , 382R32_SINT , 383 384R16G16B16A16_SINT , 385R16G16_SINT , 386R16_SINT , 387 388R8G8B8A8_SINT , 389R8G8_SINT , 390R8_SINT , 391 392R16G16B16A16_UNORM , 393R16G16_UNORM , 394R16_UNORM , 395 396R8G8B8A8_UNORM , 397R8G8B8A8_UNORM_SRGB , 398R8G8_UNORM , 399R8_UNORM , 400B8G8R8A8_UNORM , 401B8G8R8A8_UNORM_SRGB , 402B8G8R8X8_UNORM , 403B8G8R8X8_UNORM_SRGB , 404 405R16G16B16A16_SNORM , 406R16G16_SNORM , 407R16_SNORM , 408 409R8G8B8A8_SNORM , 410R8G8_SNORM , 411R8_SNORM , 412 413D32_FLOAT , 414D16_UNORM , 415D32_FLOAT_S8_UINT , 416R32_FLOAT_X32_TYPELESS , 417 418B4G4R4A4_UNORM , 419B5G6R5_UNORM , 420B5G5R5A1_UNORM , 421 422R9G9B9E5_SHAREDEXP , 423R10G10B10A2_TYPELESS , 424R10G10B10A2_UNORM , 425R10G10B10A2_UINT , 426R11G11B10_FLOAT , 427 428BC1_UNORM , 429BC1_UNORM_SRGB , 430BC2_UNORM , 431BC2_UNORM_SRGB , 432BC3_UNORM , 433BC3_UNORM_SRGB , 434BC4_UNORM , 435BC4_SNORM , 436BC5_UNORM , 437BC5_SNORM , 438BC6H_UF16 , 439BC6H_SF16 , 440BC7_UNORM , 441BC7_UNORM_SRGB , 442 443R64_UINT , 444 445R64_SINT , 446 447_Count, 448}; 449 450// TODO: Aspect = Color, Depth, Stencil, etc. 451// TODO: Channel = R, G, B, A, D, S, etc. 452// TODO: Pick : pixel or texel 453// TODO: Block is a good term for what it is 454// TODO: Width/Height/Depth/whatever should not be used. We should use extentX, extentY, etc. 455struct FormatInfo 456{ 457GfxCount 458channelCount ; ///< The amount of channels in the format. Only set if the channelType is set 459uint8_t channelType ; ///< One of SlangScalarType None if type isn't made up of elements of type. 460///< TODO: Change to uint32_t? 461 462Size blockSizeInBytes ; ///< The size of a block in bytes. 463GfxCount pixelsPerBlock ; ///< The number of pixels contained in a block. 464GfxCount blockWidth ; ///< The width of a block in pixels. 465GfxCount blockHeight ; ///< The height of a block in pixels. 466}; 467 468enum class InputSlotClass 469{ 470PerVertex, 471PerInstance 472}; 473 474struct InputElementDesc 475{ 476char const * semanticName ; ///< The name of the corresponding parameter in shader code. 477GfxIndex semanticIndex ; ///< The index of the corresponding parameter in shader code. Only 478///< needed if multiple parameters share a semantic name. 479Format format ; ///< The format of the data being fetched for this element. 480Offset offset ; ///< The offset in bytes of this element from the start of the corresponding 481///< chunk of vertex stream data. 482GfxIndex bufferSlotIndex ; ///< The index of the vertex stream to fetch this element's data from. 483}; 484 485struct VertexStreamDesc 486{ 487Size stride ; ///< The stride in bytes for this vertex stream. 488InputSlotClass slotClass ; ///< Whether the stream contains per-vertex or per-instance data. 489GfxCount instanceDataStepRate ; ///< How many instances to draw per chunk of data. 490}; 491 492enum class PrimitiveType 493{ 494Point, 495Line, 496Triangle, 497Patch 498}; 499 500enum class PrimitiveTopology 501{ 502TriangleList, 503TriangleStrip, 504PointList, 505LineList, 506LineStrip 507}; 508 509enum class ResourceState 510{ 511Undefined, 512General, 513PreInitialized, 514VertexBuffer, 515IndexBuffer, 516ConstantBuffer, 517StreamOutput, 518ShaderResource, 519UnorderedAccess, 520RenderTarget, 521DepthRead, 522DepthWrite, 523Present, 524IndirectArgument, 525CopySource, 526CopyDestination, 527ResolveSource, 528ResolveDestination, 529AccelerationStructure, 530AccelerationStructureBuildInput, 531PixelShaderResource, 532NonPixelShaderResource, 533_Count 534}; 535 536struct ResourceStateSet 537{ 538public : 539void add ( ResourceState state) { m_bitFields |= ( 1LL << ( uint32_t )state); } 540template < typename... TResourceState > 541void add ( ResourceState s, TResourceState ... states) 542{ 543add (s); 544add( states ...); 545} 546bool contains ( ResourceState state) const 547{ 548return (m_bitFields & ( 1LL << ( uint32_t )state)) != 0 ; 549} 550ResourceStateSet () 551: m_bitFields ( 0 ) 552{ 553} 554ResourceStateSet( const ResourceStateSet & other) = default; 555ResourceStateSet( ResourceState state) { add ( state ); } 556template < typename... TResourceState > 557ResourceStateSet (TResourceState... states) 558{ 559add( states ...); 560} 561 562ResourceStateSet operator & ( const ResourceStateSet & that) const 563{ 564ResourceStateSet result; 565result. m_bitFields = this -> m_bitFields & that. m_bitFields ; 566return result; 567} 568 569private : 570uint64_t m_bitFields = 0 ; 571void add () {} 572}; 573 574 575/// Describes how memory for the resource should be allocated for CPU access. 576enum class MemoryType 577{ 578DeviceLocal, 579Upload, 580ReadBack, 581}; 582 583enum class InteropHandleAPI 584{ 585Unknown, 586D3D12 , // A D3D12 object pointer. 587Vulkan, // A general Vulkan object handle. 588CUDA , // A general CUDA object handle. 589Win32, // A general Win32 HANDLE. 590FileDescriptor, // A file descriptor. 591DeviceAddress, // A device address. 592D3D12CpuDescriptorHandle, // A D3D12_CPU_DESCRIPTOR_HANDLE value. 593Metal, // A general Metal object handle. 594}; 595 596struct InteropHandle 597{ 598InteropHandleAPI api = InteropHandleAPI ::Unknown; 599uint64_t handleValue = 0 ; 600}; 601 602// Declare opaque type 603class IInputLayout : public ISlangUnknown 604{ 605public : 606struct Desc 607{ 608InputElementDesc const * inputElements = nullptr; 609GfxCount inputElementCount = 0 ; 610VertexStreamDesc const * vertexStreams = nullptr; 611GfxCount vertexStreamCount = 0 ; 612}; 613}; 614#define SLANG_UUID_IInputLayout \ 615{ \ 6160x45223711, 0xa84b, 0x455c, \ 617{ \ 6180xbe, 0xfa, 0x49, 0x37, 0x42, 0x1e, 0x8e, 0x2e \ 619} \ 620} 621 622class IResource : public ISlangUnknown 623{ 624public : 625/// The type of resource. 626/// NOTE! The order needs to be such that all texture types are at or after Texture1D (otherwise 627/// isTexture won't work correctly) 628enum class Type 629{ 630Unknown, ///< Unknown 631Buffer, ///< A buffer (like a constant/index/vertex buffer) 632Texture1D, ///< A 1d texture 633Texture2D, ///< A 2d texture 634Texture3D, ///< A 3d texture 635TextureCube, ///< A cubemap consists of 6 Texture2D like faces 636_Count, 637}; 638 639/// Base class for Descs 640struct DescBase 641{ 642Type type = Type::Unknown; 643ResourceState defaultState = ResourceState ::Undefined; 644ResourceStateSet allowedStates = ResourceStateSet (); 645MemoryType memoryType = MemoryType::DeviceLocal; 646InteropHandle existingHandle = {}; 647bool isShared = false; 648}; 649 650virtual SLANG_NO_THROW Type SLANG_MCALL getType () = 0 ; 651virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle (InteropHandle * outHandle) = 0 ; 652virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle (InteropHandle * outHandle) = 0 ; 653 654virtual SLANG_NO_THROW Result SLANG_MCALL setDebugName ( const char * name) = 0 ; 655virtual SLANG_NO_THROW const char * SLANG_MCALL getDebugName () = 0 ; 656}; 657#define SLANG_UUID_IResource \ 658{ \ 6590xa0e39f34, 0x8398, 0x4522, \ 660{ \ 6610x95, 0xc2, 0xeb, 0xc0, 0xf9, 0x84, 0xef, 0x3f \ 662} \ 663} 664 665struct MemoryRange 666{ 667// TODO: Change to Offset/Size? 668uint64_t offset ; 669uint64_t size ; 670}; 671 672class IBufferResource : public IResource 673{ 674public : 675struct Desc : public DescBase 676{ 677Size sizeInBytes = 0 ; ///< Total size in bytes 678Size elementSize = 0 ; ///< Get the element stride. If > 0, this is a structured buffer 679Format format = Format::Unknown; 680}; 681 682virtual SLANG_NO_THROW Desc * SLANG_MCALL getDesc () = 0 ; 683virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress () = 0 ; 684virtual SLANG_NO_THROW Result SLANG_MCALL map (MemoryRange * rangeToRead, void ** outPointer) = 0 ; 685virtual SLANG_NO_THROW Result SLANG_MCALL unmap (MemoryRange * writtenRange) = 0 ; 686}; 687#define SLANG_UUID_IBufferResource \ 688{ \ 6890x1b274efe, 0x5e37, 0x492b, \ 690{ \ 6910x82, 0x6e, 0x7e, 0xe7, 0xe8, 0xf5, 0xa4, 0x9b \ 692} \ 693} 694 695struct DepthStencilClearValue 696{ 697float depth = 1.0f ; 698uint32_t stencil = 0 ; 699}; 700union ColorClearValue 701{ 702float floatValues [ 4 ]; 703uint32_t uintValues [ 4 ]; 704}; 705struct ClearValue 706{ 707ColorClearValue color = {{ 0.0f , 0.0f , 0.0f , 0.0f }}; 708DepthStencilClearValue depthStencil ; 709}; 710 711struct BufferRange 712{ 713Offset offset ; ///< Offset in bytes. 714Size size ; ///< Size in bytes. 715}; 716 717enum class TextureAspect : uint32_t 718{ 719Default = 0 , 720Color = 0x00000001 , 721Depth = 0x00000002 , 722Stencil = 0x00000004 , 723MetaData = 0x00000008 , 724Plane0 = 0x00000010 , 725Plane1 = 0x00000020 , 726Plane2 = 0x00000040 , 727 728DepthStencil = Depth | Stencil, 729}; 730 731struct SubresourceRange 732{ 733TextureAspect aspectMask ; 734GfxIndex mipLevel ; 735GfxCount mipLevelCount ; 736GfxIndex baseArrayLayer ; // For Texture3D, this is WSlice. 737GfxCount layerCount ; // For cube maps, this is a multiple of 6. 738}; 739 740class ITextureResource : public IResource 741{ 742public : 743static const GfxCount kRemainingTextureSize = 0xffffffff ; 744struct Offset3D 745{ 746GfxIndex x = 0 ; 747GfxIndex y = 0 ; 748GfxIndex z = 0 ; 749Offset3D() = default ; 750Offset3D ( GfxIndex _x, GfxIndex _y, GfxIndex _z) 751: x ( _x ), y ( _y ), z( _z ) 752{ 753} 754}; 755 756struct SampleDesc 757{ 758GfxCount numSamples = 1 ; ///< Number of samples per pixel 759int quality = 0 ; ///< The quality measure for the samples 760}; 761 762struct Extents 763{ 764GfxCount width = 0 ; ///< Width in pixels 765GfxCount height = 0 ; ///< Height in pixels (if 2d or 3d) 766GfxCount depth = 0 ; ///< Depth (if 3d) 767}; 768 769struct Desc : public DescBase 770{ 771Extents size ; 772 773GfxCount arraySize = 0 ; ///< Array size 774 775GfxCount numMipLevels = 0 ; ///< Number of mip levels - if 0 will create all mip levels 776Format format ; ///< The resources format 777SampleDesc sampleDesc ; ///< How the resource is sampled 778ClearValue * optimalClearValue = nullptr; 779}; 780 781/// Data for a single subresource of a texture. 782/// 783/// Each subresource is a tensor with `1 <= rank <= 3`, 784/// where the rank is deterined by the base shape of the 785/// texture (Buffer, 1D, 2D, 3D, or Cube). For the common 786/// case of a 2D texture, `rank == 2` and each subresource 787/// is a 2D image. 788/// 789/// Subresource tensors must be stored in a row-major layout, 790/// so that the X axis strides over texels, the Y axis strides 791/// over 1D rows of texels, and the Z axis strides over 2D 792/// "layers" of texels. 793/// 794/// For a texture with multiple mip levels or array elements, 795/// each mip level and array element is stores as a distinct 796/// subresource. When indexing into an array of subresources, 797/// the index of a subresoruce for mip level `m` and array 798/// index `a` is `m + a*mipLevelCount`. 799/// 800struct SubresourceData 801{ 802/// Pointer to texel data for the subresource tensor. 803void const * data ; 804 805/// Stride in bytes between rows of the subresource tensor. 806/// 807/// This is the number of bytes to add to a pointer to a texel 808/// at (X,Y,Z) to get to a texel at (X,Y+1,Z). 809/// 810/// Devices may not support all possible values for `strideY`. 811/// In particular, they may only support strictly positive strides. 812/// 813gfx :: Size strideY ; 814 815/// Stride in bytes between layers of the subresource tensor. 816/// 817/// This is the number of bytes to add to a pointer to a texel 818/// at (X,Y,Z) to get to a texel at (X,Y,Z+1). 819/// 820/// Devices may not support all possible values for `strideZ`. 821/// In particular, they may only support strictly positive strides. 822/// 823gfx :: Size strideZ ; 824}; 825 826virtual SLANG_NO_THROW Desc * SLANG_MCALL getDesc () = 0 ; 827}; 828#define SLANG_UUID_ITextureResource \ 829{ \ 8300xcf88a31c, 0x6187, 0x46c5, \ 831{ \ 8320xa4, 0xb7, 0xeb, 0x58, 0xc7, 0x33, 0x40, 0x17 \ 833} \ 834} 835 836 837enum class ComparisonFunc : uint8_t 838{ 839Never = 0x0 , 840Less = 0x1 , 841Equal = 0x2 , 842LessEqual = 0x3 , 843Greater = 0x4 , 844NotEqual = 0x5 , 845GreaterEqual = 0x6 , 846Always = 0x7 , 847}; 848 849enum class TextureFilteringMode 850{ 851Point, 852Linear, 853}; 854 855enum class TextureAddressingMode 856{ 857Wrap, 858ClampToEdge, 859ClampToBorder, 860MirrorRepeat, 861MirrorOnce, 862}; 863 864enum class TextureReductionOp 865{ 866Average, 867Comparison, 868Minimum, 869Maximum, 870}; 871 872class ISamplerState : public ISlangUnknown 873{ 874public : 875struct Desc 876{ 877TextureFilteringMode minFilter = TextureFilteringMode ::Linear; 878TextureFilteringMode magFilter = TextureFilteringMode ::Linear; 879TextureFilteringMode mipFilter = TextureFilteringMode ::Linear; 880TextureReductionOp reductionOp = TextureReductionOp ::Average; 881TextureAddressingMode addressU = TextureAddressingMode ::Wrap; 882TextureAddressingMode addressV = TextureAddressingMode ::Wrap; 883TextureAddressingMode addressW = TextureAddressingMode ::Wrap; 884float mipLODBias = 0.0f ; 885uint32_t maxAnisotropy = 1 ; 886ComparisonFunc comparisonFunc = ComparisonFunc::Never; 887float borderColor [ 4 ] = { 1.0f , 1.0f , 1.0f , 1.0f }; 888float minLOD = - FLT_MAX ; 889float maxLOD = FLT_MAX ; 890}; 891 892/// Returns a native API handle representing this sampler state object. 893/// When using D3D12, this will be a D3D12_CPU_DESCRIPTOR_HANDLE. 894/// When using Vulkan, this will be a VkSampler. 895virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle (InteropHandle * outNativeHandle) = 0 ; 896}; 897#define SLANG_UUID_ISamplerState \ 898{ \ 8990x8b8055df, 0x9377, 0x401d, \ 900{ \ 9010x91, 0xff, 0x3f, 0xa3, 0xbf, 0x66, 0x64, 0xf4 \ 902} \ 903} 904 905class IResourceView : public ISlangUnknown 906{ 907public : 908enum class Type 909{ 910Unknown, 911 912RenderTarget, 913DepthStencil, 914ShaderResource, 915UnorderedAccess, 916AccelerationStructure, 917 918CountOf_, 919}; 920 921struct RenderTargetDesc 922{ 923// The resource shape of this render target view. 924IResource :: Type shape ; 925}; 926 927struct Desc 928{ 929Type type ; 930Format format ; 931 932// Required fields for `RenderTarget` and `DepthStencil` views. 933RenderTargetDesc renderTarget ; 934// Specifies the range of a texture resource for a 935// ShaderRsource/UnorderedAccess/RenderTarget/DepthStencil view. 936SubresourceRange subresourceRange ; 937// Specifies the range of a buffer resource for a ShaderResource/UnorderedAccess view. 938BufferRange bufferRange ; 939}; 940virtual SLANG_NO_THROW Desc * SLANG_MCALL getViewDesc () = 0 ; 941 942/// Returns a native API handle representing this resource view object. 943/// When using D3D12, this will be a D3D12_CPU_DESCRIPTOR_HANDLE or a buffer device address 944/// depending on the type of the resource view. When using Vulkan, this will be a VkImageView, 945/// VkBufferView, VkAccelerationStructure or a VkBuffer depending on the type of the resource 946/// view. 947virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle (InteropHandle * outNativeHandle) = 0 ; 948}; 949#define SLANG_UUID_IResourceView \ 950{ \ 9510x7b6c4926, 0x884, 0x408c, \ 952{ \ 9530xad, 0x8a, 0x50, 0x3a, 0x8e, 0x23, 0x98, 0xa4 \ 954} \ 955} 956 957class IAccelerationStructure : public IResourceView 958{ 959public : 960enum class Kind 961{ 962TopLevel, 963BottomLevel 964}; 965 966struct BuildFlags 967{ 968// The enum values are intentionally consistent with 969// D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAGS. 970enum Enum 971{ 972None, 973AllowUpdate = 1 , 974AllowCompaction = 2 , 975PreferFastTrace = 4 , 976PreferFastBuild = 8 , 977MinimizeMemory = 16 , 978PerformUpdate = 32 979}; 980}; 981 982enum class GeometryType 983{ 984Triangles, 985ProcedurePrimitives 986}; 987 988struct GeometryFlags 989{ 990// The enum values are intentionally consistent with 991// D3D12_RAYTRACING_GEOMETRY_FLAGS. 992enum Enum 993{ 994None, 995Opaque = 1 , 996NoDuplicateAnyHitInvocation = 2 997}; 998}; 999 1000struct TriangleDesc 1001{ 1002DeviceAddress transform3x4 ; 1003Format indexFormat ; 1004Format vertexFormat ; 1005GfxCount indexCount ; 1006GfxCount vertexCount ; 1007DeviceAddress indexData ; 1008DeviceAddress vertexData ; 1009Size vertexStride ; 1010}; 1011 1012struct ProceduralAABB 1013{ 1014float minX ; 1015float minY ; 1016float minZ ; 1017float maxX ; 1018float maxY ; 1019float maxZ ; 1020}; 1021 1022struct ProceduralAABBDesc 1023{ 1024/// Number of AABBs. 1025GfxCount count ; 1026 1027/// Pointer to an array of `ProceduralAABB` values in device memory. 1028DeviceAddress data ; 1029 1030/// Stride in bytes of the AABB values array. 1031Size stride ; 1032}; 1033 1034struct GeometryDesc 1035{ 1036GeometryType type ; 1037GeometryFlags :: Enum flags ; 1038union 1039{ 1040TriangleDesc triangles ; 1041ProceduralAABBDesc proceduralAABBs ; 1042} content ; 1043}; 1044 1045struct GeometryInstanceFlags 1046{ 1047// The enum values are kept consistent with D3D12_RAYTRACING_INSTANCE_FLAGS 1048// and VkGeometryInstanceFlagBitsKHR. 1049enum Enum : uint32_t 1050{ 1051None = 0 , 1052TriangleFacingCullDisable = 0x00000001 , 1053TriangleFrontCounterClockwise = 0x00000002 , 1054ForceOpaque = 0x00000004 , 1055NoOpaque = 0x00000008 1056}; 1057}; 1058 1059// TODO: Should any of these be changed? 1060// The layout of this struct is intentionally consistent with D3D12_RAYTRACING_INSTANCE_DESC 1061// and VkAccelerationStructureInstanceKHR. 1062struct InstanceDesc 1063{ 1064float transform [ 3 ][ 4 ]; 1065uint32_t instanceID : 24 ; 1066uint32_t instanceMask : 8 ; 1067uint32_t instanceContributionToHitGroupIndex : 24 ; 1068uint32_t flags : 8 ; // Combination of GeometryInstanceFlags::Enum values. 1069DeviceAddress accelerationStructure ; 1070}; 1071 1072struct PrebuildInfo 1073{ 1074Size resultDataMaxSize ; 1075Size scratchDataSize ; 1076Size updateScratchDataSize ; 1077}; 1078 1079struct BuildInputs 1080{ 1081Kind kind ; 1082 1083BuildFlags :: Enum flags ; 1084 1085GfxCount descCount ; 1086 1087/// Array of `InstanceDesc` values in device memory. 1088/// Used when `kind` is `TopLevel`. 1089DeviceAddress instanceDescs ; 1090 1091/// Array of `GeometryDesc` values. 1092/// Used when `kind` is `BottomLevel`. 1093const GeometryDesc * geometryDescs ; 1094}; 1095 1096struct CreateDesc 1097{ 1098Kind kind ; 1099IBufferResource * buffer ; 1100Offset offset ; 1101Size size ; 1102}; 1103 1104struct BuildDesc 1105{ 1106BuildInputs inputs ; 1107IAccelerationStructure * source ; 1108IAccelerationStructure * dest ; 1109DeviceAddress scratchData ; 1110}; 1111 1112virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress () = 0 ; 1113}; 1114#define SLANG_UUID_IAccelerationStructure \ 1115{ \ 11160xa5cdda3c, 0x1d4e, 0x4df7, \ 1117{ \ 11180x8e, 0xf2, 0xb7, 0x3f, 0xce, 0x4, 0xde, 0x3b \ 1119} \ 1120} 1121 1122class IFence : public ISlangUnknown 1123{ 1124public : 1125struct Desc 1126{ 1127uint64_t initialValue = 0 ; 1128bool isShared = false; 1129}; 1130 1131/// Returns the currently signaled value on the device. 1132virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentValue (uint64_t * outValue) = 0 ; 1133 1134/// Signals the fence from the host with the specified value. 1135virtual SLANG_NO_THROW Result SLANG_MCALL setCurrentValue ( uint64_t value) = 0 ; 1136 1137virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle (InteropHandle * outHandle) = 0 ; 1138virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle (InteropHandle * outNativeHandle) = 0 ; 1139}; 1140#define SLANG_UUID_IFence \ 1141{ \ 11420x7fe1c283, 0xd3f4, 0x48ed, \ 1143{ \ 11440xaa, 0xf3, 0x1, 0x51, 0x96, 0x4e, 0x7c, 0xb5 \ 1145} \ 1146} 1147 1148struct ShaderOffset 1149{ 1150SlangInt uniformOffset = 0 ; // TODO: Change to Offset? 1151GfxIndex bindingRangeIndex = 0 ; 1152GfxIndex bindingArrayIndex = 0 ; 1153uint32_t getHashCode () const 1154{ 1155return ( uint32_t )( ((bindingRangeIndex << 20 ) + bindingArrayIndex ) ^ uniformOffset ); 1156} 1157bool operator == ( const ShaderOffset & other ) const 1158{ 1159return uniformOffset == other . uniformOffset && 1160bindingRangeIndex == other . bindingRangeIndex && 1161bindingArrayIndex == other . bindingArrayIndex ; 1162} 1163bool operator != ( const ShaderOffset & other ) const { return ! this -> operator == ( other ); } 1164bool operator < ( const ShaderOffset & other ) const 1165{ 1166if ( bindingRangeIndex < other . bindingRangeIndex ) 1167return true; 1168if ( bindingRangeIndex > other . bindingRangeIndex ) 1169return false; 1170if ( bindingArrayIndex < other . bindingArrayIndex ) 1171return true; 1172if ( bindingArrayIndex > other . bindingArrayIndex ) 1173return false; 1174return uniformOffset < other . uniformOffset ; 1175} 1176bool operator <=( const ShaderOffset & other ) const { return ( * this == other ) || ( * this ) < other ; } 1177bool operator > ( const ShaderOffset & other ) const { return other < * this ; } 1178bool operator >=( const ShaderOffset & other ) const { return other <= * this ; } 1179}; 1180 1181enum class ShaderObjectContainerType 1182{ 1183None , 1184Array , 1185StructuredBuffer 1186}; 1187 1188class IShaderObject : public ISlangUnknown 1189{ 1190public : 1191virtual SLANG_NO_THROW slang :: TypeLayoutReflection * SLANG_MCALL getElementTypeLayout () = 0 ; 1192virtual SLANG_NO_THROW ShaderObjectContainerType SLANG_MCALL getContainerType () = 0 ; 1193virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount () = 0 ; 1194virtual SLANG_NO_THROW Result SLANG_MCALL 1195getEntryPoint (GfxIndex index , IShaderObject ** entryPoint ) = 0 ; 1196virtual SLANG_NO_THROW Result SLANG_MCALL 1197setData (ShaderOffset const & offset , void const * data , Size size ) = 0 ; 1198virtual SLANG_NO_THROW Result SLANG_MCALL 1199getObject (ShaderOffset const & offset , IShaderObject ** object ) = 0 ; 1200virtual SLANG_NO_THROW Result SLANG_MCALL 1201setObject (ShaderOffset const & offset , IShaderObject * object ) = 0 ; 1202virtual SLANG_NO_THROW Result SLANG_MCALL 1203setResource (ShaderOffset const & offset , IResourceView * resourceView ) = 0 ; 1204virtual SLANG_NO_THROW Result SLANG_MCALL 1205setSampler (ShaderOffset const & offset , ISamplerState * sampler ) = 0 ; 1206virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler ( 1207ShaderOffset const & offset , 1208IResourceView * textureView , 1209ISamplerState * sampler ) = 0 ; 1210 1211/// Manually overrides the specialization argument for the sub-object binding at `offset`. 1212/// Specialization arguments are passed to the shader compiler to specialize the type 1213/// of interface-typed shader parameters. 1214virtual SLANG_NO_THROW Result SLANG_MCALL setSpecializationArgs ( 1215ShaderOffset const & offset , 1216const slang ::SpecializationArg * args , 1217GfxCount count ) = 0 ; 1218 1219virtual SLANG_NO_THROW Result SLANG_MCALL 1220getCurrentVersion ( ITransientResourceHeap * transientHeap , IShaderObject ** outObject ) = 0 ; 1221 1222virtual SLANG_NO_THROW const void * SLANG_MCALL getRawData () = 0 ; 1223 1224virtual SLANG_NO_THROW Size SLANG_MCALL getSize () = 0 ; 1225 1226/// Use the provided constant buffer instead of the internally created one. 1227virtual SLANG_NO_THROW Result SLANG_MCALL 1228setConstantBufferOverride ( IBufferResource * constantBuffer ) = 0 ; 1229 1230 1231inline ComPtr < IShaderObject > getObject (ShaderOffset const & offset ) 1232{ 1233ComPtr < IShaderObject > object = nullptr ; 1234SLANG_RETURN_NULL_ON_FAIL ( getObject ( offset , object . writeRef ())); 1235return object ; 1236} 1237inline ComPtr < IShaderObject > getEntryPoint (GfxIndex index ) 1238{ 1239ComPtr < IShaderObject > entryPoint = nullptr ; 1240SLANG_RETURN_NULL_ON_FAIL ( getEntryPoint ( index , entryPoint . writeRef ())); 1241return entryPoint ; 1242} 1243}; 1244#define SLANG_UUID_IShaderObject \ 1245{ \ 12460xc1fa997e, 0x5ca2, 0x45ae, \ 1247{ \ 12480x9b, 0xcb, 0xc4, 0x35, 0x9e, 0x85, 0x5, 0x85 \ 1249} \ 1250} 1251 1252enum class StencilOp : uint8_t 1253{ 1254Keep , 1255Zero , 1256Replace , 1257IncrementSaturate , 1258DecrementSaturate , 1259Invert , 1260IncrementWrap , 1261DecrementWrap , 1262}; 1263 1264enum class FillMode : uint8_t 1265{ 1266Solid , 1267Wireframe , 1268}; 1269 1270enum class CullMode : uint8_t 1271{ 1272None , 1273Front , 1274Back , 1275}; 1276 1277enum class FrontFaceMode : uint8_t 1278{ 1279CounterClockwise , 1280Clockwise , 1281}; 1282 1283struct DepthStencilOpDesc 1284{ 1285StencilOp stencilFailOp = StencilOp :: Keep ; 1286StencilOp stencilDepthFailOp = StencilOp :: Keep ; 1287StencilOp stencilPassOp = StencilOp :: Keep ; 1288ComparisonFunc stencilFunc = ComparisonFunc :: Always ; 1289}; 1290 1291struct DepthStencilDesc 1292{ 1293bool depthTestEnable = false; 1294bool depthWriteEnable = true; 1295ComparisonFunc depthFunc = ComparisonFunc :: Less ; 1296 1297bool stencilEnable = false; 1298uint32_t stencilReadMask = 0xFFFFFFFF ; 1299uint32_t stencilWriteMask = 0xFFFFFFFF ; 1300DepthStencilOpDesc frontFace ; 1301DepthStencilOpDesc backFace ; 1302 1303uint32_t stencilRef = 0 ; // TODO: this should be removed 1304}; 1305 1306struct RasterizerDesc 1307{ 1308FillMode fillMode = FillMode :: Solid ; 1309CullMode cullMode = CullMode :: None ; 1310FrontFaceMode frontFace = FrontFaceMode :: CounterClockwise ; 1311int32_t depthBias = 0 ; 1312float depthBiasClamp = 0.0f ; 1313float slopeScaledDepthBias = 0.0f ; 1314bool depthClipEnable = true; 1315bool scissorEnable = false; 1316bool multisampleEnable = false; 1317bool antialiasedLineEnable = false; 1318bool enableConservativeRasterization = false; 1319uint32_t forcedSampleCount = 0 ; 1320}; 1321 1322enum class LogicOp 1323{ 1324NoOp , 1325}; 1326 1327enum class BlendOp 1328{ 1329Add , 1330Subtract , 1331ReverseSubtract , 1332Min , 1333Max , 1334}; 1335 1336enum class BlendFactor 1337{ 1338Zero , 1339One , 1340SrcColor , 1341InvSrcColor , 1342SrcAlpha , 1343InvSrcAlpha , 1344DestAlpha , 1345InvDestAlpha , 1346DestColor , 1347InvDestColor , 1348SrcAlphaSaturate , 1349BlendColor , 1350InvBlendColor , 1351SecondarySrcColor , 1352InvSecondarySrcColor , 1353SecondarySrcAlpha , 1354InvSecondarySrcAlpha , 1355}; 1356 1357namespace RenderTargetWriteMask 1358{ 1359typedef uint8_t Type; 1360enum 1361{ 1362EnableNone = 0 , 1363EnableRed = 0x01 , 1364EnableGreen = 0x02 , 1365EnableBlue = 0x04 , 1366EnableAlpha = 0x08 , 1367EnableAll = 0x0F , 1368}; 1369}; // namespace RenderTargetWriteMask 1370typedef RenderTargetWriteMask::Type RenderTargetWriteMaskT; 1371 1372struct AspectBlendDesc 1373{ 1374BlendFactor srcFactor = BlendFactor :: One ; 1375BlendFactor dstFactor = BlendFactor :: Zero ; 1376BlendOp op = BlendOp :: Add ; 1377}; 1378 1379struct TargetBlendDesc 1380{ 1381AspectBlendDesc color ; 1382AspectBlendDesc alpha ; 1383bool enableBlend = false; 1384LogicOp logicOp = LogicOp :: NoOp ; 1385RenderTargetWriteMaskT writeMask = RenderTargetWriteMask :: EnableAll ; 1386}; 1387 1388struct BlendDesc 1389{ 1390TargetBlendDesc targets [ kMaxRenderTargetCount ]; 1391GfxCount targetCount = 0 ; 1392 1393bool alphaToCoverageEnable = false; 1394}; 1395 1396class IFramebufferLayout : public ISlangUnknown 1397{ 1398public : 1399struct TargetLayout 1400{ 1401Format format ; 1402GfxCount sampleCount ; 1403} ; 1404struct Desc 1405{ 1406GfxCount renderTargetCount ; 1407TargetLayout * renderTargets = nullptr; 1408TargetLayout * depthStencil = nullptr; 1409}; 1410}; 1411#define SLANG_UUID_IFramebufferLayout \ 1412{ \ 14130xa838785, 0xc13a, 0x4832, \ 1414{ \ 14150xad, 0x88, 0x64, 0x6, 0xb5, 0x4b, 0x5e, 0xba \ 1416} \ 1417} 1418 1419struct GraphicsPipelineStateDesc 1420{ 1421IShaderProgram * program = nullptr; 1422 1423IInputLayout * inputLayout = nullptr; 1424IFramebufferLayout * framebufferLayout = nullptr; 1425PrimitiveType primitiveType = PrimitiveType::Triangle; 1426DepthStencilDesc depthStencil ; 1427RasterizerDesc rasterizer ; 1428BlendDesc blend ; 1429}; 1430 1431struct ComputePipelineStateDesc 1432{ 1433IShaderProgram * program = nullptr; 1434void * d3d12RootSignatureOverride = nullptr; 1435}; 1436 1437struct RayTracingPipelineFlags 1438{ 1439enum Enum : uint32_t 1440{ 1441None = 0 , 1442SkipTriangles = 1 , 1443SkipProcedurals = 2 , 1444}; 1445}; 1446 1447struct HitGroupDesc 1448{ 1449const char * hitGroupName = nullptr; 1450const char * closestHitEntryPoint = nullptr; 1451const char * anyHitEntryPoint = nullptr; 1452const char * intersectionEntryPoint = nullptr; 1453}; 1454 1455struct RayTracingPipelineStateDesc 1456{ 1457IShaderProgram * program = nullptr; 1458GfxCount hitGroupCount = 0 ; 1459const HitGroupDesc * hitGroups = nullptr; 1460int maxRecursion = 0 ; 1461Size maxRayPayloadSize = 0 ; 1462Size maxAttributeSizeInBytes = 8 ; 1463RayTracingPipelineFlags :: Enum flags = RayTracingPipelineFlags ::None; 1464}; 1465 1466class IShaderTable : public ISlangUnknown 1467{ 1468public : 1469// Specifies the bytes to overwrite into a record in the shader table. 1470struct ShaderRecordOverwrite 1471{ 1472Offset offset ; // Offset within the shader record. 1473Size size ; // Number of bytes to overwrite. 1474uint8_t data [ 8 ]; // Content to overwrite. 1475}; 1476 1477struct Desc 1478{ 1479GfxCount rayGenShaderCount ; 1480const char ** rayGenShaderEntryPointNames ; 1481const ShaderRecordOverwrite * rayGenShaderRecordOverwrites ; 1482 1483GfxCount missShaderCount ; 1484const char ** missShaderEntryPointNames ; 1485const ShaderRecordOverwrite * missShaderRecordOverwrites ; 1486 1487GfxCount hitGroupCount ; 1488const char ** hitGroupNames ; 1489const ShaderRecordOverwrite * hitGroupRecordOverwrites ; 1490 1491GfxCount callableShaderCount ; 1492const char ** callableShaderEntryPointNames ; 1493const ShaderRecordOverwrite * callableShaderRecordOverwrites ; 1494 1495IShaderProgram * program ; 1496}; 1497}; 1498#define SLANG_UUID_IShaderTable \ 1499{ \ 15000xa721522c, 0xdf31, 0x4c2f, \ 1501{ \ 15020xa5, 0xe7, 0x3b, 0xe0, 0x12, 0x4b, 0x31, 0x78 \ 1503} \ 1504} 1505 1506class IPipelineState : public ISlangUnknown 1507{ 1508public : 1509virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle (InteropHandle * outHandle) = 0 ; 1510}; 1511#define SLANG_UUID_IPipelineState \ 1512{ \ 15130xca7e57d, 0x8a90, 0x44f3, \ 1514{ \ 15150xbd, 0xb1, 0xfe, 0x9b, 0x35, 0x3f, 0x5a, 0x72 \ 1516} \ 1517} 1518 1519 1520struct ScissorRect 1521{ 1522int32_t minX ; 1523int32_t minY ; 1524int32_t maxX ; 1525int32_t maxY ; 1526}; 1527 1528struct Viewport 1529{ 1530float originX = 0.0f ; 1531float originY = 0.0f ; 1532float extentX = 0.0f ; 1533float extentY = 0.0f ; 1534float minZ = 0.0f ; 1535float maxZ = 1.0f ; 1536}; 1537 1538class IFramebuffer : public ISlangUnknown 1539{ 1540public : 1541struct Desc 1542{ 1543GfxCount renderTargetCount ; 1544IResourceView * const * renderTargetViews ; 1545IResourceView * depthStencilView ; 1546IFramebufferLayout * layout ; 1547}; 1548}; 1549#define SLANG_UUID_IFrameBuffer \ 1550{ \ 15510xf0c0d9a, 0x4ef3, 0x4e18, \ 1552{ \ 15530x9b, 0xa9, 0x34, 0x60, 0xea, 0x69, 0x87, 0x95 \ 1554} \ 1555} 1556 1557struct WindowHandle 1558{ 1559enum class Type 1560{ 1561Unknown , 1562Win32Handle , 1563NSWindowHandle , 1564XLibHandle , 1565}; 1566Type type ; 1567intptr_t handleValues [ 2 ]; 1568static WindowHandle FromHwnd ( void * hwnd) 1569{ 1570WindowHandle handle = {}; 1571handle . type = WindowHandle ::Type::Win32Handle; 1572handle . handleValues [ 0 ] = ( intptr_t )( hwnd ); 1573return handle ; 1574} 1575static WindowHandle FromNSWindow ( void * nswindow) 1576{ 1577WindowHandle handle = {}; 1578handle. type = WindowHandle:: Type ::NSWindowHandle; 1579handle. handleValues [ 0 ] = ( intptr_t )(nswindow); 1580return handle; 1581} 1582static WindowHandle FromXWindow ( void * xdisplay, uint32_t xwindow) 1583{ 1584WindowHandle handle = {}; 1585handle. type = WindowHandle:: Type ::XLibHandle; 1586handle. handleValues [ 0 ] = ( intptr_t )(xdisplay); 1587handle. handleValues [ 1 ] = xwindow; 1588return handle; 1589} 1590}; 1591 1592struct FaceMask 1593{ 1594enum Enum 1595{ 1596Front = 1 , 1597Back = 2 1598}; 1599}; 1600 1601class IRenderPassLayout : public ISlangUnknown 1602{ 1603public: 1604enum class TargetLoadOp 1605{ 1606Load, 1607Clear, 1608DontCare 1609}; 1610enum class TargetStoreOp 1611{ 1612Store, 1613DontCare 1614}; 1615struct TargetAccessDesc 1616{ 1617TargetLoadOp loadOp ; 1618TargetLoadOp stencilLoadOp ; 1619TargetStoreOp storeOp ; 1620TargetStoreOp stencilStoreOp ; 1621ResourceState initialState ; 1622ResourceState finalState ; 1623}; 1624struct Desc 1625{ 1626IFramebufferLayout * framebufferLayout = nullptr; 1627GfxCount renderTargetCount ; 1628TargetAccessDesc * renderTargetAccess = nullptr; 1629TargetAccessDesc * depthStencilAccess = nullptr; 1630}; 1631}; 1632#define SLANG_UUID_IRenderPassLayout \ 1633{ \ 16340xdaab0b1a, 0xf45d, 0x4ae9, \ 1635{ \ 16360xbf, 0x2c, 0xe0, 0xbb, 0x76, 0x7d, 0xfa, 0xd1 \ 1637} \ 1638} 1639 1640enum class QueryType 1641{ 1642Timestamp, 1643AccelerationStructureCompactedSize, 1644AccelerationStructureSerializedSize, 1645AccelerationStructureCurrentSize, 1646}; 1647 1648class IQueryPool : public ISlangUnknown 1649{ 1650public : 1651struct Desc 1652{ 1653QueryType type ; 1654GfxCount count ; 1655}; 1656 1657public : 1658virtual SLANG_NO_THROW Result SLANG_MCALL 1659getResult ( GfxIndex queryIndex, GfxCount count, uint64_t * data) = 0 ; 1660virtual SLANG_NO_THROW Result SLANG_MCALL reset () = 0 ; 1661}; 1662#define SLANG_UUID_IQueryPool \ 1663{ \ 16640xc2cc3784, 0x12da, 0x480a, \ 1665{ \ 16660xa8, 0x74, 0x8b, 0x31, 0x96, 0x1c, 0xa4, 0x36 \ 1667} \ 1668} 1669 1670 1671class ICommandEncoder : public ISlangUnknown 1672{ 1673SLANG_COM_INTERFACE ( 16740x77ea6383 , 16750xbe3d , 16760x40aa , 1677{ 0x8b , 0x45 , 0xfd , 0xf0 , 0xd7 , 0x5b , 0xfa , 0x34 }); 1678 1679public : 1680virtual SLANG_NO_THROW void SLANG_MCALL endEncoding () = 0 ; 1681virtual SLANG_NO_THROW void SLANG_MCALL 1682writeTimestamp ( IQueryPool * queryPool, GfxIndex queryIndex) = 0 ; 1683}; 1684 1685struct IndirectDispatchArguments 1686{ 1687GfxCount ThreadGroupCountX ; 1688GfxCount ThreadGroupCountY ; 1689GfxCount ThreadGroupCountZ ; 1690}; 1691 1692struct IndirectDrawArguments 1693{ 1694GfxCount VertexCountPerInstance ; 1695GfxCount InstanceCount ; 1696GfxIndex StartVertexLocation ; 1697GfxIndex StartInstanceLocation ; 1698}; 1699 1700struct IndirectDrawIndexedArguments 1701{ 1702GfxCount IndexCountPerInstance ; 1703GfxCount InstanceCount ; 1704GfxIndex StartIndexLocation ; 1705GfxIndex BaseVertexLocation ; 1706GfxIndex StartInstanceLocation ; 1707}; 1708 1709struct SamplePosition 1710{ 1711int8_t x ; 1712int8_t y ; 1713}; 1714 1715struct ClearResourceViewFlags 1716{ 1717enum Enum : uint32_t 1718{ 1719None = 0 , 1720ClearDepth = 1 , 1721ClearStencil = 2 , 1722FloatClearValues = 4 1723}; 1724}; 1725 1726enum class CooperativeVectorComponentType 1727{ 1728Float16 = 0 , 1729Float32 = 1 , 1730Float64 = 2 , 1731SInt8 = 3 , 1732SInt16 = 4 , 1733SInt32 = 5 , 1734SInt64 = 6 , 1735UInt8 = 7 , 1736UInt16 = 8 , 1737UInt32 = 9 , 1738UInt64 = 10 , 1739SInt8Packed = 11 , 1740UInt8Packed = 12 , 1741FloatE4M3 = 13 , 1742FloatE5M2 = 14 , 1743}; 1744 1745struct CooperativeVectorProperties 1746{ 1747CooperativeVectorComponentType inputType ; 1748CooperativeVectorComponentType inputInterpretation ; 1749CooperativeVectorComponentType matrixInterpretation ; 1750CooperativeVectorComponentType biasInterpretation ; 1751CooperativeVectorComponentType resultType ; 1752bool transpose ; 1753}; 1754 1755 1756class IResourceCommandEncoder : public ICommandEncoder 1757{ 1758// {F99A00E9-ED50-4088-8A0E-3B26755031EA} 1759SLANG_COM_INTERFACE ( 17600xf99a00e9 , 17610xed50 , 17620x4088 , 1763{ 0x8a , 0xe , 0x3b , 0x26 , 0x75 , 0x50 , 0x31 , 0xea }); 1764 1765public : 1766virtual SLANG_NO_THROW void SLANG_MCALL copyBuffer ( 1767IBufferResource * dst, 1768Offset dstOffset, 1769IBufferResource * src, 1770Offset srcOffset, 1771Size size) = 0 ; 1772 1773/// Copies texture from src to dst. If dstSubresource and srcSubresource has mipLevelCount = 0 1774/// and layerCount = 0, the entire resource is being copied and dstOffset, srcOffset and extent 1775/// arguments are ignored. 1776virtual SLANG_NO_THROW void SLANG_MCALL copyTexture ( 1777ITextureResource * dst, 1778ResourceState dstState, 1779SubresourceRange dstSubresource, 1780ITextureResource ::Offset3D dstOffset, 1781ITextureResource * src, 1782ResourceState srcState, 1783SubresourceRange srcSubresource, 1784ITextureResource ::Offset3D srcOffset, 1785ITextureResource ::Extents extent) = 0 ; 1786 1787/// Copies texture to a buffer. Each row is aligned to kTexturePitchAlignment. 1788virtual SLANG_NO_THROW void SLANG_MCALL copyTextureToBuffer ( 1789IBufferResource * dst, 1790Offset dstOffset, 1791Size dstSize, 1792Size dstRowStride, 1793ITextureResource * src, 1794ResourceState srcState, 1795SubresourceRange srcSubresource, 1796ITextureResource ::Offset3D srcOffset, 1797ITextureResource ::Extents extent) = 0 ; 1798virtual SLANG_NO_THROW void SLANG_MCALL uploadTextureData ( 1799ITextureResource * dst, 1800SubresourceRange subResourceRange, 1801ITextureResource ::Offset3D offset, 1802ITextureResource ::Extents extent, 1803ITextureResource ::SubresourceData * subResourceData, 1804GfxCount subResourceDataCount) = 0 ; 1805virtual SLANG_NO_THROW void SLANG_MCALL 1806uploadBufferData ( IBufferResource * dst, Offset offset, Size size, void * data) = 0 ; 1807virtual SLANG_NO_THROW void SLANG_MCALL textureBarrier ( 1808GfxCount count, 1809ITextureResource * const * textures, 1810ResourceState src, 1811ResourceState dst) = 0 ; 1812virtual SLANG_NO_THROW void SLANG_MCALL textureSubresourceBarrier ( 1813ITextureResource * texture, 1814SubresourceRange subresourceRange, 1815ResourceState src, 1816ResourceState dst) = 0 ; 1817virtual SLANG_NO_THROW void SLANG_MCALL bufferBarrier ( 1818GfxCount count, 1819IBufferResource * const * buffers, 1820ResourceState src, 1821ResourceState dst) = 0 ; 1822virtual SLANG_NO_THROW void SLANG_MCALL clearResourceView ( 1823IResourceView * view, 1824ClearValue * clearValue, 1825ClearResourceViewFlags::Enum flags) = 0 ; 1826virtual SLANG_NO_THROW void SLANG_MCALL resolveResource ( 1827ITextureResource * source, 1828ResourceState sourceState, 1829SubresourceRange sourceRange, 1830ITextureResource * dest, 1831ResourceState destState, 1832SubresourceRange destRange) = 0 ; 1833virtual SLANG_NO_THROW void SLANG_MCALL resolveQuery ( 1834IQueryPool * queryPool, 1835GfxIndex index, 1836GfxCount count, 1837IBufferResource * buffer, 1838Offset offset) = 0 ; 1839virtual SLANG_NO_THROW void SLANG_MCALL 1840beginDebugEvent ( const char * name, float rgbColor[ 3 ]) = 0 ; 1841virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent () = 0 ; 1842inline void textureBarrier ( ITextureResource * texture, ResourceState src, ResourceState dst) 1843{ 1844textureBarrier ( 1 , & texture, src, dst); 1845} 1846inline void bufferBarrier ( IBufferResource * buffer, ResourceState src, ResourceState dst) 1847{ 1848bufferBarrier ( 1 , & buffer, src, dst); 1849} 1850}; 1851 1852class IRenderCommandEncoder : public IResourceCommandEncoder 1853{ 1854// {7A8D56D0-53E6-4AD6-85F7-D14DC110FDCE} 1855SLANG_COM_INTERFACE ( 18560x7a8d56d0 , 18570x53e6 , 18580x4ad6 , 1859{ 0x85 , 0xf7 , 0xd1 , 0x4d , 0xc1 , 0x10 , 0xfd , 0xce }) 1860public : 1861// Sets the current pipeline state. This method returns a transient shader object for 1862// writing shader parameters. This shader object will not retain any resources or 1863// sub-shader-objects bound to it. The user must be responsible for ensuring that any 1864// resources or shader objects that is set into `outRootShaderObject` stays alive during 1865// the execution of the command buffer. 1866virtual SLANG_NO_THROW Result SLANG_MCALL 1867bindPipeline (IPipelineState * state, IShaderObject ** outRootShaderObject) = 0 ; 1868inline IShaderObject * bindPipeline ( IPipelineState * state) 1869{ 1870IShaderObject * rootObject = nullptr ; 1871SLANG_RETURN_NULL_ON_FAIL ( bindPipeline (state, & rootObject)); 1872return rootObject; 1873} 1874 1875// Sets the current pipeline state along with a pre-created mutable root shader object. 1876virtual SLANG_NO_THROW Result SLANG_MCALL 1877bindPipelineWithRootObject (IPipelineState * state, IShaderObject * rootObject) = 0 ; 1878 1879virtual SLANG_NO_THROW void SLANG_MCALL 1880setViewports ( GfxCount count, const Viewport * viewports) = 0 ; 1881virtual SLANG_NO_THROW void SLANG_MCALL 1882setScissorRects ( GfxCount count, const ScissorRect * scissors) = 0 ; 1883 1884/// Sets the viewport, and sets the scissor rect to match the viewport. 1885inline void setViewportAndScissor ( Viewport const & viewport) 1886{ 1887setViewports ( 1 , & viewport); 1888ScissorRect rect = {}; 1889rect. maxX = static_cast < gfx::Int > (viewport. extentX ); 1890rect. maxY = static_cast < gfx::Int > (viewport. extentY ); 1891setScissorRects ( 1 , & rect); 1892} 1893 1894virtual SLANG_NO_THROW void SLANG_MCALL setPrimitiveTopology ( PrimitiveTopology topology) = 0 ; 1895virtual SLANG_NO_THROW void SLANG_MCALL setVertexBuffers ( 1896GfxIndex startSlot, 1897GfxCount slotCount, 1898IBufferResource * const * buffers, 1899const Offset * offsets) = 0 ; 1900inline void setVertexBuffer ( GfxIndex slot, IBufferResource * buffer, Offset offset = 0 ) 1901{ 1902setVertexBuffers (slot, 1 , & buffer, & offset); 1903} 1904 1905virtual SLANG_NO_THROW void SLANG_MCALL 1906setIndexBuffer ( IBufferResource * buffer, Format indexFormat, Offset offset = 0 ) = 0 ; 1907virtual SLANG_NO_THROW Result SLANG_MCALL 1908draw ( GfxCount vertexCount, GfxIndex startVertex = 0 ) = 0 ; 1909virtual SLANG_NO_THROW Result SLANG_MCALL 1910drawIndexed ( GfxCount indexCount, GfxIndex startIndex = 0 , GfxIndex baseVertex = 0 ) = 0 ; 1911virtual SLANG_NO_THROW Result SLANG_MCALL drawIndirect ( 1912GfxCount maxDrawCount, 1913IBufferResource * argBuffer, 1914Offset argOffset, 1915IBufferResource * countBuffer = nullptr , 1916Offset countOffset = 0 ) = 0 ; 1917virtual SLANG_NO_THROW Result SLANG_MCALL drawIndexedIndirect ( 1918GfxCount maxDrawCount, 1919IBufferResource * argBuffer, 1920Offset argOffset, 1921IBufferResource * countBuffer = nullptr , 1922Offset countOffset = 0 ) = 0 ; 1923virtual SLANG_NO_THROW void SLANG_MCALL setStencilReference ( uint32_t referenceValue) = 0 ; 1924virtual SLANG_NO_THROW Result SLANG_MCALL setSamplePositions ( 1925GfxCount samplesPerPixel, 1926GfxCount pixelCount, 1927const SamplePosition * samplePositions) = 0 ; 1928virtual SLANG_NO_THROW Result SLANG_MCALL drawInstanced ( 1929GfxCount vertexCount, 1930GfxCount instanceCount, 1931GfxIndex startVertex, 1932GfxIndex startInstanceLocation) = 0 ; 1933virtual SLANG_NO_THROW Result SLANG_MCALL drawIndexedInstanced ( 1934GfxCount indexCount, 1935GfxCount instanceCount, 1936GfxIndex startIndexLocation, 1937GfxIndex baseVertexLocation, 1938GfxIndex startInstanceLocation) = 0 ; 1939virtual SLANG_NO_THROW Result SLANG_MCALL drawMeshTasks ( int x, int y, int z) = 0 ; 1940}; 1941 1942class IComputeCommandEncoder : public IResourceCommandEncoder 1943{ 1944// {88AA9322-82F7-4FE6-A68A-29C7FE798737} 1945SLANG_COM_INTERFACE ( 19460x88aa9322 , 19470x82f7 , 19480x4fe6 , 1949{ 0xa6 , 0x8a , 0x29 , 0xc7 , 0xfe , 0x79 , 0x87 , 0x37 }) 1950 1951public : 1952// Sets the current pipeline state. This method returns a transient shader object for 1953// writing shader parameters. This shader object will not retain any resources or 1954// sub-shader-objects bound to it. The user must be responsible for ensuring that any 1955// resources or shader objects that is set into `outRooShaderObject` stays alive during 1956// the execution of the command buffer. 1957virtual SLANG_NO_THROW Result SLANG_MCALL 1958bindPipeline (IPipelineState * state, IShaderObject ** outRootShaderObject) = 0 ; 1959inline IShaderObject * bindPipeline ( IPipelineState * state) 1960{ 1961IShaderObject * rootObject = nullptr ; 1962SLANG_RETURN_NULL_ON_FAIL ( bindPipeline (state, & rootObject)); 1963return rootObject; 1964} 1965// Sets the current pipeline state along with a pre-created mutable root shader object. 1966virtual SLANG_NO_THROW Result SLANG_MCALL 1967bindPipelineWithRootObject (IPipelineState * state, IShaderObject * rootObject) = 0 ; 1968virtual SLANG_NO_THROW Result SLANG_MCALL dispatchCompute ( int x, int y, int z) = 0 ; 1969virtual SLANG_NO_THROW Result SLANG_MCALL 1970dispatchComputeIndirect ( IBufferResource * cmdBuffer, Offset offset) = 0 ; 1971}; 1972 1973enum class AccelerationStructureCopyMode 1974{ 1975Clone, 1976Compact 1977}; 1978 1979struct AccelerationStructureQueryDesc 1980{ 1981QueryType queryType ; 1982 1983IQueryPool * queryPool ; 1984 1985GfxIndex firstQueryIndex ; 1986}; 1987 1988class IRayTracingCommandEncoder : public IResourceCommandEncoder 1989{ 1990SLANG_COM_INTERFACE ( 19910x9a672b87 , 19920x5035 , 19930x45e3 , 1994{ 0x96 , 0x7c , 0x1f , 0x85 , 0xcd , 0xb3 , 0x63 , 0x4f }) 1995public : 1996virtual SLANG_NO_THROW void SLANG_MCALL buildAccelerationStructure( 1997const IAccelerationStructure ::BuildDesc & desc, 1998GfxCount propertyQueryCount, 1999AccelerationStructureQueryDesc * queryDescs) = 0 ; 2000virtual SLANG_NO_THROW void SLANG_MCALL copyAccelerationStructure ( 2001IAccelerationStructure * dest, 2002IAccelerationStructure * src, 2003AccelerationStructureCopyMode mode) = 0 ; 2004virtual SLANG_NO_THROW void SLANG_MCALL queryAccelerationStructureProperties ( 2005GfxCount accelerationStructureCount, 2006IAccelerationStructure * const * accelerationStructures, 2007GfxCount queryCount, 2008AccelerationStructureQueryDesc * queryDescs) = 0 ; 2009virtual SLANG_NO_THROW void SLANG_MCALL 2010serializeAccelerationStructure ( DeviceAddress dest, IAccelerationStructure * source) = 0 ; 2011virtual SLANG_NO_THROW void SLANG_MCALL 2012deserializeAccelerationStructure ( IAccelerationStructure * dest, DeviceAddress source) = 0 ; 2013 2014virtual SLANG_NO_THROW Result SLANG_MCALL 2015bindPipeline (IPipelineState * state, IShaderObject ** outRootObject) = 0 ; 2016// Sets the current pipeline state along with a pre-created mutable root shader object. 2017virtual SLANG_NO_THROW Result SLANG_MCALL 2018bindPipelineWithRootObject (IPipelineState * state, IShaderObject * rootObject) = 0 ; 2019 2020/// Issues a dispatch command to start ray tracing workload with a ray tracing pipeline. 2021/// `rayGenShaderIndex` specifies the index into the shader table that identifies the ray 2022/// generation shader. 2023virtual SLANG_NO_THROW Result SLANG_MCALL dispatchRays ( 2024GfxIndex rayGenShaderIndex, 2025IShaderTable * shaderTable, 2026GfxCount width, 2027GfxCount height, 2028GfxCount depth) = 0 ; 2029}; 2030 2031class ICommandBuffer : public ISlangUnknown 2032{ 2033public : 2034// Only one encoder may be open at a time. User must call `ICommandEncoder::endEncoding` 2035// before calling other `encode*Commands` methods. 2036// Once `endEncoding` is called, the `ICommandEncoder` object becomes obsolete and is 2037// invalid for further use. To continue recording, the user must request a new encoder 2038// object by calling one of the `encode*Commands` methods again. 2039virtual SLANG_NO_THROW void SLANG_MCALL encodeRenderCommands ( 2040IRenderPassLayout * renderPass, 2041IFramebuffer * framebuffer, 2042IRenderCommandEncoder ** outEncoder) = 0 ; 2043inline IRenderCommandEncoder * encodeRenderCommands ( 2044IRenderPassLayout * renderPass, 2045IFramebuffer * framebuffer) 2046{ 2047IRenderCommandEncoder * result; 2048encodeRenderCommands (renderPass, framebuffer, & result); 2049return result; 2050} 2051 2052virtual SLANG_NO_THROW void SLANG_MCALL 2053encodeComputeCommands (IComputeCommandEncoder ** outEncoder) = 0 ; 2054inline IComputeCommandEncoder * encodeComputeCommands () 2055{ 2056IComputeCommandEncoder * result; 2057encodeComputeCommands ( & result); 2058return result; 2059} 2060 2061virtual SLANG_NO_THROW void SLANG_MCALL 2062encodeResourceCommands (IResourceCommandEncoder ** outEncoder) = 0 ; 2063inline IResourceCommandEncoder * encodeResourceCommands () 2064{ 2065IResourceCommandEncoder * result; 2066encodeResourceCommands ( & result); 2067return result; 2068} 2069 2070virtual SLANG_NO_THROW void SLANG_MCALL 2071encodeRayTracingCommands (IRayTracingCommandEncoder ** outEncoder) = 0 ; 2072inline IRayTracingCommandEncoder * encodeRayTracingCommands () 2073{ 2074IRayTracingCommandEncoder * result; 2075encodeRayTracingCommands ( & result); 2076return result; 2077} 2078 2079virtual SLANG_NO_THROW void SLANG_MCALL close () = 0 ; 2080 2081virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle (InteropHandle * outHandle) = 0 ; 2082}; 2083#define SLANG_UUID_ICommandBuffer \ 2084{ \ 20850x5d56063f, 0x91d4, 0x4723, \ 2086{ \ 20870xa7, 0xa7, 0x7a, 0x15, 0xaf, 0x93, 0xeb, 0x48 \ 2088} \ 2089} 2090 2091class ICommandBufferD3D12 : public ICommandBuffer 2092{ 2093public : 2094virtual SLANG_NO_THROW void SLANG_MCALL invalidateDescriptorHeapBinding () = 0 ; 2095virtual SLANG_NO_THROW void SLANG_MCALL ensureInternalDescriptorHeapsBound () = 0 ; 2096}; 2097#define SLANG_UUID_ICommandBufferD3D12 \ 2098{ \ 20990xd56b7616, 0x6c14, 0x4841, \ 2100{ \ 21010x9d, 0x9c, 0x7b, 0x7f, 0xdb, 0x9f, 0xd9, 0xb8 \ 2102} \ 2103} 2104 2105class ICommandQueue : public ISlangUnknown 2106{ 2107public : 2108enum class QueueType 2109{ 2110Graphics 2111}; 2112struct Desc 2113{ 2114QueueType type ; 2115}; 2116 2117// For D3D12, this is the pointer to the queue. For Vulkan, this is the queue itself. 2118typedef uint64_t NativeHandle ; 2119 2120virtual SLANG_NO_THROW const Desc & SLANG_MCALL getDesc () = 0 ; 2121 2122virtual SLANG_NO_THROW void SLANG_MCALL executeCommandBuffers ( 2123GfxCount count, 2124ICommandBuffer * const * commandBuffers, 2125IFence * fenceToSignal, 2126uint64_t newFenceValue) = 0 ; 2127inline void executeCommandBuffer ( 2128ICommandBuffer * commandBuffer, 2129IFence * fenceToSignal = nullptr , 2130uint64_t newFenceValue = 0 ) 2131{ 2132executeCommandBuffers ( 1 , & commandBuffer, fenceToSignal, newFenceValue); 2133} 2134 2135virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle (InteropHandle * outHandle) = 0 ; 2136 2137virtual SLANG_NO_THROW void SLANG_MCALL waitOnHost () = 0 ; 2138 2139/// Queues a device side wait for the given fences. 2140virtual SLANG_NO_THROW Result SLANG_MCALL 2141waitForFenceValuesOnDevice ( GfxCount fenceCount, IFence ** fences, uint64_t * waitValues) = 0 ; 2142}; 2143#define SLANG_UUID_ICommandQueue \ 2144{ \ 21450x14e2bed0, 0xad0, 0x4dc8, \ 2146{ \ 21470xb3, 0x41, 0x6, 0x3f, 0xe7, 0x2d, 0xbf, 0xe \ 2148} \ 2149} 2150 2151class ITransientResourceHeap : public ISlangUnknown 2152{ 2153public : 2154struct Flags 2155{ 2156enum Enum 2157{ 2158None = 0 , 2159AllowResizing = 0x1 , 2160}; 2161}; 2162struct Desc 2163{ 2164Flags :: Enum flags ; 2165Size constantBufferSize ; 2166GfxCount samplerDescriptorCount ; 2167GfxCount uavDescriptorCount ; 2168GfxCount srvDescriptorCount ; 2169GfxCount constantBufferDescriptorCount ; 2170GfxCount accelerationStructureDescriptorCount ; 2171}; 2172 2173// Waits until GPU commands issued before last call to `finish()` has been completed, and resets 2174// all transient resources holds by the heap. 2175// This method must be called before using the transient heap to issue new GPU commands. 2176// In most situations this method should be called at the beginning of each frame. 2177virtual SLANG_NO_THROW Result SLANG_MCALL synchronizeAndReset () = 0 ; 2178 2179// Must be called when the application has done using this heap to issue commands. In most 2180// situations this method should be called at the end of each frame. 2181virtual SLANG_NO_THROW Result SLANG_MCALL finish () = 0 ; 2182 2183// Command buffers are one-time use. Once it is submitted to the queue via 2184// `executeCommandBuffers` a command buffer is no longer valid to be used any more. Command 2185// buffers must be closed before submission. The current D3D12 implementation has a limitation 2186// that only one command buffer maybe recorded at a time. User must finish recording a command 2187// buffer before creating another command buffer. 2188virtual SLANG_NO_THROW Result SLANG_MCALL 2189createCommandBuffer (ICommandBuffer ** outCommandBuffer) = 0 ; 2190inline ComPtr < ICommandBuffer > createCommandBuffer () 2191{ 2192ComPtr < ICommandBuffer > result; 2193SLANG_RETURN_NULL_ON_FAIL ( createCommandBuffer (result. writeRef ())); 2194return result; 2195} 2196}; 2197#define SLANG_UUID_ITransientResourceHeap \ 2198{ \ 21990xcd48bd29, 0xee72, 0x41b8, \ 2200{ \ 22010xbc, 0xff, 0xa, 0x2b, 0x3a, 0xaa, 0x6d, 0xeb \ 2202} \ 2203} 2204 2205class ITransientResourceHeapD3D12 : public ISlangUnknown 2206{ 2207public : 2208enum class DescriptorType 2209{ 2210ResourceView, 2211Sampler 2212}; 2213virtual SLANG_NO_THROW Result SLANG_MCALL allocateTransientDescriptorTable ( 2214DescriptorType type, 2215GfxCount count, 2216Offset & outDescriptorOffset, 2217void ** outD3DDescriptorHeapHandle) = 0 ; 2218}; 2219#define SLANG_UUID_ITransientResourceHeapD3D12 \ 2220{ \ 22210x9bc6a8bc, 0x5f7a, 0x454a, \ 2222{ \ 22230x93, 0xef, 0x3b, 0x10, 0x5b, 0xb7, 0x63, 0x7e \ 2224} \ 2225} 2226 2227class ISwapchain : public ISlangUnknown 2228{ 2229public : 2230struct Desc 2231{ 2232Format format ; 2233GfxCount width , height ; 2234GfxCount imageCount ; 2235ICommandQueue * queue ; 2236bool enableVSync ; 2237}; 2238virtual SLANG_NO_THROW const Desc & SLANG_MCALL getDesc () = 0 ; 2239 2240/// Returns the back buffer image at `index`. 2241virtual SLANG_NO_THROW Result SLANG_MCALL 2242getImage ( GfxIndex index, ITextureResource ** outResource) = 0 ; 2243 2244/// Present the next image in the swapchain. 2245virtual SLANG_NO_THROW Result SLANG_MCALL present () = 0 ; 2246 2247/// Returns the index of next back buffer image that will be presented in the next 2248/// `present` call. If the swapchain is invalid/out-of-date, this method returns -1. 2249virtual SLANG_NO_THROW int SLANG_MCALL acquireNextImage () = 0 ; 2250 2251/// Resizes the back buffers of this swapchain. All render target views and framebuffers 2252/// referencing the back buffer images must be freed before calling this method. 2253virtual SLANG_NO_THROW Result SLANG_MCALL resize ( GfxCount width, GfxCount height) = 0 ; 2254 2255// Check if the window is occluded. 2256virtual SLANG_NO_THROW bool SLANG_MCALL isOccluded () = 0 ; 2257 2258// Toggle full screen mode. 2259virtual SLANG_NO_THROW Result SLANG_MCALL setFullScreenMode ( bool mode) = 0 ; 2260}; 2261#define SLANG_UUID_ISwapchain \ 2262{ \ 22630xbe91ba6c, 0x784, 0x4308, \ 2264{ \ 22650xa1, 0x0, 0x19, 0xc3, 0x66, 0x83, 0x44, 0xb2 \ 2266} \ 2267} 2268 2269struct AdapterLUID 2270{ 2271uint8_t luid [ 16 ]; 2272 2273bool operator == ( const AdapterLUID & other ) const 2274{ 2275for ( size_t i = 0 ; i < sizeof ( AdapterLUID ::luid); ++ i ) 2276if ( luid [i] != other.luid[i]) 2277return false ; 2278return true ; 2279} 2280bool operator != ( const AdapterLUID & other) const { return !this -> operator == (other); } 2281}; 2282 2283struct AdapterInfo 2284{ 2285// Descriptive name of the adapter. 2286char name [ 128 ]; 2287 2288// Unique identifier for the vendor (only available for D3D and Vulkan). 2289uint32_t vendorID ; 2290 2291// Unique identifier for the physical device among devices from the vendor (only available for 2292// D3D and Vulkan) 2293uint32_t deviceID ; 2294 2295// Logically unique identifier of the adapter. 2296AdapterLUID luid ; 2297}; 2298 2299class AdapterList 2300{ 2301public : 2302AdapterList (ISlangBlob * blob) 2303: m_blob( blob ) 2304{ 2305} 2306 2307const AdapterInfo * getAdapters () const 2308{ 2309return reinterpret_cast < const AdapterInfo *> (m_blob ? m_blob -> getBufferPointer () : nullptr ); 2310} 2311 2312GfxCount getCount () const 2313{ 2314return (GfxCount)(m_blob ? m_blob -> getBufferSize () / sizeof (AdapterInfo) : 0 ); 2315} 2316 2317private : 2318ComPtr < ISlangBlob > m_blob; 2319}; 2320 2321struct DeviceLimits 2322{ 2323/// Maximum dimension for 1D textures. 2324uint32_t maxTextureDimension1D ; 2325/// Maximum dimensions for 2D textures. 2326uint32_t maxTextureDimension2D ; 2327/// Maximum dimensions for 3D textures. 2328uint32_t maxTextureDimension3D ; 2329/// Maximum dimensions for cube textures. 2330uint32_t maxTextureDimensionCube ; 2331/// Maximum number of texture layers. 2332uint32_t maxTextureArrayLayers ; 2333 2334/// Maximum number of vertex input elements in a graphics pipeline. 2335uint32_t maxVertexInputElements ; 2336/// Maximum offset of a vertex input element in the vertex stream. 2337uint32_t maxVertexInputElementOffset ; 2338/// Maximum number of vertex streams in a graphics pipeline. 2339uint32_t maxVertexStreams ; 2340/// Maximum stride of a vertex stream. 2341uint32_t maxVertexStreamStride ; 2342 2343/// Maximum number of threads per thread group. 2344uint32_t maxComputeThreadsPerGroup ; 2345/// Maximum dimensions of a thread group. 2346uint32_t maxComputeThreadGroupSize [ 3 ]; 2347/// Maximum number of thread groups per dimension in a single dispatch. 2348uint32_t maxComputeDispatchThreadGroups [ 3 ]; 2349 2350/// Maximum number of viewports per pipeline. 2351uint32_t maxViewports ; 2352/// Maximum viewport dimensions. 2353uint32_t maxViewportDimensions [ 2 ]; 2354/// Maximum framebuffer dimensions. 2355uint32_t maxFramebufferDimensions [ 3 ]; 2356 2357/// Maximum samplers visible in a shader stage. 2358uint32_t maxShaderVisibleSamplers ; 2359}; 2360 2361struct DeviceInfo 2362{ 2363DeviceType deviceType ; 2364 2365DeviceLimits limits ; 2366 2367BindingStyle bindingStyle ; 2368 2369ProjectionStyle projectionStyle ; 2370 2371/// An projection matrix that ensures x, y mapping to pixels 2372/// is the same on all targets 2373float identityProjectionMatrix [ 16 ]; 2374 2375/// The name of the graphics API being used by this device. 2376const char * apiName = nullptr; 2377 2378/// The name of the graphics adapter. 2379const char * adapterName = nullptr; 2380 2381/// The clock frequency used in timestamp queries. 2382uint64_t timestampFrequency = 0 ; 2383}; 2384 2385enum class DebugMessageType 2386{ 2387Info, 2388Warning, 2389Error 2390}; 2391enum class DebugMessageSource 2392{ 2393Layer, 2394Driver, 2395Slang 2396}; 2397class IDebugCallback 2398{ 2399public : 2400virtual SLANG_NO_THROW void SLANG_MCALL 2401handleMessage ( DebugMessageType type, DebugMessageSource source, const char * message) = 0 ; 2402}; 2403 2404class IDevice : public ISlangUnknown 2405{ 2406public : 2407struct SlangDesc 2408{ 2409slang :: IGlobalSession * slangGlobalSession = 2410nullptr; // (optional) A slang global session object. If null will create automatically. 2411 2412SlangMatrixLayoutMode defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_ROW_MAJOR ; 2413 2414char const * const * searchPaths = nullptr; 2415GfxCount searchPathCount = 0 ; 2416 2417slang :: PreprocessorMacroDesc const * preprocessorMacros = nullptr; 2418GfxCount preprocessorMacroCount = 0 ; 2419 2420const char * targetProfile = nullptr; // (optional) Target shader profile. If null this will 2421// be set to platform dependent default. 2422SlangFloatingPointMode floatingPointMode = SLANG_FLOATING_POINT_MODE_DEFAULT ; 2423SlangOptimizationLevel optimizationLevel = SLANG_OPTIMIZATION_LEVEL_DEFAULT ; 2424SlangTargetFlags targetFlags = kDefaultTargetFlags ; 2425SlangLineDirectiveMode lineDirectiveMode = SLANG_LINE_DIRECTIVE_MODE_DEFAULT ; 2426}; 2427 2428struct ShaderCacheDesc 2429{ 2430// The root directory for the shader cache. If not set, shader cache is disabled. 2431const char * shaderCachePath = nullptr; 2432// The maximum number of entries stored in the cache. By default, there is no limit. 2433GfxCount maxEntryCount = 0 ; 2434}; 2435 2436struct InteropHandles 2437{ 2438InteropHandle handles [ 3 ] = {}; 2439}; 2440 2441struct Desc 2442{ 2443// The underlying API/Platform of the device. 2444DeviceType deviceType = DeviceType::Default; 2445// The device's handles (if they exist) and their associated API. For D3D12, this contains a 2446// single InteropHandle for the ID3D12Device. For Vulkan, the first InteropHandle is the 2447// VkInstance, the second is the VkPhysicalDevice, and the third is the VkDevice. For CUDA, 2448// this only contains a single value for the CUDADevice. 2449InteropHandles existingDeviceHandles ; 2450// LUID of the adapter to use. Use getGfxAdapters() to get a list of available adapters. 2451const AdapterLUID * adapterLUID = nullptr; 2452// Number of required features. 2453GfxCount requiredFeatureCount = 0 ; 2454// Array of required feature names, whose size is `requiredFeatureCount`. 2455const char ** requiredFeatures = nullptr; 2456// A command dispatcher object that intercepts and handles actual low-level API call. 2457ISlangUnknown * apiCommandDispatcher = nullptr; 2458// The slot (typically UAV) used to identify NVAPI intrinsics. If >=0 NVAPI is required. 2459GfxIndex nvapiExtnSlot = -1 ; 2460// Configurations for the shader cache. 2461ShaderCacheDesc shaderCache = {}; 2462// Configurations for Slang compiler. 2463SlangDesc slang = {}; 2464 2465GfxCount extendedDescCount = 0 ; 2466void ** extendedDescs = nullptr ; 2467}; 2468 2469virtual SLANG_NO_THROW Result SLANG_MCALL 2470getNativeDeviceHandles (InteropHandles * outHandles) = 0 ; 2471 2472virtual SLANG_NO_THROW bool SLANG_MCALL hasFeature ( const char * feature) = 0 ; 2473 2474/// Returns a list of features supported by the renderer. 2475virtual SLANG_NO_THROW Result SLANG_MCALL 2476getFeatures ( const char ** outFeatures, Size bufferSize, GfxCount * outFeatureCount) = 0 ; 2477 2478virtual SLANG_NO_THROW Result SLANG_MCALL 2479getFormatSupportedResourceStates ( Format format, ResourceStateSet * outStates) = 0 ; 2480 2481virtual SLANG_NO_THROW Result SLANG_MCALL 2482getSlangSession ( slang :: ISession ** outSlangSession) = 0 ; 2483 2484inline ComPtr < slang::ISession > getSlangSession () 2485{ 2486ComPtr < slang::ISession > result; 2487getSlangSession (result. writeRef ()); 2488return result; 2489} 2490 2491virtual SLANG_NO_THROW Result SLANG_MCALL createTransientResourceHeap( 2492const ITransientResourceHeap ::Desc & desc, 2493ITransientResourceHeap ** outHeap) = 0 ; 2494inline ComPtr < ITransientResourceHeap > createTransientResourceHeap ( 2495const ITransientResourceHeap ::Desc & desc) 2496{ 2497ComPtr < ITransientResourceHeap > result; 2498createTransientResourceHeap (desc, result. writeRef ()); 2499return result; 2500} 2501 2502/// Create a texture resource. 2503/// 2504/// If `initData` is non-null, then it must point to an array of 2505/// `ITextureResource::SubresourceData` with one element for each 2506/// subresource of the texture being created. 2507/// 2508/// The number of subresources in a texture is: 2509/// 2510/// effectiveElementCount * mipLevelCount 2511/// 2512/// where the effective element count is computed as: 2513/// 2514/// effectiveElementCount = (isArray ? arrayElementCount : 1) * (isCube ? 6 : 1); 2515/// 2516virtual SLANG_NO_THROW Result SLANG_MCALL createTextureResource ( 2517const ITextureResource ::Desc & desc, 2518const ITextureResource::SubresourceData * initData, 2519ITextureResource ** outResource) = 0 ; 2520 2521/// Create a texture resource. initData holds the initialize data to set the contents of the 2522/// texture when constructed. 2523inline SLANG_NO_THROW ComPtr < ITextureResource > createTextureResource ( 2524const ITextureResource ::Desc & desc, 2525const ITextureResource ::SubresourceData * initData = nullptr ) 2526{ 2527ComPtr < ITextureResource > resource; 2528SLANG_RETURN_NULL_ON_FAIL ( createTextureResource (desc, initData, resource. writeRef ())); 2529return resource; 2530} 2531 2532virtual SLANG_NO_THROW Result SLANG_MCALL createTextureFromNativeHandle ( 2533InteropHandle handle, 2534const ITextureResource ::Desc & srcDesc, 2535ITextureResource ** outResource) = 0 ; 2536 2537virtual SLANG_NO_THROW Result SLANG_MCALL createTextureFromSharedHandle ( 2538InteropHandle handle, 2539const ITextureResource ::Desc & srcDesc, 2540const Size size, 2541ITextureResource ** outResource) = 0 ; 2542 2543/// Create a buffer resource 2544virtual SLANG_NO_THROW Result SLANG_MCALL createBufferResource( 2545const IBufferResource ::Desc & desc, 2546const void * initData, 2547IBufferResource ** outResource) = 0 ; 2548 2549inline SLANG_NO_THROW ComPtr < IBufferResource > createBufferResource ( 2550const IBufferResource ::Desc & desc, 2551const void * initData = nullptr ) 2552{ 2553ComPtr < IBufferResource > resource; 2554SLANG_RETURN_NULL_ON_FAIL ( createBufferResource (desc, initData, resource. writeRef ())); 2555return resource; 2556} 2557 2558virtual SLANG_NO_THROW Result SLANG_MCALL createBufferFromNativeHandle ( 2559InteropHandle handle, 2560const IBufferResource ::Desc & srcDesc, 2561IBufferResource ** outResource) = 0 ; 2562 2563virtual SLANG_NO_THROW Result SLANG_MCALL createBufferFromSharedHandle ( 2564InteropHandle handle, 2565const IBufferResource ::Desc & srcDesc, 2566IBufferResource ** outResource) = 0 ; 2567 2568virtual SLANG_NO_THROW Result SLANG_MCALL 2569createSamplerState( ISamplerState :: Desc const & desc, ISamplerState ** outSampler) = 0 ; 2570 2571inline ComPtr < ISamplerState > createSamplerState ( ISamplerState ::Desc const & desc) 2572{ 2573ComPtr < ISamplerState > sampler; 2574SLANG_RETURN_NULL_ON_FAIL ( createSamplerState (desc, sampler. writeRef ())); 2575return sampler; 2576} 2577 2578virtual SLANG_NO_THROW Result SLANG_MCALL createTextureView ( 2579ITextureResource * texture, 2580IResourceView::Desc const & desc, 2581IResourceView ** outView) = 0 ; 2582 2583inline ComPtr < IResourceView > createTextureView ( 2584ITextureResource * texture, 2585IResourceView ::Desc const & desc) 2586{ 2587ComPtr < IResourceView > view; 2588SLANG_RETURN_NULL_ON_FAIL ( createTextureView (texture, desc, view. writeRef ())); 2589return view; 2590} 2591 2592virtual SLANG_NO_THROW Result SLANG_MCALL createBufferView ( 2593IBufferResource * buffer, 2594IBufferResource * counterBuffer, 2595IResourceView::Desc const & desc, 2596IResourceView ** outView) = 0 ; 2597 2598inline ComPtr < IResourceView > createBufferView ( 2599IBufferResource * buffer, 2600IBufferResource * counterBuffer, 2601IResourceView ::Desc const & desc) 2602{ 2603ComPtr < IResourceView > view; 2604SLANG_RETURN_NULL_ON_FAIL ( createBufferView (buffer, counterBuffer, desc, view. writeRef ())); 2605return view; 2606} 2607 2608virtual SLANG_NO_THROW Result SLANG_MCALL createFramebufferLayout( 2609IFramebufferLayout :: Desc const & desc, 2610IFramebufferLayout ** outFrameBuffer) = 0 ; 2611inline ComPtr < IFramebufferLayout > createFramebufferLayout ( IFramebufferLayout ::Desc const & desc) 2612{ 2613ComPtr < IFramebufferLayout > fb; 2614SLANG_RETURN_NULL_ON_FAIL ( createFramebufferLayout (desc, fb. writeRef ())); 2615return fb; 2616} 2617 2618virtual SLANG_NO_THROW Result SLANG_MCALL 2619createFramebuffer( IFramebuffer :: Desc const & desc, IFramebuffer ** outFrameBuffer) = 0 ; 2620inline ComPtr < IFramebuffer > createFramebuffer ( IFramebuffer ::Desc const & desc) 2621{ 2622ComPtr < IFramebuffer > fb; 2623SLANG_RETURN_NULL_ON_FAIL ( createFramebuffer (desc, fb. writeRef ())); 2624return fb; 2625} 2626 2627virtual SLANG_NO_THROW Result SLANG_MCALL createRenderPassLayout( 2628const IRenderPassLayout ::Desc & desc, 2629IRenderPassLayout ** outRenderPassLayout) = 0 ; 2630inline ComPtr < IRenderPassLayout > createRenderPassLayout ( const IRenderPassLayout ::Desc & desc) 2631{ 2632ComPtr < IRenderPassLayout > rs; 2633SLANG_RETURN_NULL_ON_FAIL ( createRenderPassLayout (desc, rs. writeRef ())); 2634return rs; 2635} 2636 2637virtual SLANG_NO_THROW Result SLANG_MCALL createSwapchain( 2638ISwapchain :: Desc const & desc, 2639WindowHandle window, 2640ISwapchain ** outSwapchain) = 0 ; 2641inline ComPtr < ISwapchain > createSwapchain ( ISwapchain ::Desc const & desc, WindowHandle window) 2642{ 2643ComPtr < ISwapchain > swapchain; 2644SLANG_RETURN_NULL_ON_FAIL ( createSwapchain (desc, window, swapchain. writeRef ())); 2645return swapchain; 2646} 2647 2648virtual SLANG_NO_THROW Result SLANG_MCALL 2649createInputLayout( IInputLayout :: Desc const & desc, IInputLayout ** outLayout) = 0 ; 2650 2651inline ComPtr < IInputLayout > createInputLayout ( IInputLayout ::Desc const & desc) 2652{ 2653ComPtr < IInputLayout > layout; 2654SLANG_RETURN_NULL_ON_FAIL ( createInputLayout (desc, layout. writeRef ())); 2655return layout; 2656} 2657 2658inline Result createInputLayout ( 2659Size vertexSize, 2660InputElementDesc const * inputElements, 2661GfxCount inputElementCount, 2662IInputLayout ** outLayout) 2663{ 2664VertexStreamDesc streamDesc = {vertexSize, InputSlotClass ::PerVertex, 0 }; 2665 2666IInputLayout :: Desc inputLayoutDesc = {}; 2667inputLayoutDesc. inputElementCount = inputElementCount; 2668inputLayoutDesc. inputElements = inputElements; 2669inputLayoutDesc. vertexStreamCount = 1 ; 2670inputLayoutDesc. vertexStreams = & streamDesc; 2671return createInputLayout (inputLayoutDesc, outLayout); 2672} 2673 2674inline ComPtr < IInputLayout > createInputLayout ( 2675Size vertexSize, 2676InputElementDesc const * inputElements, 2677GfxCount inputElementCount) 2678{ 2679ComPtr < IInputLayout > layout; 2680SLANG_RETURN_NULL_ON_FAIL ( 2681createInputLayout (vertexSize, inputElements, inputElementCount, layout. writeRef ())); 2682return layout; 2683} 2684 2685virtual SLANG_NO_THROW Result SLANG_MCALL 2686createCommandQueue( const ICommandQueue ::Desc & desc, ICommandQueue ** outQueue) = 0 ; 2687inline ComPtr < ICommandQueue > createCommandQueue ( const ICommandQueue ::Desc & desc) 2688{ 2689ComPtr < ICommandQueue > queue; 2690SLANG_RETURN_NULL_ON_FAIL ( createCommandQueue (desc, queue. writeRef ())); 2691return queue; 2692} 2693 2694virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObject ( 2695slang :: TypeReflection * type, 2696ShaderObjectContainerType container, 2697IShaderObject ** outObject) = 0 ; 2698 2699inline ComPtr < IShaderObject > createShaderObject ( slang ::TypeReflection * type) 2700{ 2701ComPtr < IShaderObject > object; 2702SLANG_RETURN_NULL_ON_FAIL ( 2703createShaderObject (type, ShaderObjectContainerType::None, object. writeRef ())); 2704return object; 2705} 2706 2707virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObject ( 2708slang :: TypeReflection * type, 2709ShaderObjectContainerType container, 2710IShaderObject ** outObject) = 0 ; 2711 2712virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObjectFromTypeLayout( 2713slang ::TypeLayoutReflection * typeLayout, 2714IShaderObject ** outObject) = 0 ; 2715 2716virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObjectFromTypeLayout( 2717slang ::TypeLayoutReflection * typeLayout, 2718IShaderObject ** outObject) = 0 ; 2719 2720virtual SLANG_NO_THROW Result SLANG_MCALL 2721createMutableRootShaderObject (IShaderProgram * program, IShaderObject ** outObject) = 0 ; 2722 2723virtual SLANG_NO_THROW Result SLANG_MCALL 2724createShaderTable( const IShaderTable ::Desc & desc, IShaderTable ** outTable) = 0 ; 2725 2726virtual SLANG_NO_THROW Result SLANG_MCALL createProgram( 2727const IShaderProgram ::Desc & desc, 2728IShaderProgram ** outProgram, 2729ISlangBlob ** outDiagnosticBlob = nullptr ) = 0 ; 2730 2731inline ComPtr < IShaderProgram > createProgram ( const IShaderProgram ::Desc & desc) 2732{ 2733ComPtr < IShaderProgram > program; 2734SLANG_RETURN_NULL_ON_FAIL ( createProgram (desc, program. writeRef ())); 2735return program; 2736} 2737 2738virtual SLANG_NO_THROW Result SLANG_MCALL createProgram2( 2739const IShaderProgram ::CreateDesc2 & createDesc, 2740IShaderProgram ** outProgram, 2741ISlangBlob ** outDiagnosticBlob = nullptr ) = 0 ; 2742 2743virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState( 2744const GraphicsPipelineStateDesc & desc, 2745IPipelineState ** outState) = 0 ; 2746 2747inline ComPtr < IPipelineState > createGraphicsPipelineState ( const GraphicsPipelineStateDesc & desc) 2748{ 2749ComPtr < IPipelineState > state; 2750SLANG_RETURN_NULL_ON_FAIL ( createGraphicsPipelineState (desc, state. writeRef ())); 2751return state; 2752} 2753 2754virtual SLANG_NO_THROW Result SLANG_MCALL 2755createComputePipelineState( const ComputePipelineStateDesc & desc, IPipelineState ** outState) = 0 ; 2756 2757inline ComPtr < IPipelineState > createComputePipelineState ( const ComputePipelineStateDesc & desc) 2758{ 2759ComPtr < IPipelineState > state; 2760SLANG_RETURN_NULL_ON_FAIL ( createComputePipelineState (desc, state. writeRef ())); 2761return state; 2762} 2763 2764virtual SLANG_NO_THROW Result SLANG_MCALL createRayTracingPipelineState( 2765const RayTracingPipelineStateDesc & desc, 2766IPipelineState ** outState) = 0 ; 2767 2768/// Read back texture resource and stores the result in `outBlob`. 2769virtual SLANG_NO_THROW SlangResult SLANG_MCALL readTextureResource ( 2770ITextureResource * resource, 2771ResourceState state, 2772ISlangBlob ** outBlob, 2773Size * outRowPitch, 2774Size * outPixelSize) = 0 ; 2775 2776virtual SLANG_NO_THROW SlangResult SLANG_MCALL 2777readBufferResource ( IBufferResource * buffer, Offset offset, Size size, ISlangBlob ** outBlob) = 0 ; 2778 2779/// Get the type of this renderer 2780virtual SLANG_NO_THROW const DeviceInfo & SLANG_MCALL getDeviceInfo () const = 0 ; 2781 2782virtual SLANG_NO_THROW Result SLANG_MCALL 2783createQueryPool( const IQueryPool ::Desc & desc, IQueryPool ** outPool ) = 0 ; 2784 2785 2786virtual SLANG_NO_THROW Result SLANG_MCALL getAccelerationStructurePrebuildInfo( 2787const IAccelerationStructure ::BuildInputs & buildInputs, 2788IAccelerationStructure :: PrebuildInfo * outPrebuildInfo ) = 0 ; 2789 2790virtual SLANG_NO_THROW Result SLANG_MCALL createAccelerationStructure( 2791const IAccelerationStructure ::CreateDesc & desc, 2792IAccelerationStructure ** outView ) = 0 ; 2793 2794virtual SLANG_NO_THROW Result SLANG_MCALL 2795createFence( const IFence ::Desc & desc, IFence ** outFence ) = 0 ; 2796 2797/// Wait on the host for the fences to signals. 2798/// `timeout` is in nanoseconds, can be set to `kTimeoutInfinite`. 2799virtual SLANG_NO_THROW Result SLANG_MCALL waitForFences ( 2800GfxCount fenceCount, 2801IFence ** fences, 2802uint64_t * values, 2803bool waitForAll, 2804uint64_t timeout) = 0 ; 2805 2806virtual SLANG_NO_THROW Result SLANG_MCALL getTextureAllocationInfo( 2807const ITextureResource ::Desc & desc, 2808Size * outSize, 2809Size * outAlignment) = 0 ; 2810 2811virtual SLANG_NO_THROW Result SLANG_MCALL getTextureRowAlignment ( Size * outAlignment) = 0 ; 2812 2813virtual SLANG_NO_THROW Result SLANG_MCALL getCooperativeVectorProperties ( 2814CooperativeVectorProperties * properties, 2815uint32_t * propertyCount) = 0 ; 2816 2817virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObject2( 2818slang :: ISession * slangSession, 2819slang::TypeReflection * type, 2820ShaderObjectContainerType container, 2821IShaderObject ** outObject) = 0 ; 2822 2823virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObject2( 2824slang :: ISession * slangSession, 2825slang::TypeReflection * type, 2826ShaderObjectContainerType container, 2827IShaderObject ** outObject) = 0 ; 2828}; 2829 2830#define SLANG_UUID_IDevice \ 2831{ \ 28320x715bdf26 , 0x5135 , 0x11eb , \ 2833{ \ 28340xAE , 0x93 , 0x02 , 0x42 , 0xAC , 0x13 , 0x00 , 0x02 \ 2835} \ 2836} 2837 2838struct ShaderCacheStats 2839{ 2840GfxCount hitCount; 2841GfxCount missCount; 2842GfxCount entryCount; 2843}; 2844 2845// These are exclusively used to track hit/miss counts for shader cache entries. Entry hit and 2846// miss counts specifically indicate if the file containing relevant shader code was found in 2847// the cache, while the general hit and miss counts indicate whether the file was both found and 2848// up-to-date. 2849class IShaderCache : public ISlangUnknown 2850{ 2851public : 2852virtual SLANG_NO_THROW Result SLANG_MCALL clearShaderCache () = 0 ; 2853virtual SLANG_NO_THROW Result SLANG_MCALL getShaderCacheStats (ShaderCacheStats * outStats) = 0 ; 2854virtual SLANG_NO_THROW Result SLANG_MCALL resetShaderCacheStats () = 0 ; 2855}; 2856 2857#define SLANG_UUID_IShaderCache \ 2858{ \ 28590x8eccc8ec, 0x5c04, 0x4a51, \ 2860{ \ 28610x99, 0x75, 0x13, 0xf8, 0xfe, 0xa1, 0x59, 0xf3 \ 2862} \ 2863} 2864 2865class IPipelineCreationAPIDispatcher : public ISlangUnknown 2866{ 2867public : 2868virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState ( 2869IDevice * device, 2870slang::IComponentType * program, 2871void * pipelineDesc, 2872void ** outPipelineState) = 0 ; 2873virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState ( 2874IDevice * device, 2875slang::IComponentType * program, 2876void * pipelineDesc, 2877void ** outPipelineState) = 0 ; 2878virtual SLANG_NO_THROW Result SLANG_MCALL createMeshPipelineState ( 2879IDevice * device, 2880slang::IComponentType * program, 2881void * pipelineDesc, 2882void ** outPipelineState) = 0 ; 2883virtual SLANG_NO_THROW Result SLANG_MCALL 2884beforeCreateRayTracingState (IDevice * device, slang::IComponentType * program) = 0 ; 2885virtual SLANG_NO_THROW Result SLANG_MCALL 2886afterCreateRayTracingState (IDevice * device, slang::IComponentType * program) = 0 ; 2887}; 2888#define SLANG_UUID_IPipelineCreationAPIDispatcher \ 2889{ \ 28900xc3d5f782, 0xeae1, 0x4da6, \ 2891{ \ 28920xab, 0x40, 0x75, 0x32, 0x31, 0x2, 0xb7, 0xdc \ 2893} \ 2894} 2895 2896#define SLANG_UUID_IVulkanPipelineCreationAPIDispatcher \ 2897{ \ 28980x4fcf1274, 0x8752, 0x4743, \ 2899{ \ 29000xb3, 0x51, 0x47, 0xcb, 0x83, 0x71, 0xef, 0x99 \ 2901} \ 2902} 2903 2904// Global public functions 2905 2906extern "C" 2907{ 2908/// Checks if format is compressed 2909SLANG_GFX_API bool SLANG_MCALL gfxIsCompressedFormat ( Format format); 2910 2911/// Checks if format is typeless 2912SLANG_GFX_API bool SLANG_MCALL gfxIsTypelessFormat ( Format format); 2913 2914/// Gets information about the format 2915SLANG_GFX_API SlangResult SLANG_MCALL gfxGetFormatInfo ( Format format, FormatInfo * outInfo); 2916 2917/// Gets a list of available adapters for a given device type 2918SLANG_GFX_API SlangResult SLANG_MCALL 2919gfxGetAdapters ( DeviceType type, ISlangBlob ** outAdaptersBlob); 2920 2921/// Given a type returns a function that can construct it, or nullptr if there isn't one 2922SLANG_GFX_API SlangResult SLANG_MCALL 2923gfxCreateDevice ( const IDevice ::Desc * desc, IDevice ** outDevice); 2924 2925/// Reports current set of live objects in gfx. 2926/// Currently this only calls D3D's ReportLiveObjects. 2927SLANG_GFX_API SlangResult SLANG_MCALL gfxReportLiveObjects (); 2928 2929/// Sets a callback for receiving debug messages. 2930/// The layer does not hold a strong reference to the callback object. 2931/// The user is responsible for holding the callback object alive. 2932SLANG_GFX_API SlangResult SLANG_MCALL gfxSetDebugCallback ( IDebugCallback * callback); 2933 2934/// Enables debug layer. The debug layer will check all `gfx` calls and verify that uses are 2935/// valid. 2936SLANG_GFX_API void SLANG_MCALL gfxEnableDebugLayer ( bool enable); 2937 2938SLANG_GFX_API const char * SLANG_MCALL gfxGetDeviceTypeName ( DeviceType type); 2939} 2940 2941/// Gets a list of available adapters for a given device type 2942inline AdapterList gfxGetAdapters ( DeviceType type) 2943{ 2944ComPtr < ISlangBlob > blob; 2945gfxGetAdapters (type, blob. writeRef ()); 2946return AdapterList (blob); 2947} 2948 2949// Extended descs. 2950struct D3D12ExperimentalFeaturesDesc 2951{ 2952StructType structType = StructType::D3D12ExperimentalFeaturesDesc; 2953uint32_t numFeatures ; 2954const void * featureIIDs ; 2955void * configurationStructs ; 2956uint32_t * configurationStructSizes ; 2957}; 2958 2959struct D3D12DeviceExtendedDesc 2960{ 2961StructType structType = StructType::D3D12DeviceExtendedDesc; 2962const char * rootParameterShaderAttributeName = nullptr; 2963bool debugBreakOnD3D12Error = false; 2964uint32_t highestShaderModel = 0 ; 2965}; 2966 2967struct SlangSessionExtendedDesc 2968{ 2969StructType structType = StructType::SlangSessionExtendedDesc; 2970uint32_t compilerOptionEntryCount = 0 ; 2971slang :: CompilerOptionEntry * compilerOptionEntries = nullptr; 2972}; 2973 2974/// Whether to enable ray tracing validation (currently only Vulkan - D3D requires app layer to use 2975/// NVAPI) 2976struct RayTracingValidationDesc 2977{ 2978StructType structType = StructType::RayTracingValidationDesc; 2979bool enableRaytracingValidation = false; 2980}; 2981 2982} // namespace gfx