summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/apps/compile.c4
-rw-r--r--src/glsl/apps/process.c4
-rw-r--r--src/glsl/pp/sl_pp_context.h4
-rw-r--r--src/glsl/pp/sl_pp_extension.c28
-rw-r--r--src/glsl/pp/sl_pp_if.c72
-rw-r--r--src/glsl/pp/sl_pp_public.h3
6 files changed, 58 insertions, 57 deletions
diff --git a/src/glsl/apps/compile.c b/src/glsl/apps/compile.c
index c9a830b9f3c..3b3c083c2e1 100644
--- a/src/glsl/apps/compile.c
+++ b/src/glsl/apps/compile.c
@@ -134,8 +134,8 @@ main(int argc,
return 0;
}
- if (sl_pp_context_add_extension(context, "ARB_draw_buffers", "GL_ARB_draw_buffers") ||
- sl_pp_context_add_extension(context, "ARB_texture_rectangle", "GL_ARB_texture_rectangle")) {
+ if (sl_pp_context_add_extension(context, "GL_ARB_draw_buffers") ||
+ sl_pp_context_add_extension(context, "GL_ARB_texture_rectangle")) {
fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context));
printf("Error: %s\n", sl_pp_context_error_message(context));
diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c
index 569890210f2..2d2ab911ac4 100644
--- a/src/glsl/apps/process.c
+++ b/src/glsl/apps/process.c
@@ -106,8 +106,8 @@ main(int argc,
return -1;
}
- if (sl_pp_context_add_extension(context, "ARB_draw_buffers", "GL_ARB_draw_buffers") ||
- sl_pp_context_add_extension(context, "ARB_texture_rectangle", "GL_ARB_texture_rectangle")) {
+ if (sl_pp_context_add_extension(context, "GL_ARB_draw_buffers") ||
+ sl_pp_context_add_extension(context, "GL_ARB_texture_rectangle")) {
fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context));
printf("Error: %s\n", sl_pp_context_error_message(context));
diff --git a/src/glsl/pp/sl_pp_context.h b/src/glsl/pp/sl_pp_context.h
index 3eada380cd1..983a09c02af 100644
--- a/src/glsl/pp/sl_pp_context.h
+++ b/src/glsl/pp/sl_pp_context.h
@@ -44,8 +44,8 @@
#define SL_PP_MAX_PREDEFINED 16
struct sl_pp_extension {
- int name; /*< VENDOR_extension_name */
- int name_string; /*< GL_VENDOR_extension_name */
+ int name; /*< GL_VENDOR_extension_name */
+ int enabled;
};
struct sl_pp_predefined {
diff --git a/src/glsl/pp/sl_pp_extension.c b/src/glsl/pp/sl_pp_extension.c
index 8af5731e840..777e42d0fc9 100644
--- a/src/glsl/pp/sl_pp_extension.c
+++ b/src/glsl/pp/sl_pp_extension.c
@@ -32,10 +32,15 @@
#include "sl_pp_public.h"
+/**
+ * Declare an extension to the preprocessor. This tells the preprocessor
+ * which extensions are supported by Mesa.
+ * The shader still needs to have a "#extension name: behavior" line to enable
+ * the extension.
+ */
int
sl_pp_context_add_extension(struct sl_pp_context *context,
- const char *name,
- const char *name_string)
+ const char *name)
{
struct sl_pp_extension ext;
@@ -48,15 +53,18 @@ sl_pp_context_add_extension(struct sl_pp_context *context,
return -1;
}
- ext.name_string = sl_pp_context_add_unique_str(context, name_string);
- if (ext.name_string == -1) {
- return -1;
- }
+ ext.enabled = 0;
context->extensions[context->num_extensions++] = ext;
+
+ assert(context->num_extensions <= sizeof(context->extensions));
+
return 0;
}
+/**
+ * Process a "#extension name: behavior" directive.
+ */
int
sl_pp_process_extension(struct sl_pp_context *context,
const struct sl_pp_token_info *input,
@@ -67,6 +75,7 @@ sl_pp_process_extension(struct sl_pp_context *context,
int extension_name = -1;
int behavior = -1;
struct sl_pp_token_info out;
+ struct sl_pp_extension *extension = NULL;
/* Grab the extension name. */
if (first < last && input[first].token == SL_PP_IDENTIFIER) {
@@ -86,8 +95,9 @@ sl_pp_process_extension(struct sl_pp_context *context,
out.data.extension = -1;
for (i = 0; i < context->num_extensions; i++) {
- if (extension_name == context->extensions[i].name_string) {
+ if (extension_name == context->extensions[i].name) {
out.data.extension = extension_name;
+ extension = &context->extensions[i];
break;
}
}
@@ -127,6 +137,7 @@ sl_pp_process_extension(struct sl_pp_context *context,
return -1;
}
out.token = SL_PP_EXTENSION_REQUIRE;
+ extension->enabled = 1;
} else if (behavior == context->dict.enable) {
if (out.data.extension == -1) {
/* Warning: the extension cannot be enabled. */
@@ -137,18 +148,21 @@ sl_pp_process_extension(struct sl_pp_context *context,
return -1;
}
out.token = SL_PP_EXTENSION_ENABLE;
+ extension->enabled = 1;
} else if (behavior == context->dict.warn) {
if (out.data.extension == -1) {
/* Warning: the extension is not supported. */
return 0;
}
out.token = SL_PP_EXTENSION_WARN;
+ extension->enabled = 0;
} else if (behavior == context->dict.disable) {
if (out.data.extension == -1) {
/* Warning: the extension is not supported. */
return 0;
}
out.token = SL_PP_EXTENSION_DISABLE;
+ extension->enabled = 0;
} else {
strcpy(context->error_msg, "unrecognised behavior name");
return -1;
diff --git a/src/glsl/pp/sl_pp_if.c b/src/glsl/pp/sl_pp_if.c
index f12f0f142c6..272c3a23cce 100644
--- a/src/glsl/pp/sl_pp_if.c
+++ b/src/glsl/pp/sl_pp_if.c
@@ -32,15 +32,35 @@
static int
+_macro_is_defined(struct sl_pp_context *context,
+ int macro_name)
+{
+ unsigned int i;
+ struct sl_pp_macro *macro;
+
+ for (i = 0; i < context->num_extensions; i++) {
+ if (macro_name == context->extensions[i].name) {
+ return context->extensions[i].enabled;
+ }
+ }
+
+ for (macro = context->macro; macro; macro = macro->next) {
+ if (macro_name == macro->name) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static int
_parse_defined(struct sl_pp_context *context,
struct sl_pp_token_buffer *buffer,
struct sl_pp_process_state *state)
{
struct sl_pp_token_info input;
int parens = 0;
- int macro_name;
- struct sl_pp_macro *macro;
- int defined = 0;
+ int defined;
struct sl_pp_token_info result;
if (sl_pp_token_buffer_skip_white(buffer, &input)) {
@@ -59,13 +79,7 @@ _parse_defined(struct sl_pp_context *context,
return -1;
}
- macro_name = input.data.identifier;
- for (macro = context->macro; macro; macro = macro->next) {
- if (macro->name == macro_name) {
- defined = 1;
- break;
- }
- }
+ defined = _macro_is_defined(context, input.data.identifier);
if (parens) {
if (sl_pp_token_buffer_skip_white(buffer, &input)) {
@@ -218,22 +232,9 @@ sl_pp_process_ifdef(struct sl_pp_context *context,
for (i = first; i < last; i++) {
switch (input[i].token) {
case SL_PP_IDENTIFIER:
- {
- struct sl_pp_macro *macro;
- int macro_name = input[i].data.identifier;
- int defined = 0;
-
- for (macro = context->macro; macro; macro = macro->next) {
- if (macro->name == macro_name) {
- defined = 1;
- break;
- }
- }
-
- context->if_ptr--;
- context->if_stack[context->if_ptr] = defined ? 1 : 0;
- context->if_value = _evaluate_if_stack(context);
- }
+ context->if_ptr--;
+ context->if_stack[context->if_ptr] = _macro_is_defined(context, input[i].data.identifier);
+ context->if_value = _evaluate_if_stack(context);
return 0;
case SL_PP_WHITESPACE:
@@ -265,22 +266,9 @@ sl_pp_process_ifndef(struct sl_pp_context *context,
for (i = first; i < last; i++) {
switch (input[i].token) {
case SL_PP_IDENTIFIER:
- {
- struct sl_pp_macro *macro;
- int macro_name = input[i].data.identifier;
- int defined = 0;
-
- for (macro = context->macro; macro; macro = macro->next) {
- if (macro->name == macro_name) {
- defined = 1;
- break;
- }
- }
-
- context->if_ptr--;
- context->if_stack[context->if_ptr] = defined ? 0 : 1;
- context->if_value = _evaluate_if_stack(context);
- }
+ context->if_ptr--;
+ context->if_stack[context->if_ptr] = !_macro_is_defined(context, input[i].data.identifier);
+ context->if_value = _evaluate_if_stack(context);
return 0;
case SL_PP_WHITESPACE:
diff --git a/src/glsl/pp/sl_pp_public.h b/src/glsl/pp/sl_pp_public.h
index 12528d6f8d1..ca6f722543d 100644
--- a/src/glsl/pp/sl_pp_public.h
+++ b/src/glsl/pp/sl_pp_public.h
@@ -53,8 +53,7 @@ sl_pp_context_error_position(const struct sl_pp_context *context,
int
sl_pp_context_add_extension(struct sl_pp_context *context,
- const char *name,
- const char *name_string);
+ const char *name);
int
sl_pp_context_add_predefined(struct sl_pp_context *context,