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 * Query.cpp --
30bf215546Sopenharmony_ci *    Functions that manipulate query resources.
31bf215546Sopenharmony_ci */
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "Query.h"
35bf215546Sopenharmony_ci#include "State.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "Debug.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci/*
41bf215546Sopenharmony_ci * ----------------------------------------------------------------------
42bf215546Sopenharmony_ci *
43bf215546Sopenharmony_ci * CalcPrivateQuerySize --
44bf215546Sopenharmony_ci *
45bf215546Sopenharmony_ci *    The CalcPrivateQuerySize function determines the size of the
46bf215546Sopenharmony_ci *    user-mode display driver's private region of memory (that is,
47bf215546Sopenharmony_ci *    the size of internal driver structures, not the size of the
48bf215546Sopenharmony_ci *    resource video memory) for a query.
49bf215546Sopenharmony_ci *
50bf215546Sopenharmony_ci * ----------------------------------------------------------------------
51bf215546Sopenharmony_ci */
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ciSIZE_T APIENTRY
54bf215546Sopenharmony_ciCalcPrivateQuerySize(D3D10DDI_HDEVICE hDevice,                          // IN
55bf215546Sopenharmony_ci                     __in const D3D10DDIARG_CREATEQUERY *pCreateQuery)  // IN
56bf215546Sopenharmony_ci{
57bf215546Sopenharmony_ci   return sizeof(Query);
58bf215546Sopenharmony_ci}
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_cistatic uint
62bf215546Sopenharmony_ciTranslateQueryType(D3D10DDI_QUERY query)
63bf215546Sopenharmony_ci{
64bf215546Sopenharmony_ci   switch (query) {
65bf215546Sopenharmony_ci   case D3D10DDI_QUERY_EVENT:
66bf215546Sopenharmony_ci      return PIPE_QUERY_GPU_FINISHED;
67bf215546Sopenharmony_ci   case D3D10DDI_QUERY_OCCLUSION:
68bf215546Sopenharmony_ci      return PIPE_QUERY_OCCLUSION_COUNTER;
69bf215546Sopenharmony_ci   case D3D10DDI_QUERY_TIMESTAMP:
70bf215546Sopenharmony_ci      return PIPE_QUERY_TIMESTAMP;
71bf215546Sopenharmony_ci   case D3D10DDI_QUERY_TIMESTAMPDISJOINT:
72bf215546Sopenharmony_ci      return PIPE_QUERY_TIMESTAMP_DISJOINT;
73bf215546Sopenharmony_ci   case D3D10DDI_QUERY_PIPELINESTATS:
74bf215546Sopenharmony_ci      return PIPE_QUERY_PIPELINE_STATISTICS;
75bf215546Sopenharmony_ci   case D3D10DDI_QUERY_OCCLUSIONPREDICATE:
76bf215546Sopenharmony_ci      return PIPE_QUERY_OCCLUSION_PREDICATE;
77bf215546Sopenharmony_ci   case D3D10DDI_QUERY_STREAMOUTPUTSTATS:
78bf215546Sopenharmony_ci      return PIPE_QUERY_SO_STATISTICS;
79bf215546Sopenharmony_ci   case D3D10DDI_QUERY_STREAMOVERFLOWPREDICATE:
80bf215546Sopenharmony_ci      return PIPE_QUERY_SO_OVERFLOW_PREDICATE;
81bf215546Sopenharmony_ci   default:
82bf215546Sopenharmony_ci      LOG_UNSUPPORTED(TRUE);
83bf215546Sopenharmony_ci      return PIPE_QUERY_TYPES;
84bf215546Sopenharmony_ci   }
85bf215546Sopenharmony_ci}
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci/*
89bf215546Sopenharmony_ci * ----------------------------------------------------------------------
90bf215546Sopenharmony_ci *
91bf215546Sopenharmony_ci * CreateQuery --
92bf215546Sopenharmony_ci *
93bf215546Sopenharmony_ci *    The CreateQuery function creates driver-side resources for a
94bf215546Sopenharmony_ci *    query that the Microsoft Direct3D runtime subsequently issues
95bf215546Sopenharmony_ci *    for processing.
96bf215546Sopenharmony_ci *
97bf215546Sopenharmony_ci * ----------------------------------------------------------------------
98bf215546Sopenharmony_ci */
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_civoid APIENTRY
101bf215546Sopenharmony_ciCreateQuery(D3D10DDI_HDEVICE hDevice,                          // IN
102bf215546Sopenharmony_ci            __in const D3D10DDIARG_CREATEQUERY *pCreateQuery,  // IN
103bf215546Sopenharmony_ci            D3D10DDI_HQUERY hQuery,                            // IN
104bf215546Sopenharmony_ci            D3D10DDI_HRTQUERY hRTQuery)                        // IN
105bf215546Sopenharmony_ci{
106bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci   Device *pDevice = CastDevice(hDevice);
109bf215546Sopenharmony_ci   struct pipe_context *pipe = pDevice->pipe;
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci   Query *pQuery = CastQuery(hQuery);
112bf215546Sopenharmony_ci   memset(pQuery, 0, sizeof *pQuery);
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci   pQuery->Type = pCreateQuery->Query;
115bf215546Sopenharmony_ci   pQuery->Flags = pCreateQuery->MiscFlags;
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci   pQuery->pipe_type = TranslateQueryType(pCreateQuery->Query);
118bf215546Sopenharmony_ci   if (pQuery->pipe_type < PIPE_QUERY_TYPES) {
119bf215546Sopenharmony_ci      pQuery->handle = pipe->create_query(pipe, pQuery->pipe_type, 0);
120bf215546Sopenharmony_ci   }
121bf215546Sopenharmony_ci}
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci/*
125bf215546Sopenharmony_ci * ----------------------------------------------------------------------
126bf215546Sopenharmony_ci *
127bf215546Sopenharmony_ci * DestroyQuery --
128bf215546Sopenharmony_ci *
129bf215546Sopenharmony_ci *    The DestroyQuery function releases resources for a query.
130bf215546Sopenharmony_ci *
131bf215546Sopenharmony_ci * ----------------------------------------------------------------------
132bf215546Sopenharmony_ci */
133bf215546Sopenharmony_ci
134bf215546Sopenharmony_civoid APIENTRY
135bf215546Sopenharmony_ciDestroyQuery(D3D10DDI_HDEVICE hDevice, // IN
136bf215546Sopenharmony_ci             D3D10DDI_HQUERY hQuery)   // IN
137bf215546Sopenharmony_ci{
138bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_ci   struct pipe_context *pipe = CastPipeContext(hDevice);
141bf215546Sopenharmony_ci   Query *pQuery = CastQuery(hQuery);
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci   if (pQuery->handle) {
144bf215546Sopenharmony_ci      pipe->destroy_query(pipe, pQuery->handle);
145bf215546Sopenharmony_ci   }
146bf215546Sopenharmony_ci}
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci/*
150bf215546Sopenharmony_ci * ----------------------------------------------------------------------
151bf215546Sopenharmony_ci *
152bf215546Sopenharmony_ci * QueryBegin --
153bf215546Sopenharmony_ci *
154bf215546Sopenharmony_ci *    The QueryBegin function marks the beginning of a sequence of
155bf215546Sopenharmony_ci *    graphics commands for a query and transitions the query to the
156bf215546Sopenharmony_ci *    "building" state.
157bf215546Sopenharmony_ci *
158bf215546Sopenharmony_ci * ----------------------------------------------------------------------
159bf215546Sopenharmony_ci */
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_civoid APIENTRY
162bf215546Sopenharmony_ciQueryBegin(D3D10DDI_HDEVICE hDevice,   // IN
163bf215546Sopenharmony_ci           D3D10DDI_HQUERY hQuery)     // IN
164bf215546Sopenharmony_ci{
165bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_ci   Device *pDevice = CastDevice(hDevice);
168bf215546Sopenharmony_ci   struct pipe_context *pipe = pDevice->pipe;
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci   Query *pQuery = CastQuery(hQuery);
171bf215546Sopenharmony_ci   struct pipe_query *state = CastPipeQuery(hQuery);
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci   if (state) {
174bf215546Sopenharmony_ci      assert(pQuery->pipe_type < PIPE_QUERY_TYPES);
175bf215546Sopenharmony_ci      pipe->begin_query(pipe, state);
176bf215546Sopenharmony_ci   }
177bf215546Sopenharmony_ci}
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci/*
181bf215546Sopenharmony_ci * ----------------------------------------------------------------------
182bf215546Sopenharmony_ci *
183bf215546Sopenharmony_ci * QueryEnd --
184bf215546Sopenharmony_ci *
185bf215546Sopenharmony_ci *    The QueryEnd function marks the end of a sequence of graphics
186bf215546Sopenharmony_ci *    commands for a query and transitions the query to the
187bf215546Sopenharmony_ci *    "issued" state.
188bf215546Sopenharmony_ci *
189bf215546Sopenharmony_ci * ----------------------------------------------------------------------
190bf215546Sopenharmony_ci */
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_civoid APIENTRY
193bf215546Sopenharmony_ciQueryEnd(D3D10DDI_HDEVICE hDevice,  // IN
194bf215546Sopenharmony_ci         D3D10DDI_HQUERY hQuery)    // IN
195bf215546Sopenharmony_ci{
196bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_ci   Device *pDevice = CastDevice(hDevice);
199bf215546Sopenharmony_ci   struct pipe_context *pipe = pDevice->pipe;
200bf215546Sopenharmony_ci   Query *pQuery = CastQuery(hQuery);
201bf215546Sopenharmony_ci   struct pipe_query *state = pQuery->handle;
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_ci   pQuery->SeqNo = ++pDevice->LastEmittedQuerySeqNo;
204bf215546Sopenharmony_ci   pQuery->GetDataCount = 0;
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci   if (state) {
207bf215546Sopenharmony_ci      pipe->end_query(pipe, state);
208bf215546Sopenharmony_ci   }
209bf215546Sopenharmony_ci}
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci
212bf215546Sopenharmony_ci/*
213bf215546Sopenharmony_ci * ----------------------------------------------------------------------
214bf215546Sopenharmony_ci *
215bf215546Sopenharmony_ci * QueryGetData --
216bf215546Sopenharmony_ci *
217bf215546Sopenharmony_ci *    The QueryGetData function polls for the state of a query operation.
218bf215546Sopenharmony_ci *
219bf215546Sopenharmony_ci * ----------------------------------------------------------------------
220bf215546Sopenharmony_ci */
221bf215546Sopenharmony_ci
222bf215546Sopenharmony_civoid APIENTRY
223bf215546Sopenharmony_ciQueryGetData(D3D10DDI_HDEVICE hDevice,                      // IN
224bf215546Sopenharmony_ci             D3D10DDI_HQUERY hQuery,                        // IN
225bf215546Sopenharmony_ci             __out_bcount_full_opt (DataSize) void *pData,  // OUT
226bf215546Sopenharmony_ci             UINT DataSize,                                 // IN
227bf215546Sopenharmony_ci             UINT Flags)                                    // IN
228bf215546Sopenharmony_ci{
229bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
230bf215546Sopenharmony_ci
231bf215546Sopenharmony_ci   Device *pDevice = CastDevice(hDevice);
232bf215546Sopenharmony_ci   struct pipe_context *pipe = pDevice->pipe;
233bf215546Sopenharmony_ci   Query *pQuery = CastQuery(hQuery);
234bf215546Sopenharmony_ci   struct pipe_query *state = pQuery->handle;
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ci   /*
237bf215546Sopenharmony_ci    * Never return data for recently emitted queries immediately, to make
238bf215546Sopenharmony_ci    * wgfasync happy.
239bf215546Sopenharmony_ci    */
240bf215546Sopenharmony_ci   if (DataSize == 0 &&
241bf215546Sopenharmony_ci       (pQuery->SeqNo - pDevice->LastFinishedQuerySeqNo) > 0 &&
242bf215546Sopenharmony_ci       (pQuery->GetDataCount++) == 0) {
243bf215546Sopenharmony_ci      SetError(hDevice, DXGI_DDI_ERR_WASSTILLDRAWING);
244bf215546Sopenharmony_ci      return;
245bf215546Sopenharmony_ci   }
246bf215546Sopenharmony_ci
247bf215546Sopenharmony_ci   boolean wait = !!(Flags & D3D10_DDI_GET_DATA_DO_NOT_FLUSH);
248bf215546Sopenharmony_ci   union pipe_query_result result;
249bf215546Sopenharmony_ci
250bf215546Sopenharmony_ci   memset(&result, 0, sizeof result);
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_ci   boolean ret;
253bf215546Sopenharmony_ci
254bf215546Sopenharmony_ci   if (state) {
255bf215546Sopenharmony_ci      ret = pipe->get_query_result(pipe, state, wait, &result);
256bf215546Sopenharmony_ci   } else {
257bf215546Sopenharmony_ci      LOG_UNSUPPORTED(TRUE);
258bf215546Sopenharmony_ci      ret = TRUE;
259bf215546Sopenharmony_ci   }
260bf215546Sopenharmony_ci
261bf215546Sopenharmony_ci   if (!ret) {
262bf215546Sopenharmony_ci      SetError(hDevice, DXGI_DDI_ERR_WASSTILLDRAWING);
263bf215546Sopenharmony_ci      return;
264bf215546Sopenharmony_ci   }
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci   if (pData) {
267bf215546Sopenharmony_ci      switch (pQuery->Type) {
268bf215546Sopenharmony_ci      case D3D10DDI_QUERY_EVENT:
269bf215546Sopenharmony_ci      case D3D10DDI_QUERY_OCCLUSIONPREDICATE:
270bf215546Sopenharmony_ci      case D3D10DDI_QUERY_STREAMOVERFLOWPREDICATE:
271bf215546Sopenharmony_ci         *(BOOL *)pData = result.b;
272bf215546Sopenharmony_ci         break;
273bf215546Sopenharmony_ci      case D3D10DDI_QUERY_OCCLUSION:
274bf215546Sopenharmony_ci      case D3D10DDI_QUERY_TIMESTAMP:
275bf215546Sopenharmony_ci         *(UINT64 *)pData = result.u64;
276bf215546Sopenharmony_ci         break;
277bf215546Sopenharmony_ci      case D3D10DDI_QUERY_TIMESTAMPDISJOINT:
278bf215546Sopenharmony_ci         {
279bf215546Sopenharmony_ci            D3D10_DDI_QUERY_DATA_TIMESTAMP_DISJOINT *pResult =
280bf215546Sopenharmony_ci              (D3D10_DDI_QUERY_DATA_TIMESTAMP_DISJOINT *)pData;
281bf215546Sopenharmony_ci            pResult->Frequency = result.timestamp_disjoint.frequency;
282bf215546Sopenharmony_ci            pResult->Disjoint = result.timestamp_disjoint.disjoint;
283bf215546Sopenharmony_ci         }
284bf215546Sopenharmony_ci         break;
285bf215546Sopenharmony_ci      case D3D10DDI_QUERY_PIPELINESTATS:
286bf215546Sopenharmony_ci         {
287bf215546Sopenharmony_ci            D3D10_DDI_QUERY_DATA_PIPELINE_STATISTICS *pResult =
288bf215546Sopenharmony_ci              (D3D10_DDI_QUERY_DATA_PIPELINE_STATISTICS *)pData;
289bf215546Sopenharmony_ci            pResult->IAVertices = result.pipeline_statistics.ia_vertices;
290bf215546Sopenharmony_ci            pResult->IAPrimitives = result.pipeline_statistics.ia_primitives;
291bf215546Sopenharmony_ci            pResult->VSInvocations = result.pipeline_statistics.vs_invocations;
292bf215546Sopenharmony_ci            pResult->GSInvocations = result.pipeline_statistics.gs_invocations;
293bf215546Sopenharmony_ci            pResult->GSPrimitives = result.pipeline_statistics.gs_primitives;
294bf215546Sopenharmony_ci            pResult->CInvocations = result.pipeline_statistics.c_invocations;
295bf215546Sopenharmony_ci            pResult->CPrimitives = result.pipeline_statistics.c_primitives;
296bf215546Sopenharmony_ci            pResult->PSInvocations = result.pipeline_statistics.ps_invocations;
297bf215546Sopenharmony_ci            //pResult->HSInvocations = result.pipeline_statistics.hs_invocations;
298bf215546Sopenharmony_ci            //pResult->DSInvocations = result.pipeline_statistics.ds_invocations;
299bf215546Sopenharmony_ci            //pResult->CSInvocations = result.pipeline_statistics.cs_invocations;
300bf215546Sopenharmony_ci         }
301bf215546Sopenharmony_ci         break;
302bf215546Sopenharmony_ci      case D3D10DDI_QUERY_STREAMOUTPUTSTATS:
303bf215546Sopenharmony_ci         {
304bf215546Sopenharmony_ci            D3D10_DDI_QUERY_DATA_SO_STATISTICS *pResult =
305bf215546Sopenharmony_ci              (D3D10_DDI_QUERY_DATA_SO_STATISTICS *)pData;
306bf215546Sopenharmony_ci            pResult->NumPrimitivesWritten = result.so_statistics.num_primitives_written;
307bf215546Sopenharmony_ci            pResult->PrimitivesStorageNeeded = result.so_statistics.primitives_storage_needed;
308bf215546Sopenharmony_ci         }
309bf215546Sopenharmony_ci         break;
310bf215546Sopenharmony_ci      default:
311bf215546Sopenharmony_ci         assert(0);
312bf215546Sopenharmony_ci         break;
313bf215546Sopenharmony_ci      }
314bf215546Sopenharmony_ci   }
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_ci   /*
317bf215546Sopenharmony_ci    * Keep track of the last finished query, as wgfasync checks that queries
318bf215546Sopenharmony_ci    * are completed in order.
319bf215546Sopenharmony_ci    */
320bf215546Sopenharmony_ci   if ((pQuery->SeqNo - pDevice->LastFinishedQuerySeqNo) > 0) {
321bf215546Sopenharmony_ci      pDevice->LastFinishedQuerySeqNo = pQuery->SeqNo;
322bf215546Sopenharmony_ci   }
323bf215546Sopenharmony_ci   pQuery->GetDataCount = 0x80000000;
324bf215546Sopenharmony_ci}
325bf215546Sopenharmony_ci
326bf215546Sopenharmony_ci
327bf215546Sopenharmony_ci/*
328bf215546Sopenharmony_ci * ----------------------------------------------------------------------
329bf215546Sopenharmony_ci *
330bf215546Sopenharmony_ci * SetPredication --
331bf215546Sopenharmony_ci *
332bf215546Sopenharmony_ci *    The SetPredication function specifies whether rendering and
333bf215546Sopenharmony_ci *    resource-manipulation commands that follow are actually performed.
334bf215546Sopenharmony_ci *
335bf215546Sopenharmony_ci * ----------------------------------------------------------------------
336bf215546Sopenharmony_ci */
337bf215546Sopenharmony_ci
338bf215546Sopenharmony_civoid APIENTRY
339bf215546Sopenharmony_ciSetPredication(D3D10DDI_HDEVICE hDevice,  // IN
340bf215546Sopenharmony_ci               D3D10DDI_HQUERY hQuery,    // IN
341bf215546Sopenharmony_ci               BOOL PredicateValue)       // IN
342bf215546Sopenharmony_ci{
343bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
344bf215546Sopenharmony_ci
345bf215546Sopenharmony_ci   Device *pDevice = CastDevice(hDevice);
346bf215546Sopenharmony_ci   struct pipe_context *pipe = pDevice->pipe;
347bf215546Sopenharmony_ci   Query *pQuery = CastQuery(hQuery);
348bf215546Sopenharmony_ci   struct pipe_query *state = CastPipeQuery(hQuery);
349bf215546Sopenharmony_ci   enum pipe_render_cond_flag wait;
350bf215546Sopenharmony_ci
351bf215546Sopenharmony_ci   wait = (pQuery && pQuery->Flags & D3D10DDI_QUERY_MISCFLAG_PREDICATEHINT) ?
352bf215546Sopenharmony_ci             PIPE_RENDER_COND_NO_WAIT : PIPE_RENDER_COND_WAIT;
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_ci   pipe->render_condition(pipe, state, PredicateValue, wait);
355bf215546Sopenharmony_ci
356bf215546Sopenharmony_ci   pDevice->pPredicate = pQuery;
357bf215546Sopenharmony_ci   pDevice->PredicateValue = PredicateValue;
358bf215546Sopenharmony_ci}
359bf215546Sopenharmony_ci
360bf215546Sopenharmony_ci
361bf215546Sopenharmony_ci/*
362bf215546Sopenharmony_ci * ----------------------------------------------------------------------
363bf215546Sopenharmony_ci *
364bf215546Sopenharmony_ci * CheckPredicate --
365bf215546Sopenharmony_ci *
366bf215546Sopenharmony_ci *    Check predicate value and whether to draw or not.
367bf215546Sopenharmony_ci *
368bf215546Sopenharmony_ci * ----------------------------------------------------------------------
369bf215546Sopenharmony_ci */
370bf215546Sopenharmony_ci
371bf215546Sopenharmony_ciBOOL
372bf215546Sopenharmony_ciCheckPredicate(Device *pDevice)
373bf215546Sopenharmony_ci{
374bf215546Sopenharmony_ci   Query *pQuery = pDevice->pPredicate;
375bf215546Sopenharmony_ci   if (!pQuery) {
376bf215546Sopenharmony_ci      return TRUE;
377bf215546Sopenharmony_ci   }
378bf215546Sopenharmony_ci
379bf215546Sopenharmony_ci   assert(pQuery->Type == D3D10DDI_QUERY_OCCLUSIONPREDICATE ||
380bf215546Sopenharmony_ci          pQuery->Type == D3D10DDI_QUERY_STREAMOVERFLOWPREDICATE);
381bf215546Sopenharmony_ci
382bf215546Sopenharmony_ci   struct pipe_context *pipe = pDevice->pipe;
383bf215546Sopenharmony_ci   struct pipe_query *query = pQuery->handle;
384bf215546Sopenharmony_ci   assert(query);
385bf215546Sopenharmony_ci
386bf215546Sopenharmony_ci   union pipe_query_result result;
387bf215546Sopenharmony_ci   memset(&result, 0, sizeof result);
388bf215546Sopenharmony_ci
389bf215546Sopenharmony_ci   boolean ret;
390bf215546Sopenharmony_ci   ret = pipe->get_query_result(pipe, query, TRUE, &result);
391bf215546Sopenharmony_ci   assert(ret == TRUE);
392bf215546Sopenharmony_ci   if (!ret) {
393bf215546Sopenharmony_ci      return TRUE;
394bf215546Sopenharmony_ci   }
395bf215546Sopenharmony_ci
396bf215546Sopenharmony_ci   if (!!result.b == !!pDevice->PredicateValue) {
397bf215546Sopenharmony_ci      return FALSE;
398bf215546Sopenharmony_ci   }
399bf215546Sopenharmony_ci
400bf215546Sopenharmony_ci   return TRUE;
401bf215546Sopenharmony_ci}
402bf215546Sopenharmony_ci
403bf215546Sopenharmony_ci
404bf215546Sopenharmony_ci/*
405bf215546Sopenharmony_ci * ----------------------------------------------------------------------
406bf215546Sopenharmony_ci *
407bf215546Sopenharmony_ci * CheckCounterInfo --
408bf215546Sopenharmony_ci *
409bf215546Sopenharmony_ci *    The CheckCounterInfo function determines global information that
410bf215546Sopenharmony_ci *    is related to manipulating counters.
411bf215546Sopenharmony_ci *
412bf215546Sopenharmony_ci * ----------------------------------------------------------------------
413bf215546Sopenharmony_ci */
414bf215546Sopenharmony_ci
415bf215546Sopenharmony_civoid APIENTRY
416bf215546Sopenharmony_ciCheckCounterInfo(D3D10DDI_HDEVICE hDevice,                  // IN
417bf215546Sopenharmony_ci                 __out D3D10DDI_COUNTER_INFO *pCounterInfo) // OUT
418bf215546Sopenharmony_ci{
419bf215546Sopenharmony_ci   //LOG_ENTRYPOINT();
420bf215546Sopenharmony_ci
421bf215546Sopenharmony_ci   pCounterInfo->LastDeviceDependentCounter = (D3D10DDI_QUERY)0;
422bf215546Sopenharmony_ci   pCounterInfo->NumSimultaneousCounters = 0;
423bf215546Sopenharmony_ci   pCounterInfo->NumDetectableParallelUnits = 0;
424bf215546Sopenharmony_ci}
425bf215546Sopenharmony_ci
426bf215546Sopenharmony_ci
427bf215546Sopenharmony_ci/*
428bf215546Sopenharmony_ci * ----------------------------------------------------------------------
429bf215546Sopenharmony_ci *
430bf215546Sopenharmony_ci * CheckCounter --
431bf215546Sopenharmony_ci *
432bf215546Sopenharmony_ci *    The CheckCounter function retrieves information that
433bf215546Sopenharmony_ci *    describes a counter.
434bf215546Sopenharmony_ci *
435bf215546Sopenharmony_ci * ----------------------------------------------------------------------
436bf215546Sopenharmony_ci */
437bf215546Sopenharmony_ci
438bf215546Sopenharmony_civoid APIENTRY
439bf215546Sopenharmony_ciCheckCounter(
440bf215546Sopenharmony_ci   D3D10DDI_HDEVICE hDevice,                                                                // IN
441bf215546Sopenharmony_ci   D3D10DDI_QUERY Query,                                                                    // IN
442bf215546Sopenharmony_ci   __out D3D10DDI_COUNTER_TYPE *pCounterType,                                               // OUT
443bf215546Sopenharmony_ci   __out UINT *pActiveCounters,                                                             // OUT
444bf215546Sopenharmony_ci   __out_ecount_part_z_opt (*pNameLength, *pNameLength) LPSTR pName,                        // OUT
445bf215546Sopenharmony_ci   __inout_opt UINT *pNameLength,                                                           // OUT
446bf215546Sopenharmony_ci   __out_ecount_part_z_opt (*pUnitsLength, *pUnitsLength) LPSTR pUnits,                     // OUT
447bf215546Sopenharmony_ci   __inout_opt UINT *pUnitsLength,                                                          // OUT
448bf215546Sopenharmony_ci   __out_ecount_part_z_opt (*pDescriptionLength, *pDescriptionLength) LPSTR pDescription,   // OUT
449bf215546Sopenharmony_ci   __inout_opt UINT* pDescriptionLength)                                                    // OUT
450bf215546Sopenharmony_ci{
451bf215546Sopenharmony_ci   LOG_ENTRYPOINT();
452bf215546Sopenharmony_ci
453bf215546Sopenharmony_ci   SetError(hDevice, DXGI_DDI_ERR_UNSUPPORTED);
454bf215546Sopenharmony_ci}
455