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 * OutputMerger.cpp --
30bf215546Sopenharmony_ci *    Functions that manipulate the output merger state.
31bf215546Sopenharmony_ci */
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "OutputMerger.h"
35bf215546Sopenharmony_ci#include "State.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "Debug.h"
38bf215546Sopenharmony_ci#include "Format.h"
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci#include "util/u_framebuffer.h"
41bf215546Sopenharmony_ci#include "util/format/u_format.h"
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci/*
45bf215546Sopenharmony_ci * ----------------------------------------------------------------------
46bf215546Sopenharmony_ci *
47bf215546Sopenharmony_ci * CalcPrivateRenderTargetViewSize --
48bf215546Sopenharmony_ci *
49bf215546Sopenharmony_ci *    The CalcPrivateRenderTargetViewSize function determines the size
50bf215546Sopenharmony_ci *    of the user-mode display driver's private region of memory
51bf215546Sopenharmony_ci *    (that is, the size of internal driver structures, not the size
52bf215546Sopenharmony_ci *    of the resource video memory) for a render target view.
53bf215546Sopenharmony_ci *
54bf215546Sopenharmony_ci * ----------------------------------------------------------------------
55bf215546Sopenharmony_ci */
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ciSIZE_T APIENTRY
59bf215546Sopenharmony_ciCalcPrivateRenderTargetViewSize(
60bf215546Sopenharmony_ci   D3D10DDI_HDEVICE hDevice,                                               // IN
61bf215546Sopenharmony_ci   __in const D3D10DDIARG_CREATERENDERTARGETVIEW *pCreateRenderTargetView) // IN
62bf215546Sopenharmony_ci{
63bf215546Sopenharmony_ci   return sizeof(RenderTargetView);
64bf215546Sopenharmony_ci}
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci/*
68bf215546Sopenharmony_ci * ----------------------------------------------------------------------
69bf215546Sopenharmony_ci *
70bf215546Sopenharmony_ci * CreateRenderTargetView --
71bf215546Sopenharmony_ci *
72bf215546Sopenharmony_ci *    The CreateRenderTargetView function creates a render target view.
73bf215546Sopenharmony_ci *
74bf215546Sopenharmony_ci * ----------------------------------------------------------------------
75bf215546Sopenharmony_ci */
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_civoid APIENTRY
78bf215546Sopenharmony_ciCreateRenderTargetView(
79bf215546Sopenharmony_ci   D3D10DDI_HDEVICE hDevice,                                               // IN
80bf215546Sopenharmony_ci   __in const D3D10DDIARG_CREATERENDERTARGETVIEW *pCreateRenderTargetView, // IN
81bf215546Sopenharmony_ci   D3D10DDI_HRENDERTARGETVIEW hRenderTargetView,                           // IN
82bf215546Sopenharmony_ci   D3D10DDI_HRTRENDERTARGETVIEW hRTRenderTargetView)                       // IN
83bf215546Sopenharmony_ci{
84bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
87bf215546Sopenharmony_ci   struct pipe_resource *resource = CastPipeResource(pCreateRenderTargetView->hDrvResource);
88bf215546Sopenharmony_ci   RenderTargetView *pRTView = CastRenderTargetView(hRenderTargetView);
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci   struct pipe_surface desc;
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci   memset(&desc, 0, sizeof desc);
93bf215546Sopenharmony_ci   desc.format = FormatTranslate(pCreateRenderTargetView->Format, FALSE);
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   switch (pCreateRenderTargetView->ResourceDimension) {
96bf215546Sopenharmony_ci   case D3D10DDIRESOURCE_BUFFER:
97bf215546Sopenharmony_ci      desc.u.buf.first_element = pCreateRenderTargetView->Buffer.FirstElement;
98bf215546Sopenharmony_ci      desc.u.buf.last_element = pCreateRenderTargetView->Buffer.NumElements - 1 +
99bf215546Sopenharmony_ci                                   desc.u.buf.first_element;
100bf215546Sopenharmony_ci      break;
101bf215546Sopenharmony_ci   case D3D10DDIRESOURCE_TEXTURE1D:
102bf215546Sopenharmony_ci      ASSERT(pCreateRenderTargetView->Tex1D.ArraySize != (UINT)-1);
103bf215546Sopenharmony_ci      desc.u.tex.level = pCreateRenderTargetView->Tex1D.MipSlice;
104bf215546Sopenharmony_ci      desc.u.tex.first_layer = pCreateRenderTargetView->Tex1D.FirstArraySlice;
105bf215546Sopenharmony_ci      desc.u.tex.last_layer = pCreateRenderTargetView->Tex1D.ArraySize - 1 +
106bf215546Sopenharmony_ci                                 desc.u.tex.first_layer;
107bf215546Sopenharmony_ci      break;
108bf215546Sopenharmony_ci   case D3D10DDIRESOURCE_TEXTURE2D:
109bf215546Sopenharmony_ci      ASSERT(pCreateRenderTargetView->Tex2D.ArraySize != (UINT)-1);
110bf215546Sopenharmony_ci      desc.u.tex.level = pCreateRenderTargetView->Tex2D.MipSlice;
111bf215546Sopenharmony_ci      desc.u.tex.first_layer = pCreateRenderTargetView->Tex2D.FirstArraySlice;
112bf215546Sopenharmony_ci      desc.u.tex.last_layer = pCreateRenderTargetView->Tex2D.ArraySize - 1 +
113bf215546Sopenharmony_ci                                 desc.u.tex.first_layer;
114bf215546Sopenharmony_ci      break;
115bf215546Sopenharmony_ci   case D3D10DDIRESOURCE_TEXTURE3D:
116bf215546Sopenharmony_ci      desc.u.tex.level = pCreateRenderTargetView->Tex3D.MipSlice;
117bf215546Sopenharmony_ci      desc.u.tex.first_layer = pCreateRenderTargetView->Tex3D.FirstW;
118bf215546Sopenharmony_ci      desc.u.tex.last_layer = pCreateRenderTargetView->Tex3D.WSize - 1 +
119bf215546Sopenharmony_ci                                 desc.u.tex.first_layer;
120bf215546Sopenharmony_ci      break;
121bf215546Sopenharmony_ci   case D3D10DDIRESOURCE_TEXTURECUBE:
122bf215546Sopenharmony_ci      ASSERT(pCreateRenderTargetView->TexCube.ArraySize != (UINT)-1);
123bf215546Sopenharmony_ci      desc.u.tex.level = pCreateRenderTargetView->TexCube.MipSlice;
124bf215546Sopenharmony_ci      desc.u.tex.first_layer = pCreateRenderTargetView->TexCube.FirstArraySlice;
125bf215546Sopenharmony_ci      desc.u.tex.last_layer = pCreateRenderTargetView->TexCube.ArraySize - 1 +
126bf215546Sopenharmony_ci                                 desc.u.tex.first_layer;;
127bf215546Sopenharmony_ci      break;
128bf215546Sopenharmony_ci   default:
129bf215546Sopenharmony_ci      ASSERT(0);
130bf215546Sopenharmony_ci      return;
131bf215546Sopenharmony_ci   }
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci   pRTView->surface = pipe->create_surface(pipe, resource, &desc);
134bf215546Sopenharmony_ci   assert(pRTView->surface);
135bf215546Sopenharmony_ci}
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci/*
139bf215546Sopenharmony_ci * ----------------------------------------------------------------------
140bf215546Sopenharmony_ci *
141bf215546Sopenharmony_ci * DestroyRenderTargetView --
142bf215546Sopenharmony_ci *
143bf215546Sopenharmony_ci *    The DestroyRenderTargetView function destroys the specified
144bf215546Sopenharmony_ci *    render target view object. The render target view object can
145bf215546Sopenharmony_ci *    be destoyed only if it is not currently bound to a display device.
146bf215546Sopenharmony_ci *
147bf215546Sopenharmony_ci * ----------------------------------------------------------------------
148bf215546Sopenharmony_ci */
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_civoid APIENTRY
151bf215546Sopenharmony_ciDestroyRenderTargetView(D3D10DDI_HDEVICE hDevice,                       // IN
152bf215546Sopenharmony_ci                        D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)   // IN
153bf215546Sopenharmony_ci{
154bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci   RenderTargetView *pRTView = CastRenderTargetView(hRenderTargetView);
157bf215546Sopenharmony_ci
158bf215546Sopenharmony_ci   pipe_surface_reference(&pRTView->surface, NULL);
159bf215546Sopenharmony_ci}
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_ci/*
163bf215546Sopenharmony_ci * ----------------------------------------------------------------------
164bf215546Sopenharmony_ci *
165bf215546Sopenharmony_ci * ClearRenderTargetView --
166bf215546Sopenharmony_ci *
167bf215546Sopenharmony_ci *    The ClearRenderTargetView function clears the specified
168bf215546Sopenharmony_ci *    render target view by setting it to a constant value.
169bf215546Sopenharmony_ci *
170bf215546Sopenharmony_ci * ----------------------------------------------------------------------
171bf215546Sopenharmony_ci */
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_civoid APIENTRY
174bf215546Sopenharmony_ciClearRenderTargetView(D3D10DDI_HDEVICE hDevice,                      // IN
175bf215546Sopenharmony_ci                      D3D10DDI_HRENDERTARGETVIEW hRenderTargetView,  // IN
176bf215546Sopenharmony_ci                      FLOAT pColorRGBA[4])                           // IN
177bf215546Sopenharmony_ci{
178bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
181bf215546Sopenharmony_ci   struct pipe_surface *surface = CastPipeRenderTargetView(hRenderTargetView);
182bf215546Sopenharmony_ci   union pipe_color_union clear_color;
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci   /*
185bf215546Sopenharmony_ci    * DX10 always uses float clear color but gallium does not.
186bf215546Sopenharmony_ci    * Conversion should just be ordinary conversion. Actual clamping will
187bf215546Sopenharmony_ci    * be done later but need to make sure values exceeding int/uint range
188bf215546Sopenharmony_ci    * are handled correctly.
189bf215546Sopenharmony_ci    */
190bf215546Sopenharmony_ci   if (util_format_is_pure_integer(surface->format)) {
191bf215546Sopenharmony_ci      if (util_format_is_pure_sint(surface->format)) {
192bf215546Sopenharmony_ci         unsigned i;
193bf215546Sopenharmony_ci         /* If only MIN_INT/UINT32 in c++ code would work... */
194bf215546Sopenharmony_ci         int min_int32 = 0x80000000;
195bf215546Sopenharmony_ci         int max_int32 = 0x7fffffff;
196bf215546Sopenharmony_ci         for (i = 0; i < 4; i++) {
197bf215546Sopenharmony_ci            float value = pColorRGBA[i];
198bf215546Sopenharmony_ci            /* This is an expanded clamp to handle NaN and integer conversion. */
199bf215546Sopenharmony_ci            if (util_is_nan(value)) {
200bf215546Sopenharmony_ci               clear_color.i[i] = 0;
201bf215546Sopenharmony_ci            } else if (value <= (float)min_int32) {
202bf215546Sopenharmony_ci               clear_color.i[i] = min_int32;
203bf215546Sopenharmony_ci            } else if (value >= (float)max_int32) {
204bf215546Sopenharmony_ci               clear_color.i[i] = max_int32;
205bf215546Sopenharmony_ci            } else {
206bf215546Sopenharmony_ci               clear_color.i[i] = value;
207bf215546Sopenharmony_ci            }
208bf215546Sopenharmony_ci         }
209bf215546Sopenharmony_ci      }
210bf215546Sopenharmony_ci      else {
211bf215546Sopenharmony_ci         assert(util_format_is_pure_uint(surface->format));
212bf215546Sopenharmony_ci         unsigned i;
213bf215546Sopenharmony_ci         unsigned max_uint32 = 0xffffffffU;
214bf215546Sopenharmony_ci         for (i = 0; i < 4; i++) {
215bf215546Sopenharmony_ci            float value = pColorRGBA[i];
216bf215546Sopenharmony_ci            /* This is an expanded clamp to handle NaN and integer conversion. */
217bf215546Sopenharmony_ci            if (!(value >= 0.0f)) {
218bf215546Sopenharmony_ci               /* Handles NaN. */
219bf215546Sopenharmony_ci               clear_color.ui[i] = 0;
220bf215546Sopenharmony_ci            } else if (value >= (float)max_uint32) {
221bf215546Sopenharmony_ci               clear_color.ui[i] = max_uint32;
222bf215546Sopenharmony_ci            } else {
223bf215546Sopenharmony_ci               clear_color.ui[i] = value;
224bf215546Sopenharmony_ci            }
225bf215546Sopenharmony_ci         }
226bf215546Sopenharmony_ci      }
227bf215546Sopenharmony_ci   }
228bf215546Sopenharmony_ci   else {
229bf215546Sopenharmony_ci      clear_color.f[0] = pColorRGBA[0];
230bf215546Sopenharmony_ci      clear_color.f[1] = pColorRGBA[1];
231bf215546Sopenharmony_ci      clear_color.f[2] = pColorRGBA[2];
232bf215546Sopenharmony_ci      clear_color.f[3] = pColorRGBA[3];
233bf215546Sopenharmony_ci   }
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_ci   pipe->clear_render_target(pipe,
236bf215546Sopenharmony_ci                             surface,
237bf215546Sopenharmony_ci                             &clear_color,
238bf215546Sopenharmony_ci                             0, 0,
239bf215546Sopenharmony_ci                             surface->width,
240bf215546Sopenharmony_ci                             surface->height,
241bf215546Sopenharmony_ci                             TRUE);
242bf215546Sopenharmony_ci}
243bf215546Sopenharmony_ci
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ci/*
246bf215546Sopenharmony_ci * ----------------------------------------------------------------------
247bf215546Sopenharmony_ci *
248bf215546Sopenharmony_ci * CalcPrivateDepthStencilViewSize --
249bf215546Sopenharmony_ci *
250bf215546Sopenharmony_ci *    The CalcPrivateDepthStencilViewSize function determines the size
251bf215546Sopenharmony_ci *    of the user-mode display driver's private region of memory
252bf215546Sopenharmony_ci *    (that is, the size of internal driver structures, not the size
253bf215546Sopenharmony_ci *    of the resource video memory) for a depth stencil view.
254bf215546Sopenharmony_ci *
255bf215546Sopenharmony_ci * ----------------------------------------------------------------------
256bf215546Sopenharmony_ci */
257bf215546Sopenharmony_ci
258bf215546Sopenharmony_ciSIZE_T APIENTRY
259bf215546Sopenharmony_ciCalcPrivateDepthStencilViewSize(
260bf215546Sopenharmony_ci   D3D10DDI_HDEVICE hDevice,                                               // IN
261bf215546Sopenharmony_ci   __in const D3D10DDIARG_CREATEDEPTHSTENCILVIEW *pCreateDepthStencilView) // IN
262bf215546Sopenharmony_ci{
263bf215546Sopenharmony_ci   return sizeof(DepthStencilView);
264bf215546Sopenharmony_ci}
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci
267bf215546Sopenharmony_ci/*
268bf215546Sopenharmony_ci * ----------------------------------------------------------------------
269bf215546Sopenharmony_ci *
270bf215546Sopenharmony_ci * CreateDepthStencilView --
271bf215546Sopenharmony_ci *
272bf215546Sopenharmony_ci *    The CreateDepthStencilView function creates a depth stencil view.
273bf215546Sopenharmony_ci *
274bf215546Sopenharmony_ci * ----------------------------------------------------------------------
275bf215546Sopenharmony_ci */
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_civoid APIENTRY
278bf215546Sopenharmony_ciCreateDepthStencilView(
279bf215546Sopenharmony_ci   D3D10DDI_HDEVICE hDevice,                                               // IN
280bf215546Sopenharmony_ci   __in const D3D10DDIARG_CREATEDEPTHSTENCILVIEW *pCreateDepthStencilView, // IN
281bf215546Sopenharmony_ci   D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView,                           // IN
282bf215546Sopenharmony_ci   D3D10DDI_HRTDEPTHSTENCILVIEW hRTDepthStencilView)                       // IN
283bf215546Sopenharmony_ci{
284bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
285bf215546Sopenharmony_ci
286bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
287bf215546Sopenharmony_ci   struct pipe_resource *resource = CastPipeResource(pCreateDepthStencilView->hDrvResource);
288bf215546Sopenharmony_ci   DepthStencilView *pDSView = CastDepthStencilView(hDepthStencilView);
289bf215546Sopenharmony_ci
290bf215546Sopenharmony_ci   struct pipe_surface desc;
291bf215546Sopenharmony_ci
292bf215546Sopenharmony_ci   memset(&desc, 0, sizeof desc);
293bf215546Sopenharmony_ci   desc.format = FormatTranslate(pCreateDepthStencilView->Format, TRUE);
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ci   switch (pCreateDepthStencilView->ResourceDimension) {
296bf215546Sopenharmony_ci   case D3D10DDIRESOURCE_TEXTURE1D:
297bf215546Sopenharmony_ci      ASSERT(pCreateDepthStencilView->Tex1D.ArraySize != (UINT)-1);
298bf215546Sopenharmony_ci      desc.u.tex.level = pCreateDepthStencilView->Tex1D.MipSlice;
299bf215546Sopenharmony_ci      desc.u.tex.first_layer = pCreateDepthStencilView->Tex1D.FirstArraySlice;
300bf215546Sopenharmony_ci      desc.u.tex.last_layer = pCreateDepthStencilView->Tex1D.ArraySize - 1 +
301bf215546Sopenharmony_ci                                 desc.u.tex.first_layer;
302bf215546Sopenharmony_ci      break;
303bf215546Sopenharmony_ci   case D3D10DDIRESOURCE_TEXTURE2D:
304bf215546Sopenharmony_ci      ASSERT(pCreateDepthStencilView->Tex2D.ArraySize != (UINT)-1);
305bf215546Sopenharmony_ci      desc.u.tex.level = pCreateDepthStencilView->Tex2D.MipSlice;
306bf215546Sopenharmony_ci      desc.u.tex.first_layer = pCreateDepthStencilView->Tex2D.FirstArraySlice;
307bf215546Sopenharmony_ci      desc.u.tex.last_layer = pCreateDepthStencilView->Tex2D.ArraySize - 1 +
308bf215546Sopenharmony_ci                                 desc.u.tex.first_layer;
309bf215546Sopenharmony_ci      break;
310bf215546Sopenharmony_ci   case D3D10DDIRESOURCE_TEXTURECUBE:
311bf215546Sopenharmony_ci      ASSERT(pCreateDepthStencilView->TexCube.ArraySize != (UINT)-1);
312bf215546Sopenharmony_ci      desc.u.tex.level = pCreateDepthStencilView->TexCube.MipSlice;
313bf215546Sopenharmony_ci      desc.u.tex.first_layer = pCreateDepthStencilView->TexCube.FirstArraySlice;
314bf215546Sopenharmony_ci      desc.u.tex.last_layer = pCreateDepthStencilView->TexCube.ArraySize - 1 +
315bf215546Sopenharmony_ci                                 desc.u.tex.first_layer;
316bf215546Sopenharmony_ci      break;
317bf215546Sopenharmony_ci   default:
318bf215546Sopenharmony_ci      ASSERT(0);
319bf215546Sopenharmony_ci      return;
320bf215546Sopenharmony_ci   }
321bf215546Sopenharmony_ci
322bf215546Sopenharmony_ci   pDSView->surface = pipe->create_surface(pipe, resource, &desc);
323bf215546Sopenharmony_ci   assert(pDSView->surface);
324bf215546Sopenharmony_ci}
325bf215546Sopenharmony_ci
326bf215546Sopenharmony_ci
327bf215546Sopenharmony_ci/*
328bf215546Sopenharmony_ci * ----------------------------------------------------------------------
329bf215546Sopenharmony_ci *
330bf215546Sopenharmony_ci * DestroyDepthStencilView --
331bf215546Sopenharmony_ci *
332bf215546Sopenharmony_ci *    The DestroyDepthStencilView function destroys the specified
333bf215546Sopenharmony_ci *    depth stencil view object. The depth stencil view object can
334bf215546Sopenharmony_ci *    be destoyed only if it is not currently bound to a display device.
335bf215546Sopenharmony_ci *
336bf215546Sopenharmony_ci * ----------------------------------------------------------------------
337bf215546Sopenharmony_ci */
338bf215546Sopenharmony_ci
339bf215546Sopenharmony_civoid APIENTRY
340bf215546Sopenharmony_ciDestroyDepthStencilView(D3D10DDI_HDEVICE hDevice,                       // IN
341bf215546Sopenharmony_ci                        D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)   // IN
342bf215546Sopenharmony_ci{
343bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
344bf215546Sopenharmony_ci
345bf215546Sopenharmony_ci   DepthStencilView *pDSView = CastDepthStencilView(hDepthStencilView);
346bf215546Sopenharmony_ci
347bf215546Sopenharmony_ci   pipe_surface_reference(&pDSView->surface, NULL);
348bf215546Sopenharmony_ci}
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci
351bf215546Sopenharmony_ci/*
352bf215546Sopenharmony_ci * ----------------------------------------------------------------------
353bf215546Sopenharmony_ci *
354bf215546Sopenharmony_ci * ClearDepthStencilView --
355bf215546Sopenharmony_ci *
356bf215546Sopenharmony_ci *    The ClearDepthStencilView function clears the specified
357bf215546Sopenharmony_ci *    currently bound depth-stencil view.
358bf215546Sopenharmony_ci *
359bf215546Sopenharmony_ci * ----------------------------------------------------------------------
360bf215546Sopenharmony_ci */
361bf215546Sopenharmony_ci
362bf215546Sopenharmony_civoid APIENTRY
363bf215546Sopenharmony_ciClearDepthStencilView(D3D10DDI_HDEVICE hDevice,                      // IN
364bf215546Sopenharmony_ci                      D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView,  // IN
365bf215546Sopenharmony_ci                      UINT Flags,                                    // IN
366bf215546Sopenharmony_ci                      FLOAT Depth,                                   // IN
367bf215546Sopenharmony_ci                      UINT8 Stencil)                                 // IN
368bf215546Sopenharmony_ci{
369bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
370bf215546Sopenharmony_ci
371bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
372bf215546Sopenharmony_ci   struct pipe_surface *surface = CastPipeDepthStencilView(hDepthStencilView);
373bf215546Sopenharmony_ci
374bf215546Sopenharmony_ci   unsigned flags = 0;
375bf215546Sopenharmony_ci   if (Flags & D3D10_DDI_CLEAR_DEPTH) {
376bf215546Sopenharmony_ci      flags |= PIPE_CLEAR_DEPTH;
377bf215546Sopenharmony_ci   }
378bf215546Sopenharmony_ci   if (Flags & D3D10_DDI_CLEAR_STENCIL) {
379bf215546Sopenharmony_ci      flags |= PIPE_CLEAR_STENCIL;
380bf215546Sopenharmony_ci   }
381bf215546Sopenharmony_ci
382bf215546Sopenharmony_ci   pipe->clear_depth_stencil(pipe,
383bf215546Sopenharmony_ci                             surface,
384bf215546Sopenharmony_ci                             flags,
385bf215546Sopenharmony_ci                             Depth,
386bf215546Sopenharmony_ci                             Stencil,
387bf215546Sopenharmony_ci                             0, 0,
388bf215546Sopenharmony_ci                             surface->width,
389bf215546Sopenharmony_ci                             surface->height,
390bf215546Sopenharmony_ci                             TRUE);
391bf215546Sopenharmony_ci}
392bf215546Sopenharmony_ci
393bf215546Sopenharmony_ci
394bf215546Sopenharmony_ci/*
395bf215546Sopenharmony_ci * ----------------------------------------------------------------------
396bf215546Sopenharmony_ci *
397bf215546Sopenharmony_ci * CalcPrivateBlendStateSize --
398bf215546Sopenharmony_ci *
399bf215546Sopenharmony_ci *    The CalcPrivateBlendStateSize function determines the size of
400bf215546Sopenharmony_ci *    the user-mode display driver's private region of memory (that
401bf215546Sopenharmony_ci *    is, the size of internal driver structures, not the size of
402bf215546Sopenharmony_ci *    the resource video memory) for a blend state.
403bf215546Sopenharmony_ci *
404bf215546Sopenharmony_ci * ----------------------------------------------------------------------
405bf215546Sopenharmony_ci */
406bf215546Sopenharmony_ci
407bf215546Sopenharmony_ciSIZE_T APIENTRY
408bf215546Sopenharmony_ciCalcPrivateBlendStateSize(D3D10DDI_HDEVICE hDevice,                     // IN
409bf215546Sopenharmony_ci                          __in const D3D10_DDI_BLEND_DESC *pBlendDesc)  // IN
410bf215546Sopenharmony_ci{
411bf215546Sopenharmony_ci   return sizeof(BlendState);
412bf215546Sopenharmony_ci}
413bf215546Sopenharmony_ci
414bf215546Sopenharmony_ci
415bf215546Sopenharmony_ci/*
416bf215546Sopenharmony_ci * ----------------------------------------------------------------------
417bf215546Sopenharmony_ci *
418bf215546Sopenharmony_ci * CalcPrivateBlendStateSize1 --
419bf215546Sopenharmony_ci *
420bf215546Sopenharmony_ci *    The CalcPrivateBlendStateSize function determines the size of
421bf215546Sopenharmony_ci *    the user-mode display driver's private region of memory (that
422bf215546Sopenharmony_ci *    is, the size of internal driver structures, not the size of
423bf215546Sopenharmony_ci *    the resource video memory) for a blend state.
424bf215546Sopenharmony_ci *
425bf215546Sopenharmony_ci * ----------------------------------------------------------------------
426bf215546Sopenharmony_ci */
427bf215546Sopenharmony_ci
428bf215546Sopenharmony_ciSIZE_T APIENTRY
429bf215546Sopenharmony_ciCalcPrivateBlendStateSize1(D3D10DDI_HDEVICE hDevice,                     // IN
430bf215546Sopenharmony_ci                           __in const D3D10_1_DDI_BLEND_DESC *pBlendDesc)  // IN
431bf215546Sopenharmony_ci{
432bf215546Sopenharmony_ci   return sizeof(BlendState);
433bf215546Sopenharmony_ci}
434bf215546Sopenharmony_ci
435bf215546Sopenharmony_ci
436bf215546Sopenharmony_ci/*
437bf215546Sopenharmony_ci * ----------------------------------------------------------------------
438bf215546Sopenharmony_ci *
439bf215546Sopenharmony_ci * translateBlend --
440bf215546Sopenharmony_ci *
441bf215546Sopenharmony_ci *   Translate blend function from svga3d to gallium representation.
442bf215546Sopenharmony_ci *
443bf215546Sopenharmony_ci * ----------------------------------------------------------------------
444bf215546Sopenharmony_ci */
445bf215546Sopenharmony_cistatic uint
446bf215546Sopenharmony_citranslateBlendOp(D3D10_DDI_BLEND_OP op)
447bf215546Sopenharmony_ci{
448bf215546Sopenharmony_ci   switch (op) {
449bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_OP_ADD:
450bf215546Sopenharmony_ci      return PIPE_BLEND_ADD;
451bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_OP_SUBTRACT:
452bf215546Sopenharmony_ci      return PIPE_BLEND_SUBTRACT;
453bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_OP_REV_SUBTRACT:
454bf215546Sopenharmony_ci      return PIPE_BLEND_REVERSE_SUBTRACT;
455bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_OP_MIN:
456bf215546Sopenharmony_ci      return PIPE_BLEND_MIN;
457bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_OP_MAX:
458bf215546Sopenharmony_ci      return PIPE_BLEND_MAX;
459bf215546Sopenharmony_ci   default:
460bf215546Sopenharmony_ci      assert(0);
461bf215546Sopenharmony_ci      return PIPE_BLEND_ADD;
462bf215546Sopenharmony_ci   }
463bf215546Sopenharmony_ci}
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci
466bf215546Sopenharmony_ci/*
467bf215546Sopenharmony_ci * ----------------------------------------------------------------------
468bf215546Sopenharmony_ci *
469bf215546Sopenharmony_ci * translateBlend --
470bf215546Sopenharmony_ci *
471bf215546Sopenharmony_ci *   Translate blend factor from svga3d to gallium representation.
472bf215546Sopenharmony_ci *
473bf215546Sopenharmony_ci * ----------------------------------------------------------------------
474bf215546Sopenharmony_ci */
475bf215546Sopenharmony_cistatic uint
476bf215546Sopenharmony_citranslateBlend(Device *pDevice,
477bf215546Sopenharmony_ci               D3D10_DDI_BLEND blend)
478bf215546Sopenharmony_ci{
479bf215546Sopenharmony_ci   if (!pDevice->max_dual_source_render_targets) {
480bf215546Sopenharmony_ci      switch (blend) {
481bf215546Sopenharmony_ci      case D3D10_DDI_BLEND_SRC1_COLOR:
482bf215546Sopenharmony_ci      case D3D10_DDI_BLEND_SRC1_ALPHA:
483bf215546Sopenharmony_ci         LOG_UNSUPPORTED(TRUE);
484bf215546Sopenharmony_ci         return D3D10_DDI_BLEND_ZERO;
485bf215546Sopenharmony_ci      case D3D10_DDI_BLEND_INV_SRC1_COLOR:
486bf215546Sopenharmony_ci      case D3D10_DDI_BLEND_INV_SRC1_ALPHA:
487bf215546Sopenharmony_ci         LOG_UNSUPPORTED(TRUE);
488bf215546Sopenharmony_ci         return D3D10_DDI_BLEND_ONE;
489bf215546Sopenharmony_ci      default:
490bf215546Sopenharmony_ci         break;
491bf215546Sopenharmony_ci      }
492bf215546Sopenharmony_ci   }
493bf215546Sopenharmony_ci
494bf215546Sopenharmony_ci   switch (blend) {
495bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_ZERO:
496bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_ZERO;
497bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_ONE:
498bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_ONE;
499bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_SRC_COLOR:
500bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_SRC_COLOR;
501bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_INV_SRC_COLOR:
502bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_INV_SRC_COLOR;
503bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_SRC_ALPHA:
504bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_SRC_ALPHA;
505bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_INV_SRC_ALPHA:
506bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
507bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_DEST_ALPHA:
508bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_DST_ALPHA;
509bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_INV_DEST_ALPHA:
510bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_INV_DST_ALPHA;
511bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_DEST_COLOR:
512bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_DST_COLOR;
513bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_INV_DEST_COLOR:
514bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_INV_DST_COLOR;
515bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_SRC_ALPHASAT:
516bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
517bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_BLEND_FACTOR:
518bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_CONST_COLOR;
519bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_INVBLEND_FACTOR:
520bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_INV_CONST_COLOR;
521bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_SRC1_COLOR:
522bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_SRC1_COLOR;
523bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_INV_SRC1_COLOR:
524bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_INV_SRC1_COLOR;
525bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_SRC1_ALPHA:
526bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_SRC1_ALPHA;
527bf215546Sopenharmony_ci   case D3D10_DDI_BLEND_INV_SRC1_ALPHA:
528bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_INV_SRC1_ALPHA;
529bf215546Sopenharmony_ci   default:
530bf215546Sopenharmony_ci      assert(0);
531bf215546Sopenharmony_ci      return PIPE_BLENDFACTOR_ONE;
532bf215546Sopenharmony_ci   }
533bf215546Sopenharmony_ci}
534bf215546Sopenharmony_ci
535bf215546Sopenharmony_ci
536bf215546Sopenharmony_ci/*
537bf215546Sopenharmony_ci * ----------------------------------------------------------------------
538bf215546Sopenharmony_ci *
539bf215546Sopenharmony_ci * CreateBlendState --
540bf215546Sopenharmony_ci *
541bf215546Sopenharmony_ci *    The CreateBlendState function creates a blend state.
542bf215546Sopenharmony_ci *
543bf215546Sopenharmony_ci * ----------------------------------------------------------------------
544bf215546Sopenharmony_ci */
545bf215546Sopenharmony_ci
546bf215546Sopenharmony_civoid APIENTRY
547bf215546Sopenharmony_ciCreateBlendState(D3D10DDI_HDEVICE hDevice,                     // IN
548bf215546Sopenharmony_ci                 __in const D3D10_DDI_BLEND_DESC *pBlendDesc,  // IN
549bf215546Sopenharmony_ci                 D3D10DDI_HBLENDSTATE hBlendState,             // IN
550bf215546Sopenharmony_ci                 D3D10DDI_HRTBLENDSTATE hRTBlendState)         // IN
551bf215546Sopenharmony_ci{
552bf215546Sopenharmony_ci   unsigned i;
553bf215546Sopenharmony_ci
554bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
555bf215546Sopenharmony_ci
556bf215546Sopenharmony_ci   Device *pDevice = CastDevice(hDevice);
557bf215546Sopenharmony_ci   struct pipe_context *pipe = pDevice->pipe;
558bf215546Sopenharmony_ci   BlendState *pBlendState = CastBlendState(hBlendState);
559bf215546Sopenharmony_ci
560bf215546Sopenharmony_ci   struct pipe_blend_state state;
561bf215546Sopenharmony_ci   memset(&state, 0, sizeof state);
562bf215546Sopenharmony_ci
563bf215546Sopenharmony_ci   for (i = 0; i < MIN2(PIPE_MAX_COLOR_BUFS, D3D10_DDI_SIMULTANEOUS_RENDER_TARGET_COUNT); ++i) {
564bf215546Sopenharmony_ci      state.rt[i].blend_enable = pBlendDesc->BlendEnable[i];
565bf215546Sopenharmony_ci      state.rt[i].colormask = pBlendDesc->RenderTargetWriteMask[i];
566bf215546Sopenharmony_ci
567bf215546Sopenharmony_ci      if (pBlendDesc->BlendEnable[0] != pBlendDesc->BlendEnable[i] ||
568bf215546Sopenharmony_ci          pBlendDesc->RenderTargetWriteMask[0] != pBlendDesc->RenderTargetWriteMask[i]) {
569bf215546Sopenharmony_ci         state.independent_blend_enable = 1;
570bf215546Sopenharmony_ci      }
571bf215546Sopenharmony_ci   }
572bf215546Sopenharmony_ci
573bf215546Sopenharmony_ci   state.rt[0].rgb_func = translateBlendOp(pBlendDesc->BlendOp);
574bf215546Sopenharmony_ci   if (pBlendDesc->BlendOp == D3D10_DDI_BLEND_OP_MIN ||
575bf215546Sopenharmony_ci       pBlendDesc->BlendOp == D3D10_DDI_BLEND_OP_MAX) {
576bf215546Sopenharmony_ci      state.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
577bf215546Sopenharmony_ci      state.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
578bf215546Sopenharmony_ci   } else {
579bf215546Sopenharmony_ci      state.rt[0].rgb_src_factor = translateBlend(pDevice, pBlendDesc->SrcBlend);
580bf215546Sopenharmony_ci      state.rt[0].rgb_dst_factor = translateBlend(pDevice, pBlendDesc->DestBlend);
581bf215546Sopenharmony_ci   }
582bf215546Sopenharmony_ci
583bf215546Sopenharmony_ci   state.rt[0].alpha_func = translateBlendOp(pBlendDesc->BlendOpAlpha);
584bf215546Sopenharmony_ci   if (pBlendDesc->BlendOpAlpha == D3D10_DDI_BLEND_OP_MIN ||
585bf215546Sopenharmony_ci       pBlendDesc->BlendOpAlpha == D3D10_DDI_BLEND_OP_MAX) {
586bf215546Sopenharmony_ci      state.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
587bf215546Sopenharmony_ci      state.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
588bf215546Sopenharmony_ci   } else {
589bf215546Sopenharmony_ci      state.rt[0].alpha_src_factor = translateBlend(pDevice, pBlendDesc->SrcBlendAlpha);
590bf215546Sopenharmony_ci      state.rt[0].alpha_dst_factor = translateBlend(pDevice, pBlendDesc->DestBlendAlpha);
591bf215546Sopenharmony_ci   }
592bf215546Sopenharmony_ci
593bf215546Sopenharmony_ci   /*
594bf215546Sopenharmony_ci    * Propagate to all the other rendertargets
595bf215546Sopenharmony_ci    */
596bf215546Sopenharmony_ci   for (i = 1; i < MIN2(PIPE_MAX_COLOR_BUFS, D3D10_DDI_SIMULTANEOUS_RENDER_TARGET_COUNT); ++i) {
597bf215546Sopenharmony_ci      state.rt[i].rgb_func = state.rt[0].rgb_func;
598bf215546Sopenharmony_ci      state.rt[i].rgb_src_factor = state.rt[0].rgb_src_factor;
599bf215546Sopenharmony_ci      state.rt[i].rgb_dst_factor = state.rt[0].rgb_dst_factor;
600bf215546Sopenharmony_ci      state.rt[i].alpha_func = state.rt[0].alpha_func;
601bf215546Sopenharmony_ci      state.rt[i].alpha_src_factor = state.rt[0].alpha_src_factor;
602bf215546Sopenharmony_ci      state.rt[i].alpha_dst_factor = state.rt[0].alpha_dst_factor;
603bf215546Sopenharmony_ci   }
604bf215546Sopenharmony_ci
605bf215546Sopenharmony_ci   state.alpha_to_coverage = pBlendDesc->AlphaToCoverageEnable;
606bf215546Sopenharmony_ci
607bf215546Sopenharmony_ci   pBlendState->handle = pipe->create_blend_state(pipe, &state);
608bf215546Sopenharmony_ci}
609bf215546Sopenharmony_ci
610bf215546Sopenharmony_ci
611bf215546Sopenharmony_ci/*
612bf215546Sopenharmony_ci * ----------------------------------------------------------------------
613bf215546Sopenharmony_ci *
614bf215546Sopenharmony_ci * CreateBlendState1 --
615bf215546Sopenharmony_ci *
616bf215546Sopenharmony_ci *    The CreateBlendState function creates a blend state.
617bf215546Sopenharmony_ci *
618bf215546Sopenharmony_ci * ----------------------------------------------------------------------
619bf215546Sopenharmony_ci */
620bf215546Sopenharmony_ci
621bf215546Sopenharmony_civoid APIENTRY
622bf215546Sopenharmony_ciCreateBlendState1(D3D10DDI_HDEVICE hDevice,                     // IN
623bf215546Sopenharmony_ci                  __in const D3D10_1_DDI_BLEND_DESC *pBlendDesc,  // IN
624bf215546Sopenharmony_ci                  D3D10DDI_HBLENDSTATE hBlendState,             // IN
625bf215546Sopenharmony_ci                  D3D10DDI_HRTBLENDSTATE hRTBlendState)         // IN
626bf215546Sopenharmony_ci{
627bf215546Sopenharmony_ci   unsigned i;
628bf215546Sopenharmony_ci
629bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
630bf215546Sopenharmony_ci
631bf215546Sopenharmony_ci   Device *pDevice = CastDevice(hDevice);
632bf215546Sopenharmony_ci   struct pipe_context *pipe = pDevice->pipe;
633bf215546Sopenharmony_ci   BlendState *pBlendState = CastBlendState(hBlendState);
634bf215546Sopenharmony_ci
635bf215546Sopenharmony_ci   struct pipe_blend_state state;
636bf215546Sopenharmony_ci   memset(&state, 0, sizeof state);
637bf215546Sopenharmony_ci
638bf215546Sopenharmony_ci   state.alpha_to_coverage = pBlendDesc->AlphaToCoverageEnable;
639bf215546Sopenharmony_ci   state.independent_blend_enable = pBlendDesc->IndependentBlendEnable;
640bf215546Sopenharmony_ci
641bf215546Sopenharmony_ci   for (i = 0; i < MIN2(PIPE_MAX_COLOR_BUFS, D3D10_DDI_SIMULTANEOUS_RENDER_TARGET_COUNT); ++i) {
642bf215546Sopenharmony_ci      state.rt[i].blend_enable = pBlendDesc->RenderTarget[i].BlendEnable;
643bf215546Sopenharmony_ci      state.rt[i].colormask = pBlendDesc->RenderTarget[i].RenderTargetWriteMask;
644bf215546Sopenharmony_ci
645bf215546Sopenharmony_ci      state.rt[i].rgb_func = translateBlendOp(pBlendDesc->RenderTarget[i].BlendOp);
646bf215546Sopenharmony_ci      if (pBlendDesc->RenderTarget[i].BlendOp == D3D10_DDI_BLEND_OP_MIN ||
647bf215546Sopenharmony_ci          pBlendDesc->RenderTarget[i].BlendOp == D3D10_DDI_BLEND_OP_MAX) {
648bf215546Sopenharmony_ci         state.rt[i].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
649bf215546Sopenharmony_ci         state.rt[i].rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
650bf215546Sopenharmony_ci      } else {
651bf215546Sopenharmony_ci         state.rt[i].rgb_src_factor = translateBlend(pDevice, pBlendDesc->RenderTarget[i].SrcBlend);
652bf215546Sopenharmony_ci         state.rt[i].rgb_dst_factor = translateBlend(pDevice, pBlendDesc->RenderTarget[i].DestBlend);
653bf215546Sopenharmony_ci      }
654bf215546Sopenharmony_ci
655bf215546Sopenharmony_ci      state.rt[i].alpha_func = translateBlendOp(pBlendDesc->RenderTarget[i].BlendOpAlpha);
656bf215546Sopenharmony_ci      if (pBlendDesc->RenderTarget[i].BlendOpAlpha == D3D10_DDI_BLEND_OP_MIN ||
657bf215546Sopenharmony_ci          pBlendDesc->RenderTarget[i].BlendOpAlpha == D3D10_DDI_BLEND_OP_MAX) {
658bf215546Sopenharmony_ci         state.rt[i].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
659bf215546Sopenharmony_ci         state.rt[i].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
660bf215546Sopenharmony_ci      } else {
661bf215546Sopenharmony_ci         state.rt[i].alpha_src_factor = translateBlend(pDevice, pBlendDesc->RenderTarget[i].SrcBlendAlpha);
662bf215546Sopenharmony_ci         state.rt[i].alpha_dst_factor = translateBlend(pDevice, pBlendDesc->RenderTarget[i].DestBlendAlpha);
663bf215546Sopenharmony_ci      }
664bf215546Sopenharmony_ci   }
665bf215546Sopenharmony_ci
666bf215546Sopenharmony_ci   pBlendState->handle = pipe->create_blend_state(pipe, &state);
667bf215546Sopenharmony_ci}
668bf215546Sopenharmony_ci
669bf215546Sopenharmony_ci
670bf215546Sopenharmony_ci/*
671bf215546Sopenharmony_ci * ----------------------------------------------------------------------
672bf215546Sopenharmony_ci *
673bf215546Sopenharmony_ci * DestroyBlendState --
674bf215546Sopenharmony_ci *
675bf215546Sopenharmony_ci *    The DestroyBlendState function destroys the specified blend
676bf215546Sopenharmony_ci *    state object. The blend state object can be destoyed only if
677bf215546Sopenharmony_ci *    it is not currently bound to a display device.
678bf215546Sopenharmony_ci *
679bf215546Sopenharmony_ci * ----------------------------------------------------------------------
680bf215546Sopenharmony_ci */
681bf215546Sopenharmony_ci
682bf215546Sopenharmony_civoid APIENTRY
683bf215546Sopenharmony_ciDestroyBlendState(D3D10DDI_HDEVICE hDevice,           // IN
684bf215546Sopenharmony_ci                  D3D10DDI_HBLENDSTATE hBlendState)   // IN
685bf215546Sopenharmony_ci{
686bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
687bf215546Sopenharmony_ci
688bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
689bf215546Sopenharmony_ci   BlendState *pBlendState = CastBlendState(hBlendState);
690bf215546Sopenharmony_ci
691bf215546Sopenharmony_ci   pipe->delete_blend_state(pipe, pBlendState->handle);
692bf215546Sopenharmony_ci}
693bf215546Sopenharmony_ci
694bf215546Sopenharmony_ci
695bf215546Sopenharmony_ci/*
696bf215546Sopenharmony_ci * ----------------------------------------------------------------------
697bf215546Sopenharmony_ci *
698bf215546Sopenharmony_ci * SetBlendState --
699bf215546Sopenharmony_ci *
700bf215546Sopenharmony_ci *    The SetBlendState function sets a blend state.
701bf215546Sopenharmony_ci *
702bf215546Sopenharmony_ci * ----------------------------------------------------------------------
703bf215546Sopenharmony_ci */
704bf215546Sopenharmony_ci
705bf215546Sopenharmony_civoid APIENTRY
706bf215546Sopenharmony_ciSetBlendState(D3D10DDI_HDEVICE hDevice,      // IN
707bf215546Sopenharmony_ci              D3D10DDI_HBLENDSTATE hState,   // IN
708bf215546Sopenharmony_ci              const FLOAT pBlendFactor[4],   // IN
709bf215546Sopenharmony_ci              UINT SampleMask)               // IN
710bf215546Sopenharmony_ci{
711bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
712bf215546Sopenharmony_ci
713bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
714bf215546Sopenharmony_ci   void *state = CastPipeBlendState(hState);
715bf215546Sopenharmony_ci
716bf215546Sopenharmony_ci   pipe->bind_blend_state(pipe, state);
717bf215546Sopenharmony_ci
718bf215546Sopenharmony_ci   struct pipe_blend_color color;
719bf215546Sopenharmony_ci   color.color[0] = pBlendFactor[0];
720bf215546Sopenharmony_ci   color.color[1] = pBlendFactor[1];
721bf215546Sopenharmony_ci   color.color[2] = pBlendFactor[2];
722bf215546Sopenharmony_ci   color.color[3] = pBlendFactor[3];
723bf215546Sopenharmony_ci
724bf215546Sopenharmony_ci   pipe->set_blend_color(pipe, &color);
725bf215546Sopenharmony_ci
726bf215546Sopenharmony_ci   pipe->set_sample_mask(pipe, SampleMask);
727bf215546Sopenharmony_ci}
728bf215546Sopenharmony_ci
729bf215546Sopenharmony_ci
730bf215546Sopenharmony_ci/*
731bf215546Sopenharmony_ci * ----------------------------------------------------------------------
732bf215546Sopenharmony_ci *
733bf215546Sopenharmony_ci * SetRenderTargets --
734bf215546Sopenharmony_ci *
735bf215546Sopenharmony_ci *    Set the rendertargets.
736bf215546Sopenharmony_ci *
737bf215546Sopenharmony_ci * ----------------------------------------------------------------------
738bf215546Sopenharmony_ci */
739bf215546Sopenharmony_ci
740bf215546Sopenharmony_civoid APIENTRY
741bf215546Sopenharmony_ciSetRenderTargets(D3D10DDI_HDEVICE hDevice,                              // IN
742bf215546Sopenharmony_ci                 __in_ecount (NumViews)
743bf215546Sopenharmony_ci                  const D3D10DDI_HRENDERTARGETVIEW *phRenderTargetView, // IN
744bf215546Sopenharmony_ci                 UINT RTargets,                                         // IN
745bf215546Sopenharmony_ci                 UINT ClearTargets,                                     // IN
746bf215546Sopenharmony_ci                 D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)          // IN
747bf215546Sopenharmony_ci{
748bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
749bf215546Sopenharmony_ci
750bf215546Sopenharmony_ci   Device *pDevice = CastDevice(hDevice);
751bf215546Sopenharmony_ci
752bf215546Sopenharmony_ci   struct pipe_context *pipe = pDevice->pipe;
753bf215546Sopenharmony_ci
754bf215546Sopenharmony_ci   pDevice->fb.nr_cbufs = 0;
755bf215546Sopenharmony_ci   for (unsigned i = 0; i < RTargets; ++i) {
756bf215546Sopenharmony_ci      pipe_surface_reference(&pDevice->fb.cbufs[i],
757bf215546Sopenharmony_ci                             CastPipeRenderTargetView(phRenderTargetView[i]));
758bf215546Sopenharmony_ci      if (pDevice->fb.cbufs[i]) {
759bf215546Sopenharmony_ci         pDevice->fb.nr_cbufs = i + 1;
760bf215546Sopenharmony_ci      }
761bf215546Sopenharmony_ci   }
762bf215546Sopenharmony_ci
763bf215546Sopenharmony_ci   for (unsigned i = RTargets; i < PIPE_MAX_COLOR_BUFS; ++i) {
764bf215546Sopenharmony_ci      pipe_surface_reference(&pDevice->fb.cbufs[i], NULL);
765bf215546Sopenharmony_ci   }
766bf215546Sopenharmony_ci
767bf215546Sopenharmony_ci   pipe_surface_reference(&pDevice->fb.zsbuf,
768bf215546Sopenharmony_ci                          CastPipeDepthStencilView(hDepthStencilView));
769bf215546Sopenharmony_ci
770bf215546Sopenharmony_ci   /*
771bf215546Sopenharmony_ci    * Calculate the width/height fields for this framebuffer.  D3D10
772bf215546Sopenharmony_ci    * actually specifies that they be identical for all bound views.
773bf215546Sopenharmony_ci    */
774bf215546Sopenharmony_ci   unsigned width, height;
775bf215546Sopenharmony_ci   util_framebuffer_min_size(&pDevice->fb, &width, &height);
776bf215546Sopenharmony_ci   pDevice->fb.width = width;
777bf215546Sopenharmony_ci   pDevice->fb.height = height;
778bf215546Sopenharmony_ci
779bf215546Sopenharmony_ci   pipe->set_framebuffer_state(pipe, &pDevice->fb);
780bf215546Sopenharmony_ci}
781bf215546Sopenharmony_ci
782bf215546Sopenharmony_ci
783bf215546Sopenharmony_ci/*
784bf215546Sopenharmony_ci * ----------------------------------------------------------------------
785bf215546Sopenharmony_ci *
786bf215546Sopenharmony_ci * CalcPrivateDepthStencilStateSize --
787bf215546Sopenharmony_ci *
788bf215546Sopenharmony_ci *    The CalcPrivateDepthStencilStateSize function determines the size
789bf215546Sopenharmony_ci *    of the user-mode display driver's private region of memory (that
790bf215546Sopenharmony_ci *    is, the size of internal driver structures, not the size of the
791bf215546Sopenharmony_ci *    resource video memory) for a depth stencil state.
792bf215546Sopenharmony_ci *
793bf215546Sopenharmony_ci * ----------------------------------------------------------------------
794bf215546Sopenharmony_ci */
795bf215546Sopenharmony_ci
796bf215546Sopenharmony_ciSIZE_T APIENTRY
797bf215546Sopenharmony_ciCalcPrivateDepthStencilStateSize(
798bf215546Sopenharmony_ci   D3D10DDI_HDEVICE hDevice,                                   // IN
799bf215546Sopenharmony_ci   __in const D3D10_DDI_DEPTH_STENCIL_DESC *pDepthStencilDesc) // IN
800bf215546Sopenharmony_ci{
801bf215546Sopenharmony_ci   return sizeof(DepthStencilState);
802bf215546Sopenharmony_ci}
803bf215546Sopenharmony_ci
804bf215546Sopenharmony_ci
805bf215546Sopenharmony_ci/*
806bf215546Sopenharmony_ci * ----------------------------------------------------------------------
807bf215546Sopenharmony_ci *
808bf215546Sopenharmony_ci * translateComparison --
809bf215546Sopenharmony_ci *
810bf215546Sopenharmony_ci *   Translate comparison function from DX10 to gallium representation.
811bf215546Sopenharmony_ci *
812bf215546Sopenharmony_ci * ----------------------------------------------------------------------
813bf215546Sopenharmony_ci */
814bf215546Sopenharmony_cistatic uint
815bf215546Sopenharmony_citranslateComparison(D3D10_DDI_COMPARISON_FUNC Func)
816bf215546Sopenharmony_ci{
817bf215546Sopenharmony_ci   switch (Func) {
818bf215546Sopenharmony_ci   case D3D10_DDI_COMPARISON_NEVER:
819bf215546Sopenharmony_ci      return PIPE_FUNC_NEVER;
820bf215546Sopenharmony_ci   case D3D10_DDI_COMPARISON_LESS:
821bf215546Sopenharmony_ci      return PIPE_FUNC_LESS;
822bf215546Sopenharmony_ci   case D3D10_DDI_COMPARISON_EQUAL:
823bf215546Sopenharmony_ci      return PIPE_FUNC_EQUAL;
824bf215546Sopenharmony_ci   case D3D10_DDI_COMPARISON_LESS_EQUAL:
825bf215546Sopenharmony_ci      return PIPE_FUNC_LEQUAL;
826bf215546Sopenharmony_ci   case D3D10_DDI_COMPARISON_GREATER:
827bf215546Sopenharmony_ci      return PIPE_FUNC_GREATER;
828bf215546Sopenharmony_ci   case D3D10_DDI_COMPARISON_NOT_EQUAL:
829bf215546Sopenharmony_ci      return PIPE_FUNC_NOTEQUAL;
830bf215546Sopenharmony_ci   case D3D10_DDI_COMPARISON_GREATER_EQUAL:
831bf215546Sopenharmony_ci      return PIPE_FUNC_GEQUAL;
832bf215546Sopenharmony_ci   case D3D10_DDI_COMPARISON_ALWAYS:
833bf215546Sopenharmony_ci      return PIPE_FUNC_ALWAYS;
834bf215546Sopenharmony_ci   default:
835bf215546Sopenharmony_ci      assert(0);
836bf215546Sopenharmony_ci      return PIPE_FUNC_ALWAYS;
837bf215546Sopenharmony_ci   }
838bf215546Sopenharmony_ci}
839bf215546Sopenharmony_ci
840bf215546Sopenharmony_ci
841bf215546Sopenharmony_ci/*
842bf215546Sopenharmony_ci * ----------------------------------------------------------------------
843bf215546Sopenharmony_ci *
844bf215546Sopenharmony_ci * translateStencilOp --
845bf215546Sopenharmony_ci *
846bf215546Sopenharmony_ci *   Translate stencil op from DX10 to gallium representation.
847bf215546Sopenharmony_ci *
848bf215546Sopenharmony_ci * ----------------------------------------------------------------------
849bf215546Sopenharmony_ci */
850bf215546Sopenharmony_cistatic uint
851bf215546Sopenharmony_citranslateStencilOp(D3D10_DDI_STENCIL_OP StencilOp)
852bf215546Sopenharmony_ci{
853bf215546Sopenharmony_ci   switch (StencilOp) {
854bf215546Sopenharmony_ci   case D3D10_DDI_STENCIL_OP_KEEP:
855bf215546Sopenharmony_ci      return PIPE_STENCIL_OP_KEEP;
856bf215546Sopenharmony_ci   case D3D10_DDI_STENCIL_OP_ZERO:
857bf215546Sopenharmony_ci      return PIPE_STENCIL_OP_ZERO;
858bf215546Sopenharmony_ci   case D3D10_DDI_STENCIL_OP_REPLACE:
859bf215546Sopenharmony_ci      return PIPE_STENCIL_OP_REPLACE;
860bf215546Sopenharmony_ci   case D3D10_DDI_STENCIL_OP_INCR_SAT:
861bf215546Sopenharmony_ci      return PIPE_STENCIL_OP_INCR;
862bf215546Sopenharmony_ci   case D3D10_DDI_STENCIL_OP_DECR_SAT:
863bf215546Sopenharmony_ci      return PIPE_STENCIL_OP_DECR;
864bf215546Sopenharmony_ci   case D3D10_DDI_STENCIL_OP_INVERT:
865bf215546Sopenharmony_ci      return PIPE_STENCIL_OP_INVERT;
866bf215546Sopenharmony_ci   case D3D10_DDI_STENCIL_OP_INCR:
867bf215546Sopenharmony_ci      return PIPE_STENCIL_OP_INCR_WRAP;
868bf215546Sopenharmony_ci   case D3D10_DDI_STENCIL_OP_DECR:
869bf215546Sopenharmony_ci      return PIPE_STENCIL_OP_DECR_WRAP;
870bf215546Sopenharmony_ci   default:
871bf215546Sopenharmony_ci      assert(0);
872bf215546Sopenharmony_ci      return PIPE_STENCIL_OP_KEEP;
873bf215546Sopenharmony_ci   }
874bf215546Sopenharmony_ci}
875bf215546Sopenharmony_ci
876bf215546Sopenharmony_ci
877bf215546Sopenharmony_ci/*
878bf215546Sopenharmony_ci * ----------------------------------------------------------------------
879bf215546Sopenharmony_ci *
880bf215546Sopenharmony_ci * CreateDepthStencilState --
881bf215546Sopenharmony_ci *
882bf215546Sopenharmony_ci *    The CreateDepthStencilState function creates a depth stencil state.
883bf215546Sopenharmony_ci *
884bf215546Sopenharmony_ci * ----------------------------------------------------------------------
885bf215546Sopenharmony_ci */
886bf215546Sopenharmony_ci
887bf215546Sopenharmony_civoid APIENTRY
888bf215546Sopenharmony_ciCreateDepthStencilState(
889bf215546Sopenharmony_ci   D3D10DDI_HDEVICE hDevice,                                   // IN
890bf215546Sopenharmony_ci   __in const D3D10_DDI_DEPTH_STENCIL_DESC *pDepthStencilDesc, // IN
891bf215546Sopenharmony_ci   D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState,             // IN
892bf215546Sopenharmony_ci   D3D10DDI_HRTDEPTHSTENCILSTATE hRTDepthStencilState)         // IN
893bf215546Sopenharmony_ci{
894bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
895bf215546Sopenharmony_ci
896bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
897bf215546Sopenharmony_ci   DepthStencilState *pDepthStencilState = CastDepthStencilState(hDepthStencilState);
898bf215546Sopenharmony_ci
899bf215546Sopenharmony_ci   struct pipe_depth_stencil_alpha_state state;
900bf215546Sopenharmony_ci   memset(&state, 0, sizeof state);
901bf215546Sopenharmony_ci
902bf215546Sopenharmony_ci   /* Depth. */
903bf215546Sopenharmony_ci   state.depth_enabled = (pDepthStencilDesc->DepthEnable ? 1 : 0);
904bf215546Sopenharmony_ci   state.depth_writemask = (pDepthStencilDesc->DepthWriteMask ? 1 : 0);
905bf215546Sopenharmony_ci   state.depth_func = translateComparison(pDepthStencilDesc->DepthFunc);
906bf215546Sopenharmony_ci
907bf215546Sopenharmony_ci   /* Stencil. */
908bf215546Sopenharmony_ci   if (pDepthStencilDesc->StencilEnable) {
909bf215546Sopenharmony_ci      struct pipe_stencil_state *face0 = &state.stencil[0];
910bf215546Sopenharmony_ci      struct pipe_stencil_state *face1 = &state.stencil[1];
911bf215546Sopenharmony_ci
912bf215546Sopenharmony_ci      face0->enabled   = 1;
913bf215546Sopenharmony_ci      face0->func      = translateComparison(pDepthStencilDesc->FrontFace.StencilFunc);
914bf215546Sopenharmony_ci      face0->fail_op   = translateStencilOp(pDepthStencilDesc->FrontFace.StencilFailOp);
915bf215546Sopenharmony_ci      face0->zpass_op  = translateStencilOp(pDepthStencilDesc->FrontFace.StencilPassOp);
916bf215546Sopenharmony_ci      face0->zfail_op  = translateStencilOp(pDepthStencilDesc->FrontFace.StencilDepthFailOp);
917bf215546Sopenharmony_ci      face0->valuemask = pDepthStencilDesc->StencilReadMask;
918bf215546Sopenharmony_ci      face0->writemask = pDepthStencilDesc->StencilWriteMask;
919bf215546Sopenharmony_ci
920bf215546Sopenharmony_ci      face1->enabled   = 1;
921bf215546Sopenharmony_ci      face1->func      = translateComparison(pDepthStencilDesc->BackFace.StencilFunc);
922bf215546Sopenharmony_ci      face1->fail_op   = translateStencilOp(pDepthStencilDesc->BackFace.StencilFailOp);
923bf215546Sopenharmony_ci      face1->zpass_op  = translateStencilOp(pDepthStencilDesc->BackFace.StencilPassOp);
924bf215546Sopenharmony_ci      face1->zfail_op  = translateStencilOp(pDepthStencilDesc->BackFace.StencilDepthFailOp);
925bf215546Sopenharmony_ci      face1->valuemask = pDepthStencilDesc->StencilReadMask;
926bf215546Sopenharmony_ci      face1->writemask = pDepthStencilDesc->StencilWriteMask;
927bf215546Sopenharmony_ci#ifdef DEBUG
928bf215546Sopenharmony_ci      if (!pDepthStencilDesc->FrontEnable) {
929bf215546Sopenharmony_ci         ASSERT(face0->func == PIPE_FUNC_ALWAYS);
930bf215546Sopenharmony_ci         ASSERT(face0->fail_op == PIPE_STENCIL_OP_KEEP);
931bf215546Sopenharmony_ci         ASSERT(face0->zpass_op == PIPE_STENCIL_OP_KEEP);
932bf215546Sopenharmony_ci         ASSERT(face0->zfail_op == PIPE_STENCIL_OP_KEEP);
933bf215546Sopenharmony_ci      }
934bf215546Sopenharmony_ci
935bf215546Sopenharmony_ci      if (!pDepthStencilDesc->BackEnable) {
936bf215546Sopenharmony_ci         ASSERT(face1->func == PIPE_FUNC_ALWAYS);
937bf215546Sopenharmony_ci         ASSERT(face1->fail_op == PIPE_STENCIL_OP_KEEP);
938bf215546Sopenharmony_ci         ASSERT(face1->zpass_op == PIPE_STENCIL_OP_KEEP);
939bf215546Sopenharmony_ci         ASSERT(face1->zfail_op == PIPE_STENCIL_OP_KEEP);
940bf215546Sopenharmony_ci      }
941bf215546Sopenharmony_ci#endif
942bf215546Sopenharmony_ci   }
943bf215546Sopenharmony_ci
944bf215546Sopenharmony_ci   pDepthStencilState->handle =
945bf215546Sopenharmony_ci      pipe->create_depth_stencil_alpha_state(pipe, &state);
946bf215546Sopenharmony_ci}
947bf215546Sopenharmony_ci
948bf215546Sopenharmony_ci
949bf215546Sopenharmony_ci/*
950bf215546Sopenharmony_ci * ----------------------------------------------------------------------
951bf215546Sopenharmony_ci *
952bf215546Sopenharmony_ci * DestroyDepthStencilState --
953bf215546Sopenharmony_ci *
954bf215546Sopenharmony_ci *    The CreateDepthStencilState function creates a depth stencil state.
955bf215546Sopenharmony_ci *
956bf215546Sopenharmony_ci * ----------------------------------------------------------------------
957bf215546Sopenharmony_ci */
958bf215546Sopenharmony_ci
959bf215546Sopenharmony_civoid APIENTRY
960bf215546Sopenharmony_ciDestroyDepthStencilState(D3D10DDI_HDEVICE hDevice,                         // IN
961bf215546Sopenharmony_ci                         D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)   // IN
962bf215546Sopenharmony_ci{
963bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
964bf215546Sopenharmony_ci
965bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
966bf215546Sopenharmony_ci   DepthStencilState *pDepthStencilState = CastDepthStencilState(hDepthStencilState);
967bf215546Sopenharmony_ci
968bf215546Sopenharmony_ci   pipe->delete_depth_stencil_alpha_state(pipe, pDepthStencilState->handle);
969bf215546Sopenharmony_ci}
970bf215546Sopenharmony_ci
971bf215546Sopenharmony_ci
972bf215546Sopenharmony_ci/*
973bf215546Sopenharmony_ci * ----------------------------------------------------------------------
974bf215546Sopenharmony_ci *
975bf215546Sopenharmony_ci * SetDepthStencilState --
976bf215546Sopenharmony_ci *
977bf215546Sopenharmony_ci *    The SetDepthStencilState function sets a depth-stencil state.
978bf215546Sopenharmony_ci *
979bf215546Sopenharmony_ci * ----------------------------------------------------------------------
980bf215546Sopenharmony_ci */
981bf215546Sopenharmony_ci
982bf215546Sopenharmony_civoid APIENTRY
983bf215546Sopenharmony_ciSetDepthStencilState(D3D10DDI_HDEVICE hDevice,           // IN
984bf215546Sopenharmony_ci                     D3D10DDI_HDEPTHSTENCILSTATE hState, // IN
985bf215546Sopenharmony_ci                     UINT StencilRef)                    // IN
986bf215546Sopenharmony_ci{
987bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
988bf215546Sopenharmony_ci
989bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
990bf215546Sopenharmony_ci   void *state = CastPipeDepthStencilState(hState);
991bf215546Sopenharmony_ci   struct pipe_stencil_ref psr;
992bf215546Sopenharmony_ci
993bf215546Sopenharmony_ci   psr.ref_value[0] = StencilRef;
994bf215546Sopenharmony_ci   psr.ref_value[1] = StencilRef;
995bf215546Sopenharmony_ci
996bf215546Sopenharmony_ci   pipe->bind_depth_stencil_alpha_state(pipe, state);
997bf215546Sopenharmony_ci   pipe->set_stencil_ref(pipe, psr);
998bf215546Sopenharmony_ci}
999