2016-01-21 09:19:53 -08:00
|
|
|
/*
|
|
|
|
* Copyright © 2015-2016 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "brw_compiler.h"
|
|
|
|
#include "brw_context.h"
|
|
|
|
#include "compiler/nir/nir.h"
|
|
|
|
#include "main/errors.h"
|
|
|
|
#include "util/debug.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
shader_debug_log_mesa(void *data, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct brw_context *brw = (struct brw_context *)data;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
GLuint msg_id = 0;
|
|
|
|
_mesa_gl_vdebug(&brw->ctx, &msg_id,
|
|
|
|
MESA_DEBUG_SOURCE_SHADER_COMPILER,
|
|
|
|
MESA_DEBUG_TYPE_OTHER,
|
|
|
|
MESA_DEBUG_SEVERITY_NOTIFICATION, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shader_perf_log_mesa(void *data, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct brw_context *brw = (struct brw_context *)data;
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
|
|
|
if (unlikely(INTEL_DEBUG & DEBUG_PERF)) {
|
|
|
|
va_list args_copy;
|
|
|
|
va_copy(args_copy, args);
|
|
|
|
vfprintf(stderr, fmt, args_copy);
|
|
|
|
va_end(args_copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (brw->perf_debug) {
|
|
|
|
GLuint msg_id = 0;
|
|
|
|
_mesa_gl_vdebug(&brw->ctx, &msg_id,
|
|
|
|
MESA_DEBUG_SOURCE_SHADER_COMPILER,
|
|
|
|
MESA_DEBUG_TYPE_PERFORMANCE,
|
|
|
|
MESA_DEBUG_SEVERITY_MEDIUM, fmt, args);
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2016-01-21 09:30:05 -08:00
|
|
|
#define COMMON_OPTIONS \
|
|
|
|
.lower_sub = true, \
|
|
|
|
.lower_fdiv = true, \
|
|
|
|
.lower_scmp = true, \
|
2016-04-28 12:19:13 +02:00
|
|
|
.lower_fmod32 = true, \
|
2015-08-03 15:02:05 -07:00
|
|
|
.lower_fmod64 = false, \
|
2016-01-21 09:30:05 -08:00
|
|
|
.lower_bitfield_extract = true, \
|
|
|
|
.lower_bitfield_insert = true, \
|
|
|
|
.lower_uadd_carry = true, \
|
|
|
|
.lower_usub_borrow = true, \
|
|
|
|
.lower_fdiv = true, \
|
2016-01-19 08:19:20 +01:00
|
|
|
.lower_flrp64 = true, \
|
2016-03-25 10:54:27 -07:00
|
|
|
.native_integers = true, \
|
|
|
|
.vertex_id_zero_based = true
|
2016-01-21 09:30:05 -08:00
|
|
|
|
|
|
|
static const struct nir_shader_compiler_options scalar_nir_options = {
|
|
|
|
COMMON_OPTIONS,
|
2016-01-21 15:30:57 -08:00
|
|
|
.lower_pack_half_2x16 = true,
|
2016-01-25 11:07:28 -08:00
|
|
|
.lower_pack_snorm_2x16 = true,
|
|
|
|
.lower_pack_snorm_4x8 = true,
|
|
|
|
.lower_pack_unorm_2x16 = true,
|
|
|
|
.lower_pack_unorm_4x8 = true,
|
2016-01-21 15:30:57 -08:00
|
|
|
.lower_unpack_half_2x16 = true,
|
2016-01-25 11:07:28 -08:00
|
|
|
.lower_unpack_snorm_2x16 = true,
|
|
|
|
.lower_unpack_snorm_4x8 = true,
|
|
|
|
.lower_unpack_unorm_2x16 = true,
|
|
|
|
.lower_unpack_unorm_4x8 = true,
|
2016-01-21 09:30:05 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct nir_shader_compiler_options vector_nir_options = {
|
|
|
|
COMMON_OPTIONS,
|
|
|
|
|
|
|
|
/* In the vec4 backend, our dpN instruction replicates its result to all the
|
|
|
|
* components of a vec4. We would like NIR to give us replicated fdot
|
|
|
|
* instructions because it can optimize better for us.
|
|
|
|
*/
|
|
|
|
.fdot_replicates = true,
|
2016-01-25 11:07:28 -08:00
|
|
|
|
2016-03-07 10:55:21 -08:00
|
|
|
/* Prior to Gen6, there are no three source operations for SIMD4x2. */
|
2016-04-28 07:13:10 +02:00
|
|
|
.lower_flrp32 = true,
|
2016-03-07 10:55:21 -08:00
|
|
|
|
|
|
|
.lower_pack_snorm_2x16 = true,
|
|
|
|
.lower_pack_unorm_2x16 = true,
|
|
|
|
.lower_unpack_snorm_2x16 = true,
|
|
|
|
.lower_unpack_unorm_2x16 = true,
|
|
|
|
.lower_extract_byte = true,
|
|
|
|
.lower_extract_word = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct nir_shader_compiler_options vector_nir_options_gen6 = {
|
|
|
|
COMMON_OPTIONS,
|
|
|
|
|
|
|
|
/* In the vec4 backend, our dpN instruction replicates its result to all the
|
|
|
|
* components of a vec4. We would like NIR to give us replicated fdot
|
|
|
|
* instructions because it can optimize better for us.
|
|
|
|
*/
|
|
|
|
.fdot_replicates = true,
|
|
|
|
|
2016-01-25 11:07:28 -08:00
|
|
|
.lower_pack_snorm_2x16 = true,
|
|
|
|
.lower_pack_unorm_2x16 = true,
|
|
|
|
.lower_unpack_snorm_2x16 = true,
|
|
|
|
.lower_unpack_unorm_2x16 = true,
|
|
|
|
.lower_extract_byte = true,
|
|
|
|
.lower_extract_word = true,
|
2016-01-21 09:30:05 -08:00
|
|
|
};
|
|
|
|
|
2016-01-21 09:19:53 -08:00
|
|
|
struct brw_compiler *
|
|
|
|
brw_compiler_create(void *mem_ctx, const struct brw_device_info *devinfo)
|
|
|
|
{
|
|
|
|
struct brw_compiler *compiler = rzalloc(mem_ctx, struct brw_compiler);
|
|
|
|
|
|
|
|
compiler->devinfo = devinfo;
|
|
|
|
compiler->shader_debug_log = shader_debug_log_mesa;
|
|
|
|
compiler->shader_perf_log = shader_perf_log_mesa;
|
|
|
|
|
|
|
|
brw_fs_alloc_reg_sets(compiler);
|
|
|
|
brw_vec4_alloc_reg_set(compiler);
|
|
|
|
|
i965: Add an INTEL_PRECISE_TRIG=1 option to fix SIN/COS output range.
The SIN and COS instructions on Intel hardware can produce values
slightly outside of the [-1.0, 1.0] range for a small set of values.
Obviously, this can break everyone's expectations about trig functions.
According to an internal presentation, the COS instruction can produce
a value up to 1.000027 for inputs in the range (0.08296, 0.09888). One
suggested workaround is to multiply by 0.99997, scaling down the
amplitude slightly. Apparently this also minimizes the error function,
reducing the maximum error from 0.00006 to about 0.00003.
When enabled, fixes 16 dEQP precision tests
dEQP-GLES31.functional.shaders.builtin_functions.precision.
{cos,sin}.{highp,mediump}_compute.{scalar,vec2,vec4,vec4}.
at the cost of making every sin and cos call more expensive (about
twice the number of cycles on recent hardware). Enabling this
option has been shown to reduce GPUTest Volplosion performance by
about 10%.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2016-01-27 12:21:04 -08:00
|
|
|
compiler->precise_trig = env_var_as_boolean("INTEL_PRECISE_TRIG", false);
|
|
|
|
|
2016-01-21 09:19:53 -08:00
|
|
|
compiler->scalar_stage[MESA_SHADER_VERTEX] =
|
|
|
|
devinfo->gen >= 8 && !(INTEL_DEBUG & DEBUG_VEC4VS);
|
2015-11-14 17:40:43 -08:00
|
|
|
compiler->scalar_stage[MESA_SHADER_TESS_CTRL] =
|
2016-05-08 21:49:34 -07:00
|
|
|
devinfo->gen >= 8 && env_var_as_boolean("INTEL_SCALAR_TCS", true);
|
2016-01-21 09:19:53 -08:00
|
|
|
compiler->scalar_stage[MESA_SHADER_TESS_EVAL] =
|
|
|
|
devinfo->gen >= 8 && env_var_as_boolean("INTEL_SCALAR_TES", true);
|
|
|
|
compiler->scalar_stage[MESA_SHADER_GEOMETRY] =
|
2016-05-09 17:09:35 -07:00
|
|
|
devinfo->gen >= 8 && env_var_as_boolean("INTEL_SCALAR_GS", true);
|
2016-01-21 09:19:53 -08:00
|
|
|
compiler->scalar_stage[MESA_SHADER_FRAGMENT] = true;
|
|
|
|
compiler->scalar_stage[MESA_SHADER_COMPUTE] = true;
|
|
|
|
|
|
|
|
/* We want the GLSL compiler to emit code that uses condition codes */
|
|
|
|
for (int i = 0; i < MESA_SHADER_STAGES; i++) {
|
|
|
|
compiler->glsl_compiler_options[i].MaxUnrollIterations = 32;
|
|
|
|
compiler->glsl_compiler_options[i].MaxIfDepth =
|
|
|
|
devinfo->gen < 6 ? 16 : UINT_MAX;
|
|
|
|
|
|
|
|
compiler->glsl_compiler_options[i].EmitNoNoise = true;
|
|
|
|
compiler->glsl_compiler_options[i].EmitNoMainReturn = true;
|
|
|
|
compiler->glsl_compiler_options[i].EmitNoIndirectInput = true;
|
|
|
|
compiler->glsl_compiler_options[i].EmitNoIndirectUniform = false;
|
2016-05-08 22:44:02 +02:00
|
|
|
compiler->glsl_compiler_options[i].LowerCombinedClipCullDistance = true;
|
2016-01-21 09:19:53 -08:00
|
|
|
|
|
|
|
bool is_scalar = compiler->scalar_stage[i];
|
|
|
|
|
|
|
|
compiler->glsl_compiler_options[i].EmitNoIndirectOutput = is_scalar;
|
|
|
|
compiler->glsl_compiler_options[i].EmitNoIndirectTemp = is_scalar;
|
|
|
|
compiler->glsl_compiler_options[i].OptimizeForAOS = !is_scalar;
|
|
|
|
|
|
|
|
/* !ARB_gpu_shader5 */
|
|
|
|
if (devinfo->gen < 7)
|
|
|
|
compiler->glsl_compiler_options[i].EmitNoIndirectSampler = true;
|
|
|
|
|
2016-03-07 10:55:21 -08:00
|
|
|
if (is_scalar) {
|
|
|
|
compiler->glsl_compiler_options[i].NirOptions = &scalar_nir_options;
|
|
|
|
} else {
|
|
|
|
compiler->glsl_compiler_options[i].NirOptions =
|
|
|
|
devinfo->gen < 6 ? &vector_nir_options : &vector_nir_options_gen6;
|
|
|
|
}
|
2016-01-21 09:19:53 -08:00
|
|
|
|
|
|
|
compiler->glsl_compiler_options[i].LowerBufferInterfaceBlocks = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
compiler->glsl_compiler_options[MESA_SHADER_TESS_CTRL].EmitNoIndirectInput = false;
|
|
|
|
compiler->glsl_compiler_options[MESA_SHADER_TESS_EVAL].EmitNoIndirectInput = false;
|
2015-11-14 17:40:43 -08:00
|
|
|
compiler->glsl_compiler_options[MESA_SHADER_TESS_CTRL].EmitNoIndirectOutput = false;
|
2016-01-21 09:19:53 -08:00
|
|
|
|
|
|
|
if (compiler->scalar_stage[MESA_SHADER_GEOMETRY])
|
|
|
|
compiler->glsl_compiler_options[MESA_SHADER_GEOMETRY].EmitNoIndirectInput = false;
|
|
|
|
|
|
|
|
compiler->glsl_compiler_options[MESA_SHADER_COMPUTE]
|
|
|
|
.LowerShaderSharedVariables = true;
|
|
|
|
|
|
|
|
return compiler;
|
|
|
|
}
|