|
21 | 21 |
|
22 | 22 | #define VKD3D_DBG_CHANNEL VKD3D_DBG_CHANNEL_API |
23 | 23 | #include "d3d12_crosstest.h" |
| 24 | +#include "vkd3d_command_list_vkd3d_ext.h" |
24 | 25 |
|
25 | 26 | void test_srgb_unorm_mismatch_usage_aliasing(void) |
26 | 27 | { |
@@ -3001,3 +3002,243 @@ void test_render_pass_suspend_resume_opts_disabled(void) |
3001 | 3002 | test_render_pass_suspend_resume_opts(false); |
3002 | 3003 | vkd3d_set_behavior_flags(0); |
3003 | 3004 | } |
| 3005 | + |
| 3006 | +void test_input_attachments(void) |
| 3007 | +{ |
| 3008 | + D3D12_CPU_DESCRIPTOR_HANDLE rtvs, depth, stencil, depth_stencil; |
| 3009 | + D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc; |
| 3010 | + D3D12_VK_INPUT_ATTACHMENT_MAPPINGS mappings; |
| 3011 | + ID3D12GraphicsCommandListExt2 *list_ext2; |
| 3012 | + D3D12_RENDER_TARGET_VIEW_DESC rtv_desc; |
| 3013 | + D3D12_DEPTH_STENCIL_VIEW_DESC dsv_desc; |
| 3014 | + struct test_context_desc context_desc; |
| 3015 | + D3D12_DESCRIPTOR_RANGE desc_range; |
| 3016 | + D3D12_ROOT_SIGNATURE_DESC rs_desc; |
| 3017 | + D3D12_ROOT_PARAMETER root_param; |
| 3018 | + ID3D12PipelineState *write_pso; |
| 3019 | + ID3D12DeviceExt2 *device_ext2; |
| 3020 | + ID3D12PipelineState *read_pso; |
| 3021 | + struct test_context context; |
| 3022 | + ID3D12DescriptorHeap *descs; |
| 3023 | + ID3D12DescriptorHeap *rtv; |
| 3024 | + ID3D12DescriptorHeap *dsv; |
| 3025 | + ID3D12Resource *color; |
| 3026 | + ID3D12Resource *ds; |
| 3027 | + D3D12_VIEWPORT vp; |
| 3028 | + D3D12_RECT sci; |
| 3029 | + unsigned int i; |
| 3030 | + HRESULT hr; |
| 3031 | + |
| 3032 | +#include "shaders/render_target/headers/vs_no_attachments.h" |
| 3033 | +#include "shaders/render_target/headers/ps_input_attachment_read.h" |
| 3034 | +#include "shaders/render_target/headers/ps_input_attachment_write.h" |
| 3035 | + |
| 3036 | + memset(&context_desc, 0, sizeof(context_desc)); |
| 3037 | + memset(&context, 0, sizeof(context)); |
| 3038 | + context_desc.no_pipeline = true; |
| 3039 | + context_desc.no_render_target = true; |
| 3040 | + context_desc.no_root_signature = true; |
| 3041 | + |
| 3042 | + if (!init_test_context(&context, &context_desc)) |
| 3043 | + return; |
| 3044 | + |
| 3045 | + if (FAILED(ID3D12Device_QueryInterface(context.device, &IID_ID3D12DeviceExt2, (void **)&device_ext2))) |
| 3046 | + { |
| 3047 | + skip("ID3D12DeviceExt2 not supported, skipping.\n"); |
| 3048 | + destroy_test_context(&context); |
| 3049 | + return; |
| 3050 | + } |
| 3051 | + |
| 3052 | + if (ID3D12DeviceExt2_GetTilerOptimizationTier(device_ext2) < D3D12_VK_TILER_OPTIMIZATION_TIER_1) |
| 3053 | + { |
| 3054 | + skip("Tiler optimization tier 1 not supported, skipping.\n"); |
| 3055 | + ID3D12DeviceExt2_Release(device_ext2); |
| 3056 | + destroy_test_context(&context); |
| 3057 | + return; |
| 3058 | + } |
| 3059 | + |
| 3060 | + if (FAILED(ID3D12GraphicsCommandList_QueryInterface(context.list, &IID_ID3D12GraphicsCommandListExt2, (void **)&list_ext2))) |
| 3061 | + { |
| 3062 | + skip("ID3D12GraphicsCommandListExt2 not supported, skipping.\n"); |
| 3063 | + ID3D12DeviceExt2_Release(device_ext2); |
| 3064 | + destroy_test_context(&context); |
| 3065 | + return; |
| 3066 | + } |
| 3067 | + |
| 3068 | + ID3D12DeviceExt2_OptInToTilerOptimizations(device_ext2); |
| 3069 | + |
| 3070 | + memset(&root_param, 0, sizeof(root_param)); |
| 3071 | + memset(&rs_desc, 0, sizeof(rs_desc)); |
| 3072 | + memset(&mappings, 0, sizeof(mappings)); |
| 3073 | + memset(&desc_range, 0, sizeof(desc_range)); |
| 3074 | + |
| 3075 | + root_param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; |
| 3076 | + root_param.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL; |
| 3077 | + rs_desc.NumParameters = 1; |
| 3078 | + rs_desc.pParameters = &root_param; |
| 3079 | + |
| 3080 | + mappings.NumRenderTargets = 8; |
| 3081 | + mappings.EnableDepth = TRUE; |
| 3082 | + mappings.EnableStencil = TRUE; |
| 3083 | + for (i = 0; i < 8; i++) |
| 3084 | + { |
| 3085 | + mappings.RenderTargets[i].RegisterSpace = 1; |
| 3086 | + mappings.RenderTargets[i].ShaderRegister = 100 + i; |
| 3087 | + } |
| 3088 | + mappings.Depth.RegisterSpace = 1; |
| 3089 | + mappings.Depth.ShaderRegister = 108; |
| 3090 | + mappings.Stencil.RegisterSpace = 1; |
| 3091 | + mappings.Stencil.ShaderRegister = 109; |
| 3092 | + |
| 3093 | + root_param.DescriptorTable.NumDescriptorRanges = 1; |
| 3094 | + root_param.DescriptorTable.pDescriptorRanges = &desc_range; |
| 3095 | + desc_range.RegisterSpace = 1; |
| 3096 | + desc_range.BaseShaderRegister = 100; |
| 3097 | + desc_range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; |
| 3098 | + desc_range.NumDescriptors = 10; |
| 3099 | + |
| 3100 | + create_root_signature_with_input_attachments(context.device, &rs_desc, &mappings, &context.root_signature); |
| 3101 | + |
| 3102 | + init_pipeline_state_desc(&pso_desc, context.root_signature, DXGI_FORMAT_UNKNOWN, |
| 3103 | + &vs_no_attachments_dxbc, |
| 3104 | + &ps_input_attachment_write_dxbc, NULL); |
| 3105 | + |
| 3106 | + pso_desc.NumRenderTargets = 8; |
| 3107 | + /* We write depth, stencil, RT4-8 */ |
| 3108 | + for (i = 4; i < 8; i++) |
| 3109 | + pso_desc.RTVFormats[i] = (i & 1) ? DXGI_FORMAT_R8G8B8A8_UNORM : DXGI_FORMAT_R8G8B8A8_UINT; |
| 3110 | + pso_desc.DSVFormat = DXGI_FORMAT_D32_FLOAT_S8X24_UINT; |
| 3111 | + pso_desc.DepthStencilState.DepthEnable = TRUE; |
| 3112 | + pso_desc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL; |
| 3113 | + pso_desc.DepthStencilState.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS; |
| 3114 | + pso_desc.DepthStencilState.StencilEnable = TRUE; |
| 3115 | + pso_desc.DepthStencilState.StencilWriteMask = 0xff; |
| 3116 | + pso_desc.DepthStencilState.FrontFace.StencilDepthFailOp = D3D12_STENCIL_OP_KEEP; |
| 3117 | + pso_desc.DepthStencilState.FrontFace.StencilFailOp = D3D12_STENCIL_OP_KEEP; |
| 3118 | + pso_desc.DepthStencilState.FrontFace.StencilPassOp = D3D12_STENCIL_OP_REPLACE; |
| 3119 | + pso_desc.DepthStencilState.FrontFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS; |
| 3120 | + pso_desc.DepthStencilState.BackFace = pso_desc.DepthStencilState.FrontFace; |
| 3121 | + |
| 3122 | + hr = ID3D12Device_CreateGraphicsPipelineState(context.device, &pso_desc, &IID_ID3D12PipelineState, (void **)&write_pso); |
| 3123 | + ok(SUCCEEDED(hr), "Failed to create PSO, hr #%x.\n", hr); |
| 3124 | + |
| 3125 | + pso_desc.PS = ps_input_attachment_read_dxbc; |
| 3126 | + /* We write RT0-4 */ |
| 3127 | + for (i = 0; i < 4; i++) |
| 3128 | + pso_desc.RTVFormats[i] = (i & 1) ? DXGI_FORMAT_R8G8B8A8_UNORM : DXGI_FORMAT_R8G8B8A8_UINT; |
| 3129 | + /* Test that we can use NULL formats and still use input attachments. |
| 3130 | + * NumRenderTargets must be 8 to read RT4-8 however. */ |
| 3131 | + for (i = 4; i < 8; i++) |
| 3132 | + pso_desc.RTVFormats[i] = DXGI_FORMAT_UNKNOWN; |
| 3133 | + pso_desc.DSVFormat = DXGI_FORMAT_UNKNOWN; |
| 3134 | + pso_desc.DepthStencilState.DepthEnable = FALSE; |
| 3135 | + pso_desc.DepthStencilState.StencilEnable = FALSE; |
| 3136 | + |
| 3137 | + hr = ID3D12Device_CreateGraphicsPipelineState(context.device, &pso_desc, &IID_ID3D12PipelineState, (void **)&read_pso); |
| 3138 | + ok(SUCCEEDED(hr), "Failed to create PSO, hr #%x.\n", hr); |
| 3139 | + |
| 3140 | + color = create_default_texture2d(context.device, 64, 64, 8, 1, |
| 3141 | + DXGI_FORMAT_R8G8B8A8_TYPELESS, |
| 3142 | + D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, |
| 3143 | + D3D12_RESOURCE_STATE_RENDER_TARGET); |
| 3144 | + |
| 3145 | + ds = create_default_texture2d(context.device, 64, 64, 1, 1, |
| 3146 | + DXGI_FORMAT_D32_FLOAT_S8X24_UINT, |
| 3147 | + D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, |
| 3148 | + D3D12_RESOURCE_STATE_DEPTH_WRITE); |
| 3149 | + |
| 3150 | + rtv = create_cpu_descriptor_heap(context.device, D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 8); |
| 3151 | + dsv = create_cpu_descriptor_heap(context.device, D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 3); |
| 3152 | + |
| 3153 | + for (i = 0; i < 8; i++) |
| 3154 | + { |
| 3155 | + rtv_desc.Format = (i & 1) ? DXGI_FORMAT_R8G8B8A8_UNORM : DXGI_FORMAT_R8G8B8A8_UINT; |
| 3156 | + rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY; |
| 3157 | + rtv_desc.Texture2DArray.ArraySize = 1; |
| 3158 | + rtv_desc.Texture2DArray.FirstArraySlice = i; |
| 3159 | + rtv_desc.Texture2DArray.MipSlice = 0; |
| 3160 | + rtv_desc.Texture2DArray.PlaneSlice = 0; |
| 3161 | + |
| 3162 | + /* Input attachments are implicitly created. */ |
| 3163 | + ID3D12Device_CreateRenderTargetView(context.device, color, &rtv_desc, |
| 3164 | + get_cpu_rtv_handle(&context, rtv, i)); |
| 3165 | + } |
| 3166 | + |
| 3167 | + ID3D12Device_CreateDepthStencilView(context.device, ds, NULL, |
| 3168 | + get_cpu_dsv_handle(&context, dsv, 0)); |
| 3169 | + |
| 3170 | + dsv_desc.Format = DXGI_FORMAT_D32_FLOAT_S8X24_UINT; |
| 3171 | + dsv_desc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; |
| 3172 | + dsv_desc.Texture2D.MipSlice = 0; |
| 3173 | + |
| 3174 | + /* Create input attachments. */ |
| 3175 | + dsv_desc.Flags = D3D12_DSV_FLAG_READ_ONLY_DEPTH; |
| 3176 | + ID3D12Device_CreateDepthStencilView(context.device, ds, &dsv_desc, |
| 3177 | + get_cpu_dsv_handle(&context, dsv, 1)); |
| 3178 | + |
| 3179 | + dsv_desc.Flags = D3D12_DSV_FLAG_READ_ONLY_STENCIL; |
| 3180 | + ID3D12Device_CreateDepthStencilView(context.device, ds, &dsv_desc, |
| 3181 | + get_cpu_dsv_handle(&context, dsv, 2)); |
| 3182 | + |
| 3183 | + descs = create_gpu_descriptor_heap(context.device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 10 + |
| 3184 | + ID3D12DeviceExt2_GetInputAttachmentDescriptorsCount(device_ext2)); |
| 3185 | + |
| 3186 | + ID3D12GraphicsCommandList_SetDescriptorHeaps(context.list, 1, &descs); |
| 3187 | + ID3D12GraphicsCommandList_SetGraphicsRootSignature(context.list, context.root_signature); |
| 3188 | + |
| 3189 | + /* These should not actually be read from. */ |
| 3190 | + ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(context.list, 0, |
| 3191 | + get_gpu_descriptor_handle(&context, descs, 0)); |
| 3192 | + |
| 3193 | + /* Write input attachment descriptors to heap. */ |
| 3194 | + { |
| 3195 | + rtvs = get_cpu_rtv_handle(&context, rtv, 0); |
| 3196 | + depth_stencil = get_cpu_dsv_handle(&context, dsv, 0); |
| 3197 | + depth = get_cpu_dsv_handle(&context, dsv, 1); |
| 3198 | + stencil = get_cpu_dsv_handle(&context, dsv, 2); |
| 3199 | + |
| 3200 | + ID3D12DeviceExt2_CreateInputAttachmentDescriptors(device_ext2, 8, &rtvs, TRUE, |
| 3201 | + &depth, &stencil, get_cpu_descriptor_handle(&context, descs, 10)); |
| 3202 | + ID3D12GraphicsCommandListExt2_SetRootSignatureInputAttachments(list_ext2, |
| 3203 | + get_gpu_descriptor_handle(&context, descs, 10)); |
| 3204 | + } |
| 3205 | + |
| 3206 | + set_viewport(&vp, 0, 0, 64, 64, 0, 1); |
| 3207 | + set_rect(&sci, 0, 0, 64, 64); |
| 3208 | + |
| 3209 | + ID3D12GraphicsCommandList_RSSetViewports(context.list, 1, &vp); |
| 3210 | + ID3D12GraphicsCommandList_RSSetScissorRects(context.list, 1, &sci); |
| 3211 | + ID3D12GraphicsCommandList_IASetPrimitiveTopology(context.list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); |
| 3212 | + ID3D12GraphicsCommandList_OMSetStencilRef(context.list, 0x60); |
| 3213 | + ID3D12GraphicsCommandList_OMSetRenderTargets(context.list, 8, &rtvs, TRUE, &depth_stencil); |
| 3214 | + |
| 3215 | + ID3D12GraphicsCommandList_SetPipelineState(context.list, write_pso); |
| 3216 | + ID3D12GraphicsCommandList_DrawInstanced(context.list, 3, 1, 0, 0); |
| 3217 | + |
| 3218 | + ID3D12GraphicsCommandListExt2_InputAttachmentPixelBarrier(list_ext2); |
| 3219 | + |
| 3220 | + ID3D12GraphicsCommandList_SetPipelineState(context.list, read_pso); |
| 3221 | + ID3D12GraphicsCommandList_DrawInstanced(context.list, 3, 1, 0, 0); |
| 3222 | + for (i = 0; i < 4; i++) |
| 3223 | + transition_sub_resource_state(context.list, color, i, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); |
| 3224 | + |
| 3225 | + check_sub_resource_uint(color, 0, context.queue, context.list, 0x04030201 + 0x01010101 + 25 + (0x60 << 8), 0); |
| 3226 | + reset_command_list(context.list, context.allocator); |
| 3227 | + check_sub_resource_uint(color, 1, context.queue, context.list, 0x08070605 + 0x01010101, 0); |
| 3228 | + reset_command_list(context.list, context.allocator); |
| 3229 | + check_sub_resource_uint(color, 2, context.queue, context.list, 0x0c0b0a09 + 0x01010101, 0); |
| 3230 | + reset_command_list(context.list, context.allocator); |
| 3231 | + check_sub_resource_uint(color, 3, context.queue, context.list, 0x100f0e0d + 0x01010101, 0); |
| 3232 | + reset_command_list(context.list, context.allocator); |
| 3233 | + |
| 3234 | + ID3D12Resource_Release(color); |
| 3235 | + ID3D12Resource_Release(ds); |
| 3236 | + ID3D12DescriptorHeap_Release(descs); |
| 3237 | + ID3D12DescriptorHeap_Release(rtv); |
| 3238 | + ID3D12DescriptorHeap_Release(dsv); |
| 3239 | + ID3D12PipelineState_Release(write_pso); |
| 3240 | + ID3D12PipelineState_Release(read_pso); |
| 3241 | + ID3D12GraphicsCommandListExt2_Release(list_ext2); |
| 3242 | + ID3D12DeviceExt2_Release(device_ext2); |
| 3243 | + destroy_test_context(&context); |
| 3244 | +} |
0 commit comments