#include "program/prog_parameter.h"
#include "program/program.h"
#include "intel_mipmap_tree.h"
-#include "glsl/nir/nir.h"
+#include "brw_nir.h"
+#include "brw_program.h"
#include "util/ralloc.h"
-/**
- * Return a bitfield where bit n is set if barycentric interpolation mode n
- * (see enum brw_wm_barycentric_interp_mode) is needed by the fragment shader.
- */
-static unsigned
-brw_compute_barycentric_interp_modes(struct brw_context *brw,
- bool shade_model_flat,
- bool persample_shading,
- const struct gl_fragment_program *fprog)
-{
- unsigned barycentric_interp_modes = 0;
- int attr;
-
- /* Loop through all fragment shader inputs to figure out what interpolation
- * modes are in use, and set the appropriate bits in
- * barycentric_interp_modes.
- */
- for (attr = 0; attr < VARYING_SLOT_MAX; ++attr) {
- enum glsl_interp_qualifier interp_qualifier =
- fprog->InterpQualifier[attr];
- bool is_centroid = (fprog->IsCentroid & BITFIELD64_BIT(attr)) &&
- !persample_shading;
- bool is_sample = (fprog->IsSample & BITFIELD64_BIT(attr)) ||
- persample_shading;
- bool is_gl_Color = attr == VARYING_SLOT_COL0 || attr == VARYING_SLOT_COL1;
-
- /* Ignore unused inputs. */
- if (!(fprog->Base.InputsRead & BITFIELD64_BIT(attr)))
- continue;
-
- /* Ignore WPOS and FACE, because they don't require interpolation. */
- if (attr == VARYING_SLOT_POS || attr == VARYING_SLOT_FACE)
- continue;
-
- /* Determine the set (or sets) of barycentric coordinates needed to
- * interpolate this variable. Note that when
- * brw->needs_unlit_centroid_workaround is set, centroid interpolation
- * uses PIXEL interpolation for unlit pixels and CENTROID interpolation
- * for lit pixels, so we need both sets of barycentric coordinates.
- */
- if (interp_qualifier == INTERP_QUALIFIER_NOPERSPECTIVE) {
- if (is_centroid) {
- barycentric_interp_modes |=
- 1 << BRW_WM_NONPERSPECTIVE_CENTROID_BARYCENTRIC;
- } else if (is_sample) {
- barycentric_interp_modes |=
- 1 << BRW_WM_NONPERSPECTIVE_SAMPLE_BARYCENTRIC;
- }
- if ((!is_centroid && !is_sample) ||
- brw->needs_unlit_centroid_workaround) {
- barycentric_interp_modes |=
- 1 << BRW_WM_NONPERSPECTIVE_PIXEL_BARYCENTRIC;
- }
- } else if (interp_qualifier == INTERP_QUALIFIER_SMOOTH ||
- (!(shade_model_flat && is_gl_Color) &&
- interp_qualifier == INTERP_QUALIFIER_NONE)) {
- if (is_centroid) {
- barycentric_interp_modes |=
- 1 << BRW_WM_PERSPECTIVE_CENTROID_BARYCENTRIC;
- } else if (is_sample) {
- barycentric_interp_modes |=
- 1 << BRW_WM_PERSPECTIVE_SAMPLE_BARYCENTRIC;
- }
- if ((!is_centroid && !is_sample) ||
- brw->needs_unlit_centroid_workaround) {
- barycentric_interp_modes |=
- 1 << BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC;
- }
- }
- }
-
- return barycentric_interp_modes;
-}
-
-static uint8_t
-computed_depth_mode(struct gl_fragment_program *fp)
-{
- if (fp->Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
- switch (fp->FragDepthLayout) {
- case FRAG_DEPTH_LAYOUT_NONE:
- case FRAG_DEPTH_LAYOUT_ANY:
- return BRW_PSCDEPTH_ON;
- case FRAG_DEPTH_LAYOUT_GREATER:
- return BRW_PSCDEPTH_ON_GE;
- case FRAG_DEPTH_LAYOUT_LESS:
- return BRW_PSCDEPTH_ON_LE;
- case FRAG_DEPTH_LAYOUT_UNCHANGED:
- return BRW_PSCDEPTH_OFF;
- }
- }
- return BRW_PSCDEPTH_OFF;
-}
-
static void
assign_fs_binding_table_offsets(const struct brw_device_info *devinfo,
const struct gl_shader_program *shader_prog,
fs = (struct brw_shader *)prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
memset(&prog_data, 0, sizeof(prog_data));
- /* key->alpha_test_func means simulating alpha testing via discards,
- * so the shader definitely kills pixels.
- */
- prog_data.uses_kill = fp->program.UsesKill || key->alpha_test_func;
- prog_data.uses_omask =
- fp->program.Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK);
- prog_data.computed_depth_mode = computed_depth_mode(&fp->program);
-
- prog_data.early_fragment_tests = fs && fs->base.EarlyFragmentTests;
/* Use ALT floating point mode for ARB programs so that 0^0 == 1. */
if (!prog)
prog_data.base.nr_image_params);
prog_data.base.nr_params = param_count;
- prog_data.barycentric_interp_modes =
- brw_compute_barycentric_interp_modes(brw, key->flat_shade,
- key->persample_shading,
- &fp->program);
+ if (prog) {
+ brw_nir_setup_glsl_uniforms(fp->program.Base.nir, prog, &fp->program.Base,
+ &prog_data.base, true);
+ } else {
+ brw_nir_setup_arb_uniforms(fp->program.Base.nir, &fp->program.Base,
+ &prog_data.base);
+ }
if (unlikely(brw->perf_debug)) {
start_busy = (brw->batch.last_bo &&
start_time = get_time();
}
- program = brw_wm_fs_emit(brw, mem_ctx, key, &prog_data,
- &fp->program, prog, &program_size);
+ if (unlikely(INTEL_DEBUG & DEBUG_WM))
+ brw_dump_ir("fragment", prog, fs ? &fs->base : NULL, &fp->program.Base);
+
+ int st_index8 = -1, st_index16 = -1;
+ if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
+ st_index8 = brw_get_shader_time_index(brw, prog, &fp->program.Base, ST_FS8);
+ st_index16 = brw_get_shader_time_index(brw, prog, &fp->program.Base, ST_FS16);
+ }
+
+ char *error_str = NULL;
+ program = brw_compile_fs(brw->intelScreen->compiler, brw, mem_ctx,
+ key, &prog_data, fp->program.Base.nir,
+ &fp->program.Base, st_index8, st_index16,
+ brw->use_rep_send, &program_size, &error_str);
if (program == NULL) {
+ if (prog) {
+ prog->LinkStatus = false;
+ ralloc_strcat(&prog->InfoLog, error_str);
+ }
+
+ _mesa_problem(NULL, "Failed to compile fragment shader: %s\n", error_str);
+
ralloc_free(mem_ctx);
return false;
}
return true;
}
-static bool
-key_debug(struct brw_context *brw, const char *name, int a, int b)
-{
- if (a != b) {
- perf_debug(" %s %d->%d\n", name, a, b);
- return true;
- } else {
- return false;
- }
-}
-
bool
brw_debug_recompile_sampler_key(struct brw_context *brw,
const struct brw_sampler_prog_key_data *old_key,
found |= key_debug(brw, "compressed multisample layout",
old_key->compressed_multisample_layout_mask,
key->compressed_multisample_layout_mask);
+ found |= key_debug(brw, "16x msaa",
+ old_key->msaa_16,
+ key->msaa_16);
for (unsigned int i = 0; i < MAX_SAMPLERS; i++) {
found |= key_debug(brw, "textureGather workarounds",
old_key->flat_shade, key->flat_shade);
found |= key_debug(brw, "per-sample shading",
old_key->persample_shading, key->persample_shading);
- found |= key_debug(brw, "per-sample shading and 2x MSAA",
- old_key->persample_2x, key->persample_2x);
found |= key_debug(brw, "number of color buffers",
old_key->nr_color_regions, key->nr_color_regions);
found |= key_debug(brw, "MRT alpha test or alpha-to-coverage",
old_key->render_to_fbo, key->render_to_fbo);
found |= key_debug(brw, "fragment color clamping",
old_key->clamp_fragment_color, key->clamp_fragment_color);
+ found |= key_debug(brw, "multisampled FBO",
+ old_key->multisample_fbo, key->multisample_fbo);
found |= key_debug(brw, "line smoothing",
old_key->line_aa, key->line_aa);
found |= key_debug(brw, "renderbuffer height",
if (brw->gen >= 7 &&
intel_tex->mt->msaa_layout == INTEL_MSAA_LAYOUT_CMS) {
key->compressed_multisample_layout_mask |= 1 << s;
+
+ if (intel_tex->mt->num_samples >= 16) {
+ assert(brw->gen >= 9);
+ key->msaa_16 |= 1 << s;
+ }
}
}
}
GLuint lookup = 0;
GLuint line_aa;
bool program_uses_dfdy = fp->program.UsesDFdy;
- const bool multisample_fbo = _mesa_geometric_samples(ctx->DrawBuffer) > 1;
memset(key, 0, sizeof(*key));
/* _NEW_BUFFERS */
key->nr_color_regions = ctx->DrawBuffer->_NumColorDrawBuffers;
+ /* _NEW_COLOR */
+ key->force_dual_color_blend = brw->dual_color_blend_by_location &&
+ (ctx->Color.BlendEnabled & 1) && ctx->Color.Blend[0]._UsesDualSrc;
+
/* _NEW_MULTISAMPLE, _NEW_COLOR, _NEW_BUFFERS */
key->replicate_alpha = ctx->DrawBuffer->_NumColorDrawBuffers > 1 &&
(ctx->Multisample.SampleAlphaToCoverage || ctx->Color.AlphaEnabled);
/* Ignore sample qualifier while computing this flag. */
key->persample_shading =
_mesa_get_min_invocations_per_fragment(ctx, &fp->program, true) > 1;
- if (key->persample_shading)
- key->persample_2x = _mesa_geometric_samples(ctx->DrawBuffer) == 2;
key->compute_pos_offset =
_mesa_get_min_invocations_per_fragment(ctx, &fp->program, false) > 1 &&
fp->program.Base.SystemValuesRead & SYSTEM_BIT_SAMPLE_POS;
- key->compute_sample_id =
- multisample_fbo &&
- ctx->Multisample.Enabled &&
- (fp->program.Base.SystemValuesRead & SYSTEM_BIT_SAMPLE_ID);
+ key->multisample_fbo = ctx->Multisample.Enabled &&
+ _mesa_geometric_samples(ctx->DrawBuffer) > 1;
/* BRW_NEW_VUE_MAP_GEOM_OUT */
if (brw->gen < 6 || _mesa_bitcount_64(fp->program.Base.InputsRead &