13464ebd5Sriastradh/**************************************************************************
23464ebd5Sriastradh *
3af69d88dSmrg * Copyright 2007 VMware, Inc.
43464ebd5Sriastradh * All Rights Reserved.
53464ebd5Sriastradh *
63464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
73464ebd5Sriastradh * copy of this software and associated documentation files (the
83464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including
93464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish,
103464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to
113464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to
123464ebd5Sriastradh * the following conditions:
133464ebd5Sriastradh *
143464ebd5Sriastradh * The above copyright notice and this permission notice (including the
153464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions
163464ebd5Sriastradh * of the Software.
173464ebd5Sriastradh *
183464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
193464ebd5Sriastradh * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
203464ebd5Sriastradh * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
223464ebd5Sriastradh * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
233464ebd5Sriastradh * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
243464ebd5Sriastradh * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
253464ebd5Sriastradh *
263464ebd5Sriastradh **************************************************************************/
273464ebd5Sriastradh
283464ebd5Sriastradh#ifndef I915_BATCHBUFFER_H
293464ebd5Sriastradh#define I915_BATCHBUFFER_H
303464ebd5Sriastradh
313464ebd5Sriastradh#include "util/u_debug.h"
327ec681f3Smrg#include "i915_winsys.h"
333464ebd5Sriastradh
343464ebd5Sriastradhstruct i915_context;
353464ebd5Sriastradh
3601e04c3fSmrgstatic inline size_t
373464ebd5Sriastradhi915_winsys_batchbuffer_space(struct i915_winsys_batchbuffer *batch)
383464ebd5Sriastradh{
393464ebd5Sriastradh   return batch->size - (batch->ptr - batch->map);
403464ebd5Sriastradh}
413464ebd5Sriastradh
427ec681f3Smrgstatic inline bool
433464ebd5Sriastradhi915_winsys_batchbuffer_check(struct i915_winsys_batchbuffer *batch,
443464ebd5Sriastradh                              size_t dwords)
453464ebd5Sriastradh{
463464ebd5Sriastradh   return dwords * 4 <= i915_winsys_batchbuffer_space(batch);
473464ebd5Sriastradh}
483464ebd5Sriastradh
4901e04c3fSmrgstatic inline void
503464ebd5Sriastradhi915_winsys_batchbuffer_dword_unchecked(struct i915_winsys_batchbuffer *batch,
51af69d88dSmrg                                        unsigned dword)
523464ebd5Sriastradh{
533464ebd5Sriastradh   *(unsigned *)batch->ptr = dword;
543464ebd5Sriastradh   batch->ptr += 4;
553464ebd5Sriastradh}
563464ebd5Sriastradh
5701e04c3fSmrgstatic inline void
587ec681f3Smrgi915_winsys_batchbuffer_float(struct i915_winsys_batchbuffer *batch, float f)
593464ebd5Sriastradh{
607ec681f3Smrg   union {
617ec681f3Smrg      float f;
627ec681f3Smrg      unsigned int ui;
637ec681f3Smrg   } uif;
643464ebd5Sriastradh   uif.f = f;
657ec681f3Smrg   assert(i915_winsys_batchbuffer_space(batch) >= 4);
663464ebd5Sriastradh   i915_winsys_batchbuffer_dword_unchecked(batch, uif.ui);
673464ebd5Sriastradh}
683464ebd5Sriastradh
6901e04c3fSmrgstatic inline void
703464ebd5Sriastradhi915_winsys_batchbuffer_dword(struct i915_winsys_batchbuffer *batch,
713464ebd5Sriastradh                              unsigned dword)
723464ebd5Sriastradh{
737ec681f3Smrg   assert(i915_winsys_batchbuffer_space(batch) >= 4);
743464ebd5Sriastradh   i915_winsys_batchbuffer_dword_unchecked(batch, dword);
753464ebd5Sriastradh}
763464ebd5Sriastradh
7701e04c3fSmrgstatic inline void
787ec681f3Smrgi915_winsys_batchbuffer_write(struct i915_winsys_batchbuffer *batch, void *data,
79af69d88dSmrg                              size_t size)
803464ebd5Sriastradh{
817ec681f3Smrg   assert(i915_winsys_batchbuffer_space(batch) >= size);
823464ebd5Sriastradh
833464ebd5Sriastradh   memcpy(batch->ptr, data, size);
843464ebd5Sriastradh   batch->ptr += size;
853464ebd5Sriastradh}
863464ebd5Sriastradh
877ec681f3Smrgstatic inline bool
883464ebd5Sriastradhi915_winsys_validate_buffers(struct i915_winsys_batchbuffer *batch,
89af69d88dSmrg                             struct i915_winsys_buffer **buffers,
90af69d88dSmrg                             int num_of_buffers)
913464ebd5Sriastradh{
923464ebd5Sriastradh   return batch->iws->validate_buffers(batch, buffers, num_of_buffers);
933464ebd5Sriastradh}
943464ebd5Sriastradh
9501e04c3fSmrgstatic inline int
963464ebd5Sriastradhi915_winsys_batchbuffer_reloc(struct i915_winsys_batchbuffer *batch,
973464ebd5Sriastradh                              struct i915_winsys_buffer *buffer,
983464ebd5Sriastradh                              enum i915_winsys_buffer_usage usage,
997ec681f3Smrg                              size_t offset, bool fenced)
1003464ebd5Sriastradh{
1013464ebd5Sriastradh   return batch->iws->batchbuffer_reloc(batch, buffer, usage, offset, fenced);
1023464ebd5Sriastradh}
1033464ebd5Sriastradh
1043464ebd5Sriastradh#endif
105