From aff8e204d205b5d424d2c39a5d9e004caaa1eab1 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 13 Dec 2006 14:48:36 -0700 Subject: Checkpoint new GLSL compiler back-end to produce fp/vp-style assembly instructions. --- src/mesa/shader/slang/slang_codegen.h | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/mesa/shader/slang/slang_codegen.h (limited to 'src/mesa/shader/slang/slang_codegen.h') diff --git a/src/mesa/shader/slang/slang_codegen.h b/src/mesa/shader/slang/slang_codegen.h new file mode 100644 index 00000000000..042737b2b5c --- /dev/null +++ b/src/mesa/shader/slang/slang_codegen.h @@ -0,0 +1,39 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5.3 + * + * Copyright (C) 2005-2007 Brian Paul 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 + * BRIAN PAUL 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 SLANG_CODEGEN_H +#define SLANG_CODEGEN_H + + +#include "imports.h" +#include "slang_compile.h" +#include "slang_ir.h" + + +extern struct slang_ir_node_ * +_slang_codegen_function(slang_assemble_ctx *A , struct slang_function_ *fun); + + +#endif /* SLANG_CODEGEN_H */ -- cgit v1.2.3 From 5cf7326132a37f11357b5cb31bcc9238fef5b54c Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 5 Jan 2007 16:02:45 -0700 Subject: Checkpoint glsl compiler work: sampler uniforms now implemented, linked properly. --- src/mesa/shader/shader_api.c | 9 +- .../shader/slang/library/slang_common_builtin.gc | 43 ++--- .../shader/slang/library/slang_common_builtin_gc.h | 179 ++++++++++----------- .../shader/slang/library/slang_fragment_builtin.gc | 26 +-- .../slang/library/slang_fragment_builtin_gc.h | 99 +++++------- src/mesa/shader/slang/slang_codegen.c | 92 ++++++++++- src/mesa/shader/slang/slang_codegen.h | 3 + src/mesa/shader/slang/slang_compile.c | 67 +------- src/mesa/shader/slang/slang_emit.c | 42 +++-- src/mesa/shader/slang/slang_ir.h | 1 - src/mesa/shader/slang/slang_link.h | 5 + src/mesa/shader/slang/slang_link2.c | 77 ++++++--- 12 files changed, 359 insertions(+), 284 deletions(-) (limited to 'src/mesa/shader/slang/slang_codegen.h') diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index d6dacdd6793..bd258f8737b 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -741,7 +741,8 @@ _mesa_get_uniform_location(GLcontext *ctx, GLuint program, const GLchar *name) * We need to handle things like "e.c[0].b" as seen in the * GLSL orange book, page 189. */ - if (u->Type == PROGRAM_UNIFORM && !strcmp(u->Name, name)) { + if ((u->Type == PROGRAM_UNIFORM || + u->Type == PROGRAM_SAMPLER) && !strcmp(u->Name, name)) { return loc; } } @@ -925,6 +926,12 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count, return; } } + + if (shProg->Uniforms->Parameters[location].Type == PROGRAM_SAMPLER) { + _slang_resolve_samplers(shProg, &shProg->VertexProgram->Base); + _slang_resolve_samplers(shProg, &shProg->FragmentProgram->Base); + FLUSH_VERTICES(ctx, _NEW_TEXTURE); + } } diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc index 44e059f5a0d..52f5b96d888 100644 --- a/src/mesa/shader/slang/library/slang_common_builtin.gc +++ b/src/mesa/shader/slang/library/slang_common_builtin.gc @@ -1611,36 +1611,43 @@ bvec4 not (const bvec4 v) -// -// 8.7 Texture Lookup Functions -// +//// Texture Lookup Functions (for both fragment and vertex shaders) -vec4 texture1D (sampler1D sampler, float coord) { - vec4 texel; - __asm vec4_tex1d texel, sampler, coord, 0.0; - return texel; +vec4 texture1D(const sampler1D sampler, const float coord) +{ + __asm vec4_tex1d __retVal, coord; // XXX sampler } -vec4 texture1DProj (sampler1D sampler, vec2 coord) { - return texture1D (sampler, coord.s / coord.t); +vec4 texture1DProj(const sampler1D sampler, const vec2 coord) +{ + float pcoord = coord.s / coord.t; + __asm vec4_tex1d __retVal, pcoord; // XXX sampler } -vec4 texture1DProj (sampler1D sampler, vec4 coord) { - return texture1D (sampler, coord.s / coord.q); +vec4 texture1DProj(const sampler1D sampler, const vec4 coord) +{ + float pcoord = coord.s / coord.q; + __asm vec4_tex1d __retVal, pcoord; // XXX sampler } + vec4 texture2D(const sampler2D sampler, const vec2 coord) { - __asm vec4_tex2d __retVal, coord; // XXX sampler + __asm vec4_tex2d __retVal, sampler, coord; // XXX sampler } -vec4 texture2DProj (sampler2D sampler, vec3 coord) { - return texture2D (sampler, vec2 (coord.s / coord.p, coord.t / coord.p)); -} +//vec4 texture2DProj(const sampler2D sampler, const vec3 coord) +//{ +// vec2 pcoord = coord.st / coord.p; +// __asm vec4_tex2d __retVal, pcoord; // XXX sampler +//} + +//vec4 texture2DProj(const sampler2D sampler, const vec4 coord) +//{ +// vec2 pcoord = coord.st / coord.q; +// __asm vec4_tex2d __retVal, pcoord; // XXX sampler +//} -vec4 texture2DProj (sampler2D sampler, vec4 coord) { - return texture2D (sampler, vec2 (coord.s / coord.q, coord.t / coord.q)); -} vec4 texture3D (sampler3D sampler, vec3 coord) { vec4 texel; diff --git a/src/mesa/shader/slang/library/slang_common_builtin_gc.h b/src/mesa/shader/slang/library/slang_common_builtin_gc.h index 69c1960c737..e418f532139 100644 --- a/src/mesa/shader/slang/library/slang_common_builtin_gc.h +++ b/src/mesa/shader/slang/library/slang_common_builtin_gc.h @@ -670,100 +670,93 @@ 111,116,0,1,1,0,3,118,0,0,0,1,4,118,101,99,52,95,115,101,113,0,18,95,95,114,101,116,86,97,108,0,59, 120,121,122,0,0,18,118,0,0,17,48,0,48,0,0,0,0,0,1,0,4,0,110,111,116,0,1,1,0,4,118,0,0,0,1,4,118, 101,99,52,95,115,101,113,0,18,95,95,114,101,116,86,97,108,0,0,18,118,0,0,17,48,0,48,0,0,0,0,0,1,0, -12,0,116,101,120,116,117,114,101,49,68,0,1,0,0,16,115,97,109,112,108,101,114,0,0,1,0,0,9,99,111, -111,114,100,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4,118,101,99,52,95,116,101,120,49,100,0, -18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0,0,17,48,0,48, -0,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,116,101,120,116,117,114,101,49,68,80,114,111,106,0, -1,0,0,16,115,97,109,112,108,101,114,0,0,1,0,0,10,99,111,111,114,100,0,0,0,1,8,58,116,101,120,116, -117,114,101,49,68,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0,59,115,0,18,99,111, -111,114,100,0,59,116,0,49,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,49,68,80,114,111,106,0,1,0, -0,16,115,97,109,112,108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0,0,1,8,58,116,101,120,116,117, -114,101,49,68,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0,59,115,0,18,99,111,111, -114,100,0,59,113,0,49,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,50,68,0,1,1,0,17,115,97,109,112, -108,101,114,0,0,1,1,0,10,99,111,111,114,100,0,0,0,1,4,118,101,99,52,95,116,101,120,50,100,0,18,95, -95,114,101,116,86,97,108,0,0,18,99,111,111,114,100,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,50, -68,80,114,111,106,0,1,0,0,17,115,97,109,112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,0,1,8, -58,116,101,120,116,117,114,101,50,68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,50,0,18,99, -111,111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,112,0,49,0,18,99,111,111,114,100,0,59,116,0, -18,99,111,111,114,100,0,59,112,0,49,0,0,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,50,68,80,114, -111,106,0,1,0,0,17,115,97,109,112,108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0,0,1,8,58,116,101, -120,116,117,114,101,50,68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,50,0,18,99,111,111,114, -100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,116,0,18,99,111, -111,114,100,0,59,113,0,49,0,0,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,51,68,0,1,0,0,18,115,97, -109,112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4, -118,101,99,52,95,116,101,120,51,100,0,18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114,0,0, -18,99,111,111,114,100,0,0,17,48,0,48,0,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,116,101,120, -116,117,114,101,51,68,80,114,111,106,0,1,0,0,18,115,97,109,112,108,101,114,0,0,1,0,0,12,99,111,111, -114,100,0,0,0,1,8,58,116,101,120,116,117,114,101,51,68,0,18,115,97,109,112,108,101,114,0,0,58,118, -101,99,51,0,18,99,111,111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111, -114,100,0,59,116,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,112,0,18,99, -111,111,114,100,0,59,113,0,49,0,0,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,67,117,98,101,0,1,0, -0,19,115,97,109,112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,0,1,3,2,0,12,1,116,101,120,101, -108,0,0,0,4,118,101,99,52,95,116,101,120,99,117,98,101,0,18,116,101,120,101,108,0,0,18,115,97,109, -112,108,101,114,0,0,18,99,111,111,114,100,0,0,17,48,0,48,0,0,0,0,8,18,116,101,120,101,108,0,0,0,1, -0,12,0,115,104,97,100,111,119,49,68,0,1,0,0,20,115,97,109,112,108,101,114,0,0,1,0,0,11,99,111,111, -114,100,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4,118,101,99,52,95,115,104,97,100,49,100,0,18, -116,101,120,101,108,0,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0,0,17,48,0,48,0,0, -0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,115,104,97,100,111,119,49,68,80,114,111,106,0,1,0,0,20, -115,97,109,112,108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0,0,1,8,58,115,104,97,100,111,119,49, -68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,51,0,18,99,111,111,114,100,0,59,115,0,18,99, -111,111,114,100,0,59,113,0,49,0,17,48,0,48,0,0,0,18,99,111,111,114,100,0,59,112,0,18,99,111,111, -114,100,0,59,113,0,49,0,0,0,0,0,0,1,0,12,0,115,104,97,100,111,119,50,68,0,1,0,0,21,115,97,109,112, -108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4,118,101, -99,52,95,115,104,97,100,50,100,0,18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114,0,0,18, -99,111,111,114,100,0,0,17,48,0,48,0,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,115,104,97,100, -111,119,50,68,80,114,111,106,0,1,0,0,21,115,97,109,112,108,101,114,0,0,1,0,0,12,99,111,111,114,100, -0,0,0,1,8,58,115,104,97,100,111,119,50,68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,51,0, +12,0,116,101,120,116,117,114,101,49,68,0,1,1,0,16,115,97,109,112,108,101,114,0,0,1,1,0,9,99,111, +111,114,100,0,0,0,1,4,118,101,99,52,95,116,101,120,49,100,0,18,95,95,114,101,116,86,97,108,0,0,18, +99,111,111,114,100,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,49,68,80,114,111,106,0,1,1,0,16, +115,97,109,112,108,101,114,0,0,1,1,0,10,99,111,111,114,100,0,0,0,1,3,2,0,9,1,112,99,111,111,114, +100,0,2,18,99,111,111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,116,0,49,0,0,4,118,101,99,52, +95,116,101,120,49,100,0,18,95,95,114,101,116,86,97,108,0,0,18,112,99,111,111,114,100,0,0,0,0,1,0, +12,0,116,101,120,116,117,114,101,49,68,80,114,111,106,0,1,1,0,16,115,97,109,112,108,101,114,0,0,1, +1,0,12,99,111,111,114,100,0,0,0,1,3,2,0,9,1,112,99,111,111,114,100,0,2,18,99,111,111,114,100,0,59, +115,0,18,99,111,111,114,100,0,59,113,0,49,0,0,4,118,101,99,52,95,116,101,120,49,100,0,18,95,95,114, +101,116,86,97,108,0,0,18,112,99,111,111,114,100,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,50,68, +0,1,1,0,17,115,97,109,112,108,101,114,0,0,1,1,0,10,99,111,111,114,100,0,0,0,1,4,118,101,99,52,95, +116,101,120,50,100,0,18,95,95,114,101,116,86,97,108,0,0,18,115,97,109,112,108,101,114,0,0,18,99, +111,111,114,100,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,51,68,0,1,0,0,18,115,97,109,112,108, +101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4,118,101,99, +52,95,116,101,120,51,100,0,18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114,0,0,18,99,111, +111,114,100,0,0,17,48,0,48,0,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,116,101,120,116,117,114, +101,51,68,80,114,111,106,0,1,0,0,18,115,97,109,112,108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0, +0,1,8,58,116,101,120,116,117,114,101,51,68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,51,0, 18,99,111,111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59, 116,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,112,0,18,99,111,111,114,100, -0,59,113,0,49,0,0,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,9,120,0,0,0,1,3,2,0,9,1,97,0,0,0, -4,102,108,111,97,116,95,110,111,105,115,101,49,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,9,0,110, -111,105,115,101,49,0,1,0,0,10,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97,116,95,110,111,105, -115,101,50,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,11,120,0, -0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97,116,95,110,111,105,115,101,51,0,18,97,0,0,18,120,0,0,0,8, -18,97,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,12,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111, -97,116,95,110,111,105,115,101,52,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,10,0,110,111,105,115, -101,50,0,1,0,0,9,120,0,0,0,1,8,58,118,101,99,50,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58, -110,111,105,115,101,49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101, -50,0,1,0,0,10,120,0,0,0,1,8,58,118,101,99,50,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110, -111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0, -0,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,11,120,0,0,0,1,8,58,118,101,99,50,0,58,110,111, -105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0, -51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101, -50,0,1,0,0,12,120,0,0,0,1,8,58,118,101,99,50,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110, -111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51, -0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,46,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,9,120,0, -0,0,1,8,58,118,101,99,51,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0, -18,120,0,17,49,57,0,51,52,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,46,0, -0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,10,120,0,0,0,1,8,58,118,101,99,51,0,58,110,111, +0,59,113,0,49,0,0,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,67,117,98,101,0,1,0,0,19,115,97,109, +112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4,118, +101,99,52,95,116,101,120,99,117,98,101,0,18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114, +0,0,18,99,111,111,114,100,0,0,17,48,0,48,0,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,115,104, +97,100,111,119,49,68,0,1,0,0,20,115,97,109,112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,0,1, +3,2,0,12,1,116,101,120,101,108,0,0,0,4,118,101,99,52,95,115,104,97,100,49,100,0,18,116,101,120,101, +108,0,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0,0,17,48,0,48,0,0,0,0,8,18,116, +101,120,101,108,0,0,0,1,0,12,0,115,104,97,100,111,119,49,68,80,114,111,106,0,1,0,0,20,115,97,109, +112,108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0,0,1,8,58,115,104,97,100,111,119,49,68,0,18,115, +97,109,112,108,101,114,0,0,58,118,101,99,51,0,18,99,111,111,114,100,0,59,115,0,18,99,111,111,114, +100,0,59,113,0,49,0,17,48,0,48,0,0,0,18,99,111,111,114,100,0,59,112,0,18,99,111,111,114,100,0,59, +113,0,49,0,0,0,0,0,0,1,0,12,0,115,104,97,100,111,119,50,68,0,1,0,0,21,115,97,109,112,108,101,114,0, +0,1,0,0,11,99,111,111,114,100,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4,118,101,99,52,95,115, +104,97,100,50,100,0,18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114, +100,0,0,17,48,0,48,0,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,115,104,97,100,111,119,50,68,80, +114,111,106,0,1,0,0,21,115,97,109,112,108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0,0,1,8,58,115, +104,97,100,111,119,50,68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,51,0,18,99,111,111,114, +100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,116,0,18,99,111, +111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,112,0,18,99,111,111,114,100,0,59,113,0,49,0, +0,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,9,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97, +116,95,110,111,105,115,101,49,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,9,0,110,111,105,115,101, +49,0,1,0,0,10,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97,116,95,110,111,105,115,101,50,0,18, +97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,11,120,0,0,0,1,3,2,0,9,1, +97,0,0,0,4,102,108,111,97,116,95,110,111,105,115,101,51,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0, +9,0,110,111,105,115,101,49,0,1,0,0,12,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97,116,95,110, +111,105,115,101,52,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0, +9,120,0,0,0,1,8,58,118,101,99,50,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115, +101,49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,10, +120,0,0,0,1,8,58,118,101,99,50,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101, +49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0,0,0,0,0,0,1,0, +10,0,110,111,105,115,101,50,0,1,0,0,11,120,0,0,0,1,8,58,118,101,99,50,0,58,110,111,105,115,101,49, +0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,17, +55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,12, +120,0,0,0,1,8,58,118,101,99,50,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101, +49,0,18,120,0,58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17, +50,0,55,55,0,0,0,0,46,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,9,120,0,0,0,1,8,58,118, +101,99,51,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,17,49, +57,0,51,52,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,46,0,0,0,0,0,0,1,0, +11,0,110,111,105,115,101,51,0,1,0,0,10,120,0,0,0,1,8,58,118,101,99,51,0,58,110,111,105,115,101,49, +0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,0,17, +55,0,54,54,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,53,0,52,55, +0,0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,11,120,0,0,0, +1,8,58,118,101,99,51,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18, +120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,0, +58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0, +17,49,49,0,48,52,0,0,0,0,46,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,12,120,0,0,0,1,8, +58,118,101,99,51,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0, +58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17,50,0,55,55,0, +0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,53,0,52,55,0,0,0,17,49, +55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,17,49,51,0,49,57,0,0,0,0,46,0,0,0,0,0,0,1,0,12,0,110,111, +105,115,101,52,0,1,0,0,9,120,0,0,0,1,8,58,118,101,99,52,0,58,110,111,105,115,101,49,0,18,120,0,0,0, +0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,0,58,110,111,105,115,101,49,0, +18,120,0,17,53,0,52,55,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,17,50,51,0,53,52,0,0,46,0, +0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,10,120,0,0,0,1,8,58,118,101,99,52,0,58,110,111, 105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0, 51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0, -17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0, -0,11,120,0,0,0,1,8,58,118,101,99,51,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105, -115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51, -0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,53,0,52,55,0,0,0,17,49, -55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,0,46,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0, -12,120,0,0,0,1,8,58,118,101,99,51,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115, -101,49,0,18,120,0,58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0, -0,17,50,0,55,55,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,53,0, -52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,17,49,51,0,49,57,0,0,0,0,46,0,0,0,0,0,0, -1,0,12,0,110,111,105,115,101,52,0,1,0,0,9,120,0,0,0,1,8,58,118,101,99,52,0,58,110,111,105,115,101, -49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,0,58,110,111, -105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,17,50,51, -0,53,52,0,0,46,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,10,120,0,0,0,1,8,58,118,101,99, -52,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99, -50,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58, -118,101,99,50,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0, -18,120,0,58,118,101,99,50,0,17,50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,0,46,0,0,0,0,0,0,1,0,12, -0,110,111,105,115,101,52,0,1,0,0,11,120,0,0,0,1,8,58,118,101,99,52,0,58,110,111,105,115,101,49,0, -18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,17, -55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99, -51,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,0,46,0,0,0,58,110,111,105, -115,101,49,0,18,120,0,58,118,101,99,51,0,17,50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,17,51,49,0, -57,49,0,0,0,0,46,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,12,120,0,0,0,1,8,58,118,101, -99,52,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101, -99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,46,0, -0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0, -0,0,17,49,49,0,48,52,0,0,0,17,49,51,0,49,57,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0, -58,118,101,99,52,0,17,50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,17,51,49,0,57,49,0,0,0,17,51,55,0, -52,56,0,0,0,0,46,0,0,0,0,0,0,0 +17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118, +101,99,50,0,17,50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,0,46,0,0,0,0,0,0,1,0,12,0,110,111,105, +115,101,52,0,1,0,0,11,120,0,0,0,1,8,58,118,101,99,52,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0, +58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0, +17,51,0,50,51,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,53,0,52, +55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18, +120,0,58,118,101,99,51,0,17,50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,17,51,49,0,57,49,0,0,0,0,46, +0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,12,120,0,0,0,1,8,58,118,101,99,52,0,58,110,111, +105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,49,57,0, +51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,46,0,0,0,58,110,111,105, +115,101,49,0,18,120,0,58,118,101,99,52,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48, +52,0,0,0,17,49,51,0,49,57,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0, +17,50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,17,51,49,0,57,49,0,0,0,17,51,55,0,52,56,0,0,0,0,46,0, +0,0,0,0,0,0 diff --git a/src/mesa/shader/slang/library/slang_fragment_builtin.gc b/src/mesa/shader/slang/library/slang_fragment_builtin.gc index 373b42de1d5..474535bfb1a 100644 --- a/src/mesa/shader/slang/library/slang_fragment_builtin.gc +++ b/src/mesa/shader/slang/library/slang_fragment_builtin.gc @@ -60,19 +60,19 @@ vec4 texture1DProj (sampler1D sampler, vec4 coord, float bias) { return texture1D (sampler, coord.s / coord.q, bias); } -vec4 texture2D (sampler2D sampler, vec2 coord, float bias) { - vec4 texel; - __asm vec4_tex2d texel, sampler, coord, bias; - return texel; -} - -vec4 texture2DProj (sampler2D sampler, vec3 coord, float bias) { - return texture2D (sampler, vec2 (coord.s / coord.p, coord.t / coord.p), bias); -} - -vec4 texture2DProj (sampler2D sampler, vec4 coord, float bias) { - return texture2D (sampler, vec2 (coord.s / coord.q, coord.t / coord.q), bias); -} +//vec4 texture2D (sampler2D sampler, vec2 coord, float bias) { +// vec4 texel; +// __asm vec4_tex2d texel, sampler, coord, bias; +// return texel; +//} + +//vec4 texture2DProj (sampler2D sampler, vec3 coord, float bias) { +// return texture2D (sampler, vec2 (coord.s / coord.p, coord.t / coord.p), bias); +//} + +//vec4 texture2DProj (sampler2D sampler, vec4 coord, float bias) { +// return texture2D (sampler, vec2 (coord.s / coord.q, coord.t / coord.q), bias); +//} vec4 texture3D (sampler3D sampler, vec3 coord, float bias) { vec4 texel; diff --git a/src/mesa/shader/slang/library/slang_fragment_builtin_gc.h b/src/mesa/shader/slang/library/slang_fragment_builtin_gc.h index b7f1d3816c1..69b90fb9da9 100644 --- a/src/mesa/shader/slang/library/slang_fragment_builtin_gc.h +++ b/src/mesa/shader/slang/library/slang_fragment_builtin_gc.h @@ -20,60 +20,47 @@ 1,0,0,16,115,97,109,112,108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0, 0,1,8,58,116,101,120,116,117,114,101,49,68,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114, 100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,0,18,98,105,97,115,0,0,0,0,0,1,0,12,0,116,101, -120,116,117,114,101,50,68,0,1,0,0,17,115,97,109,112,108,101,114,0,0,1,0,0,10,99,111,111,114,100,0, +120,116,117,114,101,51,68,0,1,0,0,18,115,97,109,112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0, 0,1,0,0,9,98,105,97,115,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4,118,101,99,52,95,116,101, -120,50,100,0,18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0, -0,18,98,105,97,115,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,116,101,120,116,117,114,101,50,68, -80,114,111,106,0,1,0,0,17,115,97,109,112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,1,0,0,9, -98,105,97,115,0,0,0,1,8,58,116,101,120,116,117,114,101,50,68,0,18,115,97,109,112,108,101,114,0,0, -58,118,101,99,50,0,18,99,111,111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,112,0,49,0,18,99, -111,111,114,100,0,59,116,0,18,99,111,111,114,100,0,59,112,0,49,0,0,0,18,98,105,97,115,0,0,0,0,0,1, -0,12,0,116,101,120,116,117,114,101,50,68,80,114,111,106,0,1,0,0,17,115,97,109,112,108,101,114,0,0, -1,0,0,12,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0,0,1,8,58,116,101,120,116,117,114,101,50, -68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,50,0,18,99,111,111,114,100,0,59,115,0,18,99, -111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,116,0,18,99,111,111,114,100,0,59,113,0, -49,0,0,0,18,98,105,97,115,0,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,51,68,0,1,0,0,18,115,97, -109,112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0,0,1,3,2,0,12,1, -116,101,120,101,108,0,0,0,4,118,101,99,52,95,116,101,120,51,100,0,18,116,101,120,101,108,0,0,18, -115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0,0,18,98,105,97,115,0,0,0,8,18,116,101,120, -101,108,0,0,0,1,0,12,0,116,101,120,116,117,114,101,51,68,80,114,111,106,0,1,0,0,18,115,97,109,112, -108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0,0,1,8,58,116,101,120,116, -117,114,101,51,68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,51,0,18,99,111,111,114,100,0, -59,115,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,116,0,18,99,111,111,114, -100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,112,0,18,99,111,111,114,100,0,59,113,0,49,0,0,0,18, -98,105,97,115,0,0,0,0,0,1,0,12,0,116,101,120,116,117,114,101,67,117,98,101,0,1,0,0,19,115,97,109, -112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0,0,1,3,2,0,12,1,116, -101,120,101,108,0,0,0,4,118,101,99,52,95,116,101,120,99,117,98,101,0,18,116,101,120,101,108,0,0,18, -115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0,0,18,98,105,97,115,0,0,0,8,18,116,101,120, -101,108,0,0,0,1,0,12,0,115,104,97,100,111,119,49,68,0,1,0,0,20,115,97,109,112,108,101,114,0,0,1,0, -0,11,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4, -118,101,99,52,95,115,104,97,100,49,100,0,18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114, -0,0,18,99,111,111,114,100,0,0,18,98,105,97,115,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,115, -104,97,100,111,119,49,68,80,114,111,106,0,1,0,0,20,115,97,109,112,108,101,114,0,0,1,0,0,12,99,111, -111,114,100,0,0,1,0,0,9,98,105,97,115,0,0,0,1,8,58,115,104,97,100,111,119,49,68,0,18,115,97,109, -112,108,101,114,0,0,58,118,101,99,51,0,18,99,111,111,114,100,0,59,115,0,18,99,111,111,114,100,0,59, -113,0,49,0,17,48,0,48,0,0,0,18,99,111,111,114,100,0,59,112,0,18,99,111,111,114,100,0,59,113,0,49,0, -0,0,18,98,105,97,115,0,0,0,0,0,1,0,12,0,115,104,97,100,111,119,50,68,0,1,0,0,21,115,97,109,112,108, -101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0,0,1,3,2,0,12,1,116,101,120, -101,108,0,0,0,4,118,101,99,52,95,115,104,97,100,50,100,0,18,116,101,120,101,108,0,0,18,115,97,109, -112,108,101,114,0,0,18,99,111,111,114,100,0,0,18,98,105,97,115,0,0,0,8,18,116,101,120,101,108,0,0, -0,1,0,12,0,115,104,97,100,111,119,50,68,80,114,111,106,0,1,0,0,21,115,97,109,112,108,101,114,0,0,1, -0,0,12,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0,0,1,8,58,115,104,97,100,111,119,50,68,0,18, -115,97,109,112,108,101,114,0,0,58,118,101,99,51,0,18,99,111,111,114,100,0,59,115,0,18,99,111,111, -114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,116,0,18,99,111,111,114,100,0,59,113,0,49,0,18, -99,111,111,114,100,0,59,112,0,18,99,111,111,114,100,0,59,113,0,49,0,0,0,18,98,105,97,115,0,0,0,0,0, -1,0,9,0,100,70,100,120,0,1,0,0,9,112,0,0,0,1,8,17,48,0,48,48,49,0,0,0,0,1,0,10,0,100,70,100,120,0, -1,0,0,10,112,0,0,0,1,8,58,118,101,99,50,0,17,48,0,48,48,49,0,0,0,0,0,0,1,0,11,0,100,70,100,120,0,1, -0,0,11,112,0,0,0,1,8,58,118,101,99,51,0,17,48,0,48,48,49,0,0,0,0,0,0,1,0,12,0,100,70,100,120,0,1,0, -0,12,112,0,0,0,1,8,58,118,101,99,52,0,17,48,0,48,48,49,0,0,0,0,0,0,1,0,9,0,100,70,100,121,0,1,0,0, -9,112,0,0,0,1,8,17,48,0,48,48,49,0,0,0,0,1,0,10,0,100,70,100,121,0,1,0,0,10,112,0,0,0,1,8,58,118, -101,99,50,0,17,48,0,48,48,49,0,0,0,0,0,0,1,0,11,0,100,70,100,121,0,1,0,0,11,112,0,0,0,1,8,58,118, -101,99,51,0,17,48,0,48,48,49,0,0,0,0,0,0,1,0,12,0,100,70,100,121,0,1,0,0,12,112,0,0,0,1,8,58,118, -101,99,52,0,17,48,0,48,48,49,0,0,0,0,0,0,1,0,9,0,102,119,105,100,116,104,0,1,0,0,9,112,0,0,0,1,8, -58,97,98,115,0,58,100,70,100,120,0,18,112,0,0,0,0,0,58,97,98,115,0,58,100,70,100,121,0,18,112,0,0, -0,0,0,46,0,0,1,0,10,0,102,119,105,100,116,104,0,1,0,0,10,112,0,0,0,1,8,58,97,98,115,0,58,100,70, -100,120,0,18,112,0,0,0,0,0,58,97,98,115,0,58,100,70,100,121,0,18,112,0,0,0,0,0,46,0,0,1,0,11,0,102, -119,105,100,116,104,0,1,0,0,11,112,0,0,0,1,8,58,97,98,115,0,58,100,70,100,120,0,18,112,0,0,0,0,0, -58,97,98,115,0,58,100,70,100,121,0,18,112,0,0,0,0,0,46,0,0,1,0,12,0,102,119,105,100,116,104,0,1,0, -0,12,112,0,0,0,1,8,58,97,98,115,0,58,100,70,100,120,0,18,112,0,0,0,0,0,58,97,98,115,0,58,100,70, -100,121,0,18,112,0,0,0,0,0,46,0,0,0 +120,51,100,0,18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0, +0,18,98,105,97,115,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,116,101,120,116,117,114,101,51,68, +80,114,111,106,0,1,0,0,18,115,97,109,112,108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0,1,0,0,9, +98,105,97,115,0,0,0,1,8,58,116,101,120,116,117,114,101,51,68,0,18,115,97,109,112,108,101,114,0,0, +58,118,101,99,51,0,18,99,111,111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99, +111,111,114,100,0,59,116,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,112,0, +18,99,111,111,114,100,0,59,113,0,49,0,0,0,18,98,105,97,115,0,0,0,0,0,1,0,12,0,116,101,120,116,117, +114,101,67,117,98,101,0,1,0,0,19,115,97,109,112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,1, +0,0,9,98,105,97,115,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4,118,101,99,52,95,116,101,120,99, +117,98,101,0,18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0, +0,18,98,105,97,115,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,115,104,97,100,111,119,49,68,0,1, +0,0,20,115,97,109,112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0,0, +1,3,2,0,12,1,116,101,120,101,108,0,0,0,4,118,101,99,52,95,115,104,97,100,49,100,0,18,116,101,120, +101,108,0,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0,0,18,98,105,97,115,0,0,0,8, +18,116,101,120,101,108,0,0,0,1,0,12,0,115,104,97,100,111,119,49,68,80,114,111,106,0,1,0,0,20,115, +97,109,112,108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0,0,1,8,58,115, +104,97,100,111,119,49,68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,51,0,18,99,111,111,114, +100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,0,17,48,0,48,0,0,0,18,99,111,111,114,100,0,59, +112,0,18,99,111,111,114,100,0,59,113,0,49,0,0,0,18,98,105,97,115,0,0,0,0,0,1,0,12,0,115,104,97,100, +111,119,50,68,0,1,0,0,21,115,97,109,112,108,101,114,0,0,1,0,0,11,99,111,111,114,100,0,0,1,0,0,9,98, +105,97,115,0,0,0,1,3,2,0,12,1,116,101,120,101,108,0,0,0,4,118,101,99,52,95,115,104,97,100,50,100,0, +18,116,101,120,101,108,0,0,18,115,97,109,112,108,101,114,0,0,18,99,111,111,114,100,0,0,18,98,105, +97,115,0,0,0,8,18,116,101,120,101,108,0,0,0,1,0,12,0,115,104,97,100,111,119,50,68,80,114,111,106,0, +1,0,0,21,115,97,109,112,108,101,114,0,0,1,0,0,12,99,111,111,114,100,0,0,1,0,0,9,98,105,97,115,0,0, +0,1,8,58,115,104,97,100,111,119,50,68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,51,0,18,99, +111,111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,116,0, +18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,112,0,18,99,111,111,114,100,0,59, +113,0,49,0,0,0,18,98,105,97,115,0,0,0,0,0,1,0,9,0,100,70,100,120,0,1,0,0,9,112,0,0,0,1,8,17,48,0, +48,48,49,0,0,0,0,1,0,10,0,100,70,100,120,0,1,0,0,10,112,0,0,0,1,8,58,118,101,99,50,0,17,48,0,48,48, +49,0,0,0,0,0,0,1,0,11,0,100,70,100,120,0,1,0,0,11,112,0,0,0,1,8,58,118,101,99,51,0,17,48,0,48,48, +49,0,0,0,0,0,0,1,0,12,0,100,70,100,120,0,1,0,0,12,112,0,0,0,1,8,58,118,101,99,52,0,17,48,0,48,48, +49,0,0,0,0,0,0,1,0,9,0,100,70,100,121,0,1,0,0,9,112,0,0,0,1,8,17,48,0,48,48,49,0,0,0,0,1,0,10,0, +100,70,100,121,0,1,0,0,10,112,0,0,0,1,8,58,118,101,99,50,0,17,48,0,48,48,49,0,0,0,0,0,0,1,0,11,0, +100,70,100,121,0,1,0,0,11,112,0,0,0,1,8,58,118,101,99,51,0,17,48,0,48,48,49,0,0,0,0,0,0,1,0,12,0, +100,70,100,121,0,1,0,0,12,112,0,0,0,1,8,58,118,101,99,52,0,17,48,0,48,48,49,0,0,0,0,0,0,1,0,9,0, +102,119,105,100,116,104,0,1,0,0,9,112,0,0,0,1,8,58,97,98,115,0,58,100,70,100,120,0,18,112,0,0,0,0, +0,58,97,98,115,0,58,100,70,100,121,0,18,112,0,0,0,0,0,46,0,0,1,0,10,0,102,119,105,100,116,104,0,1, +0,0,10,112,0,0,0,1,8,58,97,98,115,0,58,100,70,100,120,0,18,112,0,0,0,0,0,58,97,98,115,0,58,100,70, +100,121,0,18,112,0,0,0,0,0,46,0,0,1,0,11,0,102,119,105,100,116,104,0,1,0,0,11,112,0,0,0,1,8,58,97, +98,115,0,58,100,70,100,120,0,18,112,0,0,0,0,0,58,97,98,115,0,58,100,70,100,121,0,18,112,0,0,0,0,0, +46,0,0,1,0,12,0,102,119,105,100,116,104,0,1,0,0,12,112,0,0,0,1,8,58,97,98,115,0,58,100,70,100,120, +0,18,112,0,0,0,0,0,58,97,98,115,0,58,100,70,100,121,0,18,112,0,0,0,0,0,46,0,0,0 diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 3b96ec0a887..90d17122b66 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -92,7 +92,9 @@ static slang_asm_info AsmInfo[] = { { "float_divide", IR_DIV, 1, 2 }, { "float_power", IR_POW, 1, 2 }, /* texture / sampler */ - { "vec4_tex2d", IR_TEX, 1, 1 }, + { "vec4_tex1d", IR_TEX, 1, 1 }, + { "vec4_texb1d", IR_TEXB, 1, 3 }, + { "vec4_tex2d", IR_TEX, 1, 2 }, { "vec4_texb2d", IR_TEXB, 1, 3 }, /* unary op */ { "int_to_float", IR_I_TO_F, 1, 1 }, @@ -196,7 +198,7 @@ new_var(slang_assemble_ctx *A, slang_operation *oper, oper->var = v; n->Swizzle = swizzle; n->Var = v; - slang_resolve_storage(A->codegen/**NULL**/, n, A->program); + slang_resolve_storage(A->codegen, n, A->program); return n; } @@ -801,10 +803,6 @@ _slang_gen_asm(slang_assemble_ctx *A, slang_operation *oper, free(n0); } - if (info->Opcode == IR_TEX || info->Opcode == IR_TEXB) { - n->TexTarget = TEXTURE_2D_INDEX; - } - return n; } @@ -1568,8 +1566,10 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) slang_print_function(fun, 1); #endif - A->program->Parameters = _mesa_new_parameter_list(); - A->program->Varying = _mesa_new_parameter_list(); + /* should have been allocated earlier: */ + assert(A->program->Parameters ); + assert(A->program->Varying); + A->codegen = _slang_new_codegen_context(); /*printf("** Begin Simplify\n");*/ @@ -1608,3 +1608,79 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) } +static GLint +sampler_to_texture_index(const slang_type_specifier_type type) +{ + switch (type) { + case slang_spec_sampler1D: + return TEXTURE_1D_INDEX; + case slang_spec_sampler2D: + return TEXTURE_2D_INDEX; + case slang_spec_sampler3D: + return TEXTURE_3D_INDEX; + case slang_spec_samplerCube: + return TEXTURE_CUBE_INDEX; + case slang_spec_sampler1DShadow: + return TEXTURE_1D_INDEX; /* XXX fix */ + case slang_spec_sampler2DShadow: + return TEXTURE_2D_INDEX; /* XXX fix */ + default: + return -1; + } +} + + + +static GLint +slang_alloc_sampler(struct gl_program *prog, const char *name) +{ + GLint i = _mesa_add_sampler(prog->Parameters, name); + return i; +} + + +/** + * Called by compiler when a global variable has been parsed/compiled. + * Here we examine the variable's type to determine what kind of register + * storage will be used. + * + * A uniform such as "gl_Position" will become the register specification + * (PROGRAM_OUTPUT, VERT_RESULT_HPOS). Or, uniform "gl_FogFragCoord" + * will be (PROGRAM_INPUT, FRAG_ATTRIB_FOGC). + * + * Samplers are interesting. For "uniform sampler2D tex;" we'll specify + * (PROGRAM_SAMPLER, index) where index is resolved at link-time to an + * actual texture unit (as specified by the user calling glUniform1i()). + */ +void +_slang_codegen_global_variable(slang_variable *var, struct gl_program *prog) +{ + GLint texIndex; + slang_ir_storage *store = NULL; + + texIndex = sampler_to_texture_index(var->type.specifier.type); + + if (texIndex != -1) { + /* Texture sampler: + * store->File = PROGRAM_SAMPLER + * store->Index = sampler uniform location + * store->Size = texture type index (1D, 2D, 3D, cube, etc) + */ + GLint samplerUniform = slang_alloc_sampler(prog, (char *) var->a_name); + store = _slang_new_ir_storage(PROGRAM_SAMPLER, samplerUniform, texIndex); + printf("SAMPLER "); + } + else if (var->type.qualifier == slang_qual_uniform) { + printf("UNIFORM "); + } + + printf("CODEGEN VAR %s\n", (char*) var->a_name); + + assert(!var->aux); +#if 1 + var->aux = store; +#endif + /** + XXX allocate variable storage (aux), at least the register file. + */ +} diff --git a/src/mesa/shader/slang/slang_codegen.h b/src/mesa/shader/slang/slang_codegen.h index 042737b2b5c..ef2ccd4ebf1 100644 --- a/src/mesa/shader/slang/slang_codegen.h +++ b/src/mesa/shader/slang/slang_codegen.h @@ -35,5 +35,8 @@ extern struct slang_ir_node_ * _slang_codegen_function(slang_assemble_ctx *A , struct slang_function_ *fun); +extern void +_slang_codegen_global_variable(slang_variable *var, struct gl_program *prog); + #endif /* SLANG_CODEGEN_H */ diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index da77de709c3..711849d72f9 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -803,25 +803,7 @@ parse_child_operation(slang_parse_ctx * C, slang_output_ctx * O, slang_operation *ch; /* grow child array */ -#if 000 - oper->children = (slang_operation *) - slang_alloc_realloc(oper->children, - oper->num_children * sizeof(slang_operation), - (oper->num_children + 1) * sizeof(slang_operation)); - if (oper->children == NULL) { - slang_info_log_memory(C->L); - return 0; - } - - ch = &oper->children[oper->num_children]; - if (!slang_operation_construct(ch)) { - slang_info_log_memory(C->L); - return 0; - } - oper->num_children++; -#else ch = slang_operation_grow(&oper->num_children, &oper->children); -#endif if (statement) return parse_statement(C, O, ch); return parse_expression(C, O, ch); @@ -860,44 +842,6 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, /* local variable declaration, individual declarators are stored as * children identifiers */ -#if 000 - oper->type = slang_oper_variable_decl; - { - const unsigned int first_var = O->vars->num_variables; - - /* parse the declaration, note that there can be zero or more - * than one declarators - */ - if (!parse_declaration(C, O)) - return 0; - if (first_var < O->vars->num_variables) { - const unsigned int num_vars = O->vars->num_variables - first_var; - unsigned int i; - - oper->children = (slang_operation *) - slang_alloc_malloc(num_vars * sizeof(slang_operation)); - if (oper->children == NULL) { - slang_info_log_memory(C->L); - return 0; - } - for (oper->num_children = 0; oper->num_children < num_vars; - oper->num_children++) { - if (!slang_operation_construct - (&oper->children[oper->num_children])) { - slang_info_log_memory(C->L); - return 0; - } - } - for (i = first_var; i < O->vars->num_variables; i++) { - slang_operation *o = &oper->children[i - first_var]; - o->type = slang_oper_identifier; - o->locals->outer_scope = O->vars; - o->a_id = O->vars->variables[i].a_name; - } - } - } -#else - oper->type = slang_oper_block_no_new_scope; { const unsigned int first_var = O->vars->num_variables; @@ -925,9 +869,6 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, } } } - - -#endif break; case OP_ASM: /* the __asm statement, parse the mnemonic and all its arguments @@ -1776,6 +1717,11 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, return 0; } +#if 1 + if (C->global_scope && O->program) + _slang_codegen_global_variable(var, O->program); +#endif + /* allocate global address space for a variable with a known size */ if (C->global_scope && !(var->type.specifier.type == slang_spec_array @@ -2309,6 +2255,9 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader) = (struct gl_program **) malloc(sizeof(struct gl_program*)); shader->Programs[0] = _mesa_new_program(ctx, progTarget, 1); shader->NumPrograms = 1; + + shader->Programs[0]->Parameters = _mesa_new_parameter_list(); + shader->Programs[0]->Varying = _mesa_new_parameter_list(); } slang_info_log_construct(&info_log); diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index a3d970694f9..3f1f1373c61 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -184,6 +184,7 @@ storage_string(const slang_ir_storage *st) "UNIFORM", "WRITE_ONLY", "ADDRESS", + "SAMPLER", "UNDEFINED" }; static char s[100]; @@ -194,10 +195,8 @@ storage_string(const slang_ir_storage *st) sprintf(s, "%s[%d..%d]", files[st->File], st->Index, st->Index + st->Size - 1); #endif - if (st->File == 1000) - sprintf(s, "sampler"); - else - sprintf(s, "%s[%d]", files[st->File], st->Index); + assert(st->File < sizeof(files) / sizeof(files[0])); + sprintf(s, "%s[%d]", files[st->File], st->Index); return s; } @@ -680,10 +679,12 @@ slang_resolve_storage(slang_gen_context *gc, slang_ir_node *n, assert(n->Var); if (is_sampler_type(&n->Var->type)) { /* i.e. "uniform sampler2D tex;" */ -#define PROGRAM_SAMPLER 1000 n->Store->File = PROGRAM_SAMPLER; n->Store->Size = 1; /* never used */ n->Store->Index = alloc_sampler(gc); + n->Store->Index = slang_alloc_uniform(prog, (char *) n->Var->a_name, 1); + printf("********** Alloc sampler uniform %d\n", n->Store->Index); + abort(); /* this is a locally-declared sampler */ } else if (n->Store->Index < 0) { /* XXX assert this? */ assert(gc); @@ -701,12 +702,18 @@ slang_resolve_storage(slang_gen_context *gc, slang_ir_node *n, return; } + /* + assert(!is_sampler_type(&n->Var->type)); + */ + if (n->Opcode == IR_VAR && n->Store->File == PROGRAM_UNDEFINED) { /* try to determine the storage for this variable */ GLint i; assert(n->Var); + /*if (is_sampler(*/ + if (n->Store->Size < 0) { /* determine var/storage size now */ n->Store->Size = sizeof_type(&n->Var->type); @@ -766,14 +773,7 @@ slang_resolve_storage(slang_gen_context *gc, slang_ir_node *n, else if (n->Var->type.qualifier == slang_qual_varying) { i = slang_alloc_varying(prog, (char *) n->Var->a_name); if (i >= 0) { -#ifdef OLD_LINK - if (prog->Target == GL_VERTEX_PROGRAM_ARB) - n->Store->File = PROGRAM_OUTPUT; - else - n->Store->File = PROGRAM_INPUT; -#else n->Store->File = PROGRAM_VARYING; -#endif n->Store->Index = i; return; } @@ -1023,14 +1023,24 @@ emit_tex(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) inst = new_instruction(prog, OPCODE_TXB); } + if (!n->Store) + slang_alloc_temp_storage(gc, n, 4); + storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask); - storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store, - n->Children[0]->Swizzle); + /* Child[1] is the coord */ + storage_to_src_reg(&inst->SrcReg[0], n->Children[1]->Store, + n->Children[1]->Swizzle); - inst->TexSrcTarget = n->TexTarget; - inst->TexSrcUnit = 0; /* XXX temp */ + /* Child[0] is the sampler (a uniform which'll indicate the texture unit) */ + assert(n->Children[0]->Store); + assert(n->Children[0]->Store->Size >= TEXTURE_1D_INDEX); + inst->Sampler = n->Children[0]->Store->Index; /* i.e. uniform's index */ + inst->TexSrcTarget = n->Children[0]->Store->Size; + inst->TexSrcUnit = 27; /* Dummy value; the TexSrcUnit will be computed at + * link time, using the sampler uniform's value. + */ return inst; } diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h index b43ff1db618..0613121b989 100644 --- a/src/mesa/shader/slang/slang_ir.h +++ b/src/mesa/shader/slang/slang_ir.h @@ -112,7 +112,6 @@ typedef struct slang_ir_node_ GLfloat Value[4]; /**< If Opcode == IR_FLOAT */ slang_variable *Var; slang_ir_storage *Store; - GLuint TexTarget; /**< If Opcode == IR_TEX or IR_TEXB */ } slang_ir_node; diff --git a/src/mesa/shader/slang/slang_link.h b/src/mesa/shader/slang/slang_link.h index f56d717873b..2fc5525000f 100644 --- a/src/mesa/shader/slang/slang_link.h +++ b/src/mesa/shader/slang/slang_link.h @@ -353,6 +353,11 @@ extern void _slang_link2(GLcontext *ctx, GLhandleARB h, struct gl_shader_program *shProg); +extern void +_slang_resolve_samplers(struct gl_shader_program *shProg, + struct gl_program *prog); + + #ifdef __cplusplus } #endif diff --git a/src/mesa/shader/slang/slang_link2.c b/src/mesa/shader/slang/slang_link2.c index 33813fecc4a..8b59d7f76a9 100644 --- a/src/mesa/shader/slang/slang_link2.c +++ b/src/mesa/shader/slang/slang_link2.c @@ -138,6 +138,7 @@ is_uniform(enum register_file file) file == PROGRAM_STATE_VAR || file == PROGRAM_NAMED_PARAM || file == PROGRAM_CONSTANT || + file == PROGRAM_SAMPLER || file == PROGRAM_UNIFORM); } @@ -148,7 +149,8 @@ link_uniform_vars(struct gl_shader_program *shProg, struct gl_program *prog) GLuint *map, i; #if 0 - _mesa_print_parameter_list(prog->Parameters); + printf("================ pre link uniforms ===============\n"); + _mesa_print_parameter_list(shProg->Uniforms); #endif map = (GLuint *) malloc(prog->Parameters->NumParameters * sizeof(GLuint)); @@ -201,6 +203,9 @@ link_uniform_vars(struct gl_shader_program *shProg, struct gl_program *prog) case PROGRAM_UNIFORM: j = _mesa_add_uniform(shProg->Uniforms, p->Name, p->Size); break; + case PROGRAM_SAMPLER: + j = _mesa_add_sampler(shProg->Uniforms, p->Name); + break; default: abort(); } @@ -218,6 +223,11 @@ link_uniform_vars(struct gl_shader_program *shProg, struct gl_program *prog) } +#if 0 + printf("================ post link uniforms ===============\n"); + _mesa_print_parameter_list(shProg->Uniforms); +#endif + #if 0 { GLuint i; @@ -244,7 +254,14 @@ link_uniform_vars(struct gl_shader_program *shProg, struct gl_program *prog) inst->SrcReg[j].Index = map[ inst->SrcReg[j].Index ]; } } - /* XXX update program OutputsWritten, InputsRead */ + + if (inst->Opcode == OPCODE_TEX || + inst->Opcode == OPCODE_TXB || + inst->Opcode == OPCODE_TXB) { + printf("====== remap sampler from %d to %d\n", + inst->Sampler, map[ inst->Sampler ]); + inst->Sampler = map[ inst->Sampler ]; + } } free(map); @@ -257,7 +274,7 @@ link_uniform_vars(struct gl_shader_program *shProg, struct gl_program *prog) * XXX Temporary */ static void -slang_resolve_branches(struct gl_program *prog) +_slang_resolve_branches(struct gl_program *prog) { struct target { const char *Name; @@ -293,22 +310,47 @@ slang_resolve_branches(struct gl_program *prog) } +/** + * Scan program for texture instructions, lookup sampler/uniform's value + * to determine which texture unit to use. + * Also, update the program's TexturesUsed[] array. + */ +void +_slang_resolve_samplers(struct gl_shader_program *shProg, + struct gl_program *prog) +{ + GLuint i; + + for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++) + prog->TexturesUsed[i] = 0; + + for (i = 0; i < prog->NumInstructions; i++) { + struct prog_instruction *inst = prog->Instructions + i; + if (inst->Opcode == OPCODE_TEX || + inst->Opcode == OPCODE_TXB || + inst->Opcode == OPCODE_TXB) { + GLint sampleUnit = (GLint) shProg->Uniforms->ParameterValues[inst->Sampler][0]; + assert(sampleUnit < MAX_TEXTURE_IMAGE_UNITS); + inst->TexSrcUnit = sampleUnit; + + prog->TexturesUsed[inst->TexSrcUnit] |= (1 << inst->TexSrcTarget); + } + } +} + + /** * Scan program instructions to update the program's InputsRead and * OutputsWritten fields. - * Also, update the program's TexturesUsed[] array. */ static void -slang_update_inputs_outputs(struct gl_program *prog) +_slang_update_inputs_outputs(struct gl_program *prog) { GLuint i, j; prog->InputsRead = 0x0; prog->OutputsWritten = 0x0; - for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++) - prog->TexturesUsed[i] = 0; - for (i = 0; i < prog->NumInstructions; i++) { const struct prog_instruction *inst = prog->Instructions + i; const GLuint numSrc = _mesa_num_inst_src_regs(inst->Opcode); @@ -320,12 +362,6 @@ slang_update_inputs_outputs(struct gl_program *prog) if (inst->DstReg.File == PROGRAM_OUTPUT) { prog->OutputsWritten |= 1 << inst->DstReg.Index; } - - if (inst->Opcode == OPCODE_TEX || - inst->Opcode == OPCODE_TXB || - inst->Opcode == OPCODE_TXP) { - prog->TexturesUsed[inst->TexSrcUnit] |= (1 << inst->TexSrcTarget); - } } } @@ -425,11 +461,14 @@ _slang_link2(GLcontext *ctx, shProg->VertexProgram->Base.Parameters = shProg->Uniforms; shProg->FragmentProgram->Base.Parameters = shProg->Uniforms; - slang_resolve_branches(&shProg->VertexProgram->Base); - slang_resolve_branches(&shProg->FragmentProgram->Base); - - slang_update_inputs_outputs(&shProg->VertexProgram->Base); - slang_update_inputs_outputs(&shProg->FragmentProgram->Base); + _slang_resolve_branches(&shProg->VertexProgram->Base); + _slang_resolve_branches(&shProg->FragmentProgram->Base); +#if 1 + _slang_resolve_samplers(shProg, &shProg->VertexProgram->Base); + _slang_resolve_samplers(shProg, &shProg->FragmentProgram->Base); +#endif + _slang_update_inputs_outputs(&shProg->VertexProgram->Base); + _slang_update_inputs_outputs(&shProg->FragmentProgram->Base); #if 1 printf("************** original fragment program\n"); -- cgit v1.2.3 From cf4d4342c905c9989abb2dcc5e38968db8aeaf57 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 8 Jan 2007 13:09:47 -0700 Subject: Checkpoint: re-org of (global) variable allocation code. More to come... --- src/mesa/shader/slang/slang_codegen.c | 176 ++++++++++++++++++++++++++++++++-- src/mesa/shader/slang/slang_codegen.h | 3 +- src/mesa/shader/slang/slang_compile.c | 6 +- src/mesa/shader/slang/slang_emit.c | 139 ++------------------------- 4 files changed, 184 insertions(+), 140 deletions(-) (limited to 'src/mesa/shader/slang/slang_codegen.h') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 90d17122b66..73ad20a73d9 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -1630,12 +1630,89 @@ sampler_to_texture_index(const slang_type_specifier_type type) } +/** + * XXX return size too + */ +static GLint +_slang_input_index(const char *name, GLenum target) +{ + struct input_info { + const char *Name; + GLuint Attrib; + }; + static const struct input_info vertInputs[] = { + { "gl_Vertex", VERT_ATTRIB_POS }, + { "gl_Normal", VERT_ATTRIB_NORMAL }, + { "gl_Color", VERT_ATTRIB_COLOR0 }, + { "gl_SecondaryColor", VERT_ATTRIB_COLOR1 }, + { "gl_FogCoord", VERT_ATTRIB_FOG }, + { "gl_MultiTexCoord0", VERT_ATTRIB_TEX0 }, + { "gl_MultiTexCoord1", VERT_ATTRIB_TEX1 }, + { "gl_MultiTexCoord2", VERT_ATTRIB_TEX2 }, + { "gl_MultiTexCoord3", VERT_ATTRIB_TEX3 }, + { "gl_MultiTexCoord4", VERT_ATTRIB_TEX4 }, + { "gl_MultiTexCoord5", VERT_ATTRIB_TEX5 }, + { "gl_MultiTexCoord6", VERT_ATTRIB_TEX6 }, + { "gl_MultiTexCoord7", VERT_ATTRIB_TEX7 }, + { NULL, 0 } + }; + static const struct input_info fragInputs[] = { + { "gl_FragCoord", FRAG_ATTRIB_WPOS }, + { "gl_Color", FRAG_ATTRIB_COL0 }, + { "gl_SecondaryColor", FRAG_ATTRIB_COL1 }, + { "gl_FogFragCoord", FRAG_ATTRIB_FOGC }, + { "gl_TexCoord", FRAG_ATTRIB_TEX0 }, + { NULL, 0 } + }; + GLuint i; + const struct input_info *inputs + = (target == GL_VERTEX_PROGRAM_ARB) ? vertInputs : fragInputs; + + for (i = 0; inputs[i].Name; i++) { + if (strcmp(inputs[i].Name, name) == 0) { + /* found */ + return inputs[i].Attrib; + } + } + return -1; +} + + static GLint -slang_alloc_sampler(struct gl_program *prog, const char *name) +_slang_output_index(const char *name, GLenum target) { - GLint i = _mesa_add_sampler(prog->Parameters, name); - return i; + struct output_info { + const char *Name; + GLuint Attrib; + }; + 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 }, /* XXX indexed */ + { "gl_FogFragCoord", VERT_RESULT_FOGC }, + { "gl_PointSize", VERT_RESULT_PSIZ }, + { NULL, 0 } + }; + static const struct output_info fragOutputs[] = { + { "gl_FragColor", FRAG_RESULT_COLR }, + { "gl_FragDepth", FRAG_RESULT_DEPR }, + { NULL, 0 } + }; + GLuint i; + const struct output_info *outputs + = (target == GL_VERTEX_PROGRAM_ARB) ? vertOutputs : fragOutputs; + + for (i = 0; outputs[i].Name; i++) { + if (strcmp(outputs[i].Name, name) == 0) { + /* found */ + return outputs[i].Attrib; + } + } + return -1; } @@ -1653,8 +1730,10 @@ slang_alloc_sampler(struct gl_program *prog, const char *name) * actual texture unit (as specified by the user calling glUniform1i()). */ void -_slang_codegen_global_variable(slang_variable *var, struct gl_program *prog) +_slang_codegen_global_variable(slang_variable *var, struct gl_program *prog, + slang_unit_type type) { + const char *varName = (char *) var->a_name; GLint texIndex; slang_ir_storage *store = NULL; @@ -1666,15 +1745,98 @@ _slang_codegen_global_variable(slang_variable *var, struct gl_program *prog) * store->Index = sampler uniform location * store->Size = texture type index (1D, 2D, 3D, cube, etc) */ - GLint samplerUniform = slang_alloc_sampler(prog, (char *) var->a_name); + GLint samplerUniform = _mesa_add_sampler(prog->Parameters, varName); store = _slang_new_ir_storage(PROGRAM_SAMPLER, samplerUniform, texIndex); printf("SAMPLER "); } else if (var->type.qualifier == slang_qual_uniform) { + /* Uniform variable */ + const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); + if (prog) { + /* user-defined uniform */ + GLint uniformLoc = _mesa_add_uniform(prog->Parameters, varName, size); + store = _slang_new_ir_storage(PROGRAM_UNIFORM, uniformLoc, size); + } + else { + /* pre-defined uniform, like gl_ModelviewMatrix */ + /* We know it's a uniform, but don't allocate storage unless + * it's really used. + */ + + store = _slang_new_ir_storage(PROGRAM_STATE_VAR, -1, size); + + } printf("UNIFORM "); } - - printf("CODEGEN VAR %s\n", (char*) var->a_name); + else if (var->type.qualifier == slang_qual_varying) { + const GLint size = 4; /* XXX fix */ + if (prog) { + /* user-defined varying */ + GLint varyingLoc = _mesa_add_varying(prog->Varying, varName, size); + store = _slang_new_ir_storage(PROGRAM_VARYING, varyingLoc, size); + } + else { + /* pre-defined varying, like gl_Color or gl_TexCoord */ + if (type == slang_unit_fragment_builtin) { + GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB); + assert(index >= 0); + store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); + assert(index < FRAG_ATTRIB_MAX); + } + else { + GLint index = _slang_output_index(varName, GL_VERTEX_PROGRAM_ARB); + assert(index >= 0); + assert(type == slang_unit_vertex_builtin); + store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); + assert(index < VERT_RESULT_MAX); + } + printf("V/F "); + } + printf("VARYING "); + } + else if (var->type.qualifier == slang_qual_const) { + if (prog) { + abort(); + } + else { + /* pre-defined global constant, like gl_MaxLights */ + GLint size = -1; + store = _slang_new_ir_storage(PROGRAM_CONSTANT, -1, size); + } + printf("CONST "); + } + else if (var->type.qualifier == slang_qual_attribute) { + /* Vertex attribute */ + GLint index = _slang_input_index(varName, GL_VERTEX_PROGRAM_ARB); + GLint size = 4; /* XXX? */ + assert(index >= 0); + store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); + printf("ATTRIB "); + } + else if (var->type.qualifier == slang_qual_fixedinput) { + GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB); + GLint size = 4; /* XXX? */ + store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); + printf("INPUT "); + } + else if (var->type.qualifier == slang_qual_fixedoutput) { + if (type == slang_unit_vertex_builtin) { + GLint index = _slang_output_index(varName, GL_VERTEX_PROGRAM_ARB); + GLint size = 4; /* XXX? */ + store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); + } + else { + assert(type == slang_unit_fragment_builtin); + GLint index = _slang_output_index(varName, GL_FRAGMENT_PROGRAM_ARB); + GLint size = 4; /* XXX? */ + store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); + } + printf("OUTPUT "); + } + else { + printf("other "); + } + printf("GLOBAL VAR %s idx %d\n", (char*) var->a_name, store?store->Index:-2); assert(!var->aux); #if 1 diff --git a/src/mesa/shader/slang/slang_codegen.h b/src/mesa/shader/slang/slang_codegen.h index ef2ccd4ebf1..ad8e2a4fd88 100644 --- a/src/mesa/shader/slang/slang_codegen.h +++ b/src/mesa/shader/slang/slang_codegen.h @@ -36,7 +36,8 @@ extern struct slang_ir_node_ * _slang_codegen_function(slang_assemble_ctx *A , struct slang_function_ *fun); extern void -_slang_codegen_global_variable(slang_variable *var, struct gl_program *prog); +_slang_codegen_global_variable(slang_variable *var, struct gl_program *prog, + slang_unit_type type); #endif /* SLANG_CODEGEN_H */ diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 711849d72f9..efb23255f94 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -233,6 +233,7 @@ typedef struct slang_parse_ctx_ int parsing_builtin; GLboolean global_scope; /**< Is object being declared a global? */ slang_atom_pool *atoms; + slang_unit_type type; /**< Vertex vs. Fragment */ } slang_parse_ctx; /* slang_output_ctx */ @@ -1718,8 +1719,8 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, } #if 1 - if (C->global_scope && O->program) - _slang_codegen_global_variable(var, O->program); + if (C->global_scope /*&& O->program*/) + _slang_codegen_global_variable(var, O->program, C->type); #endif /* allocate global address space for a variable with a known size */ @@ -1992,6 +1993,7 @@ compile_binary(const byte * prod, slang_code_unit * unit, C.parsing_builtin = (builtin == NULL); C.global_scope = GL_TRUE; C.atoms = &unit->object->atompool; + C.type = type; if (!check_revision(&C)) return GL_FALSE; diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 3f1f1373c61..4c952e2e0ae 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -420,91 +420,6 @@ free_temporary(slang_gen_context *gc, GLuint r, GLint size) } - -static GLint -slang_find_input(GLenum target, const char *name, GLint index) -{ - struct input_info { - const char *Name; - GLuint Attrib; - }; - static const struct input_info vertInputs[] = { - { "gl_Vertex", VERT_ATTRIB_POS }, - { "gl_Normal", VERT_ATTRIB_NORMAL }, - { "gl_Color", VERT_ATTRIB_COLOR0 }, - { "gl_SecondaryColor", VERT_ATTRIB_COLOR1 }, - { "gl_MultiTexCoord0", VERT_ATTRIB_TEX0 }, - { "gl_MultiTexCoord1", VERT_ATTRIB_TEX1 }, - { "gl_MultiTexCoord2", VERT_ATTRIB_TEX2 }, - { NULL, 0 } - }; - static const struct input_info fragInputs[] = { - { "gl_TexCoord", FRAG_ATTRIB_TEX0 }, - { NULL, 0 } - }; - const struct input_info *inputs; - GLuint i; - - if (target == GL_VERTEX_PROGRAM_ARB) { - inputs = vertInputs; - } - else { - assert(target == GL_FRAGMENT_PROGRAM_ARB); - inputs = fragInputs; - } - - for (i = 0; inputs[i].Name; i++) { - if (strcmp(inputs[i].Name, name) == 0) { - /* found */ - return inputs[i].Attrib; - } - } - return -1; -} - - -static GLint -slang_find_output(GLenum target, const char *name, GLint index) -{ - struct output_info { - const char *Name; - GLuint Attrib; - }; - 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 }, /* XXX indexed */ - { "gl_FogFragCoord", VERT_RESULT_FOGC }, - { NULL, 0 } - }; - static const struct output_info fragOutputs[] = { - { "gl_FragColor", FRAG_RESULT_COLR }, - { NULL, 0 } - }; - const struct output_info *outputs; - GLuint i; - - if (target == GL_VERTEX_PROGRAM_ARB) { - outputs = vertOutputs; - } - else { - assert(target == GL_FRAGMENT_PROGRAM_ARB); - outputs = fragOutputs; - } - - for (i = 0; outputs[i].Name; i++) { - if (strcmp(outputs[i].Name, name) == 0) { - /* found */ - return outputs[i].Attrib; - } - } - return -1; -} - - /** * Lookup a named constant and allocate storage for the parameter in * the given parameter list. @@ -620,13 +535,6 @@ slang_alloc_uniform(struct gl_program *prog, const char *name, GLuint size) } -static GLint -slang_alloc_varying(struct gl_program *prog, const char *name) -{ - GLint i = _mesa_add_varying(prog->Varying, name, 4); /* XXX fix size */ - return i; -} - /** * Allocate temporary storage for an intermediate result (such as for @@ -705,14 +613,17 @@ slang_resolve_storage(slang_gen_context *gc, slang_ir_node *n, /* assert(!is_sampler_type(&n->Var->type)); */ + assert(n->Opcode == IR_VAR); + + assert(n->Store->File != PROGRAM_UNDEFINED); - if (n->Opcode == IR_VAR && n->Store->File == PROGRAM_UNDEFINED) { + if (n->Opcode == IR_VAR && (n->Store->File == PROGRAM_UNDEFINED + || n->Store->Index < 0)) { /* try to determine the storage for this variable */ GLint i; assert(n->Var); - - /*if (is_sampler(*/ + assert(n->Store->Size > 0); if (n->Store->Size < 0) { /* determine var/storage size now */ @@ -730,23 +641,10 @@ slang_resolve_storage(slang_gen_context *gc, slang_ir_node *n, n->Var->type.qualifier == slang_qual_const); #endif - i = slang_find_input(prog->Target, (char *) n->Var->a_name, 0); - if (i >= 0) { - n->Store->File = PROGRAM_INPUT; - n->Store->Index = i; - assert(n->Store->Size > 0); - return; - } - - i = slang_find_output(prog->Target, (char *) n->Var->a_name, 0); - if (i >= 0) { - n->Store->File = PROGRAM_OUTPUT; - n->Store->Index = i; - return; - } - i = slang_lookup_statevar((char *) n->Var->a_name, 0, prog->Parameters); if (i >= 0) { + assert(n->Store->File == PROGRAM_STATE_VAR /*|| + n->Store->File == PROGRAM_UNIFORM*/); n->Store->File = PROGRAM_STATE_VAR; n->Store->Index = i; return; @@ -754,31 +652,12 @@ slang_resolve_storage(slang_gen_context *gc, slang_ir_node *n, i = slang_lookup_constant((char *) n->Var->a_name, 0, prog->Parameters); if (i >= 0) { + assert(n->Store->File == PROGRAM_CONSTANT); n->Store->File = PROGRAM_CONSTANT; n->Store->Index = i; return; } - /* probably a uniform or varying */ - if (n->Var->type.qualifier == slang_qual_uniform) { - GLint size = n->Store->Size; - assert(size > 0); - i = slang_alloc_uniform(prog, (char *) n->Var->a_name, size); - if (i >= 0) { - n->Store->File = PROGRAM_UNIFORM; - n->Store->Index = i; - return; - } - } - else if (n->Var->type.qualifier == slang_qual_varying) { - i = slang_alloc_varying(prog, (char *) n->Var->a_name); - if (i >= 0) { - n->Store->File = PROGRAM_VARYING; - n->Store->Index = i; - return; - } - } - if (n->Store->File == PROGRAM_UNDEFINED && n->Store->Index < 0) { /* ordinary local var */ assert(n->Store->Size > 0); -- cgit v1.2.3 From 88e2dbfd10129eab2c7f4a935358a6ab2a18bf65 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 10 Jan 2007 13:33:38 -0700 Subject: checkpoint: codegen for global vars w/ initializers --- src/mesa/shader/shader_api.c | 3 +- src/mesa/shader/slang/slang_codegen.c | 365 +++++++++++++++++++--------------- src/mesa/shader/slang/slang_codegen.h | 7 +- src/mesa/shader/slang/slang_compile.c | 20 +- 4 files changed, 228 insertions(+), 167 deletions(-) (limited to 'src/mesa/shader/slang/slang_codegen.h') diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index 69314b225a4..c18bbcec4be 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -307,9 +307,10 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index, _slang_remap_attribute(&shProg->VertexProgram->Base, oldIndex, index); } +#if 0 printf("===== post BindAttrib:\n"); _mesa_print_program(&shProg->VertexProgram->Base); - +#endif } diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 07ca8107c0a..12e9588579e 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -291,10 +291,12 @@ slang_allocate_storage(slang_gen_context *gc, slang_ir_node *n, n->Store->Size = _slang_sizeof_type_specifier(&n->Var->type.specifier); assert(n->Store->Size > 0); n->Store->Index = _slang_alloc_temporary(gc, n->Store->Size); + /* printf("alloc var %s storage at %d (size %d)\n", (char *) n->Var->a_name, n->Store->Index, n->Store->Size); + */ assert(n->Store->Size > 0); n->Var->declared = GL_TRUE; return; @@ -459,155 +461,6 @@ _slang_output_index(const char *name, GLenum target) } -/** - * Called by compiler when a global variable has been parsed/compiled. - * Here we examine the variable's type to determine what kind of register - * storage will be used. - * - * A uniform such as "gl_Position" will become the register specification - * (PROGRAM_OUTPUT, VERT_RESULT_HPOS). Or, uniform "gl_FogFragCoord" - * will be (PROGRAM_INPUT, FRAG_ATTRIB_FOGC). - * - * Samplers are interesting. For "uniform sampler2D tex;" we'll specify - * (PROGRAM_SAMPLER, index) where index is resolved at link-time to an - * actual texture unit (as specified by the user calling glUniform1i()). - */ -void -_slang_codegen_global_variable(slang_variable *var, struct gl_program *prog, - slang_unit_type type) -{ - const char *varName = (char *) var->a_name; - GLint texIndex; - slang_ir_storage *store = NULL; - int dbg = 0; - - texIndex = sampler_to_texture_index(var->type.specifier.type); - - if (texIndex != -1) { - /* Texture sampler: - * store->File = PROGRAM_SAMPLER - * store->Index = sampler uniform location - * store->Size = texture type index (1D, 2D, 3D, cube, etc) - */ - GLint samplerUniform = _mesa_add_sampler(prog->Parameters, varName); - store = _slang_new_ir_storage(PROGRAM_SAMPLER, samplerUniform, texIndex); - if (dbg) printf("SAMPLER "); - } - else if (var->type.qualifier == slang_qual_uniform) { - /* Uniform variable */ - const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); - if (prog) { - /* user-defined uniform */ - GLint uniformLoc = _mesa_add_uniform(prog->Parameters, varName, size); - store = _slang_new_ir_storage(PROGRAM_UNIFORM, uniformLoc, size); - } - else { - /* pre-defined uniform, like gl_ModelviewMatrix */ - /* We know it's a uniform, but don't allocate storage unless - * it's really used. - */ - - store = _slang_new_ir_storage(PROGRAM_STATE_VAR, -1, size); - - } - if (dbg) printf("UNIFORM "); - } - else if (var->type.qualifier == slang_qual_varying) { - const GLint size = 4; /* XXX fix */ - if (prog) { - /* user-defined varying */ - GLint varyingLoc = _mesa_add_varying(prog->Varying, varName, size); - store = _slang_new_ir_storage(PROGRAM_VARYING, varyingLoc, size); - } - else { - /* pre-defined varying, like gl_Color or gl_TexCoord */ - if (type == slang_unit_fragment_builtin) { - GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB); - assert(index >= 0); - store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); - assert(index < FRAG_ATTRIB_MAX); - } - else { - GLint index = _slang_output_index(varName, GL_VERTEX_PROGRAM_ARB); - assert(index >= 0); - assert(type == slang_unit_vertex_builtin); - store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); - assert(index < VERT_RESULT_MAX); - } - if (dbg) printf("V/F "); - } - if (dbg) printf("VARYING "); - } - else if (var->type.qualifier == slang_qual_const) { - if (prog) { - /* user-defined constant */ - const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); - /* - const GLint index = _mesa_add_named_constant(prog->Parameters); - */ - printf("Global user constant\n"); - abort(); /* XXX fix */ - } - else { - /* pre-defined global constant, like gl_MaxLights */ - GLint size = -1; - store = _slang_new_ir_storage(PROGRAM_CONSTANT, -1, size); - } - if (dbg) printf("CONST "); - } - else if (var->type.qualifier == slang_qual_attribute) { - if (prog) { - /* user-defined vertex attribute */ - const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); - const GLint attr = -1; /* unknown */ - GLint index = _mesa_add_attribute(prog->Attributes, varName, - size, attr); - assert(index >= 0); - store = _slang_new_ir_storage(PROGRAM_INPUT, - VERT_ATTRIB_GENERIC0 + index, size); - } - else { - /* pre-defined vertex attrib */ - GLint index = _slang_input_index(varName, GL_VERTEX_PROGRAM_ARB); - GLint size = 4; /* XXX? */ - assert(index >= 0); - store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); - } - if (dbg) printf("ATTRIB "); - } - else if (var->type.qualifier == slang_qual_fixedinput) { - GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB); - GLint size = 4; /* XXX? */ - store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); - if (dbg) printf("INPUT "); - } - else if (var->type.qualifier == slang_qual_fixedoutput) { - if (type == slang_unit_vertex_builtin) { - GLint index = _slang_output_index(varName, GL_VERTEX_PROGRAM_ARB); - GLint size = 4; /* XXX? */ - store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); - } - else { - assert(type == slang_unit_fragment_builtin); - GLint index = _slang_output_index(varName, GL_FRAGMENT_PROGRAM_ARB); - GLint size = 4; /* XXX? */ - store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); - } - if (dbg) printf("OUTPUT "); - } - else { - /* ordinary variable */ - assert(prog); /* shouldn't be any pre-defined, unqualified vars */ - if (dbg) printf("other "); - abort(); - } - if (dbg) printf("GLOBAL VAR %s idx %d\n", (char*) var->a_name, store?store->Index:-2); - - assert(!var->aux); - - var->aux = store; -} - /**********************************************************************/ @@ -1023,10 +876,9 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, /* allocate the return var */ resultVar = slang_variable_scope_grow(commaSeq->locals); /* - printf("ALLOC __retVal from scope %p\n", (void*) commaSeq->locals); - */ printf("Alloc __resultTemp in scope %p for retval of calling %s\n", (void*)commaSeq->locals, (char *) fun->header.a_name); + */ resultVar->a_name = slang_atom_pool_atom(A->atoms, "__resultTmp"); resultVar->type = fun->header.type; /* XXX copy? */ @@ -1071,9 +923,11 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, substCount = 0; for (i = 0; i < totalArgs; i++) { slang_variable *p = &fun->parameters->variables[i]; + /* printf("Param %d: %s %s \n", i, slang_type_qual_string(p->type.qualifier), (char *) p->a_name); + */ if (p->type.qualifier == slang_qual_inout || p->type.qualifier == slang_qual_out) { /* an output param */ @@ -2110,12 +1964,197 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) } + +/** + * Called by compiler when a global variable has been parsed/compiled. + * Here we examine the variable's type to determine what kind of register + * storage will be used. + * + * A uniform such as "gl_Position" will become the register specification + * (PROGRAM_OUTPUT, VERT_RESULT_HPOS). Or, uniform "gl_FogFragCoord" + * will be (PROGRAM_INPUT, FRAG_ATTRIB_FOGC). + * + * Samplers are interesting. For "uniform sampler2D tex;" we'll specify + * (PROGRAM_SAMPLER, index) where index is resolved at link-time to an + * actual texture unit (as specified by the user calling glUniform1i()). + */ +GLboolean +_slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, + slang_unit_type type) +{ + struct gl_program *prog = A->program; + const char *varName = (char *) var->a_name; + GLint texIndex; + slang_ir_storage *store = NULL; + int dbg = 0; + GLboolean codegen = GL_FALSE; /* generate code for this global? */ + + texIndex = sampler_to_texture_index(var->type.specifier.type); + + if (texIndex != -1) { + /* Texture sampler: + * store->File = PROGRAM_SAMPLER + * store->Index = sampler uniform location + * store->Size = texture type index (1D, 2D, 3D, cube, etc) + */ + GLint samplerUniform = _mesa_add_sampler(prog->Parameters, varName); + store = _slang_new_ir_storage(PROGRAM_SAMPLER, samplerUniform, texIndex); + if (dbg) printf("SAMPLER "); + } + else if (var->type.qualifier == slang_qual_uniform) { + /* Uniform variable */ + const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); + if (prog) { + /* user-defined uniform */ + GLint uniformLoc = _mesa_add_uniform(prog->Parameters, varName, size); + store = _slang_new_ir_storage(PROGRAM_UNIFORM, uniformLoc, size); + } + else { + /* pre-defined uniform, like gl_ModelviewMatrix */ + /* We know it's a uniform, but don't allocate storage unless + * it's really used. + */ + + store = _slang_new_ir_storage(PROGRAM_STATE_VAR, -1, size); + + } + if (dbg) printf("UNIFORM "); + } + else if (var->type.qualifier == slang_qual_varying) { + const GLint size = 4; /* XXX fix */ + if (prog) { + /* user-defined varying */ + GLint varyingLoc = _mesa_add_varying(prog->Varying, varName, size); + store = _slang_new_ir_storage(PROGRAM_VARYING, varyingLoc, size); + } + else { + /* pre-defined varying, like gl_Color or gl_TexCoord */ + if (type == slang_unit_fragment_builtin) { + GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB); + assert(index >= 0); + store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); + assert(index < FRAG_ATTRIB_MAX); + } + else { + GLint index = _slang_output_index(varName, GL_VERTEX_PROGRAM_ARB); + assert(index >= 0); + assert(type == slang_unit_vertex_builtin); + store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); + assert(index < VERT_RESULT_MAX); + } + if (dbg) printf("V/F "); + } + if (dbg) printf("VARYING "); + } + else if (var->type.qualifier == slang_qual_const) { + if (prog) { + /* user-defined constant */ + /* + const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); + const GLint index = _mesa_add_named_constant(prog->Parameters); + */ + printf("Global user constant\n"); + abort(); /* XXX fix */ + } + else { + /* pre-defined global constant, like gl_MaxLights */ + GLint size = -1; + store = _slang_new_ir_storage(PROGRAM_CONSTANT, -1, size); + } + if (dbg) printf("CONST "); + } + else if (var->type.qualifier == slang_qual_attribute) { + if (prog) { + /* user-defined vertex attribute */ + const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); + const GLint attr = -1; /* unknown */ + GLint index = _mesa_add_attribute(prog->Attributes, varName, + size, attr); + assert(index >= 0); + store = _slang_new_ir_storage(PROGRAM_INPUT, + VERT_ATTRIB_GENERIC0 + index, size); + } + else { + /* pre-defined vertex attrib */ + GLint index = _slang_input_index(varName, GL_VERTEX_PROGRAM_ARB); + GLint size = 4; /* XXX? */ + assert(index >= 0); + store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); + } + if (dbg) printf("ATTRIB "); + } + else if (var->type.qualifier == slang_qual_fixedinput) { + GLint index = _slang_input_index(varName, GL_FRAGMENT_PROGRAM_ARB); + GLint size = 4; /* XXX? */ + store = _slang_new_ir_storage(PROGRAM_INPUT, index, size); + if (dbg) printf("INPUT "); + } + else if (var->type.qualifier == slang_qual_fixedoutput) { + if (type == slang_unit_vertex_builtin) { + GLint index = _slang_output_index(varName, GL_VERTEX_PROGRAM_ARB); + GLint size = 4; /* XXX? */ + store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); + } + else { + assert(type == slang_unit_fragment_builtin); + GLint index = _slang_output_index(varName, GL_FRAGMENT_PROGRAM_ARB); + GLint size = 4; /* XXX? */ + store = _slang_new_ir_storage(PROGRAM_OUTPUT, index, size); + } + if (dbg) printf("OUTPUT "); + } + else { + /* ordinary variable */ + const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); + const GLint index = -1; + store = _slang_new_ir_storage(PROGRAM_TEMPORARY, index, size); + codegen = GL_TRUE; + assert(prog); /* shouldn't be any pre-defined, unqualified vars */ + } + if (dbg) printf("GLOBAL VAR %s idx %d\n", (char*) var->a_name, + store ? store->Index : -2); + + assert(!var->aux); + var->aux = store; /* save var's storage info */ + + if (codegen) { + slang_ir_node *n; + + n = new_node(IR_VAR_DECL, NULL, NULL); + if (!n) + return GL_FALSE; + n->Var = var; + var->declared = GL_TRUE; + slang_allocate_storage(A->codegen, n, A->program); + + if (var->initializer) { + slang_ir_node *lhs, *rhs, *init; + + /* Generate IR_MOVE instruction to initialize the variable */ + lhs = new_node(IR_VAR, NULL, NULL); + lhs->Var = var; + lhs->Swizzle = SWIZZLE_NOOP; + lhs->Store = store; + + rhs = _slang_gen_operation(A, var->initializer); + init = new_node(IR_MOVE, lhs, rhs); + n = new_seq(n, init); + } + + /* emit code (n) */ + + } + + return GL_TRUE; +} + + /** - * Produce an IR tree from a function AST. + * Produce an IR tree from a function AST (fun->body). * Then call the code emitter to convert the IR tree into gl_program * instructions. */ -struct slang_ir_node_ * +GLboolean _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) { slang_ir_node *n, *endLabel; @@ -2125,11 +2164,13 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) /* we only really generate code for main, all other functions get * inlined. */ - return 0; + return GL_TRUE; /* not an error */ } #if 1 printf("\n*********** codegen_function %s\n", (char *) fun->header.a_name); +#endif +#if 0 slang_print_function(fun, 1); #endif @@ -2137,11 +2178,11 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) assert(A->program->Parameters ); assert(A->program->Varying); - A->codegen = _slang_new_codegen_context(); + assert(A->codegen); + /* A->codegen = _slang_new_codegen_context();*/ - /*printf("** Begin Simplify\n");*/ + /* fold constant expressions, etc. */ slang_simplify(fun->body, &A->space, A->atoms); - /*printf("** End Simplify\n");*/ CurFunction = fun; @@ -2159,19 +2200,23 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) CurFunction = NULL; -#if 1 +#if 0 printf("************* New AST for %s *****\n", (char*)fun->header.a_name); slang_print_function(fun, 1); +#endif +#if 1 printf("************* IR for %s *******\n", (char*)fun->header.a_name); slang_print_ir(n, 0); - printf("************* End assemble function2 ************\n\n"); + printf("************* End codegen function ************\n\n"); #endif success = _slang_emit_code(n, A->codegen, A->program); /* free codegen context */ + /* _mesa_free(A->codegen); + */ - return n; + return GL_TRUE; } diff --git a/src/mesa/shader/slang/slang_codegen.h b/src/mesa/shader/slang/slang_codegen.h index ad8e2a4fd88..76d364237a3 100644 --- a/src/mesa/shader/slang/slang_codegen.h +++ b/src/mesa/shader/slang/slang_codegen.h @@ -29,14 +29,13 @@ #include "imports.h" #include "slang_compile.h" -#include "slang_ir.h" -extern struct slang_ir_node_ * +extern GLboolean _slang_codegen_function(slang_assemble_ctx *A , struct slang_function_ *fun); -extern void -_slang_codegen_global_variable(slang_variable *var, struct gl_program *prog, +extern GLboolean +_slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, slang_unit_type type); diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 314c32f7077..bb1da271524 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -38,6 +38,7 @@ #include "slang_preprocess.h" #include "slang_storage.h" #include "slang_error.h" +#include "slang_emit.h" #include "slang_print.h" @@ -247,6 +248,7 @@ typedef struct slang_output_ctx_ slang_var_pool *global_pool; slang_machine *machine; struct gl_program *program; + slang_gen_context *codegen; } slang_output_ctx; /* _slang_compile() */ @@ -1719,8 +1721,20 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, } #if 1 - if (C->global_scope /*&& O->program*/) - _slang_codegen_global_variable(var, O->program, C->type); + if (C->global_scope) { + slang_assemble_ctx A; + + A.file = O->assembly; + A.mach = O->machine; + A.atoms = C->atoms; + A.space.funcs = O->funs; + A.space.structs = O->structs; + A.space.vars = O->vars; + A.codegen = O->codegen; + A.program = O->program; + + _slang_codegen_global_variable(&A, var, C->type); + } #endif /* allocate global address space for a variable with a known size */ @@ -1880,6 +1894,7 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition, A.space.structs = O->structs; A.space.vars = O->vars; A.program = O->program; + A.codegen = O->codegen; _slang_reset_error(); @@ -1953,6 +1968,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, o.global_pool = &unit->object->varpool; o.machine = &unit->object->machine; o.program = program; + o.codegen = _slang_new_codegen_context(); /* parse individual functions and declarations */ while (*C->I != EXTERNAL_NULL) { -- cgit v1.2.3 From 3a3bb953b63e8e85afb330f5d7c887413ad43c1e Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 17 Jan 2007 16:14:03 -0700 Subject: _slang_gen_function_call_name() now tries to adapt function calls (expand vectors, insert casts) when a perfect match isn't found. --- src/mesa/shader/slang/slang_codegen.c | 53 +++++++++++++++++++++++++++-------- src/mesa/shader/slang/slang_codegen.h | 3 ++ 2 files changed, 44 insertions(+), 12 deletions(-) (limited to 'src/mesa/shader/slang/slang_codegen.h') diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 31f2576cb5d..15c05a39a22 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -187,7 +187,7 @@ _slang_sizeof_struct(const slang_struct *s) } -static GLuint +GLuint _slang_sizeof_type_specifier(const slang_type_specifier *spec) { switch (spec->type) { @@ -482,6 +482,7 @@ static slang_asm_info AsmInfo[] = { /* unary op */ { "int_to_float", IR_I_TO_F, 1, 1 }, + { "float_to_int", IR_F_TO_I, 1, 1 }, { "float_exp", IR_EXP, 1, 1 }, { "float_exp2", IR_EXP2, 1, 1 }, { "float_log2", IR_LOG2, 1, 1 }, @@ -758,6 +759,7 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper, printf("Substitute %s with %f in id node %p\n", (char*)v->a_name, substNew[i]->literal[0], (void*) oper); + } #endif slang_operation_copy(oper, substNew[i]); break; @@ -1268,21 +1270,42 @@ _slang_gen_cond(slang_ir_node *n) } -static void print_funcs(struct slang_function_scope_ *scope) +static void +print_funcs(struct slang_function_scope_ *scope, const char *name) { int i; for (i = 0; i < scope->num_functions; i++) { slang_function *f = &scope->functions[i]; - printf("func %s\n", (char *) f->header.a_name); - if (strcmp("vec3", (char*) f->header.a_name) == 0) - printf("VEC3!\n"); + if (!name || strcmp(name, (char*) f->header.a_name) == 0) + printf(" %s (%d args)\n", name, f->param_count); } if (scope->outer_scope) - print_funcs(scope->outer_scope); + print_funcs(scope->outer_scope, name); } +/** + * Return first function in the scope that has the given name. + * This is the function we'll try to call when there is no exact match + * between function parameters and call arguments. + */ +static slang_function * +_slang_first_function(struct slang_function_scope_ *scope, const char *name) +{ + int i; + for (i = 0; i < scope->num_functions; i++) { + slang_function *f = &scope->functions[i]; + if (strcmp(name, (char*) f->header.a_name) == 0) + return f; + } + if (scope->outer_scope) + return _slang_first_function(scope->outer_scope, name); + return NULL; +} + + + /** * Assemble a function call, given a particular function name. * \param name the function's name (operators like '*' are possible). @@ -1300,15 +1323,21 @@ _slang_gen_function_call_name(slang_assemble_ctx *A, const char *name, if (atom == SLANG_ATOM_NULL) return NULL; + /* + * Use 'name' to find the function to call + */ fun = _slang_locate_function(A->space.funcs, atom, params, param_count, &A->space, A->atoms); if (!fun) { - /* XXX temporary */ - print_funcs(A->space.funcs); - fun = _slang_locate_function(A->space.funcs, atom, params, param_count, - &A->space, A->atoms); - - RETURN_ERROR2("Undefined function", name, 0); + /* A function with exactly the right parameters/types was not found. + * Try adapting the parameters. + */ + fun = _slang_first_function(A->space.funcs, name); + if (!_slang_adapt_call(oper, fun, &A->space, A->atoms)) { + RETURN_ERROR2("Undefined function (or no matching parameters)", + name, 0); + } + assert(fun); } return _slang_gen_function_call(A, fun, oper, dest); diff --git a/src/mesa/shader/slang/slang_codegen.h b/src/mesa/shader/slang/slang_codegen.h index 76d364237a3..821d3961625 100644 --- a/src/mesa/shader/slang/slang_codegen.h +++ b/src/mesa/shader/slang/slang_codegen.h @@ -31,6 +31,9 @@ #include "slang_compile.h" +extern GLuint +_slang_sizeof_type_specifier(const slang_type_specifier *spec); + extern GLboolean _slang_codegen_function(slang_assemble_ctx *A , struct slang_function_ *fun); -- cgit v1.2.3