1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
29 * Command construction utility for the SVGA3D protocol used by
30 * the VMware SVGA device, based on the svgautil library.
33 #include "svga_winsys.h"
34 #include "svga_resource_buffer.h"
35 #include "svga_resource_texture.h"
36 #include "svga_surface.h"
40 *----------------------------------------------------------------------
42 * surface_to_surfaceid --
44 * Utility function for surface ids.
45 * Can handle null surface. Does a surface_reallocation so you need
46 * to have allocated the fifo space before converting.
52 * One surface relocation is performed for texture handle.
54 *----------------------------------------------------------------------
58 surface_to_surfaceid(struct svga_winsys_context
*swc
, // IN
59 struct pipe_surface
*surface
, // IN
60 SVGA3dSurfaceImageId
*id
, // OUT
64 struct svga_surface
*s
= svga_surface(surface
);
65 swc
->surface_relocation(swc
, &id
->sid
, NULL
, s
->handle
, flags
);
66 id
->face
= s
->real_face
; /* faces have the same order */
67 id
->mipmap
= s
->real_level
;
70 swc
->surface_relocation(swc
, &id
->sid
, NULL
, NULL
, flags
);
78 *----------------------------------------------------------------------
80 * SVGA3D_FIFOReserve --
82 * Reserve space for an SVGA3D FIFO command.
84 * The 2D SVGA commands have been around for a while, so they
85 * have a rather asymmetric structure. The SVGA3D protocol is
86 * more uniform: each command begins with a header containing the
87 * command number and the full size.
89 * This is a convenience wrapper around SVGA_FIFOReserve. We
90 * reserve space for the whole command, and write the header.
92 * This function must be paired with SVGA_FIFOCommitAll().
95 * Returns a pointer to the space reserved for command-specific
96 * data. It must be 'cmdSize' bytes long.
99 * Begins a FIFO reservation.
101 *----------------------------------------------------------------------
105 SVGA3D_FIFOReserve(struct svga_winsys_context
*swc
,
107 uint32 cmdSize
, // IN
108 uint32 nr_relocs
) // IN
110 SVGA3dCmdHeader
*header
;
112 header
= swc
->reserve(swc
, sizeof *header
+ cmdSize
, nr_relocs
);
117 header
->size
= cmdSize
;
124 SVGA_FIFOCommitAll(struct svga_winsys_context
*swc
)
131 *----------------------------------------------------------------------
133 * SVGA3D_DefineContext --
135 * Create a new context, to be referred to with the provided ID.
137 * Context objects encapsulate all render state, and shader
138 * objects are per-context.
140 * Surfaces are not per-context. The same surface can be shared
141 * between multiple contexts, and surface operations can occur
144 * If the provided context ID already existed, it is redefined.
146 * Context IDs are arbitrary small non-negative integers,
147 * global to the entire SVGA device.
155 *----------------------------------------------------------------------
159 SVGA3D_DefineContext(struct svga_winsys_context
*swc
) // IN
161 SVGA3dCmdDefineContext
*cmd
;
163 cmd
= SVGA3D_FIFOReserve(swc
,
164 SVGA_3D_CMD_CONTEXT_DEFINE
, sizeof *cmd
, 0);
166 return PIPE_ERROR_OUT_OF_MEMORY
;
177 *----------------------------------------------------------------------
179 * SVGA3D_DestroyContext --
181 * Delete a context created with SVGA3D_DefineContext.
189 *----------------------------------------------------------------------
193 SVGA3D_DestroyContext(struct svga_winsys_context
*swc
) // IN
195 SVGA3dCmdDestroyContext
*cmd
;
197 cmd
= SVGA3D_FIFOReserve(swc
,
198 SVGA_3D_CMD_CONTEXT_DESTROY
, sizeof *cmd
, 0);
200 return PIPE_ERROR_OUT_OF_MEMORY
;
211 *----------------------------------------------------------------------
213 * SVGA3D_BeginDefineSurface --
215 * Begin a SURFACE_DEFINE command. This reserves space for it in
216 * the FIFO, and returns pointers to the command's faces and
219 * This function must be paired with SVGA_FIFOCommitAll().
220 * The faces and mipSizes arrays are initialized to zero.
222 * This creates a "surface" object in the SVGA3D device,
223 * with the provided surface ID (sid). Surfaces are generic
224 * containers for host VRAM objects like textures, vertex
225 * buffers, and depth/stencil buffers.
227 * Surfaces are hierarchical:
229 * - Surface may have multiple faces (for cube maps)
231 * - Each face has a list of mipmap levels
233 * - Each mipmap image may have multiple volume
234 * slices, if the image is three dimensional.
236 * - Each slice is a 2D array of 'blocks'
238 * - Each block may be one or more pixels.
239 * (Usually 1, more for DXT or YUV formats.)
241 * Surfaces are generic host VRAM objects. The SVGA3D device
242 * may optimize surfaces according to the format they were
243 * created with, but this format does not limit the ways in
244 * which the surface may be used. For example, a depth surface
245 * can be used as a texture, or a floating point image may
246 * be used as a vertex buffer. Some surface usages may be
247 * lower performance, due to software emulation, but any
248 * usage should work with any surface.
250 * If 'sid' is already defined, the old surface is deleted
251 * and this new surface replaces it.
253 * Surface IDs are arbitrary small non-negative integers,
254 * global to the entire SVGA device.
257 * Returns pointers to arrays allocated in the FIFO for 'faces'
261 * Begins a FIFO reservation.
263 *----------------------------------------------------------------------
267 SVGA3D_BeginDefineSurface(struct svga_winsys_context
*swc
,
268 struct svga_winsys_surface
*sid
, // IN
269 SVGA3dSurfaceFlags flags
, // IN
270 SVGA3dSurfaceFormat format
, // IN
271 SVGA3dSurfaceFace
**faces
, // OUT
272 SVGA3dSize
**mipSizes
, // OUT
273 uint32 numMipSizes
) // IN
275 SVGA3dCmdDefineSurface
*cmd
;
277 cmd
= SVGA3D_FIFOReserve(swc
,
278 SVGA_3D_CMD_SURFACE_DEFINE
, sizeof *cmd
+
279 sizeof **mipSizes
* numMipSizes
, 1);
281 return PIPE_ERROR_OUT_OF_MEMORY
;
283 swc
->surface_relocation(swc
, &cmd
->sid
, NULL
, sid
, SVGA_RELOC_WRITE
);
284 cmd
->surfaceFlags
= flags
;
285 cmd
->format
= format
;
287 *faces
= &cmd
->face
[0];
288 *mipSizes
= (SVGA3dSize
*) &cmd
[1];
290 memset(*faces
, 0, sizeof **faces
* SVGA3D_MAX_SURFACE_FACES
);
291 memset(*mipSizes
, 0, sizeof **mipSizes
* numMipSizes
);
298 *----------------------------------------------------------------------
300 * SVGA3D_DefineSurface2D --
302 * This is a simplified version of SVGA3D_BeginDefineSurface(),
303 * which does not support cube maps, mipmaps, or volume textures.
311 *----------------------------------------------------------------------
315 SVGA3D_DefineSurface2D(struct svga_winsys_context
*swc
, // IN
316 struct svga_winsys_surface
*sid
, // IN
319 SVGA3dSurfaceFormat format
) // IN
321 SVGA3dSize
*mipSizes
;
322 SVGA3dSurfaceFace
*faces
;
325 ret
= SVGA3D_BeginDefineSurface(swc
,
326 sid
, 0, format
, &faces
, &mipSizes
, 1);
330 faces
[0].numMipLevels
= 1;
332 mipSizes
[0].width
= width
;
333 mipSizes
[0].height
= height
;
334 mipSizes
[0].depth
= 1;
343 *----------------------------------------------------------------------
345 * SVGA3D_DestroySurface --
347 * Release the host VRAM encapsulated by a particular surface ID.
355 *----------------------------------------------------------------------
359 SVGA3D_DestroySurface(struct svga_winsys_context
*swc
,
360 struct svga_winsys_surface
*sid
) // IN
362 SVGA3dCmdDestroySurface
*cmd
;
364 cmd
= SVGA3D_FIFOReserve(swc
,
365 SVGA_3D_CMD_SURFACE_DESTROY
, sizeof *cmd
, 1);
367 return PIPE_ERROR_OUT_OF_MEMORY
;
369 swc
->surface_relocation(swc
, &cmd
->sid
, NULL
, sid
, SVGA_RELOC_READ
);
377 *----------------------------------------------------------------------
379 * SVGA3D_SurfaceDMA--
381 * Emit a SURFACE_DMA command.
383 * When the SVGA3D device asynchronously processes this FIFO
384 * command, a DMA operation is performed between host VRAM and
385 * a generic SVGAGuestPtr. The guest pointer may refer to guest
386 * VRAM (provided by the SVGA PCI device) or to guest system
387 * memory that has been set up as a Guest Memory Region (GMR)
388 * by the SVGA device.
390 * The guest's DMA buffer must remain valid (not freed, paged out,
391 * or overwritten) until the host has finished processing this
392 * command. The guest can determine that the host has finished
393 * by using the SVGA device's FIFO Fence mechanism.
395 * The guest's image buffer can be an arbitrary size and shape.
396 * Guest image data is interpreted according to the SVGA3D surface
397 * format specified when the surface was defined.
399 * The caller may optionally define the guest image's pitch.
400 * guestImage->pitch can either be zero (assume image is tightly
401 * packed) or it must be the number of bytes between vertically
402 * adjacent image blocks.
404 * The provided copybox list specifies which regions of the source
405 * image are to be copied, and where they appear on the destination.
407 * NOTE: srcx/srcy are always on the guest image and x/y are
408 * always on the host image, regardless of the actual transfer
411 * For efficiency, the SVGA3D device is free to copy more data
412 * than specified. For example, it may round copy boxes outwards
413 * such that they lie on particular alignment boundaries.
415 *----------------------------------------------------------------------
419 SVGA3D_SurfaceDMA(struct svga_winsys_context
*swc
,
420 struct svga_transfer
*st
, // IN
421 SVGA3dTransferType transfer
, // IN
422 const SVGA3dCopyBox
*boxes
, // IN
423 uint32 numBoxes
, // IN
424 SVGA3dSurfaceDMAFlags flags
) // IN
426 struct svga_texture
*texture
= svga_texture(st
->base
.resource
);
427 SVGA3dCmdSurfaceDMA
*cmd
;
428 SVGA3dCmdSurfaceDMASuffix
*pSuffix
;
429 uint32 boxesSize
= sizeof *boxes
* numBoxes
;
430 unsigned region_flags
;
431 unsigned surface_flags
;
433 if (transfer
== SVGA3D_WRITE_HOST_VRAM
) {
434 region_flags
= SVGA_RELOC_READ
;
435 surface_flags
= SVGA_RELOC_WRITE
;
437 else if (transfer
== SVGA3D_READ_HOST_VRAM
) {
438 region_flags
= SVGA_RELOC_WRITE
;
439 surface_flags
= SVGA_RELOC_READ
;
443 return PIPE_ERROR_BAD_INPUT
;
446 cmd
= SVGA3D_FIFOReserve(swc
,
447 SVGA_3D_CMD_SURFACE_DMA
,
448 sizeof *cmd
+ boxesSize
+ sizeof *pSuffix
,
451 return PIPE_ERROR_OUT_OF_MEMORY
;
453 swc
->region_relocation(swc
, &cmd
->guest
.ptr
, st
->hwbuf
, 0, region_flags
);
454 cmd
->guest
.pitch
= st
->base
.stride
;
456 swc
->surface_relocation(swc
, &cmd
->host
.sid
, NULL
,
457 texture
->handle
, surface_flags
);
458 cmd
->host
.face
= st
->face
; /* PIPE_TEX_FACE_* and SVGA3D_CUBEFACE_* match */
459 cmd
->host
.mipmap
= st
->base
.level
;
461 cmd
->transfer
= transfer
;
463 memcpy(&cmd
[1], boxes
, boxesSize
);
465 pSuffix
= (SVGA3dCmdSurfaceDMASuffix
*)((uint8_t*)cmd
+ sizeof *cmd
+ boxesSize
);
466 pSuffix
->suffixSize
= sizeof *pSuffix
;
467 pSuffix
->maximumOffset
= st
->hw_nblocksy
*st
->base
.stride
;
468 pSuffix
->flags
= flags
;
477 SVGA3D_BufferDMA(struct svga_winsys_context
*swc
,
478 struct svga_winsys_buffer
*guest
,
479 struct svga_winsys_surface
*host
,
480 SVGA3dTransferType transfer
, // IN
482 uint32 guest_offset
, // IN
483 uint32 host_offset
, // IN
484 SVGA3dSurfaceDMAFlags flags
) // IN
486 SVGA3dCmdSurfaceDMA
*cmd
;
488 SVGA3dCmdSurfaceDMASuffix
*pSuffix
;
489 unsigned region_flags
;
490 unsigned surface_flags
;
492 if (transfer
== SVGA3D_WRITE_HOST_VRAM
) {
493 region_flags
= SVGA_RELOC_READ
;
494 surface_flags
= SVGA_RELOC_WRITE
;
496 else if (transfer
== SVGA3D_READ_HOST_VRAM
) {
497 region_flags
= SVGA_RELOC_WRITE
;
498 surface_flags
= SVGA_RELOC_READ
;
502 return PIPE_ERROR_BAD_INPUT
;
505 cmd
= SVGA3D_FIFOReserve(swc
,
506 SVGA_3D_CMD_SURFACE_DMA
,
507 sizeof *cmd
+ sizeof *box
+ sizeof *pSuffix
,
510 return PIPE_ERROR_OUT_OF_MEMORY
;
512 swc
->region_relocation(swc
, &cmd
->guest
.ptr
, guest
, 0, region_flags
);
513 cmd
->guest
.pitch
= 0;
515 swc
->surface_relocation(swc
, &cmd
->host
.sid
,
516 NULL
, host
, surface_flags
);
518 cmd
->host
.mipmap
= 0;
520 cmd
->transfer
= transfer
;
522 box
= (SVGA3dCopyBox
*)&cmd
[1];
523 box
->x
= host_offset
;
529 box
->srcx
= guest_offset
;
533 pSuffix
= (SVGA3dCmdSurfaceDMASuffix
*)((uint8_t*)cmd
+ sizeof *cmd
+ sizeof *box
);
534 pSuffix
->suffixSize
= sizeof *pSuffix
;
535 pSuffix
->maximumOffset
= guest_offset
+ size
;
536 pSuffix
->flags
= flags
;
545 *----------------------------------------------------------------------
547 * SVGA3D_SetRenderTarget --
549 * Bind a surface object to a particular render target attachment
550 * point on the current context. Render target attachment points
551 * exist for color buffers, a depth buffer, and a stencil buffer.
553 * The SVGA3D device is quite lenient about the types of surfaces
554 * that may be used as render targets. The color buffers must
555 * all be the same size, but the depth and stencil buffers do not
556 * have to be the same size as the color buffer. All attachments
559 * Some combinations of render target formats may require software
560 * emulation, depending on the capabilities of the host graphics
561 * API and graphics hardware.
569 *----------------------------------------------------------------------
573 SVGA3D_SetRenderTarget(struct svga_winsys_context
*swc
,
574 SVGA3dRenderTargetType type
, // IN
575 struct pipe_surface
*surface
) // IN
577 SVGA3dCmdSetRenderTarget
*cmd
;
579 cmd
= SVGA3D_FIFOReserve(swc
,
580 SVGA_3D_CMD_SETRENDERTARGET
, sizeof *cmd
, 1);
582 return PIPE_ERROR_OUT_OF_MEMORY
;
586 surface_to_surfaceid(swc
, surface
, &cmd
->target
, SVGA_RELOC_WRITE
);
594 *----------------------------------------------------------------------
596 * SVGA3D_DefineShader --
598 * Upload the bytecode for a new shader. The bytecode is "SVGA3D
599 * format", which is theoretically a binary-compatible superset
600 * of Microsoft's DirectX shader bytecode. In practice, the
601 * SVGA3D bytecode doesn't yet have any extensions to DirectX's
604 * The SVGA3D device supports shader models 1.1 through 2.0.
606 * The caller chooses a shader ID (small positive integer) by
607 * which this shader will be identified in future commands. This
608 * ID is in a namespace which is per-context and per-shader-type.
610 * 'bytecodeLen' is specified in bytes. It must be a multiple of 4.
618 *----------------------------------------------------------------------
622 SVGA3D_DefineShader(struct svga_winsys_context
*swc
,
624 SVGA3dShaderType type
, // IN
625 const uint32
*bytecode
, // IN
626 uint32 bytecodeLen
) // IN
628 SVGA3dCmdDefineShader
*cmd
;
630 assert(bytecodeLen
% 4 == 0);
632 cmd
= SVGA3D_FIFOReserve(swc
,
633 SVGA_3D_CMD_SHADER_DEFINE
, sizeof *cmd
+ bytecodeLen
,
636 return PIPE_ERROR_OUT_OF_MEMORY
;
641 memcpy(&cmd
[1], bytecode
, bytecodeLen
);
649 *----------------------------------------------------------------------
651 * SVGA3D_DestroyShader --
653 * Delete a shader that was created by SVGA3D_DefineShader. If
654 * the shader was the current vertex or pixel shader for its
655 * context, rendering results are undefined until a new shader is
664 *----------------------------------------------------------------------
668 SVGA3D_DestroyShader(struct svga_winsys_context
*swc
,
670 SVGA3dShaderType type
) // IN
672 SVGA3dCmdDestroyShader
*cmd
;
674 cmd
= SVGA3D_FIFOReserve(swc
,
675 SVGA_3D_CMD_SHADER_DESTROY
, sizeof *cmd
,
678 return PIPE_ERROR_OUT_OF_MEMORY
;
690 *----------------------------------------------------------------------
692 * SVGA3D_SetShaderConst --
694 * Set the value of a shader constant.
696 * Shader constants are analogous to uniform variables in GLSL,
697 * except that they belong to the render context rather than to
698 * an individual shader.
700 * Constants may have one of three types: A 4-vector of floats,
701 * a 4-vector of integers, or a single boolean flag.
709 *----------------------------------------------------------------------
713 SVGA3D_SetShaderConst(struct svga_winsys_context
*swc
,
715 SVGA3dShaderType type
, // IN
716 SVGA3dShaderConstType ctype
, // IN
717 const void *value
) // IN
719 SVGA3dCmdSetShaderConst
*cmd
;
721 cmd
= SVGA3D_FIFOReserve(swc
,
722 SVGA_3D_CMD_SET_SHADER_CONST
, sizeof *cmd
,
725 return PIPE_ERROR_OUT_OF_MEMORY
;
734 case SVGA3D_CONST_TYPE_FLOAT
:
735 case SVGA3D_CONST_TYPE_INT
:
736 memcpy(&cmd
->values
, value
, sizeof cmd
->values
);
739 case SVGA3D_CONST_TYPE_BOOL
:
740 memset(&cmd
->values
, 0, sizeof cmd
->values
);
741 cmd
->values
[0] = *(uint32
*)value
;
756 *----------------------------------------------------------------------
758 * SVGA3D_SetShaderConsts --
760 * Set the value of successive shader constants.
762 * Shader constants are analogous to uniform variables in GLSL,
763 * except that they belong to the render context rather than to
764 * an individual shader.
766 * Constants may have one of three types: A 4-vector of floats,
767 * a 4-vector of integers, or a single boolean flag.
775 *----------------------------------------------------------------------
779 SVGA3D_SetShaderConsts(struct svga_winsys_context
*swc
,
781 uint32 numRegs
, // IN
782 SVGA3dShaderType type
, // IN
783 SVGA3dShaderConstType ctype
, // IN
784 const void *values
) // IN
786 SVGA3dCmdSetShaderConst
*cmd
;
788 cmd
= SVGA3D_FIFOReserve(swc
,
789 SVGA_3D_CMD_SET_SHADER_CONST
,
790 sizeof *cmd
+ (numRegs
- 1) * sizeof cmd
->values
,
793 return PIPE_ERROR_OUT_OF_MEMORY
;
800 memcpy(&cmd
->values
, values
, numRegs
* sizeof cmd
->values
);
812 *----------------------------------------------------------------------
814 * SVGA3D_SetShader --
816 * Switch active shaders. This binds a new vertex or pixel shader
817 * to the specified context.
819 * A shader ID of SVGA3D_INVALID_ID unbinds any shader, switching
820 * back to the fixed function vertex or pixel pipeline.
828 *----------------------------------------------------------------------
832 SVGA3D_SetShader(struct svga_winsys_context
*swc
,
833 SVGA3dShaderType type
, // IN
836 SVGA3dCmdSetShader
*cmd
;
838 cmd
= SVGA3D_FIFOReserve(swc
,
839 SVGA_3D_CMD_SET_SHADER
, sizeof *cmd
,
842 return PIPE_ERROR_OUT_OF_MEMORY
;
854 *----------------------------------------------------------------------
856 * SVGA3D_BeginClear --
858 * Begin a CLEAR command. This reserves space for it in the FIFO,
859 * and returns a pointer to the command's rectangle array. This
860 * function must be paired with SVGA_FIFOCommitAll().
862 * Clear is a rendering operation which fills a list of
863 * rectangles with constant values on all render target types
864 * indicated by 'flags'.
866 * Clear is not affected by clipping, depth test, or other
867 * render state which affects the fragment pipeline.
873 * May write to attached render target surfaces.
875 *----------------------------------------------------------------------
879 SVGA3D_BeginClear(struct svga_winsys_context
*swc
,
880 SVGA3dClearFlag flags
, // IN
883 uint32 stencil
, // IN
884 SVGA3dRect
**rects
, // OUT
885 uint32 numRects
) // IN
889 cmd
= SVGA3D_FIFOReserve(swc
,
891 sizeof *cmd
+ sizeof **rects
* numRects
,
894 return PIPE_ERROR_OUT_OF_MEMORY
;
897 cmd
->clearFlag
= flags
;
900 cmd
->stencil
= stencil
;
901 *rects
= (SVGA3dRect
*) &cmd
[1];
908 *----------------------------------------------------------------------
910 * SVGA3D_ClearRect --
912 * This is a simplified version of SVGA3D_BeginClear().
920 *----------------------------------------------------------------------
924 SVGA3D_ClearRect(struct svga_winsys_context
*swc
,
925 SVGA3dClearFlag flags
, // IN
928 uint32 stencil
, // IN
937 ret
= SVGA3D_BeginClear(swc
, flags
, color
, depth
, stencil
, &rect
, 1);
939 return PIPE_ERROR_OUT_OF_MEMORY
;
941 memset(rect
, 0, sizeof *rect
);
953 *----------------------------------------------------------------------
955 * SVGA3D_BeginDrawPrimitives --
957 * Begin a DRAW_PRIMITIVES command. This reserves space for it in
958 * the FIFO, and returns a pointer to the command's arrays.
959 * This function must be paired with SVGA_FIFOCommitAll().
961 * Drawing commands consist of two variable-length arrays:
962 * SVGA3dVertexDecl elements declare a set of vertex buffers to
963 * use while rendering, and SVGA3dPrimitiveRange elements specify
964 * groups of primitives each with an optional index buffer.
966 * The decls and ranges arrays are initialized to zero.
972 * May write to attached render target surfaces.
974 *----------------------------------------------------------------------
978 SVGA3D_BeginDrawPrimitives(struct svga_winsys_context
*swc
,
979 SVGA3dVertexDecl
**decls
, // OUT
980 uint32 numVertexDecls
, // IN
981 SVGA3dPrimitiveRange
**ranges
, // OUT
982 uint32 numRanges
) // IN
984 SVGA3dCmdDrawPrimitives
*cmd
;
985 SVGA3dVertexDecl
*declArray
;
986 SVGA3dPrimitiveRange
*rangeArray
;
987 uint32 declSize
= sizeof **decls
* numVertexDecls
;
988 uint32 rangeSize
= sizeof **ranges
* numRanges
;
990 cmd
= SVGA3D_FIFOReserve(swc
,
991 SVGA_3D_CMD_DRAW_PRIMITIVES
,
992 sizeof *cmd
+ declSize
+ rangeSize
,
993 numVertexDecls
+ numRanges
);
995 return PIPE_ERROR_OUT_OF_MEMORY
;
998 cmd
->numVertexDecls
= numVertexDecls
;
999 cmd
->numRanges
= numRanges
;
1001 declArray
= (SVGA3dVertexDecl
*) &cmd
[1];
1002 rangeArray
= (SVGA3dPrimitiveRange
*) &declArray
[numVertexDecls
];
1004 memset(declArray
, 0, declSize
);
1005 memset(rangeArray
, 0, rangeSize
);
1008 *ranges
= rangeArray
;
1015 *----------------------------------------------------------------------
1017 * SVGA3D_BeginSurfaceCopy --
1019 * Begin a SURFACE_COPY command. This reserves space for it in
1020 * the FIFO, and returns a pointer to the command's arrays. This
1021 * function must be paired with SVGA_FIFOCommitAll().
1023 * The box array is initialized with zeroes.
1029 * Asynchronously copies a list of boxes from surface to surface.
1031 *----------------------------------------------------------------------
1035 SVGA3D_BeginSurfaceCopy(struct svga_winsys_context
*swc
,
1036 struct pipe_surface
*src
, // IN
1037 struct pipe_surface
*dest
, // IN
1038 SVGA3dCopyBox
**boxes
, // OUT
1039 uint32 numBoxes
) // IN
1041 SVGA3dCmdSurfaceCopy
*cmd
;
1042 uint32 boxesSize
= sizeof **boxes
* numBoxes
;
1044 cmd
= SVGA3D_FIFOReserve(swc
,
1045 SVGA_3D_CMD_SURFACE_COPY
, sizeof *cmd
+ boxesSize
,
1048 return PIPE_ERROR_OUT_OF_MEMORY
;
1050 surface_to_surfaceid(swc
, src
, &cmd
->src
, SVGA_RELOC_READ
);
1051 surface_to_surfaceid(swc
, dest
, &cmd
->dest
, SVGA_RELOC_WRITE
);
1052 *boxes
= (SVGA3dCopyBox
*) &cmd
[1];
1054 memset(*boxes
, 0, boxesSize
);
1061 *----------------------------------------------------------------------
1063 * SVGA3D_SurfaceStretchBlt --
1065 * Issue a SURFACE_STRETCHBLT command: an asynchronous
1066 * surface-to-surface blit, with scaling.
1072 * Asynchronously copies one box from surface to surface.
1074 *----------------------------------------------------------------------
1078 SVGA3D_SurfaceStretchBlt(struct svga_winsys_context
*swc
,
1079 struct pipe_surface
*src
, // IN
1080 struct pipe_surface
*dest
, // IN
1081 SVGA3dBox
*boxSrc
, // IN
1082 SVGA3dBox
*boxDest
, // IN
1083 SVGA3dStretchBltMode mode
) // IN
1085 SVGA3dCmdSurfaceStretchBlt
*cmd
;
1087 cmd
= SVGA3D_FIFOReserve(swc
,
1088 SVGA_3D_CMD_SURFACE_STRETCHBLT
, sizeof *cmd
,
1091 return PIPE_ERROR_OUT_OF_MEMORY
;
1093 surface_to_surfaceid(swc
, src
, &cmd
->src
, SVGA_RELOC_READ
);
1094 surface_to_surfaceid(swc
, dest
, &cmd
->dest
, SVGA_RELOC_WRITE
);
1095 cmd
->boxSrc
= *boxSrc
;
1096 cmd
->boxDest
= *boxDest
;
1105 *----------------------------------------------------------------------
1107 * SVGA3D_SetViewport --
1109 * Set the current context's viewport rectangle. The viewport
1110 * is clipped to the dimensions of the current render target,
1111 * then all rendering is clipped to the viewport.
1119 *----------------------------------------------------------------------
1123 SVGA3D_SetViewport(struct svga_winsys_context
*swc
,
1124 SVGA3dRect
*rect
) // IN
1126 SVGA3dCmdSetViewport
*cmd
;
1128 cmd
= SVGA3D_FIFOReserve(swc
,
1129 SVGA_3D_CMD_SETVIEWPORT
, sizeof *cmd
,
1132 return PIPE_ERROR_OUT_OF_MEMORY
;
1134 cmd
->cid
= swc
->cid
;
1145 *----------------------------------------------------------------------
1147 * SVGA3D_SetScissorRect --
1149 * Set the current context's scissor rectangle. If scissoring
1150 * is enabled then all rendering is clipped to the scissor bounds.
1158 *----------------------------------------------------------------------
1162 SVGA3D_SetScissorRect(struct svga_winsys_context
*swc
,
1163 SVGA3dRect
*rect
) // IN
1165 SVGA3dCmdSetScissorRect
*cmd
;
1167 cmd
= SVGA3D_FIFOReserve(swc
,
1168 SVGA_3D_CMD_SETSCISSORRECT
, sizeof *cmd
,
1171 return PIPE_ERROR_OUT_OF_MEMORY
;
1173 cmd
->cid
= swc
->cid
;
1181 *----------------------------------------------------------------------
1183 * SVGA3D_SetClipPlane --
1185 * Set one of the current context's clip planes. If the clip
1186 * plane is enabled then all 3d rendering is clipped against
1195 *----------------------------------------------------------------------
1199 SVGA3D_SetClipPlane(struct svga_winsys_context
*swc
,
1200 uint32 index
, const float *plane
)
1202 SVGA3dCmdSetClipPlane
*cmd
;
1204 cmd
= SVGA3D_FIFOReserve(swc
,
1205 SVGA_3D_CMD_SETCLIPPLANE
, sizeof *cmd
,
1208 return PIPE_ERROR_OUT_OF_MEMORY
;
1210 cmd
->cid
= swc
->cid
;
1212 cmd
->plane
[0] = plane
[0];
1213 cmd
->plane
[1] = plane
[1];
1214 cmd
->plane
[2] = plane
[2];
1215 cmd
->plane
[3] = plane
[3];
1222 *----------------------------------------------------------------------
1224 * SVGA3D_SetZRange --
1226 * Set the range of the depth buffer to use. 'min' and 'max'
1227 * are values between 0.0 and 1.0.
1235 *----------------------------------------------------------------------
1239 SVGA3D_SetZRange(struct svga_winsys_context
*swc
,
1243 SVGA3dCmdSetZRange
*cmd
;
1245 cmd
= SVGA3D_FIFOReserve(swc
,
1246 SVGA_3D_CMD_SETZRANGE
, sizeof *cmd
,
1249 return PIPE_ERROR_OUT_OF_MEMORY
;
1251 cmd
->cid
= swc
->cid
;
1252 cmd
->zRange
.min
= zMin
;
1253 cmd
->zRange
.max
= zMax
;
1261 *----------------------------------------------------------------------
1263 * SVGA3D_BeginSetTextureState --
1265 * Begin a SETTEXTURESTATE command. This reserves space for it in
1266 * the FIFO, and returns a pointer to the command's texture state
1267 * array. This function must be paired with SVGA_FIFOCommitAll().
1269 * This command sets rendering state which is per-texture-unit.
1271 * XXX: Individual texture states need documentation. However,
1272 * they are very similar to the texture states defined by
1273 * Direct3D. The D3D documentation is a good starting point
1274 * for understanding SVGA3D texture states.
1282 *----------------------------------------------------------------------
1286 SVGA3D_BeginSetTextureState(struct svga_winsys_context
*swc
,
1287 SVGA3dTextureState
**states
, // OUT
1288 uint32 numStates
) // IN
1290 SVGA3dCmdSetTextureState
*cmd
;
1292 cmd
= SVGA3D_FIFOReserve(swc
,
1293 SVGA_3D_CMD_SETTEXTURESTATE
,
1294 sizeof *cmd
+ sizeof **states
* numStates
,
1297 return PIPE_ERROR_OUT_OF_MEMORY
;
1299 cmd
->cid
= swc
->cid
;
1300 *states
= (SVGA3dTextureState
*) &cmd
[1];
1307 *----------------------------------------------------------------------
1309 * SVGA3D_BeginSetRenderState --
1311 * Begin a SETRENDERSTATE command. This reserves space for it in
1312 * the FIFO, and returns a pointer to the command's texture state
1313 * array. This function must be paired with SVGA_FIFOCommitAll().
1315 * This command sets rendering state which is global to the context.
1317 * XXX: Individual render states need documentation. However,
1318 * they are very similar to the render states defined by
1319 * Direct3D. The D3D documentation is a good starting point
1320 * for understanding SVGA3D render states.
1328 *----------------------------------------------------------------------
1332 SVGA3D_BeginSetRenderState(struct svga_winsys_context
*swc
,
1333 SVGA3dRenderState
**states
, // OUT
1334 uint32 numStates
) // IN
1336 SVGA3dCmdSetRenderState
*cmd
;
1338 cmd
= SVGA3D_FIFOReserve(swc
,
1339 SVGA_3D_CMD_SETRENDERSTATE
,
1340 sizeof *cmd
+ sizeof **states
* numStates
,
1343 return PIPE_ERROR_OUT_OF_MEMORY
;
1345 cmd
->cid
= swc
->cid
;
1346 *states
= (SVGA3dRenderState
*) &cmd
[1];
1353 *----------------------------------------------------------------------
1355 * SVGA3D_BeginQuery--
1357 * Issues a SVGA_3D_CMD_BEGIN_QUERY command.
1363 * Commits space in the FIFO memory.
1365 *----------------------------------------------------------------------
1369 SVGA3D_BeginQuery(struct svga_winsys_context
*swc
,
1370 SVGA3dQueryType type
) // IN
1372 SVGA3dCmdBeginQuery
*cmd
;
1374 cmd
= SVGA3D_FIFOReserve(swc
,
1375 SVGA_3D_CMD_BEGIN_QUERY
,
1379 return PIPE_ERROR_OUT_OF_MEMORY
;
1381 cmd
->cid
= swc
->cid
;
1391 *----------------------------------------------------------------------
1395 * Issues a SVGA_3D_CMD_END_QUERY command.
1401 * Commits space in the FIFO memory.
1403 *----------------------------------------------------------------------
1407 SVGA3D_EndQuery(struct svga_winsys_context
*swc
,
1408 SVGA3dQueryType type
, // IN
1409 struct svga_winsys_buffer
*buffer
) // IN/OUT
1411 SVGA3dCmdEndQuery
*cmd
;
1413 cmd
= SVGA3D_FIFOReserve(swc
,
1414 SVGA_3D_CMD_END_QUERY
,
1418 return PIPE_ERROR_OUT_OF_MEMORY
;
1420 cmd
->cid
= swc
->cid
;
1423 swc
->region_relocation(swc
, &cmd
->guestResult
, buffer
, 0,
1433 *----------------------------------------------------------------------
1435 * SVGA3D_WaitForQuery--
1437 * Issues a SVGA_3D_CMD_WAIT_FOR_QUERY command. This reserves space
1438 * for it in the FIFO. This doesn't actually wait for the query to
1439 * finish but instead tells the host to start a wait at the driver
1440 * level. The caller can wait on the status variable in the
1441 * guestPtr memory or send an insert fence instruction after this
1442 * command and wait on the fence.
1448 * Commits space in the FIFO memory.
1450 *----------------------------------------------------------------------
1454 SVGA3D_WaitForQuery(struct svga_winsys_context
*swc
,
1455 SVGA3dQueryType type
, // IN
1456 struct svga_winsys_buffer
*buffer
) // IN/OUT
1458 SVGA3dCmdWaitForQuery
*cmd
;
1460 cmd
= SVGA3D_FIFOReserve(swc
,
1461 SVGA_3D_CMD_WAIT_FOR_QUERY
,
1465 return PIPE_ERROR_OUT_OF_MEMORY
;
1467 cmd
->cid
= swc
->cid
;
1470 swc
->region_relocation(swc
, &cmd
->guestResult
, buffer
, 0,