pan/bifrost: Stub out standalone compiler
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 14 Aug 2019 19:21:23 +0000 (12:21 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 14 Aug 2019 22:54:07 +0000 (22:54 +0000)
We don't actually have a standalone compiler in-tree yet, but let's get
prepared for when we do.

Signed-off-by: Ryan Houdek <Sonicadvance1@gmail.com>
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/panfrost/bifrost/cmdline.c

index 9fd7094ebe19a72bb17a2869b8472520372e012d..4a30d7ec9f6fbeecc1899c16ca13eb64989545a2 100644 (file)
  * SOFTWARE.
  */
 
+#include "disassemble.h"
+
 #include "main/mtypes.h"
 #include "compiler/glsl/standalone.h"
 #include "compiler/glsl/glsl_to_nir.h"
+#include "compiler/glsl/gl_nir.h"
 #include "compiler/nir_types.h"
-#include "disassemble.h"
 #include "util/u_dynarray.h"
 
+static void
+compile_shader(char **argv)
+{
+        struct gl_shader_program *prog;
+        nir_shader *nir[2];
+        unsigned shader_types[2] = {
+                MESA_SHADER_VERTEX,
+                MESA_SHADER_FRAGMENT,
+        };
+
+        struct standalone_options options = {
+                .glsl_version = 430,
+                .do_link = true,
+        };
+
+        static struct gl_context local_ctx;
+
+        prog = standalone_compile_shader(&options, 2, argv, &local_ctx);
+        prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program->info.stage = MESA_SHADER_FRAGMENT;
+
+#if 0
+        struct bifrost_program compiled;
+        for (unsigned i = 0; i < 2; ++i) {
+                nir[i] = glsl_to_nir(&local_ctx, prog, shader_types[i], &bifrost_nir_options);
+                NIR_PASS_V(nir[i], nir_lower_global_vars_to_local);
+                NIR_PASS_V(nir[i], nir_split_var_copies);
+                NIR_PASS_V(nir[i], nir_lower_var_copies);
+
+                NIR_PASS_V(nir[i], nir_lower_alu_to_scalar, NULL);
+
+                /* before buffers and vars_to_ssa */
+                NIR_PASS_V(nir[i], gl_nir_lower_bindless_images);
+
+                NIR_PASS_V(nir[i], gl_nir_lower_buffers, prog);
+                NIR_PASS_V(nir[i], nir_opt_constant_folding);
+                bifrost_compile_shader_nir(nir[i], &compiled);
+        }
+#endif
+}
+
 static void
 disassemble(const char *filename)
 {
@@ -56,7 +98,10 @@ main(int argc, char **argv)
                 printf("Pass a command\n");
                 exit(1);
         }
-        if (strcmp(argv[1], "disasm") == 0) {
+        if (strcmp(argv[1], "compile") == 0) {
+                compile_shader(&argv[2]);
+        }
+        else if (strcmp(argv[1], "disasm") == 0) {
                 disassemble(argv[2]);
         }
         return 0;