yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
2.8 KiB106 linesraw
1// cpu-shader-object-layout.h
2#pragma once
3#include "cpu-base.h"
4
5namespace gfx
6{
7using namespace Slang;
8
9namespace cpu
10{
11
12struct BindingRangeInfo
13{
14    slang::BindingType bindingType;
15    Index count;
16    Index baseIndex; // Flat index for sub-objects
17    Index subObjectIndex;
18
19    // TODO: The `uniformOffset` field should be removed,
20    // since it cannot be supported by the Slang reflection
21    // API once we fix some design issues.
22    //
23    // It is only being used today for pre-allocation of sub-objects
24    // for constant buffers and parameter blocks (which should be
25    // deprecated/removed anyway).
26    //
27    // Note: We would need to bring this field back, plus
28    // a lot of other complexity, if we ever want to support
29    // setting of resources/buffers directly by a binding
30    // range index and array index.
31    //
32    Index uniformOffset; // Uniform offset for a resource typed field.
33
34    bool isSpecializable;
35};
36
37struct SubObjectRangeInfo
38{
39    RefPtr<ShaderObjectLayoutImpl> layout;
40    Index bindingRangeIndex;
41};
42
43class ShaderObjectLayoutImpl : public ShaderObjectLayoutBase
44{
45public:
46    // TODO: Once memory lifetime stuff is handled, there is
47    // no specific need to even track binding or sub-object
48    // ranges for CPU.
49
50    size_t m_size = 0;
51    List<SubObjectRangeInfo> subObjectRanges;
52    List<BindingRangeInfo> m_bindingRanges;
53
54    Index m_subObjectCount = 0;
55    Index m_resourceCount = 0;
56
57    ShaderObjectLayoutImpl(
58        RendererBase* renderer,
59        slang::ISession* session,
60        slang::TypeLayoutReflection* layout);
61
62    size_t getSize();
63    Index getResourceCount() const;
64    Index getSubObjectCount() const;
65    List<SubObjectRangeInfo>& getSubObjectRanges();
66    BindingRangeInfo getBindingRange(Index index);
67    Index getBindingRangeCount() const;
68};
69
70class EntryPointLayoutImpl : public ShaderObjectLayoutImpl
71{
72private:
73    slang::EntryPointLayout* m_entryPointLayout = nullptr;
74
75public:
76    EntryPointLayoutImpl(
77        RendererBase* renderer,
78        slang::ISession* session,
79        slang::EntryPointLayout* entryPointLayout)
80        : ShaderObjectLayoutImpl(renderer, session, entryPointLayout->getTypeLayout())
81        , m_entryPointLayout(entryPointLayout)
82    {
83    }
84
85    const char* getEntryPointName();
86};
87
88class RootShaderObjectLayoutImpl : public ShaderObjectLayoutImpl
89{
90public:
91    slang::ProgramLayout* m_programLayout = nullptr;
92    List<RefPtr<EntryPointLayoutImpl>> m_entryPointLayouts;
93
94    RootShaderObjectLayoutImpl(
95        RendererBase* renderer,
96        slang::ISession* session,
97        slang::ProgramLayout* programLayout);
98
99    int getKernelIndex(UnownedStringSlice kernelName);
100    void getKernelThreadGroupSize(int kernelIndex, UInt* threadGroupSizes);
101
102    EntryPointLayoutImpl* getEntryPoint(Index index);
103};
104
105} // namespace cpu
106} // namespace gfx