Pass the desired HLSL version down to the HLSL generator.

TRAC #22330 Signed-off-by: Geoff Lang Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1738 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent bd8c10c4
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -36,7 +36,7 @@ extern "C" { ...@@ -36,7 +36,7 @@ extern "C" {
// Version number for shader translation API. // Version number for shader translation API.
// It is incremented everytime the API changes. // It is incremented everytime the API changes.
#define SH_VERSION 108 #define SH_VERSION 109
// //
// The names of the following enums have been derived by replacing GL prefix // The names of the following enums have been derived by replacing GL prefix
...@@ -79,7 +79,8 @@ typedef enum { ...@@ -79,7 +79,8 @@ typedef enum {
typedef enum { typedef enum {
SH_ESSL_OUTPUT = 0x8B45, SH_ESSL_OUTPUT = 0x8B45,
SH_GLSL_OUTPUT = 0x8B46, SH_GLSL_OUTPUT = 0x8B46,
SH_HLSL_OUTPUT = 0x8B47 SH_HLSL9_OUTPUT = 0x8B47,
SH_HLSL11_OUTPUT = 0x8B48
} ShShaderOutput; } ShShaderOutput;
typedef enum { typedef enum {
......
// //
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -14,9 +14,11 @@ ...@@ -14,9 +14,11 @@
TCompiler* ConstructCompiler( TCompiler* ConstructCompiler(
ShShaderType type, ShShaderSpec spec, ShShaderOutput output) ShShaderType type, ShShaderSpec spec, ShShaderOutput output)
{ {
switch (output) { switch (output)
case SH_HLSL_OUTPUT: {
return new TranslatorHLSL(type, spec); case SH_HLSL9_OUTPUT:
case SH_HLSL11_OUTPUT:
return new TranslatorHLSL(type, spec, output);
default: default:
return NULL; return NULL;
} }
......
...@@ -27,7 +27,8 @@ TString str(int i) ...@@ -27,7 +27,8 @@ TString str(int i)
return buffer; return buffer;
} }
OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, true), mContext(context) OutputHLSL::OutputHLSL(TParseContext &context, ShShaderOutput outputType)
: TIntermTraverser(true, true, true), mContext(context), mOutputType(outputType)
{ {
mUnfoldShortCircuit = new UnfoldShortCircuit(context, this); mUnfoldShortCircuit = new UnfoldShortCircuit(context, this);
mInsideFunction = false; mInsideFunction = false;
......
...@@ -25,7 +25,7 @@ class UnfoldShortCircuit; ...@@ -25,7 +25,7 @@ class UnfoldShortCircuit;
class OutputHLSL : public TIntermTraverser class OutputHLSL : public TIntermTraverser
{ {
public: public:
explicit OutputHLSL(TParseContext &context); OutputHLSL(TParseContext &context, ShShaderOutput outputType);
~OutputHLSL(); ~OutputHLSL();
void output(); void output();
...@@ -70,6 +70,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -70,6 +70,7 @@ class OutputHLSL : public TIntermTraverser
TString structLookup(const TString &typeName); TString structLookup(const TString &typeName);
TParseContext &mContext; TParseContext &mContext;
const ShShaderOutput mOutputType;
UnfoldShortCircuit *mUnfoldShortCircuit; UnfoldShortCircuit *mUnfoldShortCircuit;
bool mInsideFunction; bool mInsideFunction;
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -9,15 +9,15 @@ ...@@ -9,15 +9,15 @@
#include "compiler/InitializeParseContext.h" #include "compiler/InitializeParseContext.h"
#include "compiler/OutputHLSL.h" #include "compiler/OutputHLSL.h"
TranslatorHLSL::TranslatorHLSL(ShShaderType type, ShShaderSpec spec) TranslatorHLSL::TranslatorHLSL(ShShaderType type, ShShaderSpec spec, ShShaderOutput output)
: TCompiler(type, spec) : TCompiler(type, spec), mOutputType(output)
{ {
} }
void TranslatorHLSL::translate(TIntermNode *root) void TranslatorHLSL::translate(TIntermNode *root)
{ {
TParseContext& parseContext = *GetGlobalParseContext(); TParseContext& parseContext = *GetGlobalParseContext();
sh::OutputHLSL outputHLSL(parseContext); sh::OutputHLSL outputHLSL(parseContext, mOutputType);
outputHLSL.output(); outputHLSL.output();
mActiveUniforms = outputHLSL.getUniforms(); mActiveUniforms = outputHLSL.getUniforms();
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
class TranslatorHLSL : public TCompiler { class TranslatorHLSL : public TCompiler {
public: public:
TranslatorHLSL(ShShaderType type, ShShaderSpec spec); TranslatorHLSL(ShShaderType type, ShShaderSpec spec, ShShaderOutput output);
virtual TranslatorHLSL *getAsTranslatorHLSL() { return this; } virtual TranslatorHLSL *getAsTranslatorHLSL() { return this; }
const sh::ActiveUniforms &getUniforms() { return mActiveUniforms; } const sh::ActiveUniforms &getUniforms() { return mActiveUniforms; }
...@@ -21,6 +21,7 @@ protected: ...@@ -21,6 +21,7 @@ protected:
virtual void translate(TIntermNode* root); virtual void translate(TIntermNode* root);
sh::ActiveUniforms mActiveUniforms; sh::ActiveUniforms mActiveUniforms;
ShShaderOutput mOutputType;
}; };
#endif // COMPILER_TRANSLATORHLSL_H_ #endif // COMPILER_TRANSLATORHLSL_H_
...@@ -82,11 +82,11 @@ GLuint ResourceManager::createShader(GLenum type) ...@@ -82,11 +82,11 @@ GLuint ResourceManager::createShader(GLenum type)
if (type == GL_VERTEX_SHADER) if (type == GL_VERTEX_SHADER)
{ {
mShaderMap[handle] = new VertexShader(this, handle); mShaderMap[handle] = new VertexShader(this, mRenderer, handle);
} }
else if (type == GL_FRAGMENT_SHADER) else if (type == GL_FRAGMENT_SHADER)
{ {
mShaderMap[handle] = new FragmentShader(this, handle); mShaderMap[handle] = new FragmentShader(this, mRenderer, handle);
} }
else UNREACHABLE(); else UNREACHABLE();
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -21,7 +21,8 @@ namespace gl ...@@ -21,7 +21,8 @@ namespace gl
void *Shader::mFragmentCompiler = NULL; void *Shader::mFragmentCompiler = NULL;
void *Shader::mVertexCompiler = NULL; void *Shader::mVertexCompiler = NULL;
Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mResourceManager(manager) Shader::Shader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle)
: mHandle(handle), mRenderer(renderer), mResourceManager(manager)
{ {
mSource = NULL; mSource = NULL;
mHlsl = NULL; mHlsl = NULL;
...@@ -228,9 +229,11 @@ void Shader::initializeCompiler() ...@@ -228,9 +229,11 @@ void Shader::initializeCompiler()
if (result) if (result)
{ {
Context *context = getContext();
ShShaderOutput hlslVersion = (mRenderer->getMajorShaderModel() >= 4) ? SH_HLSL11_OUTPUT : SH_HLSL9_OUTPUT;
ShBuiltInResources resources; ShBuiltInResources resources;
ShInitBuiltInResources(&resources); ShInitBuiltInResources(&resources);
Context *context = getContext();
resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS; resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS;
resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS; resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS;
...@@ -243,8 +246,8 @@ void Shader::initializeCompiler() ...@@ -243,8 +246,8 @@ void Shader::initializeCompiler()
resources.OES_standard_derivatives = context->supportsDerivativeInstructions() ? 1 : 0; resources.OES_standard_derivatives = context->supportsDerivativeInstructions() ? 1 : 0;
// resources.OES_EGL_image_external = getDisplay()->getRenderer()->getShareHandleSupport() ? 1 : 0; // TODO: commented out until the extension is actually supported. // resources.OES_EGL_image_external = getDisplay()->getRenderer()->getShareHandleSupport() ? 1 : 0; // TODO: commented out until the extension is actually supported.
mFragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, SH_HLSL_OUTPUT, &resources); mFragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, hlslVersion, &resources);
mVertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, SH_HLSL_OUTPUT, &resources); mVertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, hlslVersion, &resources);
} }
} }
} }
...@@ -496,7 +499,8 @@ bool Shader::compareVarying(const Varying &x, const Varying &y) ...@@ -496,7 +499,8 @@ bool Shader::compareVarying(const Varying &x, const Varying &y)
return false; return false;
} }
VertexShader::VertexShader(ResourceManager *manager, GLuint handle) : Shader(manager, handle) VertexShader::VertexShader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle)
: Shader(manager, renderer, handle)
{ {
} }
...@@ -571,7 +575,8 @@ void VertexShader::parseAttributes() ...@@ -571,7 +575,8 @@ void VertexShader::parseAttributes()
} }
} }
FragmentShader::FragmentShader(ResourceManager *manager, GLuint handle) : Shader(manager, handle) FragmentShader::FragmentShader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle)
: Shader(manager, renderer, handle)
{ {
} }
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -21,6 +21,11 @@ ...@@ -21,6 +21,11 @@
#include "libGLESv2/ResourceManager.h" #include "libGLESv2/ResourceManager.h"
#include "compiler/Uniform.h" #include "compiler/Uniform.h"
namespace rx
{
class Renderer;
}
namespace gl namespace gl
{ {
struct Varying struct Varying
...@@ -46,7 +51,7 @@ class Shader ...@@ -46,7 +51,7 @@ class Shader
friend class ProgramBinary; friend class ProgramBinary;
public: public:
Shader(ResourceManager *manager, GLuint handle); Shader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle);
virtual ~Shader(); virtual ~Shader();
...@@ -86,6 +91,8 @@ class Shader ...@@ -86,6 +91,8 @@ class Shader
static GLenum parseType(const std::string &type); static GLenum parseType(const std::string &type);
static bool compareVarying(const Varying &x, const Varying &y); static bool compareVarying(const Varying &x, const Varying &y);
const rx::Renderer *const mRenderer;
VaryingList mVaryings; VaryingList mVaryings;
bool mUsesFragCoord; bool mUsesFragCoord;
...@@ -134,7 +141,7 @@ class VertexShader : public Shader ...@@ -134,7 +141,7 @@ class VertexShader : public Shader
friend class ProgramBinary; friend class ProgramBinary;
public: public:
VertexShader(ResourceManager *manager, GLuint handle); VertexShader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle);
~VertexShader(); ~VertexShader();
...@@ -154,7 +161,7 @@ class VertexShader : public Shader ...@@ -154,7 +161,7 @@ class VertexShader : public Shader
class FragmentShader : public Shader class FragmentShader : public Shader
{ {
public: public:
FragmentShader(ResourceManager *manager, GLuint handle); FragmentShader(ResourceManager *manager,const rx::Renderer *renderer, GLuint handle);
~FragmentShader(); ~FragmentShader();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment