radeon/r200/r300: start to make cmd buf useful
authorDave Airlie <airlied@linux.ie>
Thu, 15 Jan 2009 06:41:01 +0000 (16:41 +1000)
committerDave Airlie <airlied@linux.ie>
Thu, 15 Jan 2009 06:45:39 +0000 (16:45 +1000)
src/mesa/drivers/dri/r200/Makefile
src/mesa/drivers/dri/r300/Makefile
src/mesa/drivers/dri/r300/r300_cmdbuf.c
src/mesa/drivers/dri/r300/r300_cmdbuf.h
src/mesa/drivers/dri/r300/r300_context.c
src/mesa/drivers/dri/radeon/common_cmdbuf.h [new file with mode: 0644]
src/mesa/drivers/dri/radeon/common_context.h
src/mesa/drivers/dri/radeon/common_misc.c
src/mesa/drivers/dri/radeon/common_misc.h

index 91211e4..6b90018 100644 (file)
@@ -61,7 +61,8 @@ COMMON_SYMLINKS = \
        common_lock.c \
        common_lock.h \
        common_misc.h \
-       common_misc.c
+       common_misc.c \
+       common_cmdbuf.h
 
 DRI_LIB_DEPS += -ldrm_radeon
 
index 18fab1d..942d76f 100644 (file)
@@ -83,7 +83,8 @@ COMMON_SYMLINKS = \
        common_lock.c \
        common_lock.h \
        common_misc.c \
-       common_misc.h
+       common_misc.h \
+       common_cmdbuf.h
 
 DRI_LIB_DEPS += -ldrm_radeon
 
index bbca71d..f4b4848 100644 (file)
@@ -69,21 +69,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 #define SPACE_FOR_FLUSHING     4
 
