[Mesa-dev] [PATCH 2/2] i965: Consolidate push constant buffer setup
Ben Widawsky
benjamin.widawsky at intel.com
Thu Jul 30 14:31:21 PDT 2015
This patch replaces the previous patch listed in references.
References: http://patchwork.freedesktop.org/patch/54099/
Recommended-by: Kenneth Graunke <kenneth at whitecape.org>
Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
src/mesa/drivers/dri/i965/gen6_constant_state.c | 104 ++++++++++++++----------
1 file changed, 62 insertions(+), 42 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/gen6_constant_state.c b/src/mesa/drivers/dri/i965/gen6_constant_state.c
index 9d59d12..cde39c5 100644
--- a/src/mesa/drivers/dri/i965/gen6_constant_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_constant_state.c
@@ -27,20 +27,71 @@
#include "intel_batchbuffer.h"
#include "glsl/glsl_parser_extras.h"
+static inline void
+emit_3dstate_constant(struct brw_context *brw,
+ uint32_t opcode,
+ uint16_t read_length_0,
+ uint16_t read_length_1,
+ uint16_t read_length_2,
+ uint16_t read_length_3,
+ uint32_t ptr_0,
+ uint64_t ptr_1,
+ uint64_t ptr_2,
+ uint64_t ptr_3)
+{
+#define OUT_RELOC_NULL(x) if (x != 0) { \
+ OUT_RELOC(brw->batch.bo, I915_GEM_DOMAIN_RENDER, 0, x); } else { OUT_BATCH(x); }
+#define OUT_RELOC64_NULL(x) if (x != 0) { \
+ OUT_RELOC64(brw->batch.bo, I915_GEM_DOMAIN_RENDER, 0, x); \
+} else { OUT_BATCH(x); OUT_BATCH(x); }
+
+ if (brw->gen >= 8) {
+ BEGIN_BATCH(11);
+ OUT_BATCH(opcode << 16 | (11 - 2));
+ OUT_BATCH(read_length_0| read_length_1 << 16);
+ OUT_BATCH(read_length_2| read_length_3 << 16);
+
+ OUT_BATCH(ptr_0);
+ OUT_BATCH(0);
+ /* XXX: When using buffers other than 0, you need to specify the
+ * graphics virtual address regardless of INSTPM/debug bits
+ */
+ OUT_RELOC64_NULL(ptr_1);
+ OUT_RELOC64_NULL(ptr_2);
+ OUT_RELOC64_NULL(ptr_3);
+
+ ADVANCE_BATCH();
+ } else if (brw->gen >= 6) {
+ BEGIN_BATCH(7);
+ OUT_BATCH(opcode << 16 | (7 - 2));
+ OUT_BATCH(read_length_0 | read_length_1 << 16);
+ OUT_BATCH(read_length_2 | read_length_3 << 16);
+ OUT_BATCH(ptr_0 | GEN7_MOCS_L3);
+ OUT_RELOC_NULL(ptr_1);
+ OUT_RELOC_NULL(ptr_2);
+ OUT_RELOC_NULL(ptr_3);
+ ADVANCE_BATCH();
+ } else {
+ unreachable("unhandled gen in emit_3dstate_constant");
+ }
+
+
+#undef OUT_RELOC64_NULL
+#undef OUT_RELOC_NULL
+}
+
void
gen7_upload_constant_state(struct brw_context *brw,
const struct brw_stage_state *stage_state,
bool active, unsigned opcode)
{
- uint32_t mocs = brw->gen < 8 ? GEN7_MOCS_L3 : 0;
/* Disable if the shader stage is inactive or there are no push constants. */
active = active && stage_state->push_const_size != 0;
- int dwords = brw->gen >= 8 ? 11 : 7;
- BEGIN_BATCH(dwords);
- OUT_BATCH(opcode << 16 | (dwords - 2));
-
+ if (!active) {
+ emit_3dstate_constant(brw, opcode, 0, 0, 0, 0, 0, 0, 0, 0);
+ } else if (brw->gen >= 9) {
/* Workaround for SKL+ (we use option #2 until we have a need for more
* constant buffers). This comes from the documentation for 3DSTATE_CONSTANT_*
*
@@ -52,45 +103,14 @@ gen7_upload_constant_state(struct brw_context *brw,
* 1. always force buffer 3 to have a non zero read length
* 2. always force buffer 0 to a zero read length
*/
- if (brw->gen >= 9 && active) {
- OUT_BATCH(0);
- OUT_BATCH(stage_state->push_const_size);
+ emit_3dstate_constant(brw, opcode,
+ 0, 0, stage_state->push_const_size, 0,
+ 0, 0, stage_state->push_const_offset, 0);
} else {
- OUT_BATCH(active ? stage_state->push_const_size : 0);
- OUT_BATCH(0);
+ emit_3dstate_constant(brw, opcode,
+ stage_state->push_const_size, 0, 0, 0,
+ 0, 0, stage_state->push_const_offset, 0);
}
- /* Pointer to the constant buffer. Covered by the set of state flags
- * from gen6_prepare_wm_contants
- */
- if (brw->gen >= 9 && active) {
- OUT_BATCH(0);
- OUT_BATCH(0);
- OUT_BATCH(0);
- OUT_BATCH(0);
- /* XXX: When using buffers other than 0, you need to specify the
- * graphics virtual address regardless of INSPM/debug bits
- */
- OUT_RELOC64(brw->batch.bo, I915_GEM_DOMAIN_RENDER, 0,
- stage_state->push_const_offset);
- OUT_BATCH(0);
- OUT_BATCH(0);
- } else if (brw->gen>= 8) {
- OUT_BATCH(active ? (stage_state->push_const_offset | mocs) : 0);
- OUT_BATCH(0);
- OUT_BATCH(0);
- OUT_BATCH(0);
- OUT_BATCH(0);
- OUT_BATCH(0);
- OUT_BATCH(0);
- OUT_BATCH(0);
- } else {
- OUT_BATCH(active ? (stage_state->push_const_offset | mocs) : 0);
- OUT_BATCH(0);
- OUT_BATCH(0);
- OUT_BATCH(0);
- }
-
- ADVANCE_BATCH();
/* On SKL+ the new constants don't take effect until the next corresponding
* 3DSTATE_BINDING_TABLE_POINTER_* command is parsed so we need to ensure
--
2.5.0
More information about the mesa-dev
mailing list