1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2007 VMware, Inc.
4848b8605Smrg * All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the
8848b8605Smrg * "Software"), to deal in the Software without restriction, including
9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish,
10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to
11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to
12848b8605Smrg * the following conditions:
13848b8605Smrg *
14848b8605Smrg * The above copyright notice and this permission notice (including the
15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions
16848b8605Smrg * of the Software.
17848b8605Smrg *
18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25848b8605Smrg *
26848b8605Smrg **************************************************************************/
27848b8605Smrg
28848b8605Smrg#ifndef I915_BATCHBUFFER_H
29848b8605Smrg#define I915_BATCHBUFFER_H
30848b8605Smrg
31848b8605Smrg#include "i915_winsys.h"
32848b8605Smrg#include "util/u_debug.h"
33848b8605Smrg
34848b8605Smrgstruct i915_context;
35848b8605Smrg
36b8e80941Smrgstatic inline size_t
37848b8605Smrgi915_winsys_batchbuffer_space(struct i915_winsys_batchbuffer *batch)
38848b8605Smrg{
39848b8605Smrg   return batch->size - (batch->ptr - batch->map);
40848b8605Smrg}
41848b8605Smrg
42b8e80941Smrgstatic inline boolean
43848b8605Smrgi915_winsys_batchbuffer_check(struct i915_winsys_batchbuffer *batch,
44848b8605Smrg                              size_t dwords)
45848b8605Smrg{
46848b8605Smrg   return dwords * 4 <= i915_winsys_batchbuffer_space(batch);
47848b8605Smrg}
48848b8605Smrg
49b8e80941Smrgstatic inline void
50848b8605Smrgi915_winsys_batchbuffer_dword_unchecked(struct i915_winsys_batchbuffer *batch,
51848b8605Smrg                                        unsigned dword)
52848b8605Smrg{
53848b8605Smrg   *(unsigned *)batch->ptr = dword;
54848b8605Smrg   batch->ptr += 4;
55848b8605Smrg}
56848b8605Smrg
57b8e80941Smrgstatic inline void
58848b8605Smrgi915_winsys_batchbuffer_float(struct i915_winsys_batchbuffer *batch,
59848b8605Smrg                              float f)
60848b8605Smrg{
61848b8605Smrg   union { float f; unsigned int ui; } uif;
62848b8605Smrg   uif.f = f;
63848b8605Smrg   assert (i915_winsys_batchbuffer_space(batch) >= 4);
64848b8605Smrg   i915_winsys_batchbuffer_dword_unchecked(batch, uif.ui);
65848b8605Smrg}
66848b8605Smrg
67b8e80941Smrgstatic inline void
68848b8605Smrgi915_winsys_batchbuffer_dword(struct i915_winsys_batchbuffer *batch,
69848b8605Smrg                              unsigned dword)
70848b8605Smrg{
71848b8605Smrg   assert (i915_winsys_batchbuffer_space(batch) >= 4);
72848b8605Smrg   i915_winsys_batchbuffer_dword_unchecked(batch, dword);
73848b8605Smrg}
74848b8605Smrg
75b8e80941Smrgstatic inline void
76848b8605Smrgi915_winsys_batchbuffer_write(struct i915_winsys_batchbuffer *batch,
77848b8605Smrg                              void *data,
78848b8605Smrg                              size_t size)
79848b8605Smrg{
80848b8605Smrg   assert (i915_winsys_batchbuffer_space(batch) >= size);
81848b8605Smrg
82848b8605Smrg   memcpy(batch->ptr, data, size);
83848b8605Smrg   batch->ptr += size;
84848b8605Smrg}
85848b8605Smrg
86b8e80941Smrgstatic inline boolean
87848b8605Smrgi915_winsys_validate_buffers(struct i915_winsys_batchbuffer *batch,
88848b8605Smrg                             struct i915_winsys_buffer **buffers,
89848b8605Smrg                             int num_of_buffers)
90848b8605Smrg{
91848b8605Smrg   return batch->iws->validate_buffers(batch, buffers, num_of_buffers);
92848b8605Smrg}
93848b8605Smrg
94b8e80941Smrgstatic inline int
95848b8605Smrgi915_winsys_batchbuffer_reloc(struct i915_winsys_batchbuffer *batch,
96848b8605Smrg                              struct i915_winsys_buffer *buffer,
97848b8605Smrg                              enum i915_winsys_buffer_usage usage,
98848b8605Smrg                              size_t offset, boolean fenced)
99848b8605Smrg{
100848b8605Smrg   return batch->iws->batchbuffer_reloc(batch, buffer, usage, offset, fenced);
101848b8605Smrg}
102848b8605Smrg
103848b8605Smrg#endif
104