Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/libshaderc/src/common_shaders_for_test.h
1558 views
1
// Copyright 2015 The Shaderc Authors. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef COMMON_SHADERS_FOR_TESTS_H_
16
#define COMMON_SHADERS_FOR_TESTS_H_
17
18
#ifdef __cplusplus
19
extern "C" {
20
#endif
21
22
// The minimal shader, without a version directive.
23
const char kMinimalShaderWithoutVersion[] = "void main(){}";
24
// The minimal shader, with a version directive.
25
const char kMinimalShader[] =
26
"#version 140\n"
27
"void main(){}";
28
const char kMinimalHlslShader[] =
29
"float4 EntryPoint(uint index : SV_VERTEXID) : SV_POSITION\n"
30
"{ return float4(1.0, 2.0, 3.0, 4.0); }";
31
const char kMinimalShaderWithMacro[] =
32
"#version 140\n"
33
"#define E main\n"
34
"void E(){}\n";
35
36
// The minimal shader that needs valueless predefinition of 'E' to compile.
37
const char kValuelessPredefinitionShader[] =
38
"#version 140\n"
39
"#ifdef E\n"
40
"void main(){}\n"
41
"#else\n"
42
"#error\n"
43
"#endif";
44
45
// By default the compiler will emit a warning on line 2 complaining
46
// that 'float' is a deprecated attribute in version 130. Use verison 140
47
// because some versions of glslang will error out for a too-low version
48
// when generating SPIR-V.
49
const char kDeprecatedAttributeShader[] =
50
"#version 400\n"
51
"layout(location = 0) attribute float x;\n"
52
"void main() {}\n";
53
54
// By default the compiler will emit a warning as version 550 is an unknown
55
// version.
56
const char kMinimalUnknownVersionShader[] =
57
"#version 550\n"
58
"void main() {}\n";
59
60
// gl_ClipDistance doesn't exist in es profile (at least until 3.10).
61
const char kCoreVertShaderWithoutVersion[] =
62
"void main() {\n"
63
"gl_ClipDistance[0] = 5.;\n"
64
"}\n";
65
66
// Generated debug information should contain the name of the vector:
67
// debug_info_sample.
68
const char kMinimalDebugInfoShader[] =
69
"#version 140\n"
70
"void main(){\n"
71
"vec2 debug_info_sample = vec2(1.0,1.0);\n"
72
"}\n";
73
74
// Compiler should generate two errors.
75
const char kTwoErrorsShader[] =
76
"#version 150\n"
77
"#error\n"
78
"#error\n"
79
"void main(){}\n";
80
81
// Compiler should generate two warnings.
82
const char kTwoWarningsShader[] =
83
"#version 400\n"
84
"layout(location = 0) attribute float x;\n"
85
"layout(location = 1) attribute float y;\n"
86
"void main(){}\n";
87
88
// A shader that compiles under OpenGL compatibility profile rules,
89
// but not OpenGL core profile rules.
90
const char kOpenGLCompatibilityFragmentShader[] =
91
R"(#version 100
92
uniform highp sampler2D tex;
93
void main() {
94
gl_FragColor = texture2D(tex, vec2(0.0,0.0));
95
})";
96
97
// A shader that compiles under OpenGL core profile rules.
98
const char kOpenGLVertexShader[] =
99
R"(#version 330
100
void main() { int t = gl_VertexID; })";
101
102
// Empty 310 es shader. It is valid for vertex, fragment, compute shader kind.
103
const char kEmpty310ESShader[] =
104
"#version 310 es\n"
105
"void main() {}\n";
106
107
// Vertex only shader.
108
const char kVertexOnlyShader[] =
109
"#version 310 es\n"
110
"void main() {\n"
111
" gl_Position = vec4(1.);\n"
112
"}";
113
114
// TessControl only shader.
115
const char kTessControlOnlyShader[] =
116
"#version 440 core\n"
117
"layout(vertices = 3) out;\n"
118
"void main() { }";
119
120
// TessEvaluation only shader.
121
const char kTessEvaluationOnlyShader[] =
122
"#version 440 core\n"
123
"layout(triangles) in;\n"
124
"void main() { }";
125
126
// Geometry only shader.
127
const char kGeometryOnlyShader[] =
128
"#version 150 core\n"
129
"layout (triangles) in;\n"
130
"layout (line_strip, max_vertices = 4) out;\n"
131
"void main() { }";
132
133
// Vertex only shader with #pragma annotation.
134
const char kVertexOnlyShaderWithPragma[] =
135
"#version 310 es\n"
136
"#pragma shader_stage(vertex)\n"
137
"void main() {\n"
138
" gl_Position = vec4(1.);\n"
139
"}";
140
141
// Fragment only shader with #pragma annotation.
142
const char kFragmentOnlyShaderWithPragma[] =
143
"#version 310 es\n"
144
"#pragma shader_stage(fragment)\n"
145
"void main() {\n"
146
" gl_FragDepth = 10.;\n"
147
"}";
148
149
// TessControl only shader with #pragma annotation.
150
const char kTessControlOnlyShaderWithPragma[] =
151
"#version 440 core\n"
152
"#pragma shader_stage(tesscontrol)\n"
153
"layout(vertices = 3) out;\n"
154
"void main() { }";
155
156
// TessEvaluation only shader with #pragma annotation.
157
const char kTessEvaluationOnlyShaderWithPragma[] =
158
"#version 440 core\n"
159
"#pragma shader_stage(tesseval)\n"
160
"layout(triangles) in;\n"
161
"void main() { }";
162
163
// Geometry only shader with #pragma annotation.
164
const char kGeometryOnlyShaderWithPragma[] =
165
"#version 150 core\n"
166
"#pragma shader_stage(geometry)\n"
167
"layout (triangles) in;\n"
168
"layout (line_strip, max_vertices = 4) out;\n"
169
"void main() { }";
170
171
// Compute only shader with #pragma annotation.
172
const char kComputeOnlyShaderWithPragma[] =
173
"#version 310 es\n"
174
"#pragma shader_stage(compute)\n"
175
"void main() {\n"
176
" uvec3 temp = gl_WorkGroupID;\n"
177
"}";
178
179
// NV mesh shader without #pragma.
180
const char kNVMeshShader[] =
181
"#version 450\n"
182
"#extension GL_NV_mesh_shader : enable\n"
183
"layout(local_size_x=8) in;\n"
184
"layout(max_vertices=5) out;\n"
185
"layout(max_primitives=10) out;\n"
186
"layout(triangles) out;\n"
187
"void main() {\n"
188
" gl_MeshVerticesNV[gl_LocalInvocationID.x].gl_Position = vec4(0.0);\n"
189
"}\n";
190
191
// NV mesh shader with #pragma annotation.
192
const char kNVMeshShaderWithPragma[] =
193
"#version 450\n"
194
"#extension GL_NV_mesh_shader : enable\n"
195
"#pragma shader_stage(mesh)\n"
196
"layout(local_size_x=8) in;\n"
197
"layout(max_vertices=5) out;\n"
198
"layout(max_primitives=10) out;\n"
199
"layout(triangles) out;\n"
200
"void main() {\n"
201
" gl_MeshVerticesNV[gl_LocalInvocationID.x].gl_Position = vec4(0.0);\n"
202
"}\n";
203
204
// NV task shader without #pragma annotation.
205
const char kNVTaskShader[] =
206
"#version 450\n"
207
"#extension GL_NV_mesh_shader : enable\n"
208
"layout(local_size_x=8) in;\n"
209
"void main() {\n"
210
" gl_TaskCountNV = 2;\n"
211
"}\n";
212
213
// NV task shader with #pragma annotation.
214
const char kNVTaskShaderWithPragma[] =
215
"#version 450\n"
216
"#extension GL_NV_mesh_shader : enable\n"
217
"#pragma shader_stage(task)\n"
218
"layout(local_size_x=8) in;\n"
219
"void main() {\n"
220
" gl_TaskCountNV = 2;\n"
221
"}\n";
222
223
// Vertex only shader with invalid #pragma annotation.
224
const char kVertexOnlyShaderWithInvalidPragma[] =
225
"#version 310 es\n"
226
"#pragma shader_stage(fragment)\n"
227
"void main() {\n"
228
" gl_Position = vec4(1.);\n"
229
"}";
230
231
// Parts of a valid disassembly of a minimal shader. We only check certain
232
// parts since Glslang code generation changes in incidental ways.
233
const char* kMinimalShaderDisassemblySubstrings[] = {
234
"; SPIR-V\n"
235
"; Version: 1.0\n"
236
"; Generator: Google Shaderc over Glslang; 11\n"
237
"; Bound:",
238
239
" OpCapability Shader\n",
240
" %1 = OpExtInstImport \"GLSL.std.450\"\n",
241
" OpMemoryModel Logical GLSL450\n",
242
" OpReturn\n",
243
" OpFunctionEnd\n"};
244
245
const char* kMinimalShaderDebugInfoDisassemblySubstrings[] = {
246
"; SPIR-V\n"
247
"; Version: 1.0\n"
248
"; Generator: Google Shaderc over Glslang; 11\n"
249
"; Bound:",
250
251
" OpCapability Shader\n",
252
" %2 = OpExtInstImport \"GLSL.std.450\"\n",
253
" OpMemoryModel Logical GLSL450\n",
254
" OpReturn\n",
255
" OpFunctionEnd\n"};
256
257
const char kMinimalShaderAssembly[] = R"(
258
; SPIR-V
259
; Version: 1.0
260
; Generator: Google Shaderc over Glslang; 11
261
; Bound: 6
262
; Schema: 0
263
264
OpCapability Shader
265
%1 = OpExtInstImport "GLSL.std.450"
266
OpMemoryModel Logical GLSL450
267
OpEntryPoint Vertex %4 "main"
268
OpSource ESSL 310
269
OpName %4 "main"
270
%2 = OpTypeVoid
271
%3 = OpTypeFunction %2
272
%4 = OpFunction %2 None %3
273
%5 = OpLabel
274
OpReturn
275
OpFunctionEnd)";
276
277
const char kShaderWithUniformsWithoutBindings[] =
278
R"(#version 450
279
#extension GL_ARB_sparse_texture2 : enable
280
uniform texture2D my_tex;
281
uniform sampler my_sam;
282
layout(rgba32f) uniform image2D my_img;
283
layout(rgba32f) uniform imageBuffer my_imbuf;
284
uniform block { float x; float y; } my_ubo;
285
void main() {
286
texture(sampler2D(my_tex,my_sam),vec2(1.0));
287
vec4 t;
288
sparseImageLoadARB(my_img,ivec2(0),t);
289
imageLoad(my_imbuf,42);
290
float x = my_ubo.x;
291
})";
292
293
// A GLSL vertex shader with a weirdly packed block.
294
const char kGlslShaderWeirdPacking[] =
295
R"(#version 450
296
layout(set=0, binding=0)
297
buffer B { float x; vec3 foo; } my_ssbo;
298
void main() { my_ssbo.x = 1.0; })";
299
300
// A HLSL fragment shader with a weirdly packed block.
301
const char kHlslFragShaderWithRegisters[] =
302
R"(Buffer<float> t4 : register(t4);
303
Buffer<float> t5 : register(t5);
304
float4 main() : SV_Target0 {
305
return float4(t4.Load(0) + t5.Load(1));
306
})";
307
308
// A GLSL compute shader using a regular barrier.
309
const char kGlslShaderComputeBarrier[] =
310
R"(#version 450
311
void main() { barrier(); })";
312
313
// A GLSL compute shader using the Subgroups feature.
314
const char kGlslShaderComputeSubgroupBarrier[] =
315
R"(#version 450
316
#extension GL_KHR_shader_subgroup_basic : enable
317
void main() { subgroupBarrier(); })";
318
319
// A GLSL task shader using a regular barrier.
320
const char kGlslShaderTaskBarrier[] =
321
R"(#version 450
322
#extension GL_NV_mesh_shader : enable
323
layout(local_size_x = 32) in;
324
void main() { barrier(); })";
325
326
// A GLSL task shader using the Subgroups feature.
327
const char kGlslShaderTaskSubgroupBarrier[] =
328
R"(#version 450
329
#extension GL_NV_mesh_shader : enable
330
#extension GL_KHR_shader_subgroup_basic : enable
331
layout(local_size_x = 32) in;
332
void main() { subgroupBarrier(); })";
333
334
// A GLSL mesh shader using a regular barrier.
335
const char kGlslShaderMeshBarrier[] =
336
R"(#version 450
337
#extension GL_NV_mesh_shader : enable
338
layout(local_size_x = 32) in;
339
layout(max_vertices=81) out;
340
layout(max_primitives=32) out;
341
layout(triangles) out;
342
void main() { barrier(); })";
343
344
// A GLSL mesh shader using the Subgroups feature.
345
const char kGlslShaderMeshSubgroupBarrier[] =
346
R"(#version 450
347
#extension GL_NV_mesh_shader : enable
348
#extension GL_KHR_shader_subgroup_basic : enable
349
layout(local_size_x = 32) in;
350
layout(max_vertices=81) out;
351
layout(max_primitives=32) out;
352
layout(triangles) out;
353
void main() { subgroupBarrier(); })";
354
355
const char kGlslMultipleFnShader[] =
356
R"(#version 450
357
layout(location=0) flat in int inVal;
358
layout(location=0) out int outVal;
359
int foo(int a) { return a; }
360
void main() { outVal = foo(inVal); })";
361
362
const char kHlslShaderWithCounterBuffer[] =
363
R"(RWStructuredBuffer<uint> Ainc;
364
float4 main() : SV_Target0 {
365
return float4(Ainc.IncrementCounter(), 0, 0, 0);
366
})";
367
368
const char kHlslWaveActiveSumeComputeShader[] =
369
R"(struct S { uint val; uint result; };
370
371
[[vk::binding(0,0)]]
372
RWStructuredBuffer<S> MyBuffer;
373
374
[numthreads(32, 1, 1)]
375
void main(uint3 id : SV_DispatchThreadID) {
376
MyBuffer[id.x].result = WaveActiveSum(MyBuffer[id.x].val);
377
})";
378
379
const char kHlslMemLayoutResourceSelect[] =
380
R"(cbuffer Foo { float a; float3 b; }
381
382
[[vk::binding(0,0)]]
383
Texture2D Tex;
384
[[vk::binding(1,0)]]
385
SamplerState Sampler1;
386
[[vk::binding(2,0)]]
387
SamplerState Sampler2;
388
389
static const int val = 42;
390
391
float4 main() : SV_Target {
392
SamplerState samp;
393
394
if (val > 5)
395
samp = Sampler1;
396
else
397
samp = Sampler2;
398
399
return Tex.Sample(samp, float2(0.5, 0.5)) + float4(a, b);
400
})";
401
402
const char kGlslShaderWithClamp[] =
403
R"(#version 450
404
layout(location=0) in vec4 i;
405
layout(location=0) out vec4 o;
406
void main() { o = clamp(i, vec4(0.5), vec4(1.0)); }
407
)";
408
409
#ifdef __cplusplus
410
}
411
#endif // __cplusplus
412
413
#endif // COMMON_SHADERS_FOR_TESTS_H_
414
415