glsl: move some compiler code out of st
Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22846>
This commit is contained in:

committed by
Marge Bot

parent
ef58936876
commit
a513107424
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
#include "nir.h"
|
||||
#include "nir_builder.h"
|
||||
#include "gl_nir.h"
|
||||
#include "gl_nir_linker.h"
|
||||
#include "linker_util.h"
|
||||
@@ -125,6 +126,39 @@ gl_nir_opts(nir_shader *nir)
|
||||
NIR_PASS_V(nir, nir_lower_var_copies);
|
||||
}
|
||||
|
||||
bool
|
||||
gl_nir_can_add_pointsize_to_program(const struct gl_constants *consts,
|
||||
struct gl_program *prog)
|
||||
{
|
||||
nir_shader *nir = prog->nir;
|
||||
if (!nir)
|
||||
return true; /* fixedfunction */
|
||||
|
||||
assert(nir->info.stage == MESA_SHADER_VERTEX ||
|
||||
nir->info.stage == MESA_SHADER_TESS_EVAL ||
|
||||
nir->info.stage == MESA_SHADER_GEOMETRY);
|
||||
if (nir->info.outputs_written & VARYING_BIT_PSIZ)
|
||||
return false;
|
||||
|
||||
unsigned max_components = nir->info.stage == MESA_SHADER_GEOMETRY ?
|
||||
consts->MaxGeometryTotalOutputComponents :
|
||||
consts->Program[nir->info.stage].MaxOutputComponents;
|
||||
unsigned num_components = 0;
|
||||
unsigned needed_components = nir->info.stage == MESA_SHADER_GEOMETRY ? nir->info.gs.vertices_out : 1;
|
||||
nir_foreach_shader_out_variable(var, nir) {
|
||||
num_components += glsl_count_dword_slots(var->type, false);
|
||||
}
|
||||
|
||||
/* Ensure that there is enough attribute space to emit at least one primitive */
|
||||
if (nir->info.stage == MESA_SHADER_GEOMETRY) {
|
||||
if (num_components + needed_components > consts->Program[nir->info.stage].MaxOutputComponents)
|
||||
return false;
|
||||
num_components *= nir->info.gs.vertices_out;
|
||||
}
|
||||
|
||||
return num_components + needed_components <= max_components;
|
||||
}
|
||||
|
||||
static void
|
||||
gl_nir_link_opts(nir_shader *producer, nir_shader *consumer)
|
||||
{
|
||||
@@ -752,6 +786,44 @@ nir_build_program_resource_list(const struct gl_constants *consts,
|
||||
_mesa_set_destroy(resource_set, NULL);
|
||||
}
|
||||
|
||||
/* - create a gl_PointSize variable
|
||||
* - find every gl_Position write
|
||||
* - store 1.0 to gl_PointSize after every gl_Position write
|
||||
*/
|
||||
void
|
||||
gl_nir_add_point_size(nir_shader *nir)
|
||||
{
|
||||
nir_variable *psiz = nir_create_variable_with_location(nir, nir_var_shader_out,
|
||||
VARYING_SLOT_PSIZ, glsl_float_type());
|
||||
psiz->data.how_declared = nir_var_hidden;
|
||||
|
||||
nir_function_impl *impl = nir_shader_get_entrypoint(nir);
|
||||
nir_builder b = nir_builder_create(impl);
|
||||
bool found = false;
|
||||
nir_foreach_block_safe(block, impl) {
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
if (instr->type == nir_instr_type_intrinsic) {
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
if (intr->intrinsic == nir_intrinsic_store_deref ||
|
||||
intr->intrinsic == nir_intrinsic_copy_deref) {
|
||||
nir_variable *var = nir_intrinsic_get_var(intr, 0);
|
||||
if (var->data.location == VARYING_SLOT_POS) {
|
||||
b.cursor = nir_after_instr(instr);
|
||||
nir_deref_instr *deref = nir_build_deref_var(&b, psiz);
|
||||
nir_store_deref(&b, deref, nir_imm_float(&b, 1.0), BITFIELD_BIT(0));
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
b.cursor = nir_before_cf_list(&impl->body);
|
||||
nir_deref_instr *deref = nir_build_deref_var(&b, psiz);
|
||||
nir_store_deref(&b, deref, nir_imm_float(&b, 1.0), BITFIELD_BIT(0));
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
gl_nir_link_spirv(const struct gl_constants *consts,
|
||||
struct gl_shader_program *prog,
|
||||
|
@@ -38,6 +38,7 @@ struct gl_constants;
|
||||
struct gl_extensions;
|
||||
struct gl_linked_shader;
|
||||
struct gl_shader_program;
|
||||
struct gl_program;
|
||||
struct gl_transform_feedback_info;
|
||||
struct xfb_decl;
|
||||
struct nir_xfb_info;
|
||||
@@ -113,6 +114,13 @@ void gl_nir_link_assign_xfb_resources(const struct gl_constants *consts,
|
||||
|
||||
bool gl_nir_link_uniform_blocks(struct gl_shader_program *prog);
|
||||
|
||||
bool
|
||||
gl_nir_can_add_pointsize_to_program(const struct gl_constants *consts,
|
||||
struct gl_program *prog);
|
||||
|
||||
void
|
||||
gl_nir_add_point_size(struct nir_shader *nir);
|
||||
|
||||
bool lower_packed_varying_needs_lowering(nir_shader *shader, nir_variable *var,
|
||||
bool xfb_enabled,
|
||||
bool disable_xfb_packing,
|
||||
|
Reference in New Issue
Block a user