intel_batchbuffer.h revision beddf653a914903156712aa472b5deaddb7bbaed
16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#ifndef INTEL_BATCHBUFFER_H
26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_BATCHBUFFER_H
36b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "mtypes.h"
54cd3ef58a989f61ff22669648e4117426c6e603cDave Airlie
66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "dri_bufmgr.h"
76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_context;
96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
108e21bb516f87bfdde90d0f469ede4192435b9235Dave Airlie#define BATCH_SZ 16384
116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define BATCH_RESERVED 16
126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
13beddf653a914903156712aa472b5deaddb7bbaedEric Anholtenum cliprects_enable {
14beddf653a914903156712aa472b5deaddb7bbaedEric Anholt   INTEL_BATCH_CLIPRECTS = 0,
15beddf653a914903156712aa472b5deaddb7bbaedEric Anholt   INTEL_BATCH_NO_CLIPRECTS = 1
16beddf653a914903156712aa472b5deaddb7bbaedEric Anholt};
176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_batchbuffer
196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_context *intel;
216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
22cfc21190af1038f204d38ab4764a9c731b0323a5Eric Anholt   dri_bo *buf;
23cfc21190af1038f204d38ab4764a9c731b0323a5Eric Anholt   dri_fence *last_fence;
246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLubyte *map;
266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLubyte *ptr;
276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
28beddf653a914903156712aa472b5deaddb7bbaedEric Anholt   enum cliprects_enable cliprects_enable;
29beddf653a914903156712aa472b5deaddb7bbaedEric Anholt
306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint size;
31a8fee3a498c8c4966d57a5273408477f3aa3ce73Keith Whitwell
32a8fee3a498c8c4966d57a5273408477f3aa3ce73Keith Whitwell   GLuint dirty_state;
33a8fee3a498c8c4966d57a5273408477f3aa3ce73Keith Whitwell   GLuint id;
346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell};
356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_batchbuffer *intel_batchbuffer_alloc(struct intel_context
376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                  *intel);
386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_batchbuffer_free(struct intel_batchbuffer *batch);
406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_batchbuffer_finish(struct intel_batchbuffer *batch);
436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
44cfc21190af1038f204d38ab4764a9c731b0323a5Eric Anholtvoid intel_batchbuffer_flush(struct intel_batchbuffer *batch);
456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_batchbuffer_reset(struct intel_batchbuffer *batch);
476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Unlike bmBufferData, this currently requires the buffer be mapped.
506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Consider it a convenience function wrapping multple
516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * intel_buffer_dword() calls.
526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_batchbuffer_data(struct intel_batchbuffer *batch,
54beddf653a914903156712aa472b5deaddb7bbaedEric Anholt                            const void *data, GLuint bytes,
55beddf653a914903156712aa472b5deaddb7bbaedEric Anholt			    enum cliprects_enable cliprects_enable);
566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_batchbuffer_release_space(struct intel_batchbuffer *batch,
586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                     GLuint bytes);
596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith WhitwellGLboolean intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch,
61cfc21190af1038f204d38ab4764a9c731b0323a5Eric Anholt                                       dri_bo *buffer,
62cfc21190af1038f204d38ab4764a9c731b0323a5Eric Anholt                                       GLuint flags, GLuint offset);
636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Inline functions - might actually be better off with these
656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * non-inlined.  Certainly better off switching all command packets to
666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * be passed as structs rather than dwords, but that's a little bit of
676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * work...
686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic INLINE GLuint
706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_batchbuffer_space(struct intel_batchbuffer *batch)
716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map);
736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic INLINE void
776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, GLuint dword)
786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   assert(batch->map);
806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   assert(intel_batchbuffer_space(batch) >= 4);
816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   *(GLuint *) (batch->ptr) = dword;
826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   batch->ptr += 4;
836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic INLINE void
866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_batchbuffer_require_space(struct intel_batchbuffer *batch,
87beddf653a914903156712aa472b5deaddb7bbaedEric Anholt                                GLuint sz,
88beddf653a914903156712aa472b5deaddb7bbaedEric Anholt				enum cliprects_enable cliprects_enable)
896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   assert(sz < batch->size - 8);
91beddf653a914903156712aa472b5deaddb7bbaedEric Anholt   if (intel_batchbuffer_space(batch) < sz)
926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel_batchbuffer_flush(batch);
936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
94beddf653a914903156712aa472b5deaddb7bbaedEric Anholt   /* Upgrade the buffer to being looped over per cliprect if this batch
95beddf653a914903156712aa472b5deaddb7bbaedEric Anholt    * emit needs it.  The code used to emit a batch whenever the
96beddf653a914903156712aa472b5deaddb7bbaedEric Anholt    * cliprects_enable was changed, but reducing the overhead of frequent
97beddf653a914903156712aa472b5deaddb7bbaedEric Anholt    * batch flushing is more important than reducing state parsing,
98beddf653a914903156712aa472b5deaddb7bbaedEric Anholt    * particularly as we move towards private backbuffers and number
99beddf653a914903156712aa472b5deaddb7bbaedEric Anholt    * cliprects always being 1 except at swap.
100beddf653a914903156712aa472b5deaddb7bbaedEric Anholt    */
101beddf653a914903156712aa472b5deaddb7bbaedEric Anholt   if (cliprects_enable == INTEL_BATCH_CLIPRECTS)
102beddf653a914903156712aa472b5deaddb7bbaedEric Anholt      batch->cliprects_enable = INTEL_BATCH_CLIPRECTS;
1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Here are the crusty old macros, to be removed:
1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define BATCH_LOCALS
1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
109beddf653a914903156712aa472b5deaddb7bbaedEric Anholt#define BEGIN_BATCH(n, cliprects_enable) do {				\
110beddf653a914903156712aa472b5deaddb7bbaedEric Anholt   intel_batchbuffer_require_space(intel->batch, (n)*4, cliprects_enable); \
1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define OUT_BATCH(d)  intel_batchbuffer_emit_dword(intel->batch, d)
1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
115beddf653a914903156712aa472b5deaddb7bbaedEric Anholt#define OUT_RELOC(buf, cliprects_enable, delta) do { 			\
116cfc21190af1038f204d38ab4764a9c731b0323a5Eric Anholt   assert((delta) >= 0);						\
117beddf653a914903156712aa472b5deaddb7bbaedEric Anholt   intel_batchbuffer_emit_reloc(intel->batch, buf, cliprects_enable, delta); \
1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define ADVANCE_BATCH() do { } while(0)
1216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
124