From 8af48fc4d62798dbcc00bcfbbd8bc8f3b47982c7 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 14 Mar 2006 11:23:16 +0000 Subject: More GLSL code: - add texture sampling support; - fix assembly codegen bugs; --- .../shader/slang/library/slang_common_builtin.gc | 66 ++++++---- .../shader/slang/library/slang_common_builtin_gc.h | 121 ++++++++++-------- .../shader/slang/library/slang_fragment_builtin.gc | 63 ++++++--- .../slang/library/slang_fragment_builtin_gc.h | 121 ++++++++++-------- src/mesa/shader/slang/library/slang_shader.syn | 18 ++- src/mesa/shader/slang/library/slang_shader_syn.h | 8 +- src/mesa/shader/slang/slang_analyse.c | 100 +++++++++++++++ src/mesa/shader/slang/slang_analyse.h | 50 ++++++++ src/mesa/shader/slang/slang_assemble.c | 69 ++++++++-- src/mesa/shader/slang/slang_assemble.h | 5 + src/mesa/shader/slang/slang_execute.c | 80 ++++++++---- src/mesa/shader/slang/slang_execute_x86.c | 72 ++++++----- src/mesa/shader/slang/slang_library_texsample.c | 142 +++++++++++++++++++++ src/mesa/shader/slang/slang_library_texsample.h | 44 +++++++ src/mesa/shader/slang/slang_link.c | 50 ++++++-- src/mesa/shader/slang/slang_link.h | 32 ++++- 16 files changed, 790 insertions(+), 251 deletions(-) create mode 100644 src/mesa/shader/slang/slang_analyse.c create mode 100644 src/mesa/shader/slang/slang_analyse.h create mode 100644 src/mesa/shader/slang/slang_library_texsample.c create mode 100644 src/mesa/shader/slang/slang_library_texsample.h (limited to 'src/mesa/shader/slang') diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc index 4d82d54c14..9486f4c830 100755 --- a/src/mesa/shader/slang/library/slang_common_builtin.gc +++ b/src/mesa/shader/slang/library/slang_common_builtin.gc @@ -1,10 +1,27 @@ - -// -// TODO: -// - implement texture1D, texture3D, textureCube, -// - implement shadow1D, shadow2D, -// - +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 2006 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. + */ + // // From Shader Spec, ver. 1.10, rev. 59 // @@ -1267,8 +1284,9 @@ bvec4 not (bvec4 v) { // vec4 texture1D (sampler1D sampler, float coord) { - // XXX: - return vec4 (0.0); + vec4 texel; + __asm vec4_tex1d texel, sampler, coord, 0.0; + return texel; } vec4 texture1DProj (sampler1D sampler, vec2 coord) { @@ -1281,7 +1299,7 @@ vec4 texture1DProj (sampler1D sampler, vec4 coord) { vec4 texture2D (sampler2D sampler, vec2 coord) { vec4 texel; - __asm vec4_tex2d texel, sampler, coord; + __asm vec4_tex2d texel, sampler, coord, 0.0; return texel; } @@ -1294,8 +1312,9 @@ vec4 texture2DProj (sampler2D sampler, vec4 coord) { } vec4 texture3D (sampler3D sampler, vec3 coord) { - // XXX: - return vec4 (0.0); + vec4 texel; + __asm vec4_tex3d texel, sampler, coord, 0.0; + return texel; } vec4 texture3DProj (sampler3D sampler, vec4 coord) { @@ -1303,22 +1322,25 @@ vec4 texture3DProj (sampler3D sampler, vec4 coord) { } vec4 textureCube (samplerCube sampler, vec3 coord) { - // XXX: - return vec4 (0.0); + vec4 texel; + __asm vec4_texcube texel, sampler, coord, 0.0; + return texel; } vec4 shadow1D (sampler1DShadow sampler, vec3 coord) { - // XXX: - return vec4 (0.0); + vec4 texel; + __asm vec4_shad1d texel, sampler, coord, 0.0; + return texel; } -vec4 shadow2D (sampler2DShadow sampler, vec3 coord) { - // XXX: - return vec4 (0.0); -} - vec4 shadow1DProj (sampler1DShadow sampler, vec4 coord) { - return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q)); + return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q)); +} + +vec4 shadow2D (sampler2DShadow sampler, vec3 coord) { + vec4 texel; + __asm vec4_shad2d texel, sampler, coord, 0.0; + return texel; } vec4 shadow2DProj (sampler2DShadow sampler, vec4 coord) { 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 7198e5f947..ad4f78eebf 100644 --- a/src/mesa/shader/slang/library/slang_common_builtin_gc.h +++ b/src/mesa/shader/slang/library/slang_common_builtin_gc.h @@ -548,62 +548,71 @@ 0,56,0,18,118,0,59,121,0,56,0,18,118,0,59,122,0,56,0,0,0,0,1,0,4,0,110,111,116,0,1,0,0,4,118,0,0,0, 1,8,58,98,118,101,99,52,0,18,118,0,59,120,0,56,0,18,118,0,59,121,0,56,0,18,118,0,59,122,0,56,0,18, 118,0,59,119,0,56,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,8,58,118,101,99,52,0,17,48,0,48,0,0,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, -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,0,0,17,115,97,109,112,108,101,114,0,0,1,0,0,10,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,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,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,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,8,58,118,101,99,52,0,17,48,0,48,0,0,0,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,8,58,118,101,99,52,0,17,48,0,48,0,0,0,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,8,58,118,101,99,52,0,17,48,0,48,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,8,58,118,101,99,52,0,17, -48,0,48,0,0,0,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,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, +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,0,0,17,115,97,109,112,108,101,114,0,0,1,0,0,10,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,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,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,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, diff --git a/src/mesa/shader/slang/library/slang_fragment_builtin.gc b/src/mesa/shader/slang/library/slang_fragment_builtin.gc index 776c96db9b..8b619cd837 100755 --- a/src/mesa/shader/slang/library/slang_fragment_builtin.gc +++ b/src/mesa/shader/slang/library/slang_fragment_builtin.gc @@ -1,8 +1,29 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 2006 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. + */ // // TODO: -// - implement texture1D, texture2D, texture3D, textureCube, -// - implement shadow1D, shadow2D, // - implement dFdx, dFdy, // @@ -26,8 +47,9 @@ varying float gl_FogFragCoord; // vec4 texture1D (sampler1D sampler, float coord, float bias) { - // XXX: - return vec4 (0.0); + vec4 texel; + __asm vec4_tex1d texel, sampler, coord, bias; + return texel; } vec4 texture1DProj (sampler1D sampler, vec2 coord, float bias) { @@ -39,8 +61,9 @@ vec4 texture1DProj (sampler1D sampler, vec4 coord, float bias) { } vec4 texture2D (sampler2D sampler, vec2 coord, float bias) { - // XXX: - return vec4 (0.0); + vec4 texel; + __asm vec4_tex2d texel, sampler, coord, bias; + return texel; } vec4 texture2DProj (sampler2D sampler, vec3 coord, float bias) { @@ -52,8 +75,9 @@ vec4 texture2DProj (sampler2D sampler, vec4 coord, float bias) { } vec4 texture3D (sampler3D sampler, vec3 coord, float bias) { - // XXX: - return vec4 (0.0); + vec4 texel; + __asm vec4_tex3d texel, sampler, coord, bias; + return texel; } vec4 texture3DProj (sampler3D sampler, vec4 coord, float bias) { @@ -61,22 +85,25 @@ vec4 texture3DProj (sampler3D sampler, vec4 coord, float bias) { } vec4 textureCube (samplerCube sampler, vec3 coord, float bias) { - // XXX: - return vec4 (0.0); + vec4 texel; + __asm vec4_texcube texel, sampler, coord, bias; + return texel; } vec4 shadow1D (sampler1DShadow sampler, vec3 coord, float bias) { - // XXX: - return vec4 (0.0); -} - -vec4 shadow2D (sampler2DShadow sampler, vec3 coord, float bias) { - // XXX: - return vec4 (0.0); + vec4 texel; + __asm vec4_shad1d texel, sampler, coord, bias; + return texel; } vec4 shadow1DProj (sampler1DShadow sampler, vec4 coord, float bias) { - return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q), bias); + return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q), bias); +} + +vec4 shadow2D (sampler2DShadow sampler, vec3 coord, float bias) { + vec4 texel; + __asm vec4_shad2d texel, sampler, coord, bias; + return texel; } vec4 shadow2DProj (sampler2DShadow sampler, vec4 coord, float bias) { 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 d8202a83ca..89d4736f3e 100644 --- a/src/mesa/shader/slang/library/slang_fragment_builtin_gc.h +++ b/src/mesa/shader/slang/library/slang_fragment_builtin_gc.h @@ -10,58 +10,69 @@ 111,114,0,0,0,2,2,3,12,1,103,108,95,84,101,120,67,111,111,114,100,0,3,18,103,108,95,77,97,120,84, 101,120,116,117,114,101,67,111,111,114,100,115,0,0,0,2,2,3,9,1,103,108,95,70,111,103,70,114,97,103, 67,111,111,114,100,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,1,0,0,9,98,105,97,115,0,0,0,1,8,58,118,101,99,52,0,17, -48,0,48,0,0,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,10,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,116,0,49,0,18,98,105,97,115,0,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,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,0,1,0,0,9,98,105,97,115,0,0,0,1,8,58,118,101,99,52,0,17,48,0,48,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,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,8,58,118,101,99,52,0,17,48,0,48,0,0,0,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,8,58,118,101,99,52,0,17,48,0,48,0,0,0,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,8,58,118,101,99,52,0,17,48,0,48,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,1,0,0,9,98,105, -97,115,0,0,0,1,8,58,118,101,99,52,0,17,48,0,48,0,0,0,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,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,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,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,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,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,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,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,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,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 +101,114,0,0,1,0,0,9,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,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,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,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, +116,0,49,0,18,98,105,97,115,0,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,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, +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,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,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,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,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,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,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,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,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/library/slang_shader.syn b/src/mesa/shader/slang/library/slang_shader.syn index aeb3c6112c..36d073e88a 100644 --- a/src/mesa/shader/slang/library/slang_shader.syn +++ b/src/mesa/shader/slang/library/slang_shader.syn @@ -1168,16 +1168,26 @@ __asm_statement "__asm" .and space .and identifier .and space .and asm_arguments .and semicolon .emit OP_END; /* - ::= - | "," + ::= + | "," note: this is an extension to the standard language specification - normally slang disallows __asm statements */ asm_arguments - variable_identifier .and .true .emit OP_END .and .loop asm_arguments_1; + asm_argument .and .true .emit OP_END .and .loop asm_arguments_1; asm_arguments_1 - comma .and variable_identifier .and .true .emit OP_END; + comma .and asm_argument .and .true .emit OP_END; + +/* + ::= + | + +note: this is an extension to the standard language specification - normally slang disallows + __asm statements +*/ +asm_argument + variable_identifier .or floatconstant; /* ::= diff --git a/src/mesa/shader/slang/library/slang_shader_syn.h b/src/mesa/shader/slang/library/slang_shader_syn.h index 3f13b2583a..5a94d99d43 100644 --- a/src/mesa/shader/slang/library/slang_shader_syn.h +++ b/src/mesa/shader/slang/library/slang_shader_syn.h @@ -560,9 +560,11 @@ "__asm_statement\n" " \"__asm\" .and space .and identifier .and space .and asm_arguments .and semicolon .emit OP_END;\n" "asm_arguments\n" -" variable_identifier .and .true .emit OP_END .and .loop asm_arguments_1;\n" +" asm_argument .and .true .emit OP_END .and .loop asm_arguments_1;\n" "asm_arguments_1\n" -" comma .and variable_identifier .and .true .emit OP_END;\n" +" comma .and asm_argument .and .true .emit OP_END;\n" +"asm_argument\n" +" variable_identifier .or floatconstant;\n" "translation_unit\n" " optional_space .emit REVISION .and external_declaration .error INVALID_EXTERNAL_DECLARATION .and\n" " .loop external_declaration .and optional_space .and\n" @@ -749,4 +751,4 @@ " '\\'' .or '<' .or ',' .or '>' .or '.' .or '/' .or '?' .or err_identifier;\n" "err_identifier\n" " id_character_first .and .loop id_character_next;\n" -"" +"" \ No newline at end of file diff --git a/src/mesa/shader/slang/slang_analyse.c b/src/mesa/shader/slang/slang_analyse.c new file mode 100644 index 0000000000..164dbec350 --- /dev/null +++ b/src/mesa/shader/slang/slang_analyse.c @@ -0,0 +1,100 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 2006 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. + */ + +/** + * \file slang_analyse.c + * slang assembly code analysis + * \author Michal Krol + */ + +#include "imports.h" +#include "slang_analyse.h" +#include "slang_utility.h" + +GLboolean _slang_analyse_texture_usage (slang_program *prog) +{ + GLuint i, count = 0; + + slang_texture_usages_dtr (&prog->texture_usage); + slang_texture_usages_ctr (&prog->texture_usage); + + /* + * We could do a full code analysis to find out which uniforms are actually used. + * For now, we are very conservative and extract them from uniform binding table, which + * in turn also do not come from code analysis. + */ + + for (i = 0; i < prog->uniforms.count; i++) + { + slang_uniform_binding *b = &prog->uniforms.table[i]; + + if (b->address[SLANG_SHADER_FRAGMENT] != ~0 && b->quant->structure == NULL) + { + switch (b->quant->u.basic_type) + { + case GL_SAMPLER_1D_ARB: + case GL_SAMPLER_2D_ARB: + case GL_SAMPLER_3D_ARB: + case GL_SAMPLER_CUBE_ARB: + case GL_SAMPLER_1D_SHADOW_ARB: + case GL_SAMPLER_2D_SHADOW_ARB: + count++; + break; + } + } + } + + if (count == 0) + return GL_TRUE; + prog->texture_usage.table = (slang_texture_usage *) slang_alloc_malloc ( + count * sizeof (slang_texture_usage)); + if (prog->texture_usage.table == NULL) + return GL_FALSE; + prog->texture_usage.count = count; + + for (count = i = 0; i < prog->uniforms.count; i++) + { + slang_uniform_binding *b = &prog->uniforms.table[i]; + + if (b->address[SLANG_SHADER_FRAGMENT] != ~0 && b->quant->structure == NULL) + { + switch (b->quant->u.basic_type) + { + case GL_SAMPLER_1D_ARB: + case GL_SAMPLER_2D_ARB: + case GL_SAMPLER_3D_ARB: + case GL_SAMPLER_CUBE_ARB: + case GL_SAMPLER_1D_SHADOW_ARB: + case GL_SAMPLER_2D_SHADOW_ARB: + prog->texture_usage.table[count].quant = b->quant; + prog->texture_usage.table[count].frag_address = b->address[SLANG_SHADER_FRAGMENT]; + count++; + break; + } + } + } + + return GL_TRUE; +} + diff --git a/src/mesa/shader/slang/slang_analyse.h b/src/mesa/shader/slang/slang_analyse.h new file mode 100644 index 0000000000..89814b3cc3 --- /dev/null +++ b/src/mesa/shader/slang/slang_analyse.h @@ -0,0 +1,50 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 2006 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. + */ + +#if !defined SLANG_ANALYSE_H +#define SLANG_ANALYSE_H + +#include "slang_link.h" + +#if defined __cplusplus +extern "C" { +#endif + +/* + * Texture usage analysis is a bit more difficult than for fragment programs. While fragment + * programs statically link to texture targets and texture units, shaders statically link + * only to texture targets. The texture unit linkage is determined just before the execution + * of a given primitive by reading active uniform samplers. + * + * This procedure retrieves a list of uniforms that reach texture sample instructions. + */ + +GLboolean _slang_analyse_texture_usage (slang_program *); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/src/mesa/shader/slang/slang_assemble.c b/src/mesa/shader/slang/slang_assemble.c index b24d318384..faa13b33e6 100644 --- a/src/mesa/shader/slang/slang_assemble.c +++ b/src/mesa/shader/slang/slang_assemble.c @@ -644,7 +644,12 @@ static const struct { "float_noise3", slang_asm_float_noise3, slang_asm_float_copy }, { "float_noise4", slang_asm_float_noise4, slang_asm_float_copy }, { "int_to_float", slang_asm_int_to_float, slang_asm_float_copy }, + { "vec4_tex1d", slang_asm_vec4_tex1d, slang_asm_none }, { "vec4_tex2d", slang_asm_vec4_tex2d, slang_asm_none }, + { "vec4_tex3d", slang_asm_vec4_tex3d, slang_asm_none }, + { "vec4_texcube", slang_asm_vec4_texcube, slang_asm_none }, + { "vec4_shad1d", slang_asm_vec4_shad1d, slang_asm_none }, + { "vec4_shad2d", slang_asm_vec4_shad2d, slang_asm_none }, /* mesa-specific extensions */ { "float_print", slang_asm_float_deref, slang_asm_float_print }, { "int_print", slang_asm_int_deref, slang_asm_int_print }, @@ -930,7 +935,9 @@ static GLboolean handle_field (slang_assemble_ctx *A, slang_assembly_typeinfo *t else { GLuint i, struct_size = 0, field_offset = 0, field_size = 0; + GLboolean relocate, shrink; + /* calculate struct size, field offset and field size */ for (i = 0; i < tib->spec._struct->fields->num_variables; i++) { slang_variable *field; @@ -960,28 +967,56 @@ static GLboolean handle_field (slang_assemble_ctx *A, slang_assembly_typeinfo *t field_offset += size; } - if (!PLAB (A->file, slang_asm_addr_push, field_offset)) - return GL_FALSE; + /* + * OPTIMIZATION: If selecting the last field, no relocation is needed. + */ + relocate = field_offset != struct_size - field_size; - if (ref == slang_ref_force) + /* + * OPTIMIZATION: If field and struct sizes are equal, no partial free is needed. + */ + shrink = field_size != struct_size; + + if (relocate) { - if (!PUSH (A->file, slang_asm_addr_add)) + if (!PLAB (A->file, slang_asm_addr_push, field_offset)) return GL_FALSE; } + + if (ref == slang_ref_force) + { + if (relocate) + { + if (!PUSH (A->file, slang_asm_addr_add)) + return GL_FALSE; + } + } else { - GLuint i; + GLuint free_b = 0; - /* move the selected element to the beginning of the master expression */ - for (i = 0; i < field_size; i += 4) - if (!PLAB2 (A->file, slang_asm_float_move, struct_size - field_size + i + 4, i + 4)) - return GL_FALSE; - if (!PLAB (A->file, slang_asm_local_free, 4)) - return GL_FALSE; + if (relocate) + { + GLuint i; - /* free the rest of the master expression */ - if (!PLAB (A->file, slang_asm_local_free, struct_size - field_size)) - return GL_FALSE; + /* move the selected element to the beginning of the master expression */ + for (i = 0; i < field_size; i += 4) + if (!PLAB2 (A->file, slang_asm_float_move, struct_size - field_size + i + 4, i + 4)) + return GL_FALSE; + free_b += 4; + } + + if (shrink) + { + /* free the rest of the master expression */ + free_b += struct_size - field_size; + } + + if (free_b) + { + if (!PLAB (A->file, slang_asm_local_free, free_b)) + return GL_FALSE; + } } } @@ -1173,14 +1208,17 @@ GLboolean _slang_assemble_operation (slang_assemble_ctx *A, slang_operation *op, case slang_oper_addassign: if (!_slang_assemble_assign (A, op, "+=", ref)) return GL_FALSE; + A->ref = ref; break; case slang_oper_subassign: if (!_slang_assemble_assign (A, op, "-=", ref)) return GL_FALSE; + A->ref = ref; break; case slang_oper_mulassign: if (!_slang_assemble_assign (A, op, "*=", ref)) return GL_FALSE; + A->ref = ref; break; /*case slang_oper_modassign:*/ /*case slang_oper_lshassign:*/ @@ -1191,6 +1229,7 @@ GLboolean _slang_assemble_operation (slang_assemble_ctx *A, slang_operation *op, case slang_oper_divassign: if (!_slang_assemble_assign (A, op, "/=", ref)) return GL_FALSE; + A->ref = ref; break; case slang_oper_select: if (!_slang_assemble_select (A, op)) @@ -1279,10 +1318,12 @@ GLboolean _slang_assemble_operation (slang_assemble_ctx *A, slang_operation *op, case slang_oper_preincrement: if (!_slang_assemble_assign (A, op, "++", ref)) return GL_FALSE; + A->ref = ref; break; case slang_oper_predecrement: if (!_slang_assemble_assign (A, op, "--", ref)) return GL_FALSE; + A->ref = ref; break; case slang_oper_plus: if (!_slang_dereference (A, op)) diff --git a/src/mesa/shader/slang/slang_assemble.h b/src/mesa/shader/slang/slang_assemble.h index ed1005454f..0cde845f85 100644 --- a/src/mesa/shader/slang/slang_assemble.h +++ b/src/mesa/shader/slang/slang_assemble.h @@ -75,7 +75,12 @@ typedef enum slang_assembly_type_ slang_asm_addr_deref, slang_asm_addr_add, slang_asm_addr_multiply, + slang_asm_vec4_tex1d, slang_asm_vec4_tex2d, + slang_asm_vec4_tex3d, + slang_asm_vec4_texcube, + slang_asm_vec4_shad1d, + slang_asm_vec4_shad2d, slang_asm_jump, slang_asm_jump_if_zero, slang_asm_enter, diff --git a/src/mesa/shader/slang/slang_execute.c b/src/mesa/shader/slang/slang_execute.c index 0714ddff0d..bed63d1e5b 100644 --- a/src/mesa/shader/slang/slang_execute.c +++ b/src/mesa/shader/slang/slang_execute.c @@ -29,11 +29,9 @@ */ #include "imports.h" -#include "context.h" -#include "swrast/s_context.h" -#include "colormac.h" #include "slang_execute.h" #include "slang_library_noise.h" +#include "slang_library_texsample.h" #define DEBUG_SLANG 0 @@ -48,7 +46,8 @@ GLvoid slang_machine_ctr (slang_machine *self) GLvoid slang_machine_dtr (slang_machine *self) { #if defined(USE_X86_ASM) || defined(SLANG_X86) - /* TODO: free self->x86.compiled_func */ + if (self->x86.compiled_func != NULL) + _mesa_exec_free (self->x86.compiled_func); #endif } @@ -195,9 +194,24 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i) case slang_asm_addr_multiply: fprintf (f, "addr_multiply"); break; - case slang_vec4_tex2d: + case slang_asm_vec4_tex1d: + fprintf (f, "vec4_tex1d"); + break; + case slang_asm_vec4_tex2d: fprintf (f, "vec4_tex2d"); break; + case slang_asm_vec4_tex3d: + fprintf (f, "vec4_tex3d"); + break; + case slang_asm_vec4_texcube: + fprintf (f, "vec4_texcube"); + break; + case slang_asm_vec4_shad1d: + fprintf (f, "vec4_shad1d"); + break; + case slang_asm_vec4_shad2d: + fprintf (f, "vec4_shad2d"); + break; case slang_asm_jump: fprintf (f, "jump\t%u", a->param[0]); break; @@ -272,21 +286,6 @@ static void dump (const slang_assembly_file *file) #endif -static void fetch_texel (GLuint sampler, const GLfloat texcoord[4], GLfloat lambda, GLfloat color[4]) -{ - GET_CURRENT_CONTEXT(ctx); - SWcontext *swrast = SWRAST_CONTEXT(ctx); - GLchan rgba[4]; - - /* XXX: the function pointer is NULL! */ - swrast->TextureSample[sampler] (ctx, ctx->Texture.Unit[sampler]._Current, 1, - (const GLfloat (*)[4]) texcoord, &lambda, &rgba); - color[0] = CHAN_TO_FLOAT(rgba[0]); - color[1] = CHAN_TO_FLOAT(rgba[1]); - color[2] = CHAN_TO_FLOAT(rgba[2]); - color[3] = CHAN_TO_FLOAT(rgba[3]); -} - int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach) { slang_machine_slot *stack; @@ -465,16 +464,41 @@ int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach) stack[mach->sp + 1]._addr *= stack[mach->sp]._addr; mach->sp++; break; - case slang_asm_vec4_tex2d: - { - GLfloat st[4] = { stack[mach->sp]._float, stack[mach->sp + 1]._float, 0.0f, 1.0f }; - GLuint sampler = (GLuint) stack[mach->sp + 2]._float; - GLfloat *rgba = &mach->mem[stack[mach->sp + 3]._addr / 4]._float; - - fetch_texel (sampler, st, 0.0f, rgba); - } + case slang_asm_vec4_tex1d: + _slang_library_tex1d (stack[mach->sp]._float, stack[mach->sp + 1]._float, + stack[mach->sp + 2]._float, &mach->mem[stack[mach->sp + 3]._addr / 4]._float); mach->sp += 3; break; + case slang_asm_vec4_tex2d: + _slang_library_tex2d (stack[mach->sp]._float, stack[mach->sp + 1]._float, + stack[mach->sp + 2]._float, stack[mach->sp + 3]._float, + &mach->mem[stack[mach->sp + 4]._addr / 4]._float); + mach->sp += 4; + break; + case slang_asm_vec4_tex3d: + _slang_library_tex3d (stack[mach->sp]._float, stack[mach->sp + 1]._float, + stack[mach->sp + 2]._float, stack[mach->sp + 3]._float, stack[mach->sp + 4]._float, + &mach->mem[stack[mach->sp + 5]._addr / 4]._float); + mach->sp += 5; + break; + case slang_asm_vec4_texcube: + _slang_library_texcube (stack[mach->sp]._float, stack[mach->sp + 1]._float, + stack[mach->sp + 2]._float, stack[mach->sp + 3]._float, stack[mach->sp + 4]._float, + &mach->mem[stack[mach->sp + 5]._addr / 4]._float); + mach->sp += 5; + break; + case slang_asm_vec4_shad1d: + _slang_library_shad1d (stack[mach->sp]._float, stack[mach->sp + 1]._float, + stack[mach->sp + 2]._float, stack[mach->sp + 3]._float, stack[mach->sp + 4]._float, + &mach->mem[stack[mach->sp + 5]._addr / 4]._float); + mach->sp += 5; + break; + case slang_asm_vec4_shad2d: + _slang_library_shad2d (stack[mach->sp]._float, stack[mach->sp + 1]._float, + stack[mach->sp + 2]._float, stack[mach->sp + 3]._float, stack[mach->sp + 4]._float, + &mach->mem[stack[mach->sp + 5]._addr / 4]._float); + mach->sp += 5; + break; case slang_asm_jump: mach->ip = a->param[0]; break; diff --git a/src/mesa/shader/slang/slang_execute_x86.c b/src/mesa/shader/slang/slang_execute_x86.c index d639563239..781aeb97db 100644 --- a/src/mesa/shader/slang/slang_execute_x86.c +++ b/src/mesa/shader/slang/slang_execute_x86.c @@ -2,7 +2,7 @@ * Mesa 3-D graphics library * Version: 6.5 * - * Copyright (C) 2005-2006 Brian Paul All Rights Reserved. + * Copyright (C) 2006 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"), @@ -29,11 +29,9 @@ */ #include "imports.h" -#include "context.h" -#include "colormac.h" -#include "swrast/s_context.h" #include "slang_execute.h" #include "slang_library_noise.h" +#include "slang_library_texsample.h" #if defined(USE_X86_ASM) || defined(SLANG_X86) @@ -114,28 +112,6 @@ static GLfloat do_ceilf (GLfloat x) return CEILF (x); } -static void fetch_texel (GLuint sampler, const GLfloat texcoord[4], GLfloat lambda, GLfloat color[4]) -{ - GET_CURRENT_CONTEXT(ctx); - SWcontext *swrast = SWRAST_CONTEXT(ctx); - GLchan rgba[4]; - - /* XXX: the function pointer is NULL! */ - swrast->TextureSample[sampler] (ctx, ctx->Texture.Unit[sampler]._Current, 1, - (const GLfloat (*)[4]) texcoord, &lambda, &rgba); - color[0] = CHAN_TO_FLOAT(rgba[0]); - color[1] = CHAN_TO_FLOAT(rgba[1]); - color[2] = CHAN_TO_FLOAT(rgba[2]); - color[3] = CHAN_TO_FLOAT(rgba[3]); -} - -static GLvoid do_vec4_tex2d (GLfloat s, GLfloat t, GLuint sampler, GLfloat *rgba) -{ - GLfloat st[4] = { s, t, 0.0f, 1.0f }; - - fetch_texel (sampler, st, 0.0f, rgba); -} - static GLvoid do_print_float (GLfloat x) { _mesa_printf ("slang print: %f\n", x); @@ -373,9 +349,29 @@ static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a) x86_mul (&G->f, G->r_ecx); x86_mov (&G->f, x86_deref (G->r_esp), G->r_eax); break; + case slang_asm_vec4_tex1d: + x86_call (&G->f, (GLubyte *) _slang_library_tex1d); + x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 12)); + break; case slang_asm_vec4_tex2d: - x86_call (&G->f, (GLubyte *) do_vec4_tex2d); - x86_lea (&G->f, G->r_ebp, x86_make_disp (G->r_esp, 12)); + x86_call (&G->f, (GLubyte *) _slang_library_tex2d); + x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 16)); + break; + case slang_asm_vec4_tex3d: + x86_call (&G->f, (GLubyte *) _slang_library_tex3d); + x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 20)); + break; + case slang_asm_vec4_texcube: + x86_call (&G->f, (GLubyte *) _slang_library_texcube); + x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 20)); + break; + case slang_asm_vec4_shad1d: + x86_call (&G->f, (GLubyte *) _slang_library_shad1d); + x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 20)); + break; + case slang_asm_vec4_shad2d: + x86_call (&G->f, (GLubyte *) _slang_library_shad2d); + x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 20)); break; case slang_asm_jump: add_fixup (G, a->param[0], x86_jmp_forward (&G->f)); @@ -460,7 +456,13 @@ GLboolean _slang_x86_codegen (slang_machine *mach, slang_assembly_file *file, GL GLubyte *j_body, *j_exit; GLuint i; - x86_init_func_size (&G.f, 4*1048576); + /* + * We need as much as 1M because *all* assembly, including built-in library, is + * being translated to x86. + * The built-in library occupies 450K, so we can be safe for now. + * It is going to change in the future, when we get assembly analysis running. + */ + x86_init_func_size (&G.f, 1048576); G.r_eax = x86_make_reg (file_REG32, reg_AX); G.r_ecx = x86_make_reg (file_REG32, reg_CX); G.r_edx = x86_make_reg (file_REG32, reg_DX); @@ -487,7 +489,7 @@ GLboolean _slang_x86_codegen (slang_machine *mach, slang_assembly_file *file, GL x86_mov (&G.f, x86_deref (G.r_eax), G.r_ecx); j_body = x86_jmp_forward (&G.f); - /* discard keywords go here */ + /* "discard" instructions jump to this label */ G.l_discard = x86_get_label (&G.f); x86_mov_reg_imm (&G.f, G.r_eax, (GLint) &G.mach->kill); x86_mov_reg_imm (&G.f, G.r_ecx, 1); @@ -503,7 +505,11 @@ GLboolean _slang_x86_codegen (slang_machine *mach, slang_assembly_file *file, GL codegen_assem (&G, &file->code[i]); } - /* restore stack and return */ + /* + * Restore stack and return. + * This must be handled this way, because "discard" can be invoked from any + * place in the code. + */ x86_fixup_fwd_jump (&G.f, j_exit); x86_mov_reg_imm (&G.f, G.r_eax, (GLint) &mach->x86.esp_restore); x86_mov (&G.f, G.r_esp, x86_deref (G.r_eax)); @@ -526,7 +532,9 @@ GLboolean _slang_x86_codegen (slang_machine *mach, slang_assembly_file *file, GL slang_alloc_free (G.fixups); slang_alloc_free (G.labels); - /* TODO: free previous instance, if not NULL */ + /* install new code */ + if (mach->x86.compiled_func != NULL) + _mesa_exec_free (mach->x86.compiled_func); mach->x86.compiled_func = (GLvoid (*) (slang_machine *)) x86_get_func (&G.f); return GL_TRUE; diff --git a/src/mesa/shader/slang/slang_library_texsample.c b/src/mesa/shader/slang/slang_library_texsample.c new file mode 100644 index 0000000000..d26b767f88 --- /dev/null +++ b/src/mesa/shader/slang/slang_library_texsample.c @@ -0,0 +1,142 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 2006 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. + */ + +/** + * \file slang_library_texsample.c + * built-in library functions for texture and shadow sampling + * \author Michal Krol + */ + +#include "imports.h" +#include "context.h" +#include "colormac.h" +#include "swrast/s_context.h" +#include "slang_library_texsample.h" + +GLvoid _slang_library_tex1d (GLfloat bias, GLfloat s, GLfloat sampler, GLfloat *color) +{ + GET_CURRENT_CONTEXT(ctx); + SWcontext *swrast = SWRAST_CONTEXT(ctx); + GLuint unit = (GLuint) sampler; + GLfloat texcoord[4] = { s, 0.0f, 0.0f, 1.0f }; + GLfloat lambda = bias; + GLchan rgba[4]; + + swrast->TextureSample[unit] (ctx, ctx->Texture.Unit[unit]._Current, 1, + (const GLfloat (*)[4]) texcoord, &lambda, &rgba); + color[0] = CHAN_TO_FLOAT(rgba[0]); + color[1] = CHAN_TO_FLOAT(rgba[1]); + color[2] = CHAN_TO_FLOAT(rgba[2]); + color[3] = CHAN_TO_FLOAT(rgba[3]); +} + +GLvoid _slang_library_tex2d (GLfloat bias, GLfloat s, GLfloat t, GLfloat sampler, GLfloat *color) +{ + GET_CURRENT_CONTEXT(ctx); + SWcontext *swrast = SWRAST_CONTEXT(ctx); + GLuint unit = (GLuint) sampler; + GLfloat texcoord[4] = { s, t, 0.0f, 1.0f }; + GLfloat lambda = bias; + GLchan rgba[4]; + + swrast->TextureSample[unit] (ctx, ctx->Texture.Unit[unit]._Current, 1, + (const GLfloat (*)[4]) texcoord, &lambda, &rgba); + color[0] = CHAN_TO_FLOAT(rgba[0]); + color[1] = CHAN_TO_FLOAT(rgba[1]); + color[2] = CHAN_TO_FLOAT(rgba[2]); + color[3] = CHAN_TO_FLOAT(rgba[3]); +} + +GLvoid _slang_library_tex3d (GLfloat bias, GLfloat s, GLfloat t, GLfloat r, GLfloat sampler, + GLfloat *color) +{ + GET_CURRENT_CONTEXT(ctx); + SWcontext *swrast = SWRAST_CONTEXT(ctx); + GLuint unit = (GLuint) sampler; + GLfloat texcoord[4] = { s, t, r, 1.0f }; + GLfloat lambda = bias; + GLchan rgba[4]; + + swrast->TextureSample[unit] (ctx, ctx->Texture.Unit[unit]._Current, 1, + (const GLfloat (*)[4]) texcoord, &lambda, &rgba); + color[0] = CHAN_TO_FLOAT(rgba[0]); + color[1] = CHAN_TO_FLOAT(rgba[1]); + color[2] = CHAN_TO_FLOAT(rgba[2]); + color[3] = CHAN_TO_FLOAT(rgba[3]); +} + +GLvoid _slang_library_texcube (GLfloat bias, GLfloat s, GLfloat t, GLfloat r, GLfloat sampler, + GLfloat *color) +{ + GET_CURRENT_CONTEXT(ctx); + SWcontext *swrast = SWRAST_CONTEXT(ctx); + GLuint unit = (GLuint) sampler; + GLfloat texcoord[4] = { s, t, r, 1.0f }; + GLfloat lambda = bias; + GLchan rgba[4]; + + swrast->TextureSample[unit] (ctx, ctx->Texture.Unit[unit]._Current, 1, + (const GLfloat (*)[4]) texcoord, &lambda, &rgba); + color[0] = CHAN_TO_FLOAT(rgba[0]); + color[1] = CHAN_TO_FLOAT(rgba[1]); + color[2] = CHAN_TO_FLOAT(rgba[2]); + color[3] = CHAN_TO_FLOAT(rgba[3]); +} + +GLvoid _slang_library_shad1d (GLfloat bias, GLfloat s, GLfloat t, GLfloat r, GLfloat sampler, + GLfloat *color) +{ + GET_CURRENT_CONTEXT(ctx); + SWcontext *swrast = SWRAST_CONTEXT(ctx); + GLuint unit = (GLuint) sampler; + GLfloat texcoord[4] = { s, t, r, 1.0f }; + GLfloat lambda = bias; + GLchan rgba[4]; + + swrast->TextureSample[unit] (ctx, ctx->Texture.Unit[unit]._Current, 1, + (const GLfloat (*)[4]) texcoord, &lambda, &rgba); + color[0] = CHAN_TO_FLOAT(rgba[0]); + color[1] = CHAN_TO_FLOAT(rgba[1]); + color[2] = CHAN_TO_FLOAT(rgba[2]); + color[3] = CHAN_TO_FLOAT(rgba[3]); +} + +GLvoid _slang_library_shad2d (GLfloat bias, GLfloat s, GLfloat t, GLfloat r, GLfloat sampler, + GLfloat *color) +{ + GET_CURRENT_CONTEXT(ctx); + SWcontext *swrast = SWRAST_CONTEXT(ctx); + GLuint unit = (GLuint) sampler; + GLfloat texcoord[4] = { s, t, r, 1.0f }; + GLfloat lambda = bias; + GLchan rgba[4]; + + swrast->TextureSample[unit] (ctx, ctx->Texture.Unit[unit]._Current, 1, + (const GLfloat (*)[4]) texcoord, &lambda, &rgba); + color[0] = CHAN_TO_FLOAT(rgba[0]); + color[1] = CHAN_TO_FLOAT(rgba[1]); + color[2] = CHAN_TO_FLOAT(rgba[2]); + color[3] = CHAN_TO_FLOAT(rgba[3]); +} + diff --git a/src/mesa/shader/slang/slang_library_texsample.h b/src/mesa/shader/slang/slang_library_texsample.h new file mode 100644 index 0000000000..3aea76fd8d --- /dev/null +++ b/src/mesa/shader/slang/slang_library_texsample.h @@ -0,0 +1,44 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 2006 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. + */ + +#if !defined SLANG_LIBRARY_TEXSAMPLE_H +#define SLANG_LIBRARY_TEXSAMPLE_H + +#if defined __cplusplus +extern "C" { +#endif + +GLvoid _slang_library_tex1d (GLfloat, GLfloat, GLfloat, GLfloat *); +GLvoid _slang_library_tex2d (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat *); +GLvoid _slang_library_tex3d (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat *); +GLvoid _slang_library_texcube (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat *); +GLvoid _slang_library_shad1d (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat *); +GLvoid _slang_library_shad2d (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat *); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index 7216663e3f..58d17c1558 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -30,6 +30,7 @@ #include "imports.h" #include "slang_link.h" +#include "slang_analyse.h" /* * slang_uniform_bindings @@ -69,7 +70,7 @@ static GLboolean slang_uniform_bindings_add (slang_uniform_bindings *self, slang return GL_FALSE; self->table[n].quant = q; self->table[n].name = slang_string_duplicate (name); - for (i = 0; i < SLANG_UNIFORM_BINDING_MAX; i++) + for (i = 0; i < SLANG_SHADER_MAX; i++) self->table[n].address[i] = ~0; self->table[n].address[index] = address; if (self->table[n].name == NULL) @@ -222,6 +223,21 @@ static GLboolean gather_active_uniforms (slang_active_uniforms *u, slang_export_ return GL_TRUE; } +/* + * slang_texture_bindings + */ + +GLvoid slang_texture_usages_ctr (slang_texture_usages *self) +{ + self->table = NULL; + self->count = 0; +} + +GLvoid slang_texture_usages_dtr (slang_texture_usages *self) +{ + slang_alloc_free (self->table); +} + /* * slang_program */ @@ -232,13 +248,15 @@ GLvoid slang_program_ctr (slang_program *self) slang_uniform_bindings_ctr (&self->uniforms); slang_active_uniforms_ctr (&self->active_uniforms); - for (i = 0; i < SLANG_UNIFORM_BINDING_MAX; i++) + slang_texture_usages_ctr (&self->texture_usage); + for (i = 0; i < SLANG_SHADER_MAX; i++) { GLuint j; for (j = 0; j < SLANG_COMMON_FIXED_MAX; j++) self->common_fixed_entries[i][j] = ~0; - self->code[i] = ~0; + for (j = 0; j < SLANG_COMMON_CODE_MAX; j++) + self->code[i][j] = ~0; self->machines[i] = NULL; self->assemblies[i] = NULL; } @@ -252,6 +270,7 @@ GLvoid slang_program_dtr (slang_program *self) { slang_uniform_bindings_dtr (&self->uniforms); slang_active_uniforms_dtr (&self->active_uniforms); + slang_texture_usages_dtr (&self->texture_usage); } /* @@ -273,7 +292,7 @@ static GLuint gd (slang_export_data_table *tbl, const char *name) return ~0; } -static GLvoid fill_common_fixed_entries (GLuint e[], slang_export_data_table *tbl) +static GLvoid resolve_common_fixed (GLuint e[], slang_export_data_table *tbl) { e[SLANG_COMMON_FIXED_MODELVIEWMATRIX] = gd (tbl, "gl_ModelViewMatrix"); e[SLANG_COMMON_FIXED_PROJECTIONMATRIX] = gd (tbl, "gl_ProjectionMatrix"); @@ -322,7 +341,7 @@ static GLvoid fill_common_fixed_entries (GLuint e[], slang_export_data_table *tb e[SLANG_COMMON_FIXED_FOG] = gd (tbl, "gl_Fog"); } -static GLvoid fill_vertex_fixed_entries (GLuint e[], slang_export_data_table *tbl) +static GLvoid resolve_vertex_fixed (GLuint e[], slang_export_data_table *tbl) { e[SLANG_VERTEX_FIXED_POSITION] = gd (tbl, "gl_Position"); e[SLANG_VERTEX_FIXED_POINTSIZE] = gd (tbl, "gl_PointSize"); @@ -348,7 +367,7 @@ static GLvoid fill_vertex_fixed_entries (GLuint e[], slang_export_data_table *tb e[SLANG_VERTEX_FIXED_FOGFRAGCOORD] = gd (tbl, "gl_FogFragCoord"); } -static GLvoid fill_fragment_fixed_entries (GLuint e[], slang_export_data_table *tbl) +static GLvoid resolve_fragment_fixed (GLuint e[], slang_export_data_table *tbl) { e[SLANG_FRAGMENT_FIXED_FRAGCOORD] = gd (tbl, "gl_FragCoord"); e[SLANG_FRAGMENT_FIXED_FRONTFACING] = gd (tbl, "gl_FrontFacing"); @@ -376,9 +395,9 @@ static GLuint gc (slang_export_code_table *tbl, const char *name) return ~0; } -static GLvoid resolve_code (GLuint code[], slang_export_code_table *tbl) +static GLvoid resolve_common_code (GLuint code[], slang_export_code_table *tbl) { - code[0] = gc (tbl, "@main"); + code[SLANG_COMMON_CODE_MAIN] = gc (tbl, "@main"); } GLboolean _slang_link (slang_program *prog, slang_translation_unit **units, GLuint count) @@ -391,25 +410,28 @@ GLboolean _slang_link (slang_program *prog, slang_translation_unit **units, GLui if (units[i]->type == slang_unit_fragment_shader) { - index = SLANG_UNIFORM_BINDING_FRAGMENT; - fill_fragment_fixed_entries (prog->fragment_fixed_entries, &units[i]->exp_data); + index = SLANG_SHADER_FRAGMENT; + resolve_fragment_fixed (prog->fragment_fixed_entries, &units[i]->exp_data); } else { - index = SLANG_UNIFORM_BINDING_VERTEX; - fill_vertex_fixed_entries (prog->vertex_fixed_entries, &units[i]->exp_data); + index = SLANG_SHADER_VERTEX; + resolve_vertex_fixed (prog->vertex_fixed_entries, &units[i]->exp_data); } if (!gather_uniform_bindings (&prog->uniforms, &units[i]->exp_data, index)) return GL_FALSE; if (!gather_active_uniforms (&prog->active_uniforms, &units[i]->exp_data)) return GL_FALSE; - fill_common_fixed_entries (prog->common_fixed_entries[index], &units[i]->exp_data); - resolve_code (&prog->code[index], &units[i]->exp_code); + resolve_common_fixed (prog->common_fixed_entries[index], &units[i]->exp_data); + resolve_common_code (prog->code[index], &units[i]->exp_code); prog->machines[index] = units[i]->machine; prog->assemblies[index] = units[i]->assembly; } + if (!_slang_analyse_texture_usage (prog)) + return GL_FALSE; + return GL_TRUE; } diff --git a/src/mesa/shader/slang/slang_link.h b/src/mesa/shader/slang/slang_link.h index 5f8c4e7335..faebae625e 100644 --- a/src/mesa/shader/slang/slang_link.h +++ b/src/mesa/shader/slang/slang_link.h @@ -42,7 +42,7 @@ typedef struct { slang_export_data_quant *quant; char *name; - GLuint address[SLANG_UNIFORM_BINDING_MAX]; + GLuint address[SLANG_SHADER_MAX]; } slang_uniform_binding; typedef struct @@ -63,6 +63,21 @@ typedef struct GLuint count; } slang_active_uniforms; +typedef struct +{ + slang_export_data_quant *quant; + GLuint frag_address; +} slang_texture_usage; + +typedef struct +{ + slang_texture_usage *table; + GLuint count; +} slang_texture_usages; + +GLvoid slang_texture_usages_ctr (slang_texture_usages *); +GLvoid slang_texture_usages_dtr (slang_texture_usages *); + enum { SLANG_COMMON_FIXED_MODELVIEWMATRIX, @@ -148,16 +163,23 @@ enum SLANG_FRAGMENT_FIXED_MAX }; +enum +{ + SLANG_COMMON_CODE_MAIN, + SLANG_COMMON_CODE_MAX +}; + typedef struct { slang_uniform_bindings uniforms; slang_active_uniforms active_uniforms; - GLuint common_fixed_entries[SLANG_UNIFORM_BINDING_MAX][SLANG_COMMON_FIXED_MAX]; + slang_texture_usages texture_usage; + GLuint common_fixed_entries[SLANG_SHADER_MAX][SLANG_COMMON_FIXED_MAX]; GLuint vertex_fixed_entries[SLANG_VERTEX_FIXED_MAX]; GLuint fragment_fixed_entries[SLANG_FRAGMENT_FIXED_MAX]; - GLuint code[SLANG_UNIFORM_BINDING_MAX]; - slang_machine *machines[SLANG_UNIFORM_BINDING_MAX]; - slang_assembly_file *assemblies[SLANG_UNIFORM_BINDING_MAX]; + GLuint code[SLANG_SHADER_MAX][SLANG_COMMON_CODE_MAX]; + slang_machine *machines[SLANG_SHADER_MAX]; + slang_assembly_file *assemblies[SLANG_SHADER_MAX]; } slang_program; GLvoid slang_program_ctr (slang_program *); -- cgit v1.2.3