1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
38 #include <sys/ioctl.h>
39 #include <X11/Xlibint.h>
41 #include <X11/extensions/Xv.h>
42 #include <X11/extensions/Xvlib.h>
43 #include <X11/extensions/XvMC.h>
44 #include <X11/extensions/XvMClib.h>
46 #include "intel_xvmc.h"
47 #include "intel_batchbuffer.h"
48 #include "brw_defines.h"
49 #include "brw_structs.h"
50 #define MI_BATCH_BUFFER_END (0xA << 23)
51 #define BATCH_SIZE 8*1024 /* one bo is allocated each time, so the size can be small */
53 static void i965_end_batch(void)
55 unsigned int size = xvmc_driver->batch.ptr -
56 xvmc_driver->batch.init_ptr;
57 if ((size & 4) == 0) {
58 *(unsigned int *)xvmc_driver->batch.ptr = 0;
59 xvmc_driver->batch.ptr += 4;
61 *(unsigned int *)xvmc_driver->batch.ptr = MI_BATCH_BUFFER_END;
62 xvmc_driver->batch.ptr += 4;
65 Bool intelInitBatchBuffer(void)
67 if ((xvmc_driver->batch.buf =
68 drm_intel_bo_alloc(xvmc_driver->bufmgr,
69 "batch buffer", BATCH_SIZE, 0x1000)) == NULL) {
70 fprintf(stderr, "unable to alloc batch buffer\n");
74 drm_intel_gem_bo_map_gtt(xvmc_driver->batch.buf);
76 xvmc_driver->batch.init_ptr = xvmc_driver->batch.buf->virtual;
77 xvmc_driver->batch.size = BATCH_SIZE;
78 xvmc_driver->batch.space = BATCH_SIZE;
79 xvmc_driver->batch.ptr = xvmc_driver->batch.init_ptr;
83 void intelFiniBatchBuffer(void)
85 drm_intel_gem_bo_unmap_gtt(xvmc_driver->batch.buf);
87 drm_intel_bo_unreference(xvmc_driver->batch.buf);
90 void intelFlushBatch(Bool refill)
94 drm_intel_gem_bo_unmap_gtt(xvmc_driver->batch.buf);
96 drm_intel_bo_exec(xvmc_driver->batch.buf,
97 xvmc_driver->batch.ptr - xvmc_driver->batch.init_ptr,
100 drm_intel_bo_unreference(xvmc_driver->batch.buf);
101 if ((xvmc_driver->batch.buf =
102 drm_intel_bo_alloc(xvmc_driver->bufmgr,
103 "batch buffer", BATCH_SIZE, 0x1000)) == NULL) {
104 fprintf(stderr, "unable to alloc batch buffer\n");
107 drm_intel_gem_bo_map_gtt(xvmc_driver->batch.buf);
109 xvmc_driver->batch.init_ptr = xvmc_driver->batch.buf->virtual;
110 xvmc_driver->batch.size = BATCH_SIZE;
111 xvmc_driver->batch.space = BATCH_SIZE;
112 xvmc_driver->batch.ptr = xvmc_driver->batch.init_ptr;
115 void intelBatchbufferRequireSpace(int size)
117 assert(xvmc_driver->batch.ptr - xvmc_driver->batch.init_ptr + size <
118 xvmc_driver->batch.size - 8);
119 if (xvmc_driver->batch.ptr - xvmc_driver->batch.init_ptr + size
120 >= xvmc_driver->batch.size - 8)
124 void intelBatchbufferData(const void *data, unsigned bytes, unsigned flags)
126 intelBatchbufferRequireSpace(bytes);
127 memcpy(xvmc_driver->batch.ptr, data, bytes);
128 xvmc_driver->batch.ptr += bytes;
129 xvmc_driver->batch.space -= bytes;
132 void intel_batch_emit_reloc(dri_bo * bo, uint32_t read_domain,
133 uint32_t write_domain, uint32_t delta,
136 drm_intel_bo_emit_reloc(xvmc_driver->batch.buf,
137 ptr - xvmc_driver->batch.init_ptr, bo, delta,
138 read_domain, write_domain);