1bf215546Sopenharmony_ci/**********************************************************
2bf215546Sopenharmony_ci * Copyright 2008-2009 VMware, Inc.  All rights reserved.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person
5bf215546Sopenharmony_ci * obtaining a copy of this software and associated documentation
6bf215546Sopenharmony_ci * files (the "Software"), to deal in the Software without
7bf215546Sopenharmony_ci * restriction, including without limitation the rights to use, copy,
8bf215546Sopenharmony_ci * modify, merge, publish, distribute, sublicense, and/or sell copies
9bf215546Sopenharmony_ci * of the Software, and to permit persons to whom the Software is
10bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be
13bf215546Sopenharmony_ci * included in all copies or substantial portions of the Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18bf215546Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19bf215546Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20bf215546Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21bf215546Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22bf215546Sopenharmony_ci * SOFTWARE.
23bf215546Sopenharmony_ci *
24bf215546Sopenharmony_ci **********************************************************/
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci/**
27bf215546Sopenharmony_ci * svga_cmd.c --
28bf215546Sopenharmony_ci *
29bf215546Sopenharmony_ci *      Command construction utility for the SVGA3D protocol used by
30bf215546Sopenharmony_ci *      the VMware SVGA device, based on the svgautil library.
31bf215546Sopenharmony_ci */
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#include "svga_winsys.h"
34bf215546Sopenharmony_ci#include "svga_resource_buffer.h"
35bf215546Sopenharmony_ci#include "svga_resource_texture.h"
36bf215546Sopenharmony_ci#include "svga_surface.h"
37bf215546Sopenharmony_ci#include "svga_cmd.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci/*
40bf215546Sopenharmony_ci *----------------------------------------------------------------------
41bf215546Sopenharmony_ci *
42bf215546Sopenharmony_ci * surface_to_surfaceid --
43bf215546Sopenharmony_ci *
44bf215546Sopenharmony_ci *      Utility function for surface ids.
45bf215546Sopenharmony_ci *      Can handle null surface. Does a surface_reallocation so you need
46bf215546Sopenharmony_ci *      to have allocated the fifo space before converting.
47bf215546Sopenharmony_ci *
48bf215546Sopenharmony_ci *
49bf215546Sopenharmony_ci * param flags  mask of SVGA_RELOC_READ / _WRITE
50bf215546Sopenharmony_ci *
51bf215546Sopenharmony_ci * Results:
52bf215546Sopenharmony_ci *      id is filled out.
53bf215546Sopenharmony_ci *
54bf215546Sopenharmony_ci * Side effects:
55bf215546Sopenharmony_ci *      One surface relocation is performed for texture handle.
56bf215546Sopenharmony_ci *
57bf215546Sopenharmony_ci *----------------------------------------------------------------------
58bf215546Sopenharmony_ci */
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_cistatic inline void
61bf215546Sopenharmony_cisurface_to_surfaceid(struct svga_winsys_context *swc, // IN
62bf215546Sopenharmony_ci                     struct pipe_surface *surface,    // IN
63bf215546Sopenharmony_ci                     SVGA3dSurfaceImageId *id,        // OUT
64bf215546Sopenharmony_ci                     unsigned flags)                  // IN
65bf215546Sopenharmony_ci{
66bf215546Sopenharmony_ci   if (surface) {
67bf215546Sopenharmony_ci      struct svga_surface *s = svga_surface(surface);
68bf215546Sopenharmony_ci      swc->surface_relocation(swc, &id->sid, NULL, s->handle, flags);
69bf215546Sopenharmony_ci      id->face = s->real_layer; /* faces have the same order */
70bf215546Sopenharmony_ci      id->mipmap = s->real_level;
71bf215546Sopenharmony_ci   }
72bf215546Sopenharmony_ci   else {
73bf215546Sopenharmony_ci      swc->surface_relocation(swc, &id->sid, NULL, NULL, flags);
74bf215546Sopenharmony_ci      id->face = 0;
75bf215546Sopenharmony_ci      id->mipmap = 0;
76bf215546Sopenharmony_ci   }
77bf215546Sopenharmony_ci}
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci/*
81bf215546Sopenharmony_ci *----------------------------------------------------------------------
82bf215546Sopenharmony_ci *
83bf215546Sopenharmony_ci * SVGA3D_FIFOReserve --
84bf215546Sopenharmony_ci *
85bf215546Sopenharmony_ci *      Reserve space for an SVGA3D FIFO command.
86bf215546Sopenharmony_ci *
87bf215546Sopenharmony_ci *      The 2D SVGA commands have been around for a while, so they
88bf215546Sopenharmony_ci *      have a rather asymmetric structure. The SVGA3D protocol is
89bf215546Sopenharmony_ci *      more uniform: each command begins with a header containing the
90bf215546Sopenharmony_ci *      command number and the full size.
91bf215546Sopenharmony_ci *
92bf215546Sopenharmony_ci *      This is a convenience wrapper around SVGA_FIFOReserve. We
93bf215546Sopenharmony_ci *      reserve space for the whole command, and write the header.
94bf215546Sopenharmony_ci *
95bf215546Sopenharmony_ci *      This function must be paired with SVGA_FIFOCommitAll().
96bf215546Sopenharmony_ci *
97bf215546Sopenharmony_ci * Results:
98bf215546Sopenharmony_ci *      Returns a pointer to the space reserved for command-specific
99bf215546Sopenharmony_ci *      data. It must be 'cmdSize' bytes long.
100bf215546Sopenharmony_ci *
101bf215546Sopenharmony_ci * Side effects:
102bf215546Sopenharmony_ci *      Begins a FIFO reservation.
103bf215546Sopenharmony_ci *
104bf215546Sopenharmony_ci *----------------------------------------------------------------------
105bf215546Sopenharmony_ci */
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_civoid *
108bf215546Sopenharmony_ciSVGA3D_FIFOReserve(struct svga_winsys_context *swc,
109bf215546Sopenharmony_ci                   uint32 cmd,       // IN
110bf215546Sopenharmony_ci                   uint32 cmdSize,   // IN
111bf215546Sopenharmony_ci                   uint32 nr_relocs) // IN
112bf215546Sopenharmony_ci{
113bf215546Sopenharmony_ci   SVGA3dCmdHeader *header;
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci   header = swc->reserve(swc, sizeof *header + cmdSize, nr_relocs);
116bf215546Sopenharmony_ci   if (!header)
117bf215546Sopenharmony_ci      return NULL;
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci   header->id = cmd;
120bf215546Sopenharmony_ci   header->size = cmdSize;
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci   swc->last_command = cmd;
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci   swc->num_commands++;
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_ci   return &header[1];
127bf215546Sopenharmony_ci}
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_civoid
131bf215546Sopenharmony_ciSVGA_FIFOCommitAll(struct svga_winsys_context *swc)
132bf215546Sopenharmony_ci{
133bf215546Sopenharmony_ci   swc->commit(swc);
134bf215546Sopenharmony_ci}
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_ci/*
138bf215546Sopenharmony_ci *----------------------------------------------------------------------
139bf215546Sopenharmony_ci *
140bf215546Sopenharmony_ci * SVGA3D_DefineContext --
141bf215546Sopenharmony_ci *
142bf215546Sopenharmony_ci *      Create a new context, to be referred to with the provided ID.
143bf215546Sopenharmony_ci *
144bf215546Sopenharmony_ci *      Context objects encapsulate all render state, and shader
145bf215546Sopenharmony_ci *      objects are per-context.
146bf215546Sopenharmony_ci *
147bf215546Sopenharmony_ci *      Surfaces are not per-context. The same surface can be shared
148bf215546Sopenharmony_ci *      between multiple contexts, and surface operations can occur
149bf215546Sopenharmony_ci *      without a context.
150bf215546Sopenharmony_ci *
151bf215546Sopenharmony_ci *      If the provided context ID already existed, it is redefined.
152bf215546Sopenharmony_ci *
153bf215546Sopenharmony_ci *      Context IDs are arbitrary small non-negative integers,
154bf215546Sopenharmony_ci *      global to the entire SVGA device.
155bf215546Sopenharmony_ci *
156bf215546Sopenharmony_ci * Results:
157bf215546Sopenharmony_ci *      None.
158bf215546Sopenharmony_ci *
159bf215546Sopenharmony_ci * Side effects:
160bf215546Sopenharmony_ci *      None.
161bf215546Sopenharmony_ci *
162bf215546Sopenharmony_ci *----------------------------------------------------------------------
163bf215546Sopenharmony_ci */
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_cienum pipe_error
166bf215546Sopenharmony_ciSVGA3D_DefineContext(struct svga_winsys_context *swc)  // IN
167bf215546Sopenharmony_ci{
168bf215546Sopenharmony_ci   SVGA3dCmdDefineContext *cmd;
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
171bf215546Sopenharmony_ci                            SVGA_3D_CMD_CONTEXT_DEFINE, sizeof *cmd, 0);
172bf215546Sopenharmony_ci   if (!cmd)
173bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci   cmd->cid = swc->cid;
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci   swc->commit(swc);
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci   return PIPE_OK;
180bf215546Sopenharmony_ci}
181bf215546Sopenharmony_ci
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_ci/*
184bf215546Sopenharmony_ci *----------------------------------------------------------------------
185bf215546Sopenharmony_ci *
186bf215546Sopenharmony_ci * SVGA3D_DestroyContext --
187bf215546Sopenharmony_ci *
188bf215546Sopenharmony_ci *      Delete a context created with SVGA3D_DefineContext.
189bf215546Sopenharmony_ci *
190bf215546Sopenharmony_ci * Results:
191bf215546Sopenharmony_ci *      None.
192bf215546Sopenharmony_ci *
193bf215546Sopenharmony_ci * Side effects:
194bf215546Sopenharmony_ci *      None.
195bf215546Sopenharmony_ci *
196bf215546Sopenharmony_ci *----------------------------------------------------------------------
197bf215546Sopenharmony_ci */
198bf215546Sopenharmony_ci
199bf215546Sopenharmony_cienum pipe_error
200bf215546Sopenharmony_ciSVGA3D_DestroyContext(struct svga_winsys_context *swc)  // IN
201bf215546Sopenharmony_ci{
202bf215546Sopenharmony_ci   SVGA3dCmdDestroyContext *cmd;
203bf215546Sopenharmony_ci
204bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
205bf215546Sopenharmony_ci                            SVGA_3D_CMD_CONTEXT_DESTROY, sizeof *cmd, 0);
206bf215546Sopenharmony_ci   if (!cmd)
207bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_ci   cmd->cid = swc->cid;
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci   swc->commit(swc);
212bf215546Sopenharmony_ci
213bf215546Sopenharmony_ci   return PIPE_OK;
214bf215546Sopenharmony_ci}
215bf215546Sopenharmony_ci
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_ci/*
218bf215546Sopenharmony_ci *----------------------------------------------------------------------
219bf215546Sopenharmony_ci *
220bf215546Sopenharmony_ci * SVGA3D_BeginDefineSurface --
221bf215546Sopenharmony_ci *
222bf215546Sopenharmony_ci *      Begin a SURFACE_DEFINE command. This reserves space for it in
223bf215546Sopenharmony_ci *      the FIFO, and returns pointers to the command's faces and
224bf215546Sopenharmony_ci *      mipsizes arrays.
225bf215546Sopenharmony_ci *
226bf215546Sopenharmony_ci *      This function must be paired with SVGA_FIFOCommitAll().
227bf215546Sopenharmony_ci *      The faces and mipSizes arrays are initialized to zero.
228bf215546Sopenharmony_ci *
229bf215546Sopenharmony_ci *      This creates a "surface" object in the SVGA3D device,
230bf215546Sopenharmony_ci *      with the provided surface ID (sid). Surfaces are generic
231bf215546Sopenharmony_ci *      containers for host VRAM objects like textures, vertex
232bf215546Sopenharmony_ci *      buffers, and depth/stencil buffers.
233bf215546Sopenharmony_ci *
234bf215546Sopenharmony_ci *      Surfaces are hierarchical:
235bf215546Sopenharmony_ci *
236bf215546Sopenharmony_ci *        - Surface may have multiple faces (for cube maps)
237bf215546Sopenharmony_ci *
238bf215546Sopenharmony_ci *          - Each face has a list of mipmap levels
239bf215546Sopenharmony_ci *
240bf215546Sopenharmony_ci *             - Each mipmap image may have multiple volume
241bf215546Sopenharmony_ci *               slices, if the image is three dimensional.
242bf215546Sopenharmony_ci *
243bf215546Sopenharmony_ci *                - Each slice is a 2D array of 'blocks'
244bf215546Sopenharmony_ci *
245bf215546Sopenharmony_ci *                   - Each block may be one or more pixels.
246bf215546Sopenharmony_ci *                     (Usually 1, more for DXT or YUV formats.)
247bf215546Sopenharmony_ci *
248bf215546Sopenharmony_ci *      Surfaces are generic host VRAM objects. The SVGA3D device
249bf215546Sopenharmony_ci *      may optimize surfaces according to the format they were
250bf215546Sopenharmony_ci *      created with, but this format does not limit the ways in
251bf215546Sopenharmony_ci *      which the surface may be used. For example, a depth surface
252bf215546Sopenharmony_ci *      can be used as a texture, or a floating point image may
253bf215546Sopenharmony_ci *      be used as a vertex buffer. Some surface usages may be
254bf215546Sopenharmony_ci *      lower performance, due to software emulation, but any
255bf215546Sopenharmony_ci *      usage should work with any surface.
256bf215546Sopenharmony_ci *
257bf215546Sopenharmony_ci *      If 'sid' is already defined, the old surface is deleted
258bf215546Sopenharmony_ci *      and this new surface replaces it.
259bf215546Sopenharmony_ci *
260bf215546Sopenharmony_ci *      Surface IDs are arbitrary small non-negative integers,
261bf215546Sopenharmony_ci *      global to the entire SVGA device.
262bf215546Sopenharmony_ci *
263bf215546Sopenharmony_ci * Results:
264bf215546Sopenharmony_ci *      Returns pointers to arrays allocated in the FIFO for 'faces'
265bf215546Sopenharmony_ci *      and 'mipSizes'.
266bf215546Sopenharmony_ci *
267bf215546Sopenharmony_ci * Side effects:
268bf215546Sopenharmony_ci *      Begins a FIFO reservation.
269bf215546Sopenharmony_ci *
270bf215546Sopenharmony_ci *----------------------------------------------------------------------
271bf215546Sopenharmony_ci */
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_cienum pipe_error
274bf215546Sopenharmony_ciSVGA3D_BeginDefineSurface(struct svga_winsys_context *swc,
275bf215546Sopenharmony_ci                          struct svga_winsys_surface *sid, // IN
276bf215546Sopenharmony_ci                          SVGA3dSurface1Flags flags,    // IN
277bf215546Sopenharmony_ci                          SVGA3dSurfaceFormat format,  // IN
278bf215546Sopenharmony_ci                          SVGA3dSurfaceFace **faces,   // OUT
279bf215546Sopenharmony_ci                          SVGA3dSize **mipSizes,       // OUT
280bf215546Sopenharmony_ci                          uint32 numMipSizes)          // IN
281bf215546Sopenharmony_ci{
282bf215546Sopenharmony_ci   SVGA3dCmdDefineSurface *cmd;
283bf215546Sopenharmony_ci
284bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
285bf215546Sopenharmony_ci                            SVGA_3D_CMD_SURFACE_DEFINE, sizeof *cmd +
286bf215546Sopenharmony_ci                            sizeof **mipSizes * numMipSizes, 1);
287bf215546Sopenharmony_ci   if (!cmd)
288bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
289bf215546Sopenharmony_ci
290bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->sid, NULL, sid,
291bf215546Sopenharmony_ci                           SVGA_RELOC_WRITE | SVGA_RELOC_INTERNAL);
292bf215546Sopenharmony_ci   cmd->surfaceFlags = flags;
293bf215546Sopenharmony_ci   cmd->format = format;
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ci   *faces = &cmd->face[0];
296bf215546Sopenharmony_ci   *mipSizes = (SVGA3dSize*) &cmd[1];
297bf215546Sopenharmony_ci
298bf215546Sopenharmony_ci   memset(*faces, 0, sizeof **faces * SVGA3D_MAX_SURFACE_FACES);
299bf215546Sopenharmony_ci   memset(*mipSizes, 0, sizeof **mipSizes * numMipSizes);
300bf215546Sopenharmony_ci
301bf215546Sopenharmony_ci   return PIPE_OK;
302bf215546Sopenharmony_ci}
303bf215546Sopenharmony_ci
304bf215546Sopenharmony_ci
305bf215546Sopenharmony_ci/*
306bf215546Sopenharmony_ci *----------------------------------------------------------------------
307bf215546Sopenharmony_ci *
308bf215546Sopenharmony_ci * SVGA3D_DefineSurface2D --
309bf215546Sopenharmony_ci *
310bf215546Sopenharmony_ci *      This is a simplified version of SVGA3D_BeginDefineSurface(),
311bf215546Sopenharmony_ci *      which does not support cube maps, mipmaps, or volume textures.
312bf215546Sopenharmony_ci *
313bf215546Sopenharmony_ci * Results:
314bf215546Sopenharmony_ci *      None.
315bf215546Sopenharmony_ci *
316bf215546Sopenharmony_ci * Side effects:
317bf215546Sopenharmony_ci *      None.
318bf215546Sopenharmony_ci *
319bf215546Sopenharmony_ci *----------------------------------------------------------------------
320bf215546Sopenharmony_ci */
321bf215546Sopenharmony_ci
322bf215546Sopenharmony_cienum pipe_error
323bf215546Sopenharmony_ciSVGA3D_DefineSurface2D(struct svga_winsys_context *swc,    // IN
324bf215546Sopenharmony_ci                       struct svga_winsys_surface *sid, // IN
325bf215546Sopenharmony_ci                       uint32 width,                // IN
326bf215546Sopenharmony_ci                       uint32 height,               // IN
327bf215546Sopenharmony_ci                       SVGA3dSurfaceFormat format)  // IN
328bf215546Sopenharmony_ci{
329bf215546Sopenharmony_ci   SVGA3dSize *mipSizes;
330bf215546Sopenharmony_ci   SVGA3dSurfaceFace *faces;
331bf215546Sopenharmony_ci   enum pipe_error ret;
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci   ret = SVGA3D_BeginDefineSurface(swc,
334bf215546Sopenharmony_ci                                   sid, 0, format, &faces, &mipSizes, 1);
335bf215546Sopenharmony_ci   if (ret != PIPE_OK)
336bf215546Sopenharmony_ci      return ret;
337bf215546Sopenharmony_ci
338bf215546Sopenharmony_ci   faces[0].numMipLevels = 1;
339bf215546Sopenharmony_ci
340bf215546Sopenharmony_ci   mipSizes[0].width = width;
341bf215546Sopenharmony_ci   mipSizes[0].height = height;
342bf215546Sopenharmony_ci   mipSizes[0].depth = 1;
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci   swc->commit(swc);
345bf215546Sopenharmony_ci
346bf215546Sopenharmony_ci   return PIPE_OK;
347bf215546Sopenharmony_ci}
348bf215546Sopenharmony_ci
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci/*
351bf215546Sopenharmony_ci *----------------------------------------------------------------------
352bf215546Sopenharmony_ci *
353bf215546Sopenharmony_ci * SVGA3D_DestroySurface --
354bf215546Sopenharmony_ci *
355bf215546Sopenharmony_ci *      Release the host VRAM encapsulated by a particular surface ID.
356bf215546Sopenharmony_ci *
357bf215546Sopenharmony_ci * Results:
358bf215546Sopenharmony_ci *      None.
359bf215546Sopenharmony_ci *
360bf215546Sopenharmony_ci * Side effects:
361bf215546Sopenharmony_ci *      None.
362bf215546Sopenharmony_ci *
363bf215546Sopenharmony_ci *----------------------------------------------------------------------
364bf215546Sopenharmony_ci */
365bf215546Sopenharmony_ci
366bf215546Sopenharmony_cienum pipe_error
367bf215546Sopenharmony_ciSVGA3D_DestroySurface(struct svga_winsys_context *swc,
368bf215546Sopenharmony_ci                      struct svga_winsys_surface *sid)  // IN
369bf215546Sopenharmony_ci{
370bf215546Sopenharmony_ci   SVGA3dCmdDestroySurface *cmd;
371bf215546Sopenharmony_ci
372bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
373bf215546Sopenharmony_ci                            SVGA_3D_CMD_SURFACE_DESTROY, sizeof *cmd, 1);
374bf215546Sopenharmony_ci   if (!cmd)
375bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
376bf215546Sopenharmony_ci
377bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->sid, NULL, sid,
378bf215546Sopenharmony_ci                           SVGA_RELOC_WRITE | SVGA_RELOC_INTERNAL);
379bf215546Sopenharmony_ci   swc->commit(swc);
380bf215546Sopenharmony_ci
381bf215546Sopenharmony_ci   return PIPE_OK;
382bf215546Sopenharmony_ci}
383bf215546Sopenharmony_ci
384bf215546Sopenharmony_ci
385bf215546Sopenharmony_ci/*
386bf215546Sopenharmony_ci *----------------------------------------------------------------------
387bf215546Sopenharmony_ci *
388bf215546Sopenharmony_ci * SVGA3D_SurfaceDMA--
389bf215546Sopenharmony_ci *
390bf215546Sopenharmony_ci *      Emit a SURFACE_DMA command.
391bf215546Sopenharmony_ci *
392bf215546Sopenharmony_ci *      When the SVGA3D device asynchronously processes this FIFO
393bf215546Sopenharmony_ci *      command, a DMA operation is performed between host VRAM and
394bf215546Sopenharmony_ci *      a generic SVGAGuestPtr. The guest pointer may refer to guest
395bf215546Sopenharmony_ci *      VRAM (provided by the SVGA PCI device) or to guest system
396bf215546Sopenharmony_ci *      memory that has been set up as a Guest Memory Region (GMR)
397bf215546Sopenharmony_ci *      by the SVGA device.
398bf215546Sopenharmony_ci *
399bf215546Sopenharmony_ci *      The guest's DMA buffer must remain valid (not freed, paged out,
400bf215546Sopenharmony_ci *      or overwritten) until the host has finished processing this
401bf215546Sopenharmony_ci *      command. The guest can determine that the host has finished
402bf215546Sopenharmony_ci *      by using the SVGA device's FIFO Fence mechanism.
403bf215546Sopenharmony_ci *
404bf215546Sopenharmony_ci *      The guest's image buffer can be an arbitrary size and shape.
405bf215546Sopenharmony_ci *      Guest image data is interpreted according to the SVGA3D surface
406bf215546Sopenharmony_ci *      format specified when the surface was defined.
407bf215546Sopenharmony_ci *
408bf215546Sopenharmony_ci *      The caller may optionally define the guest image's pitch.
409bf215546Sopenharmony_ci *      guestImage->pitch can either be zero (assume image is tightly
410bf215546Sopenharmony_ci *      packed) or it must be the number of bytes between vertically
411bf215546Sopenharmony_ci *      adjacent image blocks.
412bf215546Sopenharmony_ci *
413bf215546Sopenharmony_ci *      The provided copybox list specifies which regions of the source
414bf215546Sopenharmony_ci *      image are to be copied, and where they appear on the destination.
415bf215546Sopenharmony_ci *
416bf215546Sopenharmony_ci *      NOTE: srcx/srcy are always on the guest image and x/y are
417bf215546Sopenharmony_ci *      always on the host image, regardless of the actual transfer
418bf215546Sopenharmony_ci *      direction!
419bf215546Sopenharmony_ci *
420bf215546Sopenharmony_ci *      For efficiency, the SVGA3D device is free to copy more data
421bf215546Sopenharmony_ci *      than specified. For example, it may round copy boxes outwards
422bf215546Sopenharmony_ci *      such that they lie on particular alignment boundaries.
423bf215546Sopenharmony_ci *
424bf215546Sopenharmony_ci *----------------------------------------------------------------------
425bf215546Sopenharmony_ci */
426bf215546Sopenharmony_ci
427bf215546Sopenharmony_cienum pipe_error
428bf215546Sopenharmony_ciSVGA3D_SurfaceDMA(struct svga_winsys_context *swc,
429bf215546Sopenharmony_ci                  struct svga_transfer *st,         // IN
430bf215546Sopenharmony_ci                  SVGA3dTransferType transfer,      // IN
431bf215546Sopenharmony_ci                  const SVGA3dCopyBox *boxes,       // IN
432bf215546Sopenharmony_ci                  uint32 numBoxes,                  // IN
433bf215546Sopenharmony_ci                  SVGA3dSurfaceDMAFlags flags)      // IN
434bf215546Sopenharmony_ci{
435bf215546Sopenharmony_ci   struct svga_texture *texture = svga_texture(st->base.resource);
436bf215546Sopenharmony_ci   SVGA3dCmdSurfaceDMA *cmd;
437bf215546Sopenharmony_ci   SVGA3dCmdSurfaceDMASuffix *pSuffix;
438bf215546Sopenharmony_ci   uint32 boxesSize = sizeof *boxes * numBoxes;
439bf215546Sopenharmony_ci   unsigned region_flags;
440bf215546Sopenharmony_ci   unsigned surface_flags;
441bf215546Sopenharmony_ci
442bf215546Sopenharmony_ci   assert(!swc->have_gb_objects);
443bf215546Sopenharmony_ci
444bf215546Sopenharmony_ci   if (transfer == SVGA3D_WRITE_HOST_VRAM) {
445bf215546Sopenharmony_ci      region_flags = SVGA_RELOC_READ;
446bf215546Sopenharmony_ci      surface_flags = SVGA_RELOC_WRITE;
447bf215546Sopenharmony_ci   }
448bf215546Sopenharmony_ci   else if (transfer == SVGA3D_READ_HOST_VRAM) {
449bf215546Sopenharmony_ci      region_flags = SVGA_RELOC_WRITE;
450bf215546Sopenharmony_ci      surface_flags = SVGA_RELOC_READ;
451bf215546Sopenharmony_ci   }
452bf215546Sopenharmony_ci   else {
453bf215546Sopenharmony_ci      assert(0);
454bf215546Sopenharmony_ci      return PIPE_ERROR_BAD_INPUT;
455bf215546Sopenharmony_ci   }
456bf215546Sopenharmony_ci
457bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
458bf215546Sopenharmony_ci                            SVGA_3D_CMD_SURFACE_DMA,
459bf215546Sopenharmony_ci                            sizeof *cmd + boxesSize + sizeof *pSuffix,
460bf215546Sopenharmony_ci                            2);
461bf215546Sopenharmony_ci   if (!cmd)
462bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
463bf215546Sopenharmony_ci
464bf215546Sopenharmony_ci   swc->region_relocation(swc, &cmd->guest.ptr, st->hwbuf, 0, region_flags);
465bf215546Sopenharmony_ci   cmd->guest.pitch = st->base.stride;
466bf215546Sopenharmony_ci
467bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->host.sid, NULL,
468bf215546Sopenharmony_ci                           texture->handle, surface_flags);
469bf215546Sopenharmony_ci   cmd->host.face = st->slice; /* PIPE_TEX_FACE_* and SVGA3D_CUBEFACE_* match */
470bf215546Sopenharmony_ci   cmd->host.mipmap = st->base.level;
471bf215546Sopenharmony_ci
472bf215546Sopenharmony_ci   cmd->transfer = transfer;
473bf215546Sopenharmony_ci
474bf215546Sopenharmony_ci   memcpy(&cmd[1], boxes, boxesSize);
475bf215546Sopenharmony_ci
476bf215546Sopenharmony_ci   pSuffix = (SVGA3dCmdSurfaceDMASuffix *)((uint8_t*)cmd + sizeof *cmd + boxesSize);
477bf215546Sopenharmony_ci   pSuffix->suffixSize = sizeof *pSuffix;
478bf215546Sopenharmony_ci   pSuffix->maximumOffset = st->hw_nblocksy*st->base.stride;
479bf215546Sopenharmony_ci   pSuffix->flags = flags;
480bf215546Sopenharmony_ci
481bf215546Sopenharmony_ci   swc->commit(swc);
482bf215546Sopenharmony_ci   swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH;
483bf215546Sopenharmony_ci
484bf215546Sopenharmony_ci   return PIPE_OK;
485bf215546Sopenharmony_ci}
486bf215546Sopenharmony_ci
487bf215546Sopenharmony_ci
488bf215546Sopenharmony_cienum pipe_error
489bf215546Sopenharmony_ciSVGA3D_BufferDMA(struct svga_winsys_context *swc,
490bf215546Sopenharmony_ci                 struct svga_winsys_buffer *guest,
491bf215546Sopenharmony_ci                 struct svga_winsys_surface *host,
492bf215546Sopenharmony_ci                 SVGA3dTransferType transfer,      // IN
493bf215546Sopenharmony_ci                 uint32 size,                      // IN
494bf215546Sopenharmony_ci                 uint32 guest_offset,              // IN
495bf215546Sopenharmony_ci                 uint32 host_offset,               // IN
496bf215546Sopenharmony_ci                 SVGA3dSurfaceDMAFlags flags)      // IN
497bf215546Sopenharmony_ci{
498bf215546Sopenharmony_ci   SVGA3dCmdSurfaceDMA *cmd;
499bf215546Sopenharmony_ci   SVGA3dCopyBox *box;
500bf215546Sopenharmony_ci   SVGA3dCmdSurfaceDMASuffix *pSuffix;
501bf215546Sopenharmony_ci   unsigned region_flags;
502bf215546Sopenharmony_ci   unsigned surface_flags;
503bf215546Sopenharmony_ci
504bf215546Sopenharmony_ci   assert(!swc->have_gb_objects);
505bf215546Sopenharmony_ci
506bf215546Sopenharmony_ci   if (transfer == SVGA3D_WRITE_HOST_VRAM) {
507bf215546Sopenharmony_ci      region_flags = SVGA_RELOC_READ;
508bf215546Sopenharmony_ci      surface_flags = SVGA_RELOC_WRITE;
509bf215546Sopenharmony_ci   }
510bf215546Sopenharmony_ci   else if (transfer == SVGA3D_READ_HOST_VRAM) {
511bf215546Sopenharmony_ci      region_flags = SVGA_RELOC_WRITE;
512bf215546Sopenharmony_ci      surface_flags = SVGA_RELOC_READ;
513bf215546Sopenharmony_ci   }
514bf215546Sopenharmony_ci   else {
515bf215546Sopenharmony_ci      assert(0);
516bf215546Sopenharmony_ci      return PIPE_ERROR_BAD_INPUT;
517bf215546Sopenharmony_ci   }
518bf215546Sopenharmony_ci
519bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
520bf215546Sopenharmony_ci                            SVGA_3D_CMD_SURFACE_DMA,
521bf215546Sopenharmony_ci                            sizeof *cmd + sizeof *box + sizeof *pSuffix,
522bf215546Sopenharmony_ci                            2);
523bf215546Sopenharmony_ci   if (!cmd)
524bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
525bf215546Sopenharmony_ci
526bf215546Sopenharmony_ci   swc->region_relocation(swc, &cmd->guest.ptr, guest, 0, region_flags);
527bf215546Sopenharmony_ci   cmd->guest.pitch = 0;
528bf215546Sopenharmony_ci
529bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->host.sid,
530bf215546Sopenharmony_ci                           NULL, host, surface_flags);
531bf215546Sopenharmony_ci   cmd->host.face = 0;
532bf215546Sopenharmony_ci   cmd->host.mipmap = 0;
533bf215546Sopenharmony_ci
534bf215546Sopenharmony_ci   cmd->transfer = transfer;
535bf215546Sopenharmony_ci
536bf215546Sopenharmony_ci   box = (SVGA3dCopyBox *)&cmd[1];
537bf215546Sopenharmony_ci   box->x = host_offset;
538bf215546Sopenharmony_ci   box->y = 0;
539bf215546Sopenharmony_ci   box->z = 0;
540bf215546Sopenharmony_ci   box->w = size;
541bf215546Sopenharmony_ci   box->h = 1;
542bf215546Sopenharmony_ci   box->d = 1;
543bf215546Sopenharmony_ci   box->srcx = guest_offset;
544bf215546Sopenharmony_ci   box->srcy = 0;
545bf215546Sopenharmony_ci   box->srcz = 0;
546bf215546Sopenharmony_ci
547bf215546Sopenharmony_ci   pSuffix = (SVGA3dCmdSurfaceDMASuffix *)((uint8_t*)cmd + sizeof *cmd + sizeof *box);
548bf215546Sopenharmony_ci   pSuffix->suffixSize = sizeof *pSuffix;
549bf215546Sopenharmony_ci   pSuffix->maximumOffset = guest_offset + size;
550bf215546Sopenharmony_ci   pSuffix->flags = flags;
551bf215546Sopenharmony_ci
552bf215546Sopenharmony_ci   swc->commit(swc);
553bf215546Sopenharmony_ci   swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH;
554bf215546Sopenharmony_ci
555bf215546Sopenharmony_ci   return PIPE_OK;
556bf215546Sopenharmony_ci}
557bf215546Sopenharmony_ci
558bf215546Sopenharmony_ci
559bf215546Sopenharmony_ci/*
560bf215546Sopenharmony_ci *----------------------------------------------------------------------
561bf215546Sopenharmony_ci *
562bf215546Sopenharmony_ci * SVGA3D_SetRenderTarget --
563bf215546Sopenharmony_ci *
564bf215546Sopenharmony_ci *      Bind a surface object to a particular render target attachment
565bf215546Sopenharmony_ci *      point on the current context. Render target attachment points
566bf215546Sopenharmony_ci *      exist for color buffers, a depth buffer, and a stencil buffer.
567bf215546Sopenharmony_ci *
568bf215546Sopenharmony_ci *      The SVGA3D device is quite lenient about the types of surfaces
569bf215546Sopenharmony_ci *      that may be used as render targets. The color buffers must
570bf215546Sopenharmony_ci *      all be the same size, but the depth and stencil buffers do not
571bf215546Sopenharmony_ci *      have to be the same size as the color buffer. All attachments
572bf215546Sopenharmony_ci *      are optional.
573bf215546Sopenharmony_ci *
574bf215546Sopenharmony_ci *      Some combinations of render target formats may require software
575bf215546Sopenharmony_ci *      emulation, depending on the capabilities of the host graphics
576bf215546Sopenharmony_ci *      API and graphics hardware.
577bf215546Sopenharmony_ci *
578bf215546Sopenharmony_ci * Results:
579bf215546Sopenharmony_ci *      None.
580bf215546Sopenharmony_ci *
581bf215546Sopenharmony_ci * Side effects:
582bf215546Sopenharmony_ci *      None.
583bf215546Sopenharmony_ci *
584bf215546Sopenharmony_ci *----------------------------------------------------------------------
585bf215546Sopenharmony_ci */
586bf215546Sopenharmony_ci
587bf215546Sopenharmony_cienum pipe_error
588bf215546Sopenharmony_ciSVGA3D_SetRenderTarget(struct svga_winsys_context *swc,
589bf215546Sopenharmony_ci                       SVGA3dRenderTargetType type,   // IN
590bf215546Sopenharmony_ci                       struct pipe_surface *surface)  // IN
591bf215546Sopenharmony_ci{
592bf215546Sopenharmony_ci   SVGA3dCmdSetRenderTarget *cmd;
593bf215546Sopenharmony_ci
594bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
595bf215546Sopenharmony_ci                            SVGA_3D_CMD_SETRENDERTARGET, sizeof *cmd, 1);
596bf215546Sopenharmony_ci   if (!cmd)
597bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
598bf215546Sopenharmony_ci
599bf215546Sopenharmony_ci   cmd->cid = swc->cid;
600bf215546Sopenharmony_ci   cmd->type = type;
601bf215546Sopenharmony_ci   surface_to_surfaceid(swc, surface, &cmd->target, SVGA_RELOC_WRITE);
602bf215546Sopenharmony_ci   swc->commit(swc);
603bf215546Sopenharmony_ci
604bf215546Sopenharmony_ci   return PIPE_OK;
605bf215546Sopenharmony_ci}
606bf215546Sopenharmony_ci
607bf215546Sopenharmony_ci
608bf215546Sopenharmony_ci/*
609bf215546Sopenharmony_ci *----------------------------------------------------------------------
610bf215546Sopenharmony_ci *
611bf215546Sopenharmony_ci * SVGA3D_DefineShader --
612bf215546Sopenharmony_ci *
613bf215546Sopenharmony_ci *      Upload the bytecode for a new shader. The bytecode is "SVGA3D
614bf215546Sopenharmony_ci *      format", which is theoretically a binary-compatible superset
615bf215546Sopenharmony_ci *      of Microsoft's DirectX shader bytecode. In practice, the
616bf215546Sopenharmony_ci *      SVGA3D bytecode doesn't yet have any extensions to DirectX's
617bf215546Sopenharmony_ci *      bytecode format.
618bf215546Sopenharmony_ci *
619bf215546Sopenharmony_ci *      The SVGA3D device supports shader models 1.1 through 2.0.
620bf215546Sopenharmony_ci *
621bf215546Sopenharmony_ci *      The caller chooses a shader ID (small positive integer) by
622bf215546Sopenharmony_ci *      which this shader will be identified in future commands. This
623bf215546Sopenharmony_ci *      ID is in a namespace which is per-context and per-shader-type.
624bf215546Sopenharmony_ci *
625bf215546Sopenharmony_ci *      'bytecodeLen' is specified in bytes. It must be a multiple of 4.
626bf215546Sopenharmony_ci *
627bf215546Sopenharmony_ci * Results:
628bf215546Sopenharmony_ci *      None.
629bf215546Sopenharmony_ci *
630bf215546Sopenharmony_ci * Side effects:
631bf215546Sopenharmony_ci *      None.
632bf215546Sopenharmony_ci *
633bf215546Sopenharmony_ci *----------------------------------------------------------------------
634bf215546Sopenharmony_ci */
635bf215546Sopenharmony_ci
636bf215546Sopenharmony_cienum pipe_error
637bf215546Sopenharmony_ciSVGA3D_DefineShader(struct svga_winsys_context *swc,
638bf215546Sopenharmony_ci                    uint32 shid,                  // IN
639bf215546Sopenharmony_ci                    SVGA3dShaderType type,        // IN
640bf215546Sopenharmony_ci                    const uint32 *bytecode,       // IN
641bf215546Sopenharmony_ci                    uint32 bytecodeLen)           // IN
642bf215546Sopenharmony_ci{
643bf215546Sopenharmony_ci   SVGA3dCmdDefineShader *cmd;
644bf215546Sopenharmony_ci
645bf215546Sopenharmony_ci   assert(bytecodeLen % 4 == 0);
646bf215546Sopenharmony_ci
647bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
648bf215546Sopenharmony_ci                            SVGA_3D_CMD_SHADER_DEFINE, sizeof *cmd + bytecodeLen,
649bf215546Sopenharmony_ci                            0);
650bf215546Sopenharmony_ci   if (!cmd)
651bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
652bf215546Sopenharmony_ci
653bf215546Sopenharmony_ci   cmd->cid = swc->cid;
654bf215546Sopenharmony_ci   cmd->shid = shid;
655bf215546Sopenharmony_ci   cmd->type = type;
656bf215546Sopenharmony_ci   memcpy(&cmd[1], bytecode, bytecodeLen);
657bf215546Sopenharmony_ci   swc->commit(swc);
658bf215546Sopenharmony_ci
659bf215546Sopenharmony_ci   return PIPE_OK;
660bf215546Sopenharmony_ci}
661bf215546Sopenharmony_ci
662bf215546Sopenharmony_ci
663bf215546Sopenharmony_ci/*
664bf215546Sopenharmony_ci *----------------------------------------------------------------------
665bf215546Sopenharmony_ci *
666bf215546Sopenharmony_ci * SVGA3D_DestroyShader --
667bf215546Sopenharmony_ci *
668bf215546Sopenharmony_ci *      Delete a shader that was created by SVGA3D_DefineShader. If
669bf215546Sopenharmony_ci *      the shader was the current vertex or pixel shader for its
670bf215546Sopenharmony_ci *      context, rendering results are undefined until a new shader is
671bf215546Sopenharmony_ci *      bound.
672bf215546Sopenharmony_ci *
673bf215546Sopenharmony_ci * Results:
674bf215546Sopenharmony_ci *      None.
675bf215546Sopenharmony_ci *
676bf215546Sopenharmony_ci * Side effects:
677bf215546Sopenharmony_ci *      None.
678bf215546Sopenharmony_ci *
679bf215546Sopenharmony_ci *----------------------------------------------------------------------
680bf215546Sopenharmony_ci */
681bf215546Sopenharmony_ci
682bf215546Sopenharmony_cienum pipe_error
683bf215546Sopenharmony_ciSVGA3D_DestroyShader(struct svga_winsys_context *swc,
684bf215546Sopenharmony_ci                     uint32 shid,            // IN
685bf215546Sopenharmony_ci                     SVGA3dShaderType type)  // IN
686bf215546Sopenharmony_ci{
687bf215546Sopenharmony_ci   SVGA3dCmdDestroyShader *cmd;
688bf215546Sopenharmony_ci
689bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
690bf215546Sopenharmony_ci                            SVGA_3D_CMD_SHADER_DESTROY, sizeof *cmd,
691bf215546Sopenharmony_ci                            0);
692bf215546Sopenharmony_ci   if (!cmd)
693bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
694bf215546Sopenharmony_ci
695bf215546Sopenharmony_ci   cmd->cid = swc->cid;
696bf215546Sopenharmony_ci   cmd->shid = shid;
697bf215546Sopenharmony_ci   cmd->type = type;
698bf215546Sopenharmony_ci   swc->commit(swc);
699bf215546Sopenharmony_ci
700bf215546Sopenharmony_ci   return PIPE_OK;
701bf215546Sopenharmony_ci}
702bf215546Sopenharmony_ci
703bf215546Sopenharmony_ci
704bf215546Sopenharmony_ci/*
705bf215546Sopenharmony_ci *----------------------------------------------------------------------
706bf215546Sopenharmony_ci *
707bf215546Sopenharmony_ci * SVGA3D_SetShaderConst --
708bf215546Sopenharmony_ci *
709bf215546Sopenharmony_ci *      Set the value of a shader constant.
710bf215546Sopenharmony_ci *
711bf215546Sopenharmony_ci *      Shader constants are analogous to uniform variables in GLSL,
712bf215546Sopenharmony_ci *      except that they belong to the render context rather than to
713bf215546Sopenharmony_ci *      an individual shader.
714bf215546Sopenharmony_ci *
715bf215546Sopenharmony_ci *      Constants may have one of three types: A 4-vector of floats,
716bf215546Sopenharmony_ci *      a 4-vector of integers, or a single boolean flag.
717bf215546Sopenharmony_ci *
718bf215546Sopenharmony_ci * Results:
719bf215546Sopenharmony_ci *      None.
720bf215546Sopenharmony_ci *
721bf215546Sopenharmony_ci * Side effects:
722bf215546Sopenharmony_ci *      None.
723bf215546Sopenharmony_ci *
724bf215546Sopenharmony_ci *----------------------------------------------------------------------
725bf215546Sopenharmony_ci */
726bf215546Sopenharmony_ci
727bf215546Sopenharmony_cienum pipe_error
728bf215546Sopenharmony_ciSVGA3D_SetShaderConst(struct svga_winsys_context *swc,
729bf215546Sopenharmony_ci                      uint32 reg,                   // IN
730bf215546Sopenharmony_ci                      SVGA3dShaderType type,        // IN
731bf215546Sopenharmony_ci                      SVGA3dShaderConstType ctype,  // IN
732bf215546Sopenharmony_ci                      const void *value)            // IN
733bf215546Sopenharmony_ci{
734bf215546Sopenharmony_ci   SVGA3dCmdSetShaderConst *cmd;
735bf215546Sopenharmony_ci
736bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
737bf215546Sopenharmony_ci                            SVGA_3D_CMD_SET_SHADER_CONST, sizeof *cmd,
738bf215546Sopenharmony_ci                            0);
739bf215546Sopenharmony_ci   if (!cmd)
740bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
741bf215546Sopenharmony_ci
742bf215546Sopenharmony_ci   cmd->cid = swc->cid;
743bf215546Sopenharmony_ci   cmd->reg = reg;
744bf215546Sopenharmony_ci   cmd->type = type;
745bf215546Sopenharmony_ci   cmd->ctype = ctype;
746bf215546Sopenharmony_ci
747bf215546Sopenharmony_ci   switch (ctype) {
748bf215546Sopenharmony_ci
749bf215546Sopenharmony_ci   case SVGA3D_CONST_TYPE_FLOAT:
750bf215546Sopenharmony_ci   case SVGA3D_CONST_TYPE_INT:
751bf215546Sopenharmony_ci      memcpy(&cmd->values, value, sizeof cmd->values);
752bf215546Sopenharmony_ci      break;
753bf215546Sopenharmony_ci
754bf215546Sopenharmony_ci   case SVGA3D_CONST_TYPE_BOOL:
755bf215546Sopenharmony_ci      memset(&cmd->values, 0, sizeof cmd->values);
756bf215546Sopenharmony_ci      cmd->values[0] = *(uint32*)value;
757bf215546Sopenharmony_ci      break;
758bf215546Sopenharmony_ci
759bf215546Sopenharmony_ci   default:
760bf215546Sopenharmony_ci      assert(0);
761bf215546Sopenharmony_ci      break;
762bf215546Sopenharmony_ci
763bf215546Sopenharmony_ci   }
764bf215546Sopenharmony_ci   swc->commit(swc);
765bf215546Sopenharmony_ci
766bf215546Sopenharmony_ci   return PIPE_OK;
767bf215546Sopenharmony_ci}
768bf215546Sopenharmony_ci
769bf215546Sopenharmony_ci
770bf215546Sopenharmony_ci/*
771bf215546Sopenharmony_ci *----------------------------------------------------------------------
772bf215546Sopenharmony_ci *
773bf215546Sopenharmony_ci * SVGA3D_SetShaderConsts --
774bf215546Sopenharmony_ci *
775bf215546Sopenharmony_ci *      Set the value of successive shader constants.
776bf215546Sopenharmony_ci *
777bf215546Sopenharmony_ci *      Shader constants are analogous to uniform variables in GLSL,
778bf215546Sopenharmony_ci *      except that they belong to the render context rather than to
779bf215546Sopenharmony_ci *      an individual shader.
780bf215546Sopenharmony_ci *
781bf215546Sopenharmony_ci *      Constants may have one of three types: A 4-vector of floats,
782bf215546Sopenharmony_ci *      a 4-vector of integers, or a single boolean flag.
783bf215546Sopenharmony_ci *
784bf215546Sopenharmony_ci * Results:
785bf215546Sopenharmony_ci *      None.
786bf215546Sopenharmony_ci *
787bf215546Sopenharmony_ci * Side effects:
788bf215546Sopenharmony_ci *      None.
789bf215546Sopenharmony_ci *
790bf215546Sopenharmony_ci *----------------------------------------------------------------------
791bf215546Sopenharmony_ci */
792bf215546Sopenharmony_ci
793bf215546Sopenharmony_cienum pipe_error
794bf215546Sopenharmony_ciSVGA3D_SetShaderConsts(struct svga_winsys_context *swc,
795bf215546Sopenharmony_ci                        uint32 reg,                   // IN
796bf215546Sopenharmony_ci                        uint32 numRegs,               // IN
797bf215546Sopenharmony_ci                        SVGA3dShaderType type,        // IN
798bf215546Sopenharmony_ci                        SVGA3dShaderConstType ctype,  // IN
799bf215546Sopenharmony_ci                        const void *values)           // IN
800bf215546Sopenharmony_ci{
801bf215546Sopenharmony_ci   SVGA3dCmdSetShaderConst *cmd;
802bf215546Sopenharmony_ci
803bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
804bf215546Sopenharmony_ci                            SVGA_3D_CMD_SET_SHADER_CONST,
805bf215546Sopenharmony_ci                            sizeof *cmd + (numRegs - 1) * sizeof cmd->values,
806bf215546Sopenharmony_ci                            0);
807bf215546Sopenharmony_ci   if (!cmd)
808bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
809bf215546Sopenharmony_ci
810bf215546Sopenharmony_ci   cmd->cid = swc->cid;
811bf215546Sopenharmony_ci   cmd->reg = reg;
812bf215546Sopenharmony_ci   cmd->type = type;
813bf215546Sopenharmony_ci   cmd->ctype = ctype;
814bf215546Sopenharmony_ci
815bf215546Sopenharmony_ci   memcpy(&cmd->values, values, numRegs * sizeof cmd->values);
816bf215546Sopenharmony_ci
817bf215546Sopenharmony_ci   swc->commit(swc);
818bf215546Sopenharmony_ci
819bf215546Sopenharmony_ci   return PIPE_OK;
820bf215546Sopenharmony_ci}
821bf215546Sopenharmony_ci
822bf215546Sopenharmony_ci
823bf215546Sopenharmony_ci
824bf215546Sopenharmony_ci
825bf215546Sopenharmony_ci
826bf215546Sopenharmony_ci/*
827bf215546Sopenharmony_ci *----------------------------------------------------------------------
828bf215546Sopenharmony_ci *
829bf215546Sopenharmony_ci * SVGA3D_SetShader --
830bf215546Sopenharmony_ci *
831bf215546Sopenharmony_ci *      Switch active shaders. This binds a new vertex or pixel shader
832bf215546Sopenharmony_ci *      to the specified context.
833bf215546Sopenharmony_ci *
834bf215546Sopenharmony_ci *      A shader ID of SVGA3D_INVALID_ID unbinds any shader, switching
835bf215546Sopenharmony_ci *      back to the fixed function vertex or pixel pipeline.
836bf215546Sopenharmony_ci *
837bf215546Sopenharmony_ci * Results:
838bf215546Sopenharmony_ci *      None.
839bf215546Sopenharmony_ci *
840bf215546Sopenharmony_ci * Side effects:
841bf215546Sopenharmony_ci *      None.
842bf215546Sopenharmony_ci *
843bf215546Sopenharmony_ci *----------------------------------------------------------------------
844bf215546Sopenharmony_ci */
845bf215546Sopenharmony_ci
846bf215546Sopenharmony_cienum pipe_error
847bf215546Sopenharmony_ciSVGA3D_SetShader(struct svga_winsys_context *swc,
848bf215546Sopenharmony_ci                 SVGA3dShaderType type,  // IN
849bf215546Sopenharmony_ci                 uint32 shid)            // IN
850bf215546Sopenharmony_ci{
851bf215546Sopenharmony_ci   SVGA3dCmdSetShader *cmd;
852bf215546Sopenharmony_ci
853bf215546Sopenharmony_ci   assert(type == SVGA3D_SHADERTYPE_VS || type == SVGA3D_SHADERTYPE_PS);
854bf215546Sopenharmony_ci
855bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
856bf215546Sopenharmony_ci                            SVGA_3D_CMD_SET_SHADER, sizeof *cmd,
857bf215546Sopenharmony_ci                            0);
858bf215546Sopenharmony_ci   if (!cmd)
859bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
860bf215546Sopenharmony_ci
861bf215546Sopenharmony_ci   cmd->cid = swc->cid;
862bf215546Sopenharmony_ci   cmd->type = type;
863bf215546Sopenharmony_ci   cmd->shid = shid;
864bf215546Sopenharmony_ci   swc->commit(swc);
865bf215546Sopenharmony_ci
866bf215546Sopenharmony_ci   return PIPE_OK;
867bf215546Sopenharmony_ci}
868bf215546Sopenharmony_ci
869bf215546Sopenharmony_ci
870bf215546Sopenharmony_ci/*
871bf215546Sopenharmony_ci *----------------------------------------------------------------------
872bf215546Sopenharmony_ci *
873bf215546Sopenharmony_ci * SVGA3D_BeginClear --
874bf215546Sopenharmony_ci *
875bf215546Sopenharmony_ci *      Begin a CLEAR command. This reserves space for it in the FIFO,
876bf215546Sopenharmony_ci *      and returns a pointer to the command's rectangle array.  This
877bf215546Sopenharmony_ci *      function must be paired with SVGA_FIFOCommitAll().
878bf215546Sopenharmony_ci *
879bf215546Sopenharmony_ci *      Clear is a rendering operation which fills a list of
880bf215546Sopenharmony_ci *      rectangles with constant values on all render target types
881bf215546Sopenharmony_ci *      indicated by 'flags'.
882bf215546Sopenharmony_ci *
883bf215546Sopenharmony_ci *      Clear is not affected by clipping, depth test, or other
884bf215546Sopenharmony_ci *      render state which affects the fragment pipeline.
885bf215546Sopenharmony_ci *
886bf215546Sopenharmony_ci * Results:
887bf215546Sopenharmony_ci *      None.
888bf215546Sopenharmony_ci *
889bf215546Sopenharmony_ci * Side effects:
890bf215546Sopenharmony_ci *      May write to attached render target surfaces.
891bf215546Sopenharmony_ci *
892bf215546Sopenharmony_ci *----------------------------------------------------------------------
893bf215546Sopenharmony_ci */
894bf215546Sopenharmony_ci
895bf215546Sopenharmony_cienum pipe_error
896bf215546Sopenharmony_ciSVGA3D_BeginClear(struct svga_winsys_context *swc,
897bf215546Sopenharmony_ci                  SVGA3dClearFlag flags,  // IN
898bf215546Sopenharmony_ci                  uint32 color,           // IN
899bf215546Sopenharmony_ci                  float depth,            // IN
900bf215546Sopenharmony_ci                  uint32 stencil,         // IN
901bf215546Sopenharmony_ci                  SVGA3dRect **rects,     // OUT
902bf215546Sopenharmony_ci                  uint32 numRects)        // IN
903bf215546Sopenharmony_ci{
904bf215546Sopenharmony_ci   SVGA3dCmdClear *cmd;
905bf215546Sopenharmony_ci
906bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
907bf215546Sopenharmony_ci                            SVGA_3D_CMD_CLEAR,
908bf215546Sopenharmony_ci                            sizeof *cmd + sizeof **rects * numRects,
909bf215546Sopenharmony_ci                            0);
910bf215546Sopenharmony_ci   if (!cmd)
911bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
912bf215546Sopenharmony_ci
913bf215546Sopenharmony_ci   cmd->cid = swc->cid;
914bf215546Sopenharmony_ci   cmd->clearFlag = flags;
915bf215546Sopenharmony_ci   cmd->color = color;
916bf215546Sopenharmony_ci   cmd->depth = depth;
917bf215546Sopenharmony_ci   cmd->stencil = stencil;
918bf215546Sopenharmony_ci   *rects = (SVGA3dRect*) &cmd[1];
919bf215546Sopenharmony_ci
920bf215546Sopenharmony_ci   return PIPE_OK;
921bf215546Sopenharmony_ci}
922bf215546Sopenharmony_ci
923bf215546Sopenharmony_ci
924bf215546Sopenharmony_ci/*
925bf215546Sopenharmony_ci *----------------------------------------------------------------------
926bf215546Sopenharmony_ci *
927bf215546Sopenharmony_ci * SVGA3D_ClearRect --
928bf215546Sopenharmony_ci *
929bf215546Sopenharmony_ci *      This is a simplified version of SVGA3D_BeginClear().
930bf215546Sopenharmony_ci *
931bf215546Sopenharmony_ci * Results:
932bf215546Sopenharmony_ci *      None.
933bf215546Sopenharmony_ci *
934bf215546Sopenharmony_ci * Side effects:
935bf215546Sopenharmony_ci *      None.
936bf215546Sopenharmony_ci *
937bf215546Sopenharmony_ci *----------------------------------------------------------------------
938bf215546Sopenharmony_ci */
939bf215546Sopenharmony_ci
940bf215546Sopenharmony_cienum pipe_error
941bf215546Sopenharmony_ciSVGA3D_ClearRect(struct svga_winsys_context *swc,
942bf215546Sopenharmony_ci                 SVGA3dClearFlag flags,  // IN
943bf215546Sopenharmony_ci                 uint32 color,           // IN
944bf215546Sopenharmony_ci                 float depth,            // IN
945bf215546Sopenharmony_ci                 uint32 stencil,         // IN
946bf215546Sopenharmony_ci                 uint32 x,               // IN
947bf215546Sopenharmony_ci                 uint32 y,               // IN
948bf215546Sopenharmony_ci                 uint32 w,               // IN
949bf215546Sopenharmony_ci                 uint32 h)               // IN
950bf215546Sopenharmony_ci{
951bf215546Sopenharmony_ci   SVGA3dRect *rect;
952bf215546Sopenharmony_ci   enum pipe_error ret;
953bf215546Sopenharmony_ci
954bf215546Sopenharmony_ci   ret = SVGA3D_BeginClear(swc, flags, color, depth, stencil, &rect, 1);
955bf215546Sopenharmony_ci   if (ret != PIPE_OK)
956bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
957bf215546Sopenharmony_ci
958bf215546Sopenharmony_ci   memset(rect, 0, sizeof *rect);
959bf215546Sopenharmony_ci   rect->x = x;
960bf215546Sopenharmony_ci   rect->y = y;
961bf215546Sopenharmony_ci   rect->w = w;
962bf215546Sopenharmony_ci   rect->h = h;
963bf215546Sopenharmony_ci   swc->commit(swc);
964bf215546Sopenharmony_ci
965bf215546Sopenharmony_ci   return PIPE_OK;
966bf215546Sopenharmony_ci}
967bf215546Sopenharmony_ci
968bf215546Sopenharmony_ci
969bf215546Sopenharmony_ci/*
970bf215546Sopenharmony_ci *----------------------------------------------------------------------
971bf215546Sopenharmony_ci *
972bf215546Sopenharmony_ci * SVGA3D_BeginDrawPrimitives --
973bf215546Sopenharmony_ci *
974bf215546Sopenharmony_ci *      Begin a DRAW_PRIMITIVES command. This reserves space for it in
975bf215546Sopenharmony_ci *      the FIFO, and returns a pointer to the command's arrays.
976bf215546Sopenharmony_ci *      This function must be paired with SVGA_FIFOCommitAll().
977bf215546Sopenharmony_ci *
978bf215546Sopenharmony_ci *      Drawing commands consist of two variable-length arrays:
979bf215546Sopenharmony_ci *      SVGA3dVertexDecl elements declare a set of vertex buffers to
980bf215546Sopenharmony_ci *      use while rendering, and SVGA3dPrimitiveRange elements specify
981bf215546Sopenharmony_ci *      groups of primitives each with an optional index buffer.
982bf215546Sopenharmony_ci *
983bf215546Sopenharmony_ci *      The decls and ranges arrays are initialized to zero.
984bf215546Sopenharmony_ci *
985bf215546Sopenharmony_ci * Results:
986bf215546Sopenharmony_ci *      None.
987bf215546Sopenharmony_ci *
988bf215546Sopenharmony_ci * Side effects:
989bf215546Sopenharmony_ci *      May write to attached render target surfaces.
990bf215546Sopenharmony_ci *
991bf215546Sopenharmony_ci *----------------------------------------------------------------------
992bf215546Sopenharmony_ci */
993bf215546Sopenharmony_ci
994bf215546Sopenharmony_cienum pipe_error
995bf215546Sopenharmony_ciSVGA3D_BeginDrawPrimitives(struct svga_winsys_context *swc,
996bf215546Sopenharmony_ci                           SVGA3dVertexDecl **decls,      // OUT
997bf215546Sopenharmony_ci                           uint32 numVertexDecls,         // IN
998bf215546Sopenharmony_ci                           SVGA3dPrimitiveRange **ranges, // OUT
999bf215546Sopenharmony_ci                           uint32 numRanges)              // IN
1000bf215546Sopenharmony_ci{
1001bf215546Sopenharmony_ci   SVGA3dCmdDrawPrimitives *cmd;
1002bf215546Sopenharmony_ci   SVGA3dVertexDecl *declArray;
1003bf215546Sopenharmony_ci   SVGA3dPrimitiveRange *rangeArray;
1004bf215546Sopenharmony_ci   uint32 declSize = sizeof **decls * numVertexDecls;
1005bf215546Sopenharmony_ci   uint32 rangeSize = sizeof **ranges * numRanges;
1006bf215546Sopenharmony_ci
1007bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1008bf215546Sopenharmony_ci                            SVGA_3D_CMD_DRAW_PRIMITIVES,
1009bf215546Sopenharmony_ci                            sizeof *cmd + declSize + rangeSize,
1010bf215546Sopenharmony_ci                            numVertexDecls + numRanges);
1011bf215546Sopenharmony_ci   if (!cmd)
1012bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1013bf215546Sopenharmony_ci
1014bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1015bf215546Sopenharmony_ci   cmd->numVertexDecls = numVertexDecls;
1016bf215546Sopenharmony_ci   cmd->numRanges = numRanges;
1017bf215546Sopenharmony_ci
1018bf215546Sopenharmony_ci   declArray = (SVGA3dVertexDecl*) &cmd[1];
1019bf215546Sopenharmony_ci   rangeArray = (SVGA3dPrimitiveRange*) &declArray[numVertexDecls];
1020bf215546Sopenharmony_ci
1021bf215546Sopenharmony_ci   memset(declArray, 0, declSize);
1022bf215546Sopenharmony_ci   memset(rangeArray, 0, rangeSize);
1023bf215546Sopenharmony_ci
1024bf215546Sopenharmony_ci   *decls = declArray;
1025bf215546Sopenharmony_ci   *ranges = rangeArray;
1026bf215546Sopenharmony_ci
1027bf215546Sopenharmony_ci   swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH;
1028bf215546Sopenharmony_ci
1029bf215546Sopenharmony_ci   swc->num_draw_commands++;
1030bf215546Sopenharmony_ci
1031bf215546Sopenharmony_ci   return PIPE_OK;
1032bf215546Sopenharmony_ci}
1033bf215546Sopenharmony_ci
1034bf215546Sopenharmony_ci
1035bf215546Sopenharmony_ci/*
1036bf215546Sopenharmony_ci *----------------------------------------------------------------------
1037bf215546Sopenharmony_ci *
1038bf215546Sopenharmony_ci * SVGA3D_BeginSurfaceCopy --
1039bf215546Sopenharmony_ci *
1040bf215546Sopenharmony_ci *      Begin a SURFACE_COPY command. This reserves space for it in
1041bf215546Sopenharmony_ci *      the FIFO, and returns a pointer to the command's arrays.  This
1042bf215546Sopenharmony_ci *      function must be paired with SVGA_FIFOCommitAll().
1043bf215546Sopenharmony_ci *
1044bf215546Sopenharmony_ci *      The box array is initialized with zeroes.
1045bf215546Sopenharmony_ci *
1046bf215546Sopenharmony_ci * Results:
1047bf215546Sopenharmony_ci *      None.
1048bf215546Sopenharmony_ci *
1049bf215546Sopenharmony_ci * Side effects:
1050bf215546Sopenharmony_ci *      Asynchronously copies a list of boxes from surface to surface.
1051bf215546Sopenharmony_ci *
1052bf215546Sopenharmony_ci *----------------------------------------------------------------------
1053bf215546Sopenharmony_ci */
1054bf215546Sopenharmony_ci
1055bf215546Sopenharmony_cienum pipe_error
1056bf215546Sopenharmony_ciSVGA3D_BeginSurfaceCopy(struct svga_winsys_context *swc,
1057bf215546Sopenharmony_ci                        struct pipe_surface *src,    // IN
1058bf215546Sopenharmony_ci                        struct pipe_surface *dest,   // IN
1059bf215546Sopenharmony_ci                        SVGA3dCopyBox **boxes,       // OUT
1060bf215546Sopenharmony_ci                        uint32 numBoxes)             // IN
1061bf215546Sopenharmony_ci{
1062bf215546Sopenharmony_ci   SVGA3dCmdSurfaceCopy *cmd;
1063bf215546Sopenharmony_ci   uint32 boxesSize = sizeof **boxes * numBoxes;
1064bf215546Sopenharmony_ci
1065bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1066bf215546Sopenharmony_ci                            SVGA_3D_CMD_SURFACE_COPY, sizeof *cmd + boxesSize,
1067bf215546Sopenharmony_ci                            2);
1068bf215546Sopenharmony_ci   if (!cmd)
1069bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1070bf215546Sopenharmony_ci
1071bf215546Sopenharmony_ci   surface_to_surfaceid(swc, src, &cmd->src, SVGA_RELOC_READ);
1072bf215546Sopenharmony_ci   surface_to_surfaceid(swc, dest, &cmd->dest, SVGA_RELOC_WRITE);
1073bf215546Sopenharmony_ci   *boxes = (SVGA3dCopyBox*) &cmd[1];
1074bf215546Sopenharmony_ci
1075bf215546Sopenharmony_ci   memset(*boxes, 0, boxesSize);
1076bf215546Sopenharmony_ci
1077bf215546Sopenharmony_ci   return PIPE_OK;
1078bf215546Sopenharmony_ci}
1079bf215546Sopenharmony_ci
1080bf215546Sopenharmony_ci
1081bf215546Sopenharmony_ci/*
1082bf215546Sopenharmony_ci *----------------------------------------------------------------------
1083bf215546Sopenharmony_ci *
1084bf215546Sopenharmony_ci * SVGA3D_SurfaceStretchBlt --
1085bf215546Sopenharmony_ci *
1086bf215546Sopenharmony_ci *      Issue a SURFACE_STRETCHBLT command: an asynchronous
1087bf215546Sopenharmony_ci *      surface-to-surface blit, with scaling.
1088bf215546Sopenharmony_ci *
1089bf215546Sopenharmony_ci * Results:
1090bf215546Sopenharmony_ci *      None.
1091bf215546Sopenharmony_ci *
1092bf215546Sopenharmony_ci * Side effects:
1093bf215546Sopenharmony_ci *      Asynchronously copies one box from surface to surface.
1094bf215546Sopenharmony_ci *
1095bf215546Sopenharmony_ci *----------------------------------------------------------------------
1096bf215546Sopenharmony_ci */
1097bf215546Sopenharmony_ci
1098bf215546Sopenharmony_cienum pipe_error
1099bf215546Sopenharmony_ciSVGA3D_SurfaceStretchBlt(struct svga_winsys_context *swc,
1100bf215546Sopenharmony_ci                         struct pipe_surface *src,    // IN
1101bf215546Sopenharmony_ci                         struct pipe_surface *dest,   // IN
1102bf215546Sopenharmony_ci                         SVGA3dBox *boxSrc,           // IN
1103bf215546Sopenharmony_ci                         SVGA3dBox *boxDest,          // IN
1104bf215546Sopenharmony_ci                         SVGA3dStretchBltMode mode)   // IN
1105bf215546Sopenharmony_ci{
1106bf215546Sopenharmony_ci   SVGA3dCmdSurfaceStretchBlt *cmd;
1107bf215546Sopenharmony_ci
1108bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1109bf215546Sopenharmony_ci                            SVGA_3D_CMD_SURFACE_STRETCHBLT, sizeof *cmd,
1110bf215546Sopenharmony_ci                            2);
1111bf215546Sopenharmony_ci   if (!cmd)
1112bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1113bf215546Sopenharmony_ci
1114bf215546Sopenharmony_ci   surface_to_surfaceid(swc, src, &cmd->src, SVGA_RELOC_READ);
1115bf215546Sopenharmony_ci   surface_to_surfaceid(swc, dest, &cmd->dest, SVGA_RELOC_WRITE);
1116bf215546Sopenharmony_ci   cmd->boxSrc = *boxSrc;
1117bf215546Sopenharmony_ci   cmd->boxDest = *boxDest;
1118bf215546Sopenharmony_ci   cmd->mode = mode;
1119bf215546Sopenharmony_ci   swc->commit(swc);
1120bf215546Sopenharmony_ci
1121bf215546Sopenharmony_ci   return PIPE_OK;
1122bf215546Sopenharmony_ci}
1123bf215546Sopenharmony_ci
1124bf215546Sopenharmony_ci
1125bf215546Sopenharmony_ci/*
1126bf215546Sopenharmony_ci *----------------------------------------------------------------------
1127bf215546Sopenharmony_ci *
1128bf215546Sopenharmony_ci * SVGA3D_SetViewport --
1129bf215546Sopenharmony_ci *
1130bf215546Sopenharmony_ci *      Set the current context's viewport rectangle. The viewport
1131bf215546Sopenharmony_ci *      is clipped to the dimensions of the current render target,
1132bf215546Sopenharmony_ci *      then all rendering is clipped to the viewport.
1133bf215546Sopenharmony_ci *
1134bf215546Sopenharmony_ci * Results:
1135bf215546Sopenharmony_ci *      None.
1136bf215546Sopenharmony_ci *
1137bf215546Sopenharmony_ci * Side effects:
1138bf215546Sopenharmony_ci *      None.
1139bf215546Sopenharmony_ci *
1140bf215546Sopenharmony_ci *----------------------------------------------------------------------
1141bf215546Sopenharmony_ci */
1142bf215546Sopenharmony_ci
1143bf215546Sopenharmony_cienum pipe_error
1144bf215546Sopenharmony_ciSVGA3D_SetViewport(struct svga_winsys_context *swc,
1145bf215546Sopenharmony_ci                   SVGA3dRect *rect)  // IN
1146bf215546Sopenharmony_ci{
1147bf215546Sopenharmony_ci   SVGA3dCmdSetViewport *cmd;
1148bf215546Sopenharmony_ci
1149bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1150bf215546Sopenharmony_ci                            SVGA_3D_CMD_SETVIEWPORT, sizeof *cmd,
1151bf215546Sopenharmony_ci                            0);
1152bf215546Sopenharmony_ci   if (!cmd)
1153bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1154bf215546Sopenharmony_ci
1155bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1156bf215546Sopenharmony_ci   cmd->rect = *rect;
1157bf215546Sopenharmony_ci   swc->commit(swc);
1158bf215546Sopenharmony_ci
1159bf215546Sopenharmony_ci   return PIPE_OK;
1160bf215546Sopenharmony_ci}
1161bf215546Sopenharmony_ci
1162bf215546Sopenharmony_ci
1163bf215546Sopenharmony_ci
1164bf215546Sopenharmony_ci
1165bf215546Sopenharmony_ci/*
1166bf215546Sopenharmony_ci *----------------------------------------------------------------------
1167bf215546Sopenharmony_ci *
1168bf215546Sopenharmony_ci * SVGA3D_SetScissorRect --
1169bf215546Sopenharmony_ci *
1170bf215546Sopenharmony_ci *      Set the current context's scissor rectangle. If scissoring
1171bf215546Sopenharmony_ci *      is enabled then all rendering is clipped to the scissor bounds.
1172bf215546Sopenharmony_ci *
1173bf215546Sopenharmony_ci * Results:
1174bf215546Sopenharmony_ci *      None.
1175bf215546Sopenharmony_ci *
1176bf215546Sopenharmony_ci * Side effects:
1177bf215546Sopenharmony_ci *      None.
1178bf215546Sopenharmony_ci *
1179bf215546Sopenharmony_ci *----------------------------------------------------------------------
1180bf215546Sopenharmony_ci */
1181bf215546Sopenharmony_ci
1182bf215546Sopenharmony_cienum pipe_error
1183bf215546Sopenharmony_ciSVGA3D_SetScissorRect(struct svga_winsys_context *swc,
1184bf215546Sopenharmony_ci                      SVGA3dRect *rect)  // IN
1185bf215546Sopenharmony_ci{
1186bf215546Sopenharmony_ci   SVGA3dCmdSetScissorRect *cmd;
1187bf215546Sopenharmony_ci
1188bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1189bf215546Sopenharmony_ci                            SVGA_3D_CMD_SETSCISSORRECT, sizeof *cmd,
1190bf215546Sopenharmony_ci                            0);
1191bf215546Sopenharmony_ci   if (!cmd)
1192bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1193bf215546Sopenharmony_ci
1194bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1195bf215546Sopenharmony_ci   cmd->rect = *rect;
1196bf215546Sopenharmony_ci   swc->commit(swc);
1197bf215546Sopenharmony_ci
1198bf215546Sopenharmony_ci   return PIPE_OK;
1199bf215546Sopenharmony_ci}
1200bf215546Sopenharmony_ci
1201bf215546Sopenharmony_ci/*
1202bf215546Sopenharmony_ci *----------------------------------------------------------------------
1203bf215546Sopenharmony_ci *
1204bf215546Sopenharmony_ci * SVGA3D_SetClipPlane --
1205bf215546Sopenharmony_ci *
1206bf215546Sopenharmony_ci *      Set one of the current context's clip planes. If the clip
1207bf215546Sopenharmony_ci *      plane is enabled then all 3d rendering is clipped against
1208bf215546Sopenharmony_ci *      the plane.
1209bf215546Sopenharmony_ci *
1210bf215546Sopenharmony_ci * Results:
1211bf215546Sopenharmony_ci *      None.
1212bf215546Sopenharmony_ci *
1213bf215546Sopenharmony_ci * Side effects:
1214bf215546Sopenharmony_ci *      None.
1215bf215546Sopenharmony_ci *
1216bf215546Sopenharmony_ci *----------------------------------------------------------------------
1217bf215546Sopenharmony_ci */
1218bf215546Sopenharmony_ci
1219bf215546Sopenharmony_cienum pipe_error
1220bf215546Sopenharmony_ciSVGA3D_SetClipPlane(struct svga_winsys_context *swc,
1221bf215546Sopenharmony_ci                    uint32 index, const float *plane)
1222bf215546Sopenharmony_ci{
1223bf215546Sopenharmony_ci   SVGA3dCmdSetClipPlane *cmd;
1224bf215546Sopenharmony_ci
1225bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1226bf215546Sopenharmony_ci                            SVGA_3D_CMD_SETCLIPPLANE, sizeof *cmd,
1227bf215546Sopenharmony_ci                            0);
1228bf215546Sopenharmony_ci   if (!cmd)
1229bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1230bf215546Sopenharmony_ci
1231bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1232bf215546Sopenharmony_ci   cmd->index = index;
1233bf215546Sopenharmony_ci   cmd->plane[0] = plane[0];
1234bf215546Sopenharmony_ci   cmd->plane[1] = plane[1];
1235bf215546Sopenharmony_ci   cmd->plane[2] = plane[2];
1236bf215546Sopenharmony_ci   cmd->plane[3] = plane[3];
1237bf215546Sopenharmony_ci   swc->commit(swc);
1238bf215546Sopenharmony_ci
1239bf215546Sopenharmony_ci   return PIPE_OK;
1240bf215546Sopenharmony_ci}
1241bf215546Sopenharmony_ci
1242bf215546Sopenharmony_ci/*
1243bf215546Sopenharmony_ci *----------------------------------------------------------------------
1244bf215546Sopenharmony_ci *
1245bf215546Sopenharmony_ci * SVGA3D_SetZRange --
1246bf215546Sopenharmony_ci *
1247bf215546Sopenharmony_ci *      Set the range of the depth buffer to use. 'min' and 'max'
1248bf215546Sopenharmony_ci *      are values between 0.0 and 1.0.
1249bf215546Sopenharmony_ci *
1250bf215546Sopenharmony_ci * Results:
1251bf215546Sopenharmony_ci *      None.
1252bf215546Sopenharmony_ci *
1253bf215546Sopenharmony_ci * Side effects:
1254bf215546Sopenharmony_ci *      None.
1255bf215546Sopenharmony_ci *
1256bf215546Sopenharmony_ci *----------------------------------------------------------------------
1257bf215546Sopenharmony_ci */
1258bf215546Sopenharmony_ci
1259bf215546Sopenharmony_cienum pipe_error
1260bf215546Sopenharmony_ciSVGA3D_SetZRange(struct svga_winsys_context *swc,
1261bf215546Sopenharmony_ci                 float zMin,  // IN
1262bf215546Sopenharmony_ci                 float zMax)  // IN
1263bf215546Sopenharmony_ci{
1264bf215546Sopenharmony_ci   SVGA3dCmdSetZRange *cmd;
1265bf215546Sopenharmony_ci
1266bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1267bf215546Sopenharmony_ci                            SVGA_3D_CMD_SETZRANGE, sizeof *cmd,
1268bf215546Sopenharmony_ci                            0);
1269bf215546Sopenharmony_ci   if (!cmd)
1270bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1271bf215546Sopenharmony_ci
1272bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1273bf215546Sopenharmony_ci   cmd->zRange.min = zMin;
1274bf215546Sopenharmony_ci   cmd->zRange.max = zMax;
1275bf215546Sopenharmony_ci   swc->commit(swc);
1276bf215546Sopenharmony_ci
1277bf215546Sopenharmony_ci   return PIPE_OK;
1278bf215546Sopenharmony_ci}
1279bf215546Sopenharmony_ci
1280bf215546Sopenharmony_ci
1281bf215546Sopenharmony_ci/*
1282bf215546Sopenharmony_ci *----------------------------------------------------------------------
1283bf215546Sopenharmony_ci *
1284bf215546Sopenharmony_ci * SVGA3D_BeginSetTextureState --
1285bf215546Sopenharmony_ci *
1286bf215546Sopenharmony_ci *      Begin a SETTEXTURESTATE command. This reserves space for it in
1287bf215546Sopenharmony_ci *      the FIFO, and returns a pointer to the command's texture state
1288bf215546Sopenharmony_ci *      array.  This function must be paired with SVGA_FIFOCommitAll().
1289bf215546Sopenharmony_ci *
1290bf215546Sopenharmony_ci *      This command sets rendering state which is per-texture-unit.
1291bf215546Sopenharmony_ci *
1292bf215546Sopenharmony_ci *      XXX: Individual texture states need documentation. However,
1293bf215546Sopenharmony_ci *           they are very similar to the texture states defined by
1294bf215546Sopenharmony_ci *           Direct3D. The D3D documentation is a good starting point
1295bf215546Sopenharmony_ci *           for understanding SVGA3D texture states.
1296bf215546Sopenharmony_ci *
1297bf215546Sopenharmony_ci * Results:
1298bf215546Sopenharmony_ci *      None.
1299bf215546Sopenharmony_ci *
1300bf215546Sopenharmony_ci * Side effects:
1301bf215546Sopenharmony_ci *      None.
1302bf215546Sopenharmony_ci *
1303bf215546Sopenharmony_ci *----------------------------------------------------------------------
1304bf215546Sopenharmony_ci */
1305bf215546Sopenharmony_ci
1306bf215546Sopenharmony_cienum pipe_error
1307bf215546Sopenharmony_ciSVGA3D_BeginSetTextureState(struct svga_winsys_context *swc,
1308bf215546Sopenharmony_ci                            SVGA3dTextureState **states,  // OUT
1309bf215546Sopenharmony_ci                            uint32 numStates)             // IN
1310bf215546Sopenharmony_ci{
1311bf215546Sopenharmony_ci   SVGA3dCmdSetTextureState *cmd;
1312bf215546Sopenharmony_ci
1313bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1314bf215546Sopenharmony_ci                            SVGA_3D_CMD_SETTEXTURESTATE,
1315bf215546Sopenharmony_ci                            sizeof *cmd + sizeof **states * numStates,
1316bf215546Sopenharmony_ci                            numStates);
1317bf215546Sopenharmony_ci   if (!cmd)
1318bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1319bf215546Sopenharmony_ci
1320bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1321bf215546Sopenharmony_ci   *states = (SVGA3dTextureState*) &cmd[1];
1322bf215546Sopenharmony_ci
1323bf215546Sopenharmony_ci   return PIPE_OK;
1324bf215546Sopenharmony_ci}
1325bf215546Sopenharmony_ci
1326bf215546Sopenharmony_ci
1327bf215546Sopenharmony_ci/*
1328bf215546Sopenharmony_ci *----------------------------------------------------------------------
1329bf215546Sopenharmony_ci *
1330bf215546Sopenharmony_ci * SVGA3D_BeginSetRenderState --
1331bf215546Sopenharmony_ci *
1332bf215546Sopenharmony_ci *      Begin a SETRENDERSTATE command. This reserves space for it in
1333bf215546Sopenharmony_ci *      the FIFO, and returns a pointer to the command's texture state
1334bf215546Sopenharmony_ci *      array.  This function must be paired with SVGA_FIFOCommitAll().
1335bf215546Sopenharmony_ci *
1336bf215546Sopenharmony_ci *      This command sets rendering state which is global to the context.
1337bf215546Sopenharmony_ci *
1338bf215546Sopenharmony_ci *      XXX: Individual render states need documentation. However,
1339bf215546Sopenharmony_ci *           they are very similar to the render states defined by
1340bf215546Sopenharmony_ci *           Direct3D. The D3D documentation is a good starting point
1341bf215546Sopenharmony_ci *           for understanding SVGA3D render states.
1342bf215546Sopenharmony_ci *
1343bf215546Sopenharmony_ci * Results:
1344bf215546Sopenharmony_ci *      None.
1345bf215546Sopenharmony_ci *
1346bf215546Sopenharmony_ci * Side effects:
1347bf215546Sopenharmony_ci *      None.
1348bf215546Sopenharmony_ci *
1349bf215546Sopenharmony_ci *----------------------------------------------------------------------
1350bf215546Sopenharmony_ci */
1351bf215546Sopenharmony_ci
1352bf215546Sopenharmony_cienum pipe_error
1353bf215546Sopenharmony_ciSVGA3D_BeginSetRenderState(struct svga_winsys_context *swc,
1354bf215546Sopenharmony_ci                           SVGA3dRenderState **states,  // OUT
1355bf215546Sopenharmony_ci                           uint32 numStates)            // IN
1356bf215546Sopenharmony_ci{
1357bf215546Sopenharmony_ci   SVGA3dCmdSetRenderState *cmd;
1358bf215546Sopenharmony_ci
1359bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1360bf215546Sopenharmony_ci                            SVGA_3D_CMD_SETRENDERSTATE,
1361bf215546Sopenharmony_ci                            sizeof *cmd + sizeof **states * numStates,
1362bf215546Sopenharmony_ci                            0);
1363bf215546Sopenharmony_ci   if (!cmd)
1364bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1365bf215546Sopenharmony_ci
1366bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1367bf215546Sopenharmony_ci   *states = (SVGA3dRenderState*) &cmd[1];
1368bf215546Sopenharmony_ci
1369bf215546Sopenharmony_ci   return PIPE_OK;
1370bf215546Sopenharmony_ci}
1371bf215546Sopenharmony_ci
1372bf215546Sopenharmony_ci
1373bf215546Sopenharmony_ci/*
1374bf215546Sopenharmony_ci *----------------------------------------------------------------------
1375bf215546Sopenharmony_ci *
1376bf215546Sopenharmony_ci * SVGA3D_BeginGBQuery--
1377bf215546Sopenharmony_ci *
1378bf215546Sopenharmony_ci *      GB resource version of SVGA3D_BeginQuery.
1379bf215546Sopenharmony_ci *
1380bf215546Sopenharmony_ci * Results:
1381bf215546Sopenharmony_ci *      None.
1382bf215546Sopenharmony_ci *
1383bf215546Sopenharmony_ci * Side effects:
1384bf215546Sopenharmony_ci *      Commits space in the FIFO memory.
1385bf215546Sopenharmony_ci *
1386bf215546Sopenharmony_ci *----------------------------------------------------------------------
1387bf215546Sopenharmony_ci */
1388bf215546Sopenharmony_ci
1389bf215546Sopenharmony_cistatic enum pipe_error
1390bf215546Sopenharmony_ciSVGA3D_BeginGBQuery(struct svga_winsys_context *swc,
1391bf215546Sopenharmony_ci		    SVGA3dQueryType type) // IN
1392bf215546Sopenharmony_ci{
1393bf215546Sopenharmony_ci   SVGA3dCmdBeginGBQuery *cmd;
1394bf215546Sopenharmony_ci
1395bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1396bf215546Sopenharmony_ci                            SVGA_3D_CMD_BEGIN_GB_QUERY,
1397bf215546Sopenharmony_ci                            sizeof *cmd,
1398bf215546Sopenharmony_ci                            1);
1399bf215546Sopenharmony_ci   if (!cmd)
1400bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1401bf215546Sopenharmony_ci
1402bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1403bf215546Sopenharmony_ci   cmd->type = type;
1404bf215546Sopenharmony_ci
1405bf215546Sopenharmony_ci   swc->commit(swc);
1406bf215546Sopenharmony_ci
1407bf215546Sopenharmony_ci   return PIPE_OK;
1408bf215546Sopenharmony_ci}
1409bf215546Sopenharmony_ci
1410bf215546Sopenharmony_ci
1411bf215546Sopenharmony_ci/*
1412bf215546Sopenharmony_ci *----------------------------------------------------------------------
1413bf215546Sopenharmony_ci *
1414bf215546Sopenharmony_ci * SVGA3D_BeginQuery--
1415bf215546Sopenharmony_ci *
1416bf215546Sopenharmony_ci *      Issues a SVGA_3D_CMD_BEGIN_QUERY command.
1417bf215546Sopenharmony_ci *
1418bf215546Sopenharmony_ci * Results:
1419bf215546Sopenharmony_ci *      None.
1420bf215546Sopenharmony_ci *
1421bf215546Sopenharmony_ci * Side effects:
1422bf215546Sopenharmony_ci *      Commits space in the FIFO memory.
1423bf215546Sopenharmony_ci *
1424bf215546Sopenharmony_ci *----------------------------------------------------------------------
1425bf215546Sopenharmony_ci */
1426bf215546Sopenharmony_ci
1427bf215546Sopenharmony_cienum pipe_error
1428bf215546Sopenharmony_ciSVGA3D_BeginQuery(struct svga_winsys_context *swc,
1429bf215546Sopenharmony_ci                  SVGA3dQueryType type) // IN
1430bf215546Sopenharmony_ci{
1431bf215546Sopenharmony_ci   SVGA3dCmdBeginQuery *cmd;
1432bf215546Sopenharmony_ci
1433bf215546Sopenharmony_ci   if (swc->have_gb_objects)
1434bf215546Sopenharmony_ci      return SVGA3D_BeginGBQuery(swc, type);
1435bf215546Sopenharmony_ci
1436bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1437bf215546Sopenharmony_ci                            SVGA_3D_CMD_BEGIN_QUERY,
1438bf215546Sopenharmony_ci                            sizeof *cmd,
1439bf215546Sopenharmony_ci                            0);
1440bf215546Sopenharmony_ci   if (!cmd)
1441bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1442bf215546Sopenharmony_ci
1443bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1444bf215546Sopenharmony_ci   cmd->type = type;
1445bf215546Sopenharmony_ci
1446bf215546Sopenharmony_ci   swc->commit(swc);
1447bf215546Sopenharmony_ci
1448bf215546Sopenharmony_ci   return PIPE_OK;
1449bf215546Sopenharmony_ci}
1450bf215546Sopenharmony_ci
1451bf215546Sopenharmony_ci
1452bf215546Sopenharmony_ci/*
1453bf215546Sopenharmony_ci *----------------------------------------------------------------------
1454bf215546Sopenharmony_ci *
1455bf215546Sopenharmony_ci * SVGA3D_EndGBQuery--
1456bf215546Sopenharmony_ci *
1457bf215546Sopenharmony_ci *      GB resource version of SVGA3D_EndQuery.
1458bf215546Sopenharmony_ci *
1459bf215546Sopenharmony_ci * Results:
1460bf215546Sopenharmony_ci *      None.
1461bf215546Sopenharmony_ci *
1462bf215546Sopenharmony_ci * Side effects:
1463bf215546Sopenharmony_ci *      Commits space in the FIFO memory.
1464bf215546Sopenharmony_ci *
1465bf215546Sopenharmony_ci *----------------------------------------------------------------------
1466bf215546Sopenharmony_ci */
1467bf215546Sopenharmony_ci
1468bf215546Sopenharmony_cistatic enum pipe_error
1469bf215546Sopenharmony_ciSVGA3D_EndGBQuery(struct svga_winsys_context *swc,
1470bf215546Sopenharmony_ci		  SVGA3dQueryType type,              // IN
1471bf215546Sopenharmony_ci		  struct svga_winsys_buffer *buffer) // IN/OUT
1472bf215546Sopenharmony_ci{
1473bf215546Sopenharmony_ci   SVGA3dCmdEndGBQuery *cmd;
1474bf215546Sopenharmony_ci
1475bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1476bf215546Sopenharmony_ci                            SVGA_3D_CMD_END_GB_QUERY,
1477bf215546Sopenharmony_ci                            sizeof *cmd,
1478bf215546Sopenharmony_ci                            2);
1479bf215546Sopenharmony_ci   if (!cmd)
1480bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1481bf215546Sopenharmony_ci
1482bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1483bf215546Sopenharmony_ci   cmd->type = type;
1484bf215546Sopenharmony_ci
1485bf215546Sopenharmony_ci   swc->mob_relocation(swc, &cmd->mobid, &cmd->offset, buffer,
1486bf215546Sopenharmony_ci		       0, SVGA_RELOC_READ | SVGA_RELOC_WRITE);
1487bf215546Sopenharmony_ci
1488bf215546Sopenharmony_ci   swc->commit(swc);
1489bf215546Sopenharmony_ci
1490bf215546Sopenharmony_ci   return PIPE_OK;
1491bf215546Sopenharmony_ci}
1492bf215546Sopenharmony_ci
1493bf215546Sopenharmony_ci
1494bf215546Sopenharmony_ci/*
1495bf215546Sopenharmony_ci *----------------------------------------------------------------------
1496bf215546Sopenharmony_ci *
1497bf215546Sopenharmony_ci * SVGA3D_EndQuery--
1498bf215546Sopenharmony_ci *
1499bf215546Sopenharmony_ci *      Issues a SVGA_3D_CMD_END_QUERY command.
1500bf215546Sopenharmony_ci *
1501bf215546Sopenharmony_ci * Results:
1502bf215546Sopenharmony_ci *      None.
1503bf215546Sopenharmony_ci *
1504bf215546Sopenharmony_ci * Side effects:
1505bf215546Sopenharmony_ci *      Commits space in the FIFO memory.
1506bf215546Sopenharmony_ci *
1507bf215546Sopenharmony_ci *----------------------------------------------------------------------
1508bf215546Sopenharmony_ci */
1509bf215546Sopenharmony_ci
1510bf215546Sopenharmony_cienum pipe_error
1511bf215546Sopenharmony_ciSVGA3D_EndQuery(struct svga_winsys_context *swc,
1512bf215546Sopenharmony_ci                SVGA3dQueryType type,              // IN
1513bf215546Sopenharmony_ci                struct svga_winsys_buffer *buffer) // IN/OUT
1514bf215546Sopenharmony_ci{
1515bf215546Sopenharmony_ci   SVGA3dCmdEndQuery *cmd;
1516bf215546Sopenharmony_ci
1517bf215546Sopenharmony_ci   if (swc->have_gb_objects)
1518bf215546Sopenharmony_ci      return SVGA3D_EndGBQuery(swc, type, buffer);
1519bf215546Sopenharmony_ci
1520bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1521bf215546Sopenharmony_ci                            SVGA_3D_CMD_END_QUERY,
1522bf215546Sopenharmony_ci                            sizeof *cmd,
1523bf215546Sopenharmony_ci                            1);
1524bf215546Sopenharmony_ci   if (!cmd)
1525bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1526bf215546Sopenharmony_ci
1527bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1528bf215546Sopenharmony_ci   cmd->type = type;
1529bf215546Sopenharmony_ci
1530bf215546Sopenharmony_ci   swc->region_relocation(swc, &cmd->guestResult, buffer, 0,
1531bf215546Sopenharmony_ci                          SVGA_RELOC_READ | SVGA_RELOC_WRITE);
1532bf215546Sopenharmony_ci
1533bf215546Sopenharmony_ci   swc->commit(swc);
1534bf215546Sopenharmony_ci
1535bf215546Sopenharmony_ci   return PIPE_OK;
1536bf215546Sopenharmony_ci}
1537bf215546Sopenharmony_ci
1538bf215546Sopenharmony_ci
1539bf215546Sopenharmony_ci/*
1540bf215546Sopenharmony_ci *----------------------------------------------------------------------
1541bf215546Sopenharmony_ci *
1542bf215546Sopenharmony_ci * SVGA3D_WaitForGBQuery--
1543bf215546Sopenharmony_ci *
1544bf215546Sopenharmony_ci *      GB resource version of SVGA3D_WaitForQuery.
1545bf215546Sopenharmony_ci *
1546bf215546Sopenharmony_ci * Results:
1547bf215546Sopenharmony_ci *      None.
1548bf215546Sopenharmony_ci *
1549bf215546Sopenharmony_ci * Side effects:
1550bf215546Sopenharmony_ci *      Commits space in the FIFO memory.
1551bf215546Sopenharmony_ci *
1552bf215546Sopenharmony_ci *----------------------------------------------------------------------
1553bf215546Sopenharmony_ci */
1554bf215546Sopenharmony_ci
1555bf215546Sopenharmony_cistatic enum pipe_error
1556bf215546Sopenharmony_ciSVGA3D_WaitForGBQuery(struct svga_winsys_context *swc,
1557bf215546Sopenharmony_ci		      SVGA3dQueryType type,              // IN
1558bf215546Sopenharmony_ci		      struct svga_winsys_buffer *buffer) // IN/OUT
1559bf215546Sopenharmony_ci{
1560bf215546Sopenharmony_ci   SVGA3dCmdWaitForGBQuery *cmd;
1561bf215546Sopenharmony_ci
1562bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1563bf215546Sopenharmony_ci                            SVGA_3D_CMD_WAIT_FOR_GB_QUERY,
1564bf215546Sopenharmony_ci                            sizeof *cmd,
1565bf215546Sopenharmony_ci                            2);
1566bf215546Sopenharmony_ci   if (!cmd)
1567bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1568bf215546Sopenharmony_ci
1569bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1570bf215546Sopenharmony_ci   cmd->type = type;
1571bf215546Sopenharmony_ci
1572bf215546Sopenharmony_ci   swc->mob_relocation(swc, &cmd->mobid, &cmd->offset, buffer,
1573bf215546Sopenharmony_ci		       0, SVGA_RELOC_READ | SVGA_RELOC_WRITE);
1574bf215546Sopenharmony_ci
1575bf215546Sopenharmony_ci   swc->commit(swc);
1576bf215546Sopenharmony_ci
1577bf215546Sopenharmony_ci   return PIPE_OK;
1578bf215546Sopenharmony_ci}
1579bf215546Sopenharmony_ci
1580bf215546Sopenharmony_ci
1581bf215546Sopenharmony_ci/*
1582bf215546Sopenharmony_ci *----------------------------------------------------------------------
1583bf215546Sopenharmony_ci *
1584bf215546Sopenharmony_ci * SVGA3D_WaitForQuery--
1585bf215546Sopenharmony_ci *
1586bf215546Sopenharmony_ci *      Issues a SVGA_3D_CMD_WAIT_FOR_QUERY command.  This reserves space
1587bf215546Sopenharmony_ci *      for it in the FIFO.  This doesn't actually wait for the query to
1588bf215546Sopenharmony_ci *      finish but instead tells the host to start a wait at the driver
1589bf215546Sopenharmony_ci *      level.  The caller can wait on the status variable in the
1590bf215546Sopenharmony_ci *      guestPtr memory or send an insert fence instruction after this
1591bf215546Sopenharmony_ci *      command and wait on the fence.
1592bf215546Sopenharmony_ci *
1593bf215546Sopenharmony_ci * Results:
1594bf215546Sopenharmony_ci *      None.
1595bf215546Sopenharmony_ci *
1596bf215546Sopenharmony_ci * Side effects:
1597bf215546Sopenharmony_ci *      Commits space in the FIFO memory.
1598bf215546Sopenharmony_ci *
1599bf215546Sopenharmony_ci *----------------------------------------------------------------------
1600bf215546Sopenharmony_ci */
1601bf215546Sopenharmony_ci
1602bf215546Sopenharmony_cienum pipe_error
1603bf215546Sopenharmony_ciSVGA3D_WaitForQuery(struct svga_winsys_context *swc,
1604bf215546Sopenharmony_ci                    SVGA3dQueryType type,              // IN
1605bf215546Sopenharmony_ci                    struct svga_winsys_buffer *buffer) // IN/OUT
1606bf215546Sopenharmony_ci{
1607bf215546Sopenharmony_ci   SVGA3dCmdWaitForQuery *cmd;
1608bf215546Sopenharmony_ci
1609bf215546Sopenharmony_ci   if (swc->have_gb_objects)
1610bf215546Sopenharmony_ci      return SVGA3D_WaitForGBQuery(swc, type, buffer);
1611bf215546Sopenharmony_ci
1612bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1613bf215546Sopenharmony_ci                            SVGA_3D_CMD_WAIT_FOR_QUERY,
1614bf215546Sopenharmony_ci                            sizeof *cmd,
1615bf215546Sopenharmony_ci                            1);
1616bf215546Sopenharmony_ci   if (!cmd)
1617bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1618bf215546Sopenharmony_ci
1619bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1620bf215546Sopenharmony_ci   cmd->type = type;
1621bf215546Sopenharmony_ci
1622bf215546Sopenharmony_ci   swc->region_relocation(swc, &cmd->guestResult, buffer, 0,
1623bf215546Sopenharmony_ci                          SVGA_RELOC_READ | SVGA_RELOC_WRITE);
1624bf215546Sopenharmony_ci
1625bf215546Sopenharmony_ci   swc->commit(swc);
1626bf215546Sopenharmony_ci
1627bf215546Sopenharmony_ci   return PIPE_OK;
1628bf215546Sopenharmony_ci}
1629bf215546Sopenharmony_ci
1630bf215546Sopenharmony_ci
1631bf215546Sopenharmony_cienum pipe_error
1632bf215546Sopenharmony_ciSVGA3D_BindGBShader(struct svga_winsys_context *swc,
1633bf215546Sopenharmony_ci                    struct svga_winsys_gb_shader *gbshader)
1634bf215546Sopenharmony_ci{
1635bf215546Sopenharmony_ci   SVGA3dCmdBindGBShader *cmd =
1636bf215546Sopenharmony_ci      SVGA3D_FIFOReserve(swc,
1637bf215546Sopenharmony_ci                         SVGA_3D_CMD_BIND_GB_SHADER,
1638bf215546Sopenharmony_ci                         sizeof *cmd,
1639bf215546Sopenharmony_ci                         2);  /* two relocations */
1640bf215546Sopenharmony_ci
1641bf215546Sopenharmony_ci   if (!cmd)
1642bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1643bf215546Sopenharmony_ci
1644bf215546Sopenharmony_ci   swc->shader_relocation(swc, &cmd->shid, &cmd->mobid,
1645bf215546Sopenharmony_ci			  &cmd->offsetInBytes, gbshader, 0);
1646bf215546Sopenharmony_ci
1647bf215546Sopenharmony_ci   swc->commit(swc);
1648bf215546Sopenharmony_ci
1649bf215546Sopenharmony_ci   return PIPE_OK;
1650bf215546Sopenharmony_ci}
1651bf215546Sopenharmony_ci
1652bf215546Sopenharmony_ci
1653bf215546Sopenharmony_cienum pipe_error
1654bf215546Sopenharmony_ciSVGA3D_SetGBShader(struct svga_winsys_context *swc,
1655bf215546Sopenharmony_ci                   SVGA3dShaderType type,  // IN
1656bf215546Sopenharmony_ci                   struct svga_winsys_gb_shader *gbshader)
1657bf215546Sopenharmony_ci{
1658bf215546Sopenharmony_ci   SVGA3dCmdSetShader *cmd;
1659bf215546Sopenharmony_ci
1660bf215546Sopenharmony_ci   assert(type == SVGA3D_SHADERTYPE_VS || type == SVGA3D_SHADERTYPE_PS);
1661bf215546Sopenharmony_ci
1662bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1663bf215546Sopenharmony_ci                            SVGA_3D_CMD_SET_SHADER,
1664bf215546Sopenharmony_ci                            sizeof *cmd,
1665bf215546Sopenharmony_ci                            2);  /* two relocations */
1666bf215546Sopenharmony_ci   if (!cmd)
1667bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1668bf215546Sopenharmony_ci
1669bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1670bf215546Sopenharmony_ci   cmd->type = type;
1671bf215546Sopenharmony_ci   if (gbshader)
1672bf215546Sopenharmony_ci      swc->shader_relocation(swc, &cmd->shid, NULL, NULL, gbshader, 0);
1673bf215546Sopenharmony_ci   else
1674bf215546Sopenharmony_ci      cmd->shid = SVGA_ID_INVALID;
1675bf215546Sopenharmony_ci   swc->commit(swc);
1676bf215546Sopenharmony_ci
1677bf215546Sopenharmony_ci   return PIPE_OK;
1678bf215546Sopenharmony_ci}
1679bf215546Sopenharmony_ci
1680bf215546Sopenharmony_ci
1681bf215546Sopenharmony_ci/**
1682bf215546Sopenharmony_ci * \param flags  mask of SVGA_RELOC_READ / _WRITE
1683bf215546Sopenharmony_ci */
1684bf215546Sopenharmony_cienum pipe_error
1685bf215546Sopenharmony_ciSVGA3D_BindGBSurface(struct svga_winsys_context *swc,
1686bf215546Sopenharmony_ci                     struct svga_winsys_surface *surface)
1687bf215546Sopenharmony_ci{
1688bf215546Sopenharmony_ci   SVGA3dCmdBindGBSurface *cmd =
1689bf215546Sopenharmony_ci      SVGA3D_FIFOReserve(swc,
1690bf215546Sopenharmony_ci                         SVGA_3D_CMD_BIND_GB_SURFACE,
1691bf215546Sopenharmony_ci                         sizeof *cmd,
1692bf215546Sopenharmony_ci                         2);  /* two relocations */
1693bf215546Sopenharmony_ci
1694bf215546Sopenharmony_ci   if (!cmd)
1695bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1696bf215546Sopenharmony_ci
1697bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->sid, &cmd->mobid, surface,
1698bf215546Sopenharmony_ci                           SVGA_RELOC_READ);
1699bf215546Sopenharmony_ci
1700bf215546Sopenharmony_ci   swc->commit(swc);
1701bf215546Sopenharmony_ci
1702bf215546Sopenharmony_ci   return PIPE_OK;
1703bf215546Sopenharmony_ci}
1704bf215546Sopenharmony_ci
1705bf215546Sopenharmony_ci
1706bf215546Sopenharmony_ci/**
1707bf215546Sopenharmony_ci * Update an image in a guest-backed surface.
1708bf215546Sopenharmony_ci * (Inform the device that the guest-contents have been updated.)
1709bf215546Sopenharmony_ci */
1710bf215546Sopenharmony_cienum pipe_error
1711bf215546Sopenharmony_ciSVGA3D_UpdateGBImage(struct svga_winsys_context *swc,
1712bf215546Sopenharmony_ci                     struct svga_winsys_surface *surface,
1713bf215546Sopenharmony_ci                     const SVGA3dBox *box,
1714bf215546Sopenharmony_ci                     unsigned face, unsigned mipLevel)
1715bf215546Sopenharmony_ci
1716bf215546Sopenharmony_ci{
1717bf215546Sopenharmony_ci   SVGA3dCmdUpdateGBImage *cmd =
1718bf215546Sopenharmony_ci      SVGA3D_FIFOReserve(swc,
1719bf215546Sopenharmony_ci                         SVGA_3D_CMD_UPDATE_GB_IMAGE,
1720bf215546Sopenharmony_ci                         sizeof *cmd,
1721bf215546Sopenharmony_ci                         1);  /* one relocation */
1722bf215546Sopenharmony_ci
1723bf215546Sopenharmony_ci   if (!cmd)
1724bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1725bf215546Sopenharmony_ci
1726bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->image.sid, NULL, surface,
1727bf215546Sopenharmony_ci                           SVGA_RELOC_WRITE | SVGA_RELOC_INTERNAL);
1728bf215546Sopenharmony_ci   cmd->image.face = face;
1729bf215546Sopenharmony_ci   cmd->image.mipmap = mipLevel;
1730bf215546Sopenharmony_ci   cmd->box = *box;
1731bf215546Sopenharmony_ci
1732bf215546Sopenharmony_ci   swc->commit(swc);
1733bf215546Sopenharmony_ci   swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH;
1734bf215546Sopenharmony_ci
1735bf215546Sopenharmony_ci   return PIPE_OK;
1736bf215546Sopenharmony_ci}
1737bf215546Sopenharmony_ci
1738bf215546Sopenharmony_ci
1739bf215546Sopenharmony_ci/**
1740bf215546Sopenharmony_ci * Update an entire guest-backed surface.
1741bf215546Sopenharmony_ci * (Inform the device that the guest-contents have been updated.)
1742bf215546Sopenharmony_ci */
1743bf215546Sopenharmony_cienum pipe_error
1744bf215546Sopenharmony_ciSVGA3D_UpdateGBSurface(struct svga_winsys_context *swc,
1745bf215546Sopenharmony_ci                       struct svga_winsys_surface *surface)
1746bf215546Sopenharmony_ci{
1747bf215546Sopenharmony_ci   SVGA3dCmdUpdateGBSurface *cmd =
1748bf215546Sopenharmony_ci      SVGA3D_FIFOReserve(swc,
1749bf215546Sopenharmony_ci                         SVGA_3D_CMD_UPDATE_GB_SURFACE,
1750bf215546Sopenharmony_ci                         sizeof *cmd,
1751bf215546Sopenharmony_ci                         1);  /* one relocation */
1752bf215546Sopenharmony_ci
1753bf215546Sopenharmony_ci   if (!cmd)
1754bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1755bf215546Sopenharmony_ci
1756bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->sid, NULL, surface,
1757bf215546Sopenharmony_ci                           SVGA_RELOC_WRITE | SVGA_RELOC_INTERNAL);
1758bf215546Sopenharmony_ci
1759bf215546Sopenharmony_ci   swc->commit(swc);
1760bf215546Sopenharmony_ci   swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH;
1761bf215546Sopenharmony_ci
1762bf215546Sopenharmony_ci   return PIPE_OK;
1763bf215546Sopenharmony_ci}
1764bf215546Sopenharmony_ci
1765bf215546Sopenharmony_ci
1766bf215546Sopenharmony_ci/**
1767bf215546Sopenharmony_ci * Readback an image in a guest-backed surface.
1768bf215546Sopenharmony_ci * (Request the device to flush the dirty contents into the guest.)
1769bf215546Sopenharmony_ci */
1770bf215546Sopenharmony_cienum pipe_error
1771bf215546Sopenharmony_ciSVGA3D_ReadbackGBImage(struct svga_winsys_context *swc,
1772bf215546Sopenharmony_ci                       struct svga_winsys_surface *surface,
1773bf215546Sopenharmony_ci                       unsigned face, unsigned mipLevel)
1774bf215546Sopenharmony_ci{
1775bf215546Sopenharmony_ci   SVGA3dCmdReadbackGBImage *cmd =
1776bf215546Sopenharmony_ci      SVGA3D_FIFOReserve(swc,
1777bf215546Sopenharmony_ci                         SVGA_3D_CMD_READBACK_GB_IMAGE,
1778bf215546Sopenharmony_ci                         sizeof *cmd,
1779bf215546Sopenharmony_ci                         1);  /* one relocation */
1780bf215546Sopenharmony_ci
1781bf215546Sopenharmony_ci   if (!cmd)
1782bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1783bf215546Sopenharmony_ci
1784bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->image.sid, NULL, surface,
1785bf215546Sopenharmony_ci                           SVGA_RELOC_READ | SVGA_RELOC_INTERNAL);
1786bf215546Sopenharmony_ci   cmd->image.face = face;
1787bf215546Sopenharmony_ci   cmd->image.mipmap = mipLevel;
1788bf215546Sopenharmony_ci
1789bf215546Sopenharmony_ci   swc->commit(swc);
1790bf215546Sopenharmony_ci   swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH;
1791bf215546Sopenharmony_ci
1792bf215546Sopenharmony_ci   return PIPE_OK;
1793bf215546Sopenharmony_ci}
1794bf215546Sopenharmony_ci
1795bf215546Sopenharmony_ci
1796bf215546Sopenharmony_ci/**
1797bf215546Sopenharmony_ci * Readback an entire guest-backed surface.
1798bf215546Sopenharmony_ci * (Request the device to flush the dirty contents into the guest.)
1799bf215546Sopenharmony_ci */
1800bf215546Sopenharmony_cienum pipe_error
1801bf215546Sopenharmony_ciSVGA3D_ReadbackGBSurface(struct svga_winsys_context *swc,
1802bf215546Sopenharmony_ci                         struct svga_winsys_surface *surface)
1803bf215546Sopenharmony_ci{
1804bf215546Sopenharmony_ci   SVGA3dCmdReadbackGBSurface *cmd =
1805bf215546Sopenharmony_ci      SVGA3D_FIFOReserve(swc,
1806bf215546Sopenharmony_ci                         SVGA_3D_CMD_READBACK_GB_SURFACE,
1807bf215546Sopenharmony_ci                         sizeof *cmd,
1808bf215546Sopenharmony_ci                         1);  /* one relocation */
1809bf215546Sopenharmony_ci
1810bf215546Sopenharmony_ci   if (!cmd)
1811bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1812bf215546Sopenharmony_ci
1813bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->sid, NULL, surface,
1814bf215546Sopenharmony_ci                           SVGA_RELOC_READ | SVGA_RELOC_INTERNAL);
1815bf215546Sopenharmony_ci
1816bf215546Sopenharmony_ci   swc->commit(swc);
1817bf215546Sopenharmony_ci   swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH;
1818bf215546Sopenharmony_ci
1819bf215546Sopenharmony_ci   return PIPE_OK;
1820bf215546Sopenharmony_ci}
1821bf215546Sopenharmony_ci
1822bf215546Sopenharmony_ci
1823bf215546Sopenharmony_cienum pipe_error
1824bf215546Sopenharmony_ciSVGA3D_ReadbackGBImagePartial(struct svga_winsys_context *swc,
1825bf215546Sopenharmony_ci                              struct svga_winsys_surface *surface,
1826bf215546Sopenharmony_ci                              unsigned face, unsigned mipLevel,
1827bf215546Sopenharmony_ci                              const SVGA3dBox *box,
1828bf215546Sopenharmony_ci                              bool invertBox)
1829bf215546Sopenharmony_ci{
1830bf215546Sopenharmony_ci   SVGA3dCmdReadbackGBImagePartial *cmd =
1831bf215546Sopenharmony_ci      SVGA3D_FIFOReserve(swc,
1832bf215546Sopenharmony_ci                         SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL,
1833bf215546Sopenharmony_ci                         sizeof *cmd,
1834bf215546Sopenharmony_ci                         1);  /* one relocation */
1835bf215546Sopenharmony_ci   if (!cmd)
1836bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1837bf215546Sopenharmony_ci
1838bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->image.sid, NULL, surface,
1839bf215546Sopenharmony_ci                           SVGA_RELOC_READ | SVGA_RELOC_INTERNAL);
1840bf215546Sopenharmony_ci   cmd->image.face = face;
1841bf215546Sopenharmony_ci   cmd->image.mipmap = mipLevel;
1842bf215546Sopenharmony_ci   cmd->box = *box;
1843bf215546Sopenharmony_ci   cmd->invertBox = invertBox;
1844bf215546Sopenharmony_ci
1845bf215546Sopenharmony_ci   swc->commit(swc);
1846bf215546Sopenharmony_ci   swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH;
1847bf215546Sopenharmony_ci
1848bf215546Sopenharmony_ci   return PIPE_OK;
1849bf215546Sopenharmony_ci}
1850bf215546Sopenharmony_ci
1851bf215546Sopenharmony_ci
1852bf215546Sopenharmony_cienum pipe_error
1853bf215546Sopenharmony_ciSVGA3D_InvalidateGBImagePartial(struct svga_winsys_context *swc,
1854bf215546Sopenharmony_ci                                struct svga_winsys_surface *surface,
1855bf215546Sopenharmony_ci                                unsigned face, unsigned mipLevel,
1856bf215546Sopenharmony_ci                                const SVGA3dBox *box,
1857bf215546Sopenharmony_ci                                bool invertBox)
1858bf215546Sopenharmony_ci{
1859bf215546Sopenharmony_ci   SVGA3dCmdInvalidateGBImagePartial *cmd =
1860bf215546Sopenharmony_ci      SVGA3D_FIFOReserve(swc,
1861bf215546Sopenharmony_ci                         SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL,
1862bf215546Sopenharmony_ci                         sizeof *cmd,
1863bf215546Sopenharmony_ci                         1);  /* one relocation */
1864bf215546Sopenharmony_ci   if (!cmd)
1865bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1866bf215546Sopenharmony_ci
1867bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->image.sid, NULL, surface,
1868bf215546Sopenharmony_ci                           SVGA_RELOC_READ | SVGA_RELOC_INTERNAL);
1869bf215546Sopenharmony_ci   cmd->image.face = face;
1870bf215546Sopenharmony_ci   cmd->image.mipmap = mipLevel;
1871bf215546Sopenharmony_ci   cmd->box = *box;
1872bf215546Sopenharmony_ci   cmd->invertBox = invertBox;
1873bf215546Sopenharmony_ci
1874bf215546Sopenharmony_ci   swc->commit(swc);
1875bf215546Sopenharmony_ci
1876bf215546Sopenharmony_ci   return PIPE_OK;
1877bf215546Sopenharmony_ci}
1878bf215546Sopenharmony_ci
1879bf215546Sopenharmony_cienum pipe_error
1880bf215546Sopenharmony_ciSVGA3D_InvalidateGBSurface(struct svga_winsys_context *swc,
1881bf215546Sopenharmony_ci                           struct svga_winsys_surface *surface)
1882bf215546Sopenharmony_ci{
1883bf215546Sopenharmony_ci   SVGA3dCmdInvalidateGBSurface *cmd =
1884bf215546Sopenharmony_ci      SVGA3D_FIFOReserve(swc,
1885bf215546Sopenharmony_ci                         SVGA_3D_CMD_INVALIDATE_GB_SURFACE,
1886bf215546Sopenharmony_ci                         sizeof *cmd,
1887bf215546Sopenharmony_ci                         1);  /* one relocation */
1888bf215546Sopenharmony_ci   if (!cmd)
1889bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1890bf215546Sopenharmony_ci
1891bf215546Sopenharmony_ci   swc->surface_relocation(swc, &cmd->sid, NULL, surface,
1892bf215546Sopenharmony_ci                           SVGA_RELOC_READ | SVGA_RELOC_INTERNAL);
1893bf215546Sopenharmony_ci   swc->commit(swc);
1894bf215546Sopenharmony_ci
1895bf215546Sopenharmony_ci   return PIPE_OK;
1896bf215546Sopenharmony_ci}
1897bf215546Sopenharmony_ci
1898bf215546Sopenharmony_cienum pipe_error
1899bf215546Sopenharmony_ciSVGA3D_SetGBShaderConstsInline(struct svga_winsys_context *swc,
1900bf215546Sopenharmony_ci                              unsigned regStart,
1901bf215546Sopenharmony_ci                              unsigned numRegs,
1902bf215546Sopenharmony_ci                              SVGA3dShaderType shaderType,
1903bf215546Sopenharmony_ci                              SVGA3dShaderConstType constType,
1904bf215546Sopenharmony_ci                              const void *values)
1905bf215546Sopenharmony_ci{
1906bf215546Sopenharmony_ci   SVGA3dCmdSetGBShaderConstInline *cmd;
1907bf215546Sopenharmony_ci
1908bf215546Sopenharmony_ci   assert(numRegs > 0);
1909bf215546Sopenharmony_ci
1910bf215546Sopenharmony_ci   cmd = SVGA3D_FIFOReserve(swc,
1911bf215546Sopenharmony_ci                            SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE,
1912bf215546Sopenharmony_ci                            sizeof *cmd + numRegs * sizeof(float[4]),
1913bf215546Sopenharmony_ci                            0); /* no relocations */
1914bf215546Sopenharmony_ci   if (!cmd)
1915bf215546Sopenharmony_ci      return PIPE_ERROR_OUT_OF_MEMORY;
1916bf215546Sopenharmony_ci
1917bf215546Sopenharmony_ci   cmd->cid = swc->cid;
1918bf215546Sopenharmony_ci   cmd->regStart = regStart;
1919bf215546Sopenharmony_ci   cmd->shaderType = shaderType;
1920bf215546Sopenharmony_ci   cmd->constType = constType;
1921bf215546Sopenharmony_ci
1922bf215546Sopenharmony_ci   memcpy(&cmd[1], values, numRegs * sizeof(float[4]));
1923bf215546Sopenharmony_ci
1924bf215546Sopenharmony_ci   swc->commit(swc);
1925bf215546Sopenharmony_ci
1926bf215546Sopenharmony_ci   return PIPE_OK;
1927bf215546Sopenharmony_ci}
1928