-void r300BeginBatch(r300ContextPtr r300, int n,
-                   int dostate,
-                    const char *file,
-                    const char *function,
-                    int line)
-{
-       rcommonEnsureCmdBufSpace(&r300->radeon, n, function);
-       if (!r300->radeon.cmdbuf.cs->cdw && dostate) {
-               if (RADEON_DEBUG & DEBUG_IOCTL)
-                       fprintf(stderr, "Reemit state after flush (from %s)\n", function);
-               r300EmitState(r300);
-       }
-       radeon_cs_begin(r300->radeon.cmdbuf.cs, n, file, function, line);
-}
-
 static void r300PrintStateAtom(r300ContextPtr r300,
                                struct radeon_state_atom *state)
 {
@@ -108,7 +93,7 @@ static void r300PrintStateAtom(r300ContextPtr r300,
  */
 static INLINE void r300EmitAtoms(r300ContextPtr r300, GLboolean dirty)
 {
-       BATCH_LOCALS(r300);
+       BATCH_LOCALS(&r300->radeon);
        struct radeon_state_atom *atom;
        int dwords;
 
@@ -198,7 +183,7 @@ static unsigned packet0_count(r300ContextPtr r300, uint32_t *pkt)
 void emit_vpu(GLcontext *ctx, struct radeon_state_atom * atom)
 {
        r300ContextPtr r300 = R300_CONTEXT(ctx);
-       BATCH_LOCALS(r300);
+       BATCH_LOCALS(&r300->radeon);
        drm_r300_cmd_header_t cmd;
     uint32_t addr, ndw, i;
 
@@ -237,7 +222,7 @@ void emit_vpu(GLcontext *ctx, struct radeon_state_atom * atom)
 void emit_r500fp(GLcontext *ctx, struct radeon_state_atom * atom)
 {
        r300ContextPtr r300 = R300_CONTEXT(ctx);
-       BATCH_LOCALS(r300);
+       BATCH_LOCALS(&r300->radeon);
        drm_r300_cmd_header_t cmd;
        uint32_t addr, ndw, i, sz;
        int type, clamp, stride;
@@ -277,7 +262,7 @@ void emit_r500fp(GLcontext *ctx, struct radeon_state_atom * atom)
 static void emit_tex_offsets(GLcontext *ctx, struct radeon_state_atom * atom)
 {
        r300ContextPtr r300 = R300_CONTEXT(ctx);
-       BATCH_LOCALS(r300);
+       BATCH_LOCALS(&r300->radeon);
        int numtmus = packet0_count(r300, r300->hw.tex.offset.cmd);
 
        if (numtmus) {
@@ -308,7 +293,7 @@ static void emit_tex_offsets(GLcontext *ctx, struct radeon_state_atom * atom)
 static void emit_cb_offset(GLcontext *ctx, struct radeon_state_atom * atom)
 {
        r300ContextPtr r300 = R300_CONTEXT(ctx);
-       BATCH_LOCALS(r300);
+       BATCH_LOCALS(&r300->radeon);
        struct radeon_renderbuffer *rrb;
        uint32_t cbpitch;
        GLframebuffer *fb = r300->radeon.dri.drawable->driverPrivate;
index 0c76c6c..d8a1076 100644 (file)
@@ -39,90 +39,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "r300_context.h"
 #include "radeon_cs.h"
 
+#include "common_cmdbuf.h"
 
 extern void r300EmitState(r300ContextPtr r300);
 
 extern void r300InitCmdBuf(r300ContextPtr r300);
 extern void r300DestroyCmdBuf(r300ContextPtr r300);
 
-void r300BeginBatch(r300ContextPtr r300,
-                   int n,
-                   int dostate,
-                    const char *file,
-                    const char *function,
-                    int line);
-
-/**
- * Every function writing to the command buffer needs to declare this
- * to get the necessary local variables.
- */
-#define BATCH_LOCALS(r300) \
-       const r300ContextPtr b_l_r300 = r300
-
-/**
- * Prepare writing n dwords to the command buffer,
- * including producing any necessary state emits on buffer wraparound.
- */
-#define BEGIN_BATCH(n) r300BeginBatch(b_l_r300, n, 1, __FILE__, __FUNCTION__, __LINE__)
-
-/**
- * Same as BEGIN_BATCH, but do not cause automatic state emits.
- */
-#define BEGIN_BATCH_NO_AUTOSTATE(n) r300BeginBatch(b_l_r300, n, 0, __FILE__, __FUNCTION__, __LINE__)
-
-/**
- * Write one dword to the command buffer.
- */
-#define OUT_BATCH(data) \
-       do { \
-        radeon_cs_write_dword(b_l_r300->radeon.cmdbuf.cs, data);\
-       } while(0)
-
-/**
- * Write a relocated dword to the command buffer.
- */
-#define OUT_BATCH_RELOC(data, bo, offset, rd, wd, flags) \
-       do { \
-        if (offset) {\
-            fprintf(stderr, "(%s:%s:%d) offset : %d\n",\
-            __FILE__, __FUNCTION__, __LINE__, offset);\
-        }\
-        radeon_cs_write_dword(b_l_r300->radeon.cmdbuf.cs, offset);\
-        radeon_cs_write_reloc(b_l_r300->radeon.cmdbuf.cs, \
-                              bo, \
-                              rd, \
-                              wd, \
-                              flags);\
-       } while(0)
-
-/**
- * Write n dwords from ptr to the command buffer.
- */
-#define OUT_BATCH_TABLE(ptr,n) \
-       do { \
-               int _i; \
-        for (_i=0; _i < n; _i++) {\
-            radeon_cs_write_dword(b_l_r300->radeon.cmdbuf.cs, ptr[_i]);\
-        }\
-       } while(0)
-
-/**
- * Finish writing dwords to the command buffer.
- * The number of (direct or indirect) OUT_BATCH calls between the previous
- * BEGIN_BATCH and END_BATCH must match the number specified at BEGIN_BATCH time.
- */
-#define END_BATCH() \
-       do { \
-        radeon_cs_end(b_l_r300->radeon.cmdbuf.cs, __FILE__, __FUNCTION__, __LINE__);\
-       } while(0)
-
-/**
- * After the last END_BATCH() of rendering, this indicates that flushing
- * the command buffer now is okay.
- */
-#define COMMIT_BATCH() \
-       do { \
-       } while(0)
 
 void emit_vpu(GLcontext *ctx, struct radeon_state_atom * atom);
 int check_vpu(GLcontext *ctx, struct radeon_state_atom *atom);
index f8fb830..3647022 100644 (file)
@@ -210,6 +210,11 @@ static void r300_vtbl_set_all_dirty(GLcontext *ctx)
        rmesa->hw.all_dirty = GL_TRUE;
 }
 
+static void r300_vtbl_emit_state(radeonContextPtr rmesa)
+{
+       r300EmitState((r300ContextPtr)rmesa);
+}
+
 extern int cs_write_dword(struct radeon_cs *cs, uint32_t dword);
 
 static void r300_vtbl_emit_cs_header(struct radeon_cs *cs, radeonContextPtr rmesa)
@@ -249,6 +254,7 @@ static void r300_init_vtbl(radeonContextPtr radeon)
    radeon->vtbl.set_all_dirty = r300_vtbl_set_all_dirty;
    radeon->vtbl.update_draw_buffer = r300UpdateDrawBuffer;
    radeon->vtbl.emit_cs_header = r300_vtbl_emit_cs_header;
+   radeon->vtbl.emit_state = r300_vtbl_emit_state;
 }
 
 
diff --git a/src/mesa/drivers/dri/radeon/common_cmdbuf.h b/src/mesa/drivers/dri/radeon/common_cmdbuf.h
new file mode 100644 (file)
index 0000000..018049b
--- /dev/null
@@ -0,0 +1,93 @@
+#ifndef COMMON_CMDBUF_H
+#define COMMON_CMDBUF_H
+
+void rcommonEnsureCmdBufSpace(radeonContextPtr rmesa, int dwords, const char *caller);
+int rcommonFlushCmdBuf(radeonContextPtr rmesa, const char *caller);
+int rcommonFlushCmdBufLocked(radeonContextPtr rmesa, const char *caller);
+void rcommonInitCmdBuf(radeonContextPtr rmesa, int max_state_size);
+void rcommonDestroyCmdBuf(radeonContextPtr rmesa);
+
+void rcommonBeginBatch(radeonContextPtr rmesa,
+                      int n,
+                      int dostate,
+                      const char *file,
+                      const char *function,
+                      int line);
+
+
+/**
+ * Every function writing to the command buffer needs to declare this
+ * to get the necessary local variables.
+ */
+#define BATCH_LOCALS(rmesa) \
+       const radeonContextPtr b_l_rmesa = rmesa
+
+/**
+ * Prepare writing n dwords to the command buffer,
+ * including producing any necessary state emits on buffer wraparound.
+ */
+#define BEGIN_BATCH(n) rcommonBeginBatch(b_l_rmesa, n, 1, __FILE__, __FUNCTION__, __LINE__)
+
+/**
+ * Same as BEGIN_BATCH, but do not cause automatic state emits.
+ */
+#define BEGIN_BATCH_NO_AUTOSTATE(n) rcommonBeginBatch(b_l_r300, n, 0, __FILE__, __FUNCTION__, __LINE__)
+
+/**
+ * Write one dword to the command buffer.
+ */
+#define OUT_BATCH(data) \
+       do { \
+        radeon_cs_write_dword(b_l_rmesa->cmdbuf.cs, data);\
+       } while(0)
+
+/**
+ * Write a relocated dword to the command buffer.
+ */
+#define OUT_BATCH_RELOC(data, bo, offset, rd, wd, flags) \
+       do { \
+        if (offset) {\
+            fprintf(stderr, "(%s:%s:%d) offset : %d\n",\
+            __FILE__, __FUNCTION__, __LINE__, offset);\
+        }\
+        radeon_cs_write_dword(b_l_rmesa->cmdbuf.cs, offset);\
+        radeon_cs_write_reloc(b_l_rmesa->cmdbuf.cs, \
+                              bo, \
+                              rd, \
+                              wd, \
+                              flags);\
+       } while(0)
+
+
+/**
+ * Write n dwords from ptr to the command buffer.
+ */
+#define OUT_BATCH_TABLE(ptr,n) \
+       do { \
+               int _i; \
+        for (_i=0; _i < n; _i++) {\
+            radeon_cs_write_dword(b_l_rmesa->cmdbuf.cs, ptr[_i]);\
+        }\
+       } while(0)
+
+/**
+ * Finish writing dwords to the command buffer.
+ * The number of (direct or indirect) OUT_BATCH calls between the previous
+ * BEGIN_BATCH and END_BATCH must match the number specified at BEGIN_BATCH time.
+ */
+#define END_BATCH() \
+       do { \
+        radeon_cs_end(b_l_rmesa->cmdbuf.cs, __FILE__, __FUNCTION__, __LINE__);\
+       } while(0)
+
+/**
+ * After the last END_BATCH() of rendering, this indicates that flushing
+ * the command buffer now is okay.
+ */
+#define COMMIT_BATCH() \
+       do { \
+       } while(0)
+
+
+
+#endif
index a3d9fd7..2748c51 100644 (file)
@@ -337,6 +337,7 @@ struct radeon_context {
       void (*set_all_dirty)(GLcontext *ctx);
       void (*update_draw_buffer)(GLcontext *ctx);
       void (*emit_cs_header)(struct radeon_cs *cs, radeonContextPtr rmesa);
+      void (*emit_state)(radeonContextPtr rmesa);
    } vtbl;
 };
 
index 7078757..a234352 100644 (file)
@@ -64,6 +64,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "common_context.h"
 #include "common_misc.h"
 #include "common_lock.h"
+#include "common_cmdbuf.h"
 
 #ifndef RADEON_DEBUG
 int RADEON_DEBUG = (0);
@@ -687,3 +688,18 @@ void rcommonDestroyCmdBuf(radeonContextPtr rmesa)
                radeon_cs_manager_legacy_dtor(rmesa->cmdbuf.csm);
        }
 }
+
+void rcommonBeginBatch(radeonContextPtr rmesa, int n,
+                      int dostate,
+                      const char *file,
+                      const char *function,
+                      int line)
+{
+       rcommonEnsureCmdBufSpace(rmesa, n, function);
+       if (!rmesa->cmdbuf.cs->cdw && dostate) {
+               if (RADEON_DEBUG & DEBUG_IOCTL)
+                 fprintf(stderr, "Reemit state after flush (from %s)\n", function);
+               rmesa->vtbl.emit_state(rmesa);
+       }
+       radeon_cs_begin(rmesa->cmdbuf.cs, n, file, function, line);
+}
index 7057ad9..d7161c4 100644 (file)
@@ -18,9 +18,4 @@ void radeonCopySubBuffer(__DRIdrawablePrivate * dPriv,
 
 void radeonUpdatePageFlipping(radeonContextPtr rmesa);
 
-void rcommonEnsureCmdBufSpace(radeonContextPtr rmesa, int dwords, const char *caller);
-int rcommonFlushCmdBuf(radeonContextPtr rmesa, const char *caller);
-int rcommonFlushCmdBufLocked(radeonContextPtr rmesa, const char *caller);
-void rcommonInitCmdBuf(radeonContextPtr rmesa, int max_state_size);
-void rcommonDestroyCmdBuf(radeonContextPtr rmesa);
 #endif