1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2012-2021 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17bf215546Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
21bf215546Sopenharmony_ci *
22bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
23bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
24bf215546Sopenharmony_ci * of the Software.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/*
29bf215546Sopenharmony_ci * Device.cpp --
30bf215546Sopenharmony_ci *    Functions that provide the 3D device functionality.
31bf215546Sopenharmony_ci */
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "Draw.h"
35bf215546Sopenharmony_ci#include "DxgiFns.h"
36bf215546Sopenharmony_ci#include "InputAssembly.h"
37bf215546Sopenharmony_ci#include "OutputMerger.h"
38bf215546Sopenharmony_ci#include "Query.h"
39bf215546Sopenharmony_ci#include "Rasterizer.h"
40bf215546Sopenharmony_ci#include "Resource.h"
41bf215546Sopenharmony_ci#include "Shader.h"
42bf215546Sopenharmony_ci#include "State.h"
43bf215546Sopenharmony_ci#include "Format.h"
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci#include "Debug.h"
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci#include "util/u_sampler.h"
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_cistatic void APIENTRY DestroyDevice(D3D10DDI_HDEVICE hDevice);
51bf215546Sopenharmony_cistatic void APIENTRY RelocateDeviceFuncs(D3D10DDI_HDEVICE hDevice,
52bf215546Sopenharmony_ci                                __in struct D3D10DDI_DEVICEFUNCS *pDeviceFunctions);
53bf215546Sopenharmony_cistatic void APIENTRY RelocateDeviceFuncs1(D3D10DDI_HDEVICE hDevice,
54bf215546Sopenharmony_ci                                __in struct D3D10_1DDI_DEVICEFUNCS *pDeviceFunctions);
55bf215546Sopenharmony_cistatic void APIENTRY Flush(D3D10DDI_HDEVICE hDevice);
56bf215546Sopenharmony_cistatic void APIENTRY CheckFormatSupport(D3D10DDI_HDEVICE hDevice, DXGI_FORMAT Format,
57bf215546Sopenharmony_ci                               __out UINT *pFormatCaps);
58bf215546Sopenharmony_cistatic void APIENTRY CheckMultisampleQualityLevels(D3D10DDI_HDEVICE hDevice,
59bf215546Sopenharmony_ci                                          DXGI_FORMAT Format,
60bf215546Sopenharmony_ci                                          UINT SampleCount,
61bf215546Sopenharmony_ci                                          __out UINT *pNumQualityLevels);
62bf215546Sopenharmony_cistatic void APIENTRY SetTextFilterSize(D3D10DDI_HDEVICE hDevice, UINT Width, UINT Height);
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci/*
66bf215546Sopenharmony_ci * ----------------------------------------------------------------------
67bf215546Sopenharmony_ci *
68bf215546Sopenharmony_ci * CalcPrivateDeviceSize --
69bf215546Sopenharmony_ci *
70bf215546Sopenharmony_ci *    The CalcPrivateDeviceSize function determines the size of a memory
71bf215546Sopenharmony_ci *    region that the user-mode display driver requires from the Microsoft
72bf215546Sopenharmony_ci *    Direct3D runtime to store frequently-accessed data.
73bf215546Sopenharmony_ci *
74bf215546Sopenharmony_ci * ----------------------------------------------------------------------
75bf215546Sopenharmony_ci */
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ciSIZE_T APIENTRY
78bf215546Sopenharmony_ciCalcPrivateDeviceSize(D3D10DDI_HADAPTER hAdapter,                          // IN
79bf215546Sopenharmony_ci                      __in const D3D10DDIARG_CALCPRIVATEDEVICESIZE *pData) // IN
80bf215546Sopenharmony_ci{
81bf215546Sopenharmony_ci   return sizeof(Device);
82bf215546Sopenharmony_ci}
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci/*
85bf215546Sopenharmony_ci * ----------------------------------------------------------------------
86bf215546Sopenharmony_ci *
87bf215546Sopenharmony_ci * CreateDevice --
88bf215546Sopenharmony_ci *
89bf215546Sopenharmony_ci *    The CreateDevice function creates a graphics context that is
90bf215546Sopenharmony_ci *    referenced in subsequent calls.
91bf215546Sopenharmony_ci *
92bf215546Sopenharmony_ci * ----------------------------------------------------------------------
93bf215546Sopenharmony_ci */
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ciHRESULT APIENTRY
96bf215546Sopenharmony_ciCreateDevice(D3D10DDI_HADAPTER hAdapter,                 // IN
97bf215546Sopenharmony_ci             __in D3D10DDIARG_CREATEDEVICE *pCreateData) // IN
98bf215546Sopenharmony_ci{
99bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci   if (0) {
102bf215546Sopenharmony_ci      DebugPrintf("hAdapter = %p\n", hAdapter);
103bf215546Sopenharmony_ci      DebugPrintf("pKTCallbacks = %p\n", pCreateData->pKTCallbacks);
104bf215546Sopenharmony_ci      DebugPrintf("p10_1DeviceFuncs = %p\n", pCreateData->p10_1DeviceFuncs);
105bf215546Sopenharmony_ci      DebugPrintf("hDrvDevice = %p\n", pCreateData->hDrvDevice);
106bf215546Sopenharmony_ci      DebugPrintf("DXGIBaseDDI = %p\n", pCreateData->DXGIBaseDDI);
107bf215546Sopenharmony_ci      DebugPrintf("hRTCoreLayer = %p\n", pCreateData->hRTCoreLayer);
108bf215546Sopenharmony_ci      DebugPrintf("pUMCallbacks = %p\n", pCreateData->pUMCallbacks);
109bf215546Sopenharmony_ci   }
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci   switch (pCreateData->Interface) {
112bf215546Sopenharmony_ci   case D3D10_0_DDI_INTERFACE_VERSION:
113bf215546Sopenharmony_ci   case D3D10_0_x_DDI_INTERFACE_VERSION:
114bf215546Sopenharmony_ci   case D3D10_0_7_DDI_INTERFACE_VERSION:
115bf215546Sopenharmony_ci#if SUPPORT_D3D10_1
116bf215546Sopenharmony_ci   case D3D10_1_DDI_INTERFACE_VERSION:
117bf215546Sopenharmony_ci   case D3D10_1_x_DDI_INTERFACE_VERSION:
118bf215546Sopenharmony_ci   case D3D10_1_7_DDI_INTERFACE_VERSION:
119bf215546Sopenharmony_ci#endif
120bf215546Sopenharmony_ci      break;
121bf215546Sopenharmony_ci   default:
122bf215546Sopenharmony_ci      DebugPrintf("%s: unsupported interface version 0x%08x\n",
123bf215546Sopenharmony_ci                  __FUNCTION__, pCreateData->Interface);
124bf215546Sopenharmony_ci      return E_FAIL;
125bf215546Sopenharmony_ci   }
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci   Adapter *pAdapter = CastAdapter(hAdapter);
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci   Device *pDevice = CastDevice(pCreateData->hDrvDevice);
130bf215546Sopenharmony_ci   memset(pDevice, 0, sizeof *pDevice);
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci   struct pipe_screen *screen = pAdapter->screen;
133bf215546Sopenharmony_ci   struct pipe_context *pipe = screen->context_create(screen, NULL, 0);
134bf215546Sopenharmony_ci   pDevice->pipe = pipe;
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_ci   pDevice->empty_vs = CreateEmptyShader(pDevice, PIPE_SHADER_VERTEX);
137bf215546Sopenharmony_ci   pDevice->empty_fs = CreateEmptyShader(pDevice, PIPE_SHADER_FRAGMENT);
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci   pipe->bind_vs_state(pipe, pDevice->empty_vs);
140bf215546Sopenharmony_ci   pipe->bind_fs_state(pipe, pDevice->empty_fs);
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci   pDevice->max_dual_source_render_targets =
143bf215546Sopenharmony_ci         screen->get_param(screen, PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS);
144bf215546Sopenharmony_ci
145bf215546Sopenharmony_ci   pDevice->hRTCoreLayer = pCreateData->hRTCoreLayer;
146bf215546Sopenharmony_ci   pDevice->hDevice = (HANDLE)pCreateData->hRTDevice.handle;
147bf215546Sopenharmony_ci   pDevice->KTCallbacks = *pCreateData->pKTCallbacks;
148bf215546Sopenharmony_ci   pDevice->UMCallbacks = *pCreateData->pUMCallbacks;
149bf215546Sopenharmony_ci   pDevice->pDXGIBaseCallbacks = pCreateData->DXGIBaseDDI.pDXGIBaseCallbacks;
150bf215546Sopenharmony_ci
151bf215546Sopenharmony_ci   pDevice->draw_so_target = NULL;
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_ci   if (0) {
154bf215546Sopenharmony_ci      DebugPrintf("pDevice = %p\n", pDevice);
155bf215546Sopenharmony_ci   }
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci   st_debug_parse();
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   /*
160bf215546Sopenharmony_ci    * Fill in the D3D10 DDI functions
161bf215546Sopenharmony_ci    */
162bf215546Sopenharmony_ci   D3D10DDI_DEVICEFUNCS *pDeviceFuncs = pCreateData->pDeviceFuncs;
163bf215546Sopenharmony_ci   pDeviceFuncs->pfnDefaultConstantBufferUpdateSubresourceUP = ResourceUpdateSubResourceUP;
164bf215546Sopenharmony_ci   pDeviceFuncs->pfnVsSetConstantBuffers = VsSetConstantBuffers;
165bf215546Sopenharmony_ci   pDeviceFuncs->pfnPsSetShaderResources = PsSetShaderResources;
166bf215546Sopenharmony_ci   pDeviceFuncs->pfnPsSetShader = PsSetShader;
167bf215546Sopenharmony_ci   pDeviceFuncs->pfnPsSetSamplers = PsSetSamplers;
168bf215546Sopenharmony_ci   pDeviceFuncs->pfnVsSetShader = VsSetShader;
169bf215546Sopenharmony_ci   pDeviceFuncs->pfnDrawIndexed = DrawIndexed;
170bf215546Sopenharmony_ci   pDeviceFuncs->pfnDraw = Draw;
171bf215546Sopenharmony_ci   pDeviceFuncs->pfnDynamicIABufferMapNoOverwrite = ResourceMap;
172bf215546Sopenharmony_ci   pDeviceFuncs->pfnDynamicIABufferUnmap = ResourceUnmap;
173bf215546Sopenharmony_ci   pDeviceFuncs->pfnDynamicConstantBufferMapDiscard = ResourceMap;
174bf215546Sopenharmony_ci   pDeviceFuncs->pfnDynamicIABufferMapDiscard = ResourceMap;
175bf215546Sopenharmony_ci   pDeviceFuncs->pfnDynamicConstantBufferUnmap = ResourceUnmap;
176bf215546Sopenharmony_ci   pDeviceFuncs->pfnPsSetConstantBuffers = PsSetConstantBuffers;
177bf215546Sopenharmony_ci   pDeviceFuncs->pfnIaSetInputLayout = IaSetInputLayout;
178bf215546Sopenharmony_ci   pDeviceFuncs->pfnIaSetVertexBuffers = IaSetVertexBuffers;
179bf215546Sopenharmony_ci   pDeviceFuncs->pfnIaSetIndexBuffer = IaSetIndexBuffer;
180bf215546Sopenharmony_ci   pDeviceFuncs->pfnDrawIndexedInstanced = DrawIndexedInstanced;
181bf215546Sopenharmony_ci   pDeviceFuncs->pfnDrawInstanced = DrawInstanced;
182bf215546Sopenharmony_ci   pDeviceFuncs->pfnDynamicResourceMapDiscard = ResourceMap;
183bf215546Sopenharmony_ci   pDeviceFuncs->pfnDynamicResourceUnmap = ResourceUnmap;
184bf215546Sopenharmony_ci   pDeviceFuncs->pfnGsSetConstantBuffers = GsSetConstantBuffers;
185bf215546Sopenharmony_ci   pDeviceFuncs->pfnGsSetShader = GsSetShader;
186bf215546Sopenharmony_ci   pDeviceFuncs->pfnIaSetTopology = IaSetTopology;
187bf215546Sopenharmony_ci   pDeviceFuncs->pfnStagingResourceMap = ResourceMap;
188bf215546Sopenharmony_ci   pDeviceFuncs->pfnStagingResourceUnmap = ResourceUnmap;
189bf215546Sopenharmony_ci   pDeviceFuncs->pfnVsSetShaderResources = VsSetShaderResources;
190bf215546Sopenharmony_ci   pDeviceFuncs->pfnVsSetSamplers = VsSetSamplers;
191bf215546Sopenharmony_ci   pDeviceFuncs->pfnGsSetShaderResources = GsSetShaderResources;
192bf215546Sopenharmony_ci   pDeviceFuncs->pfnGsSetSamplers = GsSetSamplers;
193bf215546Sopenharmony_ci   pDeviceFuncs->pfnSetRenderTargets = SetRenderTargets;
194bf215546Sopenharmony_ci   pDeviceFuncs->pfnShaderResourceViewReadAfterWriteHazard = ShaderResourceViewReadAfterWriteHazard;
195bf215546Sopenharmony_ci   pDeviceFuncs->pfnResourceReadAfterWriteHazard = ResourceReadAfterWriteHazard;
196bf215546Sopenharmony_ci   pDeviceFuncs->pfnSetBlendState = SetBlendState;
197bf215546Sopenharmony_ci   pDeviceFuncs->pfnSetDepthStencilState = SetDepthStencilState;
198bf215546Sopenharmony_ci   pDeviceFuncs->pfnSetRasterizerState = SetRasterizerState;
199bf215546Sopenharmony_ci   pDeviceFuncs->pfnQueryEnd = QueryEnd;
200bf215546Sopenharmony_ci   pDeviceFuncs->pfnQueryBegin = QueryBegin;
201bf215546Sopenharmony_ci   pDeviceFuncs->pfnResourceCopyRegion = ResourceCopyRegion;
202bf215546Sopenharmony_ci   pDeviceFuncs->pfnResourceUpdateSubresourceUP = ResourceUpdateSubResourceUP;
203bf215546Sopenharmony_ci   pDeviceFuncs->pfnSoSetTargets = SoSetTargets;
204bf215546Sopenharmony_ci   pDeviceFuncs->pfnDrawAuto = DrawAuto;
205bf215546Sopenharmony_ci   pDeviceFuncs->pfnSetViewports = SetViewports;
206bf215546Sopenharmony_ci   pDeviceFuncs->pfnSetScissorRects = SetScissorRects;
207bf215546Sopenharmony_ci   pDeviceFuncs->pfnClearRenderTargetView = ClearRenderTargetView;
208bf215546Sopenharmony_ci   pDeviceFuncs->pfnClearDepthStencilView = ClearDepthStencilView;
209bf215546Sopenharmony_ci   pDeviceFuncs->pfnSetPredication = SetPredication;
210bf215546Sopenharmony_ci   pDeviceFuncs->pfnQueryGetData = QueryGetData;
211bf215546Sopenharmony_ci   pDeviceFuncs->pfnFlush = Flush;
212bf215546Sopenharmony_ci   pDeviceFuncs->pfnGenMips = GenMips;
213bf215546Sopenharmony_ci   pDeviceFuncs->pfnResourceCopy = ResourceCopy;
214bf215546Sopenharmony_ci   pDeviceFuncs->pfnResourceResolveSubresource = ResourceResolveSubResource;
215bf215546Sopenharmony_ci   pDeviceFuncs->pfnResourceMap = ResourceMap;
216bf215546Sopenharmony_ci   pDeviceFuncs->pfnResourceUnmap = ResourceUnmap;
217bf215546Sopenharmony_ci   pDeviceFuncs->pfnResourceIsStagingBusy = ResourceIsStagingBusy;
218bf215546Sopenharmony_ci   pDeviceFuncs->pfnRelocateDeviceFuncs = RelocateDeviceFuncs;
219bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateResourceSize = CalcPrivateResourceSize;
220bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateOpenedResourceSize = CalcPrivateOpenedResourceSize;
221bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateResource = CreateResource;
222bf215546Sopenharmony_ci   pDeviceFuncs->pfnOpenResource = OpenResource;
223bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyResource = DestroyResource;
224bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateShaderResourceViewSize = CalcPrivateShaderResourceViewSize;
225bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateShaderResourceView = CreateShaderResourceView;
226bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyShaderResourceView = DestroyShaderResourceView;
227bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateRenderTargetViewSize = CalcPrivateRenderTargetViewSize;
228bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateRenderTargetView = CreateRenderTargetView;
229bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyRenderTargetView = DestroyRenderTargetView;
230bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateDepthStencilViewSize = CalcPrivateDepthStencilViewSize;
231bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateDepthStencilView = CreateDepthStencilView;
232bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyDepthStencilView = DestroyDepthStencilView;
233bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateElementLayoutSize = CalcPrivateElementLayoutSize;
234bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateElementLayout = CreateElementLayout;
235bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyElementLayout = DestroyElementLayout;
236bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateBlendStateSize = CalcPrivateBlendStateSize;
237bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateBlendState = CreateBlendState;
238bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyBlendState = DestroyBlendState;
239bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateDepthStencilStateSize = CalcPrivateDepthStencilStateSize;
240bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateDepthStencilState = CreateDepthStencilState;
241bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyDepthStencilState = DestroyDepthStencilState;
242bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateRasterizerStateSize = CalcPrivateRasterizerStateSize;
243bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateRasterizerState = CreateRasterizerState;
244bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyRasterizerState = DestroyRasterizerState;
245bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateShaderSize = CalcPrivateShaderSize;
246bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateVertexShader = CreateVertexShader;
247bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateGeometryShader = CreateGeometryShader;
248bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreatePixelShader = CreatePixelShader;
249bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateGeometryShaderWithStreamOutput = CalcPrivateGeometryShaderWithStreamOutput;
250bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateGeometryShaderWithStreamOutput = CreateGeometryShaderWithStreamOutput;
251bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyShader = DestroyShader;
252bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateSamplerSize = CalcPrivateSamplerSize;
253bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateSampler = CreateSampler;
254bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroySampler = DestroySampler;
255bf215546Sopenharmony_ci   pDeviceFuncs->pfnCalcPrivateQuerySize = CalcPrivateQuerySize;
256bf215546Sopenharmony_ci   pDeviceFuncs->pfnCreateQuery = CreateQuery;
257bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyQuery = DestroyQuery;
258bf215546Sopenharmony_ci   pDeviceFuncs->pfnCheckFormatSupport = CheckFormatSupport;
259bf215546Sopenharmony_ci   pDeviceFuncs->pfnCheckMultisampleQualityLevels = CheckMultisampleQualityLevels;
260bf215546Sopenharmony_ci   pDeviceFuncs->pfnCheckCounterInfo = CheckCounterInfo;
261bf215546Sopenharmony_ci   pDeviceFuncs->pfnCheckCounter = CheckCounter;
262bf215546Sopenharmony_ci   pDeviceFuncs->pfnDestroyDevice = DestroyDevice;
263bf215546Sopenharmony_ci   pDeviceFuncs->pfnSetTextFilterSize = SetTextFilterSize;
264bf215546Sopenharmony_ci   if (pCreateData->Interface == D3D10_1_DDI_INTERFACE_VERSION ||
265bf215546Sopenharmony_ci       pCreateData->Interface == D3D10_1_x_DDI_INTERFACE_VERSION ||
266bf215546Sopenharmony_ci       pCreateData->Interface == D3D10_1_7_DDI_INTERFACE_VERSION) {
267bf215546Sopenharmony_ci      D3D10_1DDI_DEVICEFUNCS *p10_1DeviceFuncs = pCreateData->p10_1DeviceFuncs;
268bf215546Sopenharmony_ci      p10_1DeviceFuncs->pfnRelocateDeviceFuncs = RelocateDeviceFuncs1;
269bf215546Sopenharmony_ci      p10_1DeviceFuncs->pfnCalcPrivateShaderResourceViewSize = CalcPrivateShaderResourceViewSize1;
270bf215546Sopenharmony_ci      p10_1DeviceFuncs->pfnCreateShaderResourceView = CreateShaderResourceView1;
271bf215546Sopenharmony_ci      p10_1DeviceFuncs->pfnCalcPrivateBlendStateSize = CalcPrivateBlendStateSize1;
272bf215546Sopenharmony_ci      p10_1DeviceFuncs->pfnCreateBlendState = CreateBlendState1;
273bf215546Sopenharmony_ci      p10_1DeviceFuncs->pfnResourceConvert = ResourceCopy;
274bf215546Sopenharmony_ci      p10_1DeviceFuncs->pfnResourceConvertRegion = ResourceCopyRegion;
275bf215546Sopenharmony_ci   }
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_ci   /*
278bf215546Sopenharmony_ci    * Fill in DXGI DDI functions
279bf215546Sopenharmony_ci    */
280bf215546Sopenharmony_ci   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnPresent =
281bf215546Sopenharmony_ci      _Present;
282bf215546Sopenharmony_ci   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnGetGammaCaps =
283bf215546Sopenharmony_ci      _GetGammaCaps;
284bf215546Sopenharmony_ci   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnSetDisplayMode =
285bf215546Sopenharmony_ci      _SetDisplayMode;
286bf215546Sopenharmony_ci   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnSetResourcePriority =
287bf215546Sopenharmony_ci      _SetResourcePriority;
288bf215546Sopenharmony_ci   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnQueryResourceResidency =
289bf215546Sopenharmony_ci      _QueryResourceResidency;
290bf215546Sopenharmony_ci   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnRotateResourceIdentities =
291bf215546Sopenharmony_ci      _RotateResourceIdentities;
292bf215546Sopenharmony_ci   pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions->pfnBlt =
293bf215546Sopenharmony_ci      _Blt;
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ci   if (0) {
296bf215546Sopenharmony_ci      return S_OK;
297bf215546Sopenharmony_ci   } else {
298bf215546Sopenharmony_ci      // Tell DXGI to not use the shared resource presentation path when
299bf215546Sopenharmony_ci      // communicating with DWM:
300bf215546Sopenharmony_ci      // http://msdn.microsoft.com/en-us/library/windows/hardware/ff569887(v=vs.85).aspx
301bf215546Sopenharmony_ci      return DXGI_STATUS_NO_REDIRECTION;
302bf215546Sopenharmony_ci   }
303bf215546Sopenharmony_ci}
304bf215546Sopenharmony_ci
305bf215546Sopenharmony_ci
306bf215546Sopenharmony_ci/*
307bf215546Sopenharmony_ci * ----------------------------------------------------------------------
308bf215546Sopenharmony_ci *
309bf215546Sopenharmony_ci * DestroyDevice --
310bf215546Sopenharmony_ci *
311bf215546Sopenharmony_ci *    The DestroyDevice function destroys a graphics context.
312bf215546Sopenharmony_ci *
313bf215546Sopenharmony_ci * ----------------------------------------------------------------------
314bf215546Sopenharmony_ci */
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_civoid APIENTRY
317bf215546Sopenharmony_ciDestroyDevice(D3D10DDI_HDEVICE hDevice)   // IN
318bf215546Sopenharmony_ci{
319bf215546Sopenharmony_ci   unsigned i;
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
322bf215546Sopenharmony_ci
323bf215546Sopenharmony_ci   Device *pDevice = CastDevice(hDevice);
324bf215546Sopenharmony_ci   struct pipe_context *pipe = pDevice->pipe;
325bf215546Sopenharmony_ci
326bf215546Sopenharmony_ci   pipe->flush(pipe, NULL, 0);
327bf215546Sopenharmony_ci
328bf215546Sopenharmony_ci   for (i = 0; i < PIPE_MAX_SO_BUFFERS; ++i) {
329bf215546Sopenharmony_ci      pipe_so_target_reference(&pDevice->so_targets[i], NULL);
330bf215546Sopenharmony_ci   }
331bf215546Sopenharmony_ci   if (pDevice->draw_so_target) {
332bf215546Sopenharmony_ci      pipe_so_target_reference(&pDevice->draw_so_target, NULL);
333bf215546Sopenharmony_ci   }
334bf215546Sopenharmony_ci
335bf215546Sopenharmony_ci   pipe->bind_fs_state(pipe, NULL);
336bf215546Sopenharmony_ci   pipe->bind_vs_state(pipe, NULL);
337bf215546Sopenharmony_ci
338bf215546Sopenharmony_ci   DeleteEmptyShader(pDevice, PIPE_SHADER_FRAGMENT, pDevice->empty_fs);
339bf215546Sopenharmony_ci   DeleteEmptyShader(pDevice, PIPE_SHADER_VERTEX, pDevice->empty_vs);
340bf215546Sopenharmony_ci
341bf215546Sopenharmony_ci   pipe_surface_reference(&pDevice->fb.zsbuf, NULL);
342bf215546Sopenharmony_ci   for (i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) {
343bf215546Sopenharmony_ci      pipe_surface_reference(&pDevice->fb.cbufs[i], NULL);
344bf215546Sopenharmony_ci   }
345bf215546Sopenharmony_ci
346bf215546Sopenharmony_ci   for (i = 0; i < PIPE_MAX_ATTRIBS; ++i) {
347bf215546Sopenharmony_ci      if (!pDevice->vertex_buffers[i].is_user_buffer) {
348bf215546Sopenharmony_ci         pipe_resource_reference(&pDevice->vertex_buffers[i].buffer.resource, NULL);
349bf215546Sopenharmony_ci      }
350bf215546Sopenharmony_ci   }
351bf215546Sopenharmony_ci
352bf215546Sopenharmony_ci   pipe_resource_reference(&pDevice->index_buffer, NULL);
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_ci   static struct pipe_sampler_view * sampler_views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
355bf215546Sopenharmony_ci   memset(sampler_views, 0, sizeof sampler_views);
356bf215546Sopenharmony_ci   pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0,
357bf215546Sopenharmony_ci                           PIPE_MAX_SHADER_SAMPLER_VIEWS, 0, false, sampler_views);
358bf215546Sopenharmony_ci   pipe->set_sampler_views(pipe, PIPE_SHADER_VERTEX, 0,
359bf215546Sopenharmony_ci                           PIPE_MAX_SHADER_SAMPLER_VIEWS, 0, false, sampler_views);
360bf215546Sopenharmony_ci   pipe->set_sampler_views(pipe, PIPE_SHADER_GEOMETRY, 0,
361bf215546Sopenharmony_ci                           PIPE_MAX_SHADER_SAMPLER_VIEWS, 0, false, sampler_views);
362bf215546Sopenharmony_ci
363bf215546Sopenharmony_ci   pipe->destroy(pipe);
364bf215546Sopenharmony_ci}
365bf215546Sopenharmony_ci
366bf215546Sopenharmony_ci
367bf215546Sopenharmony_ci/*
368bf215546Sopenharmony_ci * ----------------------------------------------------------------------
369bf215546Sopenharmony_ci *
370bf215546Sopenharmony_ci * RelocateDeviceFuncs --
371bf215546Sopenharmony_ci *
372bf215546Sopenharmony_ci *    The RelocateDeviceFuncs function notifies the user-mode
373bf215546Sopenharmony_ci *    display driver about the new location of the driver function table.
374bf215546Sopenharmony_ci *
375bf215546Sopenharmony_ci * ----------------------------------------------------------------------
376bf215546Sopenharmony_ci */
377bf215546Sopenharmony_ci
378bf215546Sopenharmony_civoid APIENTRY
379bf215546Sopenharmony_ciRelocateDeviceFuncs(D3D10DDI_HDEVICE hDevice,                           // IN
380bf215546Sopenharmony_ci                    __in struct D3D10DDI_DEVICEFUNCS *pDeviceFunctions) // IN
381bf215546Sopenharmony_ci{
382bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
383bf215546Sopenharmony_ci
384bf215546Sopenharmony_ci   /*
385bf215546Sopenharmony_ci    * Nothing to do as we don't store a pointer to this entity.
386bf215546Sopenharmony_ci    */
387bf215546Sopenharmony_ci}
388bf215546Sopenharmony_ci
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_ci/*
391bf215546Sopenharmony_ci * ----------------------------------------------------------------------
392bf215546Sopenharmony_ci *
393bf215546Sopenharmony_ci * RelocateDeviceFuncs1 --
394bf215546Sopenharmony_ci *
395bf215546Sopenharmony_ci *    The RelocateDeviceFuncs function notifies the user-mode
396bf215546Sopenharmony_ci *    display driver about the new location of the driver function table.
397bf215546Sopenharmony_ci *
398bf215546Sopenharmony_ci * ----------------------------------------------------------------------
399bf215546Sopenharmony_ci */
400bf215546Sopenharmony_ci
401bf215546Sopenharmony_civoid APIENTRY
402bf215546Sopenharmony_ciRelocateDeviceFuncs1(D3D10DDI_HDEVICE hDevice,                           // IN
403bf215546Sopenharmony_ci                    __in struct D3D10_1DDI_DEVICEFUNCS *pDeviceFunctions) // IN
404bf215546Sopenharmony_ci{
405bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
406bf215546Sopenharmony_ci
407bf215546Sopenharmony_ci   /*
408bf215546Sopenharmony_ci    * Nothing to do as we don't store a pointer to this entity.
409bf215546Sopenharmony_ci    */
410bf215546Sopenharmony_ci}
411bf215546Sopenharmony_ci
412bf215546Sopenharmony_ci
413bf215546Sopenharmony_ci/*
414bf215546Sopenharmony_ci * ----------------------------------------------------------------------
415bf215546Sopenharmony_ci *
416bf215546Sopenharmony_ci * Flush --
417bf215546Sopenharmony_ci *
418bf215546Sopenharmony_ci *    The Flush function submits outstanding hardware commands that
419bf215546Sopenharmony_ci *    are in the hardware command buffer to the display miniport driver.
420bf215546Sopenharmony_ci *
421bf215546Sopenharmony_ci * ----------------------------------------------------------------------
422bf215546Sopenharmony_ci */
423bf215546Sopenharmony_ci
424bf215546Sopenharmony_civoid APIENTRY
425bf215546Sopenharmony_ciFlush(D3D10DDI_HDEVICE hDevice)  // IN
426bf215546Sopenharmony_ci{
427bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
428bf215546Sopenharmony_ci
429bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ci   pipe->flush(pipe, NULL, 0);
432bf215546Sopenharmony_ci}
433bf215546Sopenharmony_ci
434bf215546Sopenharmony_ci
435bf215546Sopenharmony_ci/*
436bf215546Sopenharmony_ci * ----------------------------------------------------------------------
437bf215546Sopenharmony_ci *
438bf215546Sopenharmony_ci * CheckFormatSupport --
439bf215546Sopenharmony_ci *
440bf215546Sopenharmony_ci *    The CheckFormatSupport function retrieves the capabilites that
441bf215546Sopenharmony_ci *    the device has with the specified format.
442bf215546Sopenharmony_ci *
443bf215546Sopenharmony_ci * ----------------------------------------------------------------------
444bf215546Sopenharmony_ci */
445bf215546Sopenharmony_ci
446bf215546Sopenharmony_civoid APIENTRY
447bf215546Sopenharmony_ciCheckFormatSupport(D3D10DDI_HDEVICE hDevice, // IN
448bf215546Sopenharmony_ci                   DXGI_FORMAT Format,       // IN
449bf215546Sopenharmony_ci                   __out UINT *pFormatCaps)  // OUT
450bf215546Sopenharmony_ci{
451bf215546Sopenharmony_ci   //LOG_ENTRYPOINT();
452bf215546Sopenharmony_ci
453bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
454bf215546Sopenharmony_ci   struct pipe_screen *screen = pipe->screen;
455bf215546Sopenharmony_ci
456bf215546Sopenharmony_ci   *pFormatCaps = 0;
457bf215546Sopenharmony_ci
458bf215546Sopenharmony_ci   enum pipe_format format = FormatTranslate(Format, FALSE);
459bf215546Sopenharmony_ci   if (format == PIPE_FORMAT_NONE) {
460bf215546Sopenharmony_ci      *pFormatCaps = D3D10_DDI_FORMAT_SUPPORT_NOT_SUPPORTED;
461bf215546Sopenharmony_ci      return;
462bf215546Sopenharmony_ci   }
463bf215546Sopenharmony_ci
464bf215546Sopenharmony_ci   if (Format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM) {
465bf215546Sopenharmony_ci      /*
466bf215546Sopenharmony_ci       * We only need to support creation.
467bf215546Sopenharmony_ci       * http://msdn.microsoft.com/en-us/library/windows/hardware/ff552818.aspx
468bf215546Sopenharmony_ci       */
469bf215546Sopenharmony_ci      return;
470bf215546Sopenharmony_ci   }
471bf215546Sopenharmony_ci
472bf215546Sopenharmony_ci   if (screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, 0,
473bf215546Sopenharmony_ci                                   PIPE_BIND_RENDER_TARGET)) {
474bf215546Sopenharmony_ci      *pFormatCaps |= D3D10_DDI_FORMAT_SUPPORT_RENDERTARGET;
475bf215546Sopenharmony_ci      *pFormatCaps |= D3D10_DDI_FORMAT_SUPPORT_BLENDABLE;
476bf215546Sopenharmony_ci
477bf215546Sopenharmony_ci#if SUPPORT_MSAA
478bf215546Sopenharmony_ci      if (screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 4, 4,
479bf215546Sopenharmony_ci                                      PIPE_BIND_RENDER_TARGET)) {
480bf215546Sopenharmony_ci         *pFormatCaps |= D3D10_DDI_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET;
481bf215546Sopenharmony_ci      }
482bf215546Sopenharmony_ci#endif
483bf215546Sopenharmony_ci   }
484bf215546Sopenharmony_ci
485bf215546Sopenharmony_ci   if (screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, 0,
486bf215546Sopenharmony_ci                                   PIPE_BIND_SAMPLER_VIEW)) {
487bf215546Sopenharmony_ci      *pFormatCaps |= D3D10_DDI_FORMAT_SUPPORT_SHADER_SAMPLE;
488bf215546Sopenharmony_ci
489bf215546Sopenharmony_ci#if SUPPORT_MSAA
490bf215546Sopenharmony_ci      if (screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 4, 4,
491bf215546Sopenharmony_ci                                      PIPE_BIND_RENDER_TARGET)) {
492bf215546Sopenharmony_ci         *pFormatCaps |= D3D10_DDI_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
493bf215546Sopenharmony_ci      }
494bf215546Sopenharmony_ci#endif
495bf215546Sopenharmony_ci   }
496bf215546Sopenharmony_ci}
497bf215546Sopenharmony_ci
498bf215546Sopenharmony_ci
499bf215546Sopenharmony_ci/*
500bf215546Sopenharmony_ci * ----------------------------------------------------------------------
501bf215546Sopenharmony_ci *
502bf215546Sopenharmony_ci * CheckMultisampleQualityLevels --
503bf215546Sopenharmony_ci *
504bf215546Sopenharmony_ci *    The CheckMultisampleQualityLevels function retrieves the number
505bf215546Sopenharmony_ci *    of quality levels that the device supports for the specified
506bf215546Sopenharmony_ci *    number of samples.
507bf215546Sopenharmony_ci *
508bf215546Sopenharmony_ci * ----------------------------------------------------------------------
509bf215546Sopenharmony_ci */
510bf215546Sopenharmony_ci
511bf215546Sopenharmony_civoid APIENTRY
512bf215546Sopenharmony_ciCheckMultisampleQualityLevels(D3D10DDI_HDEVICE hDevice,        // IN
513bf215546Sopenharmony_ci                              DXGI_FORMAT Format,              // IN
514bf215546Sopenharmony_ci                              UINT SampleCount,                // IN
515bf215546Sopenharmony_ci                              __out UINT *pNumQualityLevels)   // OUT
516bf215546Sopenharmony_ci{
517bf215546Sopenharmony_ci   //LOG_ENTRYPOINT();
518bf215546Sopenharmony_ci
519bf215546Sopenharmony_ci   /* XXX: Disable MSAA */
520bf215546Sopenharmony_ci   *pNumQualityLevels = 0;
521bf215546Sopenharmony_ci}
522bf215546Sopenharmony_ci
523bf215546Sopenharmony_ci
524bf215546Sopenharmony_ci/*
525bf215546Sopenharmony_ci * ----------------------------------------------------------------------
526bf215546Sopenharmony_ci *
527bf215546Sopenharmony_ci * SetTextFilterSize --
528bf215546Sopenharmony_ci *
529bf215546Sopenharmony_ci *    The SetTextFilterSize function sets the width and height
530bf215546Sopenharmony_ci *    of the monochrome convolution filter.
531bf215546Sopenharmony_ci *
532bf215546Sopenharmony_ci * ----------------------------------------------------------------------
533bf215546Sopenharmony_ci */
534bf215546Sopenharmony_ci
535bf215546Sopenharmony_civoid APIENTRY
536bf215546Sopenharmony_ciSetTextFilterSize(D3D10DDI_HDEVICE hDevice,  // IN
537bf215546Sopenharmony_ci                  UINT Width,                // IN
538bf215546Sopenharmony_ci                  UINT Height)               // IN
539bf215546Sopenharmony_ci{
540bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
541bf215546Sopenharmony_ci
542bf215546Sopenharmony_ci   LOG_UNSUPPORTED(Width != 1 || Height != 1);
543bf215546Sopenharmony_ci}
544