diff options
author | Younes Manton <[email protected]> | 2010-04-30 20:42:30 -0400 |
---|---|---|
committer | Younes Manton <[email protected]> | 2010-04-30 20:42:30 -0400 |
commit | a8ea1dacc63ac567498049e5756c247b9fec6cd9 (patch) | |
tree | 4031e2e2b6166bd926b43fa4bbb3aab773a30ee5 /src/mesa/shader | |
parent | 404fb63b4649f58fce443615e49337d42b8ddece (diff) | |
parent | 35d960cc744c374ccaad48c3d80559b59c74e28a (diff) |
Merge branch 'master' of ssh://git.freedesktop.org/git/mesa/mesa into pipe-video
Conflicts:
src/gallium/auxiliary/Makefile
src/gallium/auxiliary/SConscript
src/gallium/auxiliary/util/u_format.csv
src/gallium/auxiliary/vl/vl_compositor.c
src/gallium/auxiliary/vl/vl_compositor.h
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h
src/gallium/drivers/identity/id_objects.c
src/gallium/drivers/identity/id_objects.h
src/gallium/drivers/identity/id_screen.c
src/gallium/drivers/nv40/Makefile
src/gallium/drivers/nv40/nv40_screen.c
src/gallium/drivers/softpipe/sp_texture.c
src/gallium/drivers/softpipe/sp_texture.h
src/gallium/drivers/softpipe/sp_video_context.c
src/gallium/drivers/softpipe/sp_video_context.h
src/gallium/include/pipe/p_format.h
src/gallium/include/pipe/p_screen.h
src/gallium/include/pipe/p_video_context.h
src/gallium/include/pipe/p_video_state.h
src/gallium/include/state_tracker/dri1_api.h
src/gallium/include/state_tracker/drm_api.h
src/gallium/state_trackers/dri/common/dri_context.c
src/gallium/state_trackers/xorg/xvmc/attributes.c
src/gallium/state_trackers/xorg/xvmc/block.c
src/gallium/state_trackers/xorg/xvmc/context.c
src/gallium/state_trackers/xorg/xvmc/subpicture.c
src/gallium/state_trackers/xorg/xvmc/surface.c
src/gallium/state_trackers/xorg/xvmc/tests/.gitignore
src/gallium/state_trackers/xorg/xvmc/tests/Makefile
src/gallium/state_trackers/xorg/xvmc/xvmc_private.h
src/gallium/winsys/drm/radeon/core/radeon_drm.c
src/gallium/winsys/g3dvl/vl_winsys.h
src/gallium/winsys/g3dvl/xlib/xsp_winsys.c
src/gallium/winsys/sw/Makefile
Diffstat (limited to 'src/mesa/shader')
-rw-r--r-- | src/mesa/shader/lex.yy.c | 38 | ||||
-rw-r--r-- | src/mesa/shader/nvfragparse.c | 2 | ||||
-rw-r--r-- | src/mesa/shader/nvvertparse.c | 2 | ||||
-rw-r--r-- | src/mesa/shader/prog_execute.c | 2 | ||||
-rw-r--r-- | src/mesa/shader/prog_instruction.h | 4 | ||||
-rw-r--r-- | src/mesa/shader/prog_parameter.c | 5 | ||||
-rw-r--r-- | src/mesa/shader/prog_parameter.h | 3 | ||||
-rw-r--r-- | src/mesa/shader/program.c | 4 | ||||
-rw-r--r-- | src/mesa/shader/program_lexer.l | 8 | ||||
-rw-r--r-- | src/mesa/shader/program_parse.tab.c | 9 | ||||
-rw-r--r-- | src/mesa/shader/program_parse.y | 9 | ||||
-rw-r--r-- | src/mesa/shader/program_parser.h | 2 | ||||
-rw-r--r-- | src/mesa/shader/shader_api.c | 83 | ||||
-rw-r--r-- | src/mesa/shader/shader_api.h | 9 | ||||
-rw-r--r-- | src/mesa/shader/slang/library/slang_common_builtin.gc | 22 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_builtin.c | 68 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_builtin.h | 10 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 2 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile.c | 4 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_link.c | 109 |
20 files changed, 300 insertions, 95 deletions
diff --git a/src/mesa/shader/lex.yy.c b/src/mesa/shader/lex.yy.c index d1af35fedb6..4c5c644a6ed 100644 --- a/src/mesa/shader/lex.yy.c +++ b/src/mesa/shader/lex.yy.c @@ -53,6 +53,7 @@ typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN @@ -83,8 +84,6 @@ typedef unsigned int flex_uint32_t; #define UINT32_MAX (4294967295U) #endif -#endif /* ! C99 */ - #endif /* ! FLEXINT_H */ #ifdef __cplusplus @@ -158,15 +157,7 @@ typedef void* yyscan_t; /* Size of default input buffer. */ #ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else #define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ #endif /* The state buf must be large enough to hold one state per character in the main buffer. @@ -1161,7 +1152,7 @@ handle_ident(struct asm_parser_state *state, const char *text, YYSTYPE *lval) } while(0); #define YY_EXTRA_TYPE struct asm_parser_state * -#line 1165 "lex.yy.c" +#line 1156 "lex.yy.c" #define INITIAL 0 @@ -1298,12 +1289,7 @@ static int input (yyscan_t yyscanner ); /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else #define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */ @@ -1311,7 +1297,7 @@ static int input (yyscan_t yyscanner ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#define ECHO fwrite( yytext, yyleng, 1, yyout ) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -1322,7 +1308,7 @@ static int input (yyscan_t yyscanner ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - size_t n; \ + unsigned n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -1410,7 +1396,7 @@ YY_DECL #line 157 "program_lexer.l" -#line 1414 "lex.yy.c" +#line 1400 "lex.yy.c" yylval = yylval_param; @@ -2212,7 +2198,7 @@ case 142: YY_RULE_SETUP #line 326 "program_lexer.l" { - yylval->real = _mesa_strtod(yytext, NULL); + yylval->real = _mesa_strtof(yytext, NULL); return REAL; } YY_BREAK @@ -2224,7 +2210,7 @@ YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP #line 330 "program_lexer.l" { - yylval->real = _mesa_strtod(yytext, NULL); + yylval->real = _mesa_strtof(yytext, NULL); return REAL; } YY_BREAK @@ -2232,7 +2218,7 @@ case 144: YY_RULE_SETUP #line 334 "program_lexer.l" { - yylval->real = _mesa_strtod(yytext, NULL); + yylval->real = _mesa_strtof(yytext, NULL); return REAL; } YY_BREAK @@ -2240,7 +2226,7 @@ case 145: YY_RULE_SETUP #line 338 "program_lexer.l" { - yylval->real = _mesa_strtod(yytext, NULL); + yylval->real = _mesa_strtof(yytext, NULL); return REAL; } YY_BREAK @@ -2474,7 +2460,7 @@ YY_RULE_SETUP #line 481 "program_lexer.l" ECHO; YY_BREAK -#line 2478 "lex.yy.c" +#line 2464 "lex.yy.c" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -3242,8 +3228,8 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr , yyscan_t yyscanner) /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * @param bytes the byte buffer to scan + * @param len the number of bytes in the buffer pointed to by @a bytes. * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c index d03cb4e493b..0de3c5804d2 100644 --- a/src/mesa/shader/nvfragparse.c +++ b/src/mesa/shader/nvfragparse.c @@ -456,7 +456,7 @@ Parse_ScalarConstant(struct parse_state *parseState, GLfloat *number) { char *end = NULL; - *number = (GLfloat) _mesa_strtod((const char *) parseState->pos, &end); + *number = (GLfloat) _mesa_strtof((const char *) parseState->pos, &end); if (end && end > (char *) parseState->pos) { /* got a number */ diff --git a/src/mesa/shader/nvvertparse.c b/src/mesa/shader/nvvertparse.c index 631b315af3a..7332fc4780b 100644 --- a/src/mesa/shader/nvvertparse.c +++ b/src/mesa/shader/nvvertparse.c @@ -1096,7 +1096,7 @@ Parse_PrintInstruction(struct parse_state *parseState, struct prog_instruction * } } else { - srcReg->File = 0; + srcReg->File = PROGRAM_UNDEFINED; } /* semicolon */ diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c index 37750cc330a..0067512cfb2 100644 --- a/src/mesa/shader/prog_execute.c +++ b/src/mesa/shader/prog_execute.c @@ -1767,7 +1767,7 @@ _mesa_execute_program(GLcontext * ctx, break; case OPCODE_PRINT: { - if (inst->SrcReg[0].File != -1) { + if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) { GLfloat a[4]; fetch_vector4(&inst->SrcReg[0], machine, a); printf("%s%g, %g, %g, %g\n", (const char *) inst->Data, diff --git a/src/mesa/shader/prog_instruction.h b/src/mesa/shader/prog_instruction.h index 224350caac6..28c797a4ba8 100644 --- a/src/mesa/shader/prog_instruction.h +++ b/src/mesa/shader/prog_instruction.h @@ -97,8 +97,8 @@ #define COND_EQ 2 /**< equal to zero */ #define COND_LT 3 /**< less than zero */ #define COND_UN 4 /**< unordered (NaN) */ -#define COND_GE 5 /**< greater then or equal to zero */ -#define COND_LE 6 /**< less then or equal to zero */ +#define COND_GE 5 /**< greater than or equal to zero */ +#define COND_LE 6 /**< less than or equal to zero */ #define COND_NE 7 /**< not equal to zero */ #define COND_TR 8 /**< always true */ #define COND_FL 9 /**< always false */ diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c index 25bb4f3d441..aac488c79ab 100644 --- a/src/mesa/shader/prog_parameter.c +++ b/src/mesa/shader/prog_parameter.c @@ -376,7 +376,8 @@ _mesa_add_sampler(struct gl_program_parameter_list *paramList, */ GLint _mesa_add_varying(struct gl_program_parameter_list *paramList, - const char *name, GLuint size, GLbitfield flags) + const char *name, GLuint size, GLenum datatype, + GLbitfield flags) { GLint i = _mesa_lookup_parameter_index(paramList, -1, name); if (i >= 0 && paramList->Parameters[i].Type == PROGRAM_VARYING) { @@ -386,7 +387,7 @@ _mesa_add_varying(struct gl_program_parameter_list *paramList, else { /*assert(size == 4);*/ i = _mesa_add_parameter(paramList, PROGRAM_VARYING, name, - size, GL_NONE, NULL, NULL, flags); + size, datatype, NULL, NULL, flags); return i; } } diff --git a/src/mesa/shader/prog_parameter.h b/src/mesa/shader/prog_parameter.h index 1111c859769..cc3378ae201 100644 --- a/src/mesa/shader/prog_parameter.h +++ b/src/mesa/shader/prog_parameter.h @@ -146,7 +146,8 @@ _mesa_add_sampler(struct gl_program_parameter_list *paramList, extern GLint _mesa_add_varying(struct gl_program_parameter_list *paramList, - const char *name, GLuint size, GLbitfield flags); + const char *name, GLuint size, GLenum datatype, + GLbitfield flags); extern GLint _mesa_add_attribute(struct gl_program_parameter_list *paramList, diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index f4f701b5461..f77a7737530 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -625,7 +625,7 @@ replace_registers(struct prog_instruction *inst, GLuint numInst, GLuint i, j; for (i = 0; i < numInst; i++) { /* src regs */ - for (j = 0; j < _mesa_num_inst_src_regs(inst->Opcode); j++) { + for (j = 0; j < _mesa_num_inst_src_regs(inst[i].Opcode); j++) { if (inst[i].SrcReg[j].File == oldFile && inst[i].SrcReg[j].Index == oldIndex) { inst[i].SrcReg[j].File = newFile; @@ -652,7 +652,7 @@ adjust_param_indexes(struct prog_instruction *inst, GLuint numInst, { GLuint i, j; for (i = 0; i < numInst; i++) { - for (j = 0; j < _mesa_num_inst_src_regs(inst->Opcode); j++) { + for (j = 0; j < _mesa_num_inst_src_regs(inst[i].Opcode); j++) { GLuint f = inst[i].SrcReg[j].File; if (f == PROGRAM_CONSTANT || f == PROGRAM_UNIFORM || diff --git a/src/mesa/shader/program_lexer.l b/src/mesa/shader/program_lexer.l index 83bc5089d9e..fe18272cdba 100644 --- a/src/mesa/shader/program_lexer.l +++ b/src/mesa/shader/program_lexer.l @@ -324,19 +324,19 @@ ARRAYSHADOW2D { return_token_or_IDENTIFIER(require_ARB_fp && require return INTEGER; } {num}?{frac}{exp}? { - yylval->real = _mesa_strtod(yytext, NULL); + yylval->real = _mesa_strtof(yytext, NULL); return REAL; } {num}"."/[^.] { - yylval->real = _mesa_strtod(yytext, NULL); + yylval->real = _mesa_strtof(yytext, NULL); return REAL; } {num}{exp} { - yylval->real = _mesa_strtod(yytext, NULL); + yylval->real = _mesa_strtof(yytext, NULL); return REAL; } {num}"."{exp} { - yylval->real = _mesa_strtod(yytext, NULL); + yylval->real = _mesa_strtof(yytext, NULL); return REAL; } diff --git a/src/mesa/shader/program_parse.tab.c b/src/mesa/shader/program_parse.tab.c index 5679b649749..99c4b2baa5f 100644 --- a/src/mesa/shader/program_parse.tab.c +++ b/src/mesa/shader/program_parse.tab.c @@ -5557,24 +5557,25 @@ make_error_string(const char *fmt, ...) char *str; va_list args; - va_start(args, fmt); /* Call vsnprintf once to determine how large the final string is. Call it - * again to do the actual formatting. from the v_mesa_snprintf manual page: + * again to do the actual formatting. from the vsnprintf manual page: * * Upon successful return, these functions return the number of * characters printed (not including the trailing '\0' used to end * output to strings). */ + va_start(args, fmt); length = 1 + vsnprintf(NULL, 0, fmt, args); + va_end(args); str = malloc(length); if (str) { + va_start(args, fmt); vsnprintf(str, length, fmt, args); + va_end(args); } - va_end(args); - return str; } diff --git a/src/mesa/shader/program_parse.y b/src/mesa/shader/program_parse.y index d5fb0fac3ea..06c2db7a07e 100644 --- a/src/mesa/shader/program_parse.y +++ b/src/mesa/shader/program_parse.y @@ -2596,24 +2596,25 @@ make_error_string(const char *fmt, ...) char *str; va_list args; - va_start(args, fmt); /* Call vsnprintf once to determine how large the final string is. Call it - * again to do the actual formatting. from the v_mesa_snprintf manual page: + * again to do the actual formatting. from the vsnprintf manual page: * * Upon successful return, these functions return the number of * characters printed (not including the trailing '\0' used to end * output to strings). */ + va_start(args, fmt); length = 1 + vsnprintf(NULL, 0, fmt, args); + va_end(args); str = malloc(length); if (str) { + va_start(args, fmt); vsnprintf(str, length, fmt, args); + va_end(args); } - va_end(args); - return str; } diff --git a/src/mesa/shader/program_parser.h b/src/mesa/shader/program_parser.h index 730466c30f5..be952d4b9c8 100644 --- a/src/mesa/shader/program_parser.h +++ b/src/mesa/shader/program_parser.h @@ -62,7 +62,7 @@ struct asm_symbol { */ unsigned param_binding_swizzle; - /* This is how many entries in the the program_parameter_list we take up + /* This is how many entries in the program_parameter_list we take up * with our state tokens or constants. Note that this is _not_ the same as * the number of param registers we eventually use. */ diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index 940fe2d03ce..4ff032d4ec8 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -123,6 +123,14 @@ _mesa_free_shader_program_data(GLcontext *ctx, free(shProg->InfoLog); shProg->InfoLog = NULL; } + + /* Transform feedback varying vars */ + for (i = 0; i < shProg->TransformFeedback.NumVarying; i++) { + free(shProg->TransformFeedback.VaryingNames[i]); + } + free(shProg->TransformFeedback.VaryingNames); + shProg->TransformFeedback.VaryingNames = NULL; + shProg->TransformFeedback.NumVarying = 0; } @@ -397,6 +405,25 @@ get_shader_flags(void) /** + * Find the length of the longest transform feedback varying name + * which was specified with glTransformFeedbackVaryings(). + */ +static GLint +longest_feedback_varying_name(const struct gl_shader_program *shProg) +{ + GLuint i; + GLint max = 0; + for (i = 0; i < shProg->TransformFeedback.NumVarying; i++) { + GLint len = strlen(shProg->TransformFeedback.VaryingNames[i]); + if (len > max) + max = len; + } + return max; +} + + + +/** * Initialize context's shader state. */ void @@ -437,8 +464,9 @@ _mesa_free_shader_state(GLcontext *ctx) * \param length returns number of chars copied * \param dst the string destination */ -static void -copy_string(GLchar *dst, GLsizei maxLength, GLsizei *length, const GLchar *src) +void +_mesa_copy_string(GLchar *dst, GLsizei maxLength, + GLsizei *length, const GLchar *src) { GLsizei len; for (len = 0; len < maxLength - 1 && src && src[len]; len++) @@ -754,8 +782,11 @@ _mesa_detach_shader(GLcontext *ctx, GLuint program, GLuint shader) } -static GLint -sizeof_glsl_type(GLenum type) +/** + * Return the size of the given GLSL datatype, in floats (components). + */ +GLint +_mesa_sizeof_glsl_type(GLenum type) { switch (type) { case GL_FLOAT: @@ -800,7 +831,7 @@ sizeof_glsl_type(GLenum type) case GL_FLOAT_MAT4x3: return 16; /* four float[4] vectors */ default: - _mesa_problem(NULL, "Invalid type in sizeof_glsl_type()"); + _mesa_problem(NULL, "Invalid type in _mesa_sizeof_glsl_type()"); return 1; } } @@ -879,11 +910,12 @@ _mesa_get_active_attrib(GLcontext *ctx, GLuint program, GLuint index, return; } - copy_string(nameOut, maxLength, length, attribs->Parameters[index].Name); + _mesa_copy_string(nameOut, maxLength, length, + attribs->Parameters[index].Name); if (size) *size = attribs->Parameters[index].Size - / sizeof_glsl_type(attribs->Parameters[index].DataType); + / _mesa_sizeof_glsl_type(attribs->Parameters[index].DataType); if (type) *type = attribs->Parameters[index].DataType; @@ -954,11 +986,11 @@ _mesa_get_active_uniform(GLcontext *ctx, GLuint program, GLuint index, param = &prog->Parameters->Parameters[progPos]; if (nameOut) { - copy_string(nameOut, maxLength, length, param->Name); + _mesa_copy_string(nameOut, maxLength, length, param->Name); } if (size) { - GLint typeSize = sizeof_glsl_type(param->DataType); + GLint typeSize = _mesa_sizeof_glsl_type(param->DataType); if ((GLint) param->Size > typeSize) { /* This is an array. * Array elements are placed on vector[4] boundaries so they're @@ -1063,6 +1095,17 @@ _mesa_get_programiv(GLcontext *ctx, GLuint program, case GL_PROGRAM_BINARY_LENGTH_OES: *params = 0; break; +#if FEATURE_EXT_transform_feedback + case GL_TRANSFORM_FEEDBACK_VARYINGS: + *params = shProg->TransformFeedback.NumVarying; + break; + case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: + *params = longest_feedback_varying_name(shProg) + 1; + break; + case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: + *params = shProg->TransformFeedback.BufferMode; + break; +#endif default: _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramiv(pname)"); return; @@ -1112,7 +1155,7 @@ _mesa_get_program_info_log(GLcontext *ctx, GLuint program, GLsizei bufSize, _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramInfoLog(program)"); return; } - copy_string(infoLog, bufSize, length, shProg->InfoLog); + _mesa_copy_string(infoLog, bufSize, length, shProg->InfoLog); } @@ -1125,7 +1168,7 @@ _mesa_get_shader_info_log(GLcontext *ctx, GLuint shader, GLsizei bufSize, _mesa_error(ctx, GL_INVALID_VALUE, "glGetShaderInfoLog(shader)"); return; } - copy_string(infoLog, bufSize, length, sh->InfoLog); + _mesa_copy_string(infoLog, bufSize, length, sh->InfoLog); } @@ -1141,7 +1184,7 @@ _mesa_get_shader_source(GLcontext *ctx, GLuint shader, GLsizei maxLength, if (!sh) { return; } - copy_string(sourceOut, maxLength, length, sh->Source); + _mesa_copy_string(sourceOut, maxLength, length, sh->Source); } @@ -1479,6 +1522,12 @@ _mesa_link_program(GLcontext *ctx, GLuint program) if (!shProg) return; + if (ctx->TransformFeedback.Active && shProg == ctx->Shader.CurrentProgram) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glLinkProgram(transform feedback active"); + return; + } + FLUSH_VERTICES(ctx, _NEW_PROGRAM); _slang_link(ctx, program, shProg); @@ -1543,6 +1592,12 @@ _mesa_use_program(GLcontext *ctx, GLuint program) { struct gl_shader_program *shProg; + if (ctx->TransformFeedback.Active) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glUseProgram(transform feedback active)"); + return; + } + if (ctx->Shader.CurrentProgram && ctx->Shader.CurrentProgram->Name == program) { /* no-op */ @@ -1731,7 +1786,7 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program, const GLboolean isUniformBool = is_boolean_type(param->DataType); const GLboolean areIntValues = is_integer_type(type); const GLint slots = (param->Size + 3) / 4; - const GLint typeSize = sizeof_glsl_type(param->DataType); + const GLint typeSize = _mesa_sizeof_glsl_type(param->DataType); GLsizei k, i; if ((GLint) param->Size > typeSize) { @@ -1920,7 +1975,7 @@ set_program_uniform_matrix(GLcontext *ctx, struct gl_program *program, GLuint src = 0; const struct gl_program_parameter * param = &program->Parameters->Parameters[index]; const GLuint slots = (param->Size + 3) / 4; - const GLint typeSize = sizeof_glsl_type(param->DataType); + const GLint typeSize = _mesa_sizeof_glsl_type(param->DataType); GLint nr, nc; /* check that the number of rows, columns is correct */ diff --git a/src/mesa/shader/shader_api.h b/src/mesa/shader/shader_api.h index d08d47373e1..597f0b8e75a 100644 --- a/src/mesa/shader/shader_api.h +++ b/src/mesa/shader/shader_api.h @@ -42,6 +42,15 @@ _mesa_init_shader_state(GLcontext * ctx); extern void _mesa_free_shader_state(GLcontext *ctx); + +extern void +_mesa_copy_string(GLchar *dst, GLsizei maxLength, + GLsizei *length, const GLchar *src); + +extern GLint +_mesa_sizeof_glsl_type(GLenum type); + + /* extern struct gl_shader_program * _mesa_new_shader_program(GLcontext *ctx, GLuint name); diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc index 8b7771c2846..d75354deffe 100644 --- a/src/mesa/shader/slang/library/slang_common_builtin.gc +++ b/src/mesa/shader/slang/library/slang_common_builtin.gc @@ -605,7 +605,7 @@ float sqrt(const float x) const float nx = -x; float r; __asm float_rsq r, x; - __asm float_rcp r, r; + r = r * x; __asm vec4_cmp __retVal, nx, r, 0.0; } @@ -615,8 +615,7 @@ vec2 sqrt(const vec2 x) vec2 r; __asm float_rsq r.x, x.x; __asm float_rsq r.y, x.y; - __asm float_rcp r.x, r.x; - __asm float_rcp r.y, r.y; + r = r * x; __asm vec4_cmp __retVal, nx, r, zero; } @@ -627,9 +626,7 @@ vec3 sqrt(const vec3 x) __asm float_rsq r.x, x.x; __asm float_rsq r.y, x.y; __asm float_rsq r.z, x.z; - __asm float_rcp r.x, r.x; - __asm float_rcp r.y, r.y; - __asm float_rcp r.z, r.z; + r = r * x; __asm vec4_cmp __retVal, nx, r, zero; } @@ -641,10 +638,7 @@ vec4 sqrt(const vec4 x) __asm float_rsq r.y, x.y; __asm float_rsq r.z, x.z; __asm float_rsq r.w, x.w; - __asm float_rcp r.x, r.x; - __asm float_rcp r.y, r.y; - __asm float_rcp r.z, r.z; - __asm float_rcp r.w, r.w; + r = r * x; __asm vec4_cmp __retVal, nx, r, zero; } @@ -695,7 +689,7 @@ vec3 normalize(const vec3 v) { // const float s = inversesqrt(dot(v, v)); // __retVal = v * s; -// XXX note, we _could_ use __retVal.w instead of tmp and and save a +// XXX note, we _could_ use __retVal.w instead of tmp and save a // register, but that's actually a compilation error because v is a vec3 // and the .w suffix is illegal. Oh well. float tmp; @@ -1166,7 +1160,7 @@ float length(const vec2 v) float r; const float p = dot(v, v); // p = v.x * v.x + v.y * v.y __asm float_rsq r, p; // r = 1 / sqrt(p) - __asm float_rcp __retVal.x, r; // retVal = 1 / r + __retVal = p * r; // p * r = sqrt(p); } float length(const vec3 v) @@ -1174,7 +1168,7 @@ float length(const vec3 v) float r; const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + v.z * v.z __asm float_rsq r, p; // r = 1 / sqrt(p) - __asm float_rcp __retVal, r; // retVal = 1 / r + __retVal = p * r; // p * r = sqrt(p); } float length(const vec4 v) @@ -1182,7 +1176,7 @@ float length(const vec4 v) float r; const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + ... __asm float_rsq r, p; // r = 1 / sqrt(p) - __asm float_rcp __retVal, r; // retVal = 1 / r + __retVal = p * r; // p * r = sqrt(p); } diff --git a/src/mesa/shader/slang/slang_builtin.c b/src/mesa/shader/slang/slang_builtin.c index 791e751526d..b7bf4e06dc8 100644 --- a/src/mesa/shader/slang/slang_builtin.c +++ b/src/mesa/shader/slang/slang_builtin.c @@ -752,7 +752,6 @@ static const struct input_info fragInputs[] = { { "gl_Color", FRAG_ATTRIB_COL0, GL_FLOAT_VEC4, SWIZZLE_NOOP }, { "gl_SecondaryColor", FRAG_ATTRIB_COL1, GL_FLOAT_VEC4, SWIZZLE_NOOP }, { "gl_TexCoord", FRAG_ATTRIB_TEX0, GL_FLOAT_VEC4, SWIZZLE_NOOP }, - /* note: we're packing several quantities into the fogcoord vector */ { "gl_FogFragCoord", FRAG_ATTRIB_FOGC, GL_FLOAT, SWIZZLE_XXXX }, { "gl_FrontFacing", FRAG_ATTRIB_FACE, GL_FLOAT, SWIZZLE_XXXX }, { "gl_PointCoord", FRAG_ATTRIB_PNTC, GL_FLOAT_VEC2, SWIZZLE_XYZW }, @@ -839,27 +838,28 @@ struct output_info { const char *Name; GLuint Attrib; + GLenum Type; }; /** Predefined vertex shader outputs */ static const struct output_info vertOutputs[] = { - { "gl_Position", VERT_RESULT_HPOS }, - { "gl_FrontColor", VERT_RESULT_COL0 }, - { "gl_BackColor", VERT_RESULT_BFC0 }, - { "gl_FrontSecondaryColor", VERT_RESULT_COL1 }, - { "gl_BackSecondaryColor", VERT_RESULT_BFC1 }, - { "gl_TexCoord", VERT_RESULT_TEX0 }, - { "gl_FogFragCoord", VERT_RESULT_FOGC }, - { "gl_PointSize", VERT_RESULT_PSIZ }, - { NULL, 0 } + { "gl_Position", VERT_RESULT_HPOS, GL_FLOAT_VEC4 }, + { "gl_FrontColor", VERT_RESULT_COL0, GL_FLOAT_VEC4 }, + { "gl_BackColor", VERT_RESULT_BFC0, GL_FLOAT_VEC4 }, + { "gl_FrontSecondaryColor", VERT_RESULT_COL1, GL_FLOAT_VEC4 }, + { "gl_BackSecondaryColor", VERT_RESULT_BFC1, GL_FLOAT_VEC4 }, + { "gl_TexCoord", VERT_RESULT_TEX0, GL_FLOAT_VEC4 }, + { "gl_FogFragCoord", VERT_RESULT_FOGC, GL_FLOAT }, + { "gl_PointSize", VERT_RESULT_PSIZ, GL_FLOAT }, + { NULL, 0, GL_NONE } }; /** Predefined fragment shader outputs */ static const struct output_info fragOutputs[] = { - { "gl_FragColor", FRAG_RESULT_COLOR }, - { "gl_FragDepth", FRAG_RESULT_DEPTH }, - { "gl_FragData", FRAG_RESULT_DATA0 }, - { NULL, 0 } + { "gl_FragColor", FRAG_RESULT_COLOR, GL_FLOAT_VEC4 }, + { "gl_FragDepth", FRAG_RESULT_DEPTH, GL_FLOAT }, + { "gl_FragData", FRAG_RESULT_DATA0, GL_FLOAT_VEC4 }, + { NULL, 0, GL_NONE } }; @@ -895,3 +895,43 @@ _slang_output_index(const char *name, GLenum target) } return -1; } + + +/** + * Given a VERT_RESULT_x index, return the corresponding string name. + */ +const char * +_slang_vertex_output_name(gl_vert_result index) +{ + if (index < Elements(vertOutputs)) + return vertOutputs[index].Name; + else + return NULL; +} + + +/** + * Given a FRAG_RESULT_x index, return the corresponding string name. + */ +const char * +_slang_fragment_output_name(gl_frag_result index) +{ + if (index < Elements(fragOutputs)) + return fragOutputs[index].Name; + else + return NULL; +} + + +/** + * Given a VERT_RESULT_x index, return the corresponding varying + * var's datatype. + */ +GLenum +_slang_vertex_output_type(gl_vert_result index) +{ + if (index < Elements(vertOutputs)) + return vertOutputs[index].Type; + else + return GL_NONE; +} diff --git a/src/mesa/shader/slang/slang_builtin.h b/src/mesa/shader/slang/slang_builtin.h index f814d11ac73..c3021ca33c7 100644 --- a/src/mesa/shader/slang/slang_builtin.h +++ b/src/mesa/shader/slang/slang_builtin.h @@ -51,4 +51,14 @@ extern GLenum _slang_vert_attrib_type(GLuint attrib); +const char * +_slang_vertex_output_name(gl_vert_result index); + +const char * +_slang_fragment_output_name(gl_frag_result index); + +GLenum +_slang_vertex_output_type(gl_vert_result index); + + #endif /* SLANG_BUILTIN_H */ diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index ecb2f6d5c1e..fa79632c18b 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -5130,7 +5130,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, flags |= PROG_PARAM_BIT_INVARIANT; varyingLoc = _mesa_add_varying(prog->Varying, varName, - totalSize, flags); + totalSize, GL_NONE, flags); swizzle = _slang_var_swizzle(size, 0); store = _slang_new_ir_storage_swz(PROGRAM_VARYING, varyingLoc, totalSize, swizzle); diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index b95c15fea61..ad866761570 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -246,7 +246,7 @@ parse_general_number(slang_parse_ctx *ctx, float *number) if (flt[strlen(flt) - 1] == 'f' || flt[strlen(flt) - 1] == 'F') { flt[strlen(flt) - 1] = '\0'; } - *number = (float)_mesa_strtod(flt, (char **)NULL); + *number = _mesa_strtof(flt, (char **)NULL); free(flt); return 1; @@ -312,7 +312,7 @@ parse_float(slang_parse_ctx * C, float *number) slang_string_concat(whole, "E"); slang_string_concat(whole, exponent); - *number = (float) (_mesa_strtod(whole, (char **) NULL)); + *number = _mesa_strtof(whole, (char **) NULL); _slang_free(whole); } diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index 7c7bfbdbc5e..f71fde1d727 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -87,6 +87,107 @@ bits_agree(GLbitfield flags1, GLbitfield flags2, GLbitfield bit) /** + * Examine the outputs/varyings written by the vertex shader and + * append the names of those outputs onto the Varyings list. + * This will only capture the pre-defined/built-in varyings like + * gl_Position, not user-defined varyings. + */ +static void +update_varying_var_list(GLcontext *ctx, struct gl_shader_program *shProg) +{ + if (shProg->VertexProgram) { + GLbitfield64 written = shProg->VertexProgram->Base.OutputsWritten; + GLuint i; + for (i = 0; written && i < VERT_RESULT_MAX; i++) { + if (written & BITFIELD64_BIT(i)) { + const char *name = _slang_vertex_output_name(i); + if (name) + _mesa_add_varying(shProg->Varying, name, 1, GL_FLOAT_VEC4, 0x0); + written &= ~BITFIELD64_BIT(i); + } + } + } +} + + +/** + * Do link error checking related to transform feedback. + */ +static GLboolean +link_transform_feedback(GLcontext *ctx, struct gl_shader_program *shProg) +{ + GLbitfield varyingMask; + GLuint totalComps, maxComps, i; + + if (shProg->TransformFeedback.NumVarying == 0) { + /* nothing to do */ + return GL_TRUE; + } + + /* Check that there's a vertex shader */ + if (shProg->TransformFeedback.NumVarying > 0 && + !shProg->VertexProgram) { + link_error(shProg, "Transform feedback without vertex shader"); + return GL_FALSE; + } + + /* Check that all named variables exist, and that none are duplicated. + * Also, build a count of the number of varying components to feedback. + */ + totalComps = 0; + varyingMask = 0x0; + for (i = 0; i < shProg->TransformFeedback.NumVarying; i++) { + const GLchar *name = shProg->TransformFeedback.VaryingNames[i]; + GLint v = _mesa_lookup_parameter_index(shProg->Varying, -1, name); + struct gl_program_parameter *p; + + if (v < 0) { + char msg[100]; + _mesa_snprintf(msg, sizeof(msg), + "vertex shader does not emit %s", name); + link_error(shProg, msg); + return GL_FALSE; + } + + assert(v < MAX_VARYING); + + /* already seen this varying name? */ + if (varyingMask & (1 << v)) { + char msg[100]; + _mesa_snprintf(msg, sizeof(msg), + "duplicated transform feedback varying name: %s", + name); + link_error(shProg, msg); + return GL_FALSE; + } + + varyingMask |= (1 << v); + + p = &shProg->Varying->Parameters[v]; + + totalComps += _mesa_sizeof_glsl_type(p->DataType); + } + + if (shProg->TransformFeedback.BufferMode == GL_INTERLEAVED_ATTRIBS) + maxComps = ctx->Const.MaxTransformFeedbackInterleavedComponents; + else + maxComps = ctx->Const.MaxTransformFeedbackSeparateComponents; + + /* check max varying components against the limit */ + if (totalComps > maxComps) { + char msg[100]; + _mesa_snprintf(msg, sizeof(msg), + "Too many feedback components: %u, max is %u", + totalComps, maxComps); + link_error(shProg, msg); + return GL_FALSE; + } + + return GL_TRUE; +} + + +/** * Linking varying vars involves rearranging varying vars so that the * vertex program's output varyings matches the order of the fragment * program's input varyings. @@ -157,7 +258,7 @@ link_varying_vars(GLcontext *ctx, else { /* not already in linked list */ j = _mesa_add_varying(shProg->Varying, var->Name, var->Size, - var->Flags); + var->DataType, var->Flags); } if (shProg->Varying->NumParameters > ctx->Const.MaxVarying) { @@ -866,6 +967,12 @@ _slang_link(GLcontext *ctx, } } + update_varying_var_list(ctx, shProg); + + /* checks related to transform feedback */ + if (!link_transform_feedback(ctx, shProg)) { + return; + } if (fragProg && shProg->FragmentProgram) { /* Compute initial program's TexturesUsed info */ |