Added more examples.

This commit is contained in:
bkaradzic 2012-10-07 20:41:18 -07:00
parent f1597ee25c
commit cfac3feb85
2357 changed files with 389777 additions and 116988 deletions

View file

@ -1,10 +0,0 @@
;; -*- emacs-lisp -*-
;;
;; This file is processed by the dirvars emacs package. Each variable
;; setting below is performed when this dirvars file is loaded.
;;
indent-tabs-mode: nil
tab-width: 8
c-basic-offset: 3
kde-emacs-after-parent-string: ""
evaluate: (c-set-offset 'inline-open '0)

View file

@ -2,6 +2,8 @@
*.dll
*.exe
*.ilk
*.la
*.lo
*.o
*.obj
*.os
@ -10,6 +12,7 @@
*.pyc
*.pyo
*.so
*.so.*
*.sw[a-z]
*.tar
*.tar.bz2
@ -18,9 +21,11 @@
*~
depend
depend.bak
bin/ltmain.sh
lib
lib64
configure
configure.lineno
autom4te.cache
aclocal.m4
config.log
@ -29,8 +34,14 @@ cscope*
.scon*
config.py
build
libtool
manifest.txt
Makefile.in
.dir-locals.el
.deps/
.libs/
/Makefile
*.pbxuser
*.perspectivev3
*.mode1v3
@ -50,7 +61,6 @@ CMakeCache.txt
.cproject
glsl_main
glsl_test
glcpp
glslopt
glsl_compiler
.settings/

View file

