diff options
Diffstat (limited to 'src/mesa')
42 files changed, 2108 insertions, 2208 deletions
diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources index ffe560faa3d..6669f295399 100644 --- a/src/mesa/Makefile.sources +++ b/src/mesa/Makefile.sources @@ -57,6 +57,8 @@ MAIN_FILES = \ main/dd.h \ main/debug.c \ main/debug.h \ + main/debug_output.c \ + main/debug_output.h \ main/depth.c \ main/depth.h \ main/dlist.c \ @@ -530,8 +532,6 @@ PROGRAM_FILES = \ program/program_parser.h \ program/prog_statevars.c \ program/prog_statevars.h \ - program/sampler.cpp \ - program/sampler.h \ program/string_to_uint_map.cpp \ program/symbol_table.c \ program/symbol_table.h diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index 5cfa2f8ca4f..a6545084e31 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -46,6 +46,7 @@ #include "main/mtypes.h" #include "main/framebuffer.h" #include "main/version.h" +#include "main/debug_output.h" #include "main/errors.h" #include "main/macros.h" diff --git a/src/mesa/drivers/dri/i965/brw_fs_surface_builder.cpp b/src/mesa/drivers/dri/i965/brw_fs_surface_builder.cpp index f2faceeb579..9b0750026c4 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_surface_builder.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_surface_builder.cpp @@ -1140,7 +1140,7 @@ namespace brw { dims, rsize, op, pred); /* An unbound surface access should give zero as result. */ - if (rsize) + if (rsize && pred) set_predicate(pred, bld.SEL(tmp, tmp, brw_imm_d(0))); return tmp; diff --git a/src/mesa/drivers/dri/i965/brw_misc_state.c b/src/mesa/drivers/dri/i965/brw_misc_state.c index 319c2a5669f..ab1a0d7255f 100644 --- a/src/mesa/drivers/dri/i965/brw_misc_state.c +++ b/src/mesa/drivers/dri/i965/brw_misc_state.c @@ -919,7 +919,7 @@ brw_emit_select_pipeline(struct brw_context *brw, enum brw_pipeline pipeline) * MI_PIPELINE_SELECT command to change the Pipeline Select Mode. */ const unsigned dc_flush = - brw->gen >= 7 ? PIPE_CONTROL_DATA_CACHE_INVALIDATE : 0; + brw->gen >= 7 ? PIPE_CONTROL_DATA_CACHE_FLUSH : 0; if (brw->gen == 6) { /* Hardware workaround: SNB B-Spec says: diff --git a/src/mesa/drivers/dri/i965/brw_nir.c b/src/mesa/drivers/dri/i965/brw_nir.c index ef5b34cc687..0a916c99947 100644 --- a/src/mesa/drivers/dri/i965/brw_nir.c +++ b/src/mesa/drivers/dri/i965/brw_nir.c @@ -490,6 +490,10 @@ brw_preprocess_nir(nir_shader *nir, bool is_scalar) nir = nir_optimize(nir, is_scalar); + if (is_scalar) { + OPT_V(nir_lower_load_const_to_scalar); + } + /* Lower a bunch of stuff */ OPT_V(nir_lower_var_copies); diff --git a/src/mesa/drivers/dri/i965/brw_pipe_control.c b/src/mesa/drivers/dri/i965/brw_pipe_control.c index 6c636d26139..b41e28e1ec8 100644 --- a/src/mesa/drivers/dri/i965/brw_pipe_control.c +++ b/src/mesa/drivers/dri/i965/brw_pipe_control.c @@ -51,7 +51,7 @@ gen8_add_cs_stall_workaround_bits(uint32_t *flags) PIPE_CONTROL_WRITE_TIMESTAMP | PIPE_CONTROL_STALL_AT_SCOREBOARD | PIPE_CONTROL_DEPTH_STALL | - PIPE_CONTROL_DATA_CACHE_INVALIDATE; + PIPE_CONTROL_DATA_CACHE_FLUSH; /* If we're doing a CS stall, and don't already have one of the * workaround bits set, add "Stall at Pixel Scoreboard." diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c index c9872b68d75..b093a87bb82 100644 --- a/src/mesa/drivers/dri/i965/brw_program.c +++ b/src/mesa/drivers/dri/i965/brw_program.c @@ -209,7 +209,7 @@ static void brw_memory_barrier(struct gl_context *ctx, GLbitfield barriers) { struct brw_context *brw = brw_context(ctx); - unsigned bits = (PIPE_CONTROL_DATA_CACHE_INVALIDATE | + unsigned bits = (PIPE_CONTROL_DATA_CACHE_FLUSH | PIPE_CONTROL_NO_WRITE | PIPE_CONTROL_CS_STALL); assert(brw->gen >= 7 && brw->gen <= 9); diff --git a/src/mesa/drivers/dri/i965/brw_schedule_instructions.cpp b/src/mesa/drivers/dri/i965/brw_schedule_instructions.cpp index 60f7fd9cfcd..4f97577515a 100644 --- a/src/mesa/drivers/dri/i965/brw_schedule_instructions.cpp +++ b/src/mesa/drivers/dri/i965/brw_schedule_instructions.cpp @@ -939,8 +939,9 @@ fs_instruction_scheduler::calculate_deps() foreach_in_list(schedule_node, n, &instructions) { fs_inst *inst = (fs_inst *)n->inst; - if (inst->opcode == FS_OPCODE_PLACEHOLDER_HALT || - inst->has_side_effects()) + if ((inst->opcode == FS_OPCODE_PLACEHOLDER_HALT || + inst->has_side_effects()) && + inst->opcode != FS_OPCODE_FB_WRITE) add_barrier_deps(n); /* read-after-write deps. */ @@ -1195,7 +1196,7 @@ vec4_instruction_scheduler::calculate_deps() foreach_in_list(schedule_node, n, &instructions) { vec4_instruction *inst = (vec4_instruction *)n->inst; - if (inst->has_side_effects()) + if (inst->has_side_effects() && inst->opcode != FS_OPCODE_FB_WRITE) add_barrier_deps(n); /* read-after-write deps. */ diff --git a/src/mesa/drivers/dri/i965/gen7_l3_state.c b/src/mesa/drivers/dri/i965/gen7_l3_state.c index b63e61ca8f0..0c1813f9048 100644 --- a/src/mesa/drivers/dri/i965/gen7_l3_state.c +++ b/src/mesa/drivers/dri/i965/gen7_l3_state.c @@ -330,23 +330,39 @@ setup_l3_config(struct brw_context *brw, const struct brw_l3_config *cfg) /* According to the hardware docs, the L3 partitioning can only be changed * while the pipeline is completely drained and the caches are flushed, - * which involves a first PIPE_CONTROL flush which stalls the pipeline and - * initiates invalidation of the relevant caches... + * which involves a first PIPE_CONTROL flush which stalls the pipeline... + */ + brw_emit_pipe_control_flush(brw, + PIPE_CONTROL_DATA_CACHE_FLUSH | + PIPE_CONTROL_NO_WRITE | + PIPE_CONTROL_CS_STALL); + + /* ...followed by a second pipelined PIPE_CONTROL that initiates + * invalidation of the relevant caches. Note that because RO invalidation + * happens at the top of the pipeline (i.e. right away as the PIPE_CONTROL + * command is processed by the CS) we cannot combine it with the previous + * stalling flush as the hardware documentation suggests, because that + * would cause the CS to stall on previous rendering *after* RO + * invalidation and wouldn't prevent the RO caches from being polluted by + * concurrent rendering before the stall completes. This intentionally + * doesn't implement the SKL+ hardware workaround suggesting to enable CS + * stall on PIPE_CONTROLs with the texture cache invalidation bit set for + * GPGPU workloads because the previous and subsequent PIPE_CONTROLs + * already guarantee that there is no concurrent GPGPU kernel execution + * (see SKL HSD 2132585). */ brw_emit_pipe_control_flush(brw, PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE | PIPE_CONTROL_CONST_CACHE_INVALIDATE | PIPE_CONTROL_INSTRUCTION_INVALIDATE | - PIPE_CONTROL_DATA_CACHE_INVALIDATE | - PIPE_CONTROL_NO_WRITE | - PIPE_CONTROL_CS_STALL); + PIPE_CONTROL_STATE_CACHE_INVALIDATE | + PIPE_CONTROL_NO_WRITE); - /* ...followed by a second stalling flush which guarantees that - * invalidation is complete when the L3 configuration registers are - * modified. + /* Now send a third stalling flush to make sure that invalidation is + * complete when the L3 configuration registers are modified. */ brw_emit_pipe_control_flush(brw, - PIPE_CONTROL_DATA_CACHE_INVALIDATE | + PIPE_CONTROL_DATA_CACHE_FLUSH | PIPE_CONTROL_NO_WRITE | PIPE_CONTROL_CS_STALL); diff --git a/src/mesa/drivers/dri/i965/intel_reg.h b/src/mesa/drivers/dri/i965/intel_reg.h index 8888d6f776c..365c045b8b0 100644 --- a/src/mesa/drivers/dri/i965/intel_reg.h +++ b/src/mesa/drivers/dri/i965/intel_reg.h @@ -86,7 +86,7 @@ #define PIPE_CONTROL_INTERRUPT_ENABLE (1 << 8) #define PIPE_CONTROL_FLUSH_ENABLE (1 << 7) /* Gen7+ only */ /* GT */ -#define PIPE_CONTROL_DATA_CACHE_INVALIDATE (1 << 5) +#define PIPE_CONTROL_DATA_CACHE_FLUSH (1 << 5) #define PIPE_CONTROL_VF_CACHE_INVALIDATE (1 << 4) #define PIPE_CONTROL_CONST_CACHE_INVALIDATE (1 << 3) #define PIPE_CONTROL_STATE_CACHE_INVALIDATE (1 << 2) diff --git a/src/mesa/drivers/dri/i965/test_vec4_cmod_propagation.cpp b/src/mesa/drivers/dri/i965/test_vec4_cmod_propagation.cpp index e5e566c60bc..8d4a447a88b 100644 --- a/src/mesa/drivers/dri/i965/test_vec4_cmod_propagation.cpp +++ b/src/mesa/drivers/dri/i965/test_vec4_cmod_propagation.cpp @@ -40,6 +40,7 @@ public: struct gl_context *ctx; struct gl_shader_program *shader_prog; struct brw_vertex_program *vp; + struct brw_vue_prog_data *prog_data; vec4_visitor *v; }; @@ -47,9 +48,13 @@ class cmod_propagation_vec4_visitor : public vec4_visitor { public: cmod_propagation_vec4_visitor(struct brw_compiler *compiler, - nir_shader *shader) - : vec4_visitor(compiler, NULL, NULL, NULL, shader, NULL, - false, -1) {} + nir_shader *shader, + struct brw_vue_prog_data *prog_data) + : vec4_visitor(compiler, NULL, NULL, prog_data, shader, NULL, + false, -1) + { + prog_data->dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT; + } protected: /* Dummy implementation for pure virtual methods */ @@ -96,13 +101,14 @@ void cmod_propagation_test::SetUp() ctx = (struct gl_context *)calloc(1, sizeof(*ctx)); compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler)); devinfo = (struct brw_device_info *)calloc(1, sizeof(*devinfo)); + prog_data = (struct brw_vue_prog_data *)calloc(1, sizeof(*prog_data)); compiler->devinfo = devinfo; vp = ralloc(NULL, struct brw_vertex_program); nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL); - v = new cmod_propagation_vec4_visitor(compiler, shader); + v = new cmod_propagation_vec4_visitor(compiler, shader, prog_data); _mesa_init_gl_program(&vp->program.Base, GL_VERTEX_SHADER, 0); diff --git a/src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp b/src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp index 12667ffd23c..311f07a7cca 100644 --- a/src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp +++ b/src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp @@ -39,6 +39,7 @@ public: struct gl_context *ctx; struct gl_shader_program *shader_prog; struct brw_vertex_program *vp; + struct brw_vue_prog_data *prog_data; vec4_visitor *v; }; @@ -46,10 +47,12 @@ class copy_propagation_vec4_visitor : public vec4_visitor { public: copy_propagation_vec4_visitor(struct brw_compiler *compiler, - nir_shader *shader) - : vec4_visitor(compiler, NULL, NULL, NULL, shader, NULL, + nir_shader *shader, + struct brw_vue_prog_data *prog_data) + : vec4_visitor(compiler, NULL, NULL, prog_data, shader, NULL, false /* no_spills */, -1) { + prog_data->dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT; } protected: @@ -91,13 +94,14 @@ void copy_propagation_test::SetUp() ctx = (struct gl_context *)calloc(1, sizeof(*ctx)); compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler)); devinfo = (struct brw_device_info *)calloc(1, sizeof(*devinfo)); + prog_data = (struct brw_vue_prog_data *)calloc(1, sizeof(*prog_data)); compiler->devinfo = devinfo; vp = ralloc(NULL, struct brw_vertex_program); nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL); - v = new copy_propagation_vec4_visitor(compiler, shader); + v = new copy_propagation_vec4_visitor(compiler, shader, prog_data); _mesa_init_gl_program(&vp->program.Base, GL_VERTEX_SHADER, 0); diff --git a/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp b/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp index 34dcf95dc48..cc4a2de89d5 100644 --- a/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp +++ b/src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp @@ -41,6 +41,7 @@ public: struct gl_context *ctx; struct gl_shader_program *shader_prog; struct brw_vertex_program *vp; + struct brw_vue_prog_data *prog_data; vec4_visitor *v; }; @@ -49,10 +50,12 @@ class register_coalesce_vec4_visitor : public vec4_visitor { public: register_coalesce_vec4_visitor(struct brw_compiler *compiler, - nir_shader *shader) - : vec4_visitor(compiler, NULL, NULL, NULL, shader, NULL, + nir_shader *shader, + struct brw_vue_prog_data *prog_data) + : vec4_visitor(compiler, NULL, NULL, prog_data, shader, NULL, false /* no_spills */, -1) { + prog_data->dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT; } protected: @@ -94,13 +97,14 @@ void register_coalesce_test::SetUp() ctx = (struct gl_context *)calloc(1, sizeof(*ctx)); compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler)); devinfo = (struct brw_device_info *)calloc(1, sizeof(*devinfo)); + prog_data = (struct brw_vue_prog_data *)calloc(1, sizeof(*prog_data)); compiler->devinfo = devinfo; vp = ralloc(NULL, struct brw_vertex_program); nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL); - v = new register_coalesce_vec4_visitor(compiler, shader); + v = new register_coalesce_vec4_visitor(compiler, shader, prog_data); _mesa_init_gl_program(&vp->program.Base, GL_VERTEX_SHADER, 0); diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 8b415ed6019..9388a1ca51d 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -89,6 +89,7 @@ #include "context.h" #include "cpuinfo.h" #include "debug.h" +#include "debug_output.h" #include "depth.h" #include "dlist.h" #include "eval.h" @@ -814,8 +815,8 @@ init_attrib_groups(struct gl_context *ctx) _mesa_init_current( ctx ); _mesa_init_depth( ctx ); _mesa_init_debug( ctx ); + _mesa_init_debug_output( ctx ); _mesa_init_display_list( ctx ); - _mesa_init_errors( ctx ); _mesa_init_eval( ctx ); _mesa_init_fbobjects( ctx ); _mesa_init_feedback( ctx ); diff --git a/src/mesa/main/debug_output.c b/src/mesa/main/debug_output.c new file mode 100644 index 00000000000..10ee6757cc1 --- /dev/null +++ b/src/mesa/main/debug_output.c @@ -0,0 +1,1301 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999-2016 Brian Paul, et al All Rights Reserved. + * + * 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 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 <stdarg.h> +#include <stdio.h> +#include "context.h" +#include "debug_output.h" +#include "dispatch.h" +#include "enums.h" +#include "imports.h" +#include "hash.h" +#include "mtypes.h" +#include "version.h" +#include "util/hash_table.h" +#include "util/simple_list.h" + + +static mtx_t DynamicIDMutex = _MTX_INITIALIZER_NP; +static GLuint NextDynamicID = 1; + + +/** + * A namespace element. + */ +struct gl_debug_element +{ + struct simple_node link; + + GLuint ID; + /* at which severity levels (mesa_debug_severity) is the message enabled */ + GLbitfield State; +}; + + +struct gl_debug_namespace +{ + struct simple_node Elements; + GLbitfield DefaultState; +}; + + +struct gl_debug_group { + struct gl_debug_namespace Namespaces[MESA_DEBUG_SOURCE_COUNT][MESA_DEBUG_TYPE_COUNT]; +}; + + +/** + * An error, warning, or other piece of debug information for an application + * to consume via GL_ARB_debug_output/GL_KHR_debug. + */ +struct gl_debug_message +{ + enum mesa_debug_source source; + enum mesa_debug_type type; + GLuint id; + enum mesa_debug_severity severity; + /* length as given by the user - if message was explicitly null terminated, + * length can be negative */ + GLsizei length; + GLcharARB *message; +}; + + +/** + * Debug message log. It works like a ring buffer. + */ +struct gl_debug_log { + struct gl_debug_message Messages[MAX_DEBUG_LOGGED_MESSAGES]; + GLint NextMessage; + GLint NumMessages; +}; + + +struct gl_debug_state +{ + GLDEBUGPROC Callback; + const void *CallbackData; + GLboolean SyncOutput; + GLboolean DebugOutput; + + struct gl_debug_group *Groups[MAX_DEBUG_GROUP_STACK_DEPTH]; + struct gl_debug_message GroupMessages[MAX_DEBUG_GROUP_STACK_DEPTH]; + GLint CurrentGroup; // GroupStackDepth - 1 + + struct gl_debug_log Log; +}; + + +static char out_of_memory[] = "Debugging error: out of memory"; + +static const GLenum debug_source_enums[] = { + GL_DEBUG_SOURCE_API, + GL_DEBUG_SOURCE_WINDOW_SYSTEM, + GL_DEBUG_SOURCE_SHADER_COMPILER, + GL_DEBUG_SOURCE_THIRD_PARTY, + GL_DEBUG_SOURCE_APPLICATION, + GL_DEBUG_SOURCE_OTHER, +}; + +static const GLenum debug_type_enums[] = { + GL_DEBUG_TYPE_ERROR, + GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, + GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR, + GL_DEBUG_TYPE_PORTABILITY, + GL_DEBUG_TYPE_PERFORMANCE, + GL_DEBUG_TYPE_OTHER, + GL_DEBUG_TYPE_MARKER, + GL_DEBUG_TYPE_PUSH_GROUP, + GL_DEBUG_TYPE_POP_GROUP, +}; + +static const GLenum debug_severity_enums[] = { + GL_DEBUG_SEVERITY_LOW, + GL_DEBUG_SEVERITY_MEDIUM, + GL_DEBUG_SEVERITY_HIGH, + GL_DEBUG_SEVERITY_NOTIFICATION, +}; + + +static enum mesa_debug_source +gl_enum_to_debug_source(GLenum e) +{ + unsigned i; + + for (i = 0; i < ARRAY_SIZE(debug_source_enums); i++) { + if (debug_source_enums[i] == e) + break; + } + return i; +} + +static enum mesa_debug_type +gl_enum_to_debug_type(GLenum e) +{ + unsigned i; + + for (i = 0; i < ARRAY_SIZE(debug_type_enums); i++) { + if (debug_type_enums[i] == e) + break; + } + return i; +} + +static enum mesa_debug_severity +gl_enum_to_debug_severity(GLenum e) +{ + unsigned i; + + for (i = 0; i < ARRAY_SIZE(debug_severity_enums); i++) { + if (debug_severity_enums[i] == e) + break; + } + return i; +} + + +/** + * Handles generating a GL_ARB_debug_output message ID generated by the GL or + * GLSL compiler. + * + * The GL API has this "ID" mechanism, where the intention is to allow a + * client to filter in/out messages based on source, type, and ID. Of course, + * building a giant enum list of all debug output messages that Mesa might + * generate is ridiculous, so instead we have our caller pass us a pointer to + * static storage where the ID should get stored. This ID will be shared + * across all contexts for that message (which seems like a desirable + * property, even if it's not expected by the spec), but note that it won't be + * the same between executions if messages aren't generated in the same order. + */ +void +_mesa_debug_get_id(GLuint *id) +{ + if (!(*id)) { + mtx_lock(&DynamicIDMutex); + if (!(*id)) + *id = NextDynamicID++; + mtx_unlock(&DynamicIDMutex); + } +} + +static void +debug_message_clear(struct gl_debug_message *msg) +{ + if (msg->message != (char*)out_of_memory) + free(msg->message); + msg->message = NULL; + msg->length = 0; +} + +static void +debug_message_store(struct gl_debug_message *msg, + enum mesa_debug_source source, + enum mesa_debug_type type, GLuint id, + enum mesa_debug_severity severity, + GLsizei len, const char *buf) +{ + GLsizei length = len; + + assert(!msg->message && !msg->length); + + if (length < 0) + length = strlen(buf); + + msg->message = malloc(length+1); + if (msg->message) { + (void) strncpy(msg->message, buf, (size_t)length); + msg->message[length] = '\0'; + + msg->length = len; + msg->source = source; + msg->type = type; + msg->id = id; + msg->severity = severity; + } else { + static GLuint oom_msg_id = 0; + _mesa_debug_get_id(&oom_msg_id); + + /* malloc failed! */ + msg->message = out_of_memory; + msg->length = -1; + msg->source = MESA_DEBUG_SOURCE_OTHER; + msg->type = MESA_DEBUG_TYPE_ERROR; + msg->id = oom_msg_id; + msg->severity = MESA_DEBUG_SEVERITY_HIGH; + } +} + +static void +debug_namespace_init(struct gl_debug_namespace *ns) +{ + make_empty_list(&ns->Elements); + + /* Enable all the messages with severity HIGH or MEDIUM by default */ + ns->DefaultState = (1 << MESA_DEBUG_SEVERITY_MEDIUM ) | + (1 << MESA_DEBUG_SEVERITY_HIGH) | + (1 << MESA_DEBUG_SEVERITY_NOTIFICATION); +} + +static void +debug_namespace_clear(struct gl_debug_namespace *ns) +{ + struct simple_node *node, *tmp; + + foreach_s(node, tmp, &ns->Elements) + free(node); +} + +static bool +debug_namespace_copy(struct gl_debug_namespace *dst, + const struct gl_debug_namespace *src) +{ + struct simple_node *node; + + dst->DefaultState = src->DefaultState; + + make_empty_list(&dst->Elements); + foreach(node, &src->Elements) { + const struct gl_debug_element *elem = + (const struct gl_debug_element *) node; + struct gl_debug_element *copy; + + copy = malloc(sizeof(*copy)); + if (!copy) { + debug_namespace_clear(dst); + return false; + } + + copy->ID = elem->ID; + copy->State = elem->State; + insert_at_tail(&dst->Elements, ©->link); + } + + return true; +} + +/** + * Set the state of \p id in the namespace. + */ +static bool +debug_namespace_set(struct gl_debug_namespace *ns, + GLuint id, bool enabled) +{ + const uint32_t state = (enabled) ? + ((1 << MESA_DEBUG_SEVERITY_COUNT) - 1) : 0; + struct gl_debug_element *elem = NULL; + struct simple_node *node; + + /* find the element */ + foreach(node, &ns->Elements) { + struct gl_debug_element *tmp = (struct gl_debug_element *) node; + if (tmp->ID == id) { + elem = tmp; + break; + } + } + + /* we do not need the element if it has the default state */ + if (ns->DefaultState == state) { + if (elem) { + remove_from_list(&elem->link); + free(elem); + } + return true; + } + + if (!elem) { + elem = malloc(sizeof(*elem)); + if (!elem) + return false; + + elem->ID = id; + insert_at_tail(&ns->Elements, &elem->link); + } + + elem->State = state; + + return true; +} + +/** + * Set the default state of the namespace for \p severity. When \p severity + * is MESA_DEBUG_SEVERITY_COUNT, the default values for all severities are + * updated. + */ +static void +debug_namespace_set_all(struct gl_debug_namespace *ns, + enum mesa_debug_severity severity, + bool enabled) +{ + struct simple_node *node, *tmp; + uint32_t mask, val; + + /* set all elements to the same state */ + if (severity == MESA_DEBUG_SEVERITY_COUNT) { + ns->DefaultState = (enabled) ? ((1 << severity) - 1) : 0; + debug_namespace_clear(ns); + make_empty_list(&ns->Elements); + return; + } + + mask = 1 << severity; + val = (enabled) ? mask : 0; + + ns->DefaultState = (ns->DefaultState & ~mask) | val; + + foreach_s(node, tmp, &ns->Elements) { + struct gl_debug_element *elem = (struct gl_debug_element *) node; + + elem->State = (elem->State & ~mask) | val; + if (elem->State == ns->DefaultState) { + remove_from_list(node); + free(node); + } + } +} + +/** + * Get the state of \p id in the namespace. + */ +static bool +debug_namespace_get(const struct gl_debug_namespace *ns, GLuint id, + enum mesa_debug_severity severity) +{ + struct simple_node *node; + uint32_t state; + + state = ns->DefaultState; + foreach(node, &ns->Elements) { + struct gl_debug_element *elem = (struct gl_debug_element *) node; + + if (elem->ID == id) { + state = elem->State; + break; + } + } + + return (state & (1 << severity)); +} + +/** + * Allocate and initialize context debug state. + */ +static struct gl_debug_state * +debug_create(void) +{ + struct gl_debug_state *debug; + int s, t; + + debug = CALLOC_STRUCT(gl_debug_state); + if (!debug) + return NULL; + + debug->Groups[0] = malloc(sizeof(*debug->Groups[0])); + if (!debug->Groups[0]) { + free(debug); + return NULL; + } + + /* Initialize state for filtering known debug messages. */ + for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) { + for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) + debug_namespace_init(&debug->Groups[0]->Namespaces[s][t]); + } + + return debug; +} + +/** + * Return true if the top debug group points to the group below it. + */ +static bool +debug_is_group_read_only(const struct gl_debug_state *debug) +{ + const GLint gstack = debug->CurrentGroup; + return (gstack > 0 && debug->Groups[gstack] == debug->Groups[gstack - 1]); +} + +/** + * Make the top debug group writable. + */ +static bool +debug_make_group_writable(struct gl_debug_state *debug) +{ + const GLint gstack = debug->CurrentGroup; + const struct gl_debug_group *src = debug->Groups[gstack]; + struct gl_debug_group *dst; + int s, t; + + if (!debug_is_group_read_only(debug)) + return true; + + dst = malloc(sizeof(*dst)); + if (!dst) + return false; + + for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) { + for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) { + if (!debug_namespace_copy(&dst->Namespaces[s][t], + &src->Namespaces[s][t])) { + /* error path! */ + for (t = t - 1; t >= 0; t--) + debug_namespace_clear(&dst->Namespaces[s][t]); + for (s = s - 1; s >= 0; s--) { + for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) + debug_namespace_clear(&dst->Namespaces[s][t]); + } + free(dst); + return false; + } + } + } + + debug->Groups[gstack] = dst; + + return true; +} + +/** + * Free the top debug group. + */ +static void +debug_clear_group(struct gl_debug_state *debug) +{ + const GLint gstack = debug->CurrentGroup; + + if (!debug_is_group_read_only(debug)) { + struct gl_debug_group *grp = debug->Groups[gstack]; + int s, t; + + for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) { + for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) + debug_namespace_clear(&grp->Namespaces[s][t]); + } + + free(grp); + } + + debug->Groups[gstack] = NULL; +} + +/** + * Loop through debug group stack tearing down states for + * filtering debug messages. Then free debug output state. + */ +static void +debug_destroy(struct gl_debug_state *debug) +{ + while (debug->CurrentGroup > 0) { + debug_clear_group(debug); + debug->CurrentGroup--; + } + + debug_clear_group(debug); + free(debug); +} + +/** + * Sets the state of the given message source/type/ID tuple. + */ +static void +debug_set_message_enable(struct gl_debug_state *debug, + enum mesa_debug_source source, + enum mesa_debug_type type, + GLuint id, GLboolean enabled) +{ + const GLint gstack = debug->CurrentGroup; + struct gl_debug_namespace *ns; + + debug_make_group_writable(debug); + ns = &debug->Groups[gstack]->Namespaces[source][type]; + + debug_namespace_set(ns, id, enabled); +} + +/* + * Set the state of all message IDs found in the given intersection of + * 'source', 'type', and 'severity'. The _COUNT enum can be used for + * GL_DONT_CARE (include all messages in the class). + * + * This requires both setting the state of all previously seen message + * IDs in the hash table, and setting the default state for all + * applicable combinations of source/type/severity, so that all the + * yet-unknown message IDs that may be used in the future will be + * impacted as if they were already known. + */ +static void +debug_set_message_enable_all(struct gl_debug_state *debug, + enum mesa_debug_source source, + enum mesa_debug_type type, + enum mesa_debug_severity severity, + GLboolean enabled) +{ + const GLint gstack = debug->CurrentGroup; + int s, t, smax, tmax; + + if (source == MESA_DEBUG_SOURCE_COUNT) { + source = 0; + smax = MESA_DEBUG_SOURCE_COUNT; + } else { + smax = source+1; + } + + if (type == MESA_DEBUG_TYPE_COUNT) { + type = 0; + tmax = MESA_DEBUG_TYPE_COUNT; + } else { + tmax = type+1; + } + + debug_make_group_writable(debug); + + for (s = source; s < smax; s++) { + for (t = type; t < tmax; t++) { + struct gl_debug_namespace *nspace = + &debug->Groups[gstack]->Namespaces[s][t]; + debug_namespace_set_all(nspace, severity, enabled); + } + } +} + +/** + * Returns if the given message source/type/ID tuple is enabled. + */ +bool +_mesa_debug_is_message_enabled(const struct gl_debug_state *debug, + enum mesa_debug_source source, + enum mesa_debug_type type, + GLuint id, + enum mesa_debug_severity severity) +{ + const GLint gstack = debug->CurrentGroup; + struct gl_debug_group *grp = debug->Groups[gstack]; + struct gl_debug_namespace *nspace = &grp->Namespaces[source][type]; + + if (!debug->DebugOutput) + return false; + + return debug_namespace_get(nspace, id, severity); +} + +/** + * 'buf' is not necessarily a null-terminated string. When logging, copy + * 'len' characters from it, store them in a new, null-terminated string, + * and remember the number of bytes used by that string, *including* + * the null terminator this time. + */ +static void +debug_log_message(struct gl_debug_state *debug, + enum mesa_debug_source source, + enum mesa_debug_type type, GLuint id, + enum mesa_debug_severity severity, + GLsizei len, const char *buf) +{ + struct gl_debug_log *log = &debug->Log; + GLint nextEmpty; + struct gl_debug_message *emptySlot; + + assert(len < MAX_DEBUG_MESSAGE_LENGTH); + + if (log->NumMessages == MAX_DEBUG_LOGGED_MESSAGES) + return; + + nextEmpty = (log->NextMessage + log->NumMessages) + % MAX_DEBUG_LOGGED_MESSAGES; + emptySlot = &log->Messages[nextEmpty]; + + debug_message_store(emptySlot, source, type, + id, severity, len, buf); + + log->NumMessages++; +} + +/** + * Return the oldest debug message out of the log. + */ +static const struct gl_debug_message * +debug_fetch_message(const struct gl_debug_state *debug) +{ + const struct gl_debug_log *log = &debug->Log; + + return (log->NumMessages) ? &log->Messages[log->NextMessage] : NULL; +} + +/** + * Delete the oldest debug messages out of the log. + */ +static void +debug_delete_messages(struct gl_debug_state *debug, int count) +{ + struct gl_debug_log *log = &debug->Log; + + if (count > log->NumMessages) + count = log->NumMessages; + + while (count--) { + struct gl_debug_message *msg = &log->Messages[log->NextMessage]; + + debug_message_clear(msg); + + log->NumMessages--; + log->NextMessage++; + log->NextMessage %= MAX_DEBUG_LOGGED_MESSAGES; + } +} + +static struct gl_debug_message * +debug_get_group_message(struct gl_debug_state *debug) +{ + return &debug->GroupMessages[debug->CurrentGroup]; +} + +static void +debug_push_group(struct gl_debug_state *debug) +{ + const GLint gstack = debug->CurrentGroup; + + /* just point to the previous stack */ + debug->Groups[gstack + 1] = debug->Groups[gstack]; + debug->CurrentGroup++; +} + +static void +debug_pop_group(struct gl_debug_state *debug) +{ + debug_clear_group(debug); + debug->CurrentGroup--; +} + + +/** + * Lock and return debug state for the context. The debug state will be + * allocated and initialized upon the first call. When NULL is returned, the + * debug state is not locked. + */ +static struct gl_debug_state * +_mesa_lock_debug_state(struct gl_context *ctx) +{ + mtx_lock(&ctx->DebugMutex); + + if (!ctx->Debug) { + ctx->Debug = debug_create(); + if (!ctx->Debug) { + GET_CURRENT_CONTEXT(cur); + mtx_unlock(&ctx->DebugMutex); + + /* + * This function may be called from other threads. When that is the + * case, we cannot record this OOM error. + */ + if (ctx == cur) + _mesa_error(ctx, GL_OUT_OF_MEMORY, "allocating debug state"); + + return NULL; + } + } + + return ctx->Debug; +} + +static void +_mesa_unlock_debug_state(struct gl_context *ctx) +{ + mtx_unlock(&ctx->DebugMutex); +} + +/** + * Set the integer debug state specified by \p pname. This can be called from + * _mesa_set_enable for example. + */ +bool +_mesa_set_debug_state_int(struct gl_context *ctx, GLenum pname, GLint val) +{ + struct gl_debug_state *debug = _mesa_lock_debug_state(ctx); + + if (!debug) + return false; + + switch (pname) { + case GL_DEBUG_OUTPUT: + debug->DebugOutput = (val != 0); + break; + case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB: + debug->SyncOutput = (val != 0); + break; + default: + assert(!"unknown debug output param"); + break; + } + + _mesa_unlock_debug_state(ctx); + + return true; +} + +/** + * Query the integer debug state specified by \p pname. This can be called + * _mesa_GetIntegerv for example. + */ +GLint +_mesa_get_debug_state_int(struct gl_context *ctx, GLenum pname) +{ + struct gl_debug_state *debug; + GLint val; + + mtx_lock(&ctx->DebugMutex); + debug = ctx->Debug; + if (!debug) { + mtx_unlock(&ctx->DebugMutex); + return 0; + } + + switch (pname) { + case GL_DEBUG_OUTPUT: + val = debug->DebugOutput; + break; + case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB: + val = debug->SyncOutput; + break; + case GL_DEBUG_LOGGED_MESSAGES: + val = debug->Log.NumMessages; + break; + case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH: + val = (debug->Log.NumMessages) ? + debug->Log.Messages[debug->Log.NextMessage].length : 0; + break; + case GL_DEBUG_GROUP_STACK_DEPTH: + val = debug->CurrentGroup + 1; + break; + default: + assert(!"unknown debug output param"); + val = 0; + break; + } + + mtx_unlock(&ctx->DebugMutex); + + return val; +} + +/** + * Query the pointer debug state specified by \p pname. This can be called + * _mesa_GetPointerv for example. + */ +void * +_mesa_get_debug_state_ptr(struct gl_context *ctx, GLenum pname) +{ + struct gl_debug_state *debug; + void *val; + + mtx_lock(&ctx->DebugMutex); + debug = ctx->Debug; + if (!debug) { + mtx_unlock(&ctx->DebugMutex); + return NULL; + } + + switch (pname) { + case GL_DEBUG_CALLBACK_FUNCTION_ARB: + val = (void *) debug->Callback; + break; + case GL_DEBUG_CALLBACK_USER_PARAM_ARB: + val = (void *) debug->CallbackData; + break; + default: + assert(!"unknown debug output param"); + val = NULL; + break; + } + + mtx_unlock(&ctx->DebugMutex); + + return val; +} + +/** + * Insert a debug message. The mutex is assumed to be locked, and will be + * unlocked by this call. + */ +static void +log_msg_locked_and_unlock(struct gl_context *ctx, + enum mesa_debug_source source, + enum mesa_debug_type type, GLuint id, + enum mesa_debug_severity severity, + GLint len, const char *buf) +{ + struct gl_debug_state *debug = ctx->Debug; + + if (!_mesa_debug_is_message_enabled(debug, source, type, id, severity)) { + _mesa_unlock_debug_state(ctx); + return; + } + + if (ctx->Debug->Callback) { + GLenum gl_source = debug_source_enums[source]; + GLenum gl_type = debug_type_enums[type]; + GLenum gl_severity = debug_severity_enums[severity]; + GLDEBUGPROC callback = ctx->Debug->Callback; + const void *data = ctx->Debug->CallbackData; + + /* + * When ctx->Debug->SyncOutput is GL_FALSE, the client is prepared for + * unsynchronous calls. When it is GL_TRUE, we will not spawn threads. + * In either case, we can call the callback unlocked. + */ + _mesa_unlock_debug_state(ctx); + callback(gl_source, gl_type, id, gl_severity, len, buf, data); + } + else { + debug_log_message(ctx->Debug, source, type, id, severity, len, buf); + _mesa_unlock_debug_state(ctx); + } +} + +/** + * Log a client or driver debug message. + */ +void +_mesa_log_msg(struct gl_context *ctx, enum mesa_debug_source source, + enum mesa_debug_type type, GLuint id, + enum mesa_debug_severity severity, GLint len, const char *buf) +{ + struct gl_debug_state *debug = _mesa_lock_debug_state(ctx); + + if (!debug) + return; + + log_msg_locked_and_unlock(ctx, source, type, id, severity, len, buf); +} + + +/** + * Verify that source, type, and severity are valid enums. + * + * The 'caller' param is used for handling values available + * only in glDebugMessageInsert or glDebugMessageControl + */ +static GLboolean +validate_params(struct gl_context *ctx, unsigned caller, + const char *callerstr, GLenum source, GLenum type, + GLenum severity) +{ +#define INSERT 1 +#define CONTROL 2 + switch(source) { + case GL_DEBUG_SOURCE_APPLICATION_ARB: + case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: + break; + case GL_DEBUG_SOURCE_API_ARB: + case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: + case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: + case GL_DEBUG_SOURCE_OTHER_ARB: + if (caller != INSERT) + break; + else + goto error; + case GL_DONT_CARE: + if (caller == CONTROL) + break; + else + goto error; + default: + goto error; + } + + switch(type) { + case GL_DEBUG_TYPE_ERROR_ARB: + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: + case GL_DEBUG_TYPE_PERFORMANCE_ARB: + case GL_DEBUG_TYPE_PORTABILITY_ARB: + case GL_DEBUG_TYPE_OTHER_ARB: + case GL_DEBUG_TYPE_MARKER: + case GL_DEBUG_TYPE_PUSH_GROUP: + case GL_DEBUG_TYPE_POP_GROUP: + break; + case GL_DONT_CARE: + if (caller == CONTROL) + break; + else + goto error; + default: + goto error; + } + + switch(severity) { + case GL_DEBUG_SEVERITY_HIGH_ARB: + case GL_DEBUG_SEVERITY_MEDIUM_ARB: + case GL_DEBUG_SEVERITY_LOW_ARB: + case GL_DEBUG_SEVERITY_NOTIFICATION: + break; + case GL_DONT_CARE: + if (caller == CONTROL) + break; + else + goto error; + default: + goto error; + } + return GL_TRUE; + +error: + _mesa_error(ctx, GL_INVALID_ENUM, "bad values passed to %s" + "(source=0x%x, type=0x%x, severity=0x%x)", callerstr, + source, type, severity); + + return GL_FALSE; +} + + +static GLboolean +validate_length(struct gl_context *ctx, const char *callerstr, GLsizei length, + const GLchar *buf) +{ + + if (length < 0) { + GLsizei len = strlen(buf); + + if (len >= MAX_DEBUG_MESSAGE_LENGTH) { + _mesa_error(ctx, GL_INVALID_VALUE, + "%s(null terminated string length=%d, is not less than " + "GL_MAX_DEBUG_MESSAGE_LENGTH=%d)", callerstr, len, + MAX_DEBUG_MESSAGE_LENGTH); + return GL_FALSE; + } + } + + if (length >= MAX_DEBUG_MESSAGE_LENGTH) { + _mesa_error(ctx, GL_INVALID_VALUE, + "%s(length=%d, which is not less than " + "GL_MAX_DEBUG_MESSAGE_LENGTH=%d)", callerstr, length, + MAX_DEBUG_MESSAGE_LENGTH); + return GL_FALSE; + } + + return GL_TRUE; +} + + +void GLAPIENTRY +_mesa_DebugMessageInsert(GLenum source, GLenum type, GLuint id, + GLenum severity, GLint length, + const GLchar *buf) +{ + GET_CURRENT_CONTEXT(ctx); + const char *callerstr; + + if (_mesa_is_desktop_gl(ctx)) + callerstr = "glDebugMessageInsert"; + else + callerstr = "glDebugMessageInsertKHR"; + + if (!validate_params(ctx, INSERT, callerstr, source, type, severity)) + return; /* GL_INVALID_ENUM */ + + if (!validate_length(ctx, callerstr, length, buf)) + return; /* GL_INVALID_VALUE */ + + _mesa_log_msg(ctx, gl_enum_to_debug_source(source), + gl_enum_to_debug_type(type), id, + gl_enum_to_debug_severity(severity), + length, buf); + + if (type == GL_DEBUG_TYPE_MARKER && ctx->Driver.EmitStringMarker) { + /* if length not specified, string will be null terminated: */ + if (length < 0) + length = strlen(buf); + ctx->Driver.EmitStringMarker(ctx, buf, length); + } +} + + +GLuint GLAPIENTRY +_mesa_GetDebugMessageLog(GLuint count, GLsizei logSize, GLenum *sources, + GLenum *types, GLenum *ids, GLenum *severities, + GLsizei *lengths, GLchar *messageLog) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_debug_state *debug; + const char *callerstr; + GLuint ret; + + if (_mesa_is_desktop_gl(ctx)) + callerstr = "glGetDebugMessageLog"; + else + callerstr = "glGetDebugMessageLogKHR"; + + if (!messageLog) + logSize = 0; + + if (logSize < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, + "%s(logSize=%d : logSize must not be negative)", + callerstr, logSize); + return 0; + } + + debug = _mesa_lock_debug_state(ctx); + if (!debug) + return 0; + + for (ret = 0; ret < count; ret++) { + const struct gl_debug_message *msg = debug_fetch_message(debug); + GLsizei len; + + if (!msg) + break; + + len = msg->length; + if (len < 0) + len = strlen(msg->message); + + if (logSize < len+1 && messageLog != NULL) + break; + + if (messageLog) { + assert(msg->message[len] == '\0'); + (void) strncpy(messageLog, msg->message, (size_t)len+1); + + messageLog += len+1; + logSize -= len+1; + } + + if (lengths) + *lengths++ = len+1; + if (severities) + *severities++ = debug_severity_enums[msg->severity]; + if (sources) + *sources++ = debug_source_enums[msg->source]; + if (types) + *types++ = debug_type_enums[msg->type]; + if (ids) + *ids++ = msg->id; + + debug_delete_messages(debug, 1); + } + + _mesa_unlock_debug_state(ctx); + + return ret; +} + + +void GLAPIENTRY +_mesa_DebugMessageControl(GLenum gl_source, GLenum gl_type, + GLenum gl_severity, GLsizei count, + const GLuint *ids, GLboolean enabled) +{ + GET_CURRENT_CONTEXT(ctx); + enum mesa_debug_source source = gl_enum_to_debug_source(gl_source); + enum mesa_debug_type type = gl_enum_to_debug_type(gl_type); + enum mesa_debug_severity severity = gl_enum_to_debug_severity(gl_severity); + const char *callerstr; + struct gl_debug_state *debug; + + if (_mesa_is_desktop_gl(ctx)) + callerstr = "glDebugMessageControl"; + else + callerstr = "glDebugMessageControlKHR"; + + if (count < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, + "%s(count=%d : count must not be negative)", callerstr, + count); + return; + } + + if (!validate_params(ctx, CONTROL, callerstr, gl_source, gl_type, + gl_severity)) + return; /* GL_INVALID_ENUM */ + + if (count && (gl_severity != GL_DONT_CARE || gl_type == GL_DONT_CARE + || gl_source == GL_DONT_CARE)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(When passing an array of ids, severity must be" + " GL_DONT_CARE, and source and type must not be GL_DONT_CARE.", + callerstr); + return; + } + + debug = _mesa_lock_debug_state(ctx); + if (!debug) + return; + + if (count) { + GLsizei i; + for (i = 0; i < count; i++) + debug_set_message_enable(debug, source, type, ids[i], enabled); + } + else { + debug_set_message_enable_all(debug, source, type, severity, enabled); + } + + _mesa_unlock_debug_state(ctx); +} + + +void GLAPIENTRY +_mesa_DebugMessageCallback(GLDEBUGPROC callback, const void *userParam) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_debug_state *debug = _mesa_lock_debug_state(ctx); + if (debug) { + debug->Callback = callback; + debug->CallbackData = userParam; + _mesa_unlock_debug_state(ctx); + } +} + + +void GLAPIENTRY +_mesa_PushDebugGroup(GLenum source, GLuint id, GLsizei length, + const GLchar *message) +{ + GET_CURRENT_CONTEXT(ctx); + const char *callerstr; + struct gl_debug_state *debug; + struct gl_debug_message *emptySlot; + + if (_mesa_is_desktop_gl(ctx)) + callerstr = "glPushDebugGroup"; + else + callerstr = "glPushDebugGroupKHR"; + + switch(source) { + case GL_DEBUG_SOURCE_APPLICATION: + case GL_DEBUG_SOURCE_THIRD_PARTY: + break; + default: + _mesa_error(ctx, GL_INVALID_ENUM, "bad value passed to %s" + "(source=0x%x)", callerstr, source); + return; + } + + if (!validate_length(ctx, callerstr, length, message)) + return; /* GL_INVALID_VALUE */ + + debug = _mesa_lock_debug_state(ctx); + if (!debug) + return; + + if (debug->CurrentGroup >= MAX_DEBUG_GROUP_STACK_DEPTH-1) { + _mesa_unlock_debug_state(ctx); + _mesa_error(ctx, GL_STACK_OVERFLOW, "%s", callerstr); + return; + } + + /* pop reuses the message details from push so we store this */ + emptySlot = debug_get_group_message(debug); + debug_message_store(emptySlot, + gl_enum_to_debug_source(source), + gl_enum_to_debug_type(GL_DEBUG_TYPE_PUSH_GROUP), + id, + gl_enum_to_debug_severity(GL_DEBUG_SEVERITY_NOTIFICATION), + length, message); + + debug_push_group(debug); + + log_msg_locked_and_unlock(ctx, + gl_enum_to_debug_source(source), + MESA_DEBUG_TYPE_PUSH_GROUP, id, + MESA_DEBUG_SEVERITY_NOTIFICATION, length, + message); +} + + +void GLAPIENTRY +_mesa_PopDebugGroup(void) +{ + GET_CURRENT_CONTEXT(ctx); + const char *callerstr; + struct gl_debug_state *debug; + struct gl_debug_message *gdmessage, msg; + + if (_mesa_is_desktop_gl(ctx)) + callerstr = "glPopDebugGroup"; + else + callerstr = "glPopDebugGroupKHR"; + + debug = _mesa_lock_debug_state(ctx); + if (!debug) + return; + + if (debug->CurrentGroup <= 0) { + _mesa_unlock_debug_state(ctx); + _mesa_error(ctx, GL_STACK_UNDERFLOW, "%s", callerstr); + return; + } + + debug_pop_group(debug); + + /* make a shallow copy */ + gdmessage = debug_get_group_message(debug); + msg = *gdmessage; + gdmessage->message = NULL; + gdmessage->length = 0; + + log_msg_locked_and_unlock(ctx, + msg.source, + gl_enum_to_debug_type(GL_DEBUG_TYPE_POP_GROUP), + msg.id, + gl_enum_to_debug_severity(GL_DEBUG_SEVERITY_NOTIFICATION), + msg.length, msg.message); + + debug_message_clear(&msg); +} + + +void +_mesa_init_debug_output(struct gl_context *ctx) +{ + mtx_init(&ctx->DebugMutex, mtx_plain); +} + + +void +_mesa_free_errors_data(struct gl_context *ctx) +{ + if (ctx->Debug) { + debug_destroy(ctx->Debug); + /* set to NULL just in case it is used before context is completely gone. */ + ctx->Debug = NULL; + } + + mtx_destroy(&ctx->DebugMutex); +} + +void GLAPIENTRY +_mesa_StringMarkerGREMEDY(GLsizei len, const GLvoid *string) +{ + GET_CURRENT_CONTEXT(ctx); + if (ctx->Extensions.GREMEDY_string_marker) { + /* if length not specified, string will be null terminated: */ + if (len <= 0) + len = strlen(string); + ctx->Driver.EmitStringMarker(ctx, string, len); + } else { + _mesa_error(ctx, GL_INVALID_OPERATION, "StringMarkerGREMEDY"); + } +} diff --git a/src/mesa/main/debug_output.h b/src/mesa/main/debug_output.h new file mode 100644 index 00000000000..9d8be4f2273 --- /dev/null +++ b/src/mesa/main/debug_output.h @@ -0,0 +1,107 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999-2016 Brian Paul, et al All Rights Reserved. + * + * 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 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. + */ + + +#ifndef DEBUG_OUTPUT_H +#define DEBUG_OUTPUT_H + + +#include <stdio.h> +#include <stdarg.h> +#include "compiler.h" +#include "glheader.h" +#include "mtypes.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +void +_mesa_init_debug_output(struct gl_context *ctx); + +void +_mesa_free_errors_data(struct gl_context *ctx); + +void +_mesa_debug_get_id(GLuint *id); + +bool +_mesa_set_debug_state_int(struct gl_context *ctx, GLenum pname, GLint val); + +GLint +_mesa_get_debug_state_int(struct gl_context *ctx, GLenum pname); + +void * +_mesa_get_debug_state_ptr(struct gl_context *ctx, GLenum pname); + +void +_mesa_log_msg(struct gl_context *ctx, enum mesa_debug_source source, + enum mesa_debug_type type, GLuint id, + enum mesa_debug_severity severity, GLint len, const char *buf); + +bool +_mesa_debug_is_message_enabled(const struct gl_debug_state *debug, + enum mesa_debug_source source, + enum mesa_debug_type type, + GLuint id, + enum mesa_debug_severity severity); + +void GLAPIENTRY +_mesa_DebugMessageInsert(GLenum source, GLenum type, GLuint id, + GLenum severity, GLint length, + const GLchar* buf); + +GLuint GLAPIENTRY +_mesa_GetDebugMessageLog(GLuint count, GLsizei logSize, GLenum* sources, + GLenum* types, GLenum* ids, GLenum* severities, + GLsizei* lengths, GLchar* messageLog); + +void GLAPIENTRY +_mesa_DebugMessageControl(GLenum source, GLenum type, GLenum severity, + GLsizei count, const GLuint *ids, + GLboolean enabled); + +void GLAPIENTRY +_mesa_DebugMessageCallback(GLDEBUGPROC callback, + const void *userParam); + +void GLAPIENTRY +_mesa_PushDebugGroup(GLenum source, GLuint id, GLsizei length, + const GLchar *message); + +void GLAPIENTRY +_mesa_PopDebugGroup(void); + +void GLAPIENTRY +_mesa_StringMarkerGREMEDY(GLsizei len, const GLvoid *string); + + +#ifdef __cplusplus +} +#endif + + +#endif /* DEBUG_OUTPUT_H */ diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index cd8e3b6a2f2..fb31d2f2706 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -194,7 +194,7 @@ typedef enum OPCODE_BLEND_FUNC_SEPARATE_I, OPCODE_CALL_LIST, - OPCODE_CALL_LIST_OFFSET, + OPCODE_CALL_LISTS, OPCODE_CLEAR, OPCODE_CLEAR_ACCUM, OPCODE_CLEAR_COLOR, @@ -706,6 +706,10 @@ _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist) free(get_pointer(&n[10])); n += InstSize[n[0].opcode]; break; + case OPCODE_CALL_LISTS: + free(get_pointer(&n[3])); + n += InstSize[n[0].opcode]; + break; case OPCODE_DRAW_PIXELS: free(get_pointer(&n[5])); n += InstSize[n[0].opcode]; @@ -1569,37 +1573,49 @@ static void GLAPIENTRY save_CallLists(GLsizei num, GLenum type, const GLvoid * lists) { GET_CURRENT_CONTEXT(ctx); - GLint i; - GLboolean typeErrorFlag; + unsigned type_size; + Node *n; + void *lists_copy; SAVE_FLUSH_VERTICES(ctx); switch (type) { case GL_BYTE: case GL_UNSIGNED_BYTE: + type_size = 1; + break; case GL_SHORT: case GL_UNSIGNED_SHORT: + case GL_2_BYTES: + type_size = 2; + break; + case GL_3_BYTES: + type_size = 3; + break; case GL_INT: case GL_UNSIGNED_INT: case GL_FLOAT: - case GL_2_BYTES: - case GL_3_BYTES: case GL_4_BYTES: - typeErrorFlag = GL_FALSE; + type_size = 4; break; default: - typeErrorFlag = GL_TRUE; + type_size = 0; } - for (i = 0; i < num; i++) { - GLint list = translate_id(i, type, lists); - Node *n = alloc_instruction(ctx, OPCODE_CALL_LIST_OFFSET, 2); - if (n) { - n[1].i = list; - n[2].b = typeErrorFlag; - } + if (num > 0 && type_size > 0) { + /* create a copy of the array of list IDs to save in the display list */ + lists_copy = memdup(lists, num * type_size); + } else { + lists_copy = NULL; } + n = alloc_instruction(ctx, OPCODE_CALL_LISTS, 2 + POINTER_DWORDS); + if (n) { + n[1].i = num; + n[2].e = type; + save_pointer(&n[3], lists_copy); + }; + /* After this, we don't know what state we're in. Invalidate all * cached information previously gathered: */ @@ -7772,15 +7788,9 @@ execute_list(struct gl_context *ctx, GLuint list) execute_list(ctx, n[1].ui); } break; - case OPCODE_CALL_LIST_OFFSET: - /* Generated by glCallLists() so we must add ListBase */ - if (n[2].b) { - /* user specified a bad data type at compile time */ - _mesa_error(ctx, GL_INVALID_ENUM, "glCallLists(type)"); - } - else if (ctx->ListState.CallDepth < MAX_LIST_NESTING) { - GLuint list = (GLuint) (ctx->List.ListBase + n[1].i); - execute_list(ctx, list); + case OPCODE_CALL_LISTS: + if (ctx->ListState.CallDepth < MAX_LIST_NESTING) { + CALL_CallLists(ctx->Exec, (n[1].i, n[2].e, get_pointer(&n[3]))); } break; case OPCODE_CLEAR: @@ -9105,6 +9115,14 @@ _mesa_CallLists(GLsizei n, GLenum type, const GLvoid * lists) return; } + if (n < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, "glCallLists(n < 0)"); + return; + } else if (n == 0 || lists == NULL) { + /* nothing to do */ + return; + } + /* Save the CompileFlag status, turn it off, execute display list, * and restore the CompileFlag. */ @@ -9728,9 +9746,8 @@ print_list(struct gl_context *ctx, GLuint list, const char *fname) case OPCODE_CALL_LIST: fprintf(f, "CallList %d\n", (int) n[1].ui); break; - case OPCODE_CALL_LIST_OFFSET: - fprintf(f, "CallList %d + offset %u = %u\n", (int) n[1].ui, - ctx->List.ListBase, ctx->List.ListBase + n[1].ui); + case OPCODE_CALL_LISTS: + fprintf(f, "CallLists %d, %s\n", n[1].i, enum_string(n[1].e)); break; case OPCODE_DISABLE: fprintf(f, "Disable %s\n", enum_string(n[1].e)); diff --git a/src/mesa/main/dlist.h b/src/mesa/main/dlist.h index a1214674c62..7a23208ba5a 100644 --- a/src/mesa/main/dlist.h +++ b/src/mesa/main/dlist.h @@ -38,46 +38,61 @@ GLboolean GLAPIENTRY _mesa_IsList(GLuint list); + void GLAPIENTRY _mesa_DeleteLists(GLuint list, GLsizei range); + GLuint GLAPIENTRY _mesa_GenLists(GLsizei range); + void GLAPIENTRY _mesa_NewList(GLuint name, GLenum mode); + void GLAPIENTRY _mesa_EndList(void); + void GLAPIENTRY -_mesa_CallList( GLuint list ); +_mesa_CallList(GLuint list); + void GLAPIENTRY -_mesa_CallLists( GLsizei n, GLenum type, const GLvoid *lists ); +_mesa_CallLists(GLsizei n, GLenum type, const GLvoid *lists); + void GLAPIENTRY _mesa_ListBase(GLuint base); -extern struct gl_display_list * +struct gl_display_list * _mesa_lookup_list(struct gl_context *ctx, GLuint list); -extern void _mesa_compile_error( struct gl_context *ctx, GLenum error, const char *s ); +void +_mesa_compile_error(struct gl_context *ctx, GLenum error, const char *s); -extern void *_mesa_dlist_alloc(struct gl_context *ctx, GLuint opcode, GLuint sz); +void * +_mesa_dlist_alloc(struct gl_context *ctx, GLuint opcode, GLuint sz); -extern void * +void * _mesa_dlist_alloc_aligned(struct gl_context *ctx, GLuint opcode, GLuint bytes); -extern GLint _mesa_dlist_alloc_opcode( struct gl_context *ctx, GLuint sz, - void (*execute)( struct gl_context *, void * ), - void (*destroy)( struct gl_context *, void * ), - void (*print)( struct gl_context *, void *, FILE * ) ); +GLint +_mesa_dlist_alloc_opcode(struct gl_context *ctx, GLuint sz, + void (*execute)(struct gl_context *, void *), + void (*destroy)(struct gl_context *, void *), + void (*print)(struct gl_context *, void *, FILE *)); -extern void _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist); +void +_mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist); -extern void _mesa_initialize_save_table(const struct gl_context *); +void +_mesa_initialize_save_table(const struct gl_context *); -extern void _mesa_install_dlist_vtxfmt(struct _glapi_table *disp, - const GLvertexformat *vfmt); +void +_mesa_install_dlist_vtxfmt(struct _glapi_table *disp, + const GLvertexformat *vfmt); -extern void _mesa_init_display_list( struct gl_context * ctx ); +void +_mesa_init_display_list(struct gl_context * ctx); -extern void _mesa_free_display_list_data(struct gl_context *ctx); +void +_mesa_free_display_list_data(struct gl_context *ctx); #endif /* DLIST_H */ diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index f7941817845..3fd3c2747ea 100644 --- a/src/mesa/main/enable.c +++ b/src/mesa/main/enable.c @@ -31,6 +31,7 @@ #include "glheader.h" #include "clip.h" #include "context.h" +#include "debug_output.h" #include "enable.h" #include "errors.h" #include "light.h" diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c index 674364c7b0c..9932b4a5a89 100644 --- a/src/mesa/main/errors.c +++ b/src/mesa/main/errors.c @@ -34,6 +34,7 @@ #include "enums.h" #include "imports.h" #include "context.h" +#include "debug_output.h" #include "dispatch.h" #include "hash.h" #include "mtypes.h" @@ -41,1265 +42,6 @@ #include "util/hash_table.h" #include "util/simple_list.h" -static mtx_t DynamicIDMutex = _MTX_INITIALIZER_NP; -static GLuint NextDynamicID = 1; - -/** - * A namespace element. - */ -struct gl_debug_element -{ - struct simple_node link; - - GLuint ID; - /* at which severity levels (mesa_debug_severity) is the message enabled */ - GLbitfield State; -}; - -struct gl_debug_namespace -{ - struct simple_node Elements; - GLbitfield DefaultState; -}; - -struct gl_debug_group { - struct gl_debug_namespace Namespaces[MESA_DEBUG_SOURCE_COUNT][MESA_DEBUG_TYPE_COUNT]; -}; - -/** - * An error, warning, or other piece of debug information for an application - * to consume via GL_ARB_debug_output/GL_KHR_debug. - */ -struct gl_debug_message -{ - enum mesa_debug_source source; - enum mesa_debug_type type; - GLuint id; - enum mesa_debug_severity severity; - /* length as given by the user - if message was explicitly null terminated, - * length can be negative */ - GLsizei length; - GLcharARB *message; -}; - -/** - * Debug message log. It works like a ring buffer. - */ -struct gl_debug_log { - struct gl_debug_message Messages[MAX_DEBUG_LOGGED_MESSAGES]; - GLint NextMessage; - GLint NumMessages; -}; - -struct gl_debug_state -{ - GLDEBUGPROC Callback; - const void *CallbackData; - GLboolean SyncOutput; - GLboolean DebugOutput; - - struct gl_debug_group *Groups[MAX_DEBUG_GROUP_STACK_DEPTH]; - struct gl_debug_message GroupMessages[MAX_DEBUG_GROUP_STACK_DEPTH]; - GLint CurrentGroup; // GroupStackDepth - 1 - - struct gl_debug_log Log; -}; - -static char out_of_memory[] = "Debugging error: out of memory"; - -static const GLenum debug_source_enums[] = { - GL_DEBUG_SOURCE_API, - GL_DEBUG_SOURCE_WINDOW_SYSTEM, - GL_DEBUG_SOURCE_SHADER_COMPILER, - GL_DEBUG_SOURCE_THIRD_PARTY, - GL_DEBUG_SOURCE_APPLICATION, - GL_DEBUG_SOURCE_OTHER, -}; - -static const GLenum debug_type_enums[] = { - GL_DEBUG_TYPE_ERROR, - GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, - GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR, - GL_DEBUG_TYPE_PORTABILITY, - GL_DEBUG_TYPE_PERFORMANCE, - GL_DEBUG_TYPE_OTHER, - GL_DEBUG_TYPE_MARKER, - GL_DEBUG_TYPE_PUSH_GROUP, - GL_DEBUG_TYPE_POP_GROUP, -}; - -static const GLenum debug_severity_enums[] = { - GL_DEBUG_SEVERITY_LOW, - GL_DEBUG_SEVERITY_MEDIUM, - GL_DEBUG_SEVERITY_HIGH, - GL_DEBUG_SEVERITY_NOTIFICATION, -}; - - -static enum mesa_debug_source -gl_enum_to_debug_source(GLenum e) -{ - unsigned i; - - for (i = 0; i < ARRAY_SIZE(debug_source_enums); i++) { - if (debug_source_enums[i] == e) - break; - } - return i; -} - -static enum mesa_debug_type -gl_enum_to_debug_type(GLenum e) -{ - unsigned i; - - for (i = 0; i < ARRAY_SIZE(debug_type_enums); i++) { - if (debug_type_enums[i] == e) - break; - } - return i; -} - -static enum mesa_debug_severity -gl_enum_to_debug_severity(GLenum e) -{ - unsigned i; - - for (i = 0; i < ARRAY_SIZE(debug_severity_enums); i++) { - if (debug_severity_enums[i] == e) - break; - } - return i; -} - - -/** - * Handles generating a GL_ARB_debug_output message ID generated by the GL or - * GLSL compiler. - * - * The GL API has this "ID" mechanism, where the intention is to allow a - * client to filter in/out messages based on source, type, and ID. Of course, - * building a giant enum list of all debug output messages that Mesa might - * generate is ridiculous, so instead we have our caller pass us a pointer to - * static storage where the ID should get stored. This ID will be shared - * across all contexts for that message (which seems like a desirable - * property, even if it's not expected by the spec), but note that it won't be - * the same between executions if messages aren't generated in the same order. - */ -static void -debug_get_id(GLuint *id) -{ - if (!(*id)) { - mtx_lock(&DynamicIDMutex); - if (!(*id)) - *id = NextDynamicID++; - mtx_unlock(&DynamicIDMutex); - } -} - -static void -debug_message_clear(struct gl_debug_message *msg) -{ - if (msg->message != (char*)out_of_memory) - free(msg->message); - msg->message = NULL; - msg->length = 0; -} - -static void -debug_message_store(struct gl_debug_message *msg, - enum mesa_debug_source source, - enum mesa_debug_type type, GLuint id, - enum mesa_debug_severity severity, - GLsizei len, const char *buf) -{ - GLsizei length = len; - - assert(!msg->message && !msg->length); - - if (length < 0) - length = strlen(buf); - - msg->message = malloc(length+1); - if (msg->message) { - (void) strncpy(msg->message, buf, (size_t)length); - msg->message[length] = '\0'; - - msg->length = len; - msg->source = source; - msg->type = type; - msg->id = id; - msg->severity = severity; - } else { - static GLuint oom_msg_id = 0; - debug_get_id(&oom_msg_id); - - /* malloc failed! */ - msg->message = out_of_memory; - msg->length = -1; - msg->source = MESA_DEBUG_SOURCE_OTHER; - msg->type = MESA_DEBUG_TYPE_ERROR; - msg->id = oom_msg_id; - msg->severity = MESA_DEBUG_SEVERITY_HIGH; - } -} - -static void -debug_namespace_init(struct gl_debug_namespace *ns) -{ - make_empty_list(&ns->Elements); - - /* Enable all the messages with severity HIGH or MEDIUM by default */ - ns->DefaultState = (1 << MESA_DEBUG_SEVERITY_MEDIUM ) | - (1 << MESA_DEBUG_SEVERITY_HIGH) | - (1 << MESA_DEBUG_SEVERITY_NOTIFICATION); -} - -static void -debug_namespace_clear(struct gl_debug_namespace *ns) -{ - struct simple_node *node, *tmp; - - foreach_s(node, tmp, &ns->Elements) - free(node); -} - -static bool -debug_namespace_copy(struct gl_debug_namespace *dst, - const struct gl_debug_namespace *src) -{ - struct simple_node *node; - - dst->DefaultState = src->DefaultState; - - make_empty_list(&dst->Elements); - foreach(node, &src->Elements) { - const struct gl_debug_element *elem = - (const struct gl_debug_element *) node; - struct gl_debug_element *copy; - - copy = malloc(sizeof(*copy)); - if (!copy) { - debug_namespace_clear(dst); - return false; - } - - copy->ID = elem->ID; - copy->State = elem->State; - insert_at_tail(&dst->Elements, ©->link); - } - - return true; -} - -/** - * Set the state of \p id in the namespace. - */ -static bool -debug_namespace_set(struct gl_debug_namespace *ns, - GLuint id, bool enabled) -{ - const uint32_t state = (enabled) ? - ((1 << MESA_DEBUG_SEVERITY_COUNT) - 1) : 0; - struct gl_debug_element *elem = NULL; - struct simple_node *node; - - /* find the element */ - foreach(node, &ns->Elements) { - struct gl_debug_element *tmp = (struct gl_debug_element *) node; - if (tmp->ID == id) { - elem = tmp; - break; - } - } - - /* we do not need the element if it has the default state */ - if (ns->DefaultState == state) { - if (elem) { - remove_from_list(&elem->link); - free(elem); - } - return true; - } - - if (!elem) { - elem = malloc(sizeof(*elem)); - if (!elem) - return false; - - elem->ID = id; - insert_at_tail(&ns->Elements, &elem->link); - } - - elem->State = state; - - return true; -} - -/** - * Set the default state of the namespace for \p severity. When \p severity - * is MESA_DEBUG_SEVERITY_COUNT, the default values for all severities are - * updated. - */ -static void -debug_namespace_set_all(struct gl_debug_namespace *ns, - enum mesa_debug_severity severity, - bool enabled) -{ - struct simple_node *node, *tmp; - uint32_t mask, val; - - /* set all elements to the same state */ - if (severity == MESA_DEBUG_SEVERITY_COUNT) { - ns->DefaultState = (enabled) ? ((1 << severity) - 1) : 0; - debug_namespace_clear(ns); - make_empty_list(&ns->Elements); - return; - } - - mask = 1 << severity; - val = (enabled) ? mask : 0; - - ns->DefaultState = (ns->DefaultState & ~mask) | val; - - foreach_s(node, tmp, &ns->Elements) { - struct gl_debug_element *elem = (struct gl_debug_element *) node; - - elem->State = (elem->State & ~mask) | val; - if (elem->State == ns->DefaultState) { - remove_from_list(node); - free(node); - } - } -} - -/** - * Get the state of \p id in the namespace. - */ -static bool -debug_namespace_get(const struct gl_debug_namespace *ns, GLuint id, - enum mesa_debug_severity severity) -{ - struct simple_node *node; - uint32_t state; - - state = ns->DefaultState; - foreach(node, &ns->Elements) { - struct gl_debug_element *elem = (struct gl_debug_element *) node; - - if (elem->ID == id) { - state = elem->State; - break; - } - } - - return (state & (1 << severity)); -} - -/** - * Allocate and initialize context debug state. - */ -static struct gl_debug_state * -debug_create(void) -{ - struct gl_debug_state *debug; - int s, t; - - debug = CALLOC_STRUCT(gl_debug_state); - if (!debug) - return NULL; - - debug->Groups[0] = malloc(sizeof(*debug->Groups[0])); - if (!debug->Groups[0]) { - free(debug); - return NULL; - } - - /* Initialize state for filtering known debug messages. */ - for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) { - for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) - debug_namespace_init(&debug->Groups[0]->Namespaces[s][t]); - } - - return debug; -} - -/** - * Return true if the top debug group points to the group below it. - */ -static bool -debug_is_group_read_only(const struct gl_debug_state *debug) -{ - const GLint gstack = debug->CurrentGroup; - return (gstack > 0 && debug->Groups[gstack] == debug->Groups[gstack - 1]); -} - -/** - * Make the top debug group writable. - */ -static bool -debug_make_group_writable(struct gl_debug_state *debug) -{ - const GLint gstack = debug->CurrentGroup; - const struct gl_debug_group *src = debug->Groups[gstack]; - struct gl_debug_group *dst; - int s, t; - - if (!debug_is_group_read_only(debug)) - return true; - - dst = malloc(sizeof(*dst)); - if (!dst) - return false; - - for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) { - for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) { - if (!debug_namespace_copy(&dst->Namespaces[s][t], - &src->Namespaces[s][t])) { - /* error path! */ - for (t = t - 1; t >= 0; t--) - debug_namespace_clear(&dst->Namespaces[s][t]); - for (s = s - 1; s >= 0; s--) { - for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) - debug_namespace_clear(&dst->Namespaces[s][t]); - } - free(dst); - return false; - } - } - } - - debug->Groups[gstack] = dst; - - return true; -} - -/** - * Free the top debug group. - */ -static void -debug_clear_group(struct gl_debug_state *debug) -{ - const GLint gstack = debug->CurrentGroup; - - if (!debug_is_group_read_only(debug)) { - struct gl_debug_group *grp = debug->Groups[gstack]; - int s, t; - - for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) { - for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) - debug_namespace_clear(&grp->Namespaces[s][t]); - } - - free(grp); - } - - debug->Groups[gstack] = NULL; -} - -/** - * Loop through debug group stack tearing down states for - * filtering debug messages. Then free debug output state. - */ -static void -debug_destroy(struct gl_debug_state *debug) -{ - while (debug->CurrentGroup > 0) { - debug_clear_group(debug); - debug->CurrentGroup--; - } - - debug_clear_group(debug); - free(debug); -} - -/** - * Sets the state of the given message source/type/ID tuple. - */ -static void -debug_set_message_enable(struct gl_debug_state *debug, - enum mesa_debug_source source, - enum mesa_debug_type type, - GLuint id, GLboolean enabled) -{ - const GLint gstack = debug->CurrentGroup; - struct gl_debug_namespace *ns; - - debug_make_group_writable(debug); - ns = &debug->Groups[gstack]->Namespaces[source][type]; - - debug_namespace_set(ns, id, enabled); -} - -/* - * Set the state of all message IDs found in the given intersection of - * 'source', 'type', and 'severity'. The _COUNT enum can be used for - * GL_DONT_CARE (include all messages in the class). - * - * This requires both setting the state of all previously seen message - * IDs in the hash table, and setting the default state for all - * applicable combinations of source/type/severity, so that all the - * yet-unknown message IDs that may be used in the future will be - * impacted as if they were already known. - */ -static void -debug_set_message_enable_all(struct gl_debug_state *debug, - enum mesa_debug_source source, - enum mesa_debug_type type, - enum mesa_debug_severity severity, - GLboolean enabled) -{ - const GLint gstack = debug->CurrentGroup; - int s, t, smax, tmax; - - if (source == MESA_DEBUG_SOURCE_COUNT) { - source = 0; - smax = MESA_DEBUG_SOURCE_COUNT; - } else { - smax = source+1; - } - - if (type == MESA_DEBUG_TYPE_COUNT) { - type = 0; - tmax = MESA_DEBUG_TYPE_COUNT; - } else { - tmax = type+1; - } - - debug_make_group_writable(debug); - - for (s = source; s < smax; s++) { - for (t = type; t < tmax; t++) { - struct gl_debug_namespace *nspace = - &debug->Groups[gstack]->Namespaces[s][t]; - debug_namespace_set_all(nspace, severity, enabled); - } - } -} - -/** - * Returns if the given message source/type/ID tuple is enabled. - */ -static bool -debug_is_message_enabled(const struct gl_debug_state *debug, - enum mesa_debug_source source, - enum mesa_debug_type type, - GLuint id, - enum mesa_debug_severity severity) -{ - const GLint gstack = debug->CurrentGroup; - struct gl_debug_group *grp = debug->Groups[gstack]; - struct gl_debug_namespace *nspace = &grp->Namespaces[source][type]; - - if (!debug->DebugOutput) - return false; - - return debug_namespace_get(nspace, id, severity); -} - -/** - * 'buf' is not necessarily a null-terminated string. When logging, copy - * 'len' characters from it, store them in a new, null-terminated string, - * and remember the number of bytes used by that string, *including* - * the null terminator this time. - */ -static void -debug_log_message(struct gl_debug_state *debug, - enum mesa_debug_source source, - enum mesa_debug_type type, GLuint id, - enum mesa_debug_severity severity, - GLsizei len, const char *buf) -{ - struct gl_debug_log *log = &debug->Log; - GLint nextEmpty; - struct gl_debug_message *emptySlot; - - assert(len < MAX_DEBUG_MESSAGE_LENGTH); - - if (log->NumMessages == MAX_DEBUG_LOGGED_MESSAGES) - return; - - nextEmpty = (log->NextMessage + log->NumMessages) - % MAX_DEBUG_LOGGED_MESSAGES; - emptySlot = &log->Messages[nextEmpty]; - - debug_message_store(emptySlot, source, type, - id, severity, len, buf); - - log->NumMessages++; -} - -/** - * Return the oldest debug message out of the log. - */ -static const struct gl_debug_message * -debug_fetch_message(const struct gl_debug_state *debug) -{ - const struct gl_debug_log *log = &debug->Log; - - return (log->NumMessages) ? &log->Messages[log->NextMessage] : NULL; -} - -/** - * Delete the oldest debug messages out of the log. - */ -static void -debug_delete_messages(struct gl_debug_state *debug, int count) -{ - struct gl_debug_log *log = &debug->Log; - - if (count > log->NumMessages) - count = log->NumMessages; - - while (count--) { - struct gl_debug_message *msg = &log->Messages[log->NextMessage]; - - debug_message_clear(msg); - - log->NumMessages--; - log->NextMessage++; - log->NextMessage %= MAX_DEBUG_LOGGED_MESSAGES; - } -} - -static struct gl_debug_message * -debug_get_group_message(struct gl_debug_state *debug) -{ - return &debug->GroupMessages[debug->CurrentGroup]; -} - -static void -debug_push_group(struct gl_debug_state *debug) -{ - const GLint gstack = debug->CurrentGroup; - - /* just point to the previous stack */ - debug->Groups[gstack + 1] = debug->Groups[gstack]; - debug->CurrentGroup++; -} - -static void -debug_pop_group(struct gl_debug_state *debug) -{ - debug_clear_group(debug); - debug->CurrentGroup--; -} - - -/** - * Lock and return debug state for the context. The debug state will be - * allocated and initialized upon the first call. When NULL is returned, the - * debug state is not locked. - */ -static struct gl_debug_state * -_mesa_lock_debug_state(struct gl_context *ctx) -{ - mtx_lock(&ctx->DebugMutex); - - if (!ctx->Debug) { - ctx->Debug = debug_create(); - if (!ctx->Debug) { - GET_CURRENT_CONTEXT(cur); - mtx_unlock(&ctx->DebugMutex); - - /* - * This function may be called from other threads. When that is the - * case, we cannot record this OOM error. - */ - if (ctx == cur) - _mesa_error(ctx, GL_OUT_OF_MEMORY, "allocating debug state"); - - return NULL; - } - } - - return ctx->Debug; -} - -static void -_mesa_unlock_debug_state(struct gl_context *ctx) -{ - mtx_unlock(&ctx->DebugMutex); -} - -/** - * Set the integer debug state specified by \p pname. This can be called from - * _mesa_set_enable for example. - */ -bool -_mesa_set_debug_state_int(struct gl_context *ctx, GLenum pname, GLint val) -{ - struct gl_debug_state *debug = _mesa_lock_debug_state(ctx); - - if (!debug) - return false; - - switch (pname) { - case GL_DEBUG_OUTPUT: - debug->DebugOutput = (val != 0); - break; - case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB: - debug->SyncOutput = (val != 0); - break; - default: - assert(!"unknown debug output param"); - break; - } - - _mesa_unlock_debug_state(ctx); - - return true; -} - -/** - * Query the integer debug state specified by \p pname. This can be called - * _mesa_GetIntegerv for example. - */ -GLint -_mesa_get_debug_state_int(struct gl_context *ctx, GLenum pname) -{ - struct gl_debug_state *debug; - GLint val; - - mtx_lock(&ctx->DebugMutex); - debug = ctx->Debug; - if (!debug) { - mtx_unlock(&ctx->DebugMutex); - return 0; - } - - switch (pname) { - case GL_DEBUG_OUTPUT: - val = debug->DebugOutput; - break; - case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB: - val = debug->SyncOutput; - break; - case GL_DEBUG_LOGGED_MESSAGES: - val = debug->Log.NumMessages; - break; - case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH: - val = (debug->Log.NumMessages) ? - debug->Log.Messages[debug->Log.NextMessage].length : 0; - break; - case GL_DEBUG_GROUP_STACK_DEPTH: - val = debug->CurrentGroup + 1; - break; - default: - assert(!"unknown debug output param"); - val = 0; - break; - } - - mtx_unlock(&ctx->DebugMutex); - - return val; -} - -/** - * Query the pointer debug state specified by \p pname. This can be called - * _mesa_GetPointerv for example. - */ -void * -_mesa_get_debug_state_ptr(struct gl_context *ctx, GLenum pname) -{ - struct gl_debug_state *debug; - void *val; - - mtx_lock(&ctx->DebugMutex); - debug = ctx->Debug; - if (!debug) { - mtx_unlock(&ctx->DebugMutex); - return NULL; - } - - switch (pname) { - case GL_DEBUG_CALLBACK_FUNCTION_ARB: - val = (void *) debug->Callback; - break; - case GL_DEBUG_CALLBACK_USER_PARAM_ARB: - val = (void *) debug->CallbackData; - break; - default: - assert(!"unknown debug output param"); - val = NULL; - break; - } - - mtx_unlock(&ctx->DebugMutex); - - return val; -} - -/** - * Insert a debug message. The mutex is assumed to be locked, and will be - * unlocked by this call. - */ -static void -log_msg_locked_and_unlock(struct gl_context *ctx, - enum mesa_debug_source source, - enum mesa_debug_type type, GLuint id, - enum mesa_debug_severity severity, - GLint len, const char *buf) -{ - struct gl_debug_state *debug = ctx->Debug; - - if (!debug_is_message_enabled(debug, source, type, id, severity)) { - _mesa_unlock_debug_state(ctx); - return; - } - - if (ctx->Debug->Callback) { - GLenum gl_source = debug_source_enums[source]; - GLenum gl_type = debug_type_enums[type]; - GLenum gl_severity = debug_severity_enums[severity]; - GLDEBUGPROC callback = ctx->Debug->Callback; - const void *data = ctx->Debug->CallbackData; - - /* - * When ctx->Debug->SyncOutput is GL_FALSE, the client is prepared for - * unsynchronous calls. When it is GL_TRUE, we will not spawn threads. - * In either case, we can call the callback unlocked. - */ - _mesa_unlock_debug_state(ctx); - callback(gl_source, gl_type, id, gl_severity, len, buf, data); - } - else { - debug_log_message(ctx->Debug, source, type, id, severity, len, buf); - _mesa_unlock_debug_state(ctx); - } -} - -/** - * Log a client or driver debug message. - */ -static void -log_msg(struct gl_context *ctx, enum mesa_debug_source source, - enum mesa_debug_type type, GLuint id, - enum mesa_debug_severity severity, GLint len, const char *buf) -{ - struct gl_debug_state *debug = _mesa_lock_debug_state(ctx); - - if (!debug) - return; - - log_msg_locked_and_unlock(ctx, source, type, id, severity, len, buf); -} - - -/** - * Verify that source, type, and severity are valid enums. - * - * The 'caller' param is used for handling values available - * only in glDebugMessageInsert or glDebugMessageControl - */ -static GLboolean -validate_params(struct gl_context *ctx, unsigned caller, - const char *callerstr, GLenum source, GLenum type, - GLenum severity) -{ -#define INSERT 1 -#define CONTROL 2 - switch(source) { - case GL_DEBUG_SOURCE_APPLICATION_ARB: - case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: - break; - case GL_DEBUG_SOURCE_API_ARB: - case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: - case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: - case GL_DEBUG_SOURCE_OTHER_ARB: - if (caller != INSERT) - break; - else - goto error; - case GL_DONT_CARE: - if (caller == CONTROL) - break; - else - goto error; - default: - goto error; - } - - switch(type) { - case GL_DEBUG_TYPE_ERROR_ARB: - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: - case GL_DEBUG_TYPE_PERFORMANCE_ARB: - case GL_DEBUG_TYPE_PORTABILITY_ARB: - case GL_DEBUG_TYPE_OTHER_ARB: - case GL_DEBUG_TYPE_MARKER: - case GL_DEBUG_TYPE_PUSH_GROUP: - case GL_DEBUG_TYPE_POP_GROUP: - break; - case GL_DONT_CARE: - if (caller == CONTROL) - break; - else - goto error; - default: - goto error; - } - - switch(severity) { - case GL_DEBUG_SEVERITY_HIGH_ARB: - case GL_DEBUG_SEVERITY_MEDIUM_ARB: - case GL_DEBUG_SEVERITY_LOW_ARB: - case GL_DEBUG_SEVERITY_NOTIFICATION: - break; - case GL_DONT_CARE: - if (caller == CONTROL) - break; - else - goto error; - default: - goto error; - } - return GL_TRUE; - -error: - _mesa_error(ctx, GL_INVALID_ENUM, "bad values passed to %s" - "(source=0x%x, type=0x%x, severity=0x%x)", callerstr, - source, type, severity); - - return GL_FALSE; -} - - -static GLboolean -validate_length(struct gl_context *ctx, const char *callerstr, GLsizei length, - const GLchar *buf) -{ - - if (length < 0) { - GLsizei len = strlen(buf); - - if (len >= MAX_DEBUG_MESSAGE_LENGTH) { - _mesa_error(ctx, GL_INVALID_VALUE, - "%s(null terminated string length=%d, is not less than " - "GL_MAX_DEBUG_MESSAGE_LENGTH=%d)", callerstr, len, - MAX_DEBUG_MESSAGE_LENGTH); - return GL_FALSE; - } - } - - if (length >= MAX_DEBUG_MESSAGE_LENGTH) { - _mesa_error(ctx, GL_INVALID_VALUE, - "%s(length=%d, which is not less than " - "GL_MAX_DEBUG_MESSAGE_LENGTH=%d)", callerstr, length, - MAX_DEBUG_MESSAGE_LENGTH); - return GL_FALSE; - } - - return GL_TRUE; -} - - -void GLAPIENTRY -_mesa_DebugMessageInsert(GLenum source, GLenum type, GLuint id, - GLenum severity, GLint length, - const GLchar *buf) -{ - GET_CURRENT_CONTEXT(ctx); - const char *callerstr; - - if (_mesa_is_desktop_gl(ctx)) - callerstr = "glDebugMessageInsert"; - else - callerstr = "glDebugMessageInsertKHR"; - - if (!validate_params(ctx, INSERT, callerstr, source, type, severity)) - return; /* GL_INVALID_ENUM */ - - if (!validate_length(ctx, callerstr, length, buf)) - return; /* GL_INVALID_VALUE */ - - log_msg(ctx, gl_enum_to_debug_source(source), - gl_enum_to_debug_type(type), id, - gl_enum_to_debug_severity(severity), - length, buf); - - if (type == GL_DEBUG_TYPE_MARKER && ctx->Driver.EmitStringMarker) { - /* if length not specified, string will be null terminated: */ - if (length < 0) - length = strlen(buf); - ctx->Driver.EmitStringMarker(ctx, buf, length); - } -} - - -GLuint GLAPIENTRY -_mesa_GetDebugMessageLog(GLuint count, GLsizei logSize, GLenum *sources, - GLenum *types, GLenum *ids, GLenum *severities, - GLsizei *lengths, GLchar *messageLog) -{ - GET_CURRENT_CONTEXT(ctx); - struct gl_debug_state *debug; - const char *callerstr; - GLuint ret; - - if (_mesa_is_desktop_gl(ctx)) - callerstr = "glGetDebugMessageLog"; - else - callerstr = "glGetDebugMessageLogKHR"; - - if (!messageLog) - logSize = 0; - - if (logSize < 0) { - _mesa_error(ctx, GL_INVALID_VALUE, - "%s(logSize=%d : logSize must not be negative)", - callerstr, logSize); - return 0; - } - - debug = _mesa_lock_debug_state(ctx); - if (!debug) - return 0; - - for (ret = 0; ret < count; ret++) { - const struct gl_debug_message *msg = debug_fetch_message(debug); - GLsizei len; - - if (!msg) - break; - - len = msg->length; - if (len < 0) - len = strlen(msg->message); - - if (logSize < len+1 && messageLog != NULL) - break; - - if (messageLog) { - assert(msg->message[len] == '\0'); - (void) strncpy(messageLog, msg->message, (size_t)len+1); - - messageLog += len+1; - logSize -= len+1; - } - - if (lengths) - *lengths++ = len+1; - if (severities) - *severities++ = debug_severity_enums[msg->severity]; - if (sources) - *sources++ = debug_source_enums[msg->source]; - if (types) - *types++ = debug_type_enums[msg->type]; - if (ids) - *ids++ = msg->id; - - debug_delete_messages(debug, 1); - } - - _mesa_unlock_debug_state(ctx); - - return ret; -} - - -void GLAPIENTRY -_mesa_DebugMessageControl(GLenum gl_source, GLenum gl_type, - GLenum gl_severity, GLsizei count, - const GLuint *ids, GLboolean enabled) -{ - GET_CURRENT_CONTEXT(ctx); - enum mesa_debug_source source = gl_enum_to_debug_source(gl_source); - enum mesa_debug_type type = gl_enum_to_debug_type(gl_type); - enum mesa_debug_severity severity = gl_enum_to_debug_severity(gl_severity); - const char *callerstr; - struct gl_debug_state *debug; - - if (_mesa_is_desktop_gl(ctx)) - callerstr = "glDebugMessageControl"; - else - callerstr = "glDebugMessageControlKHR"; - - if (count < 0) { - _mesa_error(ctx, GL_INVALID_VALUE, - "%s(count=%d : count must not be negative)", callerstr, - count); - return; - } - - if (!validate_params(ctx, CONTROL, callerstr, gl_source, gl_type, - gl_severity)) - return; /* GL_INVALID_ENUM */ - - if (count && (gl_severity != GL_DONT_CARE || gl_type == GL_DONT_CARE - || gl_source == GL_DONT_CARE)) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "%s(When passing an array of ids, severity must be" - " GL_DONT_CARE, and source and type must not be GL_DONT_CARE.", - callerstr); - return; - } - - debug = _mesa_lock_debug_state(ctx); - if (!debug) - return; - - if (count) { - GLsizei i; - for (i = 0; i < count; i++) - debug_set_message_enable(debug, source, type, ids[i], enabled); - } - else { - debug_set_message_enable_all(debug, source, type, severity, enabled); - } - - _mesa_unlock_debug_state(ctx); -} - - -void GLAPIENTRY -_mesa_DebugMessageCallback(GLDEBUGPROC callback, const void *userParam) -{ - GET_CURRENT_CONTEXT(ctx); - struct gl_debug_state *debug = _mesa_lock_debug_state(ctx); - if (debug) { - debug->Callback = callback; - debug->CallbackData = userParam; - _mesa_unlock_debug_state(ctx); - } -} - - -void GLAPIENTRY -_mesa_PushDebugGroup(GLenum source, GLuint id, GLsizei length, - const GLchar *message) -{ - GET_CURRENT_CONTEXT(ctx); - const char *callerstr; - struct gl_debug_state *debug; - struct gl_debug_message *emptySlot; - - if (_mesa_is_desktop_gl(ctx)) - callerstr = "glPushDebugGroup"; - else - callerstr = "glPushDebugGroupKHR"; - - switch(source) { - case GL_DEBUG_SOURCE_APPLICATION: - case GL_DEBUG_SOURCE_THIRD_PARTY: - break; - default: - _mesa_error(ctx, GL_INVALID_ENUM, "bad value passed to %s" - "(source=0x%x)", callerstr, source); - return; - } - - if (!validate_length(ctx, callerstr, length, message)) - return; /* GL_INVALID_VALUE */ - - debug = _mesa_lock_debug_state(ctx); - if (!debug) - return; - - if (debug->CurrentGroup >= MAX_DEBUG_GROUP_STACK_DEPTH-1) { - _mesa_unlock_debug_state(ctx); - _mesa_error(ctx, GL_STACK_OVERFLOW, "%s", callerstr); - return; - } - - /* pop reuses the message details from push so we store this */ - emptySlot = debug_get_group_message(debug); - debug_message_store(emptySlot, - gl_enum_to_debug_source(source), - gl_enum_to_debug_type(GL_DEBUG_TYPE_PUSH_GROUP), - id, - gl_enum_to_debug_severity(GL_DEBUG_SEVERITY_NOTIFICATION), - length, message); - - debug_push_group(debug); - - log_msg_locked_and_unlock(ctx, - gl_enum_to_debug_source(source), - MESA_DEBUG_TYPE_PUSH_GROUP, id, - MESA_DEBUG_SEVERITY_NOTIFICATION, length, - message); -} - - -void GLAPIENTRY -_mesa_PopDebugGroup(void) -{ - GET_CURRENT_CONTEXT(ctx); - const char *callerstr; - struct gl_debug_state *debug; - struct gl_debug_message *gdmessage, msg; - - if (_mesa_is_desktop_gl(ctx)) - callerstr = "glPopDebugGroup"; - else - callerstr = "glPopDebugGroupKHR"; - - debug = _mesa_lock_debug_state(ctx); - if (!debug) - return; - - if (debug->CurrentGroup <= 0) { - _mesa_unlock_debug_state(ctx); - _mesa_error(ctx, GL_STACK_UNDERFLOW, "%s", callerstr); - return; - } - - debug_pop_group(debug); - - /* make a shallow copy */ - gdmessage = debug_get_group_message(debug); - msg = *gdmessage; - gdmessage->message = NULL; - gdmessage->length = 0; - - log_msg_locked_and_unlock(ctx, - msg.source, - gl_enum_to_debug_type(GL_DEBUG_TYPE_POP_GROUP), - msg.id, - gl_enum_to_debug_severity(GL_DEBUG_SEVERITY_NOTIFICATION), - msg.length, msg.message); - - debug_message_clear(&msg); -} - - -void -_mesa_init_errors(struct gl_context *ctx) -{ - mtx_init(&ctx->DebugMutex, mtx_plain); -} - - -void -_mesa_free_errors_data(struct gl_context *ctx) -{ - if (ctx->Debug) { - debug_destroy(ctx->Debug); - /* set to NULL just in case it is used before context is completely gone. */ - ctx->Debug = NULL; - } - - mtx_destroy(&ctx->DebugMutex); -} - -void GLAPIENTRY -_mesa_StringMarkerGREMEDY(GLsizei len, const GLvoid *string) -{ - GET_CURRENT_CONTEXT(ctx); - if (ctx->Extensions.GREMEDY_string_marker) { - /* if length not specified, string will be null terminated: */ - if (len <= 0) - len = strlen(string); - ctx->Driver.EmitStringMarker(ctx, string, len); - } else { - _mesa_error(ctx, GL_INVALID_OPERATION, "StringMarkerGREMEDY"); - } -} - -/**********************************************************************/ -/** \name Diagnostics */ -/*@{*/ static FILE *LogFile = NULL; @@ -1492,11 +234,11 @@ _mesa_gl_vdebug(struct gl_context *ctx, char s[MAX_DEBUG_MESSAGE_LENGTH]; int len; - debug_get_id(id); + _mesa_debug_get_id(id); len = _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args); - log_msg(ctx, source, type, *id, severity, len, s); + _mesa_log_msg(ctx, source, type, *id, severity, len, s); } @@ -1536,17 +278,17 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... ) */ static GLuint error_msg_id = 0; - debug_get_id(&error_msg_id); + _mesa_debug_get_id(&error_msg_id); do_output = should_output(ctx, error, fmtString); mtx_lock(&ctx->DebugMutex); if (ctx->Debug) { - do_log = debug_is_message_enabled(ctx->Debug, - MESA_DEBUG_SOURCE_API, - MESA_DEBUG_TYPE_ERROR, - error_msg_id, - MESA_DEBUG_SEVERITY_HIGH); + do_log = _mesa_debug_is_message_enabled(ctx->Debug, + MESA_DEBUG_SOURCE_API, + MESA_DEBUG_TYPE_ERROR, + error_msg_id, + MESA_DEBUG_SEVERITY_HIGH); } else { do_log = GL_FALSE; @@ -1585,8 +327,8 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... ) /* Log the error via ARB_debug_output if needed.*/ if (do_log) { - log_msg(ctx, MESA_DEBUG_SOURCE_API, MESA_DEBUG_TYPE_ERROR, - error_msg_id, MESA_DEBUG_SEVERITY_HIGH, len, s2); + _mesa_log_msg(ctx, MESA_DEBUG_SOURCE_API, MESA_DEBUG_TYPE_ERROR, + error_msg_id, MESA_DEBUG_SEVERITY_HIGH, len, s2); } } @@ -1652,7 +394,7 @@ _mesa_shader_debug(struct gl_context *ctx, GLenum type, GLuint *id, enum mesa_debug_severity severity = MESA_DEBUG_SEVERITY_HIGH; int len; - debug_get_id(id); + _mesa_debug_get_id(id); len = strlen(msg); @@ -1660,7 +402,5 @@ _mesa_shader_debug(struct gl_context *ctx, GLenum type, GLuint *id, if (len >= MAX_DEBUG_MESSAGE_LENGTH) len = MAX_DEBUG_MESSAGE_LENGTH - 1; - log_msg(ctx, source, type, *id, severity, len, msg); + _mesa_log_msg(ctx, source, type, *id, severity, len, msg); } - -/*@}*/ diff --git a/src/mesa/main/errors.h b/src/mesa/main/errors.h index 92df2ac868a..5ad5254ff1b 100644 --- a/src/mesa/main/errors.h +++ b/src/mesa/main/errors.h @@ -47,14 +47,6 @@ extern "C" { #endif -struct _glapi_table; - -extern void -_mesa_init_errors( struct gl_context *ctx ); - -extern void -_mesa_free_errors_data( struct gl_context *ctx ); - extern void _mesa_warning( struct gl_context *gc, const char *fmtString, ... ) PRINTFLIKE(2, 3); @@ -76,6 +68,10 @@ _mesa_log(const char *fmtString, ...) PRINTFLIKE(1, 2); extern FILE * _mesa_get_log_file(void); +void +_mesa_shader_debug(struct gl_context *ctx, GLenum type, GLuint *id, + const char *msg); + extern void _mesa_gl_vdebug(struct gl_context *ctx, GLuint *id, @@ -104,42 +100,6 @@ _mesa_gl_debug(struct gl_context *ctx, } \ } while (0) -bool -_mesa_set_debug_state_int(struct gl_context *ctx, GLenum pname, GLint val); - -GLint -_mesa_get_debug_state_int(struct gl_context *ctx, GLenum pname); - -void * -_mesa_get_debug_state_ptr(struct gl_context *ctx, GLenum pname); - -extern void -_mesa_shader_debug(struct gl_context *ctx, GLenum type, GLuint *id, - const char *msg); - -void GLAPIENTRY -_mesa_DebugMessageInsert(GLenum source, GLenum type, GLuint id, - GLenum severity, GLint length, - const GLchar* buf); -GLuint GLAPIENTRY -_mesa_GetDebugMessageLog(GLuint count, GLsizei logSize, GLenum* sources, - GLenum* types, GLenum* ids, GLenum* severities, - GLsizei* lengths, GLchar* messageLog); -void GLAPIENTRY -_mesa_DebugMessageControl(GLenum source, GLenum type, GLenum severity, - GLsizei count, const GLuint *ids, - GLboolean enabled); -void GLAPIENTRY -_mesa_DebugMessageCallback(GLDEBUGPROC callback, - const void *userParam); -void GLAPIENTRY -_mesa_PushDebugGroup(GLenum source, GLuint id, GLsizei length, - const GLchar *message); -void GLAPIENTRY -_mesa_PopDebugGroup(void); - -void GLAPIENTRY -_mesa_StringMarkerGREMEDY(GLsizei len, const GLvoid *string); #ifdef __cplusplus } diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h index ded6f2c06dc..d1e3a99fdc0 100644 --- a/src/mesa/main/extensions_table.h +++ b/src/mesa/main/extensions_table.h @@ -273,6 +273,8 @@ EXT(MESA_texture_signed_rgba , EXT_texture_snorm EXT(MESA_window_pos , dummy_true , GLL, x , x , x , 2000) EXT(MESA_ycbcr_texture , MESA_ycbcr_texture , GLL, GLC, x , x , 2002) +EXT(NVX_gpu_memory_info , NVX_gpu_memory_info , GLL, GLC, x , x , 2013) + EXT(NV_blend_square , dummy_true , GLL, x , x , x , 1999) EXT(NV_conditional_render , NV_conditional_render , GLL, GLC, x , x , 2008) EXT(NV_depth_clamp , ARB_depth_clamp , GLL, GLC, x , x , 2001) @@ -293,7 +295,6 @@ EXT(NV_texture_barrier , NV_texture_barrier EXT(NV_texture_env_combine4 , NV_texture_env_combine4 , GLL, x , x , x , 1999) EXT(NV_texture_rectangle , NV_texture_rectangle , GLL, x , x , x , 2000) EXT(NV_vdpau_interop , NV_vdpau_interop , GLL, GLC, x , x , 2010) -EXT(NVX_gpu_memory_info , NVX_gpu_memory_info , GLL, GLC, x , x , 2013) EXT(OES_EGL_image , OES_EGL_image , GLL, GLC, ES1, ES2, 2006) /* FIXME: Mesa expects GL_OES_EGL_image to be available in OpenGL contexts. */ EXT(OES_EGL_image_external , OES_EGL_image_external , x , x , ES1, ES2, 2010) diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c index 8453a922549..9005dc5897d 100644 --- a/src/mesa/main/get.c +++ b/src/mesa/main/get.c @@ -26,6 +26,7 @@ #include "glheader.h" #include "context.h" #include "blend.h" +#include "debug_output.h" #include "enable.h" #include "enums.h" #include "errors.h" diff --git a/src/mesa/main/getstring.c b/src/mesa/main/getstring.c index 87c5a3a194f..92f8a389cd9 100644 --- a/src/mesa/main/getstring.c +++ b/src/mesa/main/getstring.c @@ -26,6 +26,7 @@ #include <stdbool.h> #include "glheader.h" #include "context.h" +#include "debug_output.h" #include "get.h" #include "enums.h" #include "extensions.h" diff --git a/src/mesa/main/queryobj.c b/src/mesa/main/queryobj.c index b86692a5f7e..7a70b592c47 100644 --- a/src/mesa/main/queryobj.c +++ b/src/mesa/main/queryobj.c @@ -807,11 +807,6 @@ invalid_enum: return; } - /* TODO: Have the driver be required to handle this fixup. */ - if (q->Target == GL_ANY_SAMPLES_PASSED || - q->Target == GL_ANY_SAMPLES_PASSED_CONSERVATIVE) - value = !!value; - switch (ptype) { case GL_INT: { GLint *param = (GLint *)offset; diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c index 7d8914291c3..681e46bfcf7 100644 --- a/src/mesa/main/viewport.c +++ b/src/mesa/main/viewport.c @@ -456,11 +456,11 @@ _mesa_get_viewport_xform(struct gl_context *ctx, unsigned i, translate[0] = half_width + x; if (ctx->Transform.ClipOrigin == GL_UPPER_LEFT) { scale[1] = -half_height; - translate[1] = half_height - y; } else { scale[1] = half_height; - translate[1] = half_height + y; } + translate[1] = half_height + y; + if (ctx->Transform.ClipDepthMode == GL_NEGATIVE_ONE_TO_ONE) { scale[2] = 0.5 * (f - n); translate[2] = 0.5 * (n + f); diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 0f17ed136da..71c5fc4a485 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -51,7 +51,6 @@ #include "program/prog_print.h" #include "program/program.h" #include "program/prog_parameter.h" -#include "program/sampler.h" static int swizzle_for_size(int size); @@ -1390,7 +1389,7 @@ ir_to_mesa_visitor::visit(ir_dereference_variable *ir) switch (var->data.mode) { case ir_var_uniform: entry = new(mem_ctx) variable_storage(var, PROGRAM_UNIFORM, - var->data.location); + var->data.param_index); this->variables.push_tail(entry); break; case ir_var_shader_in: @@ -1540,6 +1539,82 @@ get_assignment_lhs(ir_dereference *ir, ir_to_mesa_visitor *v) return dst_reg(v->result); } +/* Calculate the sampler index and also calculate the base uniform location + * for struct members. + */ +static void +calc_sampler_offsets(struct gl_shader_program *prog, ir_dereference *deref, + unsigned *offset, unsigned *array_elements, + unsigned *location) +{ + if (deref->ir_type == ir_type_dereference_variable) + return; + + switch (deref->ir_type) { + case ir_type_dereference_array: { + ir_dereference_array *deref_arr = deref->as_dereference_array(); + ir_constant *array_index = + deref_arr->array_index->constant_expression_value(); + + if (!array_index) { + /* GLSL 1.10 and 1.20 allowed variable sampler array indices, + * while GLSL 1.30 requires that the array indices be + * constant integer expressions. We don't expect any driver + * to actually work with a really variable array index, so + * all that would work would be an unrolled loop counter that ends + * up being constant above. + */ + ralloc_strcat(&prog->InfoLog, + "warning: Variable sampler array index unsupported.\n" + "This feature of the language was removed in GLSL 1.20 " + "and is unlikely to be supported for 1.10 in Mesa.\n"); + } else { + *offset += array_index->value.u[0] * *array_elements; + } + + *array_elements *= deref_arr->array->type->length; + + calc_sampler_offsets(prog, deref_arr->array->as_dereference(), + offset, array_elements, location); + break; + } + + case ir_type_dereference_record: { + ir_dereference_record *deref_record = deref->as_dereference_record(); + unsigned field_index = + deref_record->record->type->field_index(deref_record->field); + *location += + deref_record->record->type->record_location_offset(field_index); + calc_sampler_offsets(prog, deref_record->record->as_dereference(), + offset, array_elements, location); + break; + } + + default: + unreachable("Invalid deref type"); + break; + } +} + +static int +get_sampler_uniform_value(class ir_dereference *sampler, + struct gl_shader_program *shader_program, + const struct gl_program *prog) +{ + GLuint shader = _mesa_program_enum_to_shader_stage(prog->Target); + ir_variable *var = sampler->variable_referenced(); + unsigned location = var->data.location; + unsigned array_elements = 1; + unsigned offset = 0; + + calc_sampler_offsets(shader_program, sampler, &offset, &array_elements, + &location); + + assert(shader_program->UniformStorage[location].opaque[shader].active); + return shader_program->UniformStorage[location].opaque[shader].index + + offset; +} + /** * Process the condition of a conditional assignment * @@ -1989,9 +2064,8 @@ ir_to_mesa_visitor::visit(ir_texture *ir) if (ir->shadow_comparitor) inst->tex_shadow = GL_TRUE; - inst->sampler = _mesa_get_sampler_uniform_value(ir->sampler, - this->shader_program, - this->prog); + inst->sampler = get_sampler_uniform_value(ir->sampler, shader_program, + prog); switch (sampler_type->sampler_dimensionality) { case GLSL_SAMPLER_DIM_1D: @@ -2269,8 +2343,7 @@ public: { this->idx = -1; this->program_resource_visitor::process(var); - - var->data.location = this->idx; + var->data.param_index = this->idx; } private: diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c index f8659f65339..74cbbfb1cc6 100644 --- a/src/mesa/program/prog_to_nir.c +++ b/src/mesa/program/prog_to_nir.c @@ -928,7 +928,7 @@ ptn_add_output_stores(struct ptn_compile *c) nir_intrinsic_instr *store = nir_intrinsic_instr_create(b->shader, nir_intrinsic_store_var); store->num_components = glsl_get_vector_elements(var->type); - store->const_index[0] = (1 << store->num_components) - 1; + nir_intrinsic_set_write_mask(store, (1 << store->num_components) - 1); store->variables[0] = nir_deref_var_create(store, c->output_vars[var->data.location]); @@ -999,7 +999,7 @@ setup_registers_and_variables(struct ptn_compile *c) nir_intrinsic_instr *store = nir_intrinsic_instr_create(shader, nir_intrinsic_store_var); store->num_components = 4; - store->const_index[0] = WRITEMASK_XYZW; + nir_intrinsic_set_write_mask(store, WRITEMASK_XYZW); store->variables[0] = nir_deref_var_create(store, fullvar); store->src[0] = nir_src_for_ssa(f001); nir_builder_instr_insert(b, &store->instr); diff --git a/src/mesa/program/sampler.cpp b/src/mesa/program/sampler.cpp deleted file mode 100644 index f118552d64e..00000000000 --- a/src/mesa/program/sampler.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. - * Copyright (C) 2008 VMware, Inc. All Rights Reserved. - * Copyright © 2010 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 "main/mtypes.h" -#include "compiler/glsl_types.h" -#include "compiler/glsl/ir.h" -#include "compiler/glsl/ir_uniform.h" -#include "compiler/glsl/ir_visitor.h" -#include "compiler/glsl/program.h" -#include "program/hash_table.h" -#include "program/prog_parameter.h" -#include "program/program.h" - - -class get_sampler_name : public ir_hierarchical_visitor -{ -public: - get_sampler_name(ir_dereference *last, - struct gl_shader_program *shader_program) - { - this->mem_ctx = ralloc_context(NULL); - this->shader_program = shader_program; - this->name = NULL; - this->offset = 0; - this->last = last; - } - - ~get_sampler_name() - { - ralloc_free(this->mem_ctx); - } - - virtual ir_visitor_status visit(ir_dereference_variable *ir) - { - this->name = ir->var->name; - return visit_continue; - } - - virtual ir_visitor_status visit_leave(ir_dereference_record *ir) - { - this->name = ralloc_asprintf(mem_ctx, "%s.%s", name, ir->field); - return visit_continue; - } - - virtual ir_visitor_status visit_leave(ir_dereference_array *ir) - { - ir_constant *index = ir->array_index->as_constant(); - int i; - - if (index) { - i = index->value.i[0]; - } else { - /* GLSL 1.10 and 1.20 allowed variable sampler array indices, - * while GLSL 1.30 requires that the array indices be - * constant integer expressions. We don't expect any driver - * to actually work with a really variable array index, so - * all that would work would be an unrolled loop counter that ends - * up being constant above. - */ - ralloc_strcat(&shader_program->InfoLog, - "warning: Variable sampler array index unsupported.\n" - "This feature of the language was removed in GLSL 1.20 " - "and is unlikely to be supported for 1.10 in Mesa.\n"); - i = 0; - } - if (ir != last) { - this->name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i); - } else { - offset = i; - } - return visit_continue; - } - - struct gl_shader_program *shader_program; - const char *name; - void *mem_ctx; - int offset; - ir_dereference *last; -}; - - -int -_mesa_get_sampler_uniform_value(class ir_dereference *sampler, - struct gl_shader_program *shader_program, - const struct gl_program *prog) -{ - get_sampler_name getname(sampler, shader_program); - - GLuint shader = _mesa_program_enum_to_shader_stage(prog->Target); - - sampler->accept(&getname); - - unsigned location; - if (!shader_program->UniformHash->get(location, getname.name)) { - linker_error(shader_program, - "failed to find sampler named %s.\n", getname.name); - return 0; - } - - if (!shader_program->UniformStorage[location].opaque[shader].active) { - assert(0 && "cannot return a sampler"); - linker_error(shader_program, - "cannot return a sampler named %s, because it is not " - "used in this shader stage. This is a driver bug.\n", - getname.name); - return 0; - } - - return shader_program->UniformStorage[location].opaque[shader].index + - getname.offset; -} - - -class ir_rvalue * -_mesa_get_sampler_array_nonconst_index(class ir_dereference *sampler) -{ - ir_dereference_array *deref_arr = sampler->as_dereference_array(); - if (!deref_arr || deref_arr->array_index->as_constant()) - return NULL; - - return deref_arr->array_index; -} diff --git a/src/mesa/program/sampler.h b/src/mesa/program/sampler.h deleted file mode 100644 index 61c7f5851e7..00000000000 --- a/src/mesa/program/sampler.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. - * Copyright (C) 2008 VMware, Inc. All Rights Reserved. - * Copyright © 2010 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. - */ - -#ifndef SAMPLER_H -#define SAMPLER_H - - -int -_mesa_get_sampler_uniform_value(class ir_dereference *sampler, - struct gl_shader_program *shader_program, - const struct gl_program *prog); - -class ir_rvalue * -_mesa_get_sampler_array_nonconst_index(class ir_dereference *sampler); - - -#endif /* SAMPLER_H */ diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 0f9ea101889..23b7abfc1c5 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -163,7 +163,6 @@ static void update_gp( struct st_context *st ) { struct st_geometry_program *stgp; - struct st_gp_variant_key key; if (!st->ctx->GeometryProgram._Current) { cso_set_geometry_shader_handle(st->cso_context, NULL); @@ -173,10 +172,7 @@ update_gp( struct st_context *st ) stgp = st_geometry_program(st->ctx->GeometryProgram._Current); assert(stgp->Base.Base.Target == GL_GEOMETRY_PROGRAM_NV); - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - - st->gp_variant = st_get_gp_variant(st, stgp, &key); + st->gp_variant = st_get_basic_variant(st, &stgp->tgsi, &stgp->variants); st_reference_geomprog(st, &st->gp, stgp); @@ -199,7 +195,6 @@ static void update_tcp( struct st_context *st ) { struct st_tessctrl_program *sttcp; - struct st_tcp_variant_key key; if (!st->ctx->TessCtrlProgram._Current) { cso_set_tessctrl_shader_handle(st->cso_context, NULL); @@ -209,10 +204,7 @@ update_tcp( struct st_context *st ) sttcp = st_tessctrl_program(st->ctx->TessCtrlProgram._Current); assert(sttcp->Base.Base.Target == GL_TESS_CONTROL_PROGRAM_NV); - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - - st->tcp_variant = st_get_tcp_variant(st, sttcp, &key); + st->tcp_variant = st_get_basic_variant(st, &sttcp->tgsi, &sttcp->variants); st_reference_tesscprog(st, &st->tcp, sttcp); @@ -235,7 +227,6 @@ static void update_tep( struct st_context *st ) { struct st_tesseval_program *sttep; - struct st_tep_variant_key key; if (!st->ctx->TessEvalProgram._Current) { cso_set_tesseval_shader_handle(st->cso_context, NULL); @@ -245,10 +236,7 @@ update_tep( struct st_context *st ) sttep = st_tesseval_program(st->ctx->TessEvalProgram._Current); assert(sttep->Base.Base.Target == GL_TESS_EVALUATION_PROGRAM_NV); - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - - st->tep_variant = st_get_tep_variant(st, sttep, &key); + st->tep_variant = st_get_basic_variant(st, &sttep->tgsi, &sttep->variants); st_reference_tesseprog(st, &st->tep, sttep); diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index d8c3dbdd793..34809ad7163 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -176,97 +176,19 @@ make_bitmap_texture(struct gl_context *ctx, GLsizei width, GLsizei height, return pt; } -static void -setup_bitmap_vertex_data(struct st_context *st, bool normalized, - int x, int y, int width, int height, - float z, const float color[4], - struct pipe_resource **vbuf, - unsigned *vbuf_offset) -{ - const GLfloat fb_width = (GLfloat)st->state.framebuffer.width; - const GLfloat fb_height = (GLfloat)st->state.framebuffer.height; - const GLfloat x0 = (GLfloat)x; - const GLfloat x1 = (GLfloat)(x + width); - const GLfloat y0 = (GLfloat)y; - const GLfloat y1 = (GLfloat)(y + height); - GLfloat sLeft = (GLfloat)0.0, sRight = (GLfloat)1.0; - GLfloat tTop = (GLfloat)0.0, tBot = (GLfloat)1.0 - tTop; - const GLfloat clip_x0 = (GLfloat)(x0 / fb_width * 2.0 - 1.0); - const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0); - const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0); - const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0); - GLuint i; - float (*vertices)[3][4]; /**< vertex pos + color + texcoord */ - - if(!normalized) - { - sRight = (GLfloat) width; - tBot = (GLfloat) height; - } - - u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), 4, - vbuf_offset, vbuf, (void **) &vertices); - if (!*vbuf) { - return; - } - - /* Positions are in clip coords since we need to do clipping in case - * the bitmap quad goes beyond the window bounds. - */ - vertices[0][0][0] = clip_x0; - vertices[0][0][1] = clip_y0; - vertices[0][2][0] = sLeft; - vertices[0][2][1] = tTop; - - vertices[1][0][0] = clip_x1; - vertices[1][0][1] = clip_y0; - vertices[1][2][0] = sRight; - vertices[1][2][1] = tTop; - - vertices[2][0][0] = clip_x1; - vertices[2][0][1] = clip_y1; - vertices[2][2][0] = sRight; - vertices[2][2][1] = tBot; - - vertices[3][0][0] = clip_x0; - vertices[3][0][1] = clip_y1; - vertices[3][2][0] = sLeft; - vertices[3][2][1] = tBot; - - /* same for all verts: */ - for (i = 0; i < 4; i++) { - vertices[i][0][2] = z; - vertices[i][0][3] = 1.0f; - vertices[i][1][0] = color[0]; - vertices[i][1][1] = color[1]; - vertices[i][1][2] = color[2]; - vertices[i][1][3] = color[3]; - vertices[i][2][2] = 0.0; /*R*/ - vertices[i][2][3] = 1.0; /*Q*/ - } - - u_upload_unmap(st->uploader); -} - - /** - * Render a glBitmap by drawing a textured quad + * Setup pipeline state prior to rendering the bitmap textured quad. */ static void -draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z, - GLsizei width, GLsizei height, - struct pipe_sampler_view *sv, - const GLfloat *color) +setup_render_state(struct gl_context *ctx, + struct pipe_sampler_view *sv, + const GLfloat *color) { struct st_context *st = st_context(ctx); - struct pipe_context *pipe = st->pipe; struct cso_context *cso = st->cso_context; struct st_fp_variant *fpv; struct st_fp_variant_key key; - GLuint maxSize; - GLuint offset; - struct pipe_resource *vbuf = NULL; memset(&key, 0, sizeof(key)); key.st = st->has_shareable_shaders ? NULL : st; @@ -292,16 +214,6 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z, COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], colorSave); } - - /* limit checks */ - /* XXX if the bitmap is larger than the max texture size, break - * it up into chunks. - */ - maxSize = 1 << (pipe->screen->get_param(pipe->screen, - PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1); - assert(width <= (GLsizei)maxSize); - assert(height <= (GLsizei)maxSize); - cso_save_rasterizer(cso); cso_save_fragment_samplers(cso); cso_save_fragment_sampler_views(cso); @@ -373,24 +285,18 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z, cso_set_vertex_elements(cso, 3, st->velems_util_draw); cso_set_stream_outputs(st->cso_context, 0, NULL, NULL); +} - /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */ - z = z * 2.0f - 1.0f; - /* draw textured quad */ - setup_bitmap_vertex_data(st, sv->texture->target != PIPE_TEXTURE_RECT, - x, y, width, height, z, color, &vbuf, &offset); - - if (vbuf) { - util_draw_vertex_buffer(pipe, st->cso_context, vbuf, - cso_get_aux_vertex_buffer_slot(st->cso_context), - offset, - PIPE_PRIM_TRIANGLE_FAN, - 4, /* verts */ - 3); /* attribs/vert */ - } +/** + * Restore pipeline state after rendering the bitmap textured quad. + */ +static void +restore_render_state(struct gl_context *ctx) +{ + struct st_context *st = st_context(ctx); + struct cso_context *cso = st->cso_context; - /* restore state */ cso_restore_rasterizer(cso); cso_restore_fragment_samplers(cso); cso_restore_fragment_sampler_views(cso); @@ -403,6 +309,111 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z, cso_restore_vertex_elements(cso); cso_restore_aux_vertex_buffer_slot(cso); cso_restore_stream_outputs(cso); +} + + +/** + * Render a glBitmap by drawing a textured quad + */ +static void +draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z, + GLsizei width, GLsizei height, + struct pipe_sampler_view *sv, + const GLfloat *color) +{ + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; + struct pipe_resource *vbuf = NULL; + const float fb_width = (float) st->state.framebuffer.width; + const float fb_height = (float) st->state.framebuffer.height; + const float x0 = (float) x; + const float x1 = (float) (x + width); + const float y0 = (float) y; + const float y1 = (float) (y + height); + float sLeft = 0.0f, sRight = 1.0f; + float tTop = 0.0f, tBot = 1.0f - tTop; + const float clip_x0 = x0 / fb_width * 2.0f - 1.0f; + const float clip_y0 = y0 / fb_height * 2.0f - 1.0f; + const float clip_x1 = x1 / fb_width * 2.0f - 1.0f; + const float clip_y1 = y1 / fb_height * 2.0f - 1.0f; + float (*vertices)[3][4]; /**< vertex pos + color + texcoord */ + unsigned offset, i; + + /* limit checks */ + { + /* XXX if the bitmap is larger than the max texture size, break + * it up into chunks. + */ + GLuint maxSize = 1 << (pipe->screen->get_param(pipe->screen, + PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1); + assert(width <= (GLsizei) maxSize); + assert(height <= (GLsizei) maxSize); + } + + setup_render_state(ctx, sv, color); + + /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */ + z = z * 2.0f - 1.0f; + + if (sv->texture->target == PIPE_TEXTURE_RECT) { + /* use non-normalized texcoords */ + sRight = (float) width; + tBot = (float) height; + } + + u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), 4, + &offset, &vbuf, (void **) &vertices); + if (!vbuf) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBitmap"); + restore_render_state(ctx); + return; + } + + /* Positions are in clip coords since we need to do clipping in case + * the bitmap quad goes beyond the window bounds. + */ + vertices[0][0][0] = clip_x0; + vertices[0][0][1] = clip_y0; + vertices[0][2][0] = sLeft; + vertices[0][2][1] = tTop; + + vertices[1][0][0] = clip_x1; + vertices[1][0][1] = clip_y0; + vertices[1][2][0] = sRight; + vertices[1][2][1] = tTop; + + vertices[2][0][0] = clip_x1; + vertices[2][0][1] = clip_y1; + vertices[2][2][0] = sRight; + vertices[2][2][1] = tBot; + + vertices[3][0][0] = clip_x0; + vertices[3][0][1] = clip_y1; + vertices[3][2][0] = sLeft; + vertices[3][2][1] = tBot; + + /* same for all verts: */ + for (i = 0; i < 4; i++) { + vertices[i][0][2] = z; + vertices[i][0][3] = 1.0f; + vertices[i][1][0] = color[0]; + vertices[i][1][1] = color[1]; + vertices[i][1][2] = color[2]; + vertices[i][1][3] = color[3]; + vertices[i][2][2] = 0.0; /*R*/ + vertices[i][2][3] = 1.0; /*Q*/ + } + + u_upload_unmap(st->uploader); + + util_draw_vertex_buffer(pipe, st->cso_context, vbuf, + cso_get_aux_vertex_buffer_slot(st->cso_context), + offset, + PIPE_PRIM_TRIANGLE_FAN, + 4, /* verts */ + 3); /* attribs/vert */ + + restore_render_state(ctx); pipe_resource_reference(&vbuf, NULL); @@ -486,9 +497,9 @@ create_cache_trans(struct st_context *st) void st_flush_bitmap_cache(struct st_context *st) { - if (!st->bitmap.cache->empty) { - struct bitmap_cache *cache = st->bitmap.cache; + struct bitmap_cache *cache = st->bitmap.cache; + if (cache && !cache->empty) { struct pipe_context *pipe = st->pipe; struct pipe_sampler_view *sv; @@ -607,6 +618,76 @@ accum_bitmap(struct gl_context *ctx, } +/** + * One-time init for drawing bitmaps. + */ +static void +init_bitmap_state(struct st_context *st) +{ + struct pipe_sampler_state *sampler = &st->bitmap.samplers[0]; + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; + + /* This function should only be called once */ + assert(st->bitmap.cache == NULL); + + /* alloc bitmap cache object */ + st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache); + + /* init sampler state once */ + memset(sampler, 0, sizeof(*sampler)); + sampler->wrap_s = PIPE_TEX_WRAP_CLAMP; + sampler->wrap_t = PIPE_TEX_WRAP_CLAMP; + sampler->wrap_r = PIPE_TEX_WRAP_CLAMP; + sampler->min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler->min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler->mag_img_filter = PIPE_TEX_FILTER_NEAREST; + st->bitmap.samplers[1] = *sampler; + st->bitmap.samplers[1].normalized_coords = 1; + + /* init baseline rasterizer state once */ + memset(&st->bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer)); + st->bitmap.rasterizer.half_pixel_center = 1; + st->bitmap.rasterizer.bottom_edge_rule = 1; + st->bitmap.rasterizer.depth_clip = 1; + + /* find a usable texture format */ + if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_SAMPLER_VIEW)) { + st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM; + } + else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_SAMPLER_VIEW)) { + st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM; + } + else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_SAMPLER_VIEW)) { + st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM; + } + else { + /* XXX support more formats */ + assert(0); + } + + /* Create the vertex shader */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_COLOR, + st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD : + TGSI_SEMANTIC_GENERIC }; + const uint semantic_indexes[] = { 0, 0, 0 }; + st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, + semantic_names, + semantic_indexes, + FALSE); + } + + reset_cache(st); +} + /** * Called via ctx->Driver.Bitmap() @@ -622,6 +703,10 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y, assert(width > 0); assert(height > 0); + if (!st->bitmap.cache) { + init_bitmap_state(st); + } + /* We only need to validate state of the st dirty flags are set or * any non-_NEW_PROGRAM_CONSTANTS mesa flags are set. The VS we use * for bitmap drawing uses no constants and the FS constants are @@ -631,19 +716,6 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y, st_validate_state(st); } - if (!st->bitmap.vs) { - /* create pass-through vertex shader now */ - const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, - TGSI_SEMANTIC_COLOR, - st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD : - TGSI_SEMANTIC_GENERIC }; - const uint semantic_indexes[] = { 0, 0, 0 }; - st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, - semantic_names, - semantic_indexes, - FALSE); - } - if (UseBitmapCache && accum_bitmap(ctx, x, y, width, height, unpack, bitmap)) return; @@ -676,59 +748,6 @@ st_init_bitmap_functions(struct dd_function_table *functions) } -/** Per-context init */ -void -st_init_bitmap(struct st_context *st) -{ - struct pipe_sampler_state *sampler = &st->bitmap.samplers[0]; - struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; - - /* init sampler state once */ - memset(sampler, 0, sizeof(*sampler)); - sampler->wrap_s = PIPE_TEX_WRAP_CLAMP; - sampler->wrap_t = PIPE_TEX_WRAP_CLAMP; - sampler->wrap_r = PIPE_TEX_WRAP_CLAMP; - sampler->min_img_filter = PIPE_TEX_FILTER_NEAREST; - sampler->min_mip_filter = PIPE_TEX_MIPFILTER_NONE; - sampler->mag_img_filter = PIPE_TEX_FILTER_NEAREST; - st->bitmap.samplers[1] = *sampler; - st->bitmap.samplers[1].normalized_coords = 1; - - /* init baseline rasterizer state once */ - memset(&st->bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer)); - st->bitmap.rasterizer.half_pixel_center = 1; - st->bitmap.rasterizer.bottom_edge_rule = 1; - st->bitmap.rasterizer.depth_clip = 1; - - /* find a usable texture format */ - if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, - PIPE_TEXTURE_2D, 0, - PIPE_BIND_SAMPLER_VIEW)) { - st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM; - } - else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM, - PIPE_TEXTURE_2D, 0, - PIPE_BIND_SAMPLER_VIEW)) { - st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM; - } - else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, - PIPE_TEXTURE_2D, 0, - PIPE_BIND_SAMPLER_VIEW)) { - st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM; - } - else { - /* XXX support more formats */ - assert(0); - } - - /* alloc bitmap cache object */ - st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache); - - reset_cache(st); -} - - /** Per-context tear-down */ void st_destroy_bitmap(struct st_context *st) diff --git a/src/mesa/state_tracker/st_cb_bitmap.h b/src/mesa/state_tracker/st_cb_bitmap.h index dc7e5cb5c9e..4d1ae222b81 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.h +++ b/src/mesa/state_tracker/st_cb_bitmap.h @@ -42,9 +42,6 @@ extern void st_init_bitmap_functions(struct dd_function_table *functions); extern void -st_init_bitmap(struct st_context *st); - -extern void st_destroy_bitmap(struct st_context *st); extern void diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 2c4eccf1e06..ca493d84715 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -153,7 +153,8 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog) struct st_geometry_program *stgp = (struct st_geometry_program *) prog; - st_release_gp_variants(st, stgp); + st_release_basic_variants(st, stgp->Base.Base.Target, + &stgp->variants, &stgp->tgsi); if (stgp->glsl_to_tgsi) free_glsl_to_tgsi_visitor(stgp->glsl_to_tgsi); @@ -175,7 +176,8 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog) struct st_tessctrl_program *sttcp = (struct st_tessctrl_program *) prog; - st_release_tcp_variants(st, sttcp); + st_release_basic_variants(st, sttcp->Base.Base.Target, + &sttcp->variants, &sttcp->tgsi); if (sttcp->glsl_to_tgsi) free_glsl_to_tgsi_visitor(sttcp->glsl_to_tgsi); @@ -186,7 +188,8 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog) struct st_tesseval_program *sttep = (struct st_tesseval_program *) prog; - st_release_tep_variants(st, sttep); + st_release_basic_variants(st, sttep->Base.Base.Target, + &sttep->variants, &sttep->tgsi); if (sttep->glsl_to_tgsi) free_glsl_to_tgsi_visitor(sttep->glsl_to_tgsi); @@ -202,18 +205,6 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog) /** - * Called via ctx->Driver.IsProgramNative() - */ -static GLboolean -st_is_program_native(struct gl_context *ctx, - GLenum target, - struct gl_program *prog) -{ - return GL_TRUE; -} - - -/** * Called via ctx->Driver.ProgramStringNotify() * Called when the program's text/code is changed. We have to free * all shader variants and corresponding gallium shaders when this happens. @@ -239,7 +230,8 @@ st_program_string_notify( struct gl_context *ctx, else if (target == GL_GEOMETRY_PROGRAM_NV) { struct st_geometry_program *stgp = (struct st_geometry_program *) prog; - st_release_gp_variants(st, stgp); + st_release_basic_variants(st, stgp->Base.Base.Target, + &stgp->variants, &stgp->tgsi); if (!st_translate_geometry_program(st, stgp)) return false; @@ -260,7 +252,8 @@ st_program_string_notify( struct gl_context *ctx, struct st_tessctrl_program *sttcp = (struct st_tessctrl_program *) prog; - st_release_tcp_variants(st, sttcp); + st_release_basic_variants(st, sttcp->Base.Base.Target, + &sttcp->variants, &sttcp->tgsi); if (!st_translate_tessctrl_program(st, sttcp)) return false; @@ -271,7 +264,8 @@ st_program_string_notify( struct gl_context *ctx, struct st_tesseval_program *sttep = (struct st_tesseval_program *) prog; - st_release_tep_variants(st, sttep); + st_release_basic_variants(st, sttep->Base.Base.Target, + &sttep->variants, &sttep->tgsi); if (!st_translate_tesseval_program(st, sttep)) return false; @@ -297,7 +291,6 @@ st_init_program_functions(struct dd_function_table *functions) functions->UseProgram = st_use_program; functions->NewProgram = st_new_program; functions->DeleteProgram = st_delete_program; - functions->IsProgramNative = st_is_program_native; functions->ProgramStringNotify = st_program_string_notify; functions->LinkShader = st_link_shader; diff --git a/src/mesa/state_tracker/st_cb_queryobj.c b/src/mesa/state_tracker/st_cb_queryobj.c index fc239bc778c..cdb9efc762b 100644 --- a/src/mesa/state_tracker/st_cb_queryobj.c +++ b/src/mesa/state_tracker/st_cb_queryobj.c @@ -96,7 +96,8 @@ st_BeginQuery(struct gl_context *ctx, struct gl_query_object *q) switch (q->Target) { case GL_ANY_SAMPLES_PASSED: case GL_ANY_SAMPLES_PASSED_CONSERVATIVE: - /* fall-through */ + type = PIPE_QUERY_OCCLUSION_PREDICATE; + break; case GL_SAMPLES_PASSED_ARB: type = PIPE_QUERY_OCCLUSION_COUNTER; break; @@ -240,7 +241,14 @@ get_query_result(struct pipe_context *pipe, stq->base.Result = data.pipeline_statistics.c_primitives; break; default: - stq->base.Result = data.u64; + switch (stq->type) { + case PIPE_QUERY_OCCLUSION_PREDICATE: + stq->base.Result = !!data.b; + break; + default: + stq->base.Result = data.u64; + break; + } break; } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 446ebfb563f..9016846b148 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -231,7 +231,6 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe, st->cso_context = cso_create_context(pipe); st_init_atoms( st ); - st_init_bitmap(st); st_init_clear(st); st_init_draw( st ); st_init_pbo_upload(st); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 57076ad0d18..352e795d06a 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -168,9 +168,9 @@ struct st_context struct st_vp_variant *vp_variant; struct st_fp_variant *fp_variant; - struct st_gp_variant *gp_variant; - struct st_tcp_variant *tcp_variant; - struct st_tep_variant *tep_variant; + struct st_basic_variant *gp_variant; + struct st_basic_variant *tcp_variant; + struct st_basic_variant *tep_variant; struct gl_texture_object *default_texture; diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index f25bd742f79..feabe6290eb 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -808,6 +808,7 @@ void st_init_extensions(struct pipe_screen *screen, } extensions->EXT_shader_integer_mix = GL_TRUE; + extensions->ARB_arrays_of_arrays = GL_TRUE; } else { /* Optional integer support for GLSL 1.2. */ if (screen->get_shader_param(screen, PIPE_SHADER_VERTEX, diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index b8182de0be8..ce93aec4e71 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -40,7 +40,6 @@ #include "main/uniforms.h" #include "main/shaderapi.h" #include "program/prog_instruction.h" -#include "program/sampler.h" #include "pipe/p_context.h" #include "pipe/p_screen.h" @@ -257,6 +256,7 @@ public: GLboolean cond_update; bool saturate; st_src_reg sampler; /**< sampler register */ + int sampler_base; int sampler_array_size; /**< 1-based size of sampler array, 1 if not array */ int tex_target; /**< One of TEXTURE_*_INDEX */ glsl_base_type tex_type; @@ -502,6 +502,19 @@ public: void emit_arl(ir_instruction *ir, st_dst_reg dst, st_src_reg src0); + void get_deref_offsets(ir_dereference *ir, + unsigned *array_size, + unsigned *base, + unsigned *index, + st_src_reg *reladdr); + void calc_deref_offsets(ir_dereference *head, + ir_dereference *tail, + unsigned *array_elements, + unsigned *base, + unsigned *index, + st_src_reg *indirect, + unsigned *location); + bool try_emit_mad(ir_expression *ir, int mul_operand); bool try_emit_mad_for_and_not(ir_expression *ir, @@ -2350,7 +2363,7 @@ glsl_to_tgsi_visitor::visit(ir_dereference_variable *ir) switch (var->data.mode) { case ir_var_uniform: entry = new(mem_ctx) variable_storage(var, PROGRAM_UNIFORM, - var->data.location); + var->data.param_index); this->variables.push_tail(entry); break; case ir_var_shader_in: @@ -3147,19 +3160,17 @@ glsl_to_tgsi_visitor::visit_atomic_counter_intrinsic(ir_call *ir) /* Calculate the surface offset */ st_src_reg offset; - ir_dereference_array *deref_array = deref->as_dereference_array(); - - if (deref_array) { - offset = get_temp(glsl_type::uint_type); + unsigned array_size = 0, base = 0, index = 0; - deref_array->array_index->accept(this); + get_deref_offsets(deref, &array_size, &base, &index, &offset); + if (offset.file != PROGRAM_UNDEFINED) { emit_asm(ir, TGSI_OPCODE_MUL, st_dst_reg(offset), - this->result, st_src_reg_for_int(ATOMIC_COUNTER_SIZE)); + offset, st_src_reg_for_int(ATOMIC_COUNTER_SIZE)); emit_asm(ir, TGSI_OPCODE_ADD, st_dst_reg(offset), - offset, st_src_reg_for_int(location->data.offset)); + offset, st_src_reg_for_int(location->data.offset + index * ATOMIC_COUNTER_SIZE)); } else { - offset = st_src_reg_for_int(location->data.offset); + offset = st_src_reg_for_int(location->data.offset + index * ATOMIC_COUNTER_SIZE); } ir->return_deref->accept(this); @@ -3437,17 +3448,112 @@ glsl_to_tgsi_visitor::visit(ir_call *ir) } void +glsl_to_tgsi_visitor::calc_deref_offsets(ir_dereference *head, + ir_dereference *tail, + unsigned *array_elements, + unsigned *base, + unsigned *index, + st_src_reg *indirect, + unsigned *location) +{ + switch (tail->ir_type) { + case ir_type_dereference_record: { + ir_dereference_record *deref_record = tail->as_dereference_record(); + const glsl_type *struct_type = deref_record->record->type; + int field_index = deref_record->record->type->field_index(deref_record->field); + + calc_deref_offsets(head, deref_record->record->as_dereference(), array_elements, base, index, indirect, location); + + assert(field_index >= 0); + *location += struct_type->record_location_offset(field_index); + break; + } + + case ir_type_dereference_array: { + ir_dereference_array *deref_arr = tail->as_dereference_array(); + ir_constant *array_index = deref_arr->array_index->constant_expression_value(); + + if (!array_index) { + st_src_reg temp_reg; + st_dst_reg temp_dst; + + temp_reg = get_temp(glsl_type::uint_type); + temp_dst = st_dst_reg(temp_reg); + temp_dst.writemask = 1; + + deref_arr->array_index->accept(this); + if (*array_elements != 1) + emit_asm(NULL, TGSI_OPCODE_MUL, temp_dst, this->result, st_src_reg_for_int(*array_elements)); + else + emit_asm(NULL, TGSI_OPCODE_MOV, temp_dst, this->result); + + if (indirect->file == PROGRAM_UNDEFINED) + *indirect = temp_reg; + else { + temp_dst = st_dst_reg(*indirect); + temp_dst.writemask = 1; + emit_asm(NULL, TGSI_OPCODE_ADD, temp_dst, *indirect, temp_reg); + } + } else + *index += array_index->value.u[0] * *array_elements; + + *array_elements *= deref_arr->array->type->length; + + calc_deref_offsets(head, deref_arr->array->as_dereference(), array_elements, base, index, indirect, location); + break; + } + default: + break; + } +} + +void +glsl_to_tgsi_visitor::get_deref_offsets(ir_dereference *ir, + unsigned *array_size, + unsigned *base, + unsigned *index, + st_src_reg *reladdr) +{ + GLuint shader = _mesa_program_enum_to_shader_stage(this->prog->Target); + unsigned location = 0; + ir_variable *var = ir->variable_referenced(); + + memset(reladdr, 0, sizeof(*reladdr)); + reladdr->file = PROGRAM_UNDEFINED; + + *base = 0; + *array_size = 1; + + assert(var); + location = var->data.location; + calc_deref_offsets(ir, ir, array_size, base, index, reladdr, &location); + + /* + * If we end up with no indirect then adjust the base to the index, + * and set the array size to 1. + */ + if (reladdr->file == PROGRAM_UNDEFINED) { + *base = *index; + *array_size = 1; + } + + if (location != 0xffffffff) { + *base += this->shader_program->UniformStorage[location].opaque[shader].index; + *index += this->shader_program->UniformStorage[location].opaque[shader].index; + } +} + +void glsl_to_tgsi_visitor::visit(ir_texture *ir) { st_src_reg result_src, coord, cube_sc, lod_info, projector, dx, dy; st_src_reg offset[MAX_GLSL_TEXTURE_OFFSET], sample_index, component; - st_src_reg levels_src; + st_src_reg levels_src, reladdr; st_dst_reg result_dst, coord_dst, cube_sc_dst; glsl_to_tgsi_instruction *inst = NULL; unsigned opcode = TGSI_OPCODE_NOP; const glsl_type *sampler_type = ir->sampler->type; - ir_rvalue *sampler_index = - _mesa_get_sampler_array_nonconst_index(ir->sampler); + unsigned sampler_array_size = 1, sampler_index = 0, sampler_base = 0; bool is_cube_array = false; unsigned i; @@ -3669,10 +3775,10 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir) coord_dst.writemask = WRITEMASK_XYZW; } - if (sampler_index) { - sampler_index->accept(this); - emit_arl(ir, sampler_reladdr, this->result); - } + get_deref_offsets(ir->sampler, &sampler_array_size, &sampler_base, + &sampler_index, &reladdr); + if (reladdr.file != PROGRAM_UNDEFINED) + emit_arl(ir, sampler_reladdr, reladdr); if (opcode == TGSI_OPCODE_TXD) inst = emit_asm(ir, opcode, result_dst, coord, dx, dy); @@ -3705,16 +3811,13 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir) if (ir->shadow_comparitor) inst->tex_shadow = GL_TRUE; - inst->sampler.index = _mesa_get_sampler_uniform_value(ir->sampler, - this->shader_program, - this->prog); - if (sampler_index) { + inst->sampler.index = sampler_index; + inst->sampler_array_size = sampler_array_size; + inst->sampler_base = sampler_base; + + if (reladdr.file != PROGRAM_UNDEFINED) { inst->sampler.reladdr = ralloc(mem_ctx, st_src_reg); - memcpy(inst->sampler.reladdr, &sampler_reladdr, sizeof(sampler_reladdr)); - inst->sampler_array_size = - ir->sampler->as_dereference_array()->array->type->array_size(); - } else { - inst->sampler_array_size = 1; + memcpy(inst->sampler.reladdr, &reladdr, sizeof(reladdr)); } if (ir->offset) { @@ -3915,7 +4018,7 @@ count_resources(glsl_to_tgsi_visitor *v, gl_program *prog) foreach_in_list(glsl_to_tgsi_instruction, inst, &v->instructions) { if (inst->info->is_tex) { for (int i = 0; i < inst->sampler_array_size; i++) { - unsigned idx = inst->sampler.index + i; + unsigned idx = inst->sampler_base + i; v->samplers_used |= 1 << idx; debug_assert(idx < (int)ARRAY_SIZE(v->sampler_types)); diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c index 385e26b946e..84b65369d80 100644 --- a/src/mesa/state_tracker/st_manager.c +++ b/src/mesa/state_tracker/st_manager.c @@ -28,6 +28,7 @@ #include "main/mtypes.h" #include "main/extensions.h" #include "main/context.h" +#include "main/debug_output.h" #include "main/texobj.h" #include "main/teximage.h" #include "main/texstate.h" @@ -635,6 +636,7 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi, struct pipe_context *pipe; struct gl_config mode; gl_api api; + unsigned ctx_flags = 0; if (!(stapi->profile_mask & (1 << attribs->profile))) return NULL; @@ -658,7 +660,10 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi, break; } - pipe = smapi->screen->context_create(smapi->screen, NULL, 0); + if (attribs->flags & ST_CONTEXT_FLAG_ROBUST_ACCESS) + ctx_flags |= PIPE_CONTEXT_ROBUST_BUFFER_ACCESS; + + pipe = smapi->screen->context_create(smapi->screen, NULL, ctx_flags); if (!pipe) { *error = ST_CONTEXT_ERROR_NO_MEMORY; return NULL; diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index b3954547418..624586e6d67 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -140,112 +140,54 @@ st_release_fp_variants(struct st_context *st, struct st_fragment_program *stfp) /** - * Delete a geometry program variant. Note the caller must unlink + * Delete a basic program variant. Note the caller must unlink * the variant from the linked list. */ static void -delete_gp_variant(struct st_context *st, struct st_gp_variant *gpv) +delete_basic_variant(struct st_context *st, struct st_basic_variant *v, + GLenum target) { - if (gpv->driver_shader) - cso_delete_geometry_shader(st->cso_context, gpv->driver_shader); - - free(gpv); -} - - -/** - * Free all variants of a geometry program. - */ -void -st_release_gp_variants(struct st_context *st, struct st_geometry_program *stgp) -{ - struct st_gp_variant *gpv; - - for (gpv = stgp->variants; gpv; ) { - struct st_gp_variant *next = gpv->next; - delete_gp_variant(st, gpv); - gpv = next; - } - - stgp->variants = NULL; - - if (stgp->tgsi.tokens) { - ureg_free_tokens(stgp->tgsi.tokens); - stgp->tgsi.tokens = NULL; - } -} - - -/** - * Delete a tessellation control program variant. Note the caller must unlink - * the variant from the linked list. - */ -static void -delete_tcp_variant(struct st_context *st, struct st_tcp_variant *tcpv) -{ - if (tcpv->driver_shader) - cso_delete_tessctrl_shader(st->cso_context, tcpv->driver_shader); - - free(tcpv); -} - - -/** - * Free all variants of a tessellation control program. - */ -void -st_release_tcp_variants(struct st_context *st, struct st_tessctrl_program *sttcp) -{ - struct st_tcp_variant *tcpv; - - for (tcpv = sttcp->variants; tcpv; ) { - struct st_tcp_variant *next = tcpv->next; - delete_tcp_variant(st, tcpv); - tcpv = next; - } - - sttcp->variants = NULL; - - if (sttcp->tgsi.tokens) { - ureg_free_tokens(sttcp->tgsi.tokens); - sttcp->tgsi.tokens = NULL; + if (v->driver_shader) { + switch (target) { + case GL_TESS_CONTROL_PROGRAM_NV: + cso_delete_tessctrl_shader(st->cso_context, v->driver_shader); + break; + case GL_TESS_EVALUATION_PROGRAM_NV: + cso_delete_tesseval_shader(st->cso_context, v->driver_shader); + break; + case GL_GEOMETRY_PROGRAM_NV: + cso_delete_geometry_shader(st->cso_context, v->driver_shader); + break; + default: + assert(!"this shouldn't occur"); + } } -} - -/** - * Delete a tessellation evaluation program variant. Note the caller must - * unlink the variant from the linked list. - */ -static void -delete_tep_variant(struct st_context *st, struct st_tep_variant *tepv) -{ - if (tepv->driver_shader) - cso_delete_tesseval_shader(st->cso_context, tepv->driver_shader); - - free(tepv); + free(v); } /** - * Free all variants of a tessellation evaluation program. + * Free all basic program variants. */ void -st_release_tep_variants(struct st_context *st, struct st_tesseval_program *sttep) +st_release_basic_variants(struct st_context *st, GLenum target, + struct st_basic_variant **variants, + struct pipe_shader_state *tgsi) { - struct st_tep_variant *tepv; + struct st_basic_variant *v; - for (tepv = sttep->variants; tepv; ) { - struct st_tep_variant *next = tepv->next; - delete_tep_variant(st, tepv); - tepv = next; + for (v = *variants; v; ) { + struct st_basic_variant *next = v->next; + delete_basic_variant(st, v, target); + v = next; } - sttep->variants = NULL; + *variants = NULL; - if (sttep->tgsi.tokens) { - ureg_free_tokens(sttep->tgsi.tokens); - sttep->tgsi.tokens = NULL; + if (tgsi->tokens) { + ureg_free_tokens(tgsi->tokens); + tgsi->tokens = NULL; } } @@ -1324,53 +1266,43 @@ st_translate_geometry_program(struct st_context *st, } -static struct st_gp_variant * -st_create_gp_variant(struct st_context *st, - struct st_geometry_program *stgp, - const struct st_gp_variant_key *key) -{ - struct pipe_context *pipe = st->pipe; - struct st_gp_variant *gpv; - - gpv = CALLOC_STRUCT(st_gp_variant); - if (!gpv) - return NULL; - - /* fill in new variant */ - gpv->driver_shader = pipe->create_gs_state(pipe, &stgp->tgsi); - gpv->key = *key; - return gpv; -} - - /** - * Get/create geometry program variant. + * Get/create a basic program variant. */ -struct st_gp_variant * -st_get_gp_variant(struct st_context *st, - struct st_geometry_program *stgp, - const struct st_gp_variant_key *key) +struct st_basic_variant * +st_get_basic_variant(struct st_context *st, + struct pipe_shader_state *tgsi, + struct st_basic_variant **variants) { - struct st_gp_variant *gpv; + struct pipe_context *pipe = st->pipe; + struct st_basic_variant *v; + struct st_basic_variant_key key; + + memset(&key, 0, sizeof(key)); + key.st = st->has_shareable_shaders ? NULL : st; /* Search for existing variant */ - for (gpv = stgp->variants; gpv; gpv = gpv->next) { - if (memcmp(&gpv->key, key, sizeof(*key)) == 0) { + for (v = *variants; v; v = v->next) { + if (memcmp(&v->key, &key, sizeof(key)) == 0) { break; } } - if (!gpv) { + if (!v) { /* create new */ - gpv = st_create_gp_variant(st, stgp, key); - if (gpv) { + v = CALLOC_STRUCT(st_basic_variant); + if (v) { + /* fill in new variant */ + v->driver_shader = pipe->create_gs_state(pipe, tgsi); + v->key = key; + /* insert into list */ - gpv->next = stgp->variants; - stgp->variants = gpv; + v->next = *variants; + *variants = v; } } - return gpv; + return v; } @@ -1399,56 +1331,6 @@ st_translate_tessctrl_program(struct st_context *st, } -static struct st_tcp_variant * -st_create_tcp_variant(struct st_context *st, - struct st_tessctrl_program *sttcp, - const struct st_tcp_variant_key *key) -{ - struct pipe_context *pipe = st->pipe; - struct st_tcp_variant *tcpv; - - tcpv = CALLOC_STRUCT(st_tcp_variant); - if (!tcpv) - return NULL; - - /* fill in new variant */ - tcpv->driver_shader = pipe->create_tcs_state(pipe, &sttcp->tgsi); - tcpv->key = *key; - return tcpv; -} - - -/** - * Get/create tessellation control program variant. - */ -struct st_tcp_variant * -st_get_tcp_variant(struct st_context *st, - struct st_tessctrl_program *sttcp, - const struct st_tcp_variant_key *key) -{ - struct st_tcp_variant *tcpv; - - /* Search for existing variant */ - for (tcpv = sttcp->variants; tcpv; tcpv = tcpv->next) { - if (memcmp(&tcpv->key, key, sizeof(*key)) == 0) { - break; - } - } - - if (!tcpv) { - /* create new */ - tcpv = st_create_tcp_variant(st, sttcp, key); - if (tcpv) { - /* insert into list */ - tcpv->next = sttcp->variants; - sttcp->variants = tcpv; - } - } - - return tcpv; -} - - /** * Translate a tessellation evaluation program to create a new variant. */ @@ -1496,70 +1378,20 @@ st_translate_tesseval_program(struct st_context *st, } -static struct st_tep_variant * -st_create_tep_variant(struct st_context *st, - struct st_tesseval_program *sttep, - const struct st_tep_variant_key *key) -{ - struct pipe_context *pipe = st->pipe; - struct st_tep_variant *tepv; - - tepv = CALLOC_STRUCT(st_tep_variant); - if (!tepv) - return NULL; - - /* fill in new variant */ - tepv->driver_shader = pipe->create_tes_state(pipe, &sttep->tgsi); - tepv->key = *key; - return tepv; -} - - -/** - * Get/create tessellation evaluation program variant. - */ -struct st_tep_variant * -st_get_tep_variant(struct st_context *st, - struct st_tesseval_program *sttep, - const struct st_tep_variant_key *key) -{ - struct st_tep_variant *tepv; - - /* Search for existing variant */ - for (tepv = sttep->variants; tepv; tepv = tepv->next) { - if (memcmp(&tepv->key, key, sizeof(*key)) == 0) { - break; - } - } - - if (!tepv) { - /* create new */ - tepv = st_create_tep_variant(st, sttep, key); - if (tepv) { - /* insert into list */ - tepv->next = sttep->variants; - sttep->variants = tepv; - } - } - - return tepv; -} - - /** * Vert/Geom/Frag programs have per-context variants. Free all the * variants attached to the given program which match the given context. */ static void -destroy_program_variants(struct st_context *st, struct gl_program *program) +destroy_program_variants(struct st_context *st, struct gl_program *target) { - if (!program || program == &_mesa_DummyProgram) + if (!target || target == &_mesa_DummyProgram) return; - switch (program->Target) { + switch (target->Target) { case GL_VERTEX_PROGRAM_ARB: { - struct st_vertex_program *stvp = (struct st_vertex_program *) program; + struct st_vertex_program *stvp = (struct st_vertex_program *) target; struct st_vp_variant *vpv, **prevPtr = &stvp->variants; for (vpv = stvp->variants; vpv; ) { @@ -1580,7 +1412,7 @@ destroy_program_variants(struct st_context *st, struct gl_program *program) case GL_FRAGMENT_PROGRAM_ARB: { struct st_fragment_program *stfp = - (struct st_fragment_program *) program; + (struct st_fragment_program *) target; struct st_fp_variant *fpv, **prevPtr = &stfp->variants; for (fpv = stfp->variants; fpv; ) { @@ -1599,71 +1431,37 @@ destroy_program_variants(struct st_context *st, struct gl_program *program) } break; case GL_GEOMETRY_PROGRAM_NV: - { - struct st_geometry_program *stgp = - (struct st_geometry_program *) program; - struct st_gp_variant *gpv, **prevPtr = &stgp->variants; - - for (gpv = stgp->variants; gpv; ) { - struct st_gp_variant *next = gpv->next; - if (gpv->key.st == st) { - /* unlink from list */ - *prevPtr = next; - /* destroy this variant */ - delete_gp_variant(st, gpv); - } - else { - prevPtr = &gpv->next; - } - gpv = next; - } - } - break; case GL_TESS_CONTROL_PROGRAM_NV: - { - struct st_tessctrl_program *sttcp = - (struct st_tessctrl_program *) program; - struct st_tcp_variant *tcpv, **prevPtr = &sttcp->variants; - - for (tcpv = sttcp->variants; tcpv; ) { - struct st_tcp_variant *next = tcpv->next; - if (tcpv->key.st == st) { - /* unlink from list */ - *prevPtr = next; - /* destroy this variant */ - delete_tcp_variant(st, tcpv); - } - else { - prevPtr = &tcpv->next; - } - tcpv = next; - } - } - break; case GL_TESS_EVALUATION_PROGRAM_NV: { - struct st_tesseval_program *sttep = - (struct st_tesseval_program *) program; - struct st_tep_variant *tepv, **prevPtr = &sttep->variants; - - for (tepv = sttep->variants; tepv; ) { - struct st_tep_variant *next = tepv->next; - if (tepv->key.st == st) { + struct st_geometry_program *gp = (struct st_geometry_program*)target; + struct st_tessctrl_program *tcp = (struct st_tessctrl_program*)target; + struct st_tesseval_program *tep = (struct st_tesseval_program*)target; + struct st_basic_variant **variants = + target->Target == GL_GEOMETRY_PROGRAM_NV ? &gp->variants : + target->Target == GL_TESS_CONTROL_PROGRAM_NV ? &tcp->variants : + target->Target == GL_TESS_EVALUATION_PROGRAM_NV ? &tep->variants : + NULL; + struct st_basic_variant *v, **prevPtr = variants; + + for (v = *variants; v; ) { + struct st_basic_variant *next = v->next; + if (v->key.st == st) { /* unlink from list */ *prevPtr = next; /* destroy this variant */ - delete_tep_variant(st, tepv); + delete_basic_variant(st, v, target->Target); } else { - prevPtr = &tepv->next; + prevPtr = &v->next; } - tepv = next; + v = next; } } break; default: _mesa_problem(NULL, "Unexpected program target 0x%x in " - "destroy_program_variants_cb()", program->Target); + "destroy_program_variants_cb()", target->Target); } } @@ -1789,31 +1587,19 @@ st_precompile_shader_variant(struct st_context *st, case GL_TESS_CONTROL_PROGRAM_NV: { struct st_tessctrl_program *p = (struct st_tessctrl_program *)prog; - struct st_tcp_variant_key key; - - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - st_get_tcp_variant(st, p, &key); + st_get_basic_variant(st, &p->tgsi, &p->variants); break; } case GL_TESS_EVALUATION_PROGRAM_NV: { struct st_tesseval_program *p = (struct st_tesseval_program *)prog; - struct st_tep_variant_key key; - - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - st_get_tep_variant(st, p, &key); + st_get_basic_variant(st, &p->tgsi, &p->variants); break; } case GL_GEOMETRY_PROGRAM_NV: { struct st_geometry_program *p = (struct st_geometry_program *)prog; - struct st_gp_variant_key key; - - memset(&key, 0, sizeof(key)); - key.st = st->has_shareable_shaders ? NULL : st; - st_get_gp_variant(st, p, &key); + st_get_basic_variant(st, &p->tgsi, &p->variants); break; } diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index a74531581b4..7717d02cd3f 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -171,25 +171,24 @@ struct st_vertex_program -/** Geometry program variant key */ -struct st_gp_variant_key +/** Key shared by all shaders except VP, FP */ +struct st_basic_variant_key { struct st_context *st; /**< variants are per-context */ - /* no other fields yet */ }; /** * Geometry program variant. */ -struct st_gp_variant +struct st_basic_variant { /* Parameters which generated this variant. */ - struct st_gp_variant_key key; + struct st_basic_variant_key key; void *driver_shader; - struct st_gp_variant *next; + struct st_basic_variant *next; }; @@ -202,30 +201,7 @@ struct st_geometry_program struct pipe_shader_state tgsi; struct glsl_to_tgsi_visitor* glsl_to_tgsi; - struct st_gp_variant *variants; -}; - - - -/** Tessellation control program variant key */ -struct st_tcp_variant_key -{ - struct st_context *st; /**< variants are per-context */ - /* no other fields yet */ -}; - - -/** - * Tessellation control program variant. - */ -struct st_tcp_variant -{ - /* Parameters which generated this variant. */ - struct st_tcp_variant_key key; - - void *driver_shader; - - struct st_tcp_variant *next; + struct st_basic_variant *variants; }; @@ -238,30 +214,7 @@ struct st_tessctrl_program struct pipe_shader_state tgsi; struct glsl_to_tgsi_visitor* glsl_to_tgsi; - struct st_tcp_variant *variants; -}; - - - -/** Tessellation evaluation program variant key */ -struct st_tep_variant_key -{ - struct st_context *st; /**< variants are per-context */ - /* no other fields yet */ -}; - - -/** - * Tessellation evaluation program variant. - */ -struct st_tep_variant -{ - /* Parameters which generated this variant. */ - struct st_tep_variant_key key; - - void *driver_shader; - - struct st_tep_variant *next; + struct st_basic_variant *variants; }; @@ -274,7 +227,7 @@ struct st_tesseval_program struct pipe_shader_state tgsi; struct glsl_to_tgsi_visitor* glsl_to_tgsi; - struct st_tep_variant *variants; + struct st_basic_variant *variants; }; @@ -397,21 +350,10 @@ st_get_fp_variant(struct st_context *st, struct st_fragment_program *stfp, const struct st_fp_variant_key *key); - -extern struct st_gp_variant * -st_get_gp_variant(struct st_context *st, - struct st_geometry_program *stgp, - const struct st_gp_variant_key *key); - -extern struct st_tcp_variant * -st_get_tcp_variant(struct st_context *st, - struct st_tessctrl_program *sttcp, - const struct st_tcp_variant_key *key); - -extern struct st_tep_variant * -st_get_tep_variant(struct st_context *st, - struct st_tesseval_program *sttep, - const struct st_tep_variant_key *key); +extern struct st_basic_variant * +st_get_basic_variant(struct st_context *st, + struct pipe_shader_state *tgsi, + struct st_basic_variant **variants); extern void st_release_vp_variants( struct st_context *st, @@ -422,16 +364,9 @@ st_release_fp_variants( struct st_context *st, struct st_fragment_program *stfp ); extern void -st_release_gp_variants(struct st_context *st, - struct st_geometry_program *stgp); - -extern void -st_release_tcp_variants(struct st_context *st, - struct st_tessctrl_program *sttcp); - -extern void -st_release_tep_variants(struct st_context *st, - struct st_tesseval_program *sttep); +st_release_basic_variants(struct st_context *st, GLenum target, + struct st_basic_variant **variants, + struct pipe_shader_state *tgsi); extern void st_destroy_program_variants(struct st_context *st); |