File: d3d12_overlay_test.cpp

package info (click to toggle)
renderdoc 1.24%2Bdfsg-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 105,156 kB
  • sloc: cpp: 759,405; ansic: 309,460; python: 26,606; xml: 22,599; java: 11,365; cs: 7,181; makefile: 6,707; yacc: 5,682; ruby: 4,648; perl: 3,461; sh: 2,354; php: 2,119; lisp: 1,835; javascript: 1,524; tcl: 1,068; ml: 747
file content (450 lines) | stat: -rw-r--r-- 16,917 bytes parent folder | download
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/******************************************************************************
 * The MIT License (MIT)
 *
 * Copyright (c) 2019-2022 Baldur Karlsson
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 ******************************************************************************/

#include "d3d12_test.h"

RD_TEST(D3D12_Overlay_Test, D3D12GraphicsTest)
{
  static constexpr const char *Description =
      "Makes a couple of draws that show off all the overlays in some way";

  std::string vertexEndPosVert = R"EOSHADER(

struct vertin
{
	float3 pos : POSITION;
	float4 col : COLOR0;
	float2 uv : TEXCOORD0;
};

struct v2f
{
	float4 col : COLOR0;
	float2 uv : TEXCOORD0;
	float4 pos : SV_POSITION;
};

v2f main(vertin IN)
{
	v2f OUT = (v2f)0;

	OUT.pos = float4(IN.pos.xyz, 1);
	OUT.col = IN.col;
	OUT.uv = IN.uv;

	return OUT;
}

)EOSHADER";

  std::string vertexEndPosPixel = R"EOSHADER(

struct v2f
{
	float4 col : COLOR0;
	float2 uv : TEXCOORD0;
	float4 pos : SV_POSITION;
};

float4 main(v2f IN) : SV_Target0
{
	return IN.col;
}

)EOSHADER";

  std::string whitePixel = R"EOSHADER(

