radeon-gallium: Don't permit reading and writing a BO in one CS.
[mesa.git] / src / gallium / drivers / r300 / r300_cs.h
index 42ec9fb094c8a6d948d58cc4d934f69f24d0a3e3..2abf04d27ebf230e8b593a6b5ada5e3c4721e016 100644 (file)
 #ifndef R300_CS_H
 #define R300_CS_H
 
+#include "util/u_math.h"
+
 #include "r300_reg.h"
 #include "r300_winsys.h"
 
-/* Pack a 32-bit float into a dword. */
-static uint32_t pack_float_32(float f)
-{
-    union {
-        float f;
-        uint32_t u;
-    } u;
-
-    u.f = f;
-    return u.u;
-}
-
 /* Yes, I know macros are ugly. However, they are much prettier than the code
  * that they neatly hide away, and don't have the cost of function setup,so
  * we're going to use them. */
 
 #define MAX_CS_SIZE 64 * 1024 / 4
 
+#define VERY_VERBOSE_REGISTERS 0
+
 /* XXX stolen from radeon_drm.h */
 #define RADEON_GEM_DOMAIN_CPU  0x1
 #define RADEON_GEM_DOMAIN_GTT  0x2
@@ -55,37 +47,37 @@ static uint32_t pack_float_32(float f)
 #define CP_PACKET0(register, count) \
     (RADEON_CP_PACKET0 | ((count) << 16) | ((register) >> 2))
 
-#define CP_PACKET3(op, count) \
-    (RADEON_CP_PACKET3 | (op) | ((count) << 16))
-
 #define CS_LOCALS(context) \
     struct r300_winsys* cs_winsys = context->winsys; \
-    struct radeon_cs* cs = cs_winsys->cs; \
     int cs_count = 0;
 
 #define CHECK_CS(size) \
-    cs_winsys->check_cs(cs, (size))
+    cs_winsys->check_cs(cs_winsys, (size))
 
 #define BEGIN_CS(size) do { \
     CHECK_CS(size); \
-    debug_printf("r300: BEGIN_CS in %s (%s:%d)\n", __FUNCTION__, __FILE__, \
-        __LINE__); \
-    cs_winsys->begin_cs(cs, (size), __FILE__, __FUNCTION__, __LINE__); \
-    int cs_count = size; \
+    debug_printf("r300: BEGIN_CS, count %d, in %s (%s:%d)\n", \
+        size, __FUNCTION__, __FILE__, __LINE__); \
+    cs_winsys->begin_cs(cs_winsys, (size), \
+            __FILE__, __FUNCTION__, __LINE__); \
+    cs_count = size; \
 } while (0)
 
 #define OUT_CS(value) do { \
-    cs_winsys->write_cs_dword(cs, (value)); \
+    cs_winsys->write_cs_dword(cs_winsys, (value)); \
     cs_count--; \
 } while (0)
 
 #define OUT_CS_32F(value) do { \
-    cs_winsys->write_cs_dword(cs, pack_float_32(value)); \
+    cs_winsys->write_cs_dword(cs_winsys, fui(value)); \
     cs_count--; \
 } while (0)
 
 #define OUT_CS_REG(register, value) do { \
-    debug_printf("r300: writing 0x%x to register 0x%x\n", value, register); \
+    if (VERY_VERBOSE_REGISTERS) \
+        debug_printf("r300: writing 0x%08X to register 0x%04X\n", \
+            value, register); \
+    assert(register); \
     OUT_CS(CP_PACKET0(register, 0)); \
     OUT_CS(value); \
 } while (0)
@@ -93,15 +85,21 @@ static uint32_t pack_float_32(float f)
 /* Note: This expects count to be the number of registers,
  * not the actual packet0 count! */
 #define OUT_CS_REG_SEQ(register, count) do { \
-    debug_printf("r300: writing register sequence 0x%x\n", register); \
+    if (VERY_VERBOSE_REGISTERS) \
+        debug_printf("r300: writing register sequence of %d to 0x%04X\n", \
+            count, register); \
+    assert(register); \
     OUT_CS(CP_PACKET0(register, ((count) - 1))); \
 } while (0)
 
 #define OUT_CS_RELOC(bo, offset, rd, wd, flags) do { \
-    debug_printf("r300: writing relocation for buffer %p, offset %d\n", \
-        bo, offset); \
+    debug_printf("r300: writing relocation for buffer %p, offset %d, " \
+            "domains (%d, %d, %d)\n", \
+        bo, offset, rd, wd, flags); \
+    assert(bo); \
     OUT_CS(offset); \
-    cs_winsys->write_cs_reloc(cs, bo, rd, wd, flags); \
+    cs_winsys->write_cs_reloc(cs_winsys, bo, rd, wd, flags); \
+    cs_count -= 2; \
 } while (0)
 
 #define END_CS do { \
@@ -109,15 +107,40 @@ static uint32_t pack_float_32(float f)
         __LINE__); \
     if (cs_count != 0) \
         debug_printf("r300: Warning: cs_count off by %d\n", cs_count); \
-    cs_winsys->end_cs(cs, __FILE__, __FUNCTION__, __LINE__); \
+    cs_winsys->end_cs(cs_winsys, __FILE__, __FUNCTION__, __LINE__); \
 } while (0)
 
 #define FLUSH_CS do { \
-    debug_printf("r300: FLUSH_CS in %s (%s:%d)\n", __FUNCTION__, __FILE__, \
+    debug_printf("r300: FLUSH_CS in %s (%s:%d)\n\n", __FUNCTION__, __FILE__, \
         __LINE__); \
-    cs_winsys->flush_cs(cs); \
+    cs_winsys->flush_cs(cs_winsys); \
+} while (0)
+
+#define RADEON_ONE_REG_WR        (1 << 15)
+
+#define OUT_CS_ONE_REG(register, count) do { \
+    if (VERY_VERBOSE_REGISTERS) \
+        debug_printf("r300: writing data sequence of %d to 0x%04X\n", \
+            count, register); \
+    assert(register); \
+    OUT_CS(CP_PACKET0(register, ((count) - 1)) | RADEON_ONE_REG_WR); \
 } while (0)
 
-#include "r300_cs_inlines.h"
+#define CP_PACKET3(op, count) \
+    (RADEON_CP_PACKET3 | (op) | ((count) << 16))
+
+#define OUT_CS_PKT3(op, count) do { \
+    OUT_CS(CP_PACKET3(op, count)); \
+} while (0)
+
+#define OUT_CS_INDEX_RELOC(bo, offset, count, rd, wd, flags) do { \
+    debug_printf("r300: writing relocation for index buffer %p," \
+            "offset %d\n", bo, offset); \
+    assert(bo); \
+    OUT_CS(offset); \
+    OUT_CS(count); \
+    cs_winsys->write_cs_reloc(cs_winsys, bo, rd, wd, flags); \
+    cs_count -= 2; \
+} while (0)
 
 #endif /* R300_CS_H */