@ -10,11 +10,12 @@ unfortunately they *also* lack offline shader compilers. So using a GLSL optimiz
before can make the shader run much faster on a platform like that. See performance numbers
in [this blog post](http://aras-p.info/blog/2010/09/29/glsl-optimizer/).
Almost all actual code is [Mesa 3D's GLSL2](http://cgit.freedesktop.org/mesa/mesa/log/?h=glsl2)
compiler; all this library does is spits out optimized GLSL back.
Almost all actual code is [Mesa 3D's GLSL](http://cgit.freedesktop.org/mesa/mesa/log/)
compiler; all this library does is spits out optimized GLSL back, and adds GLES type precision
handling to the optimizer.
This GLSL optimizer is made for [Unity's](http://unity3d.com/) purposes and is built-in
in [Unity 3.0](http://unity3d.com/unity/whats-new/unity-3).
in [Unity 3](http://unity3d.com/unity/whats-new/unity-3) and later.
GLSL Optimizer is licensed according to the terms of the MIT license.
@ -46,5 +47,6 @@ Interface for the library is `src/glsl/glsl_optimizer.h`. General usage is:
Notes
-----
* I haven't checked if/how it works with higher GLSL versions than the
default (1.10?).
* GLSL versions 1.10 and 1.20 are supported. 1.10 is the default, use #version 120 to specify
1.20.
* GLSL ES version 1.00 is supported.

View file

@ -3,16 +3,12 @@
srcdir=`dirname "$0"`
test -z "$srcdir" && srcdir=.
SRCDIR=`(cd "$srcdir" && pwd)`
ORIGDIR=`pwd`
if test "x$SRCDIR" != "x$ORIGDIR"; then
echo "Mesa cannot be built when srcdir != builddir" 1>&2
exit 1
fi
MAKEFLAGS=""
cd "$srcdir"
autoreconf -v --install || exit 1
cd $ORIGDIR || exit $?
"$srcdir"/configure "$@"
if test -z "$NOCONFIGURE"; then
"$srcdir"/configure "$@"
fi

View file

@ -0,0 +1,148 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "glsl_optimizer.h"
static glslopt_ctx* gContext = 0;
static int printhelp(const char* msg)
{
if (msg) printf("%s\n\n\n", msg);
printf("Usage: glslopt <-f|-v> <input shader> [<output shader>]\n");
printf("\t-f : fragment shader\n");
printf("\t-v : vertex shader\n");
printf("\n\tIf no output specified, output is to [input].out.\n");
return 1;
}
static bool init()
{
gContext = glslopt_initialize(false);
if( !gContext )
return false;
return true;
}
static void term()
{
glslopt_cleanup(gContext);
}
static char* loadFile(const char* filename)
{
FILE* file = fopen(filename, "rt");
if( !file )
{
printf("Failed to open %s for reading\n", filename);
return 0;
}
fseek(file, 0, SEEK_END);
const int size = ftell(file);
fseek(file, 0, SEEK_SET);
char* result = new char[size+1];
const int count = (int)fread(result, 1, size, file);
result[count] = 0;
fclose(file);
return result;
}
static bool saveFile(const char* filename, const char* data)
{
int size = (int)strlen(data)+1;
FILE* file = fopen(filename, "wt");
if( !file )
{
printf( "Failed to open %s for writing\n", filename);
return false;
}
if( 1 != fwrite(data,size,1,file) )
{
printf( "Failed to write to %s\n", filename);
fclose(file);
return false;
}
fclose(file);
return true;
}
static bool compileShader(const char* dstfilename, const char* srcfilename, bool vertexShader)
{
const char* originalShader = loadFile(srcfilename);
if( !originalShader )
return false;
const glslopt_shader_type type = vertexShader ? kGlslOptShaderVertex : kGlslOptShaderFragment;
glslopt_shader* shader = glslopt_optimize(gContext, type, originalShader, 0);
if( !glslopt_get_status(shader) )
{
printf( "Failed to compile %s:\n\n%s\n", srcfilename, glslopt_get_log(shader));
return false;
}
const char* optimizedShader = glslopt_get_output(shader);
if( !saveFile(dstfilename, optimizedShader) )
return false;
delete[] originalShader;
return true;
}
int main(int argc, char* argv[])
{
if( argc < 3 )
return printhelp(NULL);
bool vertexShader = false, freename = false;
const char* source = 0;
char* dest = 0;
for( int i=1; i < argc; i++ )
{
if( argv[i][0] == '-' )
{
if( 0 == strcmp("-v", argv[i]) )
vertexShader = true;
if( 0 == strcmp("-f", argv[i]) )
vertexShader = false;
}
else
{
if( source == 0 )
source = argv[i];
else if( dest == 0 )
dest = argv[i];
}
}
if( !source )
return printhelp("Must give a source");
if( !init() )
{
printf("Failed to initialize glslopt!\n");
return 1;
}
if ( !dest ) {
dest = (char *) calloc(strlen(source)+5, sizeof(char));
snprintf(dest, strlen(source)+5, "%s.out", source);
freename = true;
}
int result = 0;
if( !compileShader(dest, source, vertexShader) )
result = 1;
if( freename ) free(dest);
term();
return result;
}

View file

@ -0,0 +1,16 @@
# Linux build for the sample app
OBJS = Main.o
.PHONY: clean all
LDFLAGS += -Wl,-O1 -Wl,-gc-sections
CPPFLAGS += -I ../../src/glsl -L ../../src/glsl
CXXFLAGS += -Wall -Os -s
all: $(OBJS)
g++ -o glslopt Main.o $(CPPFLAGS) -lglslopt $(CXXFLAGS) $(LDFLAGS)
clean:
rm -f glslopt $(OBJS)

View file

@ -0,0 +1,13 @@
This is a small sample program to get you quickly up and running, it transforms an input textfile
to an output textfile. The input source textfile should be a fully preprocessed GLSL shader and
the output should be a simple shader in textform.
The project file is generated by BadgerConfig.
VS2005
BadgerConfig
Jim Tilander, Santa Monica 2010

View file

@ -0,0 +1,105 @@
#
# Console files...
#
Main.cpp
Readme
#
# Original test program ..
#
#../../src/glsl/glsl_optimizer_main.cpp
#
# Mesa GLSL2 + GLSL Optimizer
#
../../src/mesa/program/hash_table.c
../../src/mesa/program/hash_table.h
../../src/mesa/program/symbol_table.c
../../src/mesa/program/symbol_table.h
../../src/talloc/talloc.c
../../src/talloc/talloc.h
../../src/glsl/ast.h
../../src/glsl/ast_expr.cpp
../../src/glsl/ast_function.cpp
../../src/glsl/ast_to_hir.cpp
../../src/glsl/ast_type.cpp
../../src/glsl/builtin_function.cpp
../../src/glsl/builtin_types.h
../../src/glsl/builtin_variables.h
../../src/glsl/glsl_lexer.cpp
../../src/glsl/glsl_lexer.lpp
../../src/glsl/glsl_optimizer.cpp
../../src/glsl/glsl_optimizer.h
../../src/glsl/glsl_parser.cpp
../../src/glsl/glsl_parser.h
../../src/glsl/glsl_parser.ypp
../../src/glsl/glsl_parser_extras.cpp
../../src/glsl/glsl_parser_extras.h
../../src/glsl/glsl_symbol_table.h
../../src/glsl/glsl_types.cpp
../../src/glsl/glsl_types.h
../../src/glsl/hir_field_selection.cpp
../../src/glsl/ir.cpp
../../src/glsl/ir.h
../../src/glsl/ir_algebraic.cpp
../../src/glsl/ir_basic_block.cpp
../../src/glsl/ir_basic_block.h
../../src/glsl/ir_clone.cpp
../../src/glsl/ir_constant_expression.cpp
../../src/glsl/ir_constant_folding.cpp
../../src/glsl/ir_constant_propagation.cpp
../../src/glsl/ir_constant_variable.cpp
../../src/glsl/ir_copy_propagation.cpp
../../src/glsl/ir_dead_code.cpp
../../src/glsl/ir_dead_code_local.cpp
../../src/glsl/ir_dead_functions.cpp
../../src/glsl/ir_div_to_mul_rcp.cpp
../../src/glsl/ir_expression_flattening.cpp
../../src/glsl/ir_expression_flattening.h
../../src/glsl/ir_function.cpp
../../src/glsl/ir_function_can_inline.cpp
../../src/glsl/ir_function_inlining.cpp
../../src/glsl/ir_function_inlining.h
../../src/glsl/ir_hierarchical_visitor.cpp
../../src/glsl/ir_hierarchical_visitor.h
../../src/glsl/ir_hv_accept.cpp
../../src/glsl/ir_if_return.cpp
../../src/glsl/ir_if_simplification.cpp
../../src/glsl/ir_if_to_cond_assign.cpp
../../src/glsl/ir_import_prototypes.cpp
../../src/glsl/ir_mat_op_to_vec.cpp
../../src/glsl/ir_mod_to_fract.cpp
../../src/glsl/ir_noop_swizzle.cpp
../../src/glsl/ir_optimization.h
../../src/glsl/ir_print_glsl_visitor.cpp
../../src/glsl/ir_print_glsl_visitor.h
../../src/glsl/ir_print_visitor.cpp
../../src/glsl/ir_print_visitor.h
../../src/glsl/ir_reader.cpp
../../src/glsl/ir_reader.h
../../src/glsl/ir_rvalue_visitor.cpp
../../src/glsl/ir_rvalue_visitor.h
../../src/glsl/ir_structure_splitting.cpp
../../src/glsl/ir_sub_to_add_neg.cpp
../../src/glsl/ir_swizzle_swizzle.cpp
../../src/glsl/ir_tree_grafting.cpp
../../src/glsl/ir_unused_structs.cpp
../../src/glsl/ir_unused_structs.h
../../src/glsl/ir_validate.cpp
../../src/glsl/ir_variable.cpp
../../src/glsl/ir_variable_refcount.cpp
../../src/glsl/ir_variable_refcount.h
../../src/glsl/ir_vec_index_to_cond_assign.cpp
../../src/glsl/ir_vec_index_to_swizzle.cpp
../../src/glsl/ir_visitor.h
../../src/glsl/link_functions.cpp
../../src/glsl/linker.cpp
../../src/glsl/linker.h
../../src/glsl/list.h
#../../src/glsl/main.cpp
../../src/glsl/program.h
../../src/glsl/s_expression.cpp
../../src/glsl/s_expression.h
../../src/glsl/msvc/msvccompat.h

View file

@ -0,0 +1,10 @@
[General]
Type = ConsoleApplication
SourceFiles = SourceFiles
Platform = Tool
[Project]
IncludePaths=../../src/talloc;../../include;../../src/mesa;../../src/mapi;../../src/glsl/msvc;../../src/glsl
Defines=snprintf=_snprintf;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE
DisabledVcWarnings=4291;4996;4800;4099;4244;4018;4245
Libraries=opengl32.lib

View file

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glslopt", "glslopt.vcproj", "{790F4C89-6715-EB39-C392-3FC1D1DB9618}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Final|Win32 = Final|Win32
Profile|Win32 = Profile|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{790F4C89-6715-EB39-C392-3FC1D1DB9618}.Debug|Win32.ActiveCfg = Debug|Win32
{790F4C89-6715-EB39-C392-3FC1D1DB9618}.Debug|Win32.Build.0 = Debug|Win32
{790F4C89-6715-EB39-C392-3FC1D1DB9618}.Final|Win32.ActiveCfg = Final|Win32
{790F4C89-6715-EB39-C392-3FC1D1DB9618}.Final|Win32.Build.0 = Final|Win32
{790F4C89-6715-EB39-C392-3FC1D1DB9618}.Profile|Win32.ActiveCfg = Profile|Win32
{790F4C89-6715-EB39-C392-3FC1D1DB9618}.Profile|Win32.Build.0 = Profile|Win32
{790F4C89-6715-EB39-C392-3FC1D1DB9618}.Release|Win32.ActiveCfg = Release|Win32
{790F4C89-6715-EB39-C392-3FC1D1DB9618}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,897 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="glslopt"
ProjectGUID="{790F4C89-6715-EB39-C392-3FC1D1DB9618}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(ProjectDir)$(ConfigurationName)"
IntermediateDirectory="$(ProjectDir)$(ConfigurationName)"
ConfigurationType="1"
UseOfMFC="0"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalOptions=""
AdditionalIncludeDirectories=";../../src/talloc;../../include;../../src/mesa;../../src/mapi;../../src/glsl/msvc;../../src/glsl;../../../../../Shared;../../../../../Tools/Shared;../../../freetype-2.1.10/include;../../../Lua/include;../../../FreeImage;../../../../Include;../../.."
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;snprintf=_snprintf;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;AURORA_TOOL;AURORA_DEBUGG"
StringPooling="false"
MinimalRebuild="false"
ExceptionHandling="2"
BasicRuntimeChecks="3"
SmallerTypeCheck="true"
RuntimeLibrary="3"
StructMemberAlignment="3"
BufferSecurityCheck="true"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="0"
FloatingPointExceptions="false"
DisableLanguageExtensions="false"
DefaultCharIsUnsigned="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
OpenMP="false"
UsePrecompiledHeader="0"
PrecompiledHeaderThrough="PreCompiled.h"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
CallingConvention="0"
CompileAs="0"
DisableSpecificWarnings="4512;4127;4996;4291;4291;4996;4800;4099;4244;4018;4245"
UseFullPaths="false"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
UseLibraryDependencyInputs="true"
AdditionalDependencies="opengl32.lib "
ShowProgress="0"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../../freetype-2.1.10/lib;../../../Lua/lib;../../../FreeImage;../../../../Lib "
GenerateManifest="true"
ModuleDefinitionFile=""
GenerateDebugInformation="true"
GenerateMapFile="true"
MapFileName="$(TargetDir)$(TargetName).map"
MapExports="false"
SubSystem="1"
StackReserveSize="8388608"
StackCommitSize="8388608"
LargeAddressAware="2"
TargetMachine="1"
AllowIsolation="true"
Profile="false"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description=""
CommandLine=""
ExcludedFromBuild="false"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(ProjectDir)$(ConfigurationName)"
IntermediateDirectory="$(ProjectDir)$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
UseOfMFC="0"
WholeProgramOptimization="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
AdditionalOptions=""
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="2"
OmitFramePointers="false"
WholeProgramOptimization="false"
AdditionalIncludeDirectories=";../../src/talloc;../../include;../../src/mesa;../../src/mapi;../../src/glsl/msvc;../../src/glsl;../../../../../Shared;../../../../../Tools/Shared;../../../freetype-2.1.10/include;../../../Lua/include;../../../FreeImage;../../../../Include;../../.."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;snprintf=_snprintf;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;AURORA_TOOL;AURORA_RELEASE"
StringPooling="false"
MinimalRebuild="false"
ExceptionHandling="2"
BasicRuntimeChecks="0"
SmallerTypeCheck="false"
RuntimeLibrary="2"
StructMemberAlignment="3"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="2"
FloatingPointExceptions="false"
DisableLanguageExtensions="false"
DefaultCharIsUnsigned="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
OpenMP="false"
UsePrecompiledHeader="0"
PrecompiledHeaderThrough="PreCompiled.h"
AssemblerOutput="0"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CallingConvention="0"
CompileAs="0"
DisableSpecificWarnings="4512;4127;4996;4291;4291;4996;4800;4099;4244;4018;4245"
UseFullPaths="false"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
UseLibraryDependencyInputs="true"
AdditionalDependencies="opengl32.lib "
ShowProgress="0"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../../freetype-2.1.10/lib;../../../Lua/lib;../../../FreeImage;../../../../Lib "
GenerateManifest="true"
ModuleDefinitionFile=""
GenerateDebugInformation="true"
GenerateMapFile="true"
MapFileName="$(TargetDir)$(TargetName).map"
MapExports="false"
SubSystem="1"
StackReserveSize="8388608"
StackCommitSize="8388608"
LargeAddressAware="2"
TargetMachine="1"
AllowIsolation="true"
Profile="false"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description=""
CommandLine=""
ExcludedFromBuild="false"
/>
</Configuration>
<Configuration
Name="Profile|Win32"
OutputDirectory="$(ProjectDir)$(ConfigurationName)"
IntermediateDirectory="$(ProjectDir)$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
UseOfMFC="0"
WholeProgramOptimization="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
AdditionalOptions=""
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="2"
OmitFramePointers="false"
WholeProgramOptimization="false"
AdditionalIncludeDirectories=";../../src/talloc;../../include;../../src/mesa;../../src/mapi;../../src/glsl/msvc;../../src/glsl;../../../../../Shared;../../../../../Tools/Shared;../../../freetype-2.1.10/include;../../../Lua/include;../../../FreeImage;../../../../Include;../../.."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;snprintf=_snprintf;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;AURORA_TOOL;AURORA_PROFILE"
StringPooling="false"
MinimalRebuild="false"
ExceptionHandling="2"
BasicRuntimeChecks="0"
SmallerTypeCheck="false"
RuntimeLibrary="2"
StructMemberAlignment="3"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="false"
EnableEnhancedInstructionSet="2"
FloatingPointExceptions="false"
DisableLanguageExtensions="false"
DefaultCharIsUnsigned="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
OpenMP="false"
UsePrecompiledHeader="0"
PrecompiledHeaderThrough="PreCompiled.h"
AssemblerOutput="0"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CallingConvention="0"
CompileAs="0"
DisableSpecificWarnings="4512;4127;4996;4291;4291;4996;4800;4099;4244;4018;4245"
UseFullPaths="false"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
UseLibraryDependencyInputs="false"
AdditionalDependencies="opengl32.lib "
ShowProgress="0"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../../freetype-2.1.10/lib;../../../Lua/lib;../../../FreeImage;../../../../Lib "
GenerateManifest="true"
ModuleDefinitionFile=""
GenerateDebugInformation="true"
GenerateMapFile="true"
MapFileName="$(TargetDir)$(TargetName).map"
MapExports="false"
SubSystem="1"
StackReserveSize="8388608"
StackCommitSize="8388608"
LargeAddressAware="2"
TargetMachine="1"
AllowIsolation="true"
Profile="false"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description=""
CommandLine=""
ExcludedFromBuild="false"
/>
</Configuration>
<Configuration
Name="Final|Win32"
OutputDirectory="$(ProjectDir)$(ConfigurationName)"
IntermediateDirectory="$(ProjectDir)$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
UseOfMFC="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
AdditionalOptions=""
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="2"
OmitFramePointers="false"
WholeProgramOptimization="true"
AdditionalIncludeDirectories=";../../src/talloc;../../include;../../src/mesa;../../src/mapi;../../src/glsl/msvc;../../src/glsl;../../../../../Shared;../../../../../Tools/Shared;../../../freetype-2.1.10/include;../../../Lua/include;../../../FreeImage;../../../../Include;../../.."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;snprintf=_snprintf;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;AURORA_TOOL;AURORA_FINAL;AURORA_RETAIL"
StringPooling="false"
MinimalRebuild="false"
ExceptionHandling="2"
BasicRuntimeChecks="0"
SmallerTypeCheck="false"
RuntimeLibrary="2"
StructMemberAlignment="3"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="false"
EnableEnhancedInstructionSet="2"
FloatingPointExceptions="false"
DisableLanguageExtensions="false"
DefaultCharIsUnsigned="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
OpenMP="false"
UsePrecompiledHeader="0"
PrecompiledHeaderThrough="PreCompiled.h"
AssemblerOutput="0"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CallingConvention="0"
CompileAs="0"
DisableSpecificWarnings="4512;4127;4996;4291;4291;4996;4800;4099;4244;4018;4245"
UseFullPaths="false"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkLibraryDependencies="true"
UseLibraryDependencyInputs="false"
AdditionalDependencies="opengl32.lib "
ShowProgress="0"
OutputFile="$(OutDir)\$(ProjectName).exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../../freetype-2.1.10/lib;../../../Lua/lib;../../../FreeImage;../../../../Lib "
GenerateManifest="true"
ModuleDefinitionFile=""
GenerateDebugInformation="true"
GenerateMapFile="true"
MapFileName="$(TargetDir)$(TargetName).map"
MapExports="false"
SubSystem="1"
StackReserveSize="8388608"
StackCommitSize="8388608"
LargeAddressAware="2"
TargetMachine="1"
AllowIsolation="true"
Profile="false"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
Description=""
CommandLine=""
ExcludedFromBuild="false"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath="Main.cpp"
>
</File>
<File
RelativePath="Readme"
>
</File>
<Filter
Name="src"
>
<Filter
Name="mesa"
>
<Filter
Name="program"
>
<File
RelativePath="..\..\src\mesa\program\hash_table.c"
>
</File>
<File
RelativePath="..\..\src\mesa\program\hash_table.h"
>
</File>
<File
RelativePath="..\..\src\mesa\program\symbol_table.c"
>
</File>
<File
RelativePath="..\..\src\mesa\program\symbol_table.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="talloc"
>
<File
RelativePath="..\..\src\talloc\talloc.c"
>
</File>
<File
RelativePath="..\..\src\talloc\talloc.h"
>
</File>
</Filter>
<Filter
Name="glsl"
>
<File
RelativePath="..\..\src\glsl\ast.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ast_expr.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ast_function.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ast_to_hir.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ast_type.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\builtin_function.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\builtin_types.h"
>
</File>
<File
RelativePath="..\..\src\glsl\builtin_variables.h"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_lexer.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_lexer.lpp"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_optimizer.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_optimizer.h"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_parser.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_parser.h"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_parser.ypp"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_parser_extras.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_parser_extras.h"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_symbol_table.h"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_types.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\glsl_types.h"
>
</File>
<File
RelativePath="..\..\src\glsl\hir_field_selection.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_algebraic.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_basic_block.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_basic_block.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_clone.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_constant_expression.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_constant_folding.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_constant_propagation.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_constant_variable.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_copy_propagation.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_dead_code.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_dead_code_local.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_dead_functions.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_div_to_mul_rcp.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_expression_flattening.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_expression_flattening.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_function.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_function_can_inline.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_function_inlining.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_function_inlining.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_hierarchical_visitor.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_hierarchical_visitor.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_hv_accept.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_if_return.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_if_simplification.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_if_to_cond_assign.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_import_prototypes.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_mat_op_to_vec.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_mod_to_fract.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_noop_swizzle.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_optimization.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_print_glsl_visitor.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_print_glsl_visitor.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_print_visitor.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_print_visitor.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_reader.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_reader.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_rvalue_visitor.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_rvalue_visitor.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_structure_splitting.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_sub_to_add_neg.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_swizzle_swizzle.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_tree_grafting.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_unused_structs.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_unused_structs.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_validate.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_variable.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_variable_refcount.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_variable_refcount.h"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_vec_index_to_cond_assign.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_vec_index_to_swizzle.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\ir_visitor.h"
>
</File>
<File
RelativePath="..\..\src\glsl\link_functions.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\linker.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\linker.h"
>
</File>
<File
RelativePath="..\..\src\glsl\list.h"
>
</File>
<File
RelativePath="..\..\src\glsl\program.h"
>
</File>
<File
RelativePath="..\..\src\glsl\s_expression.cpp"
>
</File>
<File
RelativePath="..\..\src\glsl\s_expression.h"
>
</File>
<Filter
Name="msvc"
>
<File
RelativePath="..\..\src\glsl\msvc\msvccompat.h"
>
</File>
</Filter>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -1,5 +1,5 @@
#! /bin/sh
flex --nounistd -osrc/glsl/glcpp/glcpp-lex.c src/glsl/glcpp/glcpp-lex.l
flex --nounistd -osrc/glsl/glsl_lexer.cpp src/glsl/glsl_lexer.ll
bison -v -o "src/glsl/glcpp/glcpp-parse.c" --defines=src/glsl/glcpp/glcpp-parse.h src/glsl/glcpp/glcpp-parse.y
bison -v -o "src/glsl/glcpp/glcpp-parse.c" -p "glcpp_parser_" --defines=src/glsl/glcpp/glcpp-parse.h src/glsl/glcpp/glcpp-parse.y
bison -v -o "src/glsl/glsl_parser.cpp" -p "_mesa_glsl_" --defines=src/glsl/glsl_parser.h src/glsl/glsl_parser.yy

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,8 @@
#! /bin/sh
git rm -rf docs
git rm -rf src/egl
git rm -rf src/mesa/drivers
git rm -rf src/gallium
git rm -rf src/glx
git rm -rf src/gtest
git rm -rf $(git status --porcelain | awk '/^DU/ {print $NF}')

View file

@ -0,0 +1 @@
/Makefile

View file

@ -0,0 +1,3 @@
((c-mode . ((c-basic-offset . 3)))
(c++-mode . ((c-basic-offset . 3)))
)

View file

@ -1,4 +1,8 @@
glsl_compiler
glsl_lexer.cc
glsl_parser.cc
glsl_parser.h
glsl_parser.output
builtin_compiler
glsl_test

View file

@ -0,0 +1,99 @@
# A simple makefile to build glsl-optimizer on linux
CPPFLAGS += -I../talloc \
-I../mesa \
-I../mapi
CXXFLAGS += -s -Wall -Os -fdata-sections -ffunction-sections
CFLAGS += -s -Wall -Os -fdata-sections -ffunction-sections
# This list gleaned from the VC project file. Update when needed
SRC = ast_expr.cpp \
ast_function.cpp \
ast_to_hir.cpp \
ast_type.cpp \
builtin_function.cpp \
glsl_lexer.cpp \
glsl_optimizer.cpp \
glsl_parser.cpp \
glsl_parser_extras.cpp \
glsl_symbol_table.cpp \
glsl_types.cpp \
hir_field_selection.cpp \
ir.cpp \
ir_basic_block.cpp \
ir_clone.cpp \
ir_constant_expression.cpp \
ir_expression_flattening.cpp \
ir_function.cpp \
ir_function_can_inline.cpp \
ir_function_detect_recursion.cpp \
ir_hierarchical_visitor.cpp \
ir_hv_accept.cpp \
ir_import_prototypes.cpp \
ir_print_glsl_visitor.cpp \
ir_print_visitor.cpp \
ir_reader.cpp \
ir_rvalue_visitor.cpp \
ir_unused_structs.cpp \
ir_validate.cpp \
ir_variable.cpp \
ir_variable_refcount.cpp \
link_functions.cpp \
linker.cpp \
loop_analysis.cpp \
loop_controls.cpp \
loop_unroll.cpp \
lower_discard.cpp \
lower_if_to_cond_assign.cpp \
lower_instructions.cpp \
lower_jumps.cpp \
lower_mat_op_to_vec.cpp \
lower_noise.cpp \
lower_variable_index_to_cond_assign.cpp \
lower_vec_index_to_cond_assign.cpp \
lower_vec_index_to_swizzle.cpp \
lower_vector.cpp \
main.cpp \
opt_algebraic.cpp \
opt_constant_folding.cpp \
opt_constant_propagation.cpp \
opt_constant_variable.cpp \
opt_copy_propagation.cpp \
opt_copy_propagation_elements.cpp \
opt_dead_code.cpp \
opt_dead_code_local.cpp \
opt_dead_functions.cpp \
opt_discard_simplification.cpp \
opt_function_inlining.cpp \
opt_if_simplification.cpp \
opt_noop_swizzle.cpp \
opt_redundant_jumps.cpp \
opt_structure_splitting.cpp \
opt_swizzle_swizzle.cpp \
opt_tree_grafting.cpp \
ralloc.c \
s_expression.cpp \
standalone_scaffolding.cpp \
strtod.c \
glcpp/glcpp-lex.c \
glcpp/glcpp-parse.c \
glcpp/glcpp.c \
glcpp/pp.c \
../mesa/program/hash_table.c \
../mesa/program/symbol_table.c
OBJS1 = $(SRC:.cpp=.o)
OBJS = $(OBJS1:.c=.o)
LIBNAME = libglslopt.a
.PHONY: clean all
all: $(OBJS)
ar cr $(LIBNAME) $(OBJS)
ranlib $(LIBNAME)
clean:
rm -f $(OBJS) $(LIBNAME)

View file

@ -177,7 +177,6 @@ ir_unop_fract was added. The following areas need updating to add a
new expression type:
ir.h (new enum)
ir.cpp:get_num_operands() (used for ir_reader)
ir.cpp:operator_strs (used for ir_reader)
ir_constant_expression.cpp (you probably want to be able to constant fold)
ir_validate.cpp (check users have the right types)

View file

@ -14,10 +14,10 @@ env.Prepend(CPPPATH = [
'#src/glsl/glcpp',
])
# Make glcpp/glcpp-parse.h and glsl_parser.h reacheable from the include path
env.Append(CPPPATH = [Dir('.').abspath])
# Make glcpp-parse.h and glsl_parser.h reachable from the include path.
env.Append(CPPPATH = [Dir('.').abspath, Dir('glcpp').abspath])
env.Append(YACCFLAGS = '-d')
env.Append(YACCFLAGS = '-d -p "glcpp_parser_"')
parser_env = env.Clone()
parser_env.Append(YACCFLAGS = [
@ -25,81 +25,30 @@ parser_env.Append(YACCFLAGS = [
'-p', '_mesa_glsl_',
])
# without this line scons will expect "glsl_parser.hpp" instead of
# "glsl_parser.h", causing glsl_parser.cpp to be regenerated every time
parser_env['YACCHXXFILESUFFIX'] = '.h'
glcpp_lexer = env.CFile('glcpp/glcpp-lex.c', 'glcpp/glcpp-lex.l')
glcpp_parser = env.CFile('glcpp/glcpp-parse.c', 'glcpp/glcpp-parse.y')
glsl_lexer = parser_env.CXXFile('glsl_lexer.cpp', 'glsl_lexer.ll')
glsl_parser = parser_env.CXXFile('glsl_parser.cpp', 'glsl_parser.yy')
# common generated sources
glsl_sources = [
glcpp_lexer,
glcpp_parser[0],
'glcpp/pp.c',
'ast_expr.cpp',
'ast_function.cpp',
'ast_to_hir.cpp',
'ast_type.cpp',
glsl_lexer,
glsl_parser[0],
'glsl_parser_extras.cpp',
'glsl_types.cpp',
'glsl_symbol_table.cpp',
'hir_field_selection.cpp',
'ir_basic_block.cpp',
'ir_clone.cpp',
'ir_constant_expression.cpp',
'ir.cpp',
'ir_expression_flattening.cpp',
'ir_function_can_inline.cpp',
'ir_function_detect_recursion.cpp',
'ir_function.cpp',
'ir_hierarchical_visitor.cpp',
'ir_hv_accept.cpp',
'ir_import_prototypes.cpp',
'ir_print_visitor.cpp',
'ir_reader.cpp',
'ir_rvalue_visitor.cpp',
'ir_set_program_inouts.cpp',
'ir_validate.cpp',
'ir_variable.cpp',
'ir_variable_refcount.cpp',
'linker.cpp',
'link_functions.cpp',
'loop_analysis.cpp',
'loop_controls.cpp',
'loop_unroll.cpp',
'lower_discard.cpp',
'lower_if_to_cond_assign.cpp',
'lower_instructions.cpp',
'lower_jumps.cpp',
'lower_mat_op_to_vec.cpp',
'lower_noise.cpp',
'lower_variable_index_to_cond_assign.cpp',
'lower_vec_index_to_cond_assign.cpp',
'lower_vec_index_to_swizzle.cpp',
'lower_vector.cpp',
'opt_algebraic.cpp',
'opt_constant_folding.cpp',
'opt_constant_propagation.cpp',
'opt_constant_variable.cpp',
'opt_copy_propagation.cpp',
'opt_copy_propagation_elements.cpp',
'opt_dead_code.cpp',
'opt_dead_code_local.cpp',
'opt_dead_functions.cpp',
'opt_discard_simplification.cpp',
'opt_function_inlining.cpp',
'opt_if_simplification.cpp',
'opt_noop_swizzle.cpp',
'opt_redundant_jumps.cpp',
'opt_structure_splitting.cpp',
'opt_swizzle_swizzle.cpp',
'opt_tree_grafting.cpp',
'ralloc.c',
's_expression.cpp',
'standalone_scaffolding.cpp',
'strtod.c',
]
# parse Makefile.sources
source_lists = env.ParseSourceList('Makefile.sources')
# add non-generated sources
for l in ('LIBGLCPP_FILES', 'LIBGLSL_FILES', 'LIBGLSL_CXX_FILES'):
glsl_sources += source_lists[l]
if env['msvc']:
env.Prepend(CPPPATH = ['#/src/getopt'])
env.PrependUnique(LIBS = [getopt])
@ -112,16 +61,19 @@ else:
env.Command('hash_table.c', '#src/mesa/program/hash_table.c', Copy('$TARGET', '$SOURCE'))
env.Command('symbol_table.c', '#src/mesa/program/symbol_table.c', Copy('$TARGET', '$SOURCE'))
main_obj = env.StaticObject('main.cpp')
compiler_objs = env.StaticObject(source_lists['GLSL_COMPILER_CXX_FILES'])
mesa_objs = env.StaticObject([
'hash_table.c',
'symbol_table.c',
])
compiler_objs += mesa_objs
builtin_compiler = env.Program(
target = 'builtin_compiler',
source = main_obj + glsl_sources + ['builtin_stubs.cpp'] + mesa_objs,
source = compiler_objs + glsl_sources + \
source_lists['BUILTIN_COMPILER_CXX_FILES'],
)
# SCons builtin dependency scanner doesn't detect that glsl_lexer.ll
@ -135,7 +87,7 @@ else:
command = python_cmd + ' $SCRIPT $SOURCE > $TARGET'
)
env.Depends(builtin_glsl_function, ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*'))
env.Depends(builtin_glsl_function, ['builtins/tools/generate_builtins.py', '#src/glsl/builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*'))
Export('builtin_glsl_function')
@ -172,7 +124,7 @@ env.Prepend(LIBS = [glsl])
glsl2 = env.Program(
target = 'glsl2',
source = main_obj + mesa_objs,
source = compiler_objs,
)
env.Alias('glsl2', glsl2)

View file

@ -6,22 +6,7 @@
constant index values. For others it is more complicated. Perhaps these
cases should be silently converted to uniforms?
- Implement support for ir_binop_dot in ir_algebraic.cpp. Perform
transformations such as "dot(v, vec3(0.0, 1.0, 0.0))" -> v.y.
- Track source locations throughout the IR. There are currently several
places where we cannot emit line numbers for errors (and currently emit 0:0)
because we've "lost" the line number information. This is particularly
noticeable at link time.
1.30 features:
- Implement AST-to-HIR conversion of switch-statements
- switch
- case
- Update break to correcly handle mixed nexting of switch-statements
and loops.
- Implement support for gl_ClipDistance. This is non-trivial because
gl_ClipDistance is exposed as a float[8], but all hardware actually
implements it as vec4[2].

View file

@ -206,7 +206,8 @@ public:
subexpressions[0] = NULL;
subexpressions[1] = NULL;
subexpressions[2] = NULL;
primary_expression.identifier = (char *) identifier;
primary_expression.identifier = identifier;
this->non_lvalue_description = NULL;
}
static const char *operator_string(enum ast_operators op);
@ -221,7 +222,7 @@ public:
ast_expression *subexpressions[3];
union {
char *identifier;
const char *identifier;
int int_constant;
float float_constant;
unsigned uint_constant;
@ -234,6 +235,18 @@ public:
* \c ast_function_call
*/
exec_list expressions;
/**
* For things that can't be l-values, this describes what it is.
*
* This text is used by the code that generates IR for assignments to
* detect and emit useful messages for assignments to some things that
* can't be l-values. For example, pre- or post-incerement expressions.
*
* \note
* This pointer may be \c NULL.
*/
const char *non_lvalue_description;
};
class ast_expression_bin : public ast_expression {
@ -304,11 +317,11 @@ public:
class ast_declaration : public ast_node {
public:
ast_declaration(char *identifier, int is_array, ast_expression *array_size,
ast_declaration(const char *identifier, int is_array, ast_expression *array_size,
ast_expression *initializer);
virtual void print(void) const;
char *identifier;
const char *identifier;
int is_array;
ast_expression *array_size;
@ -325,6 +338,25 @@ enum {
};
struct ast_type_qualifier {
/* Callers of this ralloc-based new need not call delete. It's
* easier to just ralloc_free 'ctx' (or any of its ancestors). */
static void* operator new(size_t size, void *ctx)
{
void *node;
node = rzalloc_size(ctx, size);
assert(node != NULL);
return node;
}
/* If the user *does* call delete, that's OK, we will just
* ralloc_free in that case. */
static void operator delete(void *table)
{
ralloc_free(table);
}
union {
struct {
unsigned invariant:1;
@ -350,6 +382,11 @@ struct ast_type_qualifier {
* qualifier is used.
*/
unsigned explicit_location:1;
/**
* Flag set if GL_ARB_explicit_attrib_location "index" layout
* qualifier is used.
*/
unsigned explicit_index:1;
/** \name Layout qualifiers for GL_AMD_conservative_depth */
/** \{ */
@ -358,6 +395,15 @@ struct ast_type_qualifier {
unsigned depth_less:1;
unsigned depth_unchanged:1;
/** \} */
/** \name Layout qualifiers for GL_ARB_uniform_buffer_object */
/** \{ */
unsigned std140:1;
unsigned shared:1;
unsigned packed:1;
unsigned column_major:1;
unsigned row_major:1;
/** \} */
}
/** \brief Set of flags, accessed by name. */
q;
@ -372,7 +418,14 @@ struct ast_type_qualifier {
* \note
* This field is only valid if \c explicit_location is set.
*/
unsigned location;
int location;
/**
* Index specified via GL_ARB_explicit_attrib_location layout
*
* \note
* This field is only valid if \c explicit_index is set.
*/
int index;
/**
* Return true if and only if an interpolation qualifier is present.
@ -390,86 +443,35 @@ struct ast_type_qualifier {
* returned string is undefined but not null.
*/
const char *interpolation_string() const;
bool merge_qualifier(YYLTYPE *loc,
_mesa_glsl_parse_state *state,
ast_type_qualifier q);
};
class ast_declarator_list;
class ast_struct_specifier : public ast_node {
public:
ast_struct_specifier(char *identifier, ast_node *declarator_list);
ast_struct_specifier(const char *identifier,
ast_declarator_list *declarator_list);
virtual void print(void) const;
virtual ir_rvalue *hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state);
char *name;
const char *name;
/* List of ast_declarator_list * */
exec_list declarations;
};
enum ast_types {
ast_void,
ast_float,
ast_int,
ast_uint,
ast_bool,
ast_vec2,
ast_vec3,
ast_vec4,
ast_bvec2,
ast_bvec3,
ast_bvec4,
ast_ivec2,
ast_ivec3,
ast_ivec4,
ast_uvec2,
ast_uvec3,
ast_uvec4,
ast_mat2,
ast_mat2x3,
ast_mat2x4,
ast_mat3x2,
ast_mat3,
ast_mat3x4,
ast_mat4x2,
ast_mat4x3,
ast_mat4,
ast_sampler1d,
ast_sampler2d,
ast_sampler2drect,
ast_sampler3d,
ast_samplercube,
ast_sampler1dshadow,
ast_sampler2dshadow,
ast_sampler2drectshadow,
ast_samplercubeshadow,
ast_sampler1darray,
ast_sampler2darray,
ast_sampler1darrayshadow,
ast_sampler2darrayshadow,
ast_isampler1d,
ast_isampler2d,
ast_isampler3d,
ast_isamplercube,
ast_isampler1darray,
ast_isampler2darray,
ast_usampler1d,
ast_usampler2d,
ast_usampler3d,
ast_usamplercube,
ast_usampler1darray,
ast_usampler2darray,
ast_struct,
ast_type_name
};
class ast_type_specifier : public ast_node {
public:
ast_type_specifier(int specifier);
/** Construct a type specifier from a type name */
ast_type_specifier(const char *name)
: type_specifier(ast_type_name), type_name(name), structure(NULL),
: type_name(name), structure(NULL),
is_array(false), array_size(NULL), precision(ast_precision_none),
is_precision_statement(false)
{
@ -478,7 +480,7 @@ public:
/** Construct a type specifier from a structure definition */
ast_type_specifier(ast_struct_specifier *s)
: type_specifier(ast_struct), type_name(s->name), structure(s),
: type_name(s->name), structure(s),
is_array(false), array_size(NULL), precision(ast_precision_none),
is_precision_statement(false)
{
@ -493,8 +495,6 @@ public:
ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
enum ast_types type_specifier;
const char *type_name;
ast_struct_specifier *structure;
@ -545,6 +545,12 @@ public:
* is used to note these cases when no type is specified.
*/
int invariant;
/**
* Flag indicating that these declarators are in a uniform block,
* allowing UBO type qualifiers.
*/
bool ubo_qualifiers_valid;
};
@ -563,7 +569,7 @@ public:
struct _mesa_glsl_parse_state *state);
ast_fully_specified_type *type;
char *identifier;
const char *identifier;
int is_array;
ast_expression *array_size;
@ -594,7 +600,7 @@ public:
struct _mesa_glsl_parse_state *state);
ast_fully_specified_type *return_type;
char *identifier;
const char *identifier;
exec_list parameters;
@ -637,13 +643,78 @@ public:
class ast_case_label : public ast_node {
public:
ast_case_label(ast_expression *test_value);
virtual void print(void) const;
virtual ir_rvalue *hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state);
/**
* An expression of NULL means 'default'.
* An test value of NULL means 'default'.
*/
ast_expression *expression;
ast_expression *test_value;
};
class ast_case_label_list : public ast_node {
public:
ast_case_label_list(void);
virtual void print(void) const;
virtual ir_rvalue *hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state);
/**
* A list of case labels.
*/
exec_list labels;
};
class ast_case_statement : public ast_node {
public:
ast_case_statement(ast_case_label_list *labels);
virtual void print(void) const;
virtual ir_rvalue *hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state);
ast_case_label_list *labels;
/**
* A list of statements.
*/
exec_list stmts;
};
class ast_case_statement_list : public ast_node {
public:
ast_case_statement_list(void);
virtual void print(void) const;
virtual ir_rvalue *hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state);
/**
* A list of cases.
*/
exec_list cases;
};
class ast_switch_body : public ast_node {
public:
ast_switch_body(ast_case_statement_list *stmts);
virtual void print(void) const;
virtual ir_rvalue *hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state);
ast_case_statement_list *stmts;
};
class ast_selection_statement : public ast_node {
public:
ast_selection_statement(ast_expression *condition,
@ -662,8 +733,18 @@ public:
class ast_switch_statement : public ast_node {
public:
ast_expression *expression;
exec_list statements;
ast_switch_statement(ast_expression *test_expression,
ast_node *body);
virtual void print(void) const;
virtual ir_rvalue *hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state);
ast_expression *test_expression;
ast_node *body;
protected:
void test_to_hir(exec_list *, struct _mesa_glsl_parse_state *);
};
class ast_iteration_statement : public ast_node {
@ -728,6 +809,25 @@ public:
ast_function *prototype;
ast_compound_statement *body;
};
class ast_uniform_block : public ast_node {
public:
ast_uniform_block(ast_type_qualifier layout,
const char *block_name,
ast_declarator_list *member_list)
: layout(layout), block_name(block_name)
{
declarations.push_degenerate_list_at_head(&member_list->link);
}
virtual ir_rvalue *hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state);
ast_type_qualifier layout;
const char *block_name;
/** List of ast_declarator_list * */
exec_list declarations;
};
/*@}*/
extern void

View file

@ -83,7 +83,7 @@ prototype_string(const glsl_type *return_type, const char *name,
const char *comma = "";
foreach_list(node, parameters) {
const ir_instruction *const param = (ir_instruction *) node;
const ir_variable *const param = (ir_variable *) node;
ralloc_asprintf_append(&str, "%s%s", comma, param->type->name);
comma = ", ";
@ -93,282 +93,393 @@ prototype_string(const glsl_type *return_type, const char *name,
return str;
}
static glsl_precision precision_from_call (const ir_function_signature* sig, glsl_precision max_prec, glsl_precision first_prec)
static glsl_precision precision_for_call (const ir_function_signature* sig, glsl_precision max_prec, glsl_precision first_prec)
{
if (sig->precision != glsl_precision_undefined)
return sig->precision;
// if return type is boolean, treat as lowp
if (sig->return_type->base_type == GLSL_TYPE_BOOL)
return glsl_precision_low;
// if it's a built-in texture function, precision comes from sampler (1st param) precision
if (sig->is_builtin)
{
if (strncmp (sig->function_name(), "texture", 7) == 0)
return first_prec;
if (strncmp (sig->function_name(), "shadow", 6) == 0)
return first_prec;
}
// other built-in: max precision of parameters
if (sig->is_builtin)
return max_prec;
// otherwise: undefined
return glsl_precision_undefined;
return glsl_precision_undefined;
}
static glsl_precision precision_for_call (const ir_function_signature* sig, exec_list *actual_parameters)
{
glsl_precision prec_params_max = glsl_precision_undefined;
glsl_precision prec_params_first = glsl_precision_undefined;
int params_counter = 0;
exec_list_iterator actual_iter = actual_parameters->iterator();
exec_list_iterator formal_iter = sig->parameters.iterator();
while (actual_iter.has_next())
{
ir_rvalue *actual = (ir_rvalue *) actual_iter.get();
ir_variable *formal = (ir_variable *) formal_iter.get();
assert(actual != NULL);
assert(formal != NULL);
glsl_precision param_prec = (glsl_precision)formal->precision;
if (param_prec == glsl_precision_undefined)
param_prec = actual->get_precision();
prec_params_max = higher_precision (prec_params_max, param_prec);
if (params_counter == 0)
prec_params_first = param_prec;
actual_iter.next();
formal_iter.next();
++params_counter;
}
return precision_for_call (sig, prec_params_max, prec_params_first);
}
/**
* Verify that 'out' and 'inout' actual parameters are lvalues. Also, verify
* that 'const_in' formal parameters (an extension in our IR) correspond to
* ir_constant actual parameters.
*/
static bool
verify_parameter_modes(_mesa_glsl_parse_state *state,
ir_function_signature *sig,
exec_list &actual_ir_parameters,
exec_list &actual_ast_parameters)
{
exec_node *actual_ir_node = actual_ir_parameters.head;
exec_node *actual_ast_node = actual_ast_parameters.head;
foreach_list(formal_node, &sig->parameters) {
/* The lists must be the same length. */
assert(!actual_ir_node->is_tail_sentinel());
assert(!actual_ast_node->is_tail_sentinel());
const ir_variable *const formal = (ir_variable *) formal_node;
const ir_rvalue *const actual = (ir_rvalue *) actual_ir_node;
const ast_expression *const actual_ast =
exec_node_data(ast_expression, actual_ast_node, link);
/* FIXME: 'loc' is incorrect (as of 2011-01-21). It is always
* FIXME: 0:0(0).
*/
YYLTYPE loc = actual_ast->get_location();
/* Verify that 'const_in' parameters are ir_constants. */
if (formal->mode == ir_var_const_in &&
actual->ir_type != ir_type_constant) {
_mesa_glsl_error(&loc, state,
"parameter `in %s' must be a constant expression",
formal->name);
return false;
}
/* Verify that 'out' and 'inout' actual parameters are lvalues. */
if (formal->mode == ir_var_out || formal->mode == ir_var_inout) {
const char *mode = NULL;
switch (formal->mode) {
case ir_var_out: mode = "out"; break;
case ir_var_inout: mode = "inout"; break;
default: assert(false); break;
}
/* This AST-based check catches errors like f(i++). The IR-based
* is_lvalue() is insufficient because the actual parameter at the
* IR-level is just a temporary value, which is an l-value.
*/
if (actual_ast->non_lvalue_description != NULL) {
_mesa_glsl_error(&loc, state,
"function parameter '%s %s' references a %s",
mode, formal->name,
actual_ast->non_lvalue_description);
return false;
}
ir_variable *var = actual->variable_referenced();
if (var)
var->assigned = true;
if (var && var->read_only) {
_mesa_glsl_error(&loc, state,
"function parameter '%s %s' references the "
"read-only variable '%s'",
mode, formal->name,
actual->variable_referenced()->name);
return false;
} else if (!actual->is_lvalue()) {
_mesa_glsl_error(&loc, state,
"function parameter '%s %s' is not an lvalue",
mode, formal->name);
return false;
}
}
actual_ir_node = actual_ir_node->next;
actual_ast_node = actual_ast_node->next;
}
return true;
}
/**
* If a function call is generated, \c call_ir will point to it on exit.
* Otherwise \c call_ir will be set to \c NULL.
*/
static ir_rvalue *
match_function_by_name(exec_list *instructions, const char *name,
YYLTYPE *loc, exec_list *actual_parameters,
generate_call(exec_list *instructions, ir_function_signature *sig,
YYLTYPE *loc, exec_list *actual_parameters,
ir_call **call_ir,
struct _mesa_glsl_parse_state *state)
{
void *ctx = state;
exec_list post_call_conversions;
*call_ir = NULL;
/* Perform implicit conversion of arguments. For out parameters, we need
* to place them in a temporary variable and do the conversion after the
* call takes place. Since we haven't emitted the call yet, we'll place
* the post-call conversions in a temporary exec_list, and emit them later.
*/
exec_list_iterator actual_iter = actual_parameters->iterator();
exec_list_iterator formal_iter = sig->parameters.iterator();
while (actual_iter.has_next()) {
ir_rvalue *actual = (ir_rvalue *) actual_iter.get();
ir_variable *formal = (ir_variable *) formal_iter.get();
assert(actual != NULL);
assert(formal != NULL);
if (formal->type->is_numeric() || formal->type->is_boolean()) {
switch (formal->mode) {
case ir_var_const_in:
case ir_var_in: {
ir_rvalue *converted
= convert_component(actual, formal->type);
actual->replace_with(converted);
break;
}
case ir_var_out:
if (actual->type != formal->type) {
/* To convert an out parameter, we need to create a
* temporary variable to hold the value before conversion,
* and then perform the conversion after the function call
* returns.
*
* This has the effect of transforming code like this:
*
* void f(out int x);
* float value;
* f(value);
*
* Into IR that's equivalent to this:
*
* void f(out int x);
* float value;
* int out_parameter_conversion;
* f(out_parameter_conversion);
* value = float(out_parameter_conversion);
*/
ir_variable *tmp =
new(ctx) ir_variable(formal->type,
"out_parameter_conversion",
ir_var_temporary, precision_for_call(sig,actual_parameters));
instructions->push_tail(tmp);
ir_dereference_variable *deref_tmp_1
= new(ctx) ir_dereference_variable(tmp);
ir_dereference_variable *deref_tmp_2
= new(ctx) ir_dereference_variable(tmp);
ir_rvalue *converted_tmp
= convert_component(deref_tmp_1, actual->type);
ir_assignment *assignment
= new(ctx) ir_assignment(actual, converted_tmp);
post_call_conversions.push_tail(assignment);
actual->replace_with(deref_tmp_2);
}
break;
case ir_var_inout:
/* Inout parameters should never require conversion, since that
* would require an implicit conversion to exist both to and
* from the formal parameter type, and there are no
* bidirectional implicit conversions.
*/
assert (actual->type == formal->type);
break;
default:
assert (!"Illegal formal parameter mode");
break;
}
}
actual_iter.next();
formal_iter.next();
}
/* If the function call is a constant expression, don't generate any
* instructions; just generate an ir_constant.
*
* Function calls were first allowed to be constant expressions in GLSL 1.20.
*/
if (state->language_version >= 120) {
ir_constant *value = sig->constant_expression_value(actual_parameters, NULL);
if (value != NULL) {
return value;
}
}
ir_dereference_variable *deref = NULL;
if (!sig->return_type->is_void()) {
/* Create a new temporary to hold the return value. */
ir_variable *var;
var = new(ctx) ir_variable(sig->return_type,
ralloc_asprintf(ctx, "%s_retval",
sig->function_name()),
ir_var_temporary, precision_for_call(sig,actual_parameters));
instructions->push_tail(var);
deref = new(ctx) ir_dereference_variable(var);
}
ir_call *call = new(ctx) ir_call(sig, deref, actual_parameters);
instructions->push_tail(call);
/* Also emit any necessary out-parameter conversions. */
instructions->append_list(&post_call_conversions);
return deref ? deref->clone(ctx, NULL) : NULL;
}
/**
* Given a function name and parameter list, find the matching signature.
*/
static ir_function_signature *
match_function_by_name(const char *name,
exec_list *actual_parameters,
struct _mesa_glsl_parse_state *state)
{
void *ctx = state;
ir_function *f = state->symbols->get_function(name);
ir_function_signature *sig;
ir_function_signature *local_sig = NULL;
ir_function_signature *sig = NULL;
sig = f ? f->matching_signature(actual_parameters) : NULL;
/* Is the function hidden by a record type constructor? */
if (state->symbols->get_type(name))
goto done; /* no match */
/* FINISHME: This doesn't handle the case where shader X contains a
* FINISHME: matching signature but shader X + N contains an _exact_
* FINISHME: matching signature.
*/
if (sig == NULL
&& (f == NULL || state->es_shader || !f->has_user_signature())
&& state->symbols->get_type(name) == NULL
&& (state->language_version == 110
|| state->symbols->get_variable(name) == NULL)) {
/* The current shader doesn't contain a matching function or signature.
* Before giving up, look for the prototype in the built-in functions.
*/
for (unsigned i = 0; i < state->num_builtins_to_link; i++) {
ir_function *builtin;
builtin = state->builtins_to_link[i]->symbols->get_function(name);
sig = builtin ? builtin->matching_signature(actual_parameters) : NULL;
if (sig != NULL) {
if (f == NULL) {
f = new(ctx) ir_function(name);
state->symbols->add_global_function(f);
emit_function(state, f);
}
/* Is the function hidden by a variable (impossible in 1.10)? */
if (state->language_version != 110 && state->symbols->get_variable(name))
goto done; /* no match */
f->add_signature(sig->clone_prototype(f, NULL));
break;
}
if (f != NULL) {
/* Look for a match in the local shader. If exact, we're done. */
bool is_exact = false;
sig = local_sig = f->matching_signature(actual_parameters, &is_exact);
if (is_exact)
goto done;
if (!state->es_shader && f->has_user_signature()) {
/* In desktop GL, the presence of a user-defined signature hides any
* built-in signatures, so we must ignore them. In contrast, in ES2
* user-defined signatures add new overloads, so we must proceed.
*/
goto done;
}
}
glsl_precision prec_params_max = glsl_precision_undefined;
glsl_precision prec_params_first = glsl_precision_undefined;
int params_counter = 0;
exec_list post_call_conversions;
/* Local shader has no exact candidates; check the built-ins. */
_mesa_glsl_initialize_functions(state);
for (unsigned i = 0; i < state->num_builtins_to_link; i++) {
ir_function *builtin =
state->builtins_to_link[i]->symbols->get_function(name);
if (builtin == NULL)
continue;
bool is_exact = false;
ir_function_signature *builtin_sig =
builtin->matching_signature(actual_parameters, &is_exact);
if (builtin_sig == NULL)
continue;
/* If the built-in signature is exact, we can stop. */
if (is_exact) {
sig = builtin_sig;
goto done;
}
if (sig == NULL) {
/* We found an inexact match, which is better than nothing. However,
* we should keep searching for an exact match.
*/
sig = builtin_sig;
}
}
done:
if (sig != NULL) {
/* Verify that 'out' and 'inout' actual parameters are lvalues. This
* isn't done in ir_function::matching_signature because that function
* cannot generate the necessary diagnostics.
*
* Also, validate that 'const_in' formal parameters (an extension of our
* IR) correspond to ir_constant actual parameters.
*
* Also, perform implicit conversion of arguments. Note: to implicitly
* convert out parameters, we need to place them in a temporary
* variable, and do the conversion after the call takes place. Since we
* haven't emitted the call yet, we'll place the post-call conversions
* in a temporary exec_list, and emit them later.
*/
exec_list_iterator actual_iter = actual_parameters->iterator();
exec_list_iterator formal_iter = sig->parameters.iterator();
while (actual_iter.has_next()) {
ir_rvalue *actual = (ir_rvalue *) actual_iter.get();
ir_variable *formal = (ir_variable *) formal_iter.get();
assert(actual != NULL);
assert(formal != NULL);
glsl_precision param_prec = (glsl_precision)formal->precision;
if (param_prec == glsl_precision_undefined)
param_prec = actual->get_precision();
prec_params_max = higher_precision (prec_params_max, param_prec);
if (params_counter == 0)
prec_params_first = param_prec;
if (formal->mode == ir_var_const_in && !actual->as_constant()) {
_mesa_glsl_error(loc, state,
"parameter `%s' must be a constant expression",
formal->name);
/* If the match is from a linked built-in shader, import the prototype. */
if (sig != local_sig) {
if (f == NULL) {
f = new(ctx) ir_function(name);
state->symbols->add_global_function(f);
emit_function(state, f);
}
if ((formal->mode == ir_var_out)
|| (formal->mode == ir_var_inout)) {
const char *mode = NULL;
switch (formal->mode) {
case ir_var_out: mode = "out"; break;
case ir_var_inout: mode = "inout"; break;
default: assert(false); break;
}
/* FIXME: 'loc' is incorrect (as of 2011-01-21). It is always
* FIXME: 0:0(0).
*/
if (actual->variable_referenced()
&& actual->variable_referenced()->read_only) {
_mesa_glsl_error(loc, state,
"function parameter '%s %s' references the "
"read-only variable '%s'",
mode, formal->name,
actual->variable_referenced()->name);
} else if (!actual->is_lvalue()) {
_mesa_glsl_error(loc, state,
"function parameter '%s %s' is not an lvalue",
mode, formal->name);
}
}
if (formal->type->is_numeric() || formal->type->is_boolean()) {
switch (formal->mode) {
case ir_var_in: {
ir_rvalue *converted
= convert_component(actual, formal->type);
actual->replace_with(converted);
break;
}
case ir_var_out:
if (actual->type != formal->type) {
/* To convert an out parameter, we need to create a
* temporary variable to hold the value before conversion,
* and then perform the conversion after the function call
* returns.
*
* This has the effect of transforming code like this:
*
* void f(out int x);
* float value;
* f(value);
*
* Into IR that's equivalent to this:
*
* void f(out int x);
* float value;
* int out_parameter_conversion;
* f(out_parameter_conversion);
* value = float(out_parameter_conversion);
*/
ir_variable *tmp =
new(ctx) ir_variable(formal->type,
"out_parameter_conversion",
ir_var_temporary, (glsl_precision)formal->precision);
instructions->push_tail(tmp);
ir_dereference_variable *deref_tmp_1
= new(ctx) ir_dereference_variable(tmp);
ir_dereference_variable *deref_tmp_2
= new(ctx) ir_dereference_variable(tmp);
ir_rvalue *converted_tmp
= convert_component(deref_tmp_1, actual->type);
ir_assignment *assignment
= new(ctx) ir_assignment(actual, converted_tmp);
post_call_conversions.push_tail(assignment);
actual->replace_with(deref_tmp_2);
}
break;
case ir_var_inout:
/* Inout parameters should never require conversion, since that
* would require an implicit conversion to exist both to and
* from the formal parameter type, and there are no
* bidirectional implicit conversions.
*/
assert (actual->type == formal->type);
break;
default:
assert (!"Illegal formal parameter mode");
break;
}
}
actual_iter.next();
formal_iter.next();
++params_counter;
f->add_signature(sig->clone_prototype(f, NULL));
}
glsl_precision call_prec = precision_from_call(sig, prec_params_max, prec_params_first);
/* Always insert the call in the instruction stream, and return a deref
* of its return val if it returns a value, since we don't know if
* the rvalue is going to be assigned to anything or not.
*
* Also insert any out parameter conversions after the call.
*/
ir_call *call = new(ctx) ir_call(sig, actual_parameters);
ir_dereference_variable *deref;
if (!sig->return_type->is_void()) {
/* If the function call is a constant expression, don't
* generate the instructions to call it; just generate an
* ir_constant representing the constant value.
*
* Function calls can only be constant expressions starting
* in GLSL 1.20.
*/
if (state->language_version >= 120) {
ir_constant *const_val = call->constant_expression_value();
if (const_val) {
return const_val;
}
}
ir_variable *var;
var = new(ctx) ir_variable(sig->return_type,
ralloc_asprintf(ctx, "%s_retval",
sig->function_name()),
ir_var_temporary, call_prec);
instructions->push_tail(var);
call->set_precision (call_prec);
deref = new(ctx) ir_dereference_variable(var);
ir_assignment *assign = new(ctx) ir_assignment(deref, call, NULL);
instructions->push_tail(assign);
deref = new(ctx) ir_dereference_variable(var);
} else {
instructions->push_tail(call);
deref = NULL;
}
instructions->append_list(&post_call_conversions);
return deref;
} else {
char *str = prototype_string(NULL, name, actual_parameters);
_mesa_glsl_error(loc, state, "no matching function for call to `%s'",
str);
ralloc_free(str);
const char *prefix = "candidates are: ";
for (int i = -1; i < (int) state->num_builtins_to_link; i++) {
glsl_symbol_table *syms = i >= 0 ? state->builtins_to_link[i]->symbols
: state->symbols;
f = syms->get_function(name);
if (f == NULL)
continue;
foreach_list (node, &f->signatures) {
ir_function_signature *sig = (ir_function_signature *) node;
str = prototype_string(sig->return_type, f->name, &sig->parameters);
_mesa_glsl_error(loc, state, "%s%s", prefix, str);
ralloc_free(str);
prefix = " ";
}
}
return ir_call::get_error_instruction(ctx);
}
return sig;
}
/**
* Raise a "no matching function" error, listing all possible overloads the
* compiler considered so developers can figure out what went wrong.
*/
static void
no_matching_function_error(const char *name,
YYLTYPE *loc,
exec_list *actual_parameters,
_mesa_glsl_parse_state *state)
{
char *str = prototype_string(NULL, name, actual_parameters);
_mesa_glsl_error(loc, state, "no matching function for call to `%s'", str);
ralloc_free(str);
const char *prefix = "candidates are: ";
for (int i = -1; i < (int) state->num_builtins_to_link; i++) {
glsl_symbol_table *syms = i >= 0 ? state->builtins_to_link[i]->symbols
: state->symbols;
ir_function *f = syms->get_function(name);
if (f == NULL)
continue;
foreach_list (node, &f->signatures) {
ir_function_signature *sig = (ir_function_signature *) node;
str = prototype_string(sig->return_type, f->name, &sig->parameters);
_mesa_glsl_error(loc, state, "%s%s", prefix, str);
ralloc_free(str);
prefix = " ";
}
}
}
/**
* Perform automatic type conversion of constructor parameters
@ -400,8 +511,7 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
result = new(ctx) ir_expression(ir_unop_i2u, src);
break;
case GLSL_TYPE_FLOAT:
result = new(ctx) ir_expression(ir_unop_i2u,
new(ctx) ir_expression(ir_unop_f2i, src));
result = new(ctx) ir_expression(ir_unop_f2u, src);
break;
case GLSL_TYPE_BOOL:
result = new(ctx) ir_expression(ir_unop_i2u,
@ -541,7 +651,7 @@ process_array_constructor(exec_list *instructions,
"parameter%s",
(constructor_type->length != 0) ? "at least" : "exactly",
min_param, (min_param <= 1) ? "" : "s");
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
if (constructor_type->length == 0) {
@ -601,7 +711,7 @@ process_array_constructor(exec_list *instructions,
return new(ctx) ir_constant(constructor_type, &actual_parameters);
ir_variable *var = new(ctx) ir_variable(constructor_type, "array_ctor",
ir_var_temporary, glsl_precision_undefined); ///@TODO
ir_var_temporary, glsl_precision_undefined);
instructions->push_tail(var);
int i = 0;
@ -687,7 +797,7 @@ emit_inline_vector_constructor(const glsl_type *type, unsigned ast_precision,
ir_rvalue *first_param = (ir_rvalue *)parameters->head;
ir_rvalue *rhs = new(ctx) ir_swizzle(first_param, 0, 0, 0, 0,
lhs_components);
var->precision = higher_precision ((glsl_precision)var->precision, rhs->get_precision());
var->precision = higher_precision ((glsl_precision)var->precision, rhs->get_precision());
ir_dereference_variable *lhs = new(ctx) ir_dereference_variable(var);
const unsigned mask = (1U << lhs_components) - 1;
@ -854,7 +964,7 @@ assign_to_matrix_column(ir_variable *var, unsigned column, unsigned row_base,
* body.
*/
ir_rvalue *
emit_inline_matrix_constructor(const glsl_type *type, unsigned ast_precision,
emit_inline_matrix_constructor(const glsl_type *type, int ast_precision,
exec_list *instructions,
exec_list *parameters,
void *ctx)
@ -1180,7 +1290,7 @@ ast_function_expression::hir(exec_list *instructions,
_mesa_glsl_error(& loc, state, "unknown type `%s' (structure name "
"may be shadowed by a variable with the same name)",
type->type_name);
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
@ -1189,14 +1299,14 @@ ast_function_expression::hir(exec_list *instructions,
if (constructor_type->is_sampler()) {
_mesa_glsl_error(& loc, state, "cannot construct sampler type `%s'",
constructor_type->name);
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
if (constructor_type->is_array()) {
if (state->language_version <= 110) {
_mesa_glsl_error(& loc, state,
"array constructors forbidden in GLSL 1.10");
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
return process_array_constructor(instructions, constructor_type,
@ -1227,7 +1337,7 @@ ast_function_expression::hir(exec_list *instructions,
"insufficient parameters to constructor "
"for `%s'",
constructor_type->name);
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
if (apply_implicit_conversion(constructor_type->fields.structure[i].type,
@ -1241,7 +1351,7 @@ ast_function_expression::hir(exec_list *instructions,
constructor_type->fields.structure[i].name,
ir->type->name,
constructor_type->fields.structure[i].type->name);
return ir_call::get_error_instruction(ctx);;
return ir_rvalue::error_value(ctx);;
}
node = node->next;
@ -1250,7 +1360,7 @@ ast_function_expression::hir(exec_list *instructions,
if (!node->is_tail_sentinel()) {
_mesa_glsl_error(&loc, state, "too many parameters in constructor "
"for `%s'", constructor_type->name);
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
ir_rvalue *const constant =
@ -1264,7 +1374,7 @@ ast_function_expression::hir(exec_list *instructions,
}
if (!constructor_type->is_numeric() && !constructor_type->is_boolean())
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
/* Total number of components of the type being constructed. */
const unsigned type_components = constructor_type->components();
@ -1291,14 +1401,14 @@ ast_function_expression::hir(exec_list *instructions,
_mesa_glsl_error(& loc, state, "too many parameters to `%s' "
"constructor",
constructor_type->name);
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
if (!result->type->is_numeric() && !result->type->is_boolean()) {
_mesa_glsl_error(& loc, state, "cannot construct `%s' from a "
"non-numeric data type",
constructor_type->name);
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
/* Count the number of matrix and nonmatrix parameters. This
@ -1323,7 +1433,7 @@ ast_function_expression::hir(exec_list *instructions,
_mesa_glsl_error(& loc, state, "cannot construct `%s' from a "
"matrix in GLSL 1.10",
constructor_type->name);
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
/* From page 50 (page 56 of the PDF) of the GLSL 1.50 spec:
@ -1337,7 +1447,7 @@ ast_function_expression::hir(exec_list *instructions,
_mesa_glsl_error(& loc, state, "for matrix `%s' constructor, "
"matrix must be only parameter",
constructor_type->name);
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
/* From page 28 (page 34 of the PDF) of the GLSL 1.10 spec:
@ -1351,7 +1461,7 @@ ast_function_expression::hir(exec_list *instructions,
_mesa_glsl_error(& loc, state, "too few components to construct "
"`%s'",
constructor_type->name);
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}
/* Later, we cast each parameter to the same base type as the
@ -1374,7 +1484,7 @@ ast_function_expression::hir(exec_list *instructions,
var->constant_value = matrix->constant_expression_value();
/* Replace the matrix with dereferences of its columns. */
for (unsigned int i = 0; i < matrix->type->matrix_columns; i++) {
for (int i = 0; i < matrix->type->matrix_columns; i++) {
matrix->insert_before(new (ctx) ir_dereference_array(var,
new(ctx) ir_constant(i)));
}
@ -1432,16 +1542,31 @@ ast_function_expression::hir(exec_list *instructions,
}
} else {
const ast_expression *id = subexpressions[0];
const char *func_name = id->primary_expression.identifier;
YYLTYPE loc = id->get_location();
exec_list actual_parameters;
process_parameters(instructions, &actual_parameters, &this->expressions,
state);
return match_function_by_name(instructions,
id->primary_expression.identifier, & loc,
&actual_parameters, state);
ir_function_signature *sig =
match_function_by_name(func_name, &actual_parameters, state);
ir_call *call = NULL;
ir_rvalue *value = NULL;
if (sig == NULL) {
no_matching_function_error(func_name, &loc, &actual_parameters, state);
value = ir_rvalue::error_value(ctx);
} else if (!verify_parameter_modes(state, sig, actual_parameters, this->expressions)) {
/* an error has already been emitted */
value = ir_rvalue::error_value(ctx);
} else {
value = generate_call(instructions, sig, &loc, &actual_parameters,
&call, state);
}
return value;
}
return ir_call::get_error_instruction(ctx);
return ir_rvalue::error_value(ctx);
}

File diff suppressed because it is too large Load diff

View file

@ -29,7 +29,7 @@ extern "C" {
void
ast_type_specifier::print(void) const
{
if (type_specifier == ast_struct) {
if (structure) {
structure->print();
} else {
printf("%s ", type_name);
@ -46,71 +46,6 @@ ast_type_specifier::print(void) const
}
}
ast_type_specifier::ast_type_specifier(int specifier)
: type_specifier(ast_types(specifier)), type_name(NULL), structure(NULL),
is_array(false), array_size(NULL), precision(ast_precision_none),
is_precision_statement(false)
{
static const char *const names[] = {
"void",
"float",
"int",
"uint",
"bool",
"vec2",
"vec3",
"vec4",
"bvec2",
"bvec3",
"bvec4",
"ivec2",
"ivec3",
"ivec4",
"uvec2",
"uvec3",
"uvec4",
"mat2",
"mat2x3",
"mat2x4",
"mat3x2",
"mat3",
"mat3x4",
"mat4x2",
"mat4x3",
"mat4",
"sampler1D",
"sampler2D",
"sampler2DRect",
"sampler3D",
"samplerCube",
"sampler1DShadow",
"sampler2DShadow",
"sampler2DRectShadow",
"samplerCubeShadow",
"sampler1DArray",
"sampler2DArray",
"sampler1DArrayShadow",
"sampler2DArrayShadow",
"isampler1D",
"isampler2D",
"isampler3D",
"isamplerCube",
"isampler1DArray",
"isampler2DArray",
"usampler1D",
"usampler2D",
"usampler3D",
"usamplerCube",
"usampler1DArray",
"usampler2DArray",
NULL, /* ast_struct */
NULL /* ast_type_name */
};
type_name = names[specifier];
}
bool
ast_fully_specified_type::has_qualifiers() const
{
@ -136,3 +71,48 @@ ast_type_qualifier::interpolation_string() const
else
return NULL;
}
bool
ast_type_qualifier::merge_qualifier(YYLTYPE *loc,
_mesa_glsl_parse_state *state,
ast_type_qualifier q)
{
ast_type_qualifier ubo_mat_mask;
ubo_mat_mask.flags.i = 0;
ubo_mat_mask.flags.q.row_major = 1;
ubo_mat_mask.flags.q.column_major = 1;
ast_type_qualifier ubo_layout_mask;
ubo_layout_mask.flags.i = 0;
ubo_layout_mask.flags.q.std140 = 1;
ubo_layout_mask.flags.q.packed = 1;
ubo_layout_mask.flags.q.shared = 1;
/* Uniform block layout qualifiers get to overwrite each
* other (rightmost having priority), while all other
* qualifiers currently don't allow duplicates.
*/
if ((this->flags.i & q.flags.i & ~(ubo_mat_mask.flags.i |
ubo_layout_mask.flags.i)) != 0) {
_mesa_glsl_error(loc, state,
"duplicate layout qualifiers used\n");
return false;
}
if ((q.flags.i & ubo_mat_mask.flags.i) != 0)
this->flags.i &= ~ubo_mat_mask.flags.i;
if ((q.flags.i & ubo_layout_mask.flags.i) != 0)
this->flags.i &= ~ubo_layout_mask.flags.i;
this->flags.i |= q.flags.i;
if (q.flags.q.explicit_location)
this->location = q.location;
if (q.flags.q.explicit_index)
this->index = q.index;
return true;
}

View file

@ -1,12 +0,0 @@
#! /bin/sh
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
ORIGDIR=`pwd`
cd $srcdir
autoreconf -v --install || exit 1
cd $ORIGDIR || exit $?
$srcdir/configure --enable-maintainer-mode "$@"

File diff suppressed because one or more lines are too long

View file

@ -35,4 +35,5 @@ _mesa_glsl_release_functions(void)
void
_mesa_glsl_initialize_functions(_mesa_glsl_parse_state *state)
{
(void) state;
}

View file

@ -63,7 +63,12 @@ const glsl_type glsl_type::builtin_core_types[] = {
};
const glsl_type *const glsl_type::bool_type = & builtin_core_types[0];
const glsl_type *const glsl_type::bvec2_type = & builtin_core_types[1];
const glsl_type *const glsl_type::bvec3_type = & builtin_core_types[2];
const glsl_type *const glsl_type::bvec4_type = & builtin_core_types[3];
const glsl_type *const glsl_type::int_type = & builtin_core_types[4];
const glsl_type *const glsl_type::ivec2_type = & builtin_core_types[5];
const glsl_type *const glsl_type::ivec3_type = & builtin_core_types[6];
const glsl_type *const glsl_type::ivec4_type = & builtin_core_types[7];
const glsl_type *const glsl_type::float_type = & builtin_core_types[8];
const glsl_type *const glsl_type::vec2_type = & builtin_core_types[9];
@ -259,6 +264,18 @@ const glsl_type *const glsl_type::uvec3_type = & builtin_130_types[2];
const glsl_type *const glsl_type::uvec4_type = & builtin_130_types[3];
/*@}*/
/** \name Types added in GLSL 1.40
*/
/*@{*/
const glsl_type glsl_type::builtin_140_types[] = {
glsl_type(GL_INT_SAMPLER_2D_RECT,
GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_INT, "isampler2DRect"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_RECT,
GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_UINT, "usampler2DRect"),
};
/*@}*/
/** \name Sampler types added by GL_ARB_texture_rectangle
*/
/*@{*/
@ -300,3 +317,13 @@ const glsl_type glsl_type::builtin_EXT_texture_buffer_object_types[] = {
GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_UINT, "usamplerBuffer"),
};
/*@}*/
/** \name Sampler types added by GL_OES_EGL_image_external
*/
/*@{*/
const glsl_type glsl_type::builtin_OES_EGL_image_external_types[] = {
glsl_type(GL_SAMPLER_EXTERNAL_OES,
GLSL_SAMPLER_DIM_EXTERNAL, 0, 0, GLSL_TYPE_FLOAT, "samplerExternalOES"),
};
/*@}*/

View file

@ -24,12 +24,25 @@
#include "ir.h"
#include "glsl_parser_extras.h"
#include "glsl_symbol_table.h"
#include "builtin_variables.h"
#include "main/uniforms.h"
#include "main/core.h"
#include "program/prog_parameter.h"
#include "program/prog_statevars.h"
#include "program/prog_instruction.h"
struct gl_builtin_uniform_element {
const char *field;
int tokens[STATE_LENGTH];
int swizzle;
};
struct gl_builtin_uniform_desc {
const char *name;
struct gl_builtin_uniform_element *elements;
unsigned int num_elements;
};
static void generate_ARB_draw_buffers_variables(exec_list *,
struct _mesa_glsl_parse_state *,
bool, _mesa_glsl_parser_targets);
@ -39,6 +52,92 @@ generate_ARB_draw_instanced_variables(exec_list *,
struct _mesa_glsl_parse_state *,
bool, _mesa_glsl_parser_targets);
struct builtin_variable {
enum ir_variable_mode mode;
int slot;
const char *type;
const char *name;
glsl_precision prec;
};
static const builtin_variable builtin_core_vs_variables[] = {
{ ir_var_out, VERT_RESULT_HPOS, "vec4", "gl_Position", glsl_precision_high },
{ ir_var_out, VERT_RESULT_PSIZ, "float", "gl_PointSize", glsl_precision_medium },
};
static const builtin_variable builtin_core_fs_variables[] = {
{ ir_var_in, FRAG_ATTRIB_WPOS, "vec4", "gl_FragCoord", glsl_precision_medium },
{ ir_var_in, FRAG_ATTRIB_FACE, "bool", "gl_FrontFacing", glsl_precision_low },
{ ir_var_out, FRAG_RESULT_COLOR, "vec4", "gl_FragColor", glsl_precision_medium },
};
static const builtin_variable builtin_100ES_fs_variables[] = {
{ ir_var_in, FRAG_ATTRIB_PNTC, "vec2", "gl_PointCoord", glsl_precision_medium },
};
static const builtin_variable builtin_110_fs_variables[] = {
{ ir_var_out, FRAG_RESULT_DEPTH, "float", "gl_FragDepth", glsl_precision_medium },
};
static const builtin_variable builtin_110_deprecated_fs_variables[] = {
{ ir_var_in, FRAG_ATTRIB_COL0, "vec4", "gl_Color", glsl_precision_medium },
{ ir_var_in, FRAG_ATTRIB_COL1, "vec4", "gl_SecondaryColor", glsl_precision_medium },
{ ir_var_in, FRAG_ATTRIB_FOGC, "float", "gl_FogFragCoord", glsl_precision_medium },
};
static const builtin_variable builtin_110_deprecated_vs_variables[] = {
{ ir_var_in, VERT_ATTRIB_POS, "vec4", "gl_Vertex", glsl_precision_high },
{ ir_var_in, VERT_ATTRIB_NORMAL, "vec3", "gl_Normal", glsl_precision_medium },
{ ir_var_in, VERT_ATTRIB_COLOR0, "vec4", "gl_Color", glsl_precision_medium },
{ ir_var_in, VERT_ATTRIB_COLOR1, "vec4", "gl_SecondaryColor", glsl_precision_medium },
{ ir_var_in, VERT_ATTRIB_TEX0, "vec4", "gl_MultiTexCoord0", glsl_precision_high },
{ ir_var_in, VERT_ATTRIB_TEX1, "vec4", "gl_MultiTexCoord1", glsl_precision_high },
{ ir_var_in, VERT_ATTRIB_TEX2, "vec4", "gl_MultiTexCoord2", glsl_precision_high },
{ ir_var_in, VERT_ATTRIB_TEX3, "vec4", "gl_MultiTexCoord3", glsl_precision_high },
{ ir_var_in, VERT_ATTRIB_TEX4, "vec4", "gl_MultiTexCoord4", glsl_precision_high },
{ ir_var_in, VERT_ATTRIB_TEX5, "vec4", "gl_MultiTexCoord5", glsl_precision_high },
{ ir_var_in, VERT_ATTRIB_TEX6, "vec4", "gl_MultiTexCoord6", glsl_precision_high },
{ ir_var_in, VERT_ATTRIB_TEX7, "vec4", "gl_MultiTexCoord7", glsl_precision_high },
{ ir_var_in, VERT_ATTRIB_FOG, "float", "gl_FogCoord", glsl_precision_high },
{ ir_var_out, VERT_RESULT_CLIP_VERTEX, "vec4", "gl_ClipVertex", glsl_precision_high },
{ ir_var_out, VERT_RESULT_COL0, "vec4", "gl_FrontColor", glsl_precision_medium },
{ ir_var_out, VERT_RESULT_BFC0, "vec4", "gl_BackColor", glsl_precision_medium },
{ ir_var_out, VERT_RESULT_COL1, "vec4", "gl_FrontSecondaryColor", glsl_precision_medium },
{ ir_var_out, VERT_RESULT_BFC1, "vec4", "gl_BackSecondaryColor", glsl_precision_medium },
{ ir_var_out, VERT_RESULT_FOGC, "float", "gl_FogFragCoord", glsl_precision_medium },
};
static const builtin_variable builtin_120_fs_variables[] = {
{ ir_var_in, FRAG_ATTRIB_PNTC, "vec2", "gl_PointCoord", glsl_precision_medium },
};
static const builtin_variable builtin_130_vs_variables[] = {
{ ir_var_system_value, SYSTEM_VALUE_VERTEX_ID, "int", "gl_VertexID", glsl_precision_high },
};
static const builtin_variable builtin_110_deprecated_uniforms[] = {
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrix", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrix", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrix", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat3", "gl_NormalMatrix", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixInverse", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixInverse", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixInverse", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixTranspose", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixTranspose", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixTranspose", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixInverseTranspose", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixInverseTranspose", glsl_precision_undefined },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixInverseTranspose", glsl_precision_undefined },
{ ir_var_uniform, -1, "float", "gl_NormalScale", glsl_precision_undefined },
{ ir_var_uniform, -1, "gl_LightModelParameters", "gl_LightModel", glsl_precision_undefined},
/* Mesa-internal ATI_envmap_bumpmap state. */
{ ir_var_uniform, -1, "vec2", "gl_BumpRotMatrix0MESA", glsl_precision_undefined},
{ ir_var_uniform, -1, "vec2", "gl_BumpRotMatrix1MESA", glsl_precision_undefined},
{ ir_var_uniform, -1, "vec4", "gl_FogParamsOptimizedMESA", glsl_precision_undefined},
};
static struct gl_builtin_uniform_element gl_DepthRange_elements[] = {
{"near", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_XXXX},
{"far", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_YYYY},
@ -166,18 +265,26 @@ static struct gl_builtin_uniform_element gl_NormalScale_elements[] = {
{NULL, {STATE_NORMAL_SCALE}, SWIZZLE_XXXX},
};
static struct gl_builtin_uniform_element gl_MESABumpRotMatrix0_elements[] = {
static struct gl_builtin_uniform_element gl_BumpRotMatrix0MESA_elements[] = {
{NULL, {STATE_INTERNAL, STATE_ROT_MATRIX_0}, SWIZZLE_XYZW},
};
static struct gl_builtin_uniform_element gl_MESABumpRotMatrix1_elements[] = {
static struct gl_builtin_uniform_element gl_BumpRotMatrix1MESA_elements[] = {
{NULL, {STATE_INTERNAL, STATE_ROT_MATRIX_1}, SWIZZLE_XYZW},
};
static struct gl_builtin_uniform_element gl_MESAFogParamsOptimized_elements[] = {
static struct gl_builtin_uniform_element gl_FogParamsOptimizedMESA_elements[] = {
{NULL, {STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED}, SWIZZLE_XYZW},
};
static struct gl_builtin_uniform_element gl_CurrentAttribVertMESA_elements[] = {
{NULL, {STATE_INTERNAL, STATE_CURRENT_ATTRIB, 0}, SWIZZLE_XYZW},
};
static struct gl_builtin_uniform_element gl_CurrentAttribFragMESA_elements[] = {
{NULL, {STATE_INTERNAL, STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED, 0}, SWIZZLE_XYZW},
};
#define MATRIX(name, statevar, modifier) \
static struct gl_builtin_uniform_element name ## _elements[] = { \
{ NULL, { statevar, 0, 0, 0, modifier}, SWIZZLE_XYZW }, \
@ -224,18 +331,18 @@ MATRIX(gl_TextureMatrixInverseTranspose,
static struct gl_builtin_uniform_element gl_NormalMatrix_elements[] = {
{ NULL, { STATE_MODELVIEW_MATRIX, 0, 0, 0, STATE_MATRIX_INVERSE},
SWIZZLE_XYZW },
MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) },
{ NULL, { STATE_MODELVIEW_MATRIX, 0, 1, 1, STATE_MATRIX_INVERSE},
SWIZZLE_XYZW },
MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) },
{ NULL, { STATE_MODELVIEW_MATRIX, 0, 2, 2, STATE_MATRIX_INVERSE},
SWIZZLE_XYZW },
MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) },
};
#undef MATRIX
#define STATEVAR(name) {#name, name ## _elements, Elements(name ## _elements)}
const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = {
static const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = {
STATEVAR(gl_DepthRange),
STATEVAR(gl_ClipPlane),
STATEVAR(gl_Point),
@ -281,9 +388,11 @@ const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = {
STATEVAR(gl_NormalMatrix),
STATEVAR(gl_NormalScale),
STATEVAR(gl_MESABumpRotMatrix0),
STATEVAR(gl_MESABumpRotMatrix1),
STATEVAR(gl_MESAFogParamsOptimized),
STATEVAR(gl_BumpRotMatrix0MESA),
STATEVAR(gl_BumpRotMatrix1MESA),
STATEVAR(gl_FogParamsOptimizedMESA),
STATEVAR(gl_CurrentAttribVertMESA),
STATEVAR(gl_CurrentAttribFragMESA),
{NULL, NULL, 0}
};
@ -291,9 +400,9 @@ const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = {
static ir_variable *
add_variable(exec_list *instructions, glsl_symbol_table *symtab,
const char *name, const glsl_type *type,
enum ir_variable_mode mode, int slot)
enum ir_variable_mode mode, int slot, glsl_precision prec = glsl_precision_undefined)
{
ir_variable *var = new(symtab) ir_variable(type, name, mode, glsl_precision_undefined);
ir_variable *var = new(symtab) ir_variable(type, name, mode, prec);
switch (var->mode) {
case ir_var_auto:
@ -313,6 +422,7 @@ add_variable(exec_list *instructions, glsl_symbol_table *symtab,
var->location = slot;
var->explicit_location = (slot >= 0);
var->explicit_index = 0;
/* Once the variable is created an initialized, add it to the symbol table
* and add the declaration to the IR stream.
@ -325,10 +435,10 @@ add_variable(exec_list *instructions, glsl_symbol_table *symtab,
static ir_variable *
add_uniform(exec_list *instructions, glsl_symbol_table *symtab,
const char *name, const glsl_type *type)
const char *name, const glsl_type *type, glsl_precision prec = glsl_precision_undefined)
{
ir_variable *const uni =
add_variable(instructions, symtab, name, type, ir_var_uniform, -1);
add_variable(instructions, symtab, name, type, ir_var_uniform, -1, prec);
unsigned i;
for (i = 0; _mesa_builtin_uniform_desc[i].name != NULL; i++) {
@ -355,7 +465,12 @@ add_uniform(exec_list *instructions, glsl_symbol_table *symtab,
memcpy(slots->tokens, element->tokens, sizeof(element->tokens));
if (type->is_array()) {
slots->tokens[1] = a;
if (strcmp(name, "gl_CurrentAttribVertMESA") == 0 ||
strcmp(name, "gl_CurrentAttribFragMESA") == 0) {
slots->tokens[2] = a;
} else {
slots->tokens[1] = a;
}
}
slots->swizzle = element->swizzle;
@ -368,7 +483,7 @@ add_uniform(exec_list *instructions, glsl_symbol_table *symtab,
static void
add_builtin_variable(exec_list *instructions, glsl_symbol_table *symtab,
const builtin_variable *proto)
const builtin_variable *proto, bool use_precision)
{
/* Create a new variable declaration from the description supplied by
* the caller.
@ -378,21 +493,24 @@ add_builtin_variable(exec_list *instructions, glsl_symbol_table *symtab,
assert(type != NULL);
if (proto->mode == ir_var_uniform) {
add_uniform(instructions, symtab, proto->name, type);
add_uniform(instructions, symtab, proto->name, type, use_precision ? proto->prec : glsl_precision_undefined);
} else {
add_variable(instructions, symtab, proto->name, type, proto->mode,
proto->slot);
proto->slot, use_precision ? proto->prec : glsl_precision_undefined);
}
}
static void
static ir_variable *
add_builtin_constant(exec_list *instructions, glsl_symbol_table *symtab,
const char *name, int value)
{
ir_variable *const var = add_variable(instructions, symtab,
name, glsl_type::int_type,
ir_var_auto, -1);
ir_var_auto, -1, glsl_precision_undefined);
var->constant_value = new(var) ir_constant(value);
var->constant_initializer = new(var) ir_constant(value);
var->has_initializer = true;
return var;
}
/* Several constants in GLSL ES have different names than normal desktop GLSL.
@ -420,30 +538,35 @@ generate_100ES_uniforms(exec_list *instructions,
state->Const.MaxFragmentUniformComponents);
add_uniform(instructions, symtab, "gl_DepthRange",
state->symbols->get_type("gl_DepthRangeParameters"));
state->symbols->get_type("gl_DepthRangeParameters"), glsl_precision_undefined);
}
static void
generate_110_uniforms(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
struct _mesa_glsl_parse_state *state,
bool add_deprecated)
{
glsl_symbol_table *const symtab = state->symbols;
for (unsigned i = 0
; i < Elements(builtin_110_deprecated_uniforms)
; i++) {
add_builtin_variable(instructions, symtab,
& builtin_110_deprecated_uniforms[i]);
if (add_deprecated) {
for (unsigned i = 0
; i < Elements(builtin_110_deprecated_uniforms)
; i++) {
add_builtin_variable(instructions, symtab,
& builtin_110_deprecated_uniforms[i], state->es_shader);
}
}
add_builtin_constant(instructions, symtab, "gl_MaxLights",
state->Const.MaxLights);
add_builtin_constant(instructions, symtab, "gl_MaxClipPlanes",
state->Const.MaxClipPlanes);
add_builtin_constant(instructions, symtab, "gl_MaxTextureUnits",
state->Const.MaxTextureUnits);
add_builtin_constant(instructions, symtab, "gl_MaxTextureCoords",
state->Const.MaxTextureCoords);
if (add_deprecated) {
add_builtin_constant(instructions, symtab, "gl_MaxLights",
state->Const.MaxLights);
add_builtin_constant(instructions, symtab, "gl_MaxClipPlanes",
state->Const.MaxClipPlanes);
add_builtin_constant(instructions, symtab, "gl_MaxTextureUnits",
state->Const.MaxTextureUnits);
add_builtin_constant(instructions, symtab, "gl_MaxTextureCoords",
state->Const.MaxTextureCoords);
}
add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs",
state->Const.MaxVertexAttribs);
add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformComponents",
@ -459,65 +582,77 @@ generate_110_uniforms(exec_list *instructions,
add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformComponents",
state->Const.MaxFragmentUniformComponents);
const glsl_type *const mat4_array_type =
glsl_type::get_array_instance(glsl_type::mat4_type,
state->Const.MaxTextureCoords);
if (add_deprecated) {
const glsl_type *const mat4_array_type =
glsl_type::get_array_instance(glsl_type::mat4_type,
state->Const.MaxTextureCoords);
add_uniform(instructions, symtab, "gl_TextureMatrix", mat4_array_type);
add_uniform(instructions, symtab, "gl_TextureMatrixInverse", mat4_array_type);
add_uniform(instructions, symtab, "gl_TextureMatrixTranspose", mat4_array_type);
add_uniform(instructions, symtab, "gl_TextureMatrixInverseTranspose", mat4_array_type);
add_uniform(instructions, symtab, "gl_TextureMatrix", mat4_array_type);
add_uniform(instructions, symtab, "gl_TextureMatrixInverse", mat4_array_type);
add_uniform(instructions, symtab, "gl_TextureMatrixTranspose", mat4_array_type);
add_uniform(instructions, symtab, "gl_TextureMatrixInverseTranspose", mat4_array_type);
}
add_uniform(instructions, symtab, "gl_DepthRange",
symtab->get_type("gl_DepthRangeParameters"));
add_uniform(instructions, symtab, "gl_ClipPlane",
glsl_type::get_array_instance(glsl_type::vec4_type,
state->Const.MaxClipPlanes));
add_uniform(instructions, symtab, "gl_Point",
symtab->get_type("gl_PointParameters"));
if (add_deprecated) {
add_uniform(instructions, symtab, "gl_ClipPlane",
glsl_type::get_array_instance(glsl_type::vec4_type,
state->Const.MaxClipPlanes));
add_uniform(instructions, symtab, "gl_Point",
symtab->get_type("gl_PointParameters"));
const glsl_type *const material_parameters_type =
symtab->get_type("gl_MaterialParameters");
add_uniform(instructions, symtab, "gl_FrontMaterial", material_parameters_type);
add_uniform(instructions, symtab, "gl_BackMaterial", material_parameters_type);
const glsl_type *const material_parameters_type =
symtab->get_type("gl_MaterialParameters");
add_uniform(instructions, symtab, "gl_FrontMaterial", material_parameters_type);
add_uniform(instructions, symtab, "gl_BackMaterial", material_parameters_type);
const glsl_type *const light_source_array_type =
glsl_type::get_array_instance(symtab->get_type("gl_LightSourceParameters"), state->Const.MaxLights);
const glsl_type *const light_source_array_type =
glsl_type::get_array_instance(symtab->get_type("gl_LightSourceParameters"), state->Const.MaxLights);
add_uniform(instructions, symtab, "gl_LightSource", light_source_array_type);
add_uniform(instructions, symtab, "gl_LightSource", light_source_array_type);
const glsl_type *const light_model_products_type =
symtab->get_type("gl_LightModelProducts");
add_uniform(instructions, symtab, "gl_FrontLightModelProduct",
light_model_products_type);
add_uniform(instructions, symtab, "gl_BackLightModelProduct",
light_model_products_type);
const glsl_type *const light_model_products_type =
symtab->get_type("gl_LightModelProducts");
add_uniform(instructions, symtab, "gl_FrontLightModelProduct",
light_model_products_type);
add_uniform(instructions, symtab, "gl_BackLightModelProduct",
light_model_products_type);
const glsl_type *const light_products_type =
glsl_type::get_array_instance(symtab->get_type("gl_LightProducts"),
state->Const.MaxLights);
add_uniform(instructions, symtab, "gl_FrontLightProduct", light_products_type);
add_uniform(instructions, symtab, "gl_BackLightProduct", light_products_type);
const glsl_type *const light_products_type =
glsl_type::get_array_instance(symtab->get_type("gl_LightProducts"),
state->Const.MaxLights);
add_uniform(instructions, symtab, "gl_FrontLightProduct", light_products_type);
add_uniform(instructions, symtab, "gl_BackLightProduct", light_products_type);
add_uniform(instructions, symtab, "gl_TextureEnvColor",
glsl_type::get_array_instance(glsl_type::vec4_type,
state->Const.MaxTextureUnits));
add_uniform(instructions, symtab, "gl_TextureEnvColor",
glsl_type::get_array_instance(glsl_type::vec4_type,
state->Const.MaxTextureUnits));
const glsl_type *const texcoords_vec4 =
glsl_type::get_array_instance(glsl_type::vec4_type,
state->Const.MaxTextureCoords);
add_uniform(instructions, symtab, "gl_EyePlaneS", texcoords_vec4);
add_uniform(instructions, symtab, "gl_EyePlaneT", texcoords_vec4);
add_uniform(instructions, symtab, "gl_EyePlaneR", texcoords_vec4);
add_uniform(instructions, symtab, "gl_EyePlaneQ", texcoords_vec4);
add_uniform(instructions, symtab, "gl_ObjectPlaneS", texcoords_vec4);
add_uniform(instructions, symtab, "gl_ObjectPlaneT", texcoords_vec4);
add_uniform(instructions, symtab, "gl_ObjectPlaneR", texcoords_vec4);
add_uniform(instructions, symtab, "gl_ObjectPlaneQ", texcoords_vec4);
const glsl_type *const texcoords_vec4 =
glsl_type::get_array_instance(glsl_type::vec4_type,
state->Const.MaxTextureCoords);
add_uniform(instructions, symtab, "gl_EyePlaneS", texcoords_vec4);
add_uniform(instructions, symtab, "gl_EyePlaneT", texcoords_vec4);
add_uniform(instructions, symtab, "gl_EyePlaneR", texcoords_vec4);
add_uniform(instructions, symtab, "gl_EyePlaneQ", texcoords_vec4);
add_uniform(instructions, symtab, "gl_ObjectPlaneS", texcoords_vec4);
add_uniform(instructions, symtab, "gl_ObjectPlaneT", texcoords_vec4);
add_uniform(instructions, symtab, "gl_ObjectPlaneR", texcoords_vec4);
add_uniform(instructions, symtab, "gl_ObjectPlaneQ", texcoords_vec4);
add_uniform(instructions, symtab, "gl_Fog",
symtab->get_type("gl_FogParameters"));
add_uniform(instructions, symtab, "gl_Fog",
symtab->get_type("gl_FogParameters"));
}
/* Mesa-internal current attrib state */
const glsl_type *const vert_attribs =
glsl_type::get_array_instance(glsl_type::vec4_type, VERT_ATTRIB_MAX);
add_uniform(instructions, symtab, "gl_CurrentAttribVertMESA", vert_attribs);
const glsl_type *const frag_attribs =
glsl_type::get_array_instance(glsl_type::vec4_type, FRAG_ATTRIB_MAX);
add_uniform(instructions, symtab, "gl_CurrentAttribFragMESA", frag_attribs);
}
/* This function should only be called for ES, not desktop GL. */
@ -527,7 +662,7 @@ generate_100ES_vs_variables(exec_list *instructions,
{
for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_core_vs_variables[i]);
& builtin_core_vs_variables[i], state->es_shader);
}
generate_100ES_uniforms(instructions, state);
@ -539,20 +674,23 @@ generate_100ES_vs_variables(exec_list *instructions,
static void
generate_110_vs_variables(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
struct _mesa_glsl_parse_state *state,
bool add_deprecated)
{
for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_core_vs_variables[i]);
& builtin_core_vs_variables[i], state->es_shader);
}
for (unsigned i = 0
; i < Elements(builtin_110_deprecated_vs_variables)
; i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_110_deprecated_vs_variables[i]);
if (add_deprecated) {
for (unsigned i = 0
; i < Elements(builtin_110_deprecated_vs_variables)
; i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_110_deprecated_vs_variables[i], state->es_shader);
}
}
generate_110_uniforms(instructions, state);
generate_110_uniforms(instructions, state, add_deprecated);
/* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
*
@ -575,33 +713,59 @@ generate_110_vs_variables(exec_list *instructions,
static void
generate_120_vs_variables(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
struct _mesa_glsl_parse_state *state,
bool add_deprecated)
{
/* GLSL version 1.20 did not add any built-in variables in the vertex
* shader.
*/
generate_110_vs_variables(instructions, state);
generate_110_vs_variables(instructions, state, add_deprecated);
}
static void
generate_130_uniforms(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
glsl_symbol_table *const symtab = state->symbols;
add_builtin_constant(instructions, symtab, "gl_MaxClipDistances",
state->Const.MaxClipPlanes);
add_builtin_constant(instructions, symtab, "gl_MaxVaryingComponents",
state->Const.MaxVaryingFloats);
}
static void
generate_130_vs_variables(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
struct _mesa_glsl_parse_state *state,
bool add_deprecated)
{
generate_120_vs_variables(instructions, state);
generate_120_vs_variables(instructions, state, add_deprecated);
for (unsigned i = 0; i < Elements(builtin_130_vs_variables); i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_130_vs_variables[i]);
& builtin_130_vs_variables[i], state->es_shader);
}
const glsl_type *const clip_distance_array_type =
glsl_type::get_array_instance(glsl_type::float_type,
state->Const.MaxClipPlanes);
generate_130_uniforms(instructions, state);
/* From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special
* Variables):
*
* The gl_ClipDistance array is predeclared as unsized and must
* be sized by the shader either redeclaring it with a size or
* indexing it only with integral constant expressions.
*
* We represent this in Mesa by initially declaring the array as
* size 0.
*/
const glsl_type *const clip_distance_array_type =
glsl_type::get_array_instance(glsl_type::float_type, 0);
/* FINISHME: gl_ClipDistance needs a real location assigned. */
add_variable(instructions, state->symbols,
"gl_ClipDistance", clip_distance_array_type, ir_var_out, -1);
"gl_ClipDistance", clip_distance_array_type, ir_var_out,
VERT_RESULT_CLIP_DIST0);
}
@ -616,19 +780,21 @@ initialize_vs_variables(exec_list *instructions,
generate_100ES_vs_variables(instructions, state);
break;
case 110:
generate_110_vs_variables(instructions, state);
generate_110_vs_variables(instructions, state, true);
break;
case 120:
generate_120_vs_variables(instructions, state);
generate_120_vs_variables(instructions, state, true);
break;
case 130:
generate_130_vs_variables(instructions, state);
generate_130_vs_variables(instructions, state, true);
break;
case 140:
generate_130_vs_variables(instructions, state, false);
break;
}
if (state->ARB_draw_instanced_enable)
generate_ARB_draw_instanced_variables(instructions, state, false,
vertex_shader);
generate_ARB_draw_instanced_variables(instructions, state, false,
vertex_shader);
}
@ -639,12 +805,12 @@ generate_100ES_fs_variables(exec_list *instructions,
{
for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_core_fs_variables[i]);
& builtin_core_fs_variables[i], state->es_shader);
}
for (unsigned i = 0; i < Elements(builtin_100ES_fs_variables); i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_100ES_fs_variables[i]);
& builtin_100ES_fs_variables[i], state->es_shader);
}
generate_100ES_uniforms(instructions, state);
@ -655,25 +821,29 @@ generate_100ES_fs_variables(exec_list *instructions,
static void
generate_110_fs_variables(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
struct _mesa_glsl_parse_state *state,
bool add_deprecated)
{
for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_core_fs_variables[i]);
& builtin_core_fs_variables[i], state->es_shader);
}
for (unsigned i = 0; i < Elements(builtin_110_fs_variables); i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_110_fs_variables[i]);
& builtin_110_fs_variables[i], state->es_shader);
}
for (unsigned i = 0
; i < Elements(builtin_110_deprecated_fs_variables)
; i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_110_deprecated_fs_variables[i]);
if (add_deprecated) {
for (unsigned i = 0
; i < Elements(builtin_110_deprecated_fs_variables)
; i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_110_deprecated_fs_variables[i], state->es_shader);
}
}
generate_110_uniforms(instructions, state);
generate_110_uniforms(instructions, state, add_deprecated);
/* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
*
@ -702,16 +872,12 @@ generate_ARB_draw_buffers_variables(exec_list *instructions,
/* gl_MaxDrawBuffers is available in all shader stages.
*/
ir_variable *const mdb =
add_variable(instructions, state->symbols,
"gl_MaxDrawBuffers", glsl_type::int_type, ir_var_auto, -1);
add_builtin_constant(instructions, state->symbols, "gl_MaxDrawBuffers",
state->Const.MaxDrawBuffers);
if (warn)
mdb->warn_extension = "GL_ARB_draw_buffers";
mdb->constant_value = new(mdb)
ir_constant(int(state->Const.MaxDrawBuffers));
/* gl_FragData is only available in the fragment shader.
*/
if (target == fragment_shader) {
@ -738,8 +904,11 @@ generate_ARB_draw_instanced_variables(exec_list *instructions,
{
/* gl_InstanceIDARB is only available in the vertex shader.
*/
if (target == vertex_shader) {
ir_variable *const inst =
if (target != vertex_shader)
return;
if (state->ARB_draw_instanced_enable) {
ir_variable *inst =
add_variable(instructions, state->symbols,
"gl_InstanceIDARB", glsl_type::int_type,
ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID);
@ -747,6 +916,21 @@ generate_ARB_draw_instanced_variables(exec_list *instructions,
if (warn)
inst->warn_extension = "GL_ARB_draw_instanced";
}
if (state->ARB_draw_instanced_enable || state->language_version >= 140) {
/* Originally ARB_draw_instanced only specified that ARB decorated name.
* Since no vendor actually implemented that behavior and some apps use
* the undecorated name, the extension now specifies that both names are
* available.
*/
ir_variable *inst =
add_variable(instructions, state->symbols,
"gl_InstanceID", glsl_type::int_type,
ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID);
if (state->language_version < 140 && warn)
inst->warn_extension = "GL_ARB_draw_instanced";
}
}
@ -784,31 +968,62 @@ generate_AMD_shader_stencil_export_variables(exec_list *instructions,
static void
generate_120_fs_variables(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
struct _mesa_glsl_parse_state *state,
bool add_deprecated)
{
generate_110_fs_variables(instructions, state);
generate_110_fs_variables(instructions, state, add_deprecated);
for (unsigned i = 0
; i < Elements(builtin_120_fs_variables)
; i++) {
add_builtin_variable(instructions, state->symbols,
& builtin_120_fs_variables[i]);
& builtin_120_fs_variables[i], state->es_shader);
}
}
static void
generate_fs_clipdistance(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
/* From the GLSL 1.30 spec, section 7.2 (Fragment Shader Special
* Variables):
*
* The built-in input variable gl_ClipDistance array contains linearly
* interpolated values for the vertex values written by the vertex shader
* to the gl_ClipDistance vertex output variable. This array must be
* sized in the fragment shader either implicitly or explicitly to be the
* same size as it was sized in the vertex shader.
*
* In other words, the array must be pre-declared as implicitly sized. We
* represent this in Mesa by initially declaring the array as size 0.
*/
const glsl_type *const clip_distance_array_type =
glsl_type::get_array_instance(glsl_type::float_type, 0);
add_variable(instructions, state->symbols,
"gl_ClipDistance", clip_distance_array_type, ir_var_in,
FRAG_ATTRIB_CLIP_DIST0);
}
static void
generate_130_fs_variables(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
generate_120_fs_variables(instructions, state);
generate_120_fs_variables(instructions, state, true);
const glsl_type *const clip_distance_array_type =
glsl_type::get_array_instance(glsl_type::float_type,
state->Const.MaxClipPlanes);
generate_130_uniforms(instructions, state);
generate_fs_clipdistance(instructions, state);
}
/* FINISHME: gl_ClipDistance needs a real location assigned. */
add_variable(instructions, state->symbols,
"gl_ClipDistance", clip_distance_array_type, ir_var_in, -1);
static void
generate_140_fs_variables(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
generate_120_fs_variables(instructions, state, false);
generate_130_uniforms(instructions, state);
generate_fs_clipdistance(instructions, state);
}
static void
@ -821,14 +1036,17 @@ initialize_fs_variables(exec_list *instructions,
generate_100ES_fs_variables(instructions, state);
break;
case 110:
generate_110_fs_variables(instructions, state);
generate_110_fs_variables(instructions, state, true);
break;
case 120:
generate_120_fs_variables(instructions, state);
generate_120_fs_variables(instructions, state, true);
break;
case 130:
generate_130_fs_variables(instructions, state);
break;
case 140:
generate_140_fs_variables(instructions, state);
break;
}
if (state->ARB_shader_stencil_export_enable)

View file

@ -1,110 +0,0 @@
/*
* Copyright © 2010 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "main/core.h" /* for slot numbers */
struct builtin_variable {
enum ir_variable_mode mode;
int slot;
const char *type;
const char *name;
};
static const builtin_variable builtin_core_vs_variables[] = {
{ ir_var_out, VERT_RESULT_HPOS, "vec4", "gl_Position" },
{ ir_var_out, VERT_RESULT_PSIZ, "float", "gl_PointSize" },
};
static const builtin_variable builtin_core_fs_variables[] = {
{ ir_var_in, FRAG_ATTRIB_WPOS, "vec4", "gl_FragCoord" },
{ ir_var_in, FRAG_ATTRIB_FACE, "bool", "gl_FrontFacing" },
{ ir_var_out, FRAG_RESULT_COLOR, "vec4", "gl_FragColor" },
};
static const builtin_variable builtin_100ES_fs_variables[] = {
{ ir_var_in, FRAG_ATTRIB_PNTC, "vec2", "gl_PointCoord" },
};
static const builtin_variable builtin_110_fs_variables[] = {
{ ir_var_out, FRAG_RESULT_DEPTH, "float", "gl_FragDepth" },
};
static const builtin_variable builtin_110_deprecated_fs_variables[] = {
{ ir_var_in, FRAG_ATTRIB_COL0, "vec4", "gl_Color" },
{ ir_var_in, FRAG_ATTRIB_COL1, "vec4", "gl_SecondaryColor" },
{ ir_var_in, FRAG_ATTRIB_FOGC, "float", "gl_FogFragCoord" },
};
static const builtin_variable builtin_110_deprecated_vs_variables[] = {
{ ir_var_in, VERT_ATTRIB_POS, "vec4", "gl_Vertex" },
{ ir_var_in, VERT_ATTRIB_NORMAL, "vec3", "gl_Normal" },
{ ir_var_in, VERT_ATTRIB_COLOR0, "vec4", "gl_Color" },
{ ir_var_in, VERT_ATTRIB_COLOR1, "vec4", "gl_SecondaryColor" },
{ ir_var_in, VERT_ATTRIB_TEX0, "vec4", "gl_MultiTexCoord0" },
{ ir_var_in, VERT_ATTRIB_TEX1, "vec4", "gl_MultiTexCoord1" },
{ ir_var_in, VERT_ATTRIB_TEX2, "vec4", "gl_MultiTexCoord2" },
{ ir_var_in, VERT_ATTRIB_TEX3, "vec4", "gl_MultiTexCoord3" },
{ ir_var_in, VERT_ATTRIB_TEX4, "vec4", "gl_MultiTexCoord4" },
{ ir_var_in, VERT_ATTRIB_TEX5, "vec4", "gl_MultiTexCoord5" },
{ ir_var_in, VERT_ATTRIB_TEX6, "vec4", "gl_MultiTexCoord6" },
{ ir_var_in, VERT_ATTRIB_TEX7, "vec4", "gl_MultiTexCoord7" },
{ ir_var_in, VERT_ATTRIB_FOG, "float", "gl_FogCoord" },
{ ir_var_out, VERT_RESULT_HPOS, "vec4", "gl_ClipVertex" },
{ ir_var_out, VERT_RESULT_COL0, "vec4", "gl_FrontColor" },
{ ir_var_out, VERT_RESULT_BFC0, "vec4", "gl_BackColor" },
{ ir_var_out, VERT_RESULT_COL1, "vec4", "gl_FrontSecondaryColor" },
{ ir_var_out, VERT_RESULT_BFC1, "vec4", "gl_BackSecondaryColor" },
{ ir_var_out, VERT_RESULT_FOGC, "float", "gl_FogFragCoord" },
};
static const builtin_variable builtin_120_fs_variables[] = {
{ ir_var_in, FRAG_ATTRIB_PNTC, "vec2", "gl_PointCoord" },
};
static const builtin_variable builtin_130_vs_variables[] = {
{ ir_var_in, -1, "int", "gl_VertexID" },
};
static const builtin_variable builtin_110_deprecated_uniforms[] = {
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrix" },
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrix" },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrix" },
{ ir_var_uniform, -1, "mat3", "gl_NormalMatrix" },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixInverse" },
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixInverse" },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixInverse" },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixTranspose" },
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixTranspose" },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixTranspose" },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixInverseTranspose" },
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixInverseTranspose" },
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixInverseTranspose" },
{ ir_var_uniform, -1, "float", "gl_NormalScale" },
{ ir_var_uniform, -1, "gl_LightModelParameters", "gl_LightModel"},
/* Mesa-internal ATI_envmap_bumpmap state. */
{ ir_var_uniform, -1, "vec2", "gl_MESABumpRotMatrix0"},
{ ir_var_uniform, -1, "vec2", "gl_MESABumpRotMatrix1"},
{ ir_var_uniform, -1, "vec4", "gl_MESAFogParamsOptimized"},
};

View file

@ -0,0 +1,106 @@
/* Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
* Copyright © 2012 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#version 120
mat2 inverse(mat2 m)
{
mat2 adj;
adj[0][0] = m[1][1];
adj[0][1] = -m[0][1];
adj[1][0] = -m[1][0];
adj[1][1] = m[0][0];
float det = m[0][0] * m[1][1] - m[1][0] * m[0][1];
return adj / det;
}
mat3 inverse(mat3 m)
{
mat3 adj;
adj[0][0] = + (m[1][1] * m[2][2] - m[2][1] * m[1][2]);
adj[1][0] = - (m[1][0] * m[2][2] - m[2][0] * m[1][2]);
adj[2][0] = + (m[1][0] * m[2][1] - m[2][0] * m[1][1]);
adj[0][1] = - (m[0][1] * m[2][2] - m[2][1] * m[0][2]);
adj[1][1] = + (m[0][0] * m[2][2] - m[2][0] * m[0][2]);
adj[2][1] = - (m[0][0] * m[2][1] - m[2][0] * m[0][1]);
adj[0][2] = + (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
adj[1][2] = - (m[0][0] * m[1][2] - m[1][0] * m[0][2]);
adj[2][2] = + (m[0][0] * m[1][1] - m[1][0] * m[0][1]);
float det = (+ m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])
- m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
+ m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]));
return adj / det;
}
mat4 inverse(mat4 m)
{
float SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3];
float SubFactor01 = m[2][1] * m[3][3] - m[3][1] * m[2][3];
float SubFactor02 = m[2][1] * m[3][2] - m[3][1] * m[2][2];
float SubFactor03 = m[2][0] * m[3][3] - m[3][0] * m[2][3];
float SubFactor04 = m[2][0] * m[3][2] - m[3][0] * m[2][2];
float SubFactor05 = m[2][0] * m[3][1] - m[3][0] * m[2][1];
float SubFactor06 = m[1][2] * m[3][3] - m[3][2] * m[1][3];
float SubFactor07 = m[1][1] * m[3][3] - m[3][1] * m[1][3];
float SubFactor08 = m[1][1] * m[3][2] - m[3][1] * m[1][2];
float SubFactor09 = m[1][0] * m[3][3] - m[3][0] * m[1][3];
float SubFactor10 = m[1][0] * m[3][2] - m[3][0] * m[1][2];
float SubFactor11 = m[1][1] * m[3][3] - m[3][1] * m[1][3];
float SubFactor12 = m[1][0] * m[3][1] - m[3][0] * m[1][1];
float SubFactor13 = m[1][2] * m[2][3] - m[2][2] * m[1][3];
float SubFactor14 = m[1][1] * m[2][3] - m[2][1] * m[1][3];
float SubFactor15 = m[1][1] * m[2][2] - m[2][1] * m[1][2];
float SubFactor16 = m[1][0] * m[2][3] - m[2][0] * m[1][3];
float SubFactor17 = m[1][0] * m[2][2] - m[2][0] * m[1][2];
float SubFactor18 = m[1][0] * m[2][1] - m[2][0] * m[1][1];
mat4 adj;
adj[0][0] = + (m[1][1] * SubFactor00 - m[1][2] * SubFactor01 + m[1][3] * SubFactor02);
adj[1][0] = - (m[1][0] * SubFactor00 - m[1][2] * SubFactor03 + m[1][3] * SubFactor04);
adj[2][0] = + (m[1][0] * SubFactor01 - m[1][1] * SubFactor03 + m[1][3] * SubFactor05);
adj[3][0] = - (m[1][0] * SubFactor02 - m[1][1] * SubFactor04 + m[1][2] * SubFactor05);
adj[0][1] = - (m[0][1] * SubFactor00 - m[0][2] * SubFactor01 + m[0][3] * SubFactor02);
adj[1][1] = + (m[0][0] * SubFactor00 - m[0][2] * SubFactor03 + m[0][3] * SubFactor04);
adj[2][1] = - (m[0][0] * SubFactor01 - m[0][1] * SubFactor03 + m[0][3] * SubFactor05);
adj[3][1] = + (m[0][0] * SubFactor02 - m[0][1] * SubFactor04 + m[0][2] * SubFactor05);
adj[0][2] = + (m[0][1] * SubFactor06 - m[0][2] * SubFactor07 + m[0][3] * SubFactor08);
adj[1][2] = - (m[0][0] * SubFactor06 - m[0][2] * SubFactor09 + m[0][3] * SubFactor10);
adj[2][2] = + (m[0][0] * SubFactor11 - m[0][1] * SubFactor09 + m[0][3] * SubFactor12);
adj[3][2] = - (m[0][0] * SubFactor08 - m[0][1] * SubFactor10 + m[0][2] * SubFactor12);
adj[0][3] = - (m[0][1] * SubFactor13 - m[0][2] * SubFactor14 + m[0][3] * SubFactor15);
adj[1][3] = + (m[0][0] * SubFactor13 - m[0][2] * SubFactor16 + m[0][3] * SubFactor17);
adj[2][3] = - (m[0][0] * SubFactor14 - m[0][1] * SubFactor16 + m[0][3] * SubFactor18);
adj[3][3] = + (m[0][0] * SubFactor15 - m[0][1] * SubFactor17 + m[0][2] * SubFactor18);
float det = (+ m[0][0] * adj[0][0]
+ m[0][1] * adj[1][0]
+ m[0][2] * adj[2][0]
+ m[0][3] * adj[3][0]);
return adj / det;
}

View file

@ -1,22 +0,0 @@
((function acos
(signature float
(parameters
(declare (in) float x))
((return (expression float - (constant float (1.5707963))
(call asin ((var_ref x)))))))
(signature vec2
(parameters
(declare (in) vec2 x))
((return (expression vec2 - (constant float (1.5707963))
(call asin ((var_ref x)))))))
(signature vec3
(parameters
(declare (in) vec3 x))
((return (expression vec3 - (constant float (1.5707963))
(call asin ((var_ref x)))))))
(signature vec4
(parameters
(declare (in) vec4 x))
((return (expression vec4 - (constant float (1.5707963))
(call asin ((var_ref x)))))))
))

View file

@ -0,0 +1,29 @@
((function acos
(signature float
(parameters
(declare (in) float x))
((declare () float s)
(call asin (var_ref s) ((var_ref x)))
(return (expression float - (constant float (1.5707964)) (var_ref s)))))
(signature vec2
(parameters
(declare (in) vec2 x))
((declare () vec2 s)
(call asin (var_ref s) ((var_ref x)))
(return (expression vec2 - (constant float (1.5707964)) (var_ref s)))))
(signature vec3
(parameters
(declare (in) vec3 x))
((declare () vec3 s)
(call asin (var_ref s) ((var_ref x)))
(return (expression vec3 - (constant float (1.5707964)) (var_ref s)))))
(signature vec4
(parameters
(declare (in) vec4 x))
((declare () vec4 s)
(call asin (var_ref s) ((var_ref x)))
(return (expression vec4 - (constant float (1.5707964)) (var_ref s)))))
))

View file

@ -7,15 +7,15 @@
(signature vec2
(parameters
(declare (in) vec2 x))
((return (expression vec2 log (expression vec2 + (var_ref x) (expression vec2 sqrt (expression vec2 - (expression vec2 * (var_ref x) (var_ref x)) (constant vec2 (1)))))))))
((return (expression vec2 log (expression vec2 + (var_ref x) (expression vec2 sqrt (expression vec2 - (expression vec2 * (var_ref x) (var_ref x)) (constant float (1)))))))))
(signature vec3
(parameters
(declare (in) vec3 x))
((return (expression vec3 log (expression vec3 + (var_ref x) (expression vec3 sqrt (expression vec3 - (expression vec3 * (var_ref x) (var_ref x)) (constant vec3 (1)))))))))
((return (expression vec3 log (expression vec3 + (var_ref x) (expression vec3 sqrt (expression vec3 - (expression vec3 * (var_ref x) (var_ref x)) (constant float (1)))))))))
(signature vec4
(parameters
(declare (in) vec4 x))
((return (expression vec4 log (expression vec4 + (var_ref x) (expression vec4 sqrt (expression vec4 - (expression vec4 * (var_ref x) (var_ref x)) (constant vec4 (1)))))))))
((return (expression vec4 log (expression vec4 + (var_ref x) (expression vec4 sqrt (expression vec4 - (expression vec4 * (var_ref x) (var_ref x)) (constant float (1)))))))))
))

View file

@ -1,21 +0,0 @@
((function asinh
(signature float
(parameters
(declare (in) float x))
((return (expression float log (expression float + (var_ref x) (expression float sqrt (expression float + (expression float * (var_ref x) (var_ref x)) (constant float (1)))))))))
(signature vec2
(parameters
(declare (in) vec2 x))
((return (expression vec2 log (expression vec2 + (var_ref x) (expression vec2 sqrt (expression vec2 + (expression vec2 * (var_ref x) (var_ref x)) (constant vec2 (1)))))))))
(signature vec3
(parameters
(declare (in) vec3 x))
((return (expression vec3 log (expression vec3 + (var_ref x) (expression vec3 sqrt (expression vec3 + (expression vec3 * (var_ref x) (var_ref x)) (constant vec3 (1)))))))))
(signature vec4
(parameters
(declare (in) vec4 x))
((return (expression vec4 log (expression vec4 + (var_ref x) (expression vec4 sqrt (expression vec4 + (expression vec4 * (var_ref x) (var_ref x)) (constant vec4 (1)))))))))
))

View file

@ -0,0 +1,53 @@
((function asinh
(signature float
(parameters
(declare (in) float x))
((return (expression float *
(expression float sign (var_ref x))
(expression float log
(expression float +
(expression float abs (var_ref x))
(expression float sqrt
(expression float +
(expression float * (var_ref x) (var_ref x))
(constant float (1))))))))))
(signature vec2
(parameters
(declare (in) vec2 x))
((return (expression vec2 *
(expression vec2 sign (var_ref x))
(expression vec2 log
(expression vec2 +
(expression vec2 abs (var_ref x))
(expression vec2 sqrt
(expression vec2 +
(expression vec2 * (var_ref x) (var_ref x))
(constant float (1))))))))))
(signature vec3
(parameters
(declare (in) vec3 x))
((return (expression vec3 *
(expression vec3 sign (var_ref x))
(expression vec3 log
(expression vec3 +
(expression vec3 abs (var_ref x))
(expression vec3 sqrt
(expression vec3 +
(expression vec3 * (var_ref x) (var_ref x))
(constant float (1))))))))))
(signature vec4
(parameters
(declare (in) vec4 x))
((return (expression vec4 *
(expression vec4 sign (var_ref x))
(expression vec4 log
(expression vec4 +
(expression vec4 abs (var_ref x))
(expression vec4 sqrt
(expression vec4 +
(expression vec4 * (var_ref x) (var_ref x))
(constant float (1))))))))))
))

View file

@ -2,50 +2,62 @@
(signature float
(parameters
(declare (in) float y_over_x))
((return (call asin ((expression float *
((declare () float s)
(call asin (var_ref s)
((expression float *
(var_ref y_over_x)
(expression float rsq
(expression float +
(expression float *
(var_ref y_over_x)
(var_ref y_over_x))
(constant float (1.0))))))))))
(constant float (1.0)))))))
(return (var_ref s))))
(signature vec2
(parameters
(declare (in) vec2 y_over_x))
((return (call asin ((expression vec2 *
((declare () vec2 s)
(call asin (var_ref s)
((expression vec2 *
(var_ref y_over_x)
(expression vec2 rsq
(expression vec2 +
(expression vec2 *
(var_ref y_over_x)
(var_ref y_over_x))
(constant float (1.0))))))))))
(constant float (1.0)))))))
(return (var_ref s))))
(signature vec3
(parameters
(declare (in) vec3 y_over_x))
((return (call asin ((expression vec3 *
((declare () vec3 s)
(call asin (var_ref s)
((expression vec3 *
(var_ref y_over_x)
(expression vec3 rsq
(expression vec3 +
(expression vec3 *
(var_ref y_over_x)
(var_ref y_over_x))
(constant float (1.0))))))))))
(constant float (1.0)))))))
(return (var_ref s))))
(signature vec4
(parameters
(declare (in) vec4 y_over_x))
((return (call asin ((expression vec4 *
((declare () vec4 s)
(call asin (var_ref s)
((expression vec4 *
(var_ref y_over_x)
(expression vec4 rsq
(expression vec4 +
(expression vec4 *
(var_ref y_over_x)
(var_ref y_over_x))
(constant float (1.0))))))))))
(constant float (1.0)))))))
(return (var_ref s))))
(signature float
(parameters
@ -57,7 +69,7 @@
(if (expression bool >
(expression float abs (var_ref x))
(expression float * (constant float (1.0e-8)) (expression float abs (var_ref y)))) (
(assign (x) (var_ref r) (call atan ((expression float / (var_ref y) (var_ref x)))))
(call atan (var_ref r) ((expression float / (var_ref y) (var_ref x))))
(if (expression bool < (var_ref x) (constant float (0.000000)) ) (
(if (expression bool >= (var_ref y) (constant float (0.000000)) )
((assign (x) (var_ref r) (expression float + (var_ref r) (constant float (3.141593)))))
@ -82,12 +94,11 @@
(declare (in) vec2 y)
(declare (in) vec2 x))
((declare () vec2 r)
(assign (x) (var_ref r)
(call atan ((swiz x (var_ref y))
(swiz x (var_ref x)))))
(assign (y) (var_ref r)
(call atan ((swiz y (var_ref y))
(swiz y (var_ref x)))))
(declare () float temp)
(call atan (var_ref temp) ((swiz x (var_ref y)) (swiz x (var_ref x))))
(assign (x) (var_ref r) (var_ref temp))
(call atan (var_ref temp) ((swiz y (var_ref y)) (swiz y (var_ref x))))
(assign (y) (var_ref r) (var_ref temp))
(return (var_ref r))))
(signature vec3
@ -95,15 +106,13 @@
(declare (in) vec3 y)
(declare (in) vec3 x))
((declare () vec3 r)
(assign (x) (var_ref r)
(call atan ((swiz x (var_ref y))
(swiz x (var_ref x)))))
(assign (y) (var_ref r)
(call atan ((swiz y (var_ref y))
(swiz y (var_ref x)))))
(assign (z) (var_ref r)
(call atan ((swiz z (var_ref y))
(swiz z (var_ref x)))))
(declare () float temp)
(call atan (var_ref temp) ((swiz x (var_ref y)) (swiz x (var_ref x))))
(assign (x) (var_ref r) (var_ref temp))
(call atan (var_ref temp) ((swiz y (var_ref y)) (swiz y (var_ref x))))
(assign (y) (var_ref r) (var_ref temp))
(call atan (var_ref temp) ((swiz z (var_ref y)) (swiz z (var_ref x))))
(assign (z) (var_ref r) (var_ref temp))
(return (var_ref r))))
(signature vec4
@ -111,18 +120,15 @@
(declare (in) vec4 y)
(declare (in) vec4 x))
((declare () vec4 r)
(assign (x) (var_ref r)
(call atan ((swiz x (var_ref y))
(swiz x (var_ref x)))))
(assign (y) (var_ref r)
(call atan ((swiz y (var_ref y))
(swiz y (var_ref x)))))
(assign (z) (var_ref r)
(call atan ((swiz z (var_ref y))
(swiz z (var_ref x)))))
(assign (w) (var_ref r)
(call atan ((swiz w (var_ref y))
(swiz w (var_ref x)))))
(return (var_ref r)))))
(declare () float temp)
(call atan (var_ref temp) ((swiz x (var_ref y)) (swiz x (var_ref x))))
(assign (x) (var_ref r) (var_ref temp))
(call atan (var_ref temp) ((swiz y (var_ref y)) (swiz y (var_ref x))))
(assign (y) (var_ref r) (var_ref temp))
(call atan (var_ref temp) ((swiz z (var_ref y)) (swiz z (var_ref x))))
(assign (z) (var_ref r) (var_ref temp))
(call atan (var_ref temp) ((swiz w (var_ref y)) (swiz w (var_ref x))))
(assign (w) (var_ref r) (var_ref temp))
(return (var_ref r))))
))

View file

@ -11,27 +11,27 @@
(signature vec2
(parameters
(declare (in) vec2 x))
((return (expression vec2 * (constant vec2 (0.5))
((return (expression vec2 * (constant float (0.5))
(expression vec2 log
(expression vec2 /
(expression vec2 + (constant vec2 (1)) (var_ref x))
(expression vec2 - (constant vec2 (1)) (var_ref x))))))))
(expression vec2 + (constant float (1)) (var_ref x))
(expression vec2 - (constant float (1)) (var_ref x))))))))
(signature vec3
(parameters
(declare (in) vec3 x))
((return (expression vec3 * (constant vec3 (0.5))
((return (expression vec3 * (constant float (0.5))
(expression vec3 log
(expression vec3 /
(expression vec3 + (constant vec3 (1)) (var_ref x))
(expression vec3 - (constant vec3 (1)) (var_ref x))))))))
(expression vec3 + (constant float (1)) (var_ref x))
(expression vec3 - (constant float (1)) (var_ref x))))))))
(signature vec4
(parameters
(declare (in) vec4 x))
((return (expression vec4 * (constant vec4 (0.5))
((return (expression vec4 * (constant float (0.5))
(expression vec4 log
(expression vec4 /
(expression vec4 + (constant vec4 (1)) (var_ref x))
(expression vec4 - (constant vec4 (1)) (var_ref x))))))))
(expression vec4 + (constant float (1)) (var_ref x))
(expression vec4 - (constant float (1)) (var_ref x))))))))
))

View file

@ -4,145 +4,145 @@
(declare (in) float arg0)
(declare (in) float arg1)
(declare (in) float arg2))
((return (expression float max (expression float min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression float clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec2
(parameters
(declare (in) vec2 arg0)
(declare (in) vec2 arg1)
(declare (in) vec2 arg2))
((return (expression vec2 max (expression vec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression vec2 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec3
(parameters
(declare (in) vec3 arg0)
(declare (in) vec3 arg1)
(declare (in) vec3 arg2))
((return (expression vec3 max (expression vec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression vec3 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec4
(parameters
(declare (in) vec4 arg0)
(declare (in) vec4 arg1)
(declare (in) vec4 arg2))
((return (expression vec4 max (expression vec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression vec4 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec2
(parameters
(declare (in) vec2 arg0)
(declare (in) float arg1)
(declare (in) float arg2))
((return (expression vec2 max (expression vec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression vec2 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec3
(parameters
(declare (in) vec3 arg0)
(declare (in) float arg1)
(declare (in) float arg2))
((return (expression vec3 max (expression vec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression vec3 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec4
(parameters
(declare (in) vec4 arg0)
(declare (in) float arg1)
(declare (in) float arg2))
((return (expression vec4 max (expression vec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression vec4 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature int
(parameters
(declare (in) int arg0)
(declare (in) int arg1)
(declare (in) int arg2))
((return (expression int max (expression int min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression int clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature ivec2
(parameters
(declare (in) ivec2 arg0)
(declare (in) ivec2 arg1)
(declare (in) ivec2 arg2))
((return (expression ivec2 max (expression ivec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression ivec2 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature ivec3
(parameters
(declare (in) ivec3 arg0)
(declare (in) ivec3 arg1)
(declare (in) ivec3 arg2))
((return (expression ivec3 max (expression ivec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression ivec3 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature ivec4
(parameters
(declare (in) ivec4 arg0)
(declare (in) ivec4 arg1)
(declare (in) ivec4 arg2))
((return (expression ivec4 max (expression ivec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression ivec4 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature ivec2
(parameters
(declare (in) ivec2 arg0)
(declare (in) int arg1)
(declare (in) int arg2))
((return (expression ivec2 max (expression ivec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression ivec2 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature ivec3
(parameters
(declare (in) ivec3 arg0)
(declare (in) int arg1)
(declare (in) int arg2))
((return (expression ivec3 max (expression ivec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression ivec3 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature ivec4
(parameters
(declare (in) ivec4 arg0)
(declare (in) int arg1)
(declare (in) int arg2))
((return (expression ivec4 max (expression ivec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression ivec4 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature uint
(parameters
(declare (in) uint arg0)
(declare (in) uint arg1)
(declare (in) uint arg2))
((return (expression uint max (expression uint min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression uint clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature uvec2
(parameters
(declare (in) uvec2 arg0)
(declare (in) uvec2 arg1)
(declare (in) uvec2 arg2))
((return (expression uvec2 max (expression uvec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression uvec2 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature uvec3
(parameters
(declare (in) uvec3 arg0)
(declare (in) uvec3 arg1)
(declare (in) uvec3 arg2))
((return (expression uvec3 max (expression uvec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression uvec3 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature uvec4
(parameters
(declare (in) uvec4 arg0)
(declare (in) uvec4 arg1)
(declare (in) uvec4 arg2))
((return (expression uvec4 max (expression uvec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression uvec4 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature uvec2
(parameters
(declare (in) uvec2 arg0)
(declare (in) uint arg1)
(declare (in) uint arg2))
((return (expression uvec2 max (expression uvec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression uvec2 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature uvec3
(parameters
(declare (in) uvec3 arg0)
(declare (in) uint arg1)
(declare (in) uint arg2))
((return (expression uvec3 max (expression uvec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression uvec3 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature uvec4
(parameters
(declare (in) uvec4 arg0)
(declare (in) uint arg1)
(declare (in) uint arg2))
((return (expression uvec4 max (expression uvec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))
((return (expression uvec4 clamp (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
))

View file

@ -9,21 +9,21 @@
(signature vec2
(parameters
(declare (in) vec2 x))
((return (expression vec2 * (constant vec2 (0.5))
((return (expression vec2 * (constant float (0.5))
(expression vec2 +
(expression vec2 exp (var_ref x))
(expression vec2 exp (expression vec2 neg (var_ref x))))))))
(signature vec3
(parameters
(declare (in) vec3 x))
((return (expression vec3 * (constant vec3 (0.5))
((return (expression vec3 * (constant float (0.5))
(expression vec3 +
(expression vec3 exp (var_ref x))
(expression vec3 exp (expression vec3 neg (var_ref x))))))))
(signature vec4
(parameters
(declare (in) vec4 x))
((return (expression vec4 * (constant vec4 (0.5))
((return (expression vec4 * (constant float (0.5))
(expression vec4 +
(expression vec4 exp (var_ref x))
(expression vec4 exp (expression vec4 neg (var_ref x))))))))

View file

@ -0,0 +1,21 @@
((function floatBitsToInt
(signature int
(parameters
(declare (in) float arg))
((return (expression int bitcast_f2i (var_ref arg)))))
(signature ivec2
(parameters
(declare (in) vec2 arg))
((return (expression ivec2 bitcast_f2i (var_ref arg)))))
(signature ivec3
(parameters
(declare (in) vec3 arg))
((return (expression ivec3 bitcast_f2i (var_ref arg)))))
(signature ivec4
(parameters
(declare (in) vec4 arg))
((return (expression ivec4 bitcast_f2i (var_ref arg)))))
))

View file

@ -0,0 +1,21 @@
((function floatBitsToUint
(signature uint
(parameters
(declare (in) float arg))
((return (expression uint bitcast_f2u (var_ref arg)))))
(signature uvec2
(parameters
(declare (in) vec2 arg))
((return (expression uvec2 bitcast_f2u (var_ref arg)))))
(signature uvec3
(parameters
(declare (in) vec3 arg))
((return (expression uvec3 bitcast_f2u (var_ref arg)))))
(signature uvec4
(parameters
(declare (in) vec4 arg))
((return (expression uvec4 bitcast_f2u (var_ref arg)))))
))

View file

@ -0,0 +1,21 @@
((function intBitsToFloat
(signature float
(parameters
(declare (in) int arg))
((return (expression float bitcast_i2f (var_ref arg)))))
(signature vec2
(parameters
(declare (in) ivec2 arg))
((return (expression vec2 bitcast_i2f (var_ref arg)))))
(signature vec3
(parameters
(declare (in) ivec3 arg))
((return (expression vec3 bitcast_i2f (var_ref arg)))))
(signature vec4
(parameters
(declare (in) ivec4 arg))
((return (expression vec4 bitcast_i2f (var_ref arg)))))
))

View file

@ -0,0 +1,17 @@
((function isinf
(signature bool
(parameters
(declare (in) float x))
((return (expression bool == (expression float abs (var_ref x)) (constant float (+INF))))))
(signature bvec2
(parameters
(declare (in) vec2 x))
((return (expression bvec2 == (expression vec2 abs (var_ref x)) (constant vec2 (+INF +INF))))))
(signature bvec3
(parameters
(declare (in) vec3 x))
((return (expression bvec3 == (expression vec3 abs (var_ref x)) (constant vec3 (+INF +INF +INF))))))
(signature bvec4
(parameters
(declare (in) vec4 x))
((return (expression bvec4 == (expression vec4 abs (var_ref x)) (constant vec4 (+INF +INF +INF +INF))))))))

View file

@ -0,0 +1,17 @@
((function isnan
(signature bool
(parameters
(declare (in) float x))
((return (expression bool != (var_ref x) (var_ref x)))))
(signature bvec2
(parameters
(declare (in) vec2 x))
((return (expression bvec2 != (var_ref x) (var_ref x)))))
(signature bvec3
(parameters
(declare (in) vec3 x))
((return (expression bvec3 != (var_ref x) (var_ref x)))))
(signature bvec4
(parameters
(declare (in) vec4 x))
((return (expression bvec4 != (var_ref x) (var_ref x)))))))

View file

@ -4,56 +4,56 @@
(declare (in) float arg0)
(declare (in) float arg1)
(declare (in) float arg2))
((return (expression float + (expression float * (var_ref arg0) (expression float - (constant float (1.000000)) (var_ref arg2))) (expression float * (var_ref arg1) (var_ref arg2))))))
((return (expression float mix (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec2
(parameters
(declare (in) vec2 arg0)
(declare (in) vec2 arg1)
(declare (in) vec2 arg2))
((return (expression vec2 + (expression vec2 * (var_ref arg0) (expression vec2 - (constant float (1.000000)) (var_ref arg2))) (expression vec2 * (var_ref arg1) (var_ref arg2))))))
((return (expression vec2 mix (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec3
(parameters
(declare (in) vec3 arg0)
(declare (in) vec3 arg1)
(declare (in) vec3 arg2))
((return (expression vec3 + (expression vec3 * (var_ref arg0) (expression vec3 - (constant float (1.000000)) (var_ref arg2))) (expression vec3 * (var_ref arg1) (var_ref arg2))))))
((return (expression vec3 mix (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec4
(parameters
(declare (in) vec4 arg0)
(declare (in) vec4 arg1)
(declare (in) vec4 arg2))
((return (expression vec4 + (expression vec4 * (var_ref arg0) (expression vec4 - (constant float (1.000000)) (var_ref arg2))) (expression vec4 * (var_ref arg1) (var_ref arg2))))))
((return (expression vec4 mix (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec2
(parameters
(declare (in) vec2 arg0)
(declare (in) vec2 arg1)
(declare (in) float arg2))
((return (expression vec2 + (expression vec2 * (var_ref arg0) (expression float - (constant float (1.000000)) (var_ref arg2))) (expression vec2 * (var_ref arg1) (var_ref arg2))))))
((return (expression vec2 mix (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec3
(parameters
(declare (in) vec3 arg0)
(declare (in) vec3 arg1)
(declare (in) float arg2))
((return (expression vec3 + (expression vec3 * (var_ref arg0) (expression float - (constant float (1.000000)) (var_ref arg2))) (expression vec3 * (var_ref arg1) (var_ref arg2))))))
((return (expression vec3 mix (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature vec4
(parameters
(declare (in) vec4 arg0)
(declare (in) vec4 arg1)
(declare (in) float arg2))
((return (expression vec4 + (expression vec4 * (var_ref arg0) (expression float - (constant float (1.000000)) (var_ref arg2))) (expression vec4 * (var_ref arg1) (var_ref arg2))))))
((return (expression vec4 mix (var_ref arg0) (var_ref arg1) (var_ref arg2)))))
(signature float
(parameters
(declare (in) float v1)
(declare (in) float v2)
(declare (in) bool a))
((assign (var_ref a) (var_ref v1) (var_ref v2))
((assign (var_ref a) (x) (var_ref v1) (var_ref v2))
(return (var_ref v1))))
(signature vec2

View file

@ -84,9 +84,9 @@
(assign (x) (var_ref _p) (expression float + (var_ref p) (constant float (1559.0))) )
(assign (x) (var_ref _x) (expression float noise(var_ref p)))
(assign (x) (var_ref _y) (expression float noise(expression float + (var_ref p) (constant float (601.0 313.0 29.0 277.0)))))
(assign (x) (var_ref _y) (expression float noise(expression float + (var_ref p) (constant float (601.0)))))
(assign (x) (var_ref _z) (expression float noise(var_ref _p)))
(assign (x) (var_ref _w) (expression float noise(expression float + (var_ref _p) (constant float (601.0 313.0 29.0 277.0)))))
(assign (x) (var_ref _w) (expression float noise(expression float + (var_ref _p) (constant float (601.0)))))
(assign (x) (var_ref _r) (var_ref _x))
(assign (y) (var_ref _r) (var_ref _y))

View file

@ -1,21 +0,0 @@
((function normalize
(signature float
(parameters
(declare (in) float arg0))
((return (expression float sign (var_ref arg0)))))
(signature vec2
(parameters
(declare (in) vec2 arg0))
((return (expression vec2 * (var_ref arg0) (expression float rsq (expression float dot (var_ref arg0) (var_ref arg0)))))))
(signature vec3
(parameters
(declare (in) vec3 arg0))
((return (expression vec3 * (var_ref arg0) (expression float rsq (expression float dot (var_ref arg0) (var_ref arg0)))))))
(signature vec4
(parameters
(declare (in) vec4 arg0))
((return (expression vec4 * (var_ref arg0) (expression float rsq (expression float dot (var_ref arg0) (var_ref arg0)))))))
))

View file

@ -0,0 +1,21 @@
((function normalize
(signature float
(parameters
(declare (in) float arg0))
((return (expression float sign (var_ref arg0)))))
(signature vec2
(parameters
(declare (in) vec2 arg0))
((return (expression vec2 normalize (var_ref arg0)))))
(signature vec3
(parameters
(declare (in) vec3 arg0))
((return (expression vec3 normalize (var_ref arg0)))))
(signature vec4
(parameters
(declare (in) vec4 arg0))
((return (expression vec4 normalize (var_ref arg0)))))
))

View file

@ -9,21 +9,21 @@
(signature vec2
(parameters
(declare (in) vec2 x))
((return (expression vec2 * (constant vec2 (0.5))
((return (expression vec2 * (constant float (0.5))
(expression vec2 -
(expression vec2 exp (var_ref x))
(expression vec2 exp (expression vec2 neg (var_ref x))))))))
(signature vec3
(parameters
(declare (in) vec3 x))
((return (expression vec3 * (constant vec3 (0.5))
((return (expression vec3 * (constant float (0.5))
(expression vec3 -
(expression vec3 exp (var_ref x))
(expression vec3 exp (expression vec3 neg (var_ref x))))))))
(signature vec4
(parameters
(declare (in) vec4 x))
((return (expression vec4 * (constant vec4 (0.5))
((return (expression vec4 * (constant float (0.5))
(expression vec4 -
(expression vec4 exp (var_ref x))
(expression vec4 exp (expression vec4 neg (var_ref x))))))))

Some files were not shown because too many files have changed in this diff Show more