float4 main() : SV_Target0
{
	return float4(1, 1, 1, 1);
}

)EOSHADER";

  int main()
  {
    // initialise, create window, create device, etc
    if(!Init())
      return 3;

    ID3DBlobPtr vsblob[3] = {};
    ID3DBlobPtr psblob[3] = {};
    ID3DBlobPtr whitepsblob[3] = {};

    {
      int i = 0;
      for(std::string profile : {"_5_0", "_5_1", "_6_0"})
      {
        if(i == 2 && !m_DXILSupport)
          continue;

        vsblob[i] = Compile(vertexEndPosVert, "main", "vs" + profile);
        psblob[i] = Compile(vertexEndPosPixel, "main", "ps" + profile);
        whitepsblob[i] = Compile(whitePixel, "main", "ps" + profile);
        i++;
      }
    }

    const DefaultA2V VBData[] = {
        // this triangle occludes in depth
        {Vec3f(-0.5f, -0.5f, 0.0f), Vec4f(0.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(-0.5f, 0.0f, 0.0f), Vec4f(0.0f, 0.0f, 1.0f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(0.0f, 0.0f, 0.0f), Vec4f(0.0f, 0.0f, 1.0f, 1.0f), Vec2f(1.0f, 0.0f)},

        // this triangle occludes in stencil
        {Vec3f(-0.5f, 0.0f, 0.9f), Vec4f(1.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(-0.5f, 0.5f, 0.9f), Vec4f(1.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(0.0f, 0.0f, 0.9f), Vec4f(1.0f, 0.0f, 0.0f, 1.0f), Vec2f(1.0f, 0.0f)},

        // this triangle is just in the background to contribute to overdraw
        {Vec3f(-0.9f, -0.9f, 0.95f), Vec4f(0.1f, 0.1f, 0.1f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(0.0f, 0.9f, 0.95f), Vec4f(0.1f, 0.1f, 0.1f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(0.9f, -0.9f, 0.95f), Vec4f(0.1f, 0.1f, 0.1f, 1.0f), Vec2f(1.0f, 0.0f)},

        // the draw has a few triangles, main one that is occluded for depth, another that is
        // adding to overdraw complexity, one that is backface culled, then a few more of various
        // sizes for triangle size overlay
        {Vec3f(-0.3f, -0.5f, 0.5f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(-0.3f, 0.5f, 0.5f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(0.5f, 0.0f, 0.5f), Vec4f(1.0f, 1.0f, 1.0f, 1.0f), Vec2f(1.0f, 0.0f)},

        {Vec3f(-0.2f, -0.2f, 0.6f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(0.2f, 0.0f, 0.6f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(0.2f, -0.4f, 0.6f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(1.0f, 0.0f)},

        // backface culled
        {Vec3f(0.1f, 0.0f, 0.5f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(0.5f, -0.2f, 0.5f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(0.5f, 0.2f, 0.5f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(1.0f, 0.0f)},

        // depth clipped (i.e. not clamped)
        {Vec3f(0.6f, 0.0f, 0.5f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(0.7f, 0.2f, 0.5f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(0.8f, 0.0f, 1.5f), Vec4f(0.0f, 0.0f, 0.0f, 1.0f), Vec2f(1.0f, 0.0f)},

        // small triangles
        // size=0.005
        {Vec3f(0.0f, 0.4f, 0.5f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(0.0f, 0.41f, 0.5f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(0.01f, 0.4f, 0.5f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(1.0f, 0.0f)},

        // size=0.015
        {Vec3f(0.0f, 0.5f, 0.5f), Vec4f(0.0f, 1.0f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(0.0f, 0.515f, 0.5f), Vec4f(0.0f, 1.0f, 1.0f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(0.015f, 0.5f, 0.5f), Vec4f(0.0f, 1.0f, 1.0f, 1.0f), Vec2f(1.0f, 0.0f)},

        // size=0.02
        {Vec3f(0.0f, 0.6f, 0.5f), Vec4f(1.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(0.0f, 0.62f, 0.5f), Vec4f(1.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(0.02f, 0.6f, 0.5f), Vec4f(1.0f, 1.0f, 0.0f, 1.0f), Vec2f(1.0f, 0.0f)},

        // size=0.025
        {Vec3f(0.0f, 0.7f, 0.5f), Vec4f(1.0f, 0.5f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(0.0f, 0.725f, 0.5f), Vec4f(1.0f, 0.5f, 1.0f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(0.025f, 0.7f, 0.5f), Vec4f(1.0f, 0.5f, 1.0f, 1.0f), Vec2f(1.0f, 0.0f)},

        // this triangle deliberately goes out of the viewport, it will test viewport & scissor
        // clipping
        {Vec3f(-1.3f, -1.3f, 0.95f), Vec4f(0.1f, 0.1f, 0.5f, 1.0f), Vec2f(0.0f, 0.0f)},
        {Vec3f(0.0f, 1.3f, 0.95f), Vec4f(0.1f, 0.1f, 0.5f, 1.0f), Vec2f(0.0f, 1.0f)},
        {Vec3f(1.3f, -1.3f, 0.95f), Vec4f(0.1f, 0.1f, 0.5f, 1.0f), Vec2f(1.0f, 0.0f)},
    };

    ID3D12ResourcePtr vb = MakeBuffer().Data(VBData);

    ID3D12RootSignaturePtr sig = MakeSig({
        tableParam(D3D12_SHADER_VISIBILITY_VERTEX, D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 0, 0, 5, 0),
        tableParam(D3D12_SHADER_VISIBILITY_PIXEL, D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 5, 0),
        tableParam(D3D12_SHADER_VISIBILITY_GEOMETRY, D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 2, 0, 5, 0),
        tableParam(D3D12_SHADER_VISIBILITY_PIXEL, D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 3, 0, 5, 0),
    });

    D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS qualData = {};
    qualData.Format = DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
    qualData.SampleCount = 4;
    dev->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &qualData, sizeof(qualData));

    D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS qualData2 = {};
    qualData2.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
    qualData2.SampleCount = 4;
    dev->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &qualData2, sizeof(qualData2));

    UINT qual = std::min(qualData.NumQualityLevels, qualData2.NumQualityLevels) > 1 ? 1 : 0;

    DXGI_SAMPLE_DESC noMSAA = {1, 0};
    DXGI_SAMPLE_DESC yesMSAA = {4, qual};

    ID3D12PipelineStatePtr depthWritePipe[3][2];
    ID3D12PipelineStatePtr stencilWritePipe[3][2];
    ID3D12PipelineStatePtr backgroundPipe[3][2];
    ID3D12PipelineStatePtr pipe[3][2];
    ID3D12PipelineStatePtr whitepipe[3];

    for(int i = 0; i < 3; i++)
    {
      if(vsblob[i] == NULL)
        continue;

      D3D12PSOCreator creator = MakePSO().RootSig(sig).InputLayout().VS(vsblob[i]).PS(psblob[i]).DSV(
          DXGI_FORMAT_D32_FLOAT_S8X24_UINT);

      creator.GraphicsDesc.RasterizerState.CullMode = D3D12_CULL_MODE_BACK;
      creator.GraphicsDesc.RasterizerState.DepthClipEnable = TRUE;

      creator.GraphicsDesc.DepthStencilState.DepthEnable = TRUE;
      creator.GraphicsDesc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
      creator.GraphicsDesc.DepthStencilState.StencilEnable = FALSE;
      creator.GraphicsDesc.DepthStencilState.FrontFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;
      creator.GraphicsDesc.DepthStencilState.FrontFace.StencilPassOp = D3D12_STENCIL_OP_REPLACE;
      creator.GraphicsDesc.DepthStencilState.FrontFace.StencilDepthFailOp = D3D12_STENCIL_OP_KEEP;
      creator.GraphicsDesc.DepthStencilState.FrontFace.StencilFailOp = D3D12_STENCIL_OP_KEEP;
      creator.GraphicsDesc.DepthStencilState.BackFace =
          creator.GraphicsDesc.DepthStencilState.FrontFace;
      creator.GraphicsDesc.DepthStencilState.StencilReadMask = 0xff;
      creator.GraphicsDesc.DepthStencilState.StencilWriteMask = 0xff;

      creator.GraphicsDesc.DepthStencilState.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS;
      creator.GraphicsDesc.SampleDesc = noMSAA;
      depthWritePipe[i][0] = creator;
      creator.GraphicsDesc.SampleDesc = yesMSAA;
      depthWritePipe[i][1] = creator;

      creator.GraphicsDesc.DepthStencilState.DepthFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL;
      creator.GraphicsDesc.DepthStencilState.StencilEnable = TRUE;

      creator.GraphicsDesc.SampleDesc = noMSAA;
      stencilWritePipe[i][0] = creator;
      creator.GraphicsDesc.SampleDesc = yesMSAA;
      stencilWritePipe[i][1] = creator;

      creator.GraphicsDesc.DepthStencilState.StencilEnable = FALSE;
      creator.GraphicsDesc.SampleDesc = noMSAA;
      backgroundPipe[i][0] = creator;
      creator.GraphicsDesc.SampleDesc = yesMSAA;
      backgroundPipe[i][1] = creator;

      creator.GraphicsDesc.DepthStencilState.StencilEnable = TRUE;
      creator.GraphicsDesc.DepthStencilState.FrontFace.StencilFunc = D3D12_COMPARISON_FUNC_GREATER;
      creator.GraphicsDesc.SampleDesc = noMSAA;
      pipe[i][0] = creator;
      creator.GraphicsDesc.SampleDesc = yesMSAA;
      pipe[i][1] = creator;

      creator.GraphicsDesc.DepthStencilState.StencilEnable = FALSE;
      creator.GraphicsDesc.DepthStencilState.DepthEnable = FALSE;
      creator.GraphicsDesc.DepthStencilState.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS;
      creator.PS(whitepsblob[i]);
      creator.DSV(DXGI_FORMAT_UNKNOWN);
      creator.GraphicsDesc.SampleDesc = noMSAA;
      whitepipe[i] = creator;
    }

    ResourceBarrier(vb, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER);

    ID3D12ResourcePtr dsv = MakeTexture(DXGI_FORMAT_D32_FLOAT_S8X24_UINT, screenWidth, screenHeight)
                                .DSV()
                                .InitialState(D3D12_RESOURCE_STATE_DEPTH_WRITE);

    ID3D12ResourcePtr subtex = MakeTexture(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, screenWidth, screenHeight)
                                   .RTV()
                                   .Array(5)
                                   .Mips(4)
                                   .InitialState(D3D12_RESOURCE_STATE_RENDER_TARGET);

    ID3D12ResourcePtr msaadsv =
        MakeTexture(DXGI_FORMAT_D32_FLOAT_S8X24_UINT, screenWidth, screenHeight)
            .DSV()
            .Multisampled(4, qual)
            .InitialState(D3D12_RESOURCE_STATE_DEPTH_WRITE);

    ID3D12ResourcePtr msaatex =
        MakeTexture(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, screenWidth, screenHeight)
            .RTV()
            .Multisampled(4, qual)
            .InitialState(D3D12_RESOURCE_STATE_RENDER_TARGET);

    while(Running())
    {
      ID3D12ResourcePtr bb;

      int pass = 0;
      for(std::string profile : {"sm5.0", "sm5.1", "sm6.0"})
      {
        if(whitepipe[pass] == NULL)
          break;

        ID3D12GraphicsCommandListPtr cmd = GetCommandBuffer();

        Reset(cmd);

        if(pass == 0)
          bb = StartUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET);

        pushMarker(cmd, profile + " tests");

        for(bool is_msaa : {false, true})
        {
          D3D12_CPU_DESCRIPTOR_HANDLE rtv =
              MakeRTV(is_msaa ? msaatex : bb).Format(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB).CreateCPU(0);

          cmd->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

          IASetVertexBuffer(cmd, vb, sizeof(DefaultA2V), 0);
          cmd->SetGraphicsRootSignature(sig);

          RSSetViewport(cmd, {10.0f, 10.0f, (float)screenWidth - 20.0f, (float)screenHeight - 20.0f,
                              0.0f, 1.0f});
          RSSetScissorRect(cmd, {0, 0, screenWidth, screenHeight});

          OMSetRenderTargets(cmd, {rtv}, MakeDSV(is_msaa ? msaadsv : dsv).CreateCPU(0));

          ClearRenderTargetView(cmd, rtv, {0.2f, 0.2f, 0.2f, 1.0f});
          ClearDepthStencilView(cmd, is_msaa ? msaadsv : dsv,
                                D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0);

          cmd->OMSetStencilRef(0x55);

          // draw the setup triangles
          cmd->SetPipelineState(depthWritePipe[pass][is_msaa ? 1 : 0]);
          cmd->DrawInstanced(3, 1, 0, 0);

          cmd->SetPipelineState(stencilWritePipe[pass][is_msaa ? 1 : 0]);
          cmd->DrawInstanced(3, 1, 3, 0);

          cmd->SetPipelineState(backgroundPipe[pass][is_msaa ? 1 : 0]);
          cmd->DrawInstanced(3, 1, 6, 0);

          // add a marker so we can easily locate this draw
          setMarker(cmd, is_msaa ? "MSAA Test" : "Normal Test");

          cmd->SetPipelineState(pipe[pass][is_msaa ? 1 : 0]);
          cmd->DrawInstanced(24, 1, 9, 0);

          if(!is_msaa)
          {
            setMarker(cmd, "Viewport Test");

            RSSetViewport(cmd, {10.0f, 10.0f, 80.0f, 80.0f, 0.0f, 1.0f});
            RSSetScissorRect(cmd, {24, 24, 76, 76});
            cmd->SetPipelineState(backgroundPipe[pass][0]);
            cmd->DrawInstanced(3, 1, 33, 0);
          }
        }

        D3D12_CPU_DESCRIPTOR_HANDLE subrtv = MakeRTV(subtex)
                                                 .Format(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB)
                                                 .FirstSlice(2)
                                                 .NumSlices(1)
                                                 .FirstMip(2)
                                                 .NumMips(1)
                                                 .CreateCPU(1);

        RSSetViewport(cmd, {5.0f, 5.0f, float(screenWidth) / 4.0f - 10.0f,
                            float(screenHeight) / 4.0f - 10.0f, 0.0f, 1.0f});
        RSSetScissorRect(cmd, {0, 0, screenWidth / 4, screenHeight / 4});

        OMSetRenderTargets(cmd, {subrtv}, {});

        ClearRenderTargetView(cmd, subrtv, {0.0f, 0.0f, 0.0f, 1.0f});

        cmd->SetPipelineState(whitepipe[pass]);

        subrtv = MakeRTV(subtex)
                     .Format(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB)
                     .FirstSlice(2)
                     .NumSlices(1)
                     .FirstMip(3)
                     .NumMips(1)
                     .CreateCPU(1);

        setMarker(cmd, "Subresources mip 2");
        cmd->DrawInstanced(24, 1, 9, 0);

        RSSetViewport(cmd, {2.0f, 2.0f, float(screenWidth / 8) - 4.0f,
                            float(screenHeight / 8) - 4.0f, 0.0f, 1.0f});
        RSSetScissorRect(cmd, {0, 0, screenWidth / 8, screenHeight / 8});

        OMSetRenderTargets(cmd, {subrtv}, {});

        ClearRenderTargetView(cmd, subrtv, {0.0f, 0.0f, 0.0f, 1.0f});

        setMarker(cmd, "Subresources mip 3");
        cmd->DrawInstanced(24, 1, 9, 0);

        cmd->Close();

        Submit({cmd});

        {
          cmd = GetCommandBuffer();

          Reset(cmd);

          D3D12_CPU_DESCRIPTOR_HANDLE rtv =
              MakeRTV(bb).Format(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB).CreateCPU(0);

          cmd->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

          IASetVertexBuffer(cmd, vb, sizeof(DefaultA2V), 0);
          cmd->SetGraphicsRootSignature(sig);

          OMSetRenderTargets(cmd, {rtv}, {});

          cmd->SetPipelineState(whitepipe[0]);

          setMarker(cmd, "NoView draw");

          cmd->DrawInstanced(3, 1, 33, 0);

          popMarker(cmd);

          cmd->Close();
        }

        Submit({cmd});

        pass++;
      }

      {
        ID3D12GraphicsCommandListPtr cmd = GetCommandBuffer();

        Reset(cmd);

        FinishUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET);

        cmd->Close();

        Submit({cmd});
      }

      Present();
    }

    return 0;
  }
};

REGISTER_TEST();