CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/GPUDriverTestScreen.cpp
Views: 1401
1
#include "GPUDriverTestScreen.h"
2
#include "Common/Data/Text/I18n.h"
3
#include "Common/UI/UI.h"
4
#include "Common/UI/View.h"
5
#include "Common/GPU/Shader.h"
6
#include "Common/GPU/ShaderWriter.h"
7
8
const uint32_t textColorOK = 0xFF30FF30;
9
const uint32_t textColorBAD = 0xFF3030FF;
10
const uint32_t bgColorOK = 0xFF106010;
11
const uint32_t bgColorBAD = 0xFF101060;
12
13
// TODO: One day, port these to use ShaderWriter.
14
15
static const std::vector<Draw::ShaderSource> fsDiscard = {
16
{ShaderLanguage::GLSL_1xx,
17
R"(
18
#ifdef GL_ES
19
precision lowp float;
20
#endif
21
#if __VERSION__ >= 130
22
#define varying in
23
#define gl_FragColor fragColor0
24
out vec4 fragColor0;
25
#endif
26
varying vec4 oColor0;
27
varying vec2 oTexCoord0;
28
uniform sampler2D Sampler0;
29
void main() {
30
#if __VERSION__ >= 130
31
vec4 color = texture(Sampler0, oTexCoord0) * oColor0;
32
#else
33
vec4 color = texture2D(Sampler0, oTexCoord0) * oColor0;
34
#endif
35
if (color.a <= 0.0)
36
discard;
37
gl_FragColor = color;
38
})"
39
},
40
{ShaderLanguage::GLSL_VULKAN,
41
R"(#version 450
42
#extension GL_ARB_separate_shader_objects : enable
43
#extension GL_ARB_shading_language_420pack : enable
44
layout(location = 0) in vec4 oColor0;
45
layout(location = 1) in vec2 oTexCoord0;
46
layout(location = 0) out vec4 fragColor0;
47
layout(set = 0, binding = 1) uniform sampler2D Sampler0;
48
void main() {
49
vec4 color = texture(Sampler0, oTexCoord0) * oColor0;
50
if (color.a <= 0.0)
51
discard;
52
fragColor0 = color;
53
})"
54
},
55
};
56
57
static const std::vector<Draw::ShaderSource> fsAdrenoLogicTest = {
58
{ShaderLanguage::GLSL_1xx,
59
R"(
60
#ifdef GL_ES
61
precision lowp float;
62
#endif
63
#if __VERSION__ >= 130
64
#define varying in
65
#define gl_FragColor fragColor0
66
out vec4 fragColor0;
67
#endif
68
varying vec4 oColor0;
69
varying vec2 oTexCoord0;
70
uniform sampler2D Sampler0;
71
void main() {
72
#if __VERSION__ >= 130
73
vec4 color = (texture(Sampler0, oTexCoord0) * oColor0).aaaa;
74
#else
75
vec4 color = (texture2D(Sampler0, oTexCoord0) * oColor0).aaaa;
76
#endif
77
color *= 2.0;
78
if (color.r < 0.002 && color.g < 0.002 && color.b < 0.002) discard;
79
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
80
})"
81
},
82
{ShaderLanguage::GLSL_VULKAN,
83
R"(#version 450
84
#extension GL_ARB_separate_shader_objects : enable
85
#extension GL_ARB_shading_language_420pack : enable
86
layout(location = 0) in vec4 oColor0;
87
layout(location = 1) in highp vec2 oTexCoord0;
88
layout(location = 0) out vec4 fragColor0;
89
layout(set = 0, binding = 1) uniform sampler2D Sampler0;
90
void main() {
91
vec4 v = texture(Sampler0, oTexCoord0).aaaa * oColor0;
92
if (v.r < 0.2 && v.g < 0.2 && v.b < 0.2) discard;
93
fragColor0 = vec4(0.0, 1.0, 0.0, 1.0);
94
})"
95
},
96
};
97
98
static const std::vector<Draw::ShaderSource> vsAdrenoLogicTest = {
99
{ GLSL_1xx,
100
"#if __VERSION__ >= 130\n"
101
"#define attribute in\n"
102
"#define varying out\n"
103
"#endif\n"
104
"attribute vec3 Position;\n"
105
"attribute vec4 Color0;\n"
106
"attribute vec2 TexCoord0;\n"
107
"varying vec4 oColor0;\n"
108
"varying vec2 oTexCoord0;\n"
109
"uniform mat4 WorldViewProj;\n"
110
"void main() {\n"
111
" gl_Position = WorldViewProj * vec4(Position, 1.0);\n"
112
" oColor0 = Color0;\n"
113
" oTexCoord0 = TexCoord0;\n"
114
"}\n"
115
},
116
{ ShaderLanguage::GLSL_VULKAN,
117
"#version 450\n"
118
"#extension GL_ARB_separate_shader_objects : enable\n"
119
"#extension GL_ARB_shading_language_420pack : enable\n"
120
"layout (std140, set = 0, binding = 0) uniform bufferVals {\n"
121
" mat4 WorldViewProj;\n"
122
"} myBufferVals;\n"
123
"layout (location = 0) in vec4 pos;\n"
124
"layout (location = 1) in vec4 inColor;\n"
125
"layout (location = 3) in vec2 inTexCoord;\n"
126
"layout (location = 0) out vec4 outColor;\n"
127
"layout (location = 1) out highp vec2 outTexCoord;\n"
128
"out gl_PerVertex { vec4 gl_Position; };\n"
129
"void main() {\n"
130
" outColor = inColor;\n"
131
" outTexCoord = inTexCoord;\n"
132
" gl_Position = myBufferVals.WorldViewProj * pos;\n"
133
"}\n"
134
}
135
};
136
137
static const std::vector<Draw::ShaderSource> fsFlat = {
138
{ShaderLanguage::GLSL_3xx,
139
"#ifdef GL_ES\n"
140
"precision lowp float;\n"
141
"precision highp int;\n"
142
"#endif\n"
143
"uniform sampler2D Sampler0;\n"
144
"flat in lowp vec4 oColor0;\n"
145
"in mediump vec3 oTexCoord0;\n"
146
"out vec4 fragColor0;\n"
147
"void main() {\n"
148
" vec4 t = texture(Sampler0, oTexCoord0.xy);\n"
149
" vec4 p = oColor0;\n"
150
" vec4 v = p * t;\n"
151
" fragColor0 = v;\n"
152
"}\n"
153
},
154
{ShaderLanguage::GLSL_1xx,
155
"#ifdef GL_ES\n"
156
"precision lowp float;\n"
157
"#endif\n"
158
"#if __VERSION__ >= 130\n"
159
"#define varying in\n"
160
"#define texture2D texture\n"
161
"#define gl_FragColor fragColor0\n"
162
"out vec4 fragColor0;\n"
163
"#endif\n"
164
"varying vec4 oColor0;\n"
165
"varying vec2 oTexCoord0;\n"
166
"uniform sampler2D Sampler0;\n"
167
"void main() { gl_FragColor = texture2D(Sampler0, oTexCoord0) * oColor0; }\n"
168
},
169
{ShaderLanguage::GLSL_VULKAN,
170
"#version 450\n"
171
"#extension GL_ARB_separate_shader_objects : enable\n"
172
"#extension GL_ARB_shading_language_420pack : enable\n"
173
"layout(location = 0) flat in lowp vec4 oColor0;\n"
174
"layout(location = 1) in highp vec2 oTexCoord0;\n"
175
"layout(location = 0) out vec4 fragColor0;\n"
176
"layout(set = 0, binding = 1) uniform sampler2D Sampler0;\n"
177
"void main() { fragColor0 = texture(Sampler0, oTexCoord0) * oColor0; }\n"
178
}
179
};
180
181
static const std::vector<Draw::ShaderSource> vsFlat = {
182
{ GLSL_3xx,
183
"in vec3 Position;\n"
184
"in vec2 TexCoord0;\n"
185
"in lowp vec4 Color0;\n"
186
"uniform mat4 WorldViewProj;\n"
187
"flat out lowp vec4 oColor0;\n"
188
"out mediump vec3 oTexCoord0;\n"
189
"void main() {\n"
190
" oTexCoord0 = vec3(TexCoord0, 1.0);\n"
191
" oColor0 = Color0;\n"
192
" vec4 outPos = WorldViewProj * vec4(Position, 1.0);\n"
193
" gl_Position = outPos;\n"
194
"}\n"
195
},
196
{ GLSL_1xx, // Doesn't actually repro the problem since flat support isn't guaranteed
197
"#if __VERSION__ >= 130\n"
198
"#define attribute in\n"
199
"#define varying out\n"
200
"#endif\n"
201
"attribute vec3 Position;\n"
202
"attribute vec4 Color0;\n"
203
"attribute vec2 TexCoord0;\n"
204
"varying vec4 oColor0;\n"
205
"varying vec2 oTexCoord0;\n"
206
"uniform mat4 WorldViewProj;\n"
207
"void main() {\n"
208
" gl_Position = WorldViewProj * vec4(Position, 1.0);\n"
209
" oColor0 = Color0;\n"
210
" oTexCoord0 = TexCoord0;\n"
211
"}\n"
212
},
213
{ ShaderLanguage::GLSL_VULKAN,
214
"#version 450\n"
215
"#extension GL_ARB_separate_shader_objects : enable\n"
216
"#extension GL_ARB_shading_language_420pack : enable\n"
217
"layout (std140, set = 0, binding = 0) uniform bufferVals {\n"
218
" mat4 WorldViewProj;\n"
219
"} myBufferVals;\n"
220
"layout (location = 0) in vec4 pos;\n"
221
"layout (location = 1) in vec4 inColor;\n"
222
"layout (location = 3) in vec2 inTexCoord;\n"
223
"layout (location = 0) flat out lowp vec4 outColor;\n"
224
"layout (location = 1) out highp vec2 outTexCoord;\n"
225
"out gl_PerVertex { vec4 gl_Position; };\n"
226
"void main() {\n"
227
" outColor = inColor;\n"
228
" outTexCoord = inTexCoord;\n"
229
" gl_Position = myBufferVals.WorldViewProj * pos;\n"
230
"}\n"
231
}
232
};
233
234
static_assert(Draw::SEM_TEXCOORD0 == 3, "Semantic shader hardcoded in glsl above.");
235
236
GPUDriverTestScreen::GPUDriverTestScreen() {
237
using namespace Draw;
238
}
239
240
GPUDriverTestScreen::~GPUDriverTestScreen() {
241
if (discardWriteDepthStencil_)
242
discardWriteDepthStencil_->Release();
243
if (discardWriteDepth_)
244
discardWriteDepth_->Release();
245
if (discardWriteStencil_)
246
discardWriteStencil_->Release();
247
248
if (drawTestStencilEqualDepthAlways_)
249
drawTestStencilEqualDepthAlways_->Release();
250
if (drawTestStencilNotEqualDepthAlways_)
251
drawTestStencilNotEqualDepthAlways_->Release();
252
if (drawTestStencilEqual_)
253
drawTestStencilEqual_->Release();
254
if (drawTestStencilNotEqual_)
255
drawTestStencilNotEqual_->Release();
256
if (drawTestStencilAlwaysDepthLessEqual_)
257
drawTestStencilAlwaysDepthLessEqual_->Release();
258
if (drawTestStencilAlwaysDepthGreater_)
259
drawTestStencilAlwaysDepthGreater_->Release();
260
if (drawTestDepthLessEqual_)
261
drawTestDepthLessEqual_->Release();
262
if (drawTestDepthGreater_)
263
drawTestDepthGreater_->Release();
264
265
if (discardFragShader_)
266
discardFragShader_->Release();
267
268
// Shader test
269
if (adrenoLogicDiscardPipeline_)
270
adrenoLogicDiscardPipeline_->Release();
271
if (flatShadingPipeline_)
272
flatShadingPipeline_->Release();
273
274
if (adrenoLogicDiscardFragShader_)
275
adrenoLogicDiscardFragShader_->Release();
276
if (adrenoLogicDiscardVertShader_)
277
adrenoLogicDiscardVertShader_->Release();
278
if (flatFragShader_)
279
flatFragShader_->Release();
280
if (flatVertShader_)
281
flatVertShader_->Release();
282
283
if (samplerNearest_)
284
samplerNearest_->Release();
285
}
286
287
void GPUDriverTestScreen::CreateViews() {
288
using namespace Draw;
289
290
if (!samplerNearest_) {
291
DrawContext *draw = screenManager()->getDrawContext();
292
SamplerStateDesc nearestDesc{};
293
samplerNearest_ = draw->CreateSamplerState(nearestDesc);
294
}
295
296
// Don't bother with views for now.
297
using namespace UI;
298
auto di = GetI18NCategory(I18NCat::DIALOG);
299
auto cr = GetI18NCategory(I18NCat::PSPCREDITS);
300
301
AnchorLayout *anchor = new AnchorLayout();
302
root_ = anchor;
303
304
tabHolder_ = new TabHolder(ORIENT_HORIZONTAL, 30.0f, new AnchorLayoutParams(FILL_PARENT, FILL_PARENT, false));
305
anchor->Add(tabHolder_);
306
tabHolder_->AddTab("Discard", new LinearLayout(ORIENT_VERTICAL));
307
tabHolder_->AddTab("Shader", new LinearLayout(ORIENT_VERTICAL));
308
309
Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(100, WRAP_CONTENT, 10, NONE, NONE, 10));
310
back->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
311
anchor->Add(back);
312
}
313
314
void GPUDriverTestScreen::DiscardTest(UIContext &dc) {
315
using namespace UI;
316
using namespace Draw;
317
if (!discardWriteDepthStencil_) {
318
DrawContext *draw = screenManager()->getDrawContext();
319
320
// Create the special shader module.
321
322
discardFragShader_ = CreateShader(draw, ShaderStage::Fragment, fsDiscard);
323
324
InputLayout *inputLayout = ui_draw2d.CreateInputLayout(draw);
325
BlendState *blendOff = draw->CreateBlendState({ false, 0xF });
326
BlendState *blendOffNoColor = draw->CreateBlendState({ false, 0x8 });
327
328
// Write depth, write stencil.
329
DepthStencilStateDesc dsDesc{};
330
dsDesc.depthTestEnabled = true;
331
dsDesc.depthWriteEnabled = true;
332
dsDesc.depthCompare = Comparison::ALWAYS;
333
dsDesc.stencilEnabled = true;
334
dsDesc.stencil.compareOp = Comparison::ALWAYS;
335
dsDesc.stencil.passOp = StencilOp::REPLACE;
336
dsDesc.stencil.failOp = StencilOp::REPLACE; // These two shouldn't matter, because the test that fails is discard, not stencil.
337
dsDesc.stencil.depthFailOp = StencilOp::REPLACE;
338
DepthStencilState *depthStencilWrite = draw->CreateDepthStencilState(dsDesc);
339
340
// Write only depth.
341
dsDesc.stencilEnabled = false;
342
DepthStencilState *depthWrite = draw->CreateDepthStencilState(dsDesc);
343
344
// Write only stencil.
345
dsDesc.stencilEnabled = true;
346
dsDesc.depthTestEnabled = false;
347
dsDesc.depthWriteEnabled = false; // Just in case the driver is crazy. when test is enabled, though, this should be ignored.
348
DepthStencilState *stencilWrite = draw->CreateDepthStencilState(dsDesc);
349
350
// Now for the shaders that read depth and/or stencil.
351
352
dsDesc.depthTestEnabled = true;
353
dsDesc.stencilEnabled = true;
354
dsDesc.depthCompare = Comparison::ALWAYS;
355
dsDesc.stencil.compareOp = Comparison::EQUAL;
356
dsDesc.stencil.failOp = StencilOp::KEEP;
357
dsDesc.stencil.depthFailOp = StencilOp::KEEP;
358
DepthStencilState *stencilEqualDepthAlways = draw->CreateDepthStencilState(dsDesc);
359
360
dsDesc.depthTestEnabled = false;
361
dsDesc.stencil.compareOp = Comparison::EQUAL;
362
DepthStencilState *stencilEqual = draw->CreateDepthStencilState(dsDesc);
363
364
dsDesc.depthTestEnabled = true;
365
dsDesc.depthCompare = Comparison::ALWAYS;
366
dsDesc.stencil.compareOp = Comparison::NOT_EQUAL;
367
DepthStencilState *stenciNotEqualDepthAlways = draw->CreateDepthStencilState(dsDesc);
368
369
dsDesc.depthTestEnabled = false;
370
dsDesc.stencil.compareOp = Comparison::NOT_EQUAL;
371
DepthStencilState *stencilNotEqual = draw->CreateDepthStencilState(dsDesc);
372
373
dsDesc.stencilEnabled = true;
374
dsDesc.depthTestEnabled = true;
375
dsDesc.stencil.compareOp = Comparison::ALWAYS;
376
dsDesc.depthCompare = Comparison::LESS_EQUAL;
377
DepthStencilState *stencilAlwaysDepthTestLessEqual = draw->CreateDepthStencilState(dsDesc);
378
dsDesc.depthCompare = Comparison::GREATER;
379
DepthStencilState *stencilAlwaysDepthTestGreater = draw->CreateDepthStencilState(dsDesc);
380
381
dsDesc.stencilEnabled = false;
382
dsDesc.depthTestEnabled = true;
383
dsDesc.depthCompare = Comparison::LESS_EQUAL;
384
DepthStencilState *depthTestLessEqual = draw->CreateDepthStencilState(dsDesc);
385
dsDesc.depthCompare = Comparison::GREATER;
386
DepthStencilState *depthTestGreater = draw->CreateDepthStencilState(dsDesc);
387
388
RasterState *rasterNoCull = draw->CreateRasterState({});
389
390
PipelineDesc discardDesc{
391
Primitive::TRIANGLE_LIST,
392
{ draw->GetVshaderPreset(VS_TEXTURE_COLOR_2D), discardFragShader_ },
393
inputLayout, depthStencilWrite, blendOffNoColor, rasterNoCull, &vsColBufDesc,
394
};
395
discardWriteDepthStencil_ = draw->CreateGraphicsPipeline(discardDesc, "test");
396
discardDesc.depthStencil = depthWrite;
397
discardWriteDepth_ = draw->CreateGraphicsPipeline(discardDesc, "test");
398
discardDesc.depthStencil = stencilWrite;
399
discardWriteStencil_ = draw->CreateGraphicsPipeline(discardDesc, "test");
400
401
PipelineDesc testDesc{
402
Primitive::TRIANGLE_LIST,
403
{ draw->GetVshaderPreset(VS_TEXTURE_COLOR_2D), draw->GetFshaderPreset(FS_TEXTURE_COLOR_2D) },
404
inputLayout, stencilEqual, blendOff, rasterNoCull, &vsColBufDesc,
405
};
406
drawTestStencilEqual_ = draw->CreateGraphicsPipeline(testDesc, "test");
407
408
testDesc.depthStencil = stencilEqualDepthAlways;
409
drawTestStencilEqualDepthAlways_ = draw->CreateGraphicsPipeline(testDesc, "test");
410
411
testDesc.depthStencil = stencilNotEqual;
412
drawTestStencilNotEqual_ = draw->CreateGraphicsPipeline(testDesc, "test");
413
414
testDesc.depthStencil = stenciNotEqualDepthAlways;
415
drawTestStencilNotEqualDepthAlways_ = draw->CreateGraphicsPipeline(testDesc, "test");
416
417
testDesc.depthStencil = stencilAlwaysDepthTestGreater;
418
drawTestStencilAlwaysDepthGreater_ = draw->CreateGraphicsPipeline(testDesc, "test");
419
420
testDesc.depthStencil = stencilAlwaysDepthTestLessEqual;
421
drawTestStencilAlwaysDepthLessEqual_ = draw->CreateGraphicsPipeline(testDesc, "test");
422
423
testDesc.depthStencil = depthTestGreater;
424
drawTestDepthGreater_ = draw->CreateGraphicsPipeline(testDesc, "test");
425
426
testDesc.depthStencil = depthTestLessEqual;
427
drawTestDepthLessEqual_ = draw->CreateGraphicsPipeline(testDesc, "test");
428
429
inputLayout->Release();
430
blendOff->Release();
431
depthStencilWrite->Release();
432
stencilEqual->Release();
433
stencilNotEqual->Release();
434
stencilEqualDepthAlways->Release();
435
stenciNotEqualDepthAlways->Release();
436
stencilAlwaysDepthTestLessEqual->Release();
437
stencilAlwaysDepthTestGreater->Release();
438
depthTestLessEqual->Release();
439
depthTestGreater->Release();
440
rasterNoCull->Release();
441
}
442
443
Draw::DrawContext *draw = dc.GetDrawContext();
444
445
static const char * const writeModeNames[] = { "Stencil+Depth", "Stencil", "Depth" };
446
Pipeline *writePipelines[] = { discardWriteDepthStencil_, discardWriteStencil_, discardWriteDepth_ };
447
const int numWriteModes = ARRAY_SIZE(writeModeNames);
448
449
static const char * const testNames[] = { "Stenc", "Stenc+DepthA", "Depth", "StencA+Depth" };
450
Pipeline *testPipeline1[] = { drawTestStencilEqual_, drawTestStencilEqualDepthAlways_, drawTestDepthLessEqual_, drawTestStencilAlwaysDepthLessEqual_ };
451
Pipeline *testPipeline2[] = { drawTestStencilNotEqual_, drawTestStencilNotEqualDepthAlways_, drawTestDepthGreater_, drawTestStencilAlwaysDepthGreater_ };
452
const int numTests = ARRAY_SIZE(testNames);
453
454
static const bool validCombinations[numWriteModes][numTests] = {
455
{true, true, true, true},
456
{true, true, false, false},
457
{false, false, true, true},
458
};
459
460
// Don't want any fancy font texture stuff going on here, so use FLAG_DYNAMIC_ASCII everywhere!
461
462
// We draw the background at Z=0.5 and the text at Z=0.9.
463
464
// Then we draw a rectangle with a depth test or stencil test that should mask out the text.
465
// Plus a second rectangle with the opposite test.
466
467
// If everything is OK, both the background and the text should be OK.
468
469
Bounds layoutBounds = dc.GetLayoutBounds();
470
471
dc.Begin();
472
dc.SetFontScale(1.0f, 1.0f);
473
std::string apiName = screenManager()->getDrawContext()->GetInfoString(InfoField::APINAME);
474
std::string vendor = screenManager()->getDrawContext()->GetInfoString(InfoField::VENDORSTRING);
475
std::string driver = screenManager()->getDrawContext()->GetInfoString(InfoField::DRIVER);
476
dc.DrawText(apiName, layoutBounds.centerX(), 20, 0xFFFFFFFF, ALIGN_CENTER);
477
dc.DrawText(vendor, layoutBounds.centerX(), 60, 0xFFFFFFFF, ALIGN_CENTER);
478
dc.DrawText(driver, layoutBounds.centerX(), 100, 0xFFFFFFFF, ALIGN_CENTER);
479
dc.Flush();
480
481
float testW = 170.f;
482
float padding = 20.0f;
483
UI::Style style = dc.theme->itemStyle;
484
485
float y = 150;
486
for (int j = 0; j < numWriteModes; j++, y += 120.f + padding) {
487
float x = layoutBounds.x + (layoutBounds.w - (float)numTests * testW - (float)(numTests - 1) * padding) / 2.0f;
488
dc.Begin();
489
dc.DrawText(writeModeNames[j], layoutBounds.x + padding, y + 40, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);
490
dc.Flush();
491
for (int i = 0; i < numTests; i++, x += testW + padding) {
492
if (!validCombinations[j][i])
493
continue;
494
dc.Begin();
495
Bounds bounds = { x, y + 40, testW, 70 };
496
dc.DrawText(testNames[i], bounds.x, y, style.fgColor, FLAG_DYNAMIC_ASCII);
497
dc.Flush();
498
499
dc.BeginPipeline(writePipelines[j], samplerNearest_);
500
// Draw the rectangle with stencil value 0, depth 0.1f and the text with stencil 0xFF, depth 0.9. Then set 0xFF as the stencil value and draw the rectangles at depth 0.5.
501
502
draw->SetStencilParams(0, 0xFF, 0xFF);
503
dc.SetCurZ(0.1f);
504
dc.FillRect(UI::Drawable(bgColorBAD), bounds);
505
// test bounds
506
dc.Flush();
507
508
draw->SetStencilParams(0xff, 0xFF, 0xFF);
509
dc.SetCurZ(0.9f);
510
dc.DrawTextRect("TEST OK", bounds, textColorBAD, ALIGN_HCENTER | ALIGN_VCENTER | FLAG_DYNAMIC_ASCII);
511
dc.Flush();
512
513
// Draw rectangle that should result in the text
514
dc.BeginPipeline(testPipeline1[i], samplerNearest_);
515
draw->SetStencilParams(0xff, 0, 0xFF);
516
dc.SetCurZ(0.5f);
517
dc.FillRect(UI::Drawable(textColorOK), bounds);
518
dc.Flush();
519
520
// Draw rectangle that should result in the bg
521
dc.BeginPipeline(testPipeline2[i], samplerNearest_);
522
draw->SetStencilParams(0xff, 0, 0xFF);
523
dc.SetCurZ(0.5f);
524
dc.FillRect(UI::Drawable(bgColorOK), bounds);
525
dc.Flush();
526
}
527
}
528
dc.Flush();
529
}
530
531
void GPUDriverTestScreen::ShaderTest(UIContext &dc) {
532
using namespace Draw;
533
534
Draw::DrawContext *draw = dc.GetDrawContext();
535
536
if (!adrenoLogicDiscardPipeline_) {
537
adrenoLogicDiscardFragShader_ = CreateShader(draw, ShaderStage::Fragment, fsAdrenoLogicTest);
538
adrenoLogicDiscardVertShader_ = CreateShader(draw, ShaderStage::Vertex, vsAdrenoLogicTest);
539
540
flatFragShader_ = CreateShader(draw, ShaderStage::Fragment, fsFlat);
541
flatVertShader_ = CreateShader(draw, ShaderStage::Vertex, vsFlat);
542
543
InputLayout *inputLayout = ui_draw2d.CreateInputLayout(draw);
544
// No blending used.
545
BlendState *blendOff = draw->CreateBlendState({ false, 0xF });
546
547
// No depth or stencil, we only use discard in this test.
548
DepthStencilStateDesc dsDesc{};
549
dsDesc.depthTestEnabled = false;
550
dsDesc.depthWriteEnabled = false;
551
DepthStencilState *depthStencilOff = draw->CreateDepthStencilState(dsDesc);
552
553
RasterState *rasterNoCull = draw->CreateRasterState({});
554
555
PipelineDesc adrenoLogicDiscardDesc{
556
Primitive::TRIANGLE_LIST,
557
{ adrenoLogicDiscardVertShader_, adrenoLogicDiscardFragShader_ },
558
inputLayout, depthStencilOff, blendOff, rasterNoCull, &vsColBufDesc,
559
};
560
adrenoLogicDiscardPipeline_ = draw->CreateGraphicsPipeline(adrenoLogicDiscardDesc, "test");
561
562
PipelineDesc flatDesc{
563
Primitive::TRIANGLE_LIST,
564
{ flatVertShader_, flatFragShader_ },
565
inputLayout, depthStencilOff, blendOff, rasterNoCull, &vsColBufDesc,
566
};
567
flatShadingPipeline_ = draw->CreateGraphicsPipeline(flatDesc, "test");
568
569
inputLayout->Release();
570
blendOff->Release();
571
depthStencilOff->Release();
572
rasterNoCull->Release();
573
}
574
575
Bounds layoutBounds = dc.GetLayoutBounds();
576
577
dc.Begin();
578
dc.SetFontScale(1.0f, 1.0f);
579
std::string apiName = screenManager()->getDrawContext()->GetInfoString(InfoField::APINAME);
580
std::string vendor = screenManager()->getDrawContext()->GetInfoString(InfoField::VENDORSTRING);
581
std::string driver = screenManager()->getDrawContext()->GetInfoString(InfoField::DRIVER);
582
dc.DrawText(apiName, layoutBounds.centerX(), 20, 0xFFFFFFFF, ALIGN_CENTER);
583
dc.DrawText(vendor, layoutBounds.centerX(), 60, 0xFFFFFFFF, ALIGN_CENTER);
584
dc.DrawText(driver, layoutBounds.centerX(), 100, 0xFFFFFFFF, ALIGN_CENTER);
585
dc.Flush();
586
587
float y = layoutBounds.y + 150;
588
float x = layoutBounds.x + 10;
589
dc.Begin();
590
dc.DrawText("Adreno logic", x, y, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);
591
dc.Flush();
592
593
float testW = 170.f;
594
595
Bounds bounds = { x + 200, y, testW, 70 };
596
597
// Draw rectangle that should result in the bg
598
dc.Begin();
599
dc.FillRect(UI::Drawable(bgColorOK), bounds);
600
dc.Flush();
601
602
// Draw text on it using the shader.
603
dc.BeginPipeline(adrenoLogicDiscardPipeline_, samplerNearest_);
604
dc.DrawTextRect("TEST OK", bounds, textColorOK, ALIGN_HCENTER | ALIGN_VCENTER | FLAG_DYNAMIC_ASCII);
605
dc.Flush();
606
607
y += 100;
608
609
dc.Begin();
610
dc.DrawText("Flat shaded tex", x, y, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);
611
dc.DrawText("(TEST OK if logo but no gradient!)", x + 400, y, 0xFFFFFFFF, ALIGN_LEFT);
612
dc.Flush();
613
614
bounds = { x + 200, y, 100, 100 };
615
616
// Draw rectangle that should be flat shaded
617
dc.BeginPipeline(flatShadingPipeline_, samplerNearest_);
618
// There is a "provoking vertex" difference here between GL and Vulkan when using flat shading. One gets one color, one gets the other.
619
// However, we now use the VK_EXT_provoking_vertex extension to make it match up (and match with the PSP).
620
dc.DrawImageVGradient(ImageID("I_ICON"), 0xFFFFFFFF, 0xFF808080, bounds);
621
dc.Flush();
622
623
y += 120;
624
625
dc.Begin();
626
dc.DrawText("Test done", x, y, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);
627
dc.Flush();
628
}
629
630
void GPUDriverTestScreen::DrawForeground(UIContext &dc) {
631
switch (tabHolder_->GetCurrentTab()) {
632
case 0:
633
DiscardTest(dc);
634
break;
635
case 1:
636
ShaderTest(dc);
637
break;
638
}
639
}
640
641