glsl: Add "built-in" functions to do 64x64 => 64 multiplication
These functions are directly available in shaders. A #define is added to detect the presence. This allows these functions to be tested using piglit regardless of whether the driver uses them for lowering. The GLSL spec says that functions and macros beginning with __ are reserved for use by the implementation... hey, that's us! Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
parent
aa38bf1e59
commit
330fc2413c
|
@ -21,8 +21,10 @@ LIBGLSL_FILES = \
|
|||
glsl/blob.h \
|
||||
glsl/builtin_functions.cpp \
|
||||
glsl/builtin_functions.h \
|
||||
glsl/builtin_int64.h \
|
||||
glsl/builtin_types.cpp \
|
||||
glsl/builtin_variables.cpp \
|
||||
glsl/generate_ir.cpp \
|
||||
glsl/glsl_parser_extras.cpp \
|
||||
glsl/glsl_parser_extras.h \
|
||||
glsl/glsl_symbol_table.cpp \
|
||||
|
|
|
@ -576,6 +576,11 @@ vote(const _mesa_glsl_parse_state *state)
|
|||
return state->ARB_shader_group_vote_enable;
|
||||
}
|
||||
|
||||
static bool
|
||||
integer_functions_supported(const _mesa_glsl_parse_state *state)
|
||||
{
|
||||
return state->extensions->MESA_shader_integer_functions;
|
||||
}
|
||||
/** @} */
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -3094,6 +3099,10 @@ builtin_builder::create_builtins()
|
|||
add_function("allInvocationsARB", _vote(ir_unop_vote_all), NULL);
|
||||
add_function("allInvocationsEqualARB", _vote(ir_unop_vote_eq), NULL);
|
||||
|
||||
add_function("__builtin_umul64",
|
||||
generate_ir::umul64(mem_ctx, integer_functions_supported),
|
||||
NULL);
|
||||
|
||||
#undef F
|
||||
#undef FI
|
||||
#undef FIUD_VEC
|
||||
|
|
|
@ -43,4 +43,11 @@ _mesa_get_main_function_signature(glsl_symbol_table *symbols);
|
|||
extern void
|
||||
_mesa_glsl_release_builtin_functions(void);
|
||||
|
||||
namespace generate_ir {
|
||||
|
||||
ir_function_signature *
|
||||
umul64(void *mem_ctx, builtin_available_predicate avail);
|
||||
|
||||
}
|
||||
|
||||
#endif /* BULITIN_FUNCTIONS_H */
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
ir_function_signature *
|
||||
umul64(void *mem_ctx, builtin_available_predicate avail)
|
||||
{
|
||||
ir_function_signature *const sig =
|
||||
new(mem_ctx) ir_function_signature(glsl_type::uvec2_type, avail);
|
||||
ir_factory body(&sig->body, mem_ctx);
|
||||
sig->is_defined = true;
|
||||
|
||||
exec_list sig_parameters;
|
||||
|
||||
ir_variable *const r0001 = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in);
|
||||
sig_parameters.push_tail(r0001);
|
||||
ir_variable *const r0002 = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "b", ir_var_function_in);
|
||||
sig_parameters.push_tail(r0002);
|
||||
ir_variable *const r0003 = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "result", ir_var_auto);
|
||||
body.emit(r0003);
|
||||
body.emit(assign(r0003, imul_high(swizzle_x(r0001), swizzle_x(r0002)), 0x02));
|
||||
|
||||
body.emit(assign(r0003, mul(swizzle_x(r0001), swizzle_x(r0002)), 0x01));
|
||||
|
||||
ir_expression *const r0004 = mul(swizzle_x(r0001), swizzle_y(r0002));
|
||||
ir_expression *const r0005 = mul(swizzle_y(r0001), swizzle_x(r0002));
|
||||
ir_expression *const r0006 = add(r0004, r0005);
|
||||
body.emit(assign(r0003, add(swizzle_y(r0003), r0006), 0x02));
|
||||
|
||||
body.emit(ret(r0003));
|
||||
|
||||
sig->replace_parameters(&sig_parameters);
|
||||
return sig;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright © 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 "ir_builder.h"
|
||||
#include "builtin_functions.h"
|
||||
#include "program/prog_instruction.h" /* for SWIZZLE_X, &c. */
|
||||
|
||||
using namespace ir_builder;
|
||||
|
||||
namespace generate_ir {
|
||||
|
||||
#include "builtin_int64.h"
|
||||
|
||||
}
|
|
@ -1334,7 +1334,8 @@ add_builtin_define(glcpp_parser_t *parser, const char *name, int value)
|
|||
}
|
||||
|
||||
glcpp_parser_t *
|
||||
glcpp_parser_create(glcpp_extension_iterator extensions, void *state, gl_api api)
|
||||
glcpp_parser_create(const struct gl_extensions *extension_list,
|
||||
glcpp_extension_iterator extensions, void *state, gl_api api)
|
||||
{
|
||||
glcpp_parser_t *parser;
|
||||
|
||||
|
@ -1369,6 +1370,7 @@ glcpp_parser_create(glcpp_extension_iterator extensions, void *state, gl_api api
|
|||
parser->error = 0;
|
||||
|
||||
parser->extensions = extensions;
|
||||
parser->extension_list = extension_list;
|
||||
parser->state = state;
|
||||
parser->api = api;
|
||||
parser->version = 0;
|
||||
|
@ -2335,6 +2337,16 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
|
|||
parser->extensions(parser->state, add_builtin_define, parser,
|
||||
version, parser->is_gles);
|
||||
|
||||
if (parser->extension_list) {
|
||||
/* If MESA_shader_integer_functions is supported, then the building
|
||||
* blocks required for the 64x64 => 64 multiply exist. Add defines for
|
||||
* those functions so that they can be tested.
|
||||
*/
|
||||
if (parser->extension_list->MESA_shader_integer_functions) {
|
||||
add_builtin_define(parser, "__have_builtin_builtin_umul64", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (explicitly_set) {
|
||||
ralloc_asprintf_rewrite_tail(&parser->output, &parser->output_length,
|
||||
"#version %" PRIiMAX "%s%s", version,
|
||||
|
|
|
@ -205,6 +205,7 @@ struct glcpp_parser {
|
|||
size_t info_log_length;
|
||||
int error;
|
||||
glcpp_extension_iterator extensions;
|
||||
const struct gl_extensions *extension_list;
|
||||
void *state;
|
||||
gl_api api;
|
||||
unsigned version;
|
||||
|
@ -225,7 +226,8 @@ struct glcpp_parser {
|
|||
};
|
||||
|
||||
glcpp_parser_t *
|
||||
glcpp_parser_create (glcpp_extension_iterator extensions, void *state, gl_api api);
|
||||
glcpp_parser_create(const struct gl_extensions *extension_list,
|
||||
glcpp_extension_iterator extensions, void *state, gl_api api);
|
||||
|
||||
int
|
||||
glcpp_parser_parse (glcpp_parser_t *parser);
|
||||
|
|
|
@ -218,7 +218,7 @@ glcpp_preprocess(void *ralloc_ctx, const char **shader, char **info_log,
|
|||
{
|
||||
int errors;
|
||||
glcpp_parser_t *parser =
|
||||
glcpp_parser_create(extensions, state, gl_ctx->API);
|
||||
glcpp_parser_create(&gl_ctx->Extensions, extensions, state, gl_ctx->API);
|
||||
|
||||
if (! gl_ctx->Const.DisableGLSLLineContinuations)
|
||||
*shader = remove_line_continuations(parser, *shader);
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/* Compile with:
|
||||
*
|
||||
* glsl_compiler --version 140 --dump-builder int64.glsl > builtin_int64.h
|
||||
*
|
||||
* Using version 1.40+ prevents built-in variables from being included.
|
||||
*/
|
||||
#version 140
|
||||
#extension GL_MESA_shader_integer_functions: require
|
||||
|
||||
uvec2
|
||||
umul64(uvec2 a, uvec2 b)
|
||||
{
|
||||
uvec2 result;
|
||||
|
||||
umulExtended(a.x, b.x, result.y, result.x);
|
||||
result.y += a.x * b.y + a.y * b.x;
|
||||
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue