Skip to content

Commit 064ac03

Browse files
tests: Add test for input attachment feedback.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
1 parent 2763dd2 commit 064ac03

4 files changed

Lines changed: 220 additions & 0 deletions

File tree

tests/d3d12_render_target.c

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,3 +3242,173 @@ void test_input_attachments(void)
32423242
ID3D12DeviceExt2_Release(device_ext2);
32433243
destroy_test_context(&context);
32443244
}
3245+
3246+
void test_input_attachments_feedback(void)
3247+
{
3248+
D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc;
3249+
D3D12_VK_INPUT_ATTACHMENT_MAPPINGS mappings;
3250+
ID3D12GraphicsCommandListExt2 *list_ext2;
3251+
struct test_context_desc context_desc;
3252+
static const float black[4] = { 0 };
3253+
D3D12_CPU_DESCRIPTOR_HANDLE depth;
3254+
D3D12_ROOT_SIGNATURE_DESC rs_desc;
3255+
D3D12_CPU_DESCRIPTOR_HANDLE rtvs;
3256+
ID3D12DeviceExt2 *device_ext2;
3257+
struct resource_readback rb;
3258+
struct test_context context;
3259+
ID3D12DescriptorHeap *descs;
3260+
ID3D12DescriptorHeap *rtv;
3261+
ID3D12DescriptorHeap *dsv;
3262+
ID3D12Resource *color;
3263+
ID3D12Resource *ds;
3264+
D3D12_VIEWPORT vp;
3265+
unsigned int x, y;
3266+
D3D12_RECT sci;
3267+
unsigned int i;
3268+
HRESULT hr;
3269+
3270+
#include "shaders/render_target/headers/vs_no_attachments.h"
3271+
#include "shaders/render_target/headers/ps_input_attachment_feedback.h"
3272+
3273+
memset(&context_desc, 0, sizeof(context_desc));
3274+
memset(&context, 0, sizeof(context));
3275+
context_desc.no_pipeline = true;
3276+
context_desc.no_render_target = true;
3277+
context_desc.no_root_signature = true;
3278+
3279+
if (!init_test_context(&context, &context_desc))
3280+
return;
3281+
3282+
if (FAILED(ID3D12Device_QueryInterface(context.device, &IID_ID3D12DeviceExt2, (void **)&device_ext2)))
3283+
{
3284+
skip("ID3D12DeviceExt2 not supported, skipping.\n");
3285+
destroy_test_context(&context);
3286+
return;
3287+
}
3288+
3289+
if (ID3D12DeviceExt2_GetTilerOptimizationTier(device_ext2) < D3D12_VK_TILER_OPTIMIZATION_TIER_1)
3290+
{
3291+
skip("Tiler optimization tier 1 not supported, skipping.\n");
3292+
ID3D12DeviceExt2_Release(device_ext2);
3293+
destroy_test_context(&context);
3294+
return;
3295+
}
3296+
3297+
if (FAILED(ID3D12GraphicsCommandList_QueryInterface(context.list, &IID_ID3D12GraphicsCommandListExt2, (void **)&list_ext2)))
3298+
{
3299+
skip("ID3D12GraphicsCommandListExt2 not supported, skipping.\n");
3300+
ID3D12DeviceExt2_Release(device_ext2);
3301+
destroy_test_context(&context);
3302+
return;
3303+
}
3304+
3305+
ID3D12DeviceExt2_OptInToTilerOptimizations(device_ext2);
3306+
3307+
memset(&rs_desc, 0, sizeof(rs_desc));
3308+
3309+
mappings.NumRenderTargets = 1;
3310+
mappings.EnableDepth = TRUE;
3311+
mappings.RenderTargets[0].RegisterSpace = 1;
3312+
mappings.RenderTargets[0].ShaderRegister = 100;
3313+
mappings.Depth.RegisterSpace = 1;
3314+
mappings.Depth.ShaderRegister = 101;
3315+
3316+
create_root_signature_with_input_attachments(context.device, &rs_desc, &mappings, &context.root_signature);
3317+
3318+
init_pipeline_state_desc(&pso_desc, context.root_signature, DXGI_FORMAT_R32_UINT,
3319+
&vs_no_attachments_dxbc,
3320+
&ps_input_attachment_feedback_dxbc, NULL);
3321+
3322+
pso_desc.DSVFormat = DXGI_FORMAT_D32_FLOAT;
3323+
pso_desc.DepthStencilState.DepthEnable = TRUE;
3324+
pso_desc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
3325+
pso_desc.DepthStencilState.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS;
3326+
3327+
hr = ID3D12Device_CreateGraphicsPipelineState(context.device, &pso_desc, &IID_ID3D12PipelineState, (void **)&context.pipeline_state);
3328+
ok(SUCCEEDED(hr), "Failed to create PSO, hr #%x.\n", hr);
3329+
3330+
color = create_default_texture2d(context.device, 64, 64, 1, 1,
3331+
DXGI_FORMAT_R32_UINT,
3332+
D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET,
3333+
D3D12_RESOURCE_STATE_RENDER_TARGET);
3334+
3335+
ds = create_default_texture2d(context.device, 64, 64, 1, 1,
3336+
DXGI_FORMAT_D32_FLOAT,
3337+
D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL,
3338+
D3D12_RESOURCE_STATE_DEPTH_WRITE);
3339+
3340+
rtv = create_cpu_descriptor_heap(context.device, D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1);
3341+
dsv = create_cpu_descriptor_heap(context.device, D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1);
3342+
3343+
rtvs = get_cpu_rtv_handle(&context, rtv, 0);
3344+
depth = get_cpu_dsv_handle(&context, dsv, 0);
3345+
3346+
ID3D12Device_CreateRenderTargetView(context.device, color, NULL, rtvs);
3347+
ID3D12Device_CreateDepthStencilView(context.device, ds, NULL, depth);
3348+
3349+
descs = create_gpu_descriptor_heap(context.device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
3350+
ID3D12DeviceExt2_GetInputAttachmentDescriptorsCount(device_ext2));
3351+
3352+
ID3D12GraphicsCommandList_SetDescriptorHeaps(context.list, 1, &descs);
3353+
ID3D12GraphicsCommandList_SetGraphicsRootSignature(context.list, context.root_signature);
3354+
3355+
/* Write input attachment descriptors to heap. */
3356+
ID3D12DeviceExt2_CreateInputAttachmentDescriptors(device_ext2, 1, &rtvs, TRUE,
3357+
&depth, NULL, get_cpu_descriptor_handle(&context, descs, 0));
3358+
ID3D12GraphicsCommandListExt2_SetRootSignatureInputAttachments(list_ext2,
3359+
get_gpu_descriptor_handle(&context, descs, 0));
3360+
3361+
set_viewport(&vp, 0, 0, 64, 64, 0, 1);
3362+
set_rect(&sci, 0, 0, 64, 64);
3363+
3364+
ID3D12GraphicsCommandList_RSSetViewports(context.list, 1, &vp);
3365+
ID3D12GraphicsCommandList_RSSetScissorRects(context.list, 1, &sci);
3366+
ID3D12GraphicsCommandList_IASetPrimitiveTopology(context.list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
3367+
ID3D12GraphicsCommandList_OMSetStencilRef(context.list, 0x60);
3368+
ID3D12GraphicsCommandListExt2_SetInputAttachmentFeedback(list_ext2, 0x1, TRUE, FALSE);
3369+
ID3D12GraphicsCommandList_OMSetRenderTargets(context.list, 1, &rtvs, TRUE, &depth);
3370+
ID3D12GraphicsCommandList_SetPipelineState(context.list, context.pipeline_state);
3371+
ID3D12GraphicsCommandList_ClearRenderTargetView(context.list, rtvs, black, 0, NULL);
3372+
ID3D12GraphicsCommandList_ClearDepthStencilView(context.list, depth, D3D12_CLEAR_FLAG_DEPTH, 0.0f, 0, 0, NULL);
3373+
3374+
for (i = 0; i < 4; i++)
3375+
{
3376+
/* Need to sync with the clear. */
3377+
ID3D12GraphicsCommandListExt2_InputAttachmentPixelBarrier(list_ext2);
3378+
ID3D12GraphicsCommandList_DrawInstanced(context.list, 3, 1, 0, 0);
3379+
}
3380+
3381+
transition_resource_state(context.list, color, D3D12_RESOURCE_STATE_RENDER_TARGET,
3382+
D3D12_RESOURCE_STATE_COPY_SOURCE);
3383+
3384+
get_texture_readback_with_command_list(color, 0, &rb, context.queue, context.list);
3385+
for (y = 0; y < 64; y++)
3386+
{
3387+
for (x = 0; x < 64; x++)
3388+
{
3389+
uint32_t rt = 0;
3390+
float d = 0.0f;
3391+
uint32_t value;
3392+
3393+
/* Resolve the feedback. */
3394+
for (i = 0; i < 4; i++)
3395+
{
3396+
rt += (uint32_t)(d * 1024.0f);
3397+
d += (x + 0.5f) / 1024.0f + (y + 0.5f) / 512.0f;
3398+
}
3399+
3400+
value = get_readback_uint(&rb, x, y, 0);
3401+
ok(value == rt, "coord %u, %u: expected %u, got %u\n", x, y, rt, value);
3402+
}
3403+
}
3404+
release_resource_readback(&rb);
3405+
3406+
ID3D12Resource_Release(color);
3407+
ID3D12Resource_Release(ds);
3408+
ID3D12DescriptorHeap_Release(descs);
3409+
ID3D12DescriptorHeap_Release(rtv);
3410+
ID3D12DescriptorHeap_Release(dsv);
3411+
ID3D12GraphicsCommandListExt2_Release(list_ext2);
3412+
ID3D12DeviceExt2_Release(device_ext2);
3413+
destroy_test_context(&context);
3414+
}

tests/d3d12_tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,4 @@ decl_test(test_render_pass_suspend_resume_opts_disabled);
529529
decl_test(test_static_sampler_dynamic_index);
530530
decl_test(test_descriptor_range_validation);
531531
decl_test(test_input_attachments);
532+
decl_test(test_input_attachments_feedback);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
static const DWORD ps_input_attachment_feedback_code_dxbc[] =
2+
{
3+
0x43425844, 0x750f9035, 0xd28534b8, 0xc9185bdd, 0x377e6b4f, 0x00000001, 0x00000230, 0x00000003,
4+
0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5+
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6+
0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000001,
7+
0x00000000, 0x00000e01, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01,
8+
0x545f5653, 0x65677261, 0x56530074, 0x7065445f, 0xab006874, 0x58454853, 0x00000174, 0x00000051,
9+
0x0000005d, 0x0100086a, 0x07001858, 0x00307e46, 0x00000000, 0x00000064, 0x00000064, 0x00004444,
10+
0x00000001, 0x07001858, 0x00307e46, 0x00000001, 0x00000065, 0x00000065, 0x00005555, 0x00000001,
11+
0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000065,
12+
0x0000c001, 0x02000068, 0x00000002, 0x0500001b, 0x00100032, 0x00000000, 0x00101046, 0x00000000,
13+
0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
14+
0x0800002d, 0x00100012, 0x00000001, 0x00100f46, 0x00000000, 0x00207e46, 0x00000000, 0x00000064,
15+
0x0800002d, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x00207e46, 0x00000001, 0x00000065,
16+
0x07000038, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x44800000, 0x0500001c,
17+
0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x0700001e, 0x00102012, 0x00000000, 0x0010001a,
18+
0x00000000, 0x0010000a, 0x00000001, 0x0a00000f, 0x00100022, 0x00000000, 0x00101046, 0x00000000,
19+
0x00004002, 0x3a800000, 0x3b000000, 0x00000000, 0x00000000, 0x06000000, 0x0000c001, 0x0010001a,
20+
0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21+
};
22+
#ifdef __GNUC__
23+
#define UNUSED_ARRAY_ATTR __attribute__((unused))
24+
#else
25+
#define UNUSED_ARRAY_ATTR
26+
#endif
27+
UNUSED_ARRAY_ATTR static const D3D12_SHADER_BYTECODE ps_input_attachment_feedback_dxbc = { ps_input_attachment_feedback_code_dxbc, sizeof(ps_input_attachment_feedback_code_dxbc) };
28+
#undef UNUSED_ARRAY_ATTR
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
struct PSOut
2+
{
3+
uint rt : SV_Target;
4+
float d : SV_Depth;
5+
};
6+
7+
Texture2D<uint> RT : register(t100, space1);
8+
Texture2D<float> Depth : register(t101, space1);
9+
10+
PSOut main(float4 pos : SV_Position)
11+
{
12+
PSOut pout;
13+
14+
pout.rt = RT.Load(int3(pos.xy, 0));
15+
pout.d = Depth.Load(int3(pos.xy, 0));
16+
17+
pout.rt += uint(pout.d * 1024.0);
18+
pout.d += pos.x / 1024.0 + pos.y / 512.0;
19+
20+
return pout;
21+
}

0 commit comments

Comments
 (0)