* 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)
{
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;