yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
2.1 KiB79 linesraw
1// cuda-shader-object-layout.h
2#pragma once
3#include "cuda-base.h"
4
5namespace gfx
6{
7#ifdef GFX_ENABLE_CUDA
8using namespace Slang;
9
10namespace cuda
11{
12
13struct BindingRangeInfo
14{
15    slang::BindingType bindingType;
16    Index count;
17    Index baseIndex; // Flat index for sub-objects
18    Index subObjectIndex;
19
20    // TODO: The `uniformOffset` field should be removed,
21    // since it cannot be supported by the Slang reflection
22    // API once we fix some design issues.
23    //
24    // It is only being used today for pre-allocation of sub-objects
25    // for constant buffers and parameter blocks (which should be
26    // deprecated/removed anyway).
27    //
28    // Note: We would need to bring this field back, plus
29    // a lot of other complexity, if we ever want to support
30    // setting of resources/buffers directly by a binding
31    // range index and array index.
32    //
33    Index uniformOffset; // Uniform offset for a resource typed field.
34
35    bool isSpecializable;
36};
37
38struct SubObjectRangeInfo
39{
40    RefPtr<ShaderObjectLayoutImpl> layout;
41    Index bindingRangeIndex;
42};
43
44class ShaderObjectLayoutImpl : public ShaderObjectLayoutBase
45{
46public:
47    List<SubObjectRangeInfo> subObjectRanges;
48    List<BindingRangeInfo> m_bindingRanges;
49
50    Index m_subObjectCount = 0;
51    Index m_resourceCount = 0;
52
53    ShaderObjectLayoutImpl(
54        RendererBase* renderer,
55        slang::ISession* session,
56        slang::TypeLayoutReflection* layout);
57
58    Index getResourceCount() const;
59    Index getSubObjectCount() const;
60    List<SubObjectRangeInfo>& getSubObjectRanges();
61    BindingRangeInfo getBindingRange(Index index);
62    Index getBindingRangeCount() const;
63};
64
65class RootShaderObjectLayoutImpl : public ShaderObjectLayoutImpl
66{
67public:
68    slang::ProgramLayout* programLayout = nullptr;
69    List<RefPtr<ShaderObjectLayoutImpl>> entryPointLayouts;
70    RootShaderObjectLayoutImpl(RendererBase* renderer, slang::ProgramLayout* inProgramLayout);
71
72    int getKernelIndex(UnownedStringSlice kernelName);
73
74    void getKernelThreadGroupSize(int kernelIndex, UInt* threadGroupSizes);
75};
76
77} // namespace cuda
78#endif
79} // namespace gfx