i965: Move non-FS-specific shader support to brw_shader.cpp.
authorEric Anholt <eric@anholt.net>
Thu, 26 May 2011 16:57:36 +0000 (09:57 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 27 May 2011 15:51:05 +0000 (08:51 -0700)
These only existed in brw_fs.cpp because it was the only .cpp file in
the area when I wrote them.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/Makefile
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_shader.cpp [new file with mode: 0644]

index b96f42bfe883c9335c3e02e3758721ce2a6cf01e..32e961659945a4f8cb9b73409e9a307ef1850f71 100644 (file)
@@ -119,7 +119,8 @@ CXX_SOURCES = \
        brw_fs_channel_expressions.cpp \
        brw_fs_reg_allocate.cpp \
        brw_fs_schedule_instructions.cpp \
-       brw_fs_vector_splitting.cpp
+       brw_fs_vector_splitting.cpp \
+       brw_shader.cpp
 
 ASM_SOURCES = 
 
index af70d922bac7ec8c00ea601e92b7147853db27b3..89803cd9f248ce9806e9f85755f74b488f2d3bd7 100644 (file)
@@ -34,7 +34,6 @@ extern "C" {
 #include "main/uniforms.h"
 #include "program/prog_parameter.h"
 #include "program/prog_print.h"
-#include "program/prog_optimize.h"
 #include "program/register_allocate.h"
 #include "program/sampler.h"
 #include "program/hash_table.h"
@@ -44,109 +43,11 @@ extern "C" {
 }
 #include "brw_fs.h"
 #include "../glsl/glsl_types.h"
-#include "../glsl/ir_optimization.h"
 #include "../glsl/ir_print_visitor.h"
 
 #define MAX_INSTRUCTION (1 << 30)
 static struct brw_reg brw_reg_from_fs_reg(class fs_reg *reg);
 
-struct gl_shader *
-brw_new_shader(struct gl_context *ctx, GLuint name, GLuint type)
-{
-   struct brw_shader *shader;
-
-   shader = rzalloc(NULL, struct brw_shader);
-   if (shader) {
-      shader->base.Type = type;
-      shader->base.Name = name;
-      _mesa_init_shader(ctx, &shader->base);
-   }
-
-   return &shader->base;
-}
-
-struct gl_shader_program *
-brw_new_shader_program(struct gl_context *ctx, GLuint name)
-{
-   struct brw_shader_program *prog;
-   prog = rzalloc(NULL, struct brw_shader_program);
-   if (prog) {
-      prog->base.Name = name;
-      _mesa_init_shader_program(ctx, &prog->base);
-   }
-   return &prog->base;
-}
-
-GLboolean
-brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
-{
-   struct brw_context *brw = brw_context(ctx);
-   struct intel_context *intel = &brw->intel;
-
-   struct brw_shader *shader =
-      (struct brw_shader *)prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
-   if (shader != NULL) {
-      void *mem_ctx = ralloc_context(NULL);
-      bool progress;
-
-      if (shader->ir)
-        ralloc_free(shader->ir);
-      shader->ir = new(shader) exec_list;
-      clone_ir_list(mem_ctx, shader->ir, shader->base.ir);
-
-      do_mat_op_to_vec(shader->ir);
-      lower_instructions(shader->ir,
-                        MOD_TO_FRACT |
-                        DIV_TO_MUL_RCP |
-                        SUB_TO_ADD_NEG |
-                        EXP_TO_EXP2 |
-                        LOG_TO_LOG2);
-
-      /* Pre-gen6 HW can only nest if-statements 16 deep.  Beyond this,
-       * if-statements need to be flattened.
-       */
-      if (intel->gen < 6)
-        lower_if_to_cond_assign(shader->ir, 16);
-
-      do_lower_texture_projection(shader->ir);
-      do_vec_index_to_cond_assign(shader->ir);
-      brw_do_cubemap_normalize(shader->ir);
-      lower_noise(shader->ir);
-      lower_quadop_vector(shader->ir, false);
-      lower_variable_index_to_cond_assign(shader->ir,
-                                         GL_TRUE, /* input */
-                                         GL_TRUE, /* output */
-                                         GL_TRUE, /* temp */
-                                         GL_TRUE /* uniform */
-                                         );
-
-      do {
-        progress = false;
-
-        brw_do_channel_expressions(shader->ir);
-        brw_do_vector_splitting(shader->ir);
-
-        progress = do_lower_jumps(shader->ir, true, true,
-                                  true, /* main return */
-                                  false, /* continue */
-                                  false /* loops */
-                                  ) || progress;
-
-        progress = do_common_optimization(shader->ir, true, 32) || progress;
-      } while (progress);
-
-      validate_ir_tree(shader->ir);
-
-      reparent_ir(shader->ir, shader->ir);
-      ralloc_free(mem_ctx);
-   }
-
-   if (!_mesa_ir_link_shader(ctx, prog))
-      return GL_FALSE;
-
-   return GL_TRUE;
-}
-
 static int
 type_size(const struct glsl_type *type)
 {
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
new file mode 100644 (file)
index 0000000..51dce6b
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+extern "C" {
+#include "main/macros.h"
+#include "brw_context.h"
+}
+#include "brw_fs.h"
+#include "../glsl/ir_optimization.h"
+#include "../glsl/ir_print_visitor.h"
+
+struct gl_shader *
+brw_new_shader(struct gl_context *ctx, GLuint name, GLuint type)
+{
+   struct brw_shader *shader;
+
+   shader = rzalloc(NULL, struct brw_shader);
+   if (shader) {
+      shader->base.Type = type;
+      shader->base.Name = name;
+      _mesa_init_shader(ctx, &shader->base);
+   }
+
+   return &shader->base;
+}
+
+struct gl_shader_program *
+brw_new_shader_program(struct gl_context *ctx, GLuint name)
+{
+   struct brw_shader_program *prog;
+   prog = rzalloc(NULL, struct brw_shader_program);
+   if (prog) {
+      prog->base.Name = name;
+      _mesa_init_shader_program(ctx, &prog->base);
+   }
+   return &prog->base;
+}
+
+GLboolean
+brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
+{
+   struct brw_context *brw = brw_context(ctx);
+   struct intel_context *intel = &brw->intel;
+
+   struct brw_shader *shader =
+      (struct brw_shader *)prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
+   if (shader != NULL) {
+      void *mem_ctx = ralloc_context(NULL);
+      bool progress;
+
+      if (shader->ir)
+        ralloc_free(shader->ir);
+      shader->ir = new(shader) exec_list;
+      clone_ir_list(mem_ctx, shader->ir, shader->base.ir);
+
+      do_mat_op_to_vec(shader->ir);
+      lower_instructions(shader->ir,
+                        MOD_TO_FRACT |
+                        DIV_TO_MUL_RCP |
+                        SUB_TO_ADD_NEG |
+                        EXP_TO_EXP2 |
+                        LOG_TO_LOG2);
+
+      /* Pre-gen6 HW can only nest if-statements 16 deep.  Beyond this,
+       * if-statements need to be flattened.
+       */
+      if (intel->gen < 6)
+        lower_if_to_cond_assign(shader->ir, 16);
+
+      do_lower_texture_projection(shader->ir);
+      do_vec_index_to_cond_assign(shader->ir);
+      brw_do_cubemap_normalize(shader->ir);
+      lower_noise(shader->ir);
+      lower_quadop_vector(shader->ir, false);
+      lower_variable_index_to_cond_assign(shader->ir,
+                                         GL_TRUE, /* input */
+                                         GL_TRUE, /* output */
+                                         GL_TRUE, /* temp */
+                                         GL_TRUE /* uniform */
+                                         );
+
+      do {
+        progress = false;
+
+        brw_do_channel_expressions(shader->ir);
+        brw_do_vector_splitting(shader->ir);
+
+        progress = do_lower_jumps(shader->ir, true, true,
+                                  true, /* main return */
+                                  false, /* continue */
+                                  false /* loops */
+                                  ) || progress;
+
+        progress = do_common_optimization(shader->ir, true, 32) || progress;
+      } while (progress);
+
+      validate_ir_tree(shader->ir);
+
+      reparent_ir(shader->ir, shader->ir);
+      ralloc_free(mem_ctx);
+   }
+
+   if (!_mesa_ir_link_shader(ctx, prog))
+      return GL_FALSE;
+
+   return GL_TRUE;
+}