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