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_screen_buffer.h"
35 #include "svga_screen_texture.h"
39 *----------------------------------------------------------------------
41 * surface_to_surfaceid --
43 * Utility function for surface ids.
44 * Can handle null surface. Does a surface_reallocation so you need
45 * to have allocated the fifo space before converting.
51 * One surface relocation is preformed for texture handle.
53 *----------------------------------------------------------------------
57 void surface_to_surfaceid(struct svga_winsys_context
*swc
, // IN
58 struct pipe_surface
*surface
, // IN
59 SVGA3dSurfaceImageId
*id
, // OUT
63 struct svga_surface
*s
= svga_surface(surface
);
64 swc
->surface_relocation(swc
, &id
->sid
, s
->handle
, flags
);
65 id
->face
= s
->real_face
; /* faces have the same order */
66 id
->mipmap
= s
->real_level
;
69 id
->sid
= SVGA3D_INVALID_ID
;
77 *----------------------------------------------------------------------
79 * SVGA3D_FIFOReserve --
81 * Reserve space for an SVGA3D FIFO command.
83 * The 2D SVGA commands have been around for a while, so they
84 * have a rather asymmetric structure. The SVGA3D protocol is
85 * more uniform: each command begins with a header containing the
86 * command number and the full size.
88 * This is a convenience wrapper around SVGA_FIFOReserve. We
89 * reserve space for the whole command, and write the header.
91 * This function must be paired with SVGA_FIFOCommitAll().
94 * Returns a pointer to the space reserved for command-specific
95 * data. It must be 'cmdSize' bytes long.
98 * Begins a FIFO reservation.
100 *----------------------------------------------------------------------
104 SVGA3D_FIFOReserve(struct svga_winsys_context
*swc
,
106 uint32 cmdSize
, // IN
107 uint32 nr_relocs
) // IN
109 SVGA3dCmdHeader
*header
;
111 header
= swc
->reserve(swc
, sizeof *header
+ cmdSize
, nr_relocs
);
116 header
->size
= cmdSize
;
123 SVGA_FIFOCommitAll(struct svga_winsys_context
*swc
)
130 *----------------------------------------------------------------------
132 * SVGA3D_DefineContext --
134 * Create a new context, to be referred to with the provided ID.
136 * Context objects encapsulate all render state, and shader
137 * objects are per-context.
139 * Surfaces are not per-context. The same surface can be shared
140 * between multiple contexts, and surface operations can occur
143 * If the provided context ID already existed, it is redefined.
145 * Context IDs are arbitrary small non-negative integers,
146 * global to the entire SVGA device.
154 *----------------------------------------------------------------------
158 SVGA3D_DefineContext(struct svga_winsys_context
*swc
) // IN
160 SVGA3dCmdDefineContext
*cmd
;
162 cmd
= SVGA3D_FIFOReserve(swc
,
163 SVGA_3D_CMD_CONTEXT_DEFINE
, sizeof *cmd
, 0);
165 return PIPE_ERROR_OUT_OF_MEMORY
;
176 *----------------------------------------------------------------------
178 * SVGA3D_DestroyContext --
180 * Delete a context created with SVGA3D_DefineContext.
188 *----------------------------------------------------------------------
192 SVGA3D_DestroyContext(struct svga_winsys_context
*swc
) // IN
194 SVGA3dCmdDestroyContext
*cmd
;
196 cmd
= SVGA3D_FIFOReserve(swc
,
197 SVGA_3D_CMD_CONTEXT_DESTROY
, sizeof *cmd
, 0);
199 return PIPE_ERROR_OUT_OF_MEMORY
;
210 *----------------------------------------------------------------------
212 * SVGA3D_BeginDefineSurface --
214 * Begin a SURFACE_DEFINE command. This reserves space for it in
215 * the FIFO, and returns pointers to the command's faces and
218 * This function must be paired with SVGA_FIFOCommitAll().
219 * The faces and mipSizes arrays are initialized to zero.
221 * This creates a "surface" object in the SVGA3D device,
222 * with the provided surface ID (sid). Surfaces are generic
223 * containers for host VRAM objects like textures, vertex
224 * buffers, and depth/stencil buffers.
226 * Surfaces are hierarchial:
228 * - Surface may have multiple faces (for cube maps)
230 * - Each face has a list of mipmap levels
232 * - Each mipmap image may have multiple volume
233 * slices, if the image is three dimensional.
235 * - Each slice is a 2D array of 'blocks'
237 * - Each block may be one or more pixels.
238 * (Usually 1, more for DXT or YUV formats.)
240 * Surfaces are generic host VRAM objects. The SVGA3D device
241 * may optimize surfaces according to the format they were
242 * created with, but this format does not limit the ways in
243 * which the surface may be used. For example, a depth surface
244 * can be used as a texture, or a floating point image may
245 * be used as a vertex buffer. Some surface usages may be
246 * lower performance, due to software emulation, but any
247 * usage should work with any surface.
249 * If 'sid' is already defined, the old surface is deleted
250 * and this new surface replaces it.
252 * Surface IDs are arbitrary small non-negative integers,
253 * global to the entire SVGA device.
256 * Returns pointers to arrays allocated in the FIFO for 'faces'
260 * Begins a FIFO reservation.
262 *----------------------------------------------------------------------
266 SVGA3D_BeginDefineSurface(struct svga_winsys_context
*swc
,
267 struct svga_winsys_surface
*sid
, // IN
268 SVGA3dSurfaceFlags flags
, // IN
269 SVGA3dSurfaceFormat format
, // IN
270 SVGA3dSurfaceFace
**faces
, // OUT
271 SVGA3dSize
**mipSizes
, // OUT
272 uint32 numMipSizes
) // IN
274 SVGA3dCmdDefineSurface
*cmd
;
276 cmd
= SVGA3D_FIFOReserve(swc
,
277 SVGA_3D_CMD_SURFACE_DEFINE
, sizeof *cmd
+
278 sizeof **mipSizes
* numMipSizes
, 1);
280 return PIPE_ERROR_OUT_OF_MEMORY
;
282 swc
->surface_relocation(swc
, &cmd
->sid
, sid
, PIPE_BUFFER_USAGE_GPU_WRITE
);
283 cmd
->surfaceFlags
= flags
;
284 cmd
->format
= format
;
286 *faces
= &cmd
->face
[0];
287 *mipSizes
= (SVGA3dSize
*) &cmd
[1];
289 memset(*faces
, 0, sizeof **faces
* SVGA3D_MAX_SURFACE_FACES
);
290 memset(*mipSizes
, 0, sizeof **mipSizes
* numMipSizes
);
297 *----------------------------------------------------------------------
299 * SVGA3D_DefineSurface2D --
301 * This is a simplified version of SVGA3D_BeginDefineSurface(),
302 * which does not support cube maps, mipmaps, or volume textures.
310 *----------------------------------------------------------------------
314 SVGA3D_DefineSurface2D(struct svga_winsys_context
*swc
, // IN
315 struct svga_winsys_surface
*sid
, // IN
318 SVGA3dSurfaceFormat format
) // IN
320 SVGA3dSize
*mipSizes
;
321 SVGA3dSurfaceFace
*faces
;
324 ret
= SVGA3D_BeginDefineSurface(swc
,
325 sid
, 0, format
, &faces
, &mipSizes
, 1);
329 faces
[0].numMipLevels
= 1;
331 mipSizes
[0].width
= width
;
332 mipSizes
[0].height
= height
;
333 mipSizes
[0].depth
= 1;
342 *----------------------------------------------------------------------
344 * SVGA3D_DestroySurface --
346 * Release the host VRAM encapsulated by a particular surface ID.
354 *----------------------------------------------------------------------
358 SVGA3D_DestroySurface(struct svga_winsys_context
*swc
,
359 struct svga_winsys_surface
*sid
) // IN
361 SVGA3dCmdDestroySurface
*cmd
;
363 cmd
= SVGA3D_FIFOReserve(swc
,
364 SVGA_3D_CMD_SURFACE_DESTROY
, sizeof *cmd
, 1);
366 return PIPE_ERROR_OUT_OF_MEMORY
;
368 swc
->surface_relocation(swc
, &cmd
->sid
, sid
, PIPE_BUFFER_USAGE_GPU_READ
);
376 *----------------------------------------------------------------------
378 * SVGA3D_BeginSurfaceDMA--
380 * Begin a SURFACE_DMA command. This reserves space for it in
381 * the FIFO, and returns a pointer to the command's box array.
382 * This function must be paired with SVGA_FIFOCommitAll().
384 * When the SVGA3D device asynchronously processes this FIFO
385 * command, a DMA operation is performed between host VRAM and
386 * a generic SVGAGuestPtr. The guest pointer may refer to guest
387 * VRAM (provided by the SVGA PCI device) or to guest system
388 * memory that has been set up as a Guest Memory Region (GMR)
389 * by the SVGA device.
391 * The guest's DMA buffer must remain valid (not freed, paged out,
392 * or overwritten) until the host has finished processing this
393 * command. The guest can determine that the host has finished
394 * by using the SVGA device's FIFO Fence mechanism.
396 * The guest's image buffer can be an arbitrary size and shape.
397 * Guest image data is interpreted according to the SVGA3D surface
398 * format specified when the surface was defined.
400 * The caller may optionally define the guest image's pitch.
401 * guestImage->pitch can either be zero (assume image is tightly
402 * packed) or it must be the number of bytes between vertically
403 * adjacent image blocks.
405 * The provided copybox list specifies which regions of the source
406 * image are to be copied, and where they appear on the destination.
408 * NOTE: srcx/srcy are always on the guest image and x/y are
409 * always on the host image, regardless of the actual transfer
412 * For efficiency, the SVGA3D device is free to copy more data
413 * than specified. For example, it may round copy boxes outwards
414 * such that they lie on particular alignment boundaries.
416 *----------------------------------------------------------------------
420 SVGA3D_SurfaceDMA(struct svga_winsys_context
*swc
,
421 struct svga_transfer
*st
, // IN
422 SVGA3dTransferType transfer
, // IN
423 const SVGA3dCopyBox
*boxes
, // IN
424 uint32 numBoxes
) // IN
426 struct svga_texture
*texture
= svga_texture(st
->base
.texture
);
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
= PIPE_BUFFER_USAGE_GPU_READ
;
435 surface_flags
= PIPE_BUFFER_USAGE_GPU_WRITE
;
437 else if(transfer
== SVGA3D_READ_HOST_VRAM
) {
438 region_flags
= PIPE_BUFFER_USAGE_GPU_WRITE
;
439 surface_flags
= PIPE_BUFFER_USAGE_GPU_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
, texture
->handle
, surface_flags
);
457 cmd
->host
.face
= st
->base
.face
; /* PIPE_TEX_FACE_* and SVGA3D_CUBEFACE_* match */
458 cmd
->host
.mipmap
= st
->base
.level
;
460 cmd
->transfer
= transfer
;
462 memcpy(&cmd
[1], boxes
, boxesSize
);
464 pSuffix
= (SVGA3dCmdSurfaceDMASuffix
*)((uint8_t*)cmd
+ sizeof *cmd
+ boxesSize
);
465 pSuffix
->suffixSize
= sizeof *pSuffix
;
466 pSuffix
->maximumOffset
= st
->hw_nblocksy
*st
->base
.stride
;
467 memset(&pSuffix
->flags
, 0, sizeof pSuffix
->flags
);
476 SVGA3D_BufferDMA(struct svga_winsys_context
*swc
,
477 struct svga_winsys_buffer
*guest
,
478 struct svga_winsys_surface
*host
,
479 SVGA3dTransferType transfer
, // IN
481 uint32 guest_offset
, // IN
482 uint32 host_offset
, // IN
483 SVGA3dSurfaceDMAFlags flags
) // IN
485 SVGA3dCmdSurfaceDMA
*cmd
;
487 SVGA3dCmdSurfaceDMASuffix
*pSuffix
;
488 unsigned region_flags
;
489 unsigned surface_flags
;
491 if(transfer
== SVGA3D_WRITE_HOST_VRAM
) {
492 region_flags
= PIPE_BUFFER_USAGE_GPU_READ
;
493 surface_flags
= PIPE_BUFFER_USAGE_GPU_WRITE
;
495 else if(transfer
== SVGA3D_READ_HOST_VRAM
) {
496 region_flags
= PIPE_BUFFER_USAGE_GPU_WRITE
;
497 surface_flags
= PIPE_BUFFER_USAGE_GPU_READ
;
501 return PIPE_ERROR_BAD_INPUT
;
504 cmd
= SVGA3D_FIFOReserve(swc
,
505 SVGA_3D_CMD_SURFACE_DMA
,
506 sizeof *cmd
+ sizeof *box
+ sizeof *pSuffix
,
509 return PIPE_ERROR_OUT_OF_MEMORY
;
511 swc
->region_relocation(swc
, &cmd
->guest
.ptr
, guest
, 0, region_flags
);
512 cmd
->guest
.pitch
= 0;
514 swc
->surface_relocation(swc
, &cmd
->host
.sid
, host
, surface_flags
);
516 cmd
->host
.mipmap
= 0;
518 cmd
->transfer
= transfer
;
520 box
= (SVGA3dCopyBox
*)&cmd
[1];
521 box
->x
= host_offset
;
527 box
->srcx
= guest_offset
;
531 pSuffix
= (SVGA3dCmdSurfaceDMASuffix
*)((uint8_t*)cmd
+ sizeof *cmd
+ sizeof *box
);
532 pSuffix
->suffixSize
= sizeof *pSuffix
;
533 pSuffix
->maximumOffset
= guest_offset
+ size
;
534 pSuffix
->flags
= flags
;
543 *----------------------------------------------------------------------
545 * SVGA3D_SetRenderTarget --
547 * Bind a surface object to a particular render target attachment
548 * point on the current context. Render target attachment points
549 * exist for color buffers, a depth buffer, and a stencil buffer.
551 * The SVGA3D device is quite lenient about the types of surfaces
552 * that may be used as render targets. The color buffers must
553 * all be the same size, but the depth and stencil buffers do not
554 * have to be the same size as the color buffer. All attachments
557 * Some combinations of render target formats may require software
558 * emulation, depending on the capabilities of the host graphics
559 * API and graphics hardware.
567 *----------------------------------------------------------------------
571 SVGA3D_SetRenderTarget(struct svga_winsys_context
*swc
,
572 SVGA3dRenderTargetType type
, // IN
573 struct pipe_surface
*surface
) // IN
575 SVGA3dCmdSetRenderTarget
*cmd
;
577 cmd
= SVGA3D_FIFOReserve(swc
,
578 SVGA_3D_CMD_SETRENDERTARGET
, sizeof *cmd
, 1);
580 return PIPE_ERROR_OUT_OF_MEMORY
;
587 surface_to_surfaceid(swc
, surface
, &cmd
->target
, PIPE_BUFFER_USAGE_GPU_WRITE
);
600 *----------------------------------------------------------------------
602 * SVGA3D_DefineShader --
604 * Upload the bytecode for a new shader. The bytecode is "SVGA3D
605 * format", which is theoretically a binary-compatible superset
606 * of Microsoft's DirectX shader bytecode. In practice, the
607 * SVGA3D bytecode doesn't yet have any extensions to DirectX's
610 * The SVGA3D device supports shader models 1.1 through 2.0.
612 * The caller chooses a shader ID (small positive integer) by
613 * which this shader will be identified in future commands. This
614 * ID is in a namespace which is per-context and per-shader-type.
616 * 'bytecodeLen' is specified in bytes. It must be a multiple of 4.
624 *----------------------------------------------------------------------
628 SVGA3D_DefineShader(struct svga_winsys_context
*swc
,
630 SVGA3dShaderType type
, // IN
631 const uint32
*bytecode
, // IN
632 uint32 bytecodeLen
) // IN
634 SVGA3dCmdDefineShader
*cmd
;
636 assert(bytecodeLen
% 4 == 0);
638 cmd
= SVGA3D_FIFOReserve(swc
,
639 SVGA_3D_CMD_SHADER_DEFINE
, sizeof *cmd
+ bytecodeLen
,
642 return PIPE_ERROR_OUT_OF_MEMORY
;
647 memcpy(&cmd
[1], bytecode
, bytecodeLen
);
655 *----------------------------------------------------------------------
657 * SVGA3D_DestroyShader --
659 * Delete a shader that was created by SVGA3D_DefineShader. If
660 * the shader was the current vertex or pixel shader for its
661 * context, rendering results are undefined until a new shader is
670 *----------------------------------------------------------------------
674 SVGA3D_DestroyShader(struct svga_winsys_context
*swc
,
676 SVGA3dShaderType type
) // IN
678 SVGA3dCmdDestroyShader
*cmd
;
680 cmd
= SVGA3D_FIFOReserve(swc
,
681 SVGA_3D_CMD_SHADER_DESTROY
, sizeof *cmd
,
684 return PIPE_ERROR_OUT_OF_MEMORY
;
696 *----------------------------------------------------------------------
698 * SVGA3D_SetShaderConst --
700 * Set the value of a shader constant.
702 * Shader constants are analogous to uniform variables in GLSL,
703 * except that they belong to the render context rather than to
704 * an individual shader.
706 * Constants may have one of three types: A 4-vector of floats,
707 * a 4-vector of integers, or a single boolean flag.
715 *----------------------------------------------------------------------
719 SVGA3D_SetShaderConst(struct svga_winsys_context
*swc
,
721 SVGA3dShaderType type
, // IN
722 SVGA3dShaderConstType ctype
, // IN
723 const void *value
) // IN
725 SVGA3dCmdSetShaderConst
*cmd
;
727 cmd
= SVGA3D_FIFOReserve(swc
,
728 SVGA_3D_CMD_SET_SHADER_CONST
, sizeof *cmd
,
731 return PIPE_ERROR_OUT_OF_MEMORY
;
740 case SVGA3D_CONST_TYPE_FLOAT
:
741 case SVGA3D_CONST_TYPE_INT
:
742 memcpy(&cmd
->values
, value
, sizeof cmd
->values
);
745 case SVGA3D_CONST_TYPE_BOOL
:
746 memset(&cmd
->values
, 0, sizeof cmd
->values
);
747 cmd
->values
[0] = *(uint32
*)value
;
765 *----------------------------------------------------------------------
767 * SVGA3D_SetShader --
769 * Switch active shaders. This binds a new vertex or pixel shader
770 * to the specified context.
772 * A shader ID of SVGA3D_INVALID_ID unbinds any shader, switching
773 * back to the fixed function vertex or pixel pipeline.
781 *----------------------------------------------------------------------
785 SVGA3D_SetShader(struct svga_winsys_context
*swc
,
786 SVGA3dShaderType type
, // IN
789 SVGA3dCmdSetShader
*cmd
;
791 cmd
= SVGA3D_FIFOReserve(swc
,
792 SVGA_3D_CMD_SET_SHADER
, sizeof *cmd
,
795 return PIPE_ERROR_OUT_OF_MEMORY
;
807 *----------------------------------------------------------------------
809 * SVGA3D_BeginClear --
811 * Begin a CLEAR command. This reserves space for it in the FIFO,
812 * and returns a pointer to the command's rectangle array. This
813 * function must be paired with SVGA_FIFOCommitAll().
815 * Clear is a rendering operation which fills a list of
816 * rectangles with constant values on all render target types
817 * indicated by 'flags'.
819 * Clear is not affected by clipping, depth test, or other
820 * render state which affects the fragment pipeline.
826 * May write to attached render target surfaces.
828 *----------------------------------------------------------------------
832 SVGA3D_BeginClear(struct svga_winsys_context
*swc
,
833 SVGA3dClearFlag flags
, // IN
836 uint32 stencil
, // IN
837 SVGA3dRect
**rects
, // OUT
838 uint32 numRects
) // IN
842 cmd
= SVGA3D_FIFOReserve(swc
,
844 sizeof *cmd
+ sizeof **rects
* numRects
,
847 return PIPE_ERROR_OUT_OF_MEMORY
;
850 cmd
->clearFlag
= flags
;
853 cmd
->stencil
= stencil
;
854 *rects
= (SVGA3dRect
*) &cmd
[1];
861 *----------------------------------------------------------------------
863 * SVGA3D_ClearRect --
865 * This is a simplified version of SVGA3D_BeginClear().
873 *----------------------------------------------------------------------
877 SVGA3D_ClearRect(struct svga_winsys_context
*swc
,
878 SVGA3dClearFlag flags
, // IN
881 uint32 stencil
, // IN
890 ret
= SVGA3D_BeginClear(swc
, flags
, color
, depth
, stencil
, &rect
, 1);
892 return PIPE_ERROR_OUT_OF_MEMORY
;
894 memset(rect
, 0, sizeof *rect
);
906 *----------------------------------------------------------------------
908 * SVGA3D_BeginDrawPrimitives --
910 * Begin a DRAW_PRIMITIVES command. This reserves space for it in
911 * the FIFO, and returns a pointer to the command's arrays.
912 * This function must be paired with SVGA_FIFOCommitAll().
914 * Drawing commands consist of two variable-length arrays:
915 * SVGA3dVertexDecl elements declare a set of vertex buffers to
916 * use while rendering, and SVGA3dPrimitiveRange elements specify
917 * groups of primitives each with an optional index buffer.
919 * The decls and ranges arrays are initialized to zero.
925 * May write to attached render target surfaces.
927 *----------------------------------------------------------------------
931 SVGA3D_BeginDrawPrimitives(struct svga_winsys_context
*swc
,
932 SVGA3dVertexDecl
**decls
, // OUT
933 uint32 numVertexDecls
, // IN
934 SVGA3dPrimitiveRange
**ranges
, // OUT
935 uint32 numRanges
) // IN
937 SVGA3dCmdDrawPrimitives
*cmd
;
938 SVGA3dVertexDecl
*declArray
;
939 SVGA3dPrimitiveRange
*rangeArray
;
940 uint32 declSize
= sizeof **decls
* numVertexDecls
;
941 uint32 rangeSize
= sizeof **ranges
* numRanges
;
943 cmd
= SVGA3D_FIFOReserve(swc
,
944 SVGA_3D_CMD_DRAW_PRIMITIVES
,
945 sizeof *cmd
+ declSize
+ rangeSize
,
946 numVertexDecls
+ numRanges
);
948 return PIPE_ERROR_OUT_OF_MEMORY
;
951 cmd
->numVertexDecls
= numVertexDecls
;
952 cmd
->numRanges
= numRanges
;
954 declArray
= (SVGA3dVertexDecl
*) &cmd
[1];
955 rangeArray
= (SVGA3dPrimitiveRange
*) &declArray
[numVertexDecls
];
957 memset(declArray
, 0, declSize
);
958 memset(rangeArray
, 0, rangeSize
);
961 *ranges
= rangeArray
;
968 *----------------------------------------------------------------------
970 * SVGA3D_BeginSurfaceCopy --
972 * Begin a SURFACE_COPY command. This reserves space for it in
973 * the FIFO, and returns a pointer to the command's arrays. This
974 * function must be paired with SVGA_FIFOCommitAll().
976 * The box array is initialized with zeroes.
982 * Asynchronously copies a list of boxes from surface to surface.
984 *----------------------------------------------------------------------
988 SVGA3D_BeginSurfaceCopy(struct svga_winsys_context
*swc
,
989 struct pipe_surface
*src
, // IN
990 struct pipe_surface
*dest
, // IN
991 SVGA3dCopyBox
**boxes
, // OUT
992 uint32 numBoxes
) // IN
994 SVGA3dCmdSurfaceCopy
*cmd
;
995 uint32 boxesSize
= sizeof **boxes
* numBoxes
;
997 cmd
= SVGA3D_FIFOReserve(swc
,
998 SVGA_3D_CMD_SURFACE_COPY
, sizeof *cmd
+ boxesSize
,
1001 return PIPE_ERROR_OUT_OF_MEMORY
;
1003 surface_to_surfaceid(swc
, src
, &cmd
->src
, PIPE_BUFFER_USAGE_GPU_READ
);
1004 surface_to_surfaceid(swc
, dest
, &cmd
->dest
, PIPE_BUFFER_USAGE_GPU_WRITE
);
1005 *boxes
= (SVGA3dCopyBox
*) &cmd
[1];
1007 memset(*boxes
, 0, boxesSize
);
1014 *----------------------------------------------------------------------
1016 * SVGA3D_SurfaceStretchBlt --
1018 * Issue a SURFACE_STRETCHBLT command: an asynchronous
1019 * surface-to-surface blit, with scaling.
1025 * Asynchronously copies one box from surface to surface.
1027 *----------------------------------------------------------------------
1031 SVGA3D_SurfaceStretchBlt(struct svga_winsys_context
*swc
,
1032 struct pipe_surface
*src
, // IN
1033 struct pipe_surface
*dest
, // IN
1034 SVGA3dBox
*boxSrc
, // IN
1035 SVGA3dBox
*boxDest
, // IN
1036 SVGA3dStretchBltMode mode
) // IN
1038 SVGA3dCmdSurfaceStretchBlt
*cmd
;
1040 cmd
= SVGA3D_FIFOReserve(swc
,
1041 SVGA_3D_CMD_SURFACE_STRETCHBLT
, sizeof *cmd
,
1044 return PIPE_ERROR_OUT_OF_MEMORY
;
1046 surface_to_surfaceid(swc
, src
, &cmd
->src
, PIPE_BUFFER_USAGE_GPU_READ
);
1047 surface_to_surfaceid(swc
, dest
, &cmd
->dest
, PIPE_BUFFER_USAGE_GPU_WRITE
);
1048 cmd
->boxSrc
= *boxSrc
;
1049 cmd
->boxDest
= *boxDest
;
1058 *----------------------------------------------------------------------
1060 * SVGA3D_SetViewport --
1062 * Set the current context's viewport rectangle. The viewport
1063 * is clipped to the dimensions of the current render target,
1064 * then all rendering is clipped to the viewport.
1072 *----------------------------------------------------------------------
1076 SVGA3D_SetViewport(struct svga_winsys_context
*swc
,
1077 SVGA3dRect
*rect
) // IN
1079 SVGA3dCmdSetViewport
*cmd
;
1081 cmd
= SVGA3D_FIFOReserve(swc
,
1082 SVGA_3D_CMD_SETVIEWPORT
, sizeof *cmd
,
1085 return PIPE_ERROR_OUT_OF_MEMORY
;
1087 cmd
->cid
= swc
->cid
;
1098 *----------------------------------------------------------------------
1100 * SVGA3D_SetScissorRect --
1102 * Set the current context's scissor rectangle. If scissor
1103 * is enabled then all rendering is clipped to the scissor.
1111 *----------------------------------------------------------------------
1115 SVGA3D_SetScissorRect(struct svga_winsys_context
*swc
,
1116 SVGA3dRect
*rect
) // IN
1118 SVGA3dCmdSetScissorRect
*cmd
;
1120 cmd
= SVGA3D_FIFOReserve(swc
,
1121 SVGA_3D_CMD_SETSCISSORRECT
, sizeof *cmd
,
1124 return PIPE_ERROR_OUT_OF_MEMORY
;
1126 cmd
->cid
= swc
->cid
;
1134 *----------------------------------------------------------------------
1136 * SVGA3D_SetClipPlane --
1138 * Set one of the current context's clip planes. If the clip
1139 * plane is enabled then all 3d rendering is clipped to against
1148 *----------------------------------------------------------------------
1151 enum pipe_error
SVGA3D_SetClipPlane(struct svga_winsys_context
*swc
,
1152 uint32 index
, const float *plane
)
1154 SVGA3dCmdSetClipPlane
*cmd
;
1156 cmd
= SVGA3D_FIFOReserve(swc
,
1157 SVGA_3D_CMD_SETCLIPPLANE
, sizeof *cmd
,
1160 return PIPE_ERROR_OUT_OF_MEMORY
;
1162 cmd
->cid
= swc
->cid
;
1164 cmd
->plane
[0] = plane
[0];
1165 cmd
->plane
[1] = plane
[1];
1166 cmd
->plane
[2] = plane
[2];
1167 cmd
->plane
[3] = plane
[3];
1174 *----------------------------------------------------------------------
1176 * SVGA3D_SetZRange --
1178 * Set the range of the depth buffer to use. 'min' and 'max'
1179 * are values between 0.0 and 1.0.
1187 *----------------------------------------------------------------------
1191 SVGA3D_SetZRange(struct svga_winsys_context
*swc
,
1195 SVGA3dCmdSetZRange
*cmd
;
1197 cmd
= SVGA3D_FIFOReserve(swc
,
1198 SVGA_3D_CMD_SETZRANGE
, sizeof *cmd
,
1201 return PIPE_ERROR_OUT_OF_MEMORY
;
1203 cmd
->cid
= swc
->cid
;
1204 cmd
->zRange
.min
= zMin
;
1205 cmd
->zRange
.max
= zMax
;
1213 *----------------------------------------------------------------------
1215 * SVGA3D_BeginSetTextureState --
1217 * Begin a SETTEXTURESTATE command. This reserves space for it in
1218 * the FIFO, and returns a pointer to the command's texture state
1219 * array. This function must be paired with SVGA_FIFOCommitAll().
1221 * This command sets rendering state which is per-texture-unit.
1223 * XXX: Individual texture states need documentation. However,
1224 * they are very similar to the texture states defined by
1225 * Direct3D. The D3D documentation is a good starting point
1226 * for understanding SVGA3D texture states.
1234 *----------------------------------------------------------------------
1238 SVGA3D_BeginSetTextureState(struct svga_winsys_context
*swc
,
1239 SVGA3dTextureState
**states
, // OUT
1240 uint32 numStates
) // IN
1242 SVGA3dCmdSetTextureState
*cmd
;
1244 cmd
= SVGA3D_FIFOReserve(swc
,
1245 SVGA_3D_CMD_SETTEXTURESTATE
,
1246 sizeof *cmd
+ sizeof **states
* numStates
,
1249 return PIPE_ERROR_OUT_OF_MEMORY
;
1251 cmd
->cid
= swc
->cid
;
1252 *states
= (SVGA3dTextureState
*) &cmd
[1];
1259 *----------------------------------------------------------------------
1261 * SVGA3D_BeginSetRenderState --
1263 * Begin a SETRENDERSTATE command. This reserves space for it in
1264 * the FIFO, and returns a pointer to the command's texture state
1265 * array. This function must be paired with SVGA_FIFOCommitAll().
1267 * This command sets rendering state which is global to the context.
1269 * XXX: Individual render states need documentation. However,
1270 * they are very similar to the render states defined by
1271 * Direct3D. The D3D documentation is a good starting point
1272 * for understanding SVGA3D render states.
1280 *----------------------------------------------------------------------
1284 SVGA3D_BeginSetRenderState(struct svga_winsys_context
*swc
,
1285 SVGA3dRenderState
**states
, // OUT
1286 uint32 numStates
) // IN
1288 SVGA3dCmdSetRenderState
*cmd
;
1290 cmd
= SVGA3D_FIFOReserve(swc
,
1291 SVGA_3D_CMD_SETRENDERSTATE
,
1292 sizeof *cmd
+ sizeof **states
* numStates
,
1295 return PIPE_ERROR_OUT_OF_MEMORY
;
1297 cmd
->cid
= swc
->cid
;
1298 *states
= (SVGA3dRenderState
*) &cmd
[1];
1305 *----------------------------------------------------------------------
1307 * SVGA3D_BeginQuery--
1309 * Issues a SVGA_3D_CMD_BEGIN_QUERY command.
1315 * Commits space in the FIFO memory.
1317 *----------------------------------------------------------------------
1321 SVGA3D_BeginQuery(struct svga_winsys_context
*swc
,
1322 SVGA3dQueryType type
) // IN
1324 SVGA3dCmdBeginQuery
*cmd
;
1326 cmd
= SVGA3D_FIFOReserve(swc
,
1327 SVGA_3D_CMD_BEGIN_QUERY
,
1331 return PIPE_ERROR_OUT_OF_MEMORY
;
1333 cmd
->cid
= swc
->cid
;
1343 *----------------------------------------------------------------------
1347 * Issues a SVGA_3D_CMD_END_QUERY command.
1353 * Commits space in the FIFO memory.
1355 *----------------------------------------------------------------------
1359 SVGA3D_EndQuery(struct svga_winsys_context
*swc
,
1360 SVGA3dQueryType type
, // IN
1361 struct svga_winsys_buffer
*buffer
) // IN/OUT
1363 SVGA3dCmdEndQuery
*cmd
;
1365 cmd
= SVGA3D_FIFOReserve(swc
,
1366 SVGA_3D_CMD_END_QUERY
,
1370 return PIPE_ERROR_OUT_OF_MEMORY
;
1372 cmd
->cid
= swc
->cid
;
1375 swc
->region_relocation(swc
, &cmd
->guestResult
, buffer
, 0,
1376 PIPE_BUFFER_USAGE_GPU_WRITE
);
1385 *----------------------------------------------------------------------
1387 * SVGA3D_WaitForQuery--
1389 * Issues a SVGA_3D_CMD_WAIT_FOR_QUERY command. This reserves space
1390 * for it in the FIFO. This doesn't actually wait for the query to
1391 * finish but instead tells the host to start a wait at the driver
1392 * level. The caller can wait on the status variable in the
1393 * guestPtr memory or send an insert fence instruction after this
1394 * command and wait on the fence.
1400 * Commits space in the FIFO memory.
1402 *----------------------------------------------------------------------
1406 SVGA3D_WaitForQuery(struct svga_winsys_context
*swc
,
1407 SVGA3dQueryType type
, // IN
1408 struct svga_winsys_buffer
*buffer
) // IN/OUT
1410 SVGA3dCmdWaitForQuery
*cmd
;
1412 cmd
= SVGA3D_FIFOReserve(swc
,
1413 SVGA_3D_CMD_WAIT_FOR_QUERY
,
1417 return PIPE_ERROR_OUT_OF_MEMORY
;
1419 cmd
->cid
= swc
->cid
;
1422 swc
->region_relocation(swc
, &cmd
->guestResult
, buffer
, 0,
1423 PIPE_BUFFER_USAGE_GPU_WRITE
);