*
*/
+#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"
/*
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;
+}
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
va_end(vargs);
}
+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,
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,
#include "compiler/glsl/program.h"
#include "compiler/glsl/gl_nir.h"
#include "compiler/glsl/glsl_to_nir.h"
-#include "glsl/float64_glsl.h"
#include "brw_program.h"
#include "brw_context.h"
static struct gl_program *brwNewProgram(struct gl_context *ctx, GLenum target,
GLuint id, bool is_arb_asm);
-static nir_shader *
-compile_fp64_funcs(struct gl_context *ctx,
- const nir_shader_compiler_options *options,
- void *mem_ctx,
- gl_shader_stage stage)
-{
- const GLuint name = ~0;
- struct gl_shader *sh;
-
- sh = _mesa_new_shader(name, stage);
-
- 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);
- }
- }
-
- struct gl_shader_program *sh_prog;
- sh_prog = _mesa_new_shader_program(name);
- sh_prog->Label = NULL;
- sh_prog->NumShaders = 1;
- sh_prog->Shaders = malloc(sizeof(struct gl_shader *));
- sh_prog->Shaders[0] = sh;
-
- struct gl_linked_shader *linked = rzalloc(NULL, struct gl_linked_shader);
- linked->Stage = stage;
- linked->Program =
- brwNewProgram(ctx,
- _mesa_shader_stage_to_program(stage),
- name, false);
-
- linked->ir = sh->ir;
- sh_prog->_LinkedShaders[stage] = linked;
-
- nir_shader *nir = glsl_to_nir(sh_prog, stage, options);
-
- return nir_shader_clone(mem_ctx, nir);
-}
-
nir_shader *
brw_create_nir(struct brw_context *brw,
const struct gl_shader_program *shader_prog,
if ((options->lower_doubles_options & nir_lower_fp64_full_software) &&
nir->info.uses_64bit) {
- nir_shader *fp64 = compile_fp64_funcs(ctx, options, ralloc_parent(nir), stage);
-
- nir_validate_shader(fp64, "fp64");
+ nir_shader *fp64 = glsl_float64_funcs_to_nir(ctx, options);
+ ralloc_steal(ralloc_parent(nir), fp64);
exec_list_append(&nir->functions, &fp64->functions);
}
libi965 = static_library(
'i965',
[files_i965, i965_oa_sources, ir_expression_operation_h,
- xmlpool_options_h, float64_glsl_h],
+ xmlpool_options_h],
include_directories : [
inc_common, inc_intel, inc_dri_common, inc_util, inc_include,
],
#include "compiler/glsl/ir.h"
#include "compiler/glsl/ir_optimization.h"
#include "compiler/glsl/string_to_uint_map.h"
-#include "compiler/glsl/float64_glsl.h"
static int
type_size(const struct glsl_type *type)
} while (progress);
}
-static nir_shader *
-compile_fp64_funcs(struct gl_context *ctx,
- const nir_shader_compiler_options *options,
- void *mem_ctx,
- gl_shader_stage stage)
-{
- const GLuint name = ~0;
- struct gl_shader *sh;
-
- sh = _mesa_new_shader(name, stage);
-
- sh->Source = float64_source;
- sh->CompileStatus = COMPILE_FAILURE;
- _mesa_compile_shader(ctx, sh);
-
- if (!sh->CompileStatus) {
- if (sh->InfoLog) {
- _mesa_problem(ctx,
- "fp64 software impl compile failed:\n%s\nsource:\n%s\n",
- sh->InfoLog, float64_source);
- }
- }
-
- struct gl_shader_program *sh_prog;
- sh_prog = _mesa_new_shader_program(name);
- sh_prog->Label = NULL;
- sh_prog->NumShaders = 1;
- sh_prog->Shaders = (struct gl_shader **)malloc(sizeof(struct gl_shader *));
- sh_prog->Shaders[0] = sh;
-
- struct gl_linked_shader *linked = rzalloc(NULL, struct gl_linked_shader);
- linked->Stage = stage;
- linked->Program =
- ctx->Driver.NewProgram(ctx, _mesa_shader_stage_to_program(stage),
- name, false);
-
- linked->ir = sh->ir;
- sh_prog->_LinkedShaders[stage] = linked;
-
- nir_shader *nir = glsl_to_nir(sh_prog, stage, options);
-
- return nir_shader_clone(mem_ctx, nir);
-}
-
/* First third of converting glsl_to_nir.. this leaves things in a pre-
* nir_lower_io state, so that shader variants can more easily insert/
* replace variables, etc.
nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
if (nir->info.uses_64bit &&
(options->lower_doubles_options & nir_lower_fp64_full_software) != 0) {
- nir_shader *fp64 =
- compile_fp64_funcs(st->ctx, options, ralloc_parent(nir),
- nir->info.stage);
- nir_validate_shader(fp64, "fp64");
+ nir_shader *fp64 = glsl_float64_funcs_to_nir(st->ctx, options);
+ ralloc_steal(ralloc_parent(nir), fp64);
exec_list_append(&nir->functions, &fp64->functions);
}