|
@@ -88,6 +88,86 @@ const char* ShaderDataTypeStr(DKShaderDataType t)
|
88
|
88
|
return "Error";
|
89
|
89
|
}
|
90
|
90
|
|
|
91
|
+DKVertexDescriptor VertexDescriptorForVertexAttributes(const DKArray<DKVertexAttribute>& attrs)
|
|
92
|
+{
|
|
93
|
+ uint32_t vertexSize = 0;
|
|
94
|
+ DKVertexDescriptor descriptor = {};
|
|
95
|
+
|
|
96
|
+ for (uint32_t i = 0; i < attrs.Count(); ++i)
|
|
97
|
+ {
|
|
98
|
+ if (const DKVertexAttribute& attr = attrs.Value(i); attr.active)
|
|
99
|
+ {
|
|
100
|
+ DKVertexAttributeDescriptor desc = {};
|
|
101
|
+
|
|
102
|
+ switch (attr.type)
|
|
103
|
+ {
|
|
104
|
+ case DKShaderDataType::Float:
|
|
105
|
+ case DKShaderDataType::Half:
|
|
106
|
+ case DKShaderDataType::Int:
|
|
107
|
+ case DKShaderDataType::UInt:
|
|
108
|
+ case DKShaderDataType::Short:
|
|
109
|
+ case DKShaderDataType::UShort:
|
|
110
|
+ case DKShaderDataType::Char:
|
|
111
|
+ case DKShaderDataType::UChar:
|
|
112
|
+ case DKShaderDataType::Bool:
|
|
113
|
+ desc.format = DKVertexFormat::Float;
|
|
114
|
+ desc.offset = vertexSize;
|
|
115
|
+ vertexSize += 4;
|
|
116
|
+ break;
|
|
117
|
+ case DKShaderDataType::Float2:
|
|
118
|
+ case DKShaderDataType::Half2:
|
|
119
|
+ case DKShaderDataType::Int2:
|
|
120
|
+ case DKShaderDataType::UInt2:
|
|
121
|
+ case DKShaderDataType::Short2:
|
|
122
|
+ case DKShaderDataType::UShort2:
|
|
123
|
+ case DKShaderDataType::Char2:
|
|
124
|
+ case DKShaderDataType::UChar2:
|
|
125
|
+ case DKShaderDataType::Bool2:
|
|
126
|
+ desc.format = DKVertexFormat::Float2;
|
|
127
|
+ desc.offset = vertexSize;
|
|
128
|
+ vertexSize += 8;
|
|
129
|
+ break;
|
|
130
|
+ case DKShaderDataType::Float3:
|
|
131
|
+ case DKShaderDataType::Half3:
|
|
132
|
+ case DKShaderDataType::Int3:
|
|
133
|
+ case DKShaderDataType::UInt3:
|
|
134
|
+ case DKShaderDataType::Short3:
|
|
135
|
+ case DKShaderDataType::UShort3:
|
|
136
|
+ case DKShaderDataType::Char3:
|
|
137
|
+ case DKShaderDataType::UChar3:
|
|
138
|
+ case DKShaderDataType::Bool3:
|
|
139
|
+ desc.format = DKVertexFormat::Float3;
|
|
140
|
+ desc.offset = vertexSize;
|
|
141
|
+ vertexSize += 12;
|
|
142
|
+ break;
|
|
143
|
+ case DKShaderDataType::Float4:
|
|
144
|
+ case DKShaderDataType::Half4:
|
|
145
|
+ case DKShaderDataType::Int4:
|
|
146
|
+ case DKShaderDataType::UInt4:
|
|
147
|
+ case DKShaderDataType::Short4:
|
|
148
|
+ case DKShaderDataType::UShort4:
|
|
149
|
+ case DKShaderDataType::Char4:
|
|
150
|
+ case DKShaderDataType::UChar4:
|
|
151
|
+ case DKShaderDataType::Bool4:
|
|
152
|
+ desc.format = DKVertexFormat::Float4;
|
|
153
|
+ desc.offset = vertexSize;
|
|
154
|
+ vertexSize += 16;
|
|
155
|
+ break;
|
|
156
|
+ default:
|
|
157
|
+ DKASSERT_DESC(0, "Unsupported type!");
|
|
158
|
+ break;
|
|
159
|
+ }
|
|
160
|
+ desc.location = attr.location;
|
|
161
|
+
|
|
162
|
+ descriptor.attributes.Add(desc);
|
|
163
|
+ }
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ descriptor.layouts = { { DKVertexStepRate::Vertex, vertexSize}, };
|
|
167
|
+
|
|
168
|
+ return descriptor;
|
|
169
|
+};
|
|
170
|
+
|
91
|
171
|
void PrintShaderResource(const DKShaderResource& res)
|
92
|
172
|
{
|
93
|
173
|
struct MemberPrinter
|
|
@@ -206,22 +286,6 @@ public:
|
206
|
286
|
DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/texturearray/instancing.vert.spv");
|
207
|
287
|
DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/texturearray/instancing.frag.spv");
|
208
|
288
|
|
209
|
|
- struct Vertex
|
210
|
|
- {
|
211
|
|
- DKVector3 position;
|
212
|
|
- DKVector2 uv;
|
213
|
|
- DKVector3 normal;
|
214
|
|
- };
|
215
|
|
- DKVertexDescriptor vertexDescriptor;
|
216
|
|
- vertexDescriptor.attributes = {
|
217
|
|
- { DKVertexFormat::Float3, 0, 0, 0 },
|
218
|
|
- { DKVertexFormat::Float2, sizeof(DKVector2), 0, 1 },
|
219
|
|
- { DKVertexFormat::Float3, sizeof(DKVector3), 0, 2 },
|
220
|
|
- };
|
221
|
|
- vertexDescriptor.layouts = {
|
222
|
|
- { DKVertexStepRate::Vertex, sizeof(Vertex), 0 },
|
223
|
|
- };
|
224
|
|
-
|
225
|
289
|
DKShader vertShader(vertData, DKShader::Vertex);
|
226
|
290
|
DKShader fragShader(fragData, DKShader::Fragment);
|
227
|
291
|
|
|
@@ -241,6 +305,10 @@ public:
|
241
|
305
|
DKLog(" --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
|
242
|
306
|
}
|
243
|
307
|
|
|
308
|
+ // setup dummy vertex-descriptor
|
|
309
|
+ DKVertexDescriptor vertexDescriptor = VertexDescriptorForVertexAttributes(vertShaderFunction->VertexAttributes());
|
|
310
|
+
|
|
311
|
+ // setup rendering pipeline state object (PSO)
|
244
|
312
|
DKRenderPipelineDescriptor pipelineDescriptor;
|
245
|
313
|
pipelineDescriptor.vertexFunction = vertShaderFunction;
|
246
|
314
|
pipelineDescriptor.fragmentFunction = fragShaderFunction;
|