Commit 9b4e8626 by Olli Etuaho

Redesign samplers in shaders on D3D11

Translation of samplers to HLSL on D3D11 is changed as follows: Instead of passing around HLSL sampler and HLSL texture references in shaders, all references to ESSL samplers are converted to constant indices within the shader body. Each ESSL sampler is identified by an unique index. In the code generated to implement ESSL texture functions, these indices are used to index arrays of HLSL samplers and HLSL textures to get the sampler and texture to use. HLSL textures and samplers are grouped into arrays by their types. Each unique combination of a HLSL texture type + HLSL sampler type gets its own array. To convert a unique sampler index to an index to one of these arrays, a constant offset is applied. In the most common case of a 2D texture and a regular (non-comparison) sampler, the index offset is always zero and is omitted. The end goal of this refactoring is to make adding extra metadata for samplers easier. The unique sampler index can be used in follow-up changes to index an array of metadata passed in uniforms, which can contain such things as the base level of the texture. This does not solve the issues with samplers in structs. The interface from the point of view of libANGLE is still exactly the same, the only thing that changes is how samplers are handled inside the shader. On feature level 9_3, the D3D compiler has a bug where it can report that the maximum sampler index is exceeded when in fact it is not. This can happen when an array of samplers is declared in the shader. Because of this the new approach can't be used on D3D11 feature level 9_3, but it will continue using the old approach instead. BUG=angleproject:1261 TEST=angle_end2end_tests, dEQP-GLES3.functional.shaders.texture_functions.* (no regressions) dEQP-GLES3.functional.texture.units.* (no regressions) Change-Id: I5fbb0c4280000202dc2795a628b56bd8194ef96f Reviewed-on: https://chromium-review.googlesource.com/320571Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Tryjob-Request: Olli Etuaho <oetuaho@nvidia.com>
parent 5bf9ff4a
......@@ -48,7 +48,7 @@ typedef unsigned int GLenum;
// Version number for shader translation API.
// It is incremented every time the API changes.
#define ANGLE_SH_VERSION 141
#define ANGLE_SH_VERSION 142
typedef enum {
SH_GLES2_SPEC = 0x8B40,
......@@ -80,28 +80,35 @@ typedef enum {
SH_CSS_SHADERS_SPEC = 0x8B42
} ShShaderSpec;
typedef enum {
// ESSL output only supported in some configurations.
SH_ESSL_OUTPUT = 0x8B45,
// GLSL output only supported in some configurations.
SH_GLSL_COMPATIBILITY_OUTPUT = 0x8B46,
//Note: GL introduced core profiles in 1.5.
SH_GLSL_130_OUTPUT = 0x8B47,
SH_GLSL_140_OUTPUT = 0x8B80,
SH_GLSL_150_CORE_OUTPUT = 0x8B81,
SH_GLSL_330_CORE_OUTPUT = 0x8B82,
SH_GLSL_400_CORE_OUTPUT = 0x8B83,
SH_GLSL_410_CORE_OUTPUT = 0x8B84,
SH_GLSL_420_CORE_OUTPUT = 0x8B85,
SH_GLSL_430_CORE_OUTPUT = 0x8B86,
SH_GLSL_440_CORE_OUTPUT = 0x8B87,
SH_GLSL_450_CORE_OUTPUT = 0x8B88,
// HLSL output only supported in some configurations.
SH_HLSL_OUTPUT = 0x8B48,
SH_HLSL9_OUTPUT = 0x8B48,
SH_HLSL11_OUTPUT = 0x8B49
typedef enum
{
// ESSL output only supported in some configurations.
SH_ESSL_OUTPUT = 0x8B45,
// GLSL output only supported in some configurations.
SH_GLSL_COMPATIBILITY_OUTPUT = 0x8B46,
// Note: GL introduced core profiles in 1.5.
SH_GLSL_130_OUTPUT = 0x8B47,
SH_GLSL_140_OUTPUT = 0x8B80,
SH_GLSL_150_CORE_OUTPUT = 0x8B81,
SH_GLSL_330_CORE_OUTPUT = 0x8B82,
SH_GLSL_400_CORE_OUTPUT = 0x8B83,
SH_GLSL_410_CORE_OUTPUT = 0x8B84,
SH_GLSL_420_CORE_OUTPUT = 0x8B85,
SH_GLSL_430_CORE_OUTPUT = 0x8B86,
SH_GLSL_440_CORE_OUTPUT = 0x8B87,
SH_GLSL_450_CORE_OUTPUT = 0x8B88,
// HLSL output only supported in some configurations.
// Deprecated:
SH_HLSL_OUTPUT = 0x8B48,
SH_HLSL9_OUTPUT = 0x8B48,
SH_HLSL11_OUTPUT = 0x8B49,
// Prefer using these to specify HLSL output type:
SH_HLSL_3_0_OUTPUT = 0x8B48, // D3D 9
SH_HLSL_4_1_OUTPUT = 0x8B49, // D3D 11
SH_HLSL_4_0_FL9_3_OUTPUT = 0x8B4A // D3D 11 feature level 9_3
} ShShaderOutput;
// Compile options.
......@@ -332,8 +339,8 @@ COMPILER_EXPORT const std::string &ShGetBuiltInResourcesString(const ShHandle ha
// type: Specifies the type of shader - GL_FRAGMENT_SHADER or GL_VERTEX_SHADER.
// spec: Specifies the language spec the compiler must conform to -
// SH_GLES2_SPEC or SH_WEBGL_SPEC.
// output: Specifies the output code type - SH_ESSL_OUTPUT, SH_GLSL_OUTPUT,
// SH_HLSL9_OUTPUT or SH_HLSL11_OUTPUT. Note: Each output type may only
// output: Specifies the output code type - for example SH_ESSL_OUTPUT, SH_GLSL_OUTPUT,
// SH_HLSL_3_0_OUTPUT or SH_HLSL_4_1_OUTPUT. Note: Each output type may only
// be supported in some configurations.
// resources: Specifies the built-in resources.
COMPILER_EXPORT ShHandle ShConstructCompiler(
......
......@@ -146,11 +146,11 @@ int main(int argc, char *argv[])
case 'h':
if (argv[0][4] == '1' && argv[0][5] == '1')
{
output = SH_HLSL11_OUTPUT;
output = SH_HLSL_4_1_OUTPUT;
}
else
{
output = SH_HLSL9_OUTPUT;
output = SH_HLSL_3_0_OUTPUT;
}
break;
default: failCode = EFailUsage;
......
......@@ -51,8 +51,9 @@ TCompiler* ConstructCompiler(
// configuration. Return NULL per the ShConstructCompiler API.
return nullptr;
#endif // ANGLE_ENABLE_GLSL
case SH_HLSL9_OUTPUT:
case SH_HLSL11_OUTPUT:
case SH_HLSL_3_0_OUTPUT:
case SH_HLSL_4_1_OUTPUT:
case SH_HLSL_4_0_FL9_3_OUTPUT:
#ifdef ANGLE_ENABLE_HLSL
return new TranslatorHLSL(type, spec, output);
#else
......
......@@ -47,7 +47,7 @@ void TranslatorHLSL::translate(TIntermNode *root, int compileOptions)
// Work around D3D9 bug that would manifest in vertex shaders with selection blocks which
// use a vertex attribute as a condition, and some related computation in the else block.
if (getOutputType() == SH_HLSL9_OUTPUT && getShaderType() == GL_VERTEX_SHADER)
if (getOutputType() == SH_HLSL_3_0_OUTPUT && getShaderType() == GL_VERTEX_SHADER)
{
sh::RewriteElseBlocks(root, getTemporaryIndex());
}
......
......@@ -93,7 +93,9 @@ const Uniform *UniformHLSL::findUniformByName(const TString &name) const
return NULL;
}
unsigned int UniformHLSL::declareUniformAndAssignRegister(const TType &type, const TString &name)
unsigned int UniformHLSL::declareUniformAndAssignRegister(const TType &type,
const TString &name,
unsigned int *registerCount)
{
unsigned int registerIndex = (IsSampler(type.getBasicType()) ? mSamplerRegister : mUniformRegister);
......@@ -102,43 +104,119 @@ unsigned int UniformHLSL::declareUniformAndAssignRegister(const TType &type, con
mUniformRegisterMap[uniform->name] = registerIndex;
unsigned int registerCount = HLSLVariableRegisterCount(*uniform, mOutputType);
ASSERT(registerCount);
*registerCount = HLSLVariableRegisterCount(*uniform, mOutputType);
if (gl::IsSamplerType(uniform->type))
{
mSamplerRegister += registerCount;
mSamplerRegister += *registerCount;
}
else
{
mUniformRegister += registerCount;
mUniformRegister += *registerCount;
}
return registerIndex;
}
TString UniformHLSL::uniformsHeader(ShShaderOutput outputType, const ReferencedSymbols &referencedUniforms)
unsigned int UniformHLSL::declareUniformAndAssignRegister(const TType &type, const TString &name)
{
unsigned int registerCount;
return declareUniformAndAssignRegister(type, name, &registerCount);
}
void UniformHLSL::outputHLSLSamplerUniformGroup(TInfoSinkBase &out,
const HLSLTextureSamplerGroup textureGroup,
const TVector<const TIntermSymbol *> &group,
unsigned int *groupTextureRegisterIndex)
{
TString uniforms;
if (group.empty())
{
return;
}
unsigned int groupRegisterCount = 0;
for (const TIntermSymbol *uniform : group)
{
const TType &type = uniform->getType();
const TString &name = uniform->getSymbol();
unsigned int registerCount;
unsigned int samplerArrayIndex =
declareUniformAndAssignRegister(type, name, &registerCount);
groupRegisterCount += registerCount;
if (type.isArray())
{
out << "static const uint " << DecorateIfNeeded(uniform->getName()) << ArrayString(type)
<< " = {";
for (int i = 0; i < type.getArraySize(); ++i)
{
if (i > 0)
out << ", ";
out << (samplerArrayIndex + i);
}
out << "};\n";
}
else
{
out << "static const uint " << DecorateIfNeeded(uniform->getName()) << " = "
<< samplerArrayIndex << ";\n";
}
}
TString suffix = TextureGroupSuffix(textureGroup);
// Since HLSL_TEXTURE_2D is the first group, it has a fixed offset of zero.
if (textureGroup != HLSL_TEXTURE_2D)
{
out << "static const uint textureIndexOffset" << suffix << " = "
<< (*groupTextureRegisterIndex) << ";\n";
out << "static const uint samplerIndexOffset" << suffix << " = "
<< (*groupTextureRegisterIndex) << ";\n";
}
out << "uniform " << TextureString(textureGroup) << " textures" << suffix << "["
<< groupRegisterCount << "]"
<< " : register(t" << (*groupTextureRegisterIndex) << ");\n";
out << "uniform " << SamplerString(textureGroup) << " samplers" << suffix << "["
<< groupRegisterCount << "]"
<< " : register(s" << (*groupTextureRegisterIndex) << ");\n";
*groupTextureRegisterIndex += groupRegisterCount;
}
for (ReferencedSymbols::const_iterator uniformIt = referencedUniforms.begin();
uniformIt != referencedUniforms.end(); uniformIt++)
void UniformHLSL::uniformsHeader(TInfoSinkBase &out,
ShShaderOutput outputType,
const ReferencedSymbols &referencedUniforms)
{
if (!referencedUniforms.empty())
{
out << "// Uniforms\n\n";
}
// In the case of HLSL 4, sampler uniforms need to be grouped by type before the code is
// written. They are grouped based on the combination of the HLSL texture type and
// HLSL sampler type, enumerated in HLSLTextureSamplerGroup.
TVector<TVector<const TIntermSymbol *>> groupedSamplerUniforms;
groupedSamplerUniforms.resize(HLSL_TEXTURE_MAX + 1);
for (auto &uniformIt : referencedUniforms)
{
const TIntermSymbol &uniform = *uniformIt->second;
// Output regular uniforms. Group sampler uniforms by type.
const TIntermSymbol &uniform = *uniformIt.second;
const TType &type = uniform.getType();
const TString &name = uniform.getSymbol();
unsigned int registerIndex = declareUniformAndAssignRegister(type, name);
if (outputType == SH_HLSL11_OUTPUT && IsSampler(type.getBasicType())) // Also declare the texture
if (outputType == SH_HLSL_4_1_OUTPUT && IsSampler(type.getBasicType()))
{
uniforms += "uniform " + SamplerString(type) + " sampler_" + DecorateUniform(name, type) + ArrayString(type) +
" : register(s" + str(registerIndex) + ");\n";
uniforms += "uniform " + TextureString(type) + " texture_" + DecorateUniform(name, type) + ArrayString(type) +
" : register(t" + str(registerIndex) + ");\n";
HLSLTextureSamplerGroup group = TextureGroup(type.getBasicType());
groupedSamplerUniforms[group].push_back(&uniform);
}
else if (outputType == SH_HLSL_4_0_FL9_3_OUTPUT && IsSampler(type.getBasicType()))
{
unsigned int registerIndex = declareUniformAndAssignRegister(type, name);
out << "uniform " << SamplerString(type.getBasicType()) << " sampler_"
<< DecorateUniform(name, type) << ArrayString(type) << " : register(s"
<< str(registerIndex) << ");\n";
out << "uniform " << TextureString(type.getBasicType()) << " texture_"
<< DecorateUniform(name, type) << ArrayString(type) << " : register(t"
<< str(registerIndex) << ");\n";
}
else
{
unsigned int registerIndex = declareUniformAndAssignRegister(type, name);
const TStructure *structure = type.getStruct();
// If this is a nameless struct, we need to use its full definition, rather than its (empty) name.
// TypeString() will invoke defineNameless in this case; qualifier prefixes are unnecessary for
......@@ -149,11 +227,23 @@ TString UniformHLSL::uniformsHeader(ShShaderOutput outputType, const ReferencedS
const TString &registerString = TString("register(") + UniformRegisterPrefix(type) + str(registerIndex) + ")";
uniforms += "uniform " + typeName + " " + DecorateUniform(name, type) + ArrayString(type) + " : " + registerString + ";\n";
out << "uniform " << typeName << " " << DecorateUniform(name, type) << ArrayString(type)
<< " : " << registerString << ";\n";
}
}
return (uniforms.empty() ? "" : ("// Uniforms\n\n" + uniforms));
if (outputType == SH_HLSL_4_1_OUTPUT)
{
unsigned int groupTextureRegisterIndex = 0;
// TEXTURE_2D is special, index offset is assumed to be 0 and omitted in that case.
ASSERT(HLSL_TEXTURE_MIN == HLSL_TEXTURE_2D);
for (int groupId = HLSL_TEXTURE_MIN; groupId < HLSL_TEXTURE_MAX; ++groupId)
{
outputHLSLSamplerUniformGroup(out, HLSLTextureSamplerGroup(groupId),
groupedSamplerUniforms[groupId],
&groupTextureRegisterIndex);
}
}
}
TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks)
......
......@@ -11,6 +11,7 @@
#define COMPILER_TRANSLATOR_UNIFORMHLSL_H_
#include "compiler/translator/OutputHLSL.h"
#include "compiler/translator/UtilsHLSL.h"
namespace sh
{
......@@ -23,7 +24,13 @@ class UniformHLSL : angle::NonCopyable
void reserveUniformRegisters(unsigned int registerCount);
void reserveInterfaceBlockRegisters(unsigned int registerCount);
TString uniformsHeader(ShShaderOutput outputType, const ReferencedSymbols &referencedUniforms);
void outputHLSLSamplerUniformGroup(TInfoSinkBase &out,
const HLSLTextureSamplerGroup textureGroup,
const TVector<const TIntermSymbol *> &group,
unsigned int *groupTextureRegisterIndex);
void uniformsHeader(TInfoSinkBase &out,
ShShaderOutput outputType,
const ReferencedSymbols &referencedUniforms);
TString interfaceBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks);
// Used for direct index references
......@@ -45,6 +52,9 @@ class UniformHLSL : angle::NonCopyable
const Uniform *findUniformByName(const TString &name) const;
// Returns the uniform's register index
unsigned int declareUniformAndAssignRegister(const TType &type,
const TString &name,
unsigned int *registerCount);
unsigned int declareUniformAndAssignRegister(const TType &type, const TString &name);
unsigned int mUniformRegister;
......
......@@ -15,9 +15,9 @@
namespace sh
{
TString SamplerString(const TType &type)
TString SamplerString(const TBasicType type)
{
if (IsShadowSampler(type.getBasicType()))
if (IsShadowSampler(type))
{
return "SamplerComparisonState";
}
......@@ -27,32 +27,158 @@ TString SamplerString(const TType &type)
}
}
TString TextureString(const TType &type)
TString SamplerString(HLSLTextureSamplerGroup type)
{
switch (type.getBasicType())
if (type >= HLSL_COMPARISON_SAMPLER_GROUP_BEGIN && type <= HLSL_COMPARISON_SAMPLER_GROUP_END)
{
case EbtSampler2D: return "Texture2D";
case EbtSamplerCube: return "TextureCube";
case EbtSamplerExternalOES: return "Texture2D";
case EbtSampler2DArray: return "Texture2DArray";
case EbtSampler3D: return "Texture3D";
case EbtISampler2D: return "Texture2D<int4>";
case EbtISampler3D: return "Texture3D<int4>";
case EbtISamplerCube: return "Texture2DArray<int4>";
case EbtISampler2DArray: return "Texture2DArray<int4>";
case EbtUSampler2D: return "Texture2D<uint4>";
case EbtUSampler3D: return "Texture3D<uint4>";
case EbtUSamplerCube: return "Texture2DArray<uint4>";
case EbtUSampler2DArray: return "Texture2DArray<uint4>";
case EbtSampler2DShadow: return "Texture2D";
case EbtSamplerCubeShadow: return "TextureCube";
case EbtSampler2DArrayShadow: return "Texture2DArray";
default: UNREACHABLE();
return "SamplerComparisonState";
}
else
{
return "SamplerState";
}
}
HLSLTextureSamplerGroup TextureGroup(const TBasicType type)
{
switch (type)
{
case EbtSampler2D:
return HLSL_TEXTURE_2D;
case EbtSamplerCube:
return HLSL_TEXTURE_CUBE;
case EbtSamplerExternalOES:
return HLSL_TEXTURE_2D;
case EbtSampler2DArray:
return HLSL_TEXTURE_2D_ARRAY;
case EbtSampler3D:
return HLSL_TEXTURE_3D;
case EbtISampler2D:
return HLSL_TEXTURE_2D_INT4;
case EbtISampler3D:
return HLSL_TEXTURE_3D_INT4;
case EbtISamplerCube:
return HLSL_TEXTURE_2D_ARRAY_INT4;
case EbtISampler2DArray:
return HLSL_TEXTURE_2D_ARRAY_INT4;
case EbtUSampler2D:
return HLSL_TEXTURE_2D_UINT4;
case EbtUSampler3D:
return HLSL_TEXTURE_3D_UINT4;
case EbtUSamplerCube:
return HLSL_TEXTURE_2D_ARRAY_UINT4;
case EbtUSampler2DArray:
return HLSL_TEXTURE_2D_ARRAY_UINT4;
case EbtSampler2DShadow:
return HLSL_TEXTURE_2D_COMPARISON;
case EbtSamplerCubeShadow:
return HLSL_TEXTURE_CUBE_COMPARISON;
case EbtSampler2DArrayShadow:
return HLSL_TEXTURE_2D_ARRAY_COMPARISON;
default:
UNREACHABLE();
}
return HLSL_TEXTURE_UNKNOWN;
}
TString TextureString(const HLSLTextureSamplerGroup type)
{
switch (type)
{
case HLSL_TEXTURE_2D:
return "Texture2D";
case HLSL_TEXTURE_CUBE:
return "TextureCube";
case HLSL_TEXTURE_2D_ARRAY:
return "Texture2DArray";
case HLSL_TEXTURE_3D:
return "Texture3D";
case HLSL_TEXTURE_2D_INT4:
return "Texture2D<int4>";
case HLSL_TEXTURE_3D_INT4:
return "Texture3D<int4>";
case HLSL_TEXTURE_2D_ARRAY_INT4:
return "Texture2DArray<int4>";
case HLSL_TEXTURE_2D_UINT4:
return "Texture2D<uint4>";
case HLSL_TEXTURE_3D_UINT4:
return "Texture3D<uint4>";
case HLSL_TEXTURE_2D_ARRAY_UINT4:
return "Texture2DArray<uint4>";
case HLSL_TEXTURE_2D_COMPARISON:
return "Texture2D";
case HLSL_TEXTURE_CUBE_COMPARISON:
return "TextureCube";
case HLSL_TEXTURE_2D_ARRAY_COMPARISON:
return "Texture2DArray";
default:
UNREACHABLE();
}
return "<unknown texture type>";
}
TString TextureString(const TBasicType type)
{
return TextureString(TextureGroup(type));
}
TString TextureGroupSuffix(const HLSLTextureSamplerGroup type)
{
switch (type)
{
case HLSL_TEXTURE_2D:
return "2D";
case HLSL_TEXTURE_CUBE:
return "Cube";
case HLSL_TEXTURE_2D_ARRAY:
return "2DArray";
case HLSL_TEXTURE_3D:
return "3D";
case HLSL_TEXTURE_2D_INT4:
return "2D_int4_";
case HLSL_TEXTURE_3D_INT4:
return "3D_int4_";
case HLSL_TEXTURE_2D_ARRAY_INT4:
return "2DArray_int4_";
case HLSL_TEXTURE_2D_UINT4:
return "2D_uint4_";
case HLSL_TEXTURE_3D_UINT4:
return "3D_uint4_";
case HLSL_TEXTURE_2D_ARRAY_UINT4:
return "2DArray_uint4_";
case HLSL_TEXTURE_2D_COMPARISON:
return "2D_comparison";
case HLSL_TEXTURE_CUBE_COMPARISON:
return "Cube_comparison";
case HLSL_TEXTURE_2D_ARRAY_COMPARISON:
return "2DArray_comparison";
default:
UNREACHABLE();
}
return "<unknown texture type>";
}
TString TextureGroupSuffix(const TBasicType type)
{
return TextureGroupSuffix(TextureGroup(type));
}
TString TextureTypeSuffix(const TBasicType type)
{
switch (type)
{
case EbtISamplerCube:
return "Cube_int4_";
case EbtUSamplerCube:
return "Cube_uint4_";
default:
// All other types are identified by their group suffix
return TextureGroupSuffix(type);
}
}
TString DecorateUniform(const TString &string, const TType &type)
{
if (type.getBasicType() == EbtSamplerExternalOES)
......@@ -270,4 +396,43 @@ TString QualifierString(TQualifier qualifier)
return "";
}
int HLSLTextureCoordsCount(const TBasicType samplerType)
{
switch (samplerType)
{
case EbtSampler2D:
return 2;
case EbtSampler3D:
return 3;
case EbtSamplerCube:
return 3;
case EbtSampler2DArray:
return 3;
case EbtISampler2D:
return 2;
case EbtISampler3D:
return 3;
case EbtISamplerCube:
return 3;
case EbtISampler2DArray:
return 3;
case EbtUSampler2D:
return 2;
case EbtUSampler3D:
return 3;
case EbtUSamplerCube:
return 3;
case EbtUSampler2DArray:
return 3;
case EbtSampler2DShadow:
return 2;
case EbtSamplerCubeShadow:
return 3;
case EbtSampler2DArrayShadow:
return 3;
default:
UNREACHABLE();
}
return 0;
}
}
......@@ -20,8 +20,44 @@ class TName;
namespace sh
{
TString TextureString(const TType &type);
TString SamplerString(const TType &type);
// Unique combinations of HLSL Texture type and HLSL Sampler type.
enum HLSLTextureSamplerGroup
{
// Regular samplers
HLSL_TEXTURE_2D,
HLSL_TEXTURE_MIN = HLSL_TEXTURE_2D,
HLSL_TEXTURE_CUBE,
HLSL_TEXTURE_2D_ARRAY,
HLSL_TEXTURE_3D,
HLSL_TEXTURE_2D_INT4,
HLSL_TEXTURE_3D_INT4,
HLSL_TEXTURE_2D_ARRAY_INT4,
HLSL_TEXTURE_2D_UINT4,
HLSL_TEXTURE_3D_UINT4,
HLSL_TEXTURE_2D_ARRAY_UINT4,
// Comparison samplers
HLSL_TEXTURE_2D_COMPARISON,
HLSL_TEXTURE_CUBE_COMPARISON,
HLSL_TEXTURE_2D_ARRAY_COMPARISON,
HLSL_COMPARISON_SAMPLER_GROUP_BEGIN = HLSL_TEXTURE_2D_COMPARISON,
HLSL_COMPARISON_SAMPLER_GROUP_END = HLSL_TEXTURE_2D_ARRAY_COMPARISON,
HLSL_TEXTURE_UNKNOWN,
HLSL_TEXTURE_MAX = HLSL_TEXTURE_UNKNOWN
};
HLSLTextureSamplerGroup TextureGroup(const TBasicType type);
TString TextureString(const HLSLTextureSamplerGroup type);
TString TextureString(const TBasicType type);
TString TextureGroupSuffix(const HLSLTextureSamplerGroup type);
TString TextureGroupSuffix(const TBasicType type);
TString TextureTypeSuffix(const TBasicType type);
TString SamplerString(const TBasicType type);
TString SamplerString(HLSLTextureSamplerGroup type);
// Prepends an underscore to avoid naming clashes
TString Decorate(const TString &string);
TString DecorateIfNeeded(const TName &name);
......@@ -36,7 +72,7 @@ TString QualifiedStructNameString(const TStructure &structure, bool useHLSLRowMa
bool useStd140Packing);
TString InterpolationString(TQualifier qualifier);
TString QualifierString(TQualifier qualifier);
int HLSLTextureCoordsCount(const TBasicType samplerType);
}
#endif // COMPILER_TRANSLATOR_UTILSHLSL_H_
......@@ -113,9 +113,14 @@ HLSLBlockEncoder::HLSLBlockEncoderStrategy HLSLBlockEncoder::GetStrategyFor(ShSh
{
switch (outputType)
{
case SH_HLSL9_OUTPUT: return ENCODE_LOOSE;
case SH_HLSL11_OUTPUT: return ENCODE_PACKED;
default: UNREACHABLE(); return ENCODE_PACKED;
case SH_HLSL_3_0_OUTPUT:
return ENCODE_LOOSE;
case SH_HLSL_4_1_OUTPUT:
case SH_HLSL_4_0_FL9_3_OUTPUT:
return ENCODE_PACKED;
default:
UNREACHABLE();
return ENCODE_PACKED;
}
}
......
......@@ -3,7 +3,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// CompilerGL:
// CompilerD3D:
// Implementation of the D3D compiler methods.
//
......@@ -12,26 +12,8 @@
namespace rx
{
namespace
{
ShShaderOutput GetShaderOutputType(RendererClass rendererClass)
{
if (rendererClass == RENDERER_D3D11)
{
return SH_HLSL11_OUTPUT;
}
else
{
ASSERT(rendererClass == RENDERER_D3D9);
return SH_HLSL9_OUTPUT;
}
}
} // anonymous namespace
CompilerD3D::CompilerD3D(RendererClass rendererClass)
: mTranslatorOutputType(GetShaderOutputType(rendererClass))
CompilerD3D::CompilerD3D(ShShaderOutput translatorOutputType)
: mTranslatorOutputType(translatorOutputType)
{
}
......
......@@ -18,7 +18,7 @@ namespace rx
class CompilerD3D : public CompilerImpl
{
public:
CompilerD3D(RendererClass rendererClass);
CompilerD3D(ShShaderOutput translatorOutputType);
~CompilerD3D() override {}
gl::Error release() override { return gl::Error(GL_NO_ERROR); }
......
......@@ -16,7 +16,6 @@
#include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/renderer/d3d/BufferD3D.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/DeviceD3D.h"
#include "libANGLE/renderer/d3d/DisplayD3D.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h"
......@@ -70,11 +69,6 @@ void RendererD3D::cleanup()
}
}
CompilerImpl *RendererD3D::createCompiler()
{
return new CompilerD3D(getRendererClass());
}
SamplerImpl *RendererD3D::createSampler()
{
return new SamplerD3D();
......
......@@ -133,8 +133,6 @@ class RendererD3D : public Renderer, public BufferFactoryD3D
bool isDeviceLost() const override;
std::string getVendorString() const override;
CompilerImpl *createCompiler() override;
SamplerImpl *createSampler() override;
virtual int getMinorShaderModel() const = 0;
......
......@@ -42,6 +42,7 @@
#include "libANGLE/renderer/d3d/d3d11/Trim11.h"
#include "libANGLE/renderer/d3d/d3d11/VertexArray11.h"
#include "libANGLE/renderer/d3d/d3d11/VertexBuffer11.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/DeviceD3D.h"
#include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h"
......@@ -1161,6 +1162,18 @@ SwapChainD3D *Renderer11::createSwapChain(NativeWindow nativeWindow,
orientation);
}
CompilerImpl *Renderer11::createCompiler()
{
if (mRenderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3)
{
return new CompilerD3D(SH_HLSL_4_0_FL9_3_OUTPUT);
}
else
{
return new CompilerD3D(SH_HLSL_4_1_OUTPUT);
}
}
void *Renderer11::getD3DDevice()
{
return reinterpret_cast<void*>(mDevice);
......
......@@ -118,6 +118,8 @@ class Renderer11 : public RendererD3D
GLenum depthBufferFormat,
EGLint orientation) override;
CompilerImpl *createCompiler() override;
virtual gl::Error generateSwizzle(gl::Texture *texture);
virtual gl::Error setSamplerState(gl::SamplerType type, int index, gl::Texture *texture, const gl::SamplerState &sampler);
virtual gl::Error setTexture(gl::SamplerType type, int index, gl::Texture *texture);
......
......@@ -36,6 +36,7 @@
#include "libANGLE/renderer/d3d/d3d9/TextureStorage9.h"
#include "libANGLE/renderer/d3d/d3d9/VertexArray9.h"
#include "libANGLE/renderer/d3d/d3d9/VertexBuffer9.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/DeviceD3D.h"
#include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h"
......@@ -663,6 +664,11 @@ SwapChainD3D *Renderer9::createSwapChain(NativeWindow nativeWindow,
orientation);
}
CompilerImpl *Renderer9::createCompiler()
{
return new CompilerD3D(SH_HLSL_3_0_OUTPUT);
}
void *Renderer9::getD3DDevice()
{
return reinterpret_cast<void*>(mDevice);
......
......@@ -85,6 +85,8 @@ class Renderer9 : public RendererD3D
GLenum depthBufferFormat,
EGLint orientation) override;
CompilerImpl *createCompiler() override;
gl::Error allocateEventQuery(IDirect3DQuery9 **outQuery);
void freeEventQuery(IDirect3DQuery9* query);
......
......@@ -26,8 +26,9 @@ class UnrollFlattenTest : public testing::Test
void compile(const std::string &shaderString)
{
std::string infoLog;
bool compilationSuccess = compileTestShader(GL_FRAGMENT_SHADER, SH_GLES2_SPEC, SH_HLSL11_OUTPUT,
shaderString, SH_VARIABLES, &mTranslatedSource, &infoLog);
bool compilationSuccess =
compileTestShader(GL_FRAGMENT_SHADER, SH_GLES2_SPEC, SH_HLSL_4_1_OUTPUT, shaderString,
SH_VARIABLES, &mTranslatedSource, &infoLog);
if (!compilationSuccess)
{
FAIL() << "Shader compilation failed " << infoLog;
......
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