intel_batchbuffer.h revision 6b9e31f3eb3dbe20cbc8493b963bbc6530e392c6
16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#ifndef INTEL_BATCHBUFFER_H 26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_BATCHBUFFER_H 36b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "mtypes.h" 56b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "dri_bufmgr.h" 66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_context; 86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define BATCH_SZ 16384 106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define BATCH_RESERVED 16 116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define MAX_RELOCS 100 136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_BATCH_NO_CLIPRECTS 0x1 156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_BATCH_CLIPRECTS 0x2 166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct buffer_reloc 186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct _DriBufferObject *buf; 206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint offset; 216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint delta; /* not needed? */ 226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}; 236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_batchbuffer 256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct bufmgr *bm; 276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct intel_context *intel; 286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct _DriBufferObject *buffer; 306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct _DriFenceObject *last_fence; 316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint flags; 326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell drmBOList list; 346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint list_count; 356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLubyte *map; 366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLubyte *ptr; 376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct buffer_reloc reloc[MAX_RELOCS]; 396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint nr_relocs; 406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint size; 416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}; 426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_batchbuffer *intel_batchbuffer_alloc(struct intel_context 446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *intel); 456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_batchbuffer_free(struct intel_batchbuffer *batch); 476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_batchbuffer_finish(struct intel_batchbuffer *batch); 506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct _DriFenceObject *intel_batchbuffer_flush(struct intel_batchbuffer 526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *batch); 536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_batchbuffer_reset(struct intel_batchbuffer *batch); 556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Unlike bmBufferData, this currently requires the buffer be mapped. 586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Consider it a convenience function wrapping multple 596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * intel_buffer_dword() calls. 606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_batchbuffer_data(struct intel_batchbuffer *batch, 626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell const void *data, GLuint bytes, GLuint flags); 636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_batchbuffer_release_space(struct intel_batchbuffer *batch, 656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint bytes); 666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith WhitwellGLboolean intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch, 686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct _DriBufferObject *buffer, 696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint flags, 706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint mask, GLuint offset); 716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Inline functions - might actually be better off with these 736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * non-inlined. Certainly better off switching all command packets to 746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * be passed as structs rather than dwords, but that's a little bit of 756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * work... 766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic INLINE GLuint 786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_batchbuffer_space(struct intel_batchbuffer *batch) 796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map); 816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic INLINE void 856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, GLuint dword) 866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell assert(batch->map); 886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell assert(intel_batchbuffer_space(batch) >= 4); 896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *(GLuint *) (batch->ptr) = dword; 906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell batch->ptr += 4; 916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic INLINE void 946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_batchbuffer_require_space(struct intel_batchbuffer *batch, 956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint sz, GLuint flags) 966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell assert(sz < batch->size - 8); 986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (intel_batchbuffer_space(batch) < sz || 996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell (batch->flags != 0 && flags != 0 && batch->flags != flags)) 1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel_batchbuffer_flush(batch); 1016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell batch->flags |= flags; 1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Here are the crusty old macros, to be removed: 1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define BATCH_LOCALS 1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define BEGIN_BATCH(n, flags) do { \ 1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell assert(!intel->prim.flush); \ 1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel_batchbuffer_require_space(intel->batch, (n)*4, flags); \ 1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0) 1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define OUT_BATCH(d) intel_batchbuffer_emit_dword(intel->batch, d) 1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define OUT_RELOC(buf,flags,mask,delta) do { \ 1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell assert((delta) >= 0); \ 1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell intel_batchbuffer_emit_reloc(intel->batch, buf, flags, mask, delta); \ 1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0) 1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define ADVANCE_BATCH() do { } while(0) 1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif 125