17ec681f3Smrg/*
27ec681f3Smrg * Copyright © Microsoft Corporation
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
217ec681f3Smrg * IN THE SOFTWARE.
227ec681f3Smrg */
237ec681f3Smrg
247ec681f3Smrg#ifndef D3D12_SCREEN_H
257ec681f3Smrg#define D3D12_SCREEN_H
267ec681f3Smrg
277ec681f3Smrg#include "pipe/p_screen.h"
287ec681f3Smrg
297ec681f3Smrg#include "util/slab.h"
307ec681f3Smrg#include "d3d12_descriptor_pool.h"
317ec681f3Smrg
327ec681f3Smrg#ifndef _WIN32
337ec681f3Smrg#include <wsl/winadapter.h>
347ec681f3Smrg#endif
357ec681f3Smrg
367ec681f3Smrg#define D3D12_IGNORE_SDK_LAYERS
377ec681f3Smrg#include <directx/d3d12.h>
387ec681f3Smrg
397ec681f3Smrgstruct pb_manager;
407ec681f3Smrg
417ec681f3Smrgenum resource_dimension
427ec681f3Smrg{
437ec681f3Smrg   RESOURCE_DIMENSION_UNKNOWN = 0,
447ec681f3Smrg   RESOURCE_DIMENSION_BUFFER = 1,
457ec681f3Smrg   RESOURCE_DIMENSION_TEXTURE1D = 2,
467ec681f3Smrg   RESOURCE_DIMENSION_TEXTURE2D = 3,
477ec681f3Smrg   RESOURCE_DIMENSION_TEXTURE2DMS = 4,
487ec681f3Smrg   RESOURCE_DIMENSION_TEXTURE3D = 5,
497ec681f3Smrg   RESOURCE_DIMENSION_TEXTURECUBE = 6,
507ec681f3Smrg   RESOURCE_DIMENSION_TEXTURE1DARRAY = 7,
517ec681f3Smrg   RESOURCE_DIMENSION_TEXTURE2DARRAY = 8,
527ec681f3Smrg   RESOURCE_DIMENSION_TEXTURE2DMSARRAY = 9,
537ec681f3Smrg   RESOURCE_DIMENSION_TEXTURECUBEARRAY = 10,
547ec681f3Smrg   RESOURCE_DIMENSION_COUNT
557ec681f3Smrg};
567ec681f3Smrg
577ec681f3Smrgstruct d3d12_screen {
587ec681f3Smrg   struct pipe_screen base;
597ec681f3Smrg   struct sw_winsys *winsys;
607ec681f3Smrg
617ec681f3Smrg   ID3D12Device *dev;
627ec681f3Smrg   ID3D12CommandQueue *cmdqueue;
637ec681f3Smrg
647ec681f3Smrg   struct slab_parent_pool transfer_pool;
657ec681f3Smrg   struct pb_manager *bufmgr;
667ec681f3Smrg   struct pb_manager *cache_bufmgr;
677ec681f3Smrg   struct pb_manager *slab_bufmgr;
687ec681f3Smrg   struct pb_manager *readback_slab_bufmgr;
697ec681f3Smrg
707ec681f3Smrg   mtx_t descriptor_pool_mutex;
717ec681f3Smrg   struct d3d12_descriptor_pool *rtv_pool;
727ec681f3Smrg   struct d3d12_descriptor_pool *dsv_pool;
737ec681f3Smrg   struct d3d12_descriptor_pool *view_pool;
747ec681f3Smrg
757ec681f3Smrg   struct d3d12_descriptor_handle null_srvs[RESOURCE_DIMENSION_COUNT];
767ec681f3Smrg   struct d3d12_descriptor_handle null_rtv;
777ec681f3Smrg
787ec681f3Smrg   /* capabilities */
797ec681f3Smrg   D3D_FEATURE_LEVEL max_feature_level;
807ec681f3Smrg   D3D12_FEATURE_DATA_ARCHITECTURE architecture;
817ec681f3Smrg   D3D12_FEATURE_DATA_D3D12_OPTIONS opts;
827ec681f3Smrg   D3D12_FEATURE_DATA_D3D12_OPTIONS2 opts2;
837ec681f3Smrg   D3D12_FEATURE_DATA_D3D12_OPTIONS3 opts3;
847ec681f3Smrg   D3D12_FEATURE_DATA_D3D12_OPTIONS4 opts4;
857ec681f3Smrg
867ec681f3Smrg   /* description */
877ec681f3Smrg   uint32_t vendor_id;
887ec681f3Smrg   uint64_t memory_size_megabytes;
897ec681f3Smrg   double timestamp_multiplier;
907ec681f3Smrg   bool have_load_at_vertex;
917ec681f3Smrg};
927ec681f3Smrg
937ec681f3Smrgstatic inline struct d3d12_screen *
947ec681f3Smrgd3d12_screen(struct pipe_screen *pipe)
957ec681f3Smrg{
967ec681f3Smrg   return (struct d3d12_screen *)pipe;
977ec681f3Smrg}
987ec681f3Smrg
997ec681f3Smrgstruct d3d12_dxgi_screen {
1007ec681f3Smrg   struct d3d12_screen base;
1017ec681f3Smrg
1027ec681f3Smrg   struct IDXGIFactory4 *factory;
1037ec681f3Smrg   struct IDXGIAdapter1 *adapter;
1047ec681f3Smrg   wchar_t description[128];
1057ec681f3Smrg};
1067ec681f3Smrg
1077ec681f3Smrgstatic inline struct d3d12_dxgi_screen *
1087ec681f3Smrgd3d12_dxgi_screen(struct d3d12_screen *screen)
1097ec681f3Smrg{
1107ec681f3Smrg   return (struct d3d12_dxgi_screen *)screen;
1117ec681f3Smrg}
1127ec681f3Smrg
1137ec681f3Smrgstruct d3d12_dxcore_screen {
1147ec681f3Smrg   struct d3d12_screen base;
1157ec681f3Smrg
1167ec681f3Smrg   struct IDXCoreAdapterFactory *factory;
1177ec681f3Smrg   struct IDXCoreAdapter *adapter;
1187ec681f3Smrg   char description[256];
1197ec681f3Smrg};
1207ec681f3Smrg
1217ec681f3Smrgstatic inline struct d3d12_dxcore_screen *
1227ec681f3Smrgd3d12_dxcore_screen(struct d3d12_screen *screen)
1237ec681f3Smrg{
1247ec681f3Smrg   return (struct d3d12_dxcore_screen *)screen;
1257ec681f3Smrg}
1267ec681f3Smrg
1277ec681f3Smrgbool
1287ec681f3Smrgd3d12_init_screen(struct d3d12_screen *screen, struct sw_winsys *winsys, IUnknown *adapter);
1297ec681f3Smrg
1307ec681f3Smrg#endif
131