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
|
// render.h
#pragma once
#include "options.h"
#include "window.h"
#include "shader-input-layout.h"
namespace renderer_test {
typedef struct Buffer Buffer;
typedef struct InputLayout InputLayout;
typedef struct ShaderProgram ShaderProgram;
typedef struct BindingState BindingState;
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:
virtual void initialize(void* inWindowHandle) = 0;
virtual void setClearColor(float const* color) = 0;
virtual void clearFrame() = 0;
virtual void presentFrame() = 0;
virtual void captureScreenShot(char const* outputPath) = 0;
virtual void serializeOutput(BindingState * state, char const* outputPath) = 0;
virtual Buffer* createBuffer(BufferDesc const& desc) = 0;
virtual InputLayout* createInputLayout(InputElementDesc const* 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, UInt const* strides, UInt const* offsets) = 0;
inline void setVertexBuffer(UInt slot, Buffer* buffer, UInt stride, UInt offset = 0)
{
setVertexBuffers(slot, 1, &buffer, &stride, &offset);
}
virtual void setShaderProgram(ShaderProgram* program) = 0;
virtual void setConstantBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets) = 0;
inline void setConstantBuffer(UInt slot, Buffer* buffer, UInt offset = 0)
{
setConstantBuffers(slot, 1, &buffer, &offset);
}
virtual void draw(UInt vertexCount, UInt startVertex = 0) = 0;
virtual void dispatchCompute(int x, int y, int z) = 0;
};
} // renderer_test
|