mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 13:10:10 +01:00
glsl: use pipe_screen::nir_options instead of NirOptions
Perhaps the more interesting thing is that the GLSL compiler can now access pipe_screen for caps Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36094>
This commit is contained in:
parent
eba8f95805
commit
09cc5f0c37
9 changed files with 35 additions and 25 deletions
|
|
@ -35,6 +35,7 @@
|
|||
#include "main/shaderobj.h"
|
||||
#include "util/glheader.h"
|
||||
#include "util/perf/cpu_trace.h"
|
||||
#include "pipe/p_screen.h"
|
||||
|
||||
/**
|
||||
* This file included general link methods, using NIR.
|
||||
|
|
@ -1275,7 +1276,8 @@ lower_patch_vertices_in(struct gl_shader_program *shader_prog)
|
|||
}
|
||||
|
||||
static void
|
||||
preprocess_shader(const struct gl_constants *consts,
|
||||
preprocess_shader(const struct pipe_screen *screen,
|
||||
const struct gl_constants *consts,
|
||||
const struct gl_extensions *exts,
|
||||
struct gl_program *prog,
|
||||
struct gl_shader_program *shader_program,
|
||||
|
|
@ -1283,7 +1285,7 @@ preprocess_shader(const struct gl_constants *consts,
|
|||
{
|
||||
const struct gl_shader_compiler_options *gl_options =
|
||||
&consts->ShaderCompilerOptions[prog->info.stage];
|
||||
const nir_shader_compiler_options *options = gl_options->NirOptions;
|
||||
const nir_shader_compiler_options *options = screen->nir_options[prog->info.stage];
|
||||
assert(options);
|
||||
|
||||
nir_shader *nir = prog->nir;
|
||||
|
|
@ -1358,15 +1360,15 @@ preprocess_shader(const struct gl_constants *consts,
|
|||
}
|
||||
|
||||
static bool
|
||||
prelink_lowering(const struct gl_constants *consts,
|
||||
prelink_lowering(const struct pipe_screen *screen,
|
||||
const struct gl_constants *consts,
|
||||
const struct gl_extensions *exts,
|
||||
struct gl_shader_program *shader_program,
|
||||
struct gl_linked_shader **linked_shader, unsigned num_shaders)
|
||||
{
|
||||
for (unsigned i = 0; i < num_shaders; i++) {
|
||||
struct gl_linked_shader *shader = linked_shader[i];
|
||||
const nir_shader_compiler_options *options =
|
||||
consts->ShaderCompilerOptions[shader->Stage].NirOptions;
|
||||
const nir_shader_compiler_options *options = screen->nir_options[shader->Stage];
|
||||
struct gl_program *prog = shader->Program;
|
||||
|
||||
/* NIR drivers that support tess shaders and compact arrays need to use
|
||||
|
|
@ -1384,7 +1386,7 @@ prelink_lowering(const struct gl_constants *consts,
|
|||
i == MESA_SHADER_VERTEX)
|
||||
remove_dead_varyings_pre_linking(prog->nir);
|
||||
|
||||
preprocess_shader(consts, exts, prog, shader_program, shader->Stage);
|
||||
preprocess_shader(screen, consts, exts, prog, shader_program, shader->Stage);
|
||||
|
||||
if (prog->nir->info.shared_size > consts->MaxComputeSharedMemorySize) {
|
||||
linker_error(shader_program, "Too much shared memory used (%u/%u)\n",
|
||||
|
|
@ -1587,7 +1589,8 @@ gl_nir_lower_optimize_varyings(const struct gl_constants *consts,
|
|||
}
|
||||
|
||||
bool
|
||||
gl_nir_link_spirv(const struct gl_constants *consts,
|
||||
gl_nir_link_spirv(const struct pipe_screen *screen,
|
||||
const struct gl_constants *consts,
|
||||
const struct gl_extensions *exts,
|
||||
struct gl_shader_program *prog,
|
||||
const struct gl_nir_linker_options *options)
|
||||
|
|
@ -1607,7 +1610,7 @@ gl_nir_link_spirv(const struct gl_constants *consts,
|
|||
|
||||
gl_nir_link_assign_xfb_resources(consts, prog);
|
||||
|
||||
if (!prelink_lowering(consts, exts, prog, linked_shader, num_shaders))
|
||||
if (!prelink_lowering(screen, consts, exts, prog, linked_shader, num_shaders))
|
||||
return false;
|
||||
|
||||
gl_nir_lower_optimize_varyings(consts, prog, true);
|
||||
|
|
@ -3228,7 +3231,8 @@ is_sampler_array_accessed_indirectly(nir_deref_instr *deref)
|
|||
* that includes loop induction variable).
|
||||
*/
|
||||
static bool
|
||||
validate_sampler_array_indexing(const struct gl_constants *consts,
|
||||
validate_sampler_array_indexing(const struct pipe_screen *screen,
|
||||
const struct gl_constants *consts,
|
||||
struct gl_shader_program *prog)
|
||||
{
|
||||
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||
|
|
@ -3236,7 +3240,7 @@ validate_sampler_array_indexing(const struct gl_constants *consts,
|
|||
continue;
|
||||
|
||||
bool no_dynamic_indexing =
|
||||
consts->ShaderCompilerOptions[i].NirOptions->force_indirect_unrolling_sampler;
|
||||
screen->nir_options[i]->force_indirect_unrolling_sampler;
|
||||
|
||||
bool uses_indirect_sampler_array_indexing = false;
|
||||
nir_foreach_function_impl(impl, prog->_LinkedShaders[i]->Program->nir) {
|
||||
|
|
@ -3958,7 +3962,8 @@ gl_nir_link_glsl(struct gl_context *ctx, struct gl_shader_program *prog)
|
|||
if (!gl_assign_attribute_or_color_locations(consts, prog))
|
||||
goto done;
|
||||
|
||||
if (!prelink_lowering(consts, exts, prog, linked_shader, num_linked_shaders))
|
||||
if (!prelink_lowering(ctx->screen, consts, exts, prog, linked_shader,
|
||||
num_linked_shaders))
|
||||
goto done;
|
||||
|
||||
if (!gl_nir_link_varyings(consts, exts, api, prog))
|
||||
|
|
@ -3970,7 +3975,7 @@ gl_nir_link_glsl(struct gl_context *ctx, struct gl_shader_program *prog)
|
|||
*/
|
||||
if ((!prog->IsES && prog->GLSL_Version < 130) ||
|
||||
(prog->IsES && prog->GLSL_Version < 300)) {
|
||||
if (!validate_sampler_array_indexing(consts, prog))
|
||||
if (!validate_sampler_array_indexing(ctx->screen, consts, prog))
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ struct gl_program;
|
|||
struct gl_transform_feedback_info;
|
||||
struct xfb_decl;
|
||||
struct nir_xfb_info;
|
||||
struct pipe_screen;
|
||||
|
||||
struct gl_nir_linker_options {
|
||||
bool fill_parameters;
|
||||
|
|
@ -62,7 +63,8 @@ void gl_nir_opts(nir_shader *nir);
|
|||
void gl_nir_detect_recursion_linked(struct gl_shader_program *prog,
|
||||
nir_shader *shader);
|
||||
|
||||
bool gl_nir_link_spirv(const struct gl_constants *consts,
|
||||
bool gl_nir_link_spirv(const struct pipe_screen *screen,
|
||||
const struct gl_constants *consts,
|
||||
const struct gl_extensions *exts,
|
||||
struct gl_shader_program *prog,
|
||||
const struct gl_nir_linker_options *options);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@
|
|||
#include "glsl_to_nir.h"
|
||||
#include "ir_optimization.h"
|
||||
#include "builtin_functions.h"
|
||||
#include "pipe/p_screen.h"
|
||||
|
||||
/**
|
||||
* Format a short human-readable description of the given GLSL version.
|
||||
|
|
@ -2449,7 +2450,8 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
|
|||
if (shader->CompileStatus == COMPILE_SUCCESS) {
|
||||
memcpy(shader->compiled_source_blake3, source_blake3, BLAKE3_OUT_LEN);
|
||||
|
||||
shader->nir = glsl_to_nir(shader, options->NirOptions, source_blake3);
|
||||
shader->nir = glsl_to_nir(shader, ctx->screen->nir_options[shader->Stage],
|
||||
source_blake3);
|
||||
}
|
||||
|
||||
if (ctx->Cache && shader->CompileStatus == COMPILE_SUCCESS) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
#include "main/mtypes.h"
|
||||
#include "program/program.h"
|
||||
#include "nir_shader_compiler_options.h"
|
||||
#include "pipe/p_screen.h"
|
||||
|
||||
static const struct standalone_options *options;
|
||||
|
||||
|
|
@ -55,10 +56,10 @@ initialize_context(struct gl_context *ctx, gl_api api)
|
|||
_mesa_glsl_builtin_functions_init_or_ref();
|
||||
|
||||
ctx->Version = 450;
|
||||
ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].NirOptions =
|
||||
&nir_fs_options;
|
||||
ctx->Const.ShaderCompilerOptions[MESA_SHADER_FRAGMENT].NirOptions =
|
||||
&nir_vs_options;
|
||||
|
||||
ctx->screen->nir_options[MESA_SHADER_VERTEX] = &nir_vs_options;
|
||||
ctx->screen->nir_options[MESA_SHADER_FRAGMENT] = &nir_fs_options;
|
||||
|
||||
|
||||
/* The standalone compiler needs to claim support for almost
|
||||
* everything in order to compile the built-in functions.
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include "util/strtod.h"
|
||||
#include "main/mtypes.h"
|
||||
#include "string_to_uint_map.h"
|
||||
#include "pipe/p_screen.h"
|
||||
|
||||
void
|
||||
_mesa_warning(struct gl_context *ctx, const char *fmt, ...)
|
||||
|
|
@ -201,6 +202,8 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
|
|||
{
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
ctx->screen = (struct pipe_screen*)calloc(1, sizeof(struct pipe_screen));
|
||||
|
||||
ctx->API = api;
|
||||
|
||||
ctx->Extensions.dummy_true = true;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
#include "glsl_to_nir.h"
|
||||
#include "linker_util.h"
|
||||
#include "nir_builder.h"
|
||||
#include "pipe/p_screen.h"
|
||||
|
||||
/* The printed-GLSL-IR tests use fmemopen so we can do stdio to memory (or you'd
|
||||
* need equivalent tempfiles that you manage). Just disable this test on those
|
||||
|
|
@ -174,7 +175,7 @@ namespace
|
|||
for (int i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||
ctx->Const.ShaderCompilerOptions[i].LowerPrecisionFloat16 = true;
|
||||
ctx->Const.ShaderCompilerOptions[i].LowerPrecisionInt16 = true;
|
||||
ctx->Const.ShaderCompilerOptions[i].NirOptions = &compiler_options;
|
||||
ctx->screen->nir_options[i] = &compiler_options;
|
||||
}
|
||||
|
||||
/* GL_ARB_explicit_uniform_location, GL_MAX_UNIFORM_LOCATIONS */
|
||||
|
|
|
|||
|
|
@ -362,8 +362,6 @@ struct gl_shader_compiler_options
|
|||
|
||||
/** (driconf) Force gl_Position to be considered precise */
|
||||
GLboolean PositionAlwaysPrecise;
|
||||
|
||||
const struct nir_shader_compiler_options *NirOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -209,8 +209,6 @@ void st_init_limits(struct pipe_screen *screen,
|
|||
(sh == PIPE_SHADER_COMPUTE && !screen->caps.compute))
|
||||
continue;
|
||||
|
||||
options->NirOptions = screen->nir_options[stage];
|
||||
|
||||
pc->MaxTextureImageUnits =
|
||||
_min(screen->shader_caps[sh].max_texture_samplers,
|
||||
MAX_TEXTURE_IMAGE_UNITS);
|
||||
|
|
|
|||
|
|
@ -449,8 +449,8 @@ st_link_glsl_to_nir(struct gl_context *ctx,
|
|||
static const gl_nir_linker_options opts = {
|
||||
true /*fill_parameters */
|
||||
};
|
||||
if (!gl_nir_link_spirv(&ctx->Const, &ctx->Extensions, shader_program,
|
||||
&opts))
|
||||
if (!gl_nir_link_spirv(ctx->screen, &ctx->Const, &ctx->Extensions,
|
||||
shader_program, &opts))
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue