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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
// render.h
#pragma once
#include "options.h"
#include "window.h"
#include "shader-input-layout.h"
#include "../../source/core/slang-result.h"
#include "../../source/core/smart-pointer.h"
namespace renderer_test {
// Declare opaque type
class Buffer: public Slang::RefObject
{
public:
};
class InputLayout: public Slang::RefObject
{
public:
};
class ShaderProgram: public Slang::RefObject
{
public:
};
class BindingState: public Slang::RefObject
{
public:
};
struct ShaderCompileRequest
{
struct SourceInfo
{
char const* path;
// The data may either be source text (in which
// case it can be assumed to be nul-terminated with
// `dataEnd` pointing at the terminator), or
// raw binary data (in which case `dataEnd` points
// at the end of the buffer).
char const* dataBegin;
char const* dataEnd;
};
struct EntryPoint
{
char const* name = nullptr;
char const* profile = nullptr;
SourceInfo source;
};
SourceInfo source;
EntryPoint vertexShader;
EntryPoint fragmentShader;
EntryPoint computeShader;
Slang::List<Slang::String> entryPointTypeArguments;
};
class ShaderCompiler
{
public:
virtual ShaderProgram* compileProgram(ShaderCompileRequest const& request) = 0;
};
enum class Format
{
Unknown,
RGB_Float32,
RG_Float32,
};
enum class BufferFlavor
{
Constant,
Vertex
};
struct BufferDesc
{
UInt size = 0;
BufferFlavor flavor = BufferFlavor::Constant;
void const* initData = nullptr;
};
struct InputElementDesc
{
char const* semanticName;
UInt semanticIndex;
Format format;
UInt offset;
};
enum class MapFlavor
{
HostRead,
HostWrite,
WriteDiscard,
};
enum class PrimitiveTopology
{
TriangleList,
};
class Renderer: public Slang::RefObject
{
public:
virtual SlangResult initialize(void* inWindowHandle) = 0;
virtual void setClearColor(const float color[4]) = 0;
virtual void clearFrame() = 0;
virtual void presentFrame() = 0;
virtual SlangResult captureScreenShot(const char* outputPath) = 0;
virtual void serializeOutput(BindingState* state, const char* outputPath) = 0;
virtual Buffer* createBuffer(const BufferDesc& desc) = 0;
virtual InputLayout* createInputLayout(const InputElementDesc* inputElements, UInt inputElementCount) = 0;
virtual BindingState* createBindingState(const ShaderInputLayout& shaderInput) = 0;
virtual ShaderCompiler* getShaderCompiler() = 0;
virtual void* map(Buffer* buffer, MapFlavor flavor) = 0;
virtual void unmap(Buffer* buffer) = 0;
virtual void setInputLayout(InputLayout* inputLayout) = 0;
virtual void setPrimitiveTopology(PrimitiveTopology topology) = 0;
virtual void setBindingState(BindingState* state) = 0;
virtual void setVertexBuffers(UInt startSlot, UInt slotCount, Buffer*const* buffers, const UInt* strides, const UInt* offsets) = 0;
inline void setVertexBuffer(UInt slot, Buffer* buffer, UInt stride, UInt offset = 0);
virtual void setShaderProgram(ShaderProgram* program) = 0;
virtual void setConstantBuffers(UInt startSlot, UInt slotCount, Buffer*const* buffers, const UInt* offsets) = 0;
inline void setConstantBuffer(UInt slot, Buffer* buffer, UInt offset = 0);
virtual void draw(UInt vertexCount, UInt startVertex = 0) = 0;
virtual void dispatchCompute(int x, int y, int z) = 0;
/// Commit any buffered state changes or draw calls.
/// presentFrame will commitAll implicitly before doing a present
virtual void submitGpuWork() = 0;
/// Blocks until Gpu work is complete
virtual void waitForGpu() = 0;
};
// ----------------------------------------------------------------------------------------
inline void Renderer::setVertexBuffer(UInt slot, Buffer* buffer, UInt stride, UInt offset)
{
setVertexBuffers(slot, 1, &buffer, &stride, &offset);
}
// ----------------------------------------------------------------------------------------
inline void Renderer::setConstantBuffer(UInt slot, Buffer* buffer, UInt offset)
{
setConstantBuffers(slot, 1, &buffer, &offset);
}
} // renderer_test
|