diff --git a/content/canvas/test/webgl/failing_tests_windows.txt b/content/canvas/test/webgl/failing_tests_windows.txt index 93b0e99ac26..1f1c4145dd4 100644 --- a/content/canvas/test/webgl/failing_tests_windows.txt +++ b/content/canvas/test/webgl/failing_tests_windows.txt @@ -3,11 +3,9 @@ conformance/context/premultiplyalpha-test.html conformance/glsl/functions/glsl-function-atan.html conformance/glsl/functions/glsl-function-atan-xy.html conformance/glsl/functions/glsl-function-mod-gentype.html -conformance/glsl/misc/glsl-function-nodes.html conformance/glsl/misc/glsl-long-variable-names.html conformance/glsl/misc/shader-with-256-character-identifier.frag.html conformance/glsl/misc/shader-with-long-line.html -conformance/glsl/variables/gl-frontfacing.html conformance/reading/read-pixels-test.html conformance/renderbuffers/framebuffer-object-attachment.html conformance/more/conformance/quickCheckAPI-S_V.html diff --git a/gfx/angle/CONTRIBUTORS b/gfx/angle/CONTRIBUTORS index 51221b1290e..6f9946a1f68 100644 --- a/gfx/angle/CONTRIBUTORS +++ b/gfx/angle/CONTRIBUTORS @@ -28,6 +28,7 @@ Google Inc. Adrienne Walker Mozilla Corp. + Ehsan Akhgari Benoit Jacob Makoto Kato Vladimir Vukicevic @@ -40,3 +41,5 @@ Jim Hauxwell ddefrostt timeless Yore Apex +Mark Callow + diff --git a/gfx/angle/DEPS b/gfx/angle/DEPS index 072737b6667..b50d4e3aa59 100644 --- a/gfx/angle/DEPS +++ b/gfx/angle/DEPS @@ -1,6 +1,6 @@ deps = { "trunk/third_party/gyp": - "http://gyp.googlecode.com/svn/trunk@800", + "http://gyp.googlecode.com/svn/trunk@1080", } hooks = [ diff --git a/gfx/angle/README.mozilla b/gfx/angle/README.mozilla index 0c9856a20fb..b588b7ef3b8 100644 --- a/gfx/angle/README.mozilla +++ b/gfx/angle/README.mozilla @@ -1,17 +1,14 @@ This is the ANGLE project, from http://code.google.com/p/angleproject/ -Current revision: r774 +Current revision: r802 == Applied local patches == In this order: - angle-nspr-misc.patch - don't bother with ANGLE_OS detection with NSPR - angle-renaming.patch - rename debug.h to compilerdebug.h to avoid conflict in our makefiles - angle-instrinsic-msvc2005.patch - work around a MSVC 2005 compile error + angle-renaming-debug.patch - rename debug.h to compilerdebug.h to avoid conflict in our makefiles + angle-intrinsic-msvc2005.patch - work around a MSVC 2005 compile error angle-limit-identifiers-to-250-chars.patch - see bug 675625 angle-use-xmalloc.patch - see bug 680840. Can drop this patch whenever the new preprocessor lands. - angle-mCurrentValueOffsets-size_t.patch - ANGLE bug 220 - compile fix on win64 - angle-pool_allocator-assignable.patch - ANGLE r798 In addition to these patches, the Makefile.in files are ours, they're not present in upsteam ANGLE. diff --git a/gfx/angle/angle-instrinsic-msvc2005.patch b/gfx/angle/angle-intrinsic-msvc2005.patch similarity index 100% rename from gfx/angle/angle-instrinsic-msvc2005.patch rename to gfx/angle/angle-intrinsic-msvc2005.patch diff --git a/gfx/angle/angle-nspr-misc.patch b/gfx/angle/angle-nspr-misc.patch deleted file mode 100644 index c7412df00be..00000000000 --- a/gfx/angle/angle-nspr-misc.patch +++ /dev/null @@ -1,2 +0,0 @@ -# HG changeset patch -# Parent 6a9ec71ad85de76c551a5398b1427d9f76430b1f diff --git a/gfx/angle/angle-use-xmalloc.patch b/gfx/angle/angle-use-xmalloc.patch index 2a09fef7f79..f70cf4cfb00 100644 --- a/gfx/angle/angle-use-xmalloc.patch +++ b/gfx/angle/angle-use-xmalloc.patch @@ -1,17 +1,18 @@ # HG changeset patch -# Parent 74f1894d664435118be4fdefd53cabfdaa9985bc +# Parent fecc64a6df53a9056b21958affad38c80ca38496 + diff --git a/gfx/angle/Makefile.in b/gfx/angle/Makefile.in --- a/gfx/angle/Makefile.in +++ b/gfx/angle/Makefile.in -@@ -123,16 +123,18 @@ CSRCS = \ - memory.c \ - scanner.c \ - symbols.c \ - tokens.c \ +@@ -127,16 +127,18 @@ CSRCS = \ $(NULL) DEFINES += -DANGLE_USE_NSPR -DANGLE_BUILD + #these defines are from ANGLE's build_angle.gyp + DEFINES += -DANGLE_DISABLE_TRACE + DEFINES += -DANGLE_COMPILE_OPTIMIZATION_LEVEL=D3DCOMPILE_OPTIMIZATION_LEVEL0 + +EXTRA_DSO_LDOPTS = $(MOZALLOC_LIB) + ifdef MOZ_ANGLE @@ -25,14 +26,14 @@ diff --git a/gfx/angle/Makefile.in b/gfx/angle/Makefile.in diff --git a/gfx/angle/README.mozilla b/gfx/angle/README.mozilla --- a/gfx/angle/README.mozilla +++ b/gfx/angle/README.mozilla -@@ -4,16 +4,17 @@ Current revision: r740 +@@ -3,16 +3,17 @@ This is the ANGLE project, from http://c + Current revision: r774 == Applied local patches == In this order: - angle-nspr-misc.patch - don't bother with ANGLE_OS detection with NSPR angle-renaming.patch - rename debug.h to compilerdebug.h to avoid conflict in our makefiles - angle-intrinsic-msvc2005.patch - work around a MSVC 2005 compile error + angle-instrinsic-msvc2005.patch - work around a MSVC 2005 compile error angle-limit-identifiers-to-250-chars.patch - see bug 675625 + angle-use-xmalloc.patch - see bug 680840. Can drop this patch whenever the new preprocessor lands. @@ -118,7 +119,7 @@ diff --git a/gfx/angle/src/compiler/preprocessor/atom.c b/gfx/angle/src/compiler diff --git a/gfx/angle/src/libEGL/Makefile.in b/gfx/angle/src/libEGL/Makefile.in --- a/gfx/angle/src/libEGL/Makefile.in +++ b/gfx/angle/src/libEGL/Makefile.in -@@ -150,8 +150,10 @@ RCFILE = $(srcdir)/libEGL.rc +@@ -153,8 +153,10 @@ RCFILE = $(srcdir)/libEGL.rc include $(topsrcdir)/config/rules.mk EXTRA_DSO_LDOPTS = "$(MOZ_DIRECTX_SDK_PATH)/lib/$(MOZ_DIRECTX_SDK_CPU_SUFFIX)/d3d9.lib" \ @@ -132,7 +133,7 @@ diff --git a/gfx/angle/src/libEGL/Makefile.in b/gfx/angle/src/libEGL/Makefile.in diff --git a/gfx/angle/src/libGLESv2/Makefile.in b/gfx/angle/src/libGLESv2/Makefile.in --- a/gfx/angle/src/libGLESv2/Makefile.in +++ b/gfx/angle/src/libGLESv2/Makefile.in -@@ -159,8 +159,10 @@ CPPSRCS += \ +@@ -162,8 +162,10 @@ CPPSRCS += \ DEFFILE = $(srcdir)/libGLESv2.def RCFILE = $(srcdir)/libGLESv2.rc diff --git a/gfx/angle/build/common.gypi b/gfx/angle/build/common.gypi index 8682410ebb2..65125e228d3 100644 --- a/gfx/angle/build/common.gypi +++ b/gfx/angle/build/common.gypi @@ -4,7 +4,7 @@ { 'variables': { - 'library%': 'shared_library', + 'component%': 'static_library', }, 'target_defaults': { 'default_configuration': 'Debug', @@ -81,6 +81,11 @@ }, }, # Release }, # configurations + 'conditions': [ + ['component=="shared_library"', { + 'defines': ['COMPONENT_BUILD'], + }], + ], }, # target_defaults 'conditions': [ ['OS=="win"', { diff --git a/gfx/angle/extensions/ANGLE_translated_shader_source.txt b/gfx/angle/extensions/ANGLE_translated_shader_source.txt new file mode 100644 index 00000000000..a5234ebe961 --- /dev/null +++ b/gfx/angle/extensions/ANGLE_translated_shader_source.txt @@ -0,0 +1,118 @@ +Name + + ANGLE_translated_shader_source + +Name Strings + + GL_ANGLE_translated_shader_source + +Contributors + + Daniel Koch, TransGaming Inc. + Gregg Tavares, Google Inc. + Kenneth Russell, Google Inc. + Zhenyao Mo, Google Inc. + +Contact + + Zhenyao Mo, Google Inc. (zmo 'at' google 'dot' com) + +Status + + Implemented in ANGLE ES2 + +Version + + Last Modified Date: October 5, 2011 + Author Revision: 2 + +Number + + OpenGL ES Extension #?? + +Dependencies + + OpenGL ES 2.0 is required. + + The extension is written against the OpenGL ES 2.0 specification. + +Overview + + WebGL uses the GLSL ES 2.0 spec on all platforms, and translates these + shaders to the host platform's native language (HLSL, GLSL, and even GLSL + ES). For debugging purposes, it is useful to be able to examine the shader + after translation. + + This extension addes a new function to query the translated shader source, + and adds a new enum for GetShaderiv's parameter to query the + translated shader source length. + +IP Status + + No known IP claims. + +New Types + + None + +New Procedures and Functions + + void GetTranslatedShaderSourceANGLE(uint shader, sizei bufsize, + sizei* length, char* source); + +New Tokens + + Accepted by the parameter of GetShaderiv: + + TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0 + +Additions to Chapter 6 of the OpenGL ES 2.0 Specification (State and State +Requests) + + Append in the end of the fourth paragraph of section 6.1.8 (Shader and + Program Queries): + + " If is TRANSLATED_SHADER_LENGTH_ANGLE, the length of the translated + source string, including a null terminator, is returned. If no source has + been defined, CompileShader has not been called, or the translation has + failed for , zero is returned." + + Append after the last paragraph of section 6.1.8 (Shader and Program + Queries): + + "The command + + void GetTranslatedShaderSourceANGLE( uint shader, sizei bufSize, + sizei *length, char *source ); + + returns in the string making up the translated source code for + the shader object . The string will be null terminated. + The actual number of characters written into , excluding the null + terminator, is returned in . If is NULL, no length is + returned. The maximum number of characters that may be written into + , including the null terminator, is speciļ¬ed by . The + string is the translated string of a concatenation of the strings + passed to the GL using ShaderSource. The length of this translated string + is given by TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, which can be queried + with GetShaderiv. + + If no source has been defined, CompileShader has not been called, or the + translation has failed for , zero is returned for , and + an empty string is returned for . + + If the value of SHADER_COMPILER is not TRUE, then the error INVALID_- + OPERATION is generated." + +Issues + + 1) What enum value should be used for TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE? + + RESOLVED: The first draft used a temporary enum value. This been replaced + with a enum allocated from the ANGLE range of GL enums. + +Revision History + + Revision 1, 2011/09/29, zmo + - first draft + Revision 2, 2011/10/05, dgkoch + - assigned enum diff --git a/gfx/angle/extensions/EGL_ANGLE_software_display.txt b/gfx/angle/extensions/EGL_ANGLE_software_display.txt index c584817fc7c..556e1bee505 100644 --- a/gfx/angle/extensions/EGL_ANGLE_software_display.txt +++ b/gfx/angle/extensions/EGL_ANGLE_software_display.txt @@ -21,7 +21,7 @@ Status Version - Version 1, July 12, 2011 + Version 2, October 19, 2011 Number @@ -46,7 +46,7 @@ New Procedures and Functions New Tokens - None + EGL_SOFTWARE_DISPLAY_ANGLE (EGLNativeDisplayType)-1 Additions to Chapter 3 of the EGL 1.4 Specification (EGL Functions and Errors) @@ -61,3 +61,5 @@ Issues Revision History Version 1, 2011/07/12 - first draft. + Version 2, 2011/10/18 - add token definition + diff --git a/gfx/angle/include/GLES2/gl2ext.h b/gfx/angle/include/GLES2/gl2ext.h index 9371ad7d8f8..b95a58df101 100644 --- a/gfx/angle/include/GLES2/gl2ext.h +++ b/gfx/angle/include/GLES2/gl2ext.h @@ -217,6 +217,11 @@ typedef void* GLeglImageOES; #define GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE 0x83F3 #endif +/* GL_ANGLE_translated_shader_source */ +#ifndef GL_ANGLE_translated_shader_source +#define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0 +#endif + /*------------------------------------------------------------------------* * APPLE extension tokens *------------------------------------------------------------------------*/ @@ -810,6 +815,15 @@ typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEANGLEPROC) (GLenum #define GL_ANGLE_texture_compression_dxt5 1 #endif +/* GL_ANGLE_translated_shader_source */ +#ifndef GL_ANGLE_translated_shader_source +#define GL_ANGLE_translated_shader_source 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetTranslatedShaderSourceANGLE (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source); +#endif +typedef void (GL_APIENTRYP PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC) (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source); +#endif + /*------------------------------------------------------------------------* * APPLE extension functions *------------------------------------------------------------------------*/ diff --git a/gfx/angle/include/GLSLANG/ShaderLang.h b/gfx/angle/include/GLSLANG/ShaderLang.h index 91af12af7e8..bbe3a126fb6 100644 --- a/gfx/angle/include/GLSLANG/ShaderLang.h +++ b/gfx/angle/include/GLSLANG/ShaderLang.h @@ -6,6 +6,23 @@ #ifndef _COMPILER_INTERFACE_INCLUDED_ #define _COMPILER_INTERFACE_INCLUDED_ +#if defined(COMPONENT_BUILD) +#if defined(_WIN32) || defined(_WIN64) + +#if defined(COMPILER_IMPLEMENTATION) +#define COMPILER_EXPORT __declspec(dllexport) +#else +#define COMPILER_EXPORT __declspec(dllimport) +#endif // defined(COMPILER_IMPLEMENTATION) + +#else // defined(WIN32) +#define COMPILER_EXPORT __attribute__((visibility("default"))) +#endif + +#else // defined(COMPONENT_BUILD) +#define COMPILER_EXPORT +#endif + // // This is the platform independent interface between an OGL driver // and the shading language compiler. @@ -93,12 +110,12 @@ typedef enum { // compiler operations. // If the function succeeds, the return value is nonzero, else zero. // -int ShInitialize(); +COMPILER_EXPORT int ShInitialize(); // // Driver should call this at shutdown. // If the function succeeds, the return value is nonzero, else zero. // -int ShFinalize(); +COMPILER_EXPORT int ShFinalize(); // // Implementation dependent built-in resources (constants and extensions). @@ -125,7 +142,7 @@ typedef struct // // Initialize built-in resources with minimum expected values. // -void ShInitBuiltInResources(ShBuiltInResources* resources); +COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources); // // ShHandle held by but opaque to the driver. It is allocated, @@ -148,10 +165,12 @@ typedef void* ShHandle; // output: Specifies the output code type - SH_ESSL_OUTPUT, SH_GLSL_OUTPUT, // or SH_HLSL_OUTPUT. // resources: Specifies the built-in resources. -ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec, - ShShaderOutput output, - const ShBuiltInResources* resources); -void ShDestruct(ShHandle handle); +COMPILER_EXPORT ShHandle ShConstructCompiler( + ShShaderType type, + ShShaderSpec spec, + ShShaderOutput output, + const ShBuiltInResources* resources); +COMPILER_EXPORT void ShDestruct(ShHandle handle); // // Compiles the given shader source. @@ -178,7 +197,7 @@ void ShDestruct(ShHandle handle); // Can be queried by calling ShGetActiveAttrib() and // ShGetActiveUniform(). // -int ShCompile( +COMPILER_EXPORT int ShCompile( const ShHandle handle, const char* const shaderStrings[], const int numStrings, @@ -206,7 +225,9 @@ int ShCompile( // the null termination character. // // params: Requested parameter -void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params); +COMPILER_EXPORT void ShGetInfo(const ShHandle handle, + ShShaderInfo pname, + int* params); // Returns nul-terminated information log for a compiled shader. // Parameters: @@ -216,7 +237,7 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params); // to accomodate the information log. The size of the buffer required // to store the returned information log can be obtained by calling // ShGetInfo with SH_INFO_LOG_LENGTH. -void ShGetInfoLog(const ShHandle handle, char* infoLog); +COMPILER_EXPORT void ShGetInfoLog(const ShHandle handle, char* infoLog); // Returns null-terminated object code for a compiled shader. // Parameters: @@ -226,7 +247,7 @@ void ShGetInfoLog(const ShHandle handle, char* infoLog); // accomodate the object code. The size of the buffer required to // store the returned object code can be obtained by calling // ShGetInfo with SH_OBJECT_CODE_LENGTH. -void ShGetObjectCode(const ShHandle handle, char* objCode); +COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode); // Returns information about an active attribute variable. // Parameters: @@ -247,13 +268,13 @@ void ShGetObjectCode(const ShHandle handle, char* objCode); // memory (SH_MAPPED_NAME_MAX_LENGTH), or NULL if don't care // about the mapped name. If the name is not mapped, then name and // mappedName are the same. -void ShGetActiveAttrib(const ShHandle handle, - int index, - int* length, - int* size, - ShDataType* type, - char* name, - char* mappedName); +COMPILER_EXPORT void ShGetActiveAttrib(const ShHandle handle, + int index, + int* length, + int* size, + ShDataType* type, + char* name, + char* mappedName); // Returns information about an active uniform variable. // Parameters: @@ -274,13 +295,13 @@ void ShGetActiveAttrib(const ShHandle handle, // memory (SH_MAPPED_NAME_MAX_LENGTH), or NULL if don't care // about the mapped name. If the name is not mapped, then name and // mappedName are the same. -void ShGetActiveUniform(const ShHandle handle, - int index, - int* length, - int* size, - ShDataType* type, - char* name, - char* mappedName); +COMPILER_EXPORT void ShGetActiveUniform(const ShHandle handle, + int index, + int* length, + int* size, + ShDataType* type, + char* name, + char* mappedName); #ifdef __cplusplus } diff --git a/gfx/angle/samples/build_samples.gyp b/gfx/angle/samples/build_samples.gyp index 313b7451043..7cbb90701a1 100644 --- a/gfx/angle/samples/build_samples.gyp +++ b/gfx/angle/samples/build_samples.gyp @@ -25,10 +25,18 @@ ], 'include_dirs': [ '../include', + '../src', ], 'sources': [ 'translator/translator.cpp', + '../src/common/debug.cpp', ], + 'msvs_settings': { + 'VCLinkerTool': { + 'AdditionalLibraryDirectories': ['$(DXSDK_DIR)/lib/x86'], + 'AdditionalDependencies': ['d3d9.lib'], + } + } }, ], 'conditions': [ diff --git a/gfx/angle/samples/translator/translator.cpp b/gfx/angle/samples/translator/translator.cpp index a4bf6c2b129..421316fe1b7 100644 --- a/gfx/angle/samples/translator/translator.cpp +++ b/gfx/angle/samples/translator/translator.cpp @@ -149,12 +149,12 @@ int main(int argc, char* argv[]) } if (compiled && (compileOptions & SH_ATTRIBUTES_UNIFORMS)) { LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE ATTRIBS"); - PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES, compileOptions & SH_MAP_LONG_VARIABLE_NAMES); + PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES, (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) != 0); LogMsg("END", "COMPILER", numCompiles, "ACTIVE ATTRIBS"); printf("\n\n"); LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE UNIFORMS"); - PrintActiveVariables(compiler, SH_ACTIVE_UNIFORMS, compileOptions & SH_MAP_LONG_VARIABLE_NAMES); + PrintActiveVariables(compiler, SH_ACTIVE_UNIFORMS, (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) != 0); LogMsg("END", "COMPILER", numCompiles, "ACTIVE UNIFORMS"); printf("\n\n"); } diff --git a/gfx/angle/src/common/debug.cpp b/gfx/angle/src/common/debug.cpp index 4dd7327e796..9fd95c1e656 100644 --- a/gfx/angle/src/common/debug.cpp +++ b/gfx/angle/src/common/debug.cpp @@ -63,7 +63,11 @@ void trace(bool traceFileDebugOnly, const char *format, ...) { va_list vararg; va_start(vararg, format); +#if defined(ANGLE_DISABLE_PERF) + output(traceFileDebugOnly, NULL, format, vararg); +#else output(traceFileDebugOnly, D3DPERF_SetMarker, format, vararg); +#endif va_end(vararg); } @@ -79,10 +83,12 @@ bool perfActive() ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...) { +#if !defined(ANGLE_DISABLE_PERF) va_list vararg; va_start(vararg, format); output(true, reinterpret_cast(D3DPERF_BeginEvent), format, vararg); va_end(vararg); +#endif } ScopedPerfEventHelper::~ScopedPerfEventHelper() diff --git a/gfx/angle/src/common/version.h b/gfx/angle/src/common/version.h index 2827ea22e1d..90abab28696 100644 --- a/gfx/angle/src/common/version.h +++ b/gfx/angle/src/common/version.h @@ -1,7 +1,7 @@ #define MAJOR_VERSION 0 #define MINOR_VERSION 0 #define BUILD_VERSION 0 -#define BUILD_REVISION 774 +#define BUILD_REVISION 802 #define STRINGIFY(x) #x #define MACRO_STRINGIFY(x) STRINGIFY(x) diff --git a/gfx/angle/src/compiler/OutputHLSL.cpp b/gfx/angle/src/compiler/OutputHLSL.cpp index 8e804d6ce3c..231728b7a51 100644 --- a/gfx/angle/src/compiler/OutputHLSL.cpp +++ b/gfx/angle/src/compiler/OutputHLSL.cpp @@ -1503,7 +1503,7 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node) if (node->usesTernaryOperator()) { - out << "t" << mUnfoldSelect->getTemporaryIndex(); + out << "s" << mUnfoldSelect->getNextTemporaryIndex(); } else // if/else statement { @@ -1567,21 +1567,6 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node) } else { - if (node->getInit()) - { - mUnfoldSelect->traverse(node->getInit()); - } - - if (node->getCondition()) - { - mUnfoldSelect->traverse(node->getCondition()); - } - - if (node->getExpression()) - { - mUnfoldSelect->traverse(node->getExpression()); - } - out << "for("; if (node->getInit()) diff --git a/gfx/angle/src/compiler/UnfoldSelect.cpp b/gfx/angle/src/compiler/UnfoldSelect.cpp index a36c3931ec0..d3985e68b9f 100644 --- a/gfx/angle/src/compiler/UnfoldSelect.cpp +++ b/gfx/angle/src/compiler/UnfoldSelect.cpp @@ -20,8 +20,9 @@ UnfoldSelect::UnfoldSelect(TParseContext &context, OutputHLSL *outputHLSL) : mCo void UnfoldSelect::traverse(TIntermNode *node) { - mTemporaryIndex++; + int rewindIndex = mTemporaryIndex; node->traverse(this); + mTemporaryIndex = rewindIndex; } bool UnfoldSelect::visitSelection(Visit visit, TIntermSelection *node) @@ -30,36 +31,66 @@ bool UnfoldSelect::visitSelection(Visit visit, TIntermSelection *node) if (node->usesTernaryOperator()) { - int i = mTemporaryIndex++; + int i = mTemporaryIndex; - out << mOutputHLSL->typeString(node->getType()) << " t" << i << ";\n"; + out << mOutputHLSL->typeString(node->getType()) << " s" << i << ";\n"; + mTemporaryIndex = i + 1; node->getCondition()->traverse(this); out << "if("; + mTemporaryIndex = i + 1; node->getCondition()->traverse(mOutputHLSL); out << ")\n" "{\n"; + mTemporaryIndex = i + 1; node->getTrueBlock()->traverse(this); - out << " t" << i << " = "; + out << " s" << i << " = "; + mTemporaryIndex = i + 1; node->getTrueBlock()->traverse(mOutputHLSL); out << ";\n" "}\n" "else\n" "{\n"; + mTemporaryIndex = i + 1; node->getFalseBlock()->traverse(this); - out << " t" << i << " = "; + out << " s" << i << " = "; + mTemporaryIndex = i + 1; node->getFalseBlock()->traverse(mOutputHLSL); out << ";\n" "}\n"; - mTemporaryIndex--; + mTemporaryIndex = i + 1; } return false; } -int UnfoldSelect::getTemporaryIndex() +bool UnfoldSelect::visitLoop(Visit visit, TIntermLoop *node) { - return mTemporaryIndex; + int rewindIndex = mTemporaryIndex; + + if (node->getInit()) + { + node->getInit()->traverse(this); + } + + if (node->getCondition()) + { + node->getCondition()->traverse(this); + } + + if (node->getExpression()) + { + node->getExpression()->traverse(this); + } + + mTemporaryIndex = rewindIndex; + + return false; +} + +int UnfoldSelect::getNextTemporaryIndex() +{ + return mTemporaryIndex++; } } diff --git a/gfx/angle/src/compiler/UnfoldSelect.h b/gfx/angle/src/compiler/UnfoldSelect.h index de296e4428d..4a3ba5f86ed 100644 --- a/gfx/angle/src/compiler/UnfoldSelect.h +++ b/gfx/angle/src/compiler/UnfoldSelect.h @@ -23,8 +23,9 @@ class UnfoldSelect : public TIntermTraverser void traverse(TIntermNode *node); bool visitSelection(Visit visit, TIntermSelection *node); + bool visitLoop(Visit visit, TIntermLoop *node); - int getTemporaryIndex(); + int getNextTemporaryIndex(); protected: TParseContext &mContext; diff --git a/gfx/angle/src/compiler/intermOut.cpp b/gfx/angle/src/compiler/intermOut.cpp index 798a69af7eb..e83c7b72f2a 100644 --- a/gfx/angle/src/compiler/intermOut.cpp +++ b/gfx/angle/src/compiler/intermOut.cpp @@ -261,6 +261,8 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate* node) case EOpRefract: out << "refract"; break; case EOpMul: out << "component-wise multiply"; break; + case EOpDeclaration: out << "Declaration: "; break; + default: out.message(EPrefixError, "Bad aggregation op"); } diff --git a/gfx/angle/src/libGLESv2/Context.cpp b/gfx/angle/src/libGLESv2/Context.cpp index e5e05d58254..77d0e91e8b3 100644 --- a/gfx/angle/src/libGLESv2/Context.cpp +++ b/gfx/angle/src/libGLESv2/Context.cpp @@ -381,6 +381,8 @@ void Context::markAllStateDirty() mSampleStateDirty = true; mDitherStateDirty = true; mFrontFaceDirty = true; + mDxUniformsDirty = true; + mCachedCurrentProgram = NULL; } void Context::setClearColor(float red, float green, float blue, float alpha) @@ -893,6 +895,7 @@ void Context::deleteShader(GLuint shader) void Context::deleteProgram(GLuint program) { mResourceManager->deleteProgram(program); + mCachedCurrentProgram = NULL; } void Context::deleteTexture(GLuint texture) @@ -973,7 +976,7 @@ Framebuffer *Context::getReadFramebuffer() Framebuffer *Context::getDrawFramebuffer() { - return getFramebuffer(mState.drawFramebuffer); + return mBoundDrawFramebuffer; } void Context::bindArrayBuffer(unsigned int buffer) @@ -1022,6 +1025,8 @@ void Context::bindDrawFramebuffer(GLuint framebuffer) } mState.drawFramebuffer = framebuffer; + + mBoundDrawFramebuffer = getFramebuffer(framebuffer); } void Context::bindRenderbuffer(GLuint renderbuffer) @@ -1040,6 +1045,8 @@ void Context::useProgram(GLuint program) { Program *newProgram = mResourceManager->getProgram(program); Program *oldProgram = mResourceManager->getProgram(priorProgram); + mCachedCurrentProgram = NULL; + mDxUniformsDirty = true; if (newProgram) { @@ -1057,6 +1064,10 @@ void Context::setFramebufferZero(Framebuffer *buffer) { delete mFramebufferMap[0]; mFramebufferMap[0] = buffer; + if (mState.drawFramebuffer == 0) + { + mBoundDrawFramebuffer = buffer; + } } void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer) @@ -1105,7 +1116,11 @@ Buffer *Context::getElementArrayBuffer() Program *Context::getCurrentProgram() { - return mResourceManager->getProgram(mState.currentProgram); + if (!mCachedCurrentProgram) + { + mCachedCurrentProgram = mResourceManager->getProgram(mState.currentProgram); + } + return mCachedCurrentProgram; } Texture2D *Context::getTexture2D() @@ -1614,19 +1629,19 @@ bool Context::applyRenderTarget(bool ignoreViewport) return error(GL_INVALID_FRAMEBUFFER_OPERATION, false); } - IDirect3DSurface9 *renderTarget = framebufferObject->getRenderTarget(); - - if (!renderTarget) - { - return false; // Context must be lost - } - + IDirect3DSurface9 *renderTarget = NULL; IDirect3DSurface9 *depthStencil = NULL; bool renderTargetChanged = false; unsigned int renderTargetSerial = framebufferObject->getRenderTargetSerial(); if (renderTargetSerial != mAppliedRenderTargetSerial) { + renderTarget = framebufferObject->getRenderTarget(); + + if (!renderTarget) + { + return false; // Context must be lost + } device->SetRenderTarget(0, renderTarget); mAppliedRenderTargetSerial = renderTargetSerial; mScissorStateDirty = true; // Scissor area must be clamped to render target's size-- this is different for different render targets. @@ -1670,6 +1685,15 @@ bool Context::applyRenderTarget(bool ignoreViewport) if (!mRenderTargetDescInitialized || renderTargetChanged) { + if (!renderTarget) + { + renderTarget = framebufferObject->getRenderTarget(); + + if (!renderTarget) + { + return false; // Context must be lost + } + } renderTarget->GetDesc(&mRenderTargetDesc); mRenderTargetDescInitialized = true; } @@ -1709,6 +1733,7 @@ bool Context::applyRenderTarget(bool ignoreViewport) device->SetViewport(&viewport); mSetViewport = viewport; mViewportInitialized = true; + mDxUniformsDirty = true; } if (mScissorStateDirty) @@ -1731,7 +1756,7 @@ bool Context::applyRenderTarget(bool ignoreViewport) mScissorStateDirty = false; } - if (mState.currentProgram) + if (mState.currentProgram && mDxUniformsDirty) { Program *programObject = getCurrentProgram(); @@ -1752,6 +1777,7 @@ bool Context::applyRenderTarget(bool ignoreViewport) GLint depthRange = programObject->getDxDepthRangeLocation(); GLfloat nearFarDiff[3] = {zNear, zFar, zFar - zNear}; programObject->setUniform3fv(depthRange, 1, nearFarDiff); + mDxUniformsDirty = false; } return true; @@ -2089,12 +2115,14 @@ void Context::applyTextures(SamplerType type) Program *programObject = getCurrentProgram(); int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; // Range of Direct3D 9 samplers of given sampler type + unsigned int *appliedTextureSerial = (type == SAMPLER_PIXEL) ? mAppliedTextureSerialPS : mAppliedTextureSerialVS; + int d3dSamplerOffset = (type == SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0; + int samplerRange = programObject->getUsedSamplerRange(type); - for (int samplerIndex = 0; samplerIndex < samplerCount; samplerIndex++) + for (int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++) { int textureUnit = programObject->getSamplerMapping(type, samplerIndex); // OpenGL texture image unit index - int d3dSampler = (type == SAMPLER_PIXEL) ? samplerIndex : D3DVERTEXTEXTURESAMPLER0 + samplerIndex; - unsigned int *appliedTextureSerial = (type == SAMPLER_PIXEL) ? mAppliedTextureSerialPS : mAppliedTextureSerialVS; + int d3dSampler = samplerIndex + d3dSamplerOffset; if (textureUnit != -1) { @@ -2148,6 +2176,15 @@ void Context::applyTextures(SamplerType type) } } } + + for (int samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++) + { + if (appliedTextureSerial[samplerIndex] != 0) + { + device->SetTexture(samplerIndex + d3dSamplerOffset, NULL); + appliedTextureSerial[samplerIndex] = 0; + } + } } void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels) @@ -3434,6 +3471,7 @@ void Context::initExtensionString() { mExtensionString += "GL_ANGLE_texture_compression_dxt5 "; } + mExtensionString += "GL_ANGLE_translated_shader_source "; // Other vendor-specific extensions if (supportsEventQueries()) diff --git a/gfx/angle/src/libGLESv2/Context.h b/gfx/angle/src/libGLESv2/Context.h index 583c52437f5..6e99762ae74 100644 --- a/gfx/angle/src/libGLESv2/Context.h +++ b/gfx/angle/src/libGLESv2/Context.h @@ -544,6 +544,9 @@ class Context D3DVIEWPORT9 mSetViewport; bool mRenderTargetDescInitialized; D3DSURFACE_DESC mRenderTargetDesc; + bool mDxUniformsDirty; + Program *mCachedCurrentProgram; + Framebuffer *mBoundDrawFramebuffer; bool mSupportsShaderModel3; bool mSupportsVertexTexture; diff --git a/gfx/angle/src/libGLESv2/Framebuffer.cpp b/gfx/angle/src/libGLESv2/Framebuffer.cpp index 0f7ec20f880..3858e2694f0 100644 --- a/gfx/angle/src/libGLESv2/Framebuffer.cpp +++ b/gfx/angle/src/libGLESv2/Framebuffer.cpp @@ -58,19 +58,19 @@ Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle) const void Framebuffer::setColorbuffer(GLenum type, GLuint colorbuffer) { - mColorbufferType = type; + mColorbufferType = (colorbuffer != 0) ? type : GL_NONE; mColorbufferPointer.set(lookupRenderbuffer(type, colorbuffer)); } void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer) { - mDepthbufferType = type; + mDepthbufferType = (depthbuffer != 0) ? type : GL_NONE; mDepthbufferPointer.set(lookupRenderbuffer(type, depthbuffer)); } void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer) { - mStencilbufferType = type; + mStencilbufferType = (stencilbuffer != 0) ? type : GL_NONE; mStencilbufferPointer.set(lookupRenderbuffer(type, stencilbuffer)); } diff --git a/gfx/angle/src/libGLESv2/Program.cpp b/gfx/angle/src/libGLESv2/Program.cpp index fd79e46689f..e5ffd25785f 100644 --- a/gfx/angle/src/libGLESv2/Program.cpp +++ b/gfx/angle/src/libGLESv2/Program.cpp @@ -40,7 +40,6 @@ Uniform::Uniform(GLenum type, const std::string &_name, unsigned int arraySize) data = new unsigned char[bytes]; memset(data, 0, bytes); dirty = true; - handlesSet = false; } Uniform::~Uniform() @@ -144,8 +143,6 @@ bool Program::detachShader(Shader *shader) } else UNREACHABLE(); - unlink(); - return true; } @@ -200,11 +197,26 @@ int Program::getSemanticIndex(int attributeIndex) return mSemanticIndex[attributeIndex]; } +// Returns one more than the highest sampler index used. +GLint Program::getUsedSamplerRange(SamplerType type) +{ + switch (type) + { + case SAMPLER_PIXEL: + return mUsedPixelSamplerRange; + case SAMPLER_VERTEX: + return mUsedVertexSamplerRange; + default: + UNREACHABLE(); + return 0; + } +} + // Returns the index of the texture image unit (0-19) corresponding to a Direct3D 9 sampler // index (0-15 for the pixel shader and 0-3 for the vertex shader). GLint Program::getSamplerMapping(SamplerType type, unsigned int samplerIndex) { - GLuint logicalTextureUnit = -1; + GLint logicalTextureUnit = -1; switch (type) { @@ -227,7 +239,7 @@ GLint Program::getSamplerMapping(SamplerType type, unsigned int samplerIndex) default: UNREACHABLE(); } - if (logicalTextureUnit >= 0 && logicalTextureUnit < getContext()->getMaximumCombinedTextureImageUnits()) + if (logicalTextureUnit >= 0 && logicalTextureUnit < (GLint)getContext()->getMaximumCombinedTextureImageUnits()) { return logicalTextureUnit; } @@ -300,8 +312,17 @@ bool Program::setUniform1fv(GLint location, GLsizei count, const GLfloat* v) count = std::min(arraySize - (int)mUniformIndex[location].element, count); - memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat), - v, sizeof(GLfloat) * count); + GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4; + + for (int i = 0; i < count; i++) + { + target[0] = v[0]; + target[1] = 0; + target[2] = 0; + target[3] = 0; + target += 4; + v += 1; + } } else if (targetUniform->type == GL_BOOL) { @@ -357,8 +378,17 @@ bool Program::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) count = std::min(arraySize - (int)mUniformIndex[location].element, count); - memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * 2, - v, 2 * sizeof(GLfloat) * count); + GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4; + + for (int i = 0; i < count; i++) + { + target[0] = v[0]; + target[1] = v[1]; + target[2] = 0; + target[3] = 0; + target += 4; + v += 2; + } } else if (targetUniform->type == GL_BOOL_VEC2) { @@ -415,8 +445,17 @@ bool Program::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) count = std::min(arraySize - (int)mUniformIndex[location].element, count); - memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * 3, - v, 3 * sizeof(GLfloat) * count); + GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4; + + for (int i = 0; i < count; i++) + { + target[0] = v[0]; + target[1] = v[1]; + target[2] = v[2]; + target[3] = 0; + target += 4; + v += 3; + } } else if (targetUniform->type == GL_BOOL_VEC3) { @@ -510,6 +549,37 @@ bool Program::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) return true; } +template +void transposeMatrix(T *target, const GLfloat *value) +{ + int copyWidth = std::min(targetWidth, srcWidth); + int copyHeight = std::min(targetHeight, srcHeight); + + for (int x = 0; x < copyWidth; x++) + { + for (int y = 0; y < copyHeight; y++) + { + target[x * targetWidth + y] = value[y * srcWidth + x]; + } + } + // clear unfilled right side + for (int y = 0; y < copyHeight; y++) + { + for (int x = srcWidth; x < targetWidth; x++) + { + target[y * targetWidth + x] = 0; + } + } + // clear unfilled bottom. + for (int y = srcHeight; y < targetHeight; y++) + { + for (int x = 0; x < targetWidth; x++) + { + target[y * targetWidth + x] = 0; + } + } +} + bool Program::setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value) { if (location < 0 || location >= (int)mUniformIndex.size()) @@ -532,8 +602,13 @@ bool Program::setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat * count = std::min(arraySize - (int)mUniformIndex[location].element, count); - memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * 4, - value, 4 * sizeof(GLfloat) * count); + GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 8; + for (int i = 0; i < count; i++) + { + transposeMatrix(target, value); + target += 8; + value += 4; + } return true; } @@ -560,12 +635,18 @@ bool Program::setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat * count = std::min(arraySize - (int)mUniformIndex[location].element, count); - memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * 9, - value, 9 * sizeof(GLfloat) * count); + GLfloat *target = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 12; + for (int i = 0; i < count; i++) + { + transposeMatrix(target, value); + target += 12; + value += 9; + } return true; } + bool Program::setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value) { if (location < 0 || location >= (int)mUniformIndex.size()) @@ -588,8 +669,13 @@ bool Program::setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat * count = std::min(arraySize - (int)mUniformIndex[location].element, count); - memcpy(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * 16, - value, 16 * sizeof(GLfloat) * count); + GLfloat *target = (GLfloat*)(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * 16); + for (int i = 0; i < count; i++) + { + transposeMatrix(target, value); + target += 16; + value += 16; + } return true; } @@ -833,35 +919,51 @@ bool Program::getUniformfv(GLint location, GLfloat *params) Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - unsigned int count = UniformComponentCount(targetUniform->type); - - switch (UniformComponentType(targetUniform->type)) + switch (targetUniform->type) { - case GL_BOOL: + case GL_FLOAT_MAT2: + transposeMatrix(params, (GLfloat*)targetUniform->data + mUniformIndex[location].element * 8); + break; + case GL_FLOAT_MAT3: + transposeMatrix(params, (GLfloat*)targetUniform->data + mUniformIndex[location].element * 12); + break; + case GL_FLOAT_MAT4: + transposeMatrix(params, (GLfloat*)targetUniform->data + mUniformIndex[location].element * 16); + break; + default: { - GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * count; + unsigned int count = UniformComponentCount(targetUniform->type); + unsigned int internalCount = UniformInternalComponentCount(targetUniform->type); - for (unsigned int i = 0; i < count; ++i) + switch (UniformComponentType(targetUniform->type)) { - params[i] = (boolParams[i] == GL_FALSE) ? 0.0f : 1.0f; + case GL_BOOL: + { + GLboolean *boolParams = (GLboolean*)targetUniform->data + mUniformIndex[location].element * internalCount; + + for (unsigned int i = 0; i < count; ++i) + { + params[i] = (boolParams[i] == GL_FALSE) ? 0.0f : 1.0f; + } + } + break; + case GL_FLOAT: + memcpy(params, targetUniform->data + mUniformIndex[location].element * internalCount * sizeof(GLfloat), + count * sizeof(GLfloat)); + break; + case GL_INT: + { + GLint *intParams = (GLint*)targetUniform->data + mUniformIndex[location].element * internalCount; + + for (unsigned int i = 0; i < count; ++i) + { + params[i] = (float)intParams[i]; + } + } + break; + default: UNREACHABLE(); } } - break; - case GL_FLOAT: - memcpy(params, targetUniform->data + mUniformIndex[location].element * count * sizeof(GLfloat), - count * sizeof(GLfloat)); - break; - case GL_INT: - { - GLint *intParams = (GLint*)targetUniform->data + mUniformIndex[location].element * count; - - for (unsigned int i = 0; i < count; ++i) - { - params[i] = (float)intParams[i]; - } - } - break; - default: UNREACHABLE(); } return true; @@ -876,35 +978,57 @@ bool Program::getUniformiv(GLint location, GLint *params) Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - unsigned int count = UniformComponentCount(targetUniform->type); - - switch (UniformComponentType(targetUniform->type)) + switch (targetUniform->type) { - case GL_BOOL: + case GL_FLOAT_MAT2: { - GLboolean *boolParams = targetUniform->data + mUniformIndex[location].element * count; - - for (unsigned int i = 0; i < count; ++i) - { - params[i] = (GLint)boolParams[i]; - } + transposeMatrix(params, (GLfloat*)targetUniform->data + mUniformIndex[location].element * 8); } break; - case GL_FLOAT: + case GL_FLOAT_MAT3: { - GLfloat *floatParams = (GLfloat*)targetUniform->data + mUniformIndex[location].element * count; - - for (unsigned int i = 0; i < count; ++i) - { - params[i] = (GLint)floatParams[i]; - } + transposeMatrix(params, (GLfloat*)targetUniform->data + mUniformIndex[location].element * 12); } break; - case GL_INT: - memcpy(params, targetUniform->data + mUniformIndex[location].element * count * sizeof(GLint), - count * sizeof(GLint)); + case GL_FLOAT_MAT4: + { + transposeMatrix(params, (GLfloat*)targetUniform->data + mUniformIndex[location].element * 16); + } break; - default: UNREACHABLE(); + default: + { + unsigned int count = UniformComponentCount(targetUniform->type); + unsigned int internalCount = UniformInternalComponentCount(targetUniform->type); + + switch (UniformComponentType(targetUniform->type)) + { + case GL_BOOL: + { + GLboolean *boolParams = targetUniform->data + mUniformIndex[location].element * internalCount; + + for (unsigned int i = 0; i < count; ++i) + { + params[i] = (GLint)boolParams[i]; + } + } + break; + case GL_FLOAT: + { + GLfloat *floatParams = (GLfloat*)targetUniform->data + mUniformIndex[location].element * internalCount; + + for (unsigned int i = 0; i < count; ++i) + { + params[i] = (GLint)floatParams[i]; + } + } + break; + case GL_INT: + memcpy(params, targetUniform->data + mUniformIndex[location].element * internalCount * sizeof(GLint), + count * sizeof(GLint)); + break; + default: UNREACHABLE(); + } + } } return true; @@ -922,15 +1046,8 @@ void Program::dirtyAllUniforms() // Applies all the uniforms set for this program object to the Direct3D 9 device void Program::applyUniforms() { - unsigned int numUniforms = mUniformIndex.size(); - for (unsigned int location = 0; location < numUniforms; location++) - { - if (mUniformIndex[location].element != 0) - { - continue; - } - - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; + for (std::vector::iterator ub = mUniforms.begin(), ue = mUniforms.end(); ub != ue; ++ub) { + Uniform *targetUniform = *ub; if (targetUniform->dirty) { @@ -941,23 +1058,23 @@ void Program::applyUniforms() switch (targetUniform->type) { - case GL_BOOL: applyUniform1bv(location, arraySize, b); break; - case GL_BOOL_VEC2: applyUniform2bv(location, arraySize, b); break; - case GL_BOOL_VEC3: applyUniform3bv(location, arraySize, b); break; - case GL_BOOL_VEC4: applyUniform4bv(location, arraySize, b); break; - case GL_FLOAT: applyUniform1fv(location, arraySize, f); break; - case GL_FLOAT_VEC2: applyUniform2fv(location, arraySize, f); break; - case GL_FLOAT_VEC3: applyUniform3fv(location, arraySize, f); break; - case GL_FLOAT_VEC4: applyUniform4fv(location, arraySize, f); break; - case GL_FLOAT_MAT2: applyUniformMatrix2fv(location, arraySize, f); break; - case GL_FLOAT_MAT3: applyUniformMatrix3fv(location, arraySize, f); break; - case GL_FLOAT_MAT4: applyUniformMatrix4fv(location, arraySize, f); break; + case GL_BOOL: applyUniformnbv(targetUniform, arraySize, 1, b); break; + case GL_BOOL_VEC2: applyUniformnbv(targetUniform, arraySize, 2, b); break; + case GL_BOOL_VEC3: applyUniformnbv(targetUniform, arraySize, 3, b); break; + case GL_BOOL_VEC4: applyUniformnbv(targetUniform, arraySize, 4, b); break; + case GL_FLOAT: + case GL_FLOAT_VEC2: + case GL_FLOAT_VEC3: + case GL_FLOAT_VEC4: + case GL_FLOAT_MAT2: + case GL_FLOAT_MAT3: + case GL_FLOAT_MAT4: applyUniformnfv(targetUniform, f); break; case GL_SAMPLER_2D: case GL_SAMPLER_CUBE: - case GL_INT: applyUniform1iv(location, arraySize, i); break; - case GL_INT_VEC2: applyUniform2iv(location, arraySize, i); break; - case GL_INT_VEC3: applyUniform3iv(location, arraySize, i); break; - case GL_INT_VEC4: applyUniform4iv(location, arraySize, i); break; + case GL_INT: applyUniform1iv(targetUniform, arraySize, i); break; + case GL_INT_VEC2: applyUniform2iv(targetUniform, arraySize, i); break; + case GL_INT_VEC3: applyUniform3iv(targetUniform, arraySize, i); break; + case GL_INT_VEC4: applyUniform4iv(targetUniform, arraySize, i); break; default: UNREACHABLE(); } @@ -1726,6 +1843,7 @@ bool Program::defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT mSamplersPS[samplerIndex].active = true; mSamplersPS[samplerIndex].textureType = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? TEXTURE_CUBE : TEXTURE_2D; mSamplersPS[samplerIndex].logicalTextureUnit = 0; + mUsedPixelSamplerRange = std::max(samplerIndex + 1, mUsedPixelSamplerRange); } else { @@ -1741,6 +1859,7 @@ bool Program::defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT mSamplersVS[samplerIndex].active = true; mSamplersVS[samplerIndex].textureType = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? TEXTURE_CUBE : TEXTURE_2D; mSamplersVS[samplerIndex].logicalTextureUnit = 0; + mUsedVertexSamplerRange = std::max(samplerIndex + 1, mUsedVertexSamplerRange); } else { @@ -1816,6 +1935,9 @@ bool Program::defineUniform(const D3DXCONSTANT_DESC &constantDescription, std::s } } + initializeConstantHandles(uniform, &uniform->ps, mConstantTablePS); + initializeConstantHandles(uniform, &uniform->vs, mConstantTableVS); + mUniforms.push_back(uniform); unsigned int uniformIndex = mUniforms.size() - 1; @@ -1927,382 +2049,107 @@ std::string Program::undecorateUniform(const std::string &_name) return _name; } -bool Program::applyUniform1bv(GLint location, GLsizei count, const GLboolean *v) +void Program::applyUniformnbv(Uniform *targetUniform, GLsizei count, int width, const GLboolean *v) { - BOOL *vector = new BOOL[count]; - for (int i = 0; i < count; i++) - { - if (v[i] == GL_FALSE) - vector[i] = 0; - else - vector[i] = 1; - } - - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - if (constantPS) + float *vector = NULL; + BOOL *boolVector = NULL; + + if (targetUniform->ps.registerCount && targetUniform->ps.registerSet == D3DXRS_FLOAT4 || + targetUniform->vs.registerCount && targetUniform->vs.registerSet == D3DXRS_FLOAT4) { - mConstantTablePS->SetBoolArray(device, constantPS, vector, count); - } + vector = new float[4 * count]; - if (constantVS) - { - mConstantTableVS->SetBoolArray(device, constantVS, vector, count); - } - - delete [] vector; - - return true; -} - -bool Program::applyUniform2bv(GLint location, GLsizei count, const GLboolean *v) -{ - D3DXVECTOR4 *vector = new D3DXVECTOR4[count]; - - for (int i = 0; i < count; i++) - { - vector[i] = D3DXVECTOR4((v[0] == GL_FALSE ? 0.0f : 1.0f), - (v[1] == GL_FALSE ? 0.0f : 1.0f), 0, 0); - - v += 2; - } - - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetVectorArray(device, constantPS, vector, count); - } - - if (constantVS) - { - mConstantTableVS->SetVectorArray(device, constantVS, vector, count); - } - - delete[] vector; - - return true; -} - -bool Program::applyUniform3bv(GLint location, GLsizei count, const GLboolean *v) -{ - D3DXVECTOR4 *vector = new D3DXVECTOR4[count]; - - for (int i = 0; i < count; i++) - { - vector[i] = D3DXVECTOR4((v[0] == GL_FALSE ? 0.0f : 1.0f), - (v[1] == GL_FALSE ? 0.0f : 1.0f), - (v[2] == GL_FALSE ? 0.0f : 1.0f), 0); - - v += 3; - } - - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetVectorArray(device, constantPS, vector, count); - } - - if (constantVS) - { - mConstantTableVS->SetVectorArray(device, constantVS, vector, count); - } - - delete[] vector; - - return true; -} - -bool Program::applyUniform4bv(GLint location, GLsizei count, const GLboolean *v) -{ - D3DXVECTOR4 *vector = new D3DXVECTOR4[count]; - - for (int i = 0; i < count; i++) - { - vector[i] = D3DXVECTOR4((v[0] == GL_FALSE ? 0.0f : 1.0f), - (v[1] == GL_FALSE ? 0.0f : 1.0f), - (v[2] == GL_FALSE ? 0.0f : 1.0f), - (v[3] == GL_FALSE ? 0.0f : 1.0f)); - - v += 3; - } - - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetVectorArray(device, constantPS, vector, count); - } - - if (constantVS) - { - mConstantTableVS->SetVectorArray(device, constantVS, vector, count); - } - - delete [] vector; - - return true; -} - -bool Program::applyUniform1fv(GLint location, GLsizei count, const GLfloat *v) -{ - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetFloatArray(device, constantPS, v, count); - } - - if (constantVS) - { - mConstantTableVS->SetFloatArray(device, constantVS, v, count); - } - - return true; -} - -bool Program::applyUniform2fv(GLint location, GLsizei count, const GLfloat *v) -{ - D3DXVECTOR4 *vector = new D3DXVECTOR4[count]; - - for (int i = 0; i < count; i++) - { - vector[i] = D3DXVECTOR4(v[0], v[1], 0, 0); - - v += 2; - } - - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetVectorArray(device, constantPS, vector, count); - } - - if (constantVS) - { - mConstantTableVS->SetVectorArray(device, constantVS, vector, count); - } - - delete[] vector; - - return true; -} - -bool Program::applyUniform3fv(GLint location, GLsizei count, const GLfloat *v) -{ - D3DXVECTOR4 *vector = new D3DXVECTOR4[count]; - - for (int i = 0; i < count; i++) - { - vector[i] = D3DXVECTOR4(v[0], v[1], v[2], 0); - - v += 3; - } - - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetVectorArray(device, constantPS, vector, count); - } - - if (constantVS) - { - mConstantTableVS->SetVectorArray(device, constantVS, vector, count); - } - - delete[] vector; - - return true; -} - -bool Program::applyUniform4fv(GLint location, GLsizei count, const GLfloat *v) -{ - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetVectorArray(device, constantPS, (D3DXVECTOR4*)v, count); - } - - if (constantVS) - { - mConstantTableVS->SetVectorArray(device, constantVS, (D3DXVECTOR4*)v, count); - } - - return true; -} - -bool Program::applyUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value) -{ - D3DXMATRIX *matrix = new D3DXMATRIX[count]; - - for (int i = 0; i < count; i++) - { - matrix[i] = D3DXMATRIX(value[0], value[2], 0, 0, - value[1], value[3], 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1); - - value += 4; - } - - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetMatrixTransposeArray(device, constantPS, matrix, count); - } - - if (constantVS) - { - mConstantTableVS->SetMatrixTransposeArray(device, constantVS, matrix, count); - } - - delete[] matrix; - - return true; -} - -bool Program::applyUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value) -{ - D3DXMATRIX *matrix = new D3DXMATRIX[count]; - - for (int i = 0; i < count; i++) - { - matrix[i] = D3DXMATRIX(value[0], value[3], value[6], 0, - value[1], value[4], value[7], 0, - value[2], value[5], value[8], 0, - 0, 0, 0, 1); - - value += 9; - } - - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetMatrixTransposeArray(device, constantPS, matrix, count); - } - - if (constantVS) - { - mConstantTableVS->SetMatrixTransposeArray(device, constantVS, matrix, count); - } - - delete[] matrix; - - return true; -} - -bool Program::applyUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value) -{ - D3DXMATRIX *matrix = new D3DXMATRIX[count]; - - for (int i = 0; i < count; i++) - { - matrix[i] = D3DXMATRIX(value[0], value[4], value[8], value[12], - value[1], value[5], value[9], value[13], - value[2], value[6], value[10], value[14], - value[3], value[7], value[11], value[15]); - - value += 16; - } - - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetMatrixTransposeArray(device, constantPS, matrix, count); - } - - if (constantVS) - { - mConstantTableVS->SetMatrixTransposeArray(device, constantVS, matrix, count); - } - - delete[] matrix; - - return true; -} - -bool Program::applyUniform1iv(GLint location, GLsizei count, const GLint *v) -{ - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - D3DXCONSTANT_DESC constantDescription; - UINT descriptionCount = 1; - HRESULT result = mConstantTablePS->GetConstantDesc(constantPS, &constantDescription, &descriptionCount); - ASSERT(SUCCEEDED(result)); - - if (constantDescription.RegisterSet == D3DXRS_SAMPLER) + for (int i = 0; i < count; i++) { - unsigned int firstIndex = mConstantTablePS->GetSamplerIndex(constantPS); + for (int j = 0; j < 4; j++) + { + if (j < width) + { + vector[i * 4 + j] = (v[i * width + j] == GL_FALSE) ? 0.0f : 1.0f; + } + else + { + vector[i * 4 + j] = 0.0f; + } + } + } + } + + if (targetUniform->ps.registerCount && targetUniform->ps.registerSet == D3DXRS_BOOL || + targetUniform->vs.registerCount && targetUniform->vs.registerSet == D3DXRS_BOOL) + { + boolVector = new BOOL[count * width]; + for (int i = 0; i < count * width; i++) + { + boolVector[i] = v[i] != GL_FALSE; + } + } + + if (targetUniform->ps.registerCount) + { + if (targetUniform->ps.registerSet == D3DXRS_FLOAT4) + { + device->SetPixelShaderConstantF(targetUniform->ps.registerIndex, vector, targetUniform->ps.registerCount); + } + else if (targetUniform->ps.registerSet == D3DXRS_BOOL) + { + device->SetPixelShaderConstantB(targetUniform->ps.registerIndex, boolVector, targetUniform->ps.registerCount); + } + else UNREACHABLE(); + } + + if (targetUniform->vs.registerCount) + { + if (targetUniform->vs.registerSet == D3DXRS_FLOAT4) + { + device->SetVertexShaderConstantF(targetUniform->vs.registerIndex, vector, targetUniform->vs.registerCount); + } + else if (targetUniform->vs.registerSet == D3DXRS_BOOL) + { + device->SetVertexShaderConstantB(targetUniform->vs.registerIndex, boolVector, targetUniform->vs.registerCount); + } + else UNREACHABLE(); + } + + delete [] vector; + delete [] boolVector; +} + +bool Program::applyUniformnfv(Uniform *targetUniform, const GLfloat *v) +{ + IDirect3DDevice9 *device = getDevice(); + + if (targetUniform->ps.registerCount) + { + device->SetPixelShaderConstantF(targetUniform->ps.registerIndex, v, targetUniform->ps.registerCount); + } + + if (targetUniform->vs.registerCount) + { + device->SetVertexShaderConstantF(targetUniform->vs.registerIndex, v, targetUniform->vs.registerCount); + } + + return true; +} + +bool Program::applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint *v) +{ + D3DXVECTOR4 *vector = new D3DXVECTOR4[count]; + + for (int i = 0; i < count; i++) + { + vector[i] = D3DXVECTOR4((float)v[i], 0, 0, 0); + } + + IDirect3DDevice9 *device = getDevice(); + + if (targetUniform->ps.registerCount) + { + if (targetUniform->ps.registerSet == D3DXRS_SAMPLER) + { + unsigned int firstIndex = targetUniform->ps.registerIndex; for (int i = 0; i < count; i++) { @@ -2317,20 +2164,16 @@ bool Program::applyUniform1iv(GLint location, GLsizei count, const GLint *v) } else { - mConstantTablePS->SetIntArray(device, constantPS, v, count); + ASSERT(targetUniform->ps.registerSet == D3DXRS_FLOAT4); + device->SetPixelShaderConstantF(targetUniform->ps.registerIndex, (const float*)vector, targetUniform->ps.registerCount); } } - if (constantVS) + if (targetUniform->vs.registerCount) { - D3DXCONSTANT_DESC constantDescription; - UINT descriptionCount = 1; - HRESULT result = mConstantTableVS->GetConstantDesc(constantVS, &constantDescription, &descriptionCount); - ASSERT(SUCCEEDED(result)); - - if (constantDescription.RegisterSet == D3DXRS_SAMPLER) + if (targetUniform->vs.registerSet == D3DXRS_SAMPLER) { - unsigned int firstIndex = mConstantTableVS->GetSamplerIndex(constantVS); + unsigned int firstIndex = targetUniform->vs.registerIndex; for (int i = 0; i < count; i++) { @@ -2345,14 +2188,17 @@ bool Program::applyUniform1iv(GLint location, GLsizei count, const GLint *v) } else { - mConstantTableVS->SetIntArray(device, constantVS, v, count); + ASSERT(targetUniform->vs.registerSet == D3DXRS_FLOAT4); + device->SetVertexShaderConstantF(targetUniform->vs.registerIndex, (const float *)vector, targetUniform->vs.registerCount); } } + delete [] vector; + return true; } -bool Program::applyUniform2iv(GLint location, GLsizei count, const GLint *v) +bool Program::applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint *v) { D3DXVECTOR4 *vector = new D3DXVECTOR4[count]; @@ -2363,29 +2209,14 @@ bool Program::applyUniform2iv(GLint location, GLsizei count, const GLint *v) v += 2; } - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetVectorArray(device, constantPS, vector, count); - } - - if (constantVS) - { - mConstantTableVS->SetVectorArray(device, constantVS, vector, count); - } + applyUniformniv(targetUniform, count, vector); delete[] vector; return true; } -bool Program::applyUniform3iv(GLint location, GLsizei count, const GLint *v) +bool Program::applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint *v) { D3DXVECTOR4 *vector = new D3DXVECTOR4[count]; @@ -2396,29 +2227,14 @@ bool Program::applyUniform3iv(GLint location, GLsizei count, const GLint *v) v += 3; } - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetVectorArray(device, constantPS, vector, count); - } - - if (constantVS) - { - mConstantTableVS->SetVectorArray(device, constantVS, vector, count); - } + applyUniformniv(targetUniform, count, vector); delete[] vector; return true; } -bool Program::applyUniform4iv(GLint location, GLsizei count, const GLint *v) +bool Program::applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint *v) { D3DXVECTOR4 *vector = new D3DXVECTOR4[count]; @@ -2429,28 +2245,29 @@ bool Program::applyUniform4iv(GLint location, GLsizei count, const GLint *v) v += 4; } - Uniform *targetUniform = mUniforms[mUniformIndex[location].index]; - - D3DXHANDLE constantPS; - D3DXHANDLE constantVS; - getConstantHandles(targetUniform, &constantPS, &constantVS); - IDirect3DDevice9 *device = getDevice(); - - if (constantPS) - { - mConstantTablePS->SetVectorArray(device, constantPS, vector, count); - } - - if (constantVS) - { - mConstantTableVS->SetVectorArray(device, constantVS, vector, count); - } + applyUniformniv(targetUniform, count, vector); delete [] vector; return true; } +void Program::applyUniformniv(Uniform *targetUniform, GLsizei count, const D3DXVECTOR4 *vector) +{ + IDirect3DDevice9 *device = getDevice(); + + if (targetUniform->ps.registerCount) + { + ASSERT(targetUniform->ps.registerSet == D3DXRS_FLOAT4); + device->SetPixelShaderConstantF(targetUniform->ps.registerIndex, (const float *)vector, targetUniform->ps.registerCount); + } + + if (targetUniform->vs.registerCount) + { + ASSERT(targetUniform->vs.registerSet == D3DXRS_FLOAT4); + device->SetVertexShaderConstantF(targetUniform->vs.registerIndex, (const float *)vector, targetUniform->vs.registerCount); + } +} // append a santized message to the program info log. // The D3D compiler includes a fake file path in some of the warning or error @@ -2515,7 +2332,7 @@ void Program::resetInfoLog() } } -// Returns the program object to an unlinked state, after detaching a shader, before re-linking, or at destruction +// Returns the program object to an unlinked state, before re-linking, or at destruction void Program::unlink(bool destroy) { if (destroy) // Object being destructed @@ -2573,6 +2390,9 @@ void Program::unlink(bool destroy) mSamplersVS[index].active = false; } + mUsedVertexSamplerRange = 0; + mUsedPixelSamplerRange = 0; + while (!mUniforms.empty()) { delete mUniforms.back(); @@ -2900,7 +2720,7 @@ bool Program::validateSamplers(bool logErrors) textureUnitType[i] = TEXTURE_UNKNOWN; } - for (unsigned int i = 0; i < MAX_TEXTURE_IMAGE_UNITS; ++i) + for (unsigned int i = 0; i < mUsedPixelSamplerRange; ++i) { if (mSamplersPS[i].active) { @@ -2935,7 +2755,7 @@ bool Program::validateSamplers(bool logErrors) } } - for (unsigned int i = 0; i < MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; ++i) + for (unsigned int i = 0; i < mUsedVertexSamplerRange; ++i) { if (mSamplersVS[i].active) { @@ -2973,17 +2793,23 @@ bool Program::validateSamplers(bool logErrors) return true; } -void Program::getConstantHandles(Uniform *targetUniform, D3DXHANDLE *constantPS, D3DXHANDLE *constantVS) +void Program::initializeConstantHandles(Uniform *targetUniform, Uniform::RegisterInfo *ri, ID3DXConstantTable *constantTable) { - if (!targetUniform->handlesSet) + D3DXHANDLE handle = constantTable->GetConstantByName(0, targetUniform->_name.c_str()); + if (handle) { - targetUniform->psHandle = mConstantTablePS->GetConstantByName(0, targetUniform->_name.c_str()); - targetUniform->vsHandle = mConstantTableVS->GetConstantByName(0, targetUniform->_name.c_str()); - targetUniform->handlesSet = true; + UINT descriptionCount = 1; + D3DXCONSTANT_DESC constantDescription; + HRESULT result = constantTable->GetConstantDesc(handle, &constantDescription, &descriptionCount); + ASSERT(SUCCEEDED(result)); + ri->registerIndex = constantDescription.RegisterIndex; + ri->registerCount = constantDescription.RegisterCount; + ri->registerSet = constantDescription.RegisterSet; + } + else + { + ri->registerCount = 0; } - - *constantPS = targetUniform->psHandle; - *constantVS = targetUniform->vsHandle; } GLint Program::getDxDepthRangeLocation() const diff --git a/gfx/angle/src/libGLESv2/Program.h b/gfx/angle/src/libGLESv2/Program.h index 4bf344fcf18..23be162ddc3 100644 --- a/gfx/angle/src/libGLESv2/Program.h +++ b/gfx/angle/src/libGLESv2/Program.h @@ -42,9 +42,15 @@ struct Uniform unsigned char *data; bool dirty; - D3DXHANDLE vsHandle; - D3DXHANDLE psHandle; - bool handlesSet; + struct RegisterInfo + { + int registerSet; + int registerIndex; + int registerCount; + }; + + RegisterInfo ps; + RegisterInfo vs; }; // Struct used for correlating uniforms/elements of uniform arrays to handles @@ -77,6 +83,7 @@ class Program GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex); TextureType getSamplerTextureType(SamplerType type, unsigned int samplerIndex); + GLint getUsedSamplerRange(SamplerType type); GLint getUniformLocation(std::string name); bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v); @@ -149,23 +156,15 @@ class Program bool defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = ""); bool defineUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name); Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name); - bool applyUniform1bv(GLint location, GLsizei count, const GLboolean *v); - bool applyUniform2bv(GLint location, GLsizei count, const GLboolean *v); - bool applyUniform3bv(GLint location, GLsizei count, const GLboolean *v); - bool applyUniform4bv(GLint location, GLsizei count, const GLboolean *v); - bool applyUniform1fv(GLint location, GLsizei count, const GLfloat *v); - bool applyUniform2fv(GLint location, GLsizei count, const GLfloat *v); - bool applyUniform3fv(GLint location, GLsizei count, const GLfloat *v); - bool applyUniform4fv(GLint location, GLsizei count, const GLfloat *v); - bool applyUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value); - bool applyUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value); - bool applyUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value); - bool applyUniform1iv(GLint location, GLsizei count, const GLint *v); - bool applyUniform2iv(GLint location, GLsizei count, const GLint *v); - bool applyUniform3iv(GLint location, GLsizei count, const GLint *v); - bool applyUniform4iv(GLint location, GLsizei count, const GLint *v); + bool applyUniformnfv(Uniform *targetUniform, const GLfloat *v); + bool applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint *v); + bool applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint *v); + bool applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint *v); + bool applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint *v); + void applyUniformniv(Uniform *targetUniform, GLsizei count, const D3DXVECTOR4 *vector); + void applyUniformnbv(Uniform *targetUniform, GLsizei count, int width, const GLboolean *v); - void getConstantHandles(Uniform *targetUniform, D3DXHANDLE *constantPS, D3DXHANDLE *constantVS); + void initializeConstantHandles(Uniform *targetUniform, Uniform::RegisterInfo *rs, ID3DXConstantTable *constantTable); void appendToInfoLogSanitized(const char *message); void appendToInfoLog(const char *info, ...); @@ -197,6 +196,8 @@ class Program Sampler mSamplersPS[MAX_TEXTURE_IMAGE_UNITS]; Sampler mSamplersVS[MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF]; + GLuint mUsedVertexSamplerRange; + GLuint mUsedPixelSamplerRange; typedef std::vector UniformArray; UniformArray mUniforms; diff --git a/gfx/angle/src/libGLESv2/Shader.cpp b/gfx/angle/src/libGLESv2/Shader.cpp index f66b2c52ab7..58eed078406 100644 --- a/gfx/angle/src/libGLESv2/Shader.cpp +++ b/gfx/angle/src/libGLESv2/Shader.cpp @@ -157,22 +157,34 @@ int Shader::getSourceLength() const } } -void Shader::getSource(GLsizei bufSize, GLsizei *length, char *source) +int Shader::getTranslatedSourceLength() const +{ + if (!mHlsl) + { + return 0; + } + else + { + return strlen(mHlsl) + 1; + } +} + +void Shader::getSourceImpl(char *source, GLsizei bufSize, GLsizei *length, char *buffer) { int index = 0; - if (mSource) + if (source) { - while (index < bufSize - 1 && index < (int)strlen(mSource)) + while (index < bufSize - 1 && index < (int)strlen(source)) { - source[index] = mSource[index]; + buffer[index] = source[index]; index++; } } if (bufSize) { - source[index] = '\0'; + buffer[index] = '\0'; } if (length) @@ -181,6 +193,16 @@ void Shader::getSource(GLsizei bufSize, GLsizei *length, char *source) } } +void Shader::getSource(GLsizei bufSize, GLsizei *length, char *buffer) +{ + getSourceImpl(mSource, bufSize, length, buffer); +} + +void Shader::getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) +{ + getSourceImpl(mHlsl, bufSize, length, buffer); +} + bool Shader::isCompiled() { return mHlsl != NULL; diff --git a/gfx/angle/src/libGLESv2/Shader.h b/gfx/angle/src/libGLESv2/Shader.h index 535b42d8c6a..22fc6376c8e 100644 --- a/gfx/angle/src/libGLESv2/Shader.h +++ b/gfx/angle/src/libGLESv2/Shader.h @@ -57,7 +57,9 @@ class Shader int getInfoLogLength() const; void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog); int getSourceLength() const; - void getSource(GLsizei bufSize, GLsizei *length, char *source); + void getSource(GLsizei bufSize, GLsizei *length, char *buffer); + int getTranslatedSourceLength() const; + void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer); virtual void compile() = 0; bool isCompiled(); @@ -78,6 +80,8 @@ class Shader void compileToHLSL(void *compiler); + void getSourceImpl(char *source, GLsizei bufSize, GLsizei *length, char *buffer); + static GLenum parseType(const std::string &type); static bool compareVarying(const Varying &x, const Varying &y); diff --git a/gfx/angle/src/libGLESv2/libGLESv2.cpp b/gfx/angle/src/libGLESv2/libGLESv2.cpp index 5a816d4df72..745b8fb8c26 100644 --- a/gfx/angle/src/libGLESv2/libGLESv2.cpp +++ b/gfx/angle/src/libGLESv2/libGLESv2.cpp @@ -1987,7 +1987,7 @@ void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenu try { if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE) - || renderbuffertarget != GL_RENDERBUFFER) + || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)) { return error(GL_INVALID_ENUM); } @@ -2003,13 +2003,13 @@ void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenu framebuffer = context->getReadFramebuffer(); framebufferHandle = context->getReadFramebufferHandle(); } - else + else { framebuffer = context->getDrawFramebuffer(); framebufferHandle = context->getDrawFramebufferHandle(); } - if (framebufferHandle == 0 || !framebuffer) + if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0)) { return error(GL_INVALID_OPERATION); } @@ -3089,6 +3089,9 @@ void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params) case GL_SHADER_SOURCE_LENGTH: *params = shaderObject->getSourceLength(); return; + case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: + *params = shaderObject->getTranslatedSourceLength(); + return; default: return error(GL_INVALID_ENUM); } @@ -3209,6 +3212,38 @@ void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length } } +void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source) +{ + EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)", + shader, bufsize, length, source); + + try + { + if (bufsize < 0) + { + return error(GL_INVALID_VALUE); + } + + gl::Context *context = gl::getContext(); + + if (context) + { + gl::Shader *shaderObject = context->getShader(shader); + + if (!shaderObject) + { + return error(GL_INVALID_OPERATION); + } + + shaderObject->getTranslatedSource(bufsize, length, source); + } + } + catch(std::bad_alloc&) + { + return error(GL_OUT_OF_MEMORY); + } +} + const GLubyte* __stdcall glGetString(GLenum name) { EVENT("(GLenum name = 0x%X)", name); @@ -5769,6 +5804,7 @@ __eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char * {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV}, {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV}, {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV}, + {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE}, }; for (int ext = 0; ext < sizeof(glExtensions) / sizeof(Extension); ext++) diff --git a/gfx/angle/src/libGLESv2/libGLESv2.def b/gfx/angle/src/libGLESv2/libGLESv2.def index b91217199bf..4793f75fbb1 100644 --- a/gfx/angle/src/libGLESv2/libGLESv2.def +++ b/gfx/angle/src/libGLESv2/libGLESv2.def @@ -154,6 +154,7 @@ EXPORTS glIsFenceNV @155 glSetFenceNV @156 glTestFenceNV @157 + glGetTranslatedShaderSourceANGLE @159 ; EGL dependencies glCreateContext @144 NONAME diff --git a/gfx/angle/src/libGLESv2/utilities.cpp b/gfx/angle/src/libGLESv2/utilities.cpp index 01cca3c05f7..3dba89987d3 100644 --- a/gfx/angle/src/libGLESv2/utilities.cpp +++ b/gfx/angle/src/libGLESv2/utilities.cpp @@ -54,6 +54,42 @@ int UniformComponentCount(GLenum type) return 0; } +// This is how much data we actually store for a uniform +int UniformInternalComponentCount(GLenum type) +{ + switch (type) + { + case GL_BOOL: + case GL_INT: + case GL_SAMPLER_2D: + case GL_SAMPLER_CUBE: + return 1; + case GL_BOOL_VEC2: + case GL_INT_VEC2: + return 2; + case GL_INT_VEC3: + case GL_BOOL_VEC3: + return 3; + case GL_FLOAT: + case GL_FLOAT_VEC2: + case GL_FLOAT_VEC3: + case GL_BOOL_VEC4: + case GL_FLOAT_VEC4: + case GL_INT_VEC4: + return 4; + case GL_FLOAT_MAT2: + return 8; + case GL_FLOAT_MAT3: + return 12; + case GL_FLOAT_MAT4: + return 16; + default: + UNREACHABLE(); + } + + return 0; +} + GLenum UniformComponentType(GLenum type) { switch(type) @@ -85,16 +121,22 @@ GLenum UniformComponentType(GLenum type) return GL_NONE; } -size_t UniformTypeSize(GLenum type) +size_t UniformComponentSize(GLenum type) { switch(type) { case GL_BOOL: return sizeof(GLboolean); case GL_FLOAT: return sizeof(GLfloat); case GL_INT: return sizeof(GLint); + default: UNREACHABLE(); } - return UniformTypeSize(UniformComponentType(type)) * UniformComponentCount(type); + return 0; +} + +size_t UniformTypeSize(GLenum type) +{ + return UniformComponentSize(UniformComponentType(type)) * UniformInternalComponentCount(type); } int VariableRowCount(GLenum type) diff --git a/gfx/angle/src/libGLESv2/utilities.h b/gfx/angle/src/libGLESv2/utilities.h index bf7f4f93482..f6b964c4556 100644 --- a/gfx/angle/src/libGLESv2/utilities.h +++ b/gfx/angle/src/libGLESv2/utilities.h @@ -22,6 +22,7 @@ namespace gl struct Color; int UniformComponentCount(GLenum type); +int UniformInternalComponentCount(GLenum type); GLenum UniformComponentType(GLenum type); size_t UniformTypeSize(GLenum type); int VariableRowCount(GLenum type);