summaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2019-03-03 10:00:14 -0600
committerJason Ekstrand <[email protected]>2019-03-06 17:24:57 +0000
commit82d9a37a59c94ba3678b33acb9f2749cbbd7bfcc (patch)
treedea010697e00ab3e9db880e325ea6f5a3ed9a5a8 /src/compiler
parent8993e0973f7d0cfb211e0c39de82ef2497584df3 (diff)
glsl/nir: Add a shared helper for building float64 shaders
Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/glsl/glsl_to_nir.cpp41
-rw-r--r--src/compiler/glsl/glsl_to_nir.h3
-rw-r--r--src/compiler/glsl/standalone_scaffolding.cpp18
-rw-r--r--src/compiler/glsl/standalone_scaffolding.h3
4 files changed, 65 insertions, 0 deletions
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index f7df91d887d..950885a1e00 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -25,14 +25,18 @@
*
*/
+#include "float64_glsl.h"
#include "glsl_to_nir.h"
#include "ir_visitor.h"
#include "ir_hierarchical_visitor.h"
#include "ir.h"
+#include "program.h"
#include "compiler/nir/nir_control_flow.h"
#include "compiler/nir/nir_builder.h"
+#include "main/errors.h"
#include "main/imports.h"
#include "main/mtypes.h"
+#include "main/shaderobj.h"
#include "util/u_math.h"
/*
@@ -2324,3 +2328,40 @@ nir_visitor::visit(ir_barrier *)
nir_intrinsic_instr_create(this->shader, nir_intrinsic_barrier);
nir_builder_instr_insert(&b, &instr->instr);
}
+
+nir_shader *
+glsl_float64_funcs_to_nir(struct gl_context *ctx,
+ const nir_shader_compiler_options *options)
+{
+ /* We pretend it's a vertex shader. Ultimately, the stage shouldn't
+ * matter because we're not optimizing anything here.
+ */
+ struct gl_shader *sh = _mesa_new_shader(-1, MESA_SHADER_VERTEX);
+ sh->Source = float64_source;
+ sh->CompileStatus = COMPILE_FAILURE;
+ _mesa_glsl_compile_shader(ctx, sh, false, false, true);
+
+ if (!sh->CompileStatus) {
+ if (sh->InfoLog) {
+ _mesa_problem(ctx,
+ "fp64 software impl compile failed:\n%s\nsource:\n%s\n",
+ sh->InfoLog, float64_source);
+ }
+ return NULL;
+ }
+
+ nir_shader *nir = nir_shader_create(NULL, MESA_SHADER_VERTEX, options, NULL);
+
+ nir_visitor v1(nir);
+ nir_function_visitor v2(&v1);
+ v2.run(sh->ir);
+ visit_exec_list(sh->ir, &v1);
+
+ /* _mesa_delete_shader will try to free sh->Source but it's static const */
+ sh->Source = NULL;
+ _mesa_delete_shader(ctx, sh);
+
+ nir_validate_shader(nir, "float64_funcs_to_nir");
+
+ return nir;
+}
diff --git a/src/compiler/glsl/glsl_to_nir.h b/src/compiler/glsl/glsl_to_nir.h
index 8e38e0e1c9c..115c8e1270b 100644
--- a/src/compiler/glsl/glsl_to_nir.h
+++ b/src/compiler/glsl/glsl_to_nir.h
@@ -40,6 +40,9 @@ nir_shader *glsl_to_nir(const struct gl_shader_program *shader_prog,
gl_shader_stage stage,
const nir_shader_compiler_options *options);
+nir_shader *glsl_float64_funcs_to_nir(struct gl_context *ctx,
+ const nir_shader_compiler_options *options);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/compiler/glsl/standalone_scaffolding.cpp b/src/compiler/glsl/standalone_scaffolding.cpp
index ec5f28ae40c..b80054a4707 100644
--- a/src/compiler/glsl/standalone_scaffolding.cpp
+++ b/src/compiler/glsl/standalone_scaffolding.cpp
@@ -55,6 +55,24 @@ _mesa_warning(struct gl_context *ctx, const char *fmt, ...)
}
void
+_mesa_problem(struct gl_context *ctx, const char *fmt, ...)
+{
+ va_list vargs;
+ (void) ctx;
+
+ va_start(vargs, fmt);
+
+ /* This output is not thread-safe, but that's good enough for the
+ * standalone compiler.
+ */
+ fprintf(stderr, "Mesa problem: ");
+ vfprintf(stderr, fmt, vargs);
+ fprintf(stderr, "\n");
+
+ va_end(vargs);
+}
+
+void
_mesa_reference_shader_program_data(struct gl_context *ctx,
struct gl_shader_program_data **ptr,
struct gl_shader_program_data *data)
diff --git a/src/compiler/glsl/standalone_scaffolding.h b/src/compiler/glsl/standalone_scaffolding.h
index 7da76f06fef..d7d1a9ea7ff 100644
--- a/src/compiler/glsl/standalone_scaffolding.h
+++ b/src/compiler/glsl/standalone_scaffolding.h
@@ -38,6 +38,9 @@ extern "C" void
_mesa_warning(struct gl_context *ctx, const char *fmtString, ... );
extern "C" void
+_mesa_problem(struct gl_context *ctx, const char *fmtString, ... );
+
+extern "C" void
_mesa_reference_shader_program_data(struct gl_context *ctx,
struct gl_shader_program_data **ptr,
struct gl_shader_program_data *data);