зеркало из https://github.com/AvaloniaUI/angle.git
Disable the HLSL code in Angle if it is not being used.
We're only using the HLSL code in Windows so it's not necessary to compile and distribute it on other platforms. This adds a defined ANGLE_ENABLE_HLSL that can be checked in files that are used by non-HLSL code as well. Mostly the HLSL code is just not include by the build system. Details of the space savings (heavily truncated) Total change: -165717 bytes =========================== -606 - Source: angle/src/common/utilities.cpp -627 - Source: angle/src/compiler/translator/FlagStd140Structs.cpp -695 - Source: /usr/include/c++/4.8/bits/stl_algo.h -710 - Source: angle/src/compiler/translator/TranslatorHLSL.cpp -713 - Source: angle/src/compiler/translator/IntermNode.h -863 - Source: /usr/include/c++/4.8/bits/stl_map.h -935 - Source: angle/src/compiler/translator/blocklayout.cpp -1515 - Source: angle/src/compiler/translator/BuiltInFunctionEmulator.cpp -1655 - Source: angle/src/compiler/translator/UnfoldShortCircuit.cpp -2375 - Source: /usr/include/c++/4.8/bits/vector.tcc -3135 - Source: angle/src/compiler/translator/RewriteElseBlocks.cpp -4656 - Source: angle/src/compiler/translator/UtilsHLSL.cpp -5265 - Source: angle/src/compiler/translator/BuiltInFunctionEmulatorHLSL.cpp -6505 - Source: /usr/include/c++/4.8/bits/stl_tree.h -11480 - Source: angle/src/compiler/translator/UniformHLSL.cpp -13580 - Source: angle/src/compiler/translator/StructureHLSL.cpp -18964 - Source: ?? (constant strings and a few vtbls) -89332 - Source: angle/src/compiler/translator/OutputHLSL.cpp Change-Id: I23ccc98abd0a21f847dd34f9482800b3ba679d56 Reviewed-on: https://chromium-review.googlesource.com/251528 Tested-by: bratell at Opera <bratell@opera.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
This commit is contained in:
Родитель
53f076fac8
Коммит
73941deb4f
53
BUILD.gn
53
BUILD.gn
|
@ -30,6 +30,29 @@ config("internal_config") {
|
|||
]
|
||||
}
|
||||
|
||||
angle_enable_d3d9 = false
|
||||
angle_enable_d3d11 = false
|
||||
angle_enable_gl = false
|
||||
|
||||
if (is_win) {
|
||||
angle_enable_d3d9 = true
|
||||
angle_enable_d3d11 = true
|
||||
angle_enable_gl = true
|
||||
|
||||
import("//build/config/win/visual_studio_version.gni")
|
||||
copy("copy_compiler_dll") {
|
||||
sources = [ "$windows_sdk_path/Redist/D3D/$cpu_arch/d3dcompiler_47.dll" ]
|
||||
outputs = [ "$root_build_dir/d3dcompiler_47.dll" ]
|
||||
}
|
||||
|
||||
} # is_win
|
||||
|
||||
angle_enable_hlsl = false
|
||||
|
||||
if (angle_enable_d3d9 || angle_enable_d3d11) {
|
||||
angle_enable_hlsl = true
|
||||
}
|
||||
|
||||
component("translator") {
|
||||
sources = [
|
||||
"src/compiler/translator/ShaderLang.cpp",
|
||||
|
@ -38,6 +61,11 @@ component("translator") {
|
|||
|
||||
defines = [ "ANGLE_TRANSLATOR_IMPLEMENTATION" ]
|
||||
|
||||
if (angle_enable_hlsl) {
|
||||
sources += rebase_path(compiler_gypi.angle_translator_lib_hlsl_sources, ".", "src")
|
||||
defines += [ "ANGLE_ENABLE_HLSL" ]
|
||||
}
|
||||
|
||||
configs -= [ "//build/config/compiler:chromium_code" ]
|
||||
configs += [
|
||||
":internal_config",
|
||||
|
@ -91,6 +119,10 @@ static_library("angle_common") {
|
|||
static_library("translator_lib") {
|
||||
sources = rebase_path(compiler_gypi.angle_translator_lib_sources, ".", "src")
|
||||
|
||||
if (angle_enable_hlsl) {
|
||||
sources += rebase_path(compiler_gypi.angle_translator_lib_hlsl_sources, ".", "src")
|
||||
defines = [ "ANGLE_ENABLE_HLSL" ]
|
||||
}
|
||||
configs -= [ "//build/config/compiler:chromium_code" ]
|
||||
configs += [
|
||||
":internal_config",
|
||||
|
@ -115,6 +147,10 @@ static_library("translator_static") {
|
|||
"src/compiler/translator/ShaderVars.cpp",
|
||||
]
|
||||
|
||||
if (angle_enable_hlsl) {
|
||||
defines = [ "ANGLE_ENABLE_HLSL" ]
|
||||
}
|
||||
|
||||
configs -= [ "//build/config/compiler:chromium_code" ]
|
||||
configs += [
|
||||
":internal_config",
|
||||
|
@ -146,23 +182,6 @@ action("commit_id") {
|
|||
public_configs = [ ":commit_id_config" ]
|
||||
}
|
||||
|
||||
angle_enable_d3d9 = false
|
||||
angle_enable_d3d11 = false
|
||||
angle_enable_gl = false
|
||||
|
||||
if (is_win) {
|
||||
angle_enable_d3d9 = true
|
||||
angle_enable_d3d11 = true
|
||||
angle_enable_gl = true
|
||||
|
||||
import("//build/config/win/visual_studio_version.gni")
|
||||
copy("copy_compiler_dll") {
|
||||
sources = [ "$windows_sdk_path/Redist/D3D/$cpu_arch/d3dcompiler_47.dll" ]
|
||||
outputs = [ "$root_build_dir/d3dcompiler_47.dll" ]
|
||||
}
|
||||
|
||||
} # is_win
|
||||
|
||||
config("libANGLE_config") {
|
||||
cflags = []
|
||||
defines = []
|
||||
|
|
|
@ -83,6 +83,8 @@ typedef enum {
|
|||
typedef enum {
|
||||
SH_ESSL_OUTPUT = 0x8B45,
|
||||
SH_GLSL_OUTPUT = 0x8B46,
|
||||
|
||||
// HLSL output only supported in some configurations.
|
||||
SH_HLSL_OUTPUT = 0x8B47,
|
||||
SH_HLSL9_OUTPUT = 0x8B47,
|
||||
SH_HLSL11_OUTPUT = 0x8B48
|
||||
|
@ -294,7 +296,8 @@ COMPILER_EXPORT const std::string &ShGetBuiltInResourcesString(const ShHandle ha
|
|||
// 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.
|
||||
// SH_HLSL9_OUTPUT or SH_HLSL11_OUTPUT. Note: HLSL output is only
|
||||
// supported in some configurations.
|
||||
// resources: Specifies the built-in resources.
|
||||
COMPILER_EXPORT ShHandle ShConstructCompiler(
|
||||
sh::GLenum type,
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
'angle_enable_d3d9%': 0,
|
||||
'angle_enable_d3d11%': 0,
|
||||
'angle_enable_gl%': 0,
|
||||
'angle_enable_hlsl%': 0,
|
||||
'conditions':
|
||||
[
|
||||
['OS=="win"',
|
||||
|
@ -23,6 +24,7 @@
|
|||
'angle_enable_gl%': 1,
|
||||
'angle_enable_d3d9%': 1,
|
||||
'angle_enable_d3d11%': 1,
|
||||
'angle_enable_hlsl%': 1,
|
||||
}],
|
||||
],
|
||||
},
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
{
|
||||
'variables':
|
||||
{
|
||||
# This file list is shared with the GN build.
|
||||
# These file lists are shared with the GN build.
|
||||
'angle_translator_lib_sources':
|
||||
[
|
||||
'../include/EGL/egl.h',
|
||||
|
@ -26,8 +26,6 @@
|
|||
'compiler/translator/BuiltInFunctionEmulator.h',
|
||||
'compiler/translator/BuiltInFunctionEmulatorGLSL.cpp',
|
||||
'compiler/translator/BuiltInFunctionEmulatorGLSL.h',
|
||||
'compiler/translator/BuiltInFunctionEmulatorHLSL.cpp',
|
||||
'compiler/translator/BuiltInFunctionEmulatorHLSL.h',
|
||||
'compiler/translator/CodeGen.cpp',
|
||||
'compiler/translator/Common.h',
|
||||
'compiler/translator/Compiler.cpp',
|
||||
|
@ -35,8 +33,6 @@
|
|||
'compiler/translator/ConstantUnion.h',
|
||||
'compiler/translator/DetectCallDepth.cpp',
|
||||
'compiler/translator/DetectCallDepth.h',
|
||||
'compiler/translator/DetectDiscontinuity.cpp',
|
||||
'compiler/translator/DetectDiscontinuity.h',
|
||||
'compiler/translator/Diagnostics.cpp',
|
||||
'compiler/translator/Diagnostics.h',
|
||||
'compiler/translator/DirectiveHandler.cpp',
|
||||
|
@ -60,11 +56,11 @@
|
|||
'compiler/translator/InitializeParseContext.h',
|
||||
'compiler/translator/InitializeVariables.cpp',
|
||||
'compiler/translator/InitializeVariables.h',
|
||||
'compiler/translator/IntermNode.h',
|
||||
'compiler/translator/IntermNode.cpp',
|
||||
'compiler/translator/IntermTraverse.cpp',
|
||||
'compiler/translator/Intermediate.h',
|
||||
'compiler/translator/Intermediate.cpp',
|
||||
'compiler/translator/IntermNode.h',
|
||||
'compiler/translator/IntermNode.cpp',
|
||||
'compiler/translator/LoopInfo.cpp',
|
||||
'compiler/translator/LoopInfo.h',
|
||||
'compiler/translator/MMap.h',
|
||||
|
@ -77,8 +73,6 @@
|
|||
'compiler/translator/OutputGLSL.h',
|
||||
'compiler/translator/OutputGLSLBase.cpp',
|
||||
'compiler/translator/OutputGLSLBase.h',
|
||||
'compiler/translator/OutputHLSL.cpp',
|
||||
'compiler/translator/OutputHLSL.h',
|
||||
'compiler/translator/ParseContext.cpp',
|
||||
'compiler/translator/ParseContext.h',
|
||||
'compiler/translator/PoolAlloc.cpp',
|
||||
|
@ -89,32 +83,20 @@
|
|||
'compiler/translator/RegenerateStructNames.cpp',
|
||||
'compiler/translator/RegenerateStructNames.h',
|
||||
'compiler/translator/RenameFunction.h',
|
||||
'compiler/translator/RewriteElseBlocks.cpp',
|
||||
'compiler/translator/RewriteElseBlocks.h',
|
||||
'compiler/translator/ScalarizeVecAndMatConstructorArgs.cpp',
|
||||
'compiler/translator/ScalarizeVecAndMatConstructorArgs.h',
|
||||
'compiler/translator/SearchSymbol.cpp',
|
||||
'compiler/translator/SearchSymbol.h',
|
||||
'compiler/translator/StructureHLSL.cpp',
|
||||
'compiler/translator/StructureHLSL.h',
|
||||
'compiler/translator/SymbolTable.cpp',
|
||||
'compiler/translator/SymbolTable.h',
|
||||
'compiler/translator/TranslatorESSL.cpp',
|
||||
'compiler/translator/TranslatorESSL.h',
|
||||
'compiler/translator/TranslatorGLSL.cpp',
|
||||
'compiler/translator/TranslatorGLSL.h',
|
||||
'compiler/translator/TranslatorHLSL.cpp',
|
||||
'compiler/translator/TranslatorHLSL.h',
|
||||
'compiler/translator/Types.cpp',
|
||||
'compiler/translator/Types.h',
|
||||
'compiler/translator/UnfoldShortCircuit.cpp',
|
||||
'compiler/translator/UnfoldShortCircuit.h',
|
||||
'compiler/translator/UnfoldShortCircuitAST.cpp',
|
||||
'compiler/translator/UnfoldShortCircuitAST.h',
|
||||
'compiler/translator/UniformHLSL.cpp',
|
||||
'compiler/translator/UniformHLSL.h',
|
||||
'compiler/translator/UtilsHLSL.cpp',
|
||||
'compiler/translator/UtilsHLSL.h',
|
||||
'compiler/translator/ValidateLimitations.cpp',
|
||||
'compiler/translator/ValidateLimitations.h',
|
||||
'compiler/translator/ValidateOutputs.cpp',
|
||||
|
@ -155,6 +137,29 @@
|
|||
'third_party/compiler/ArrayBoundsClamper.cpp',
|
||||
'third_party/compiler/ArrayBoundsClamper.h',
|
||||
],
|
||||
'angle_translator_lib_hlsl_sources':
|
||||
[
|
||||
'compiler/translator/blocklayoutHLSL.cpp',
|
||||
'compiler/translator/blocklayoutHLSL.h',
|
||||
'compiler/translator/BuiltInFunctionEmulatorHLSL.cpp',
|
||||
'compiler/translator/BuiltInFunctionEmulatorHLSL.h',
|
||||
'compiler/translator/DetectDiscontinuity.cpp',
|
||||
'compiler/translator/DetectDiscontinuity.h',
|
||||
'compiler/translator/OutputHLSL.cpp',
|
||||
'compiler/translator/OutputHLSL.h',
|
||||
'compiler/translator/RewriteElseBlocks.cpp',
|
||||
'compiler/translator/RewriteElseBlocks.h',
|
||||
'compiler/translator/StructureHLSL.cpp',
|
||||
'compiler/translator/StructureHLSL.h',
|
||||
'compiler/translator/TranslatorHLSL.cpp',
|
||||
'compiler/translator/TranslatorHLSL.h',
|
||||
'compiler/translator/UnfoldShortCircuit.cpp',
|
||||
'compiler/translator/UnfoldShortCircuit.h',
|
||||
'compiler/translator/UniformHLSL.cpp',
|
||||
'compiler/translator/UniformHLSL.h',
|
||||
'compiler/translator/UtilsHLSL.cpp',
|
||||
'compiler/translator/UtilsHLSL.h',
|
||||
],
|
||||
'angle_preprocessor_sources':
|
||||
[
|
||||
'compiler/preprocessor/DiagnosticsBase.cpp',
|
||||
|
@ -244,6 +249,24 @@
|
|||
{
|
||||
'msvs_enable_winphone' : '1',
|
||||
}],
|
||||
['angle_enable_hlsl==1',
|
||||
{
|
||||
'defines':
|
||||
[
|
||||
'ANGLE_ENABLE_HLSL',
|
||||
],
|
||||
'direct_dependent_settings':
|
||||
{
|
||||
'defines':
|
||||
[
|
||||
'ANGLE_ENABLE_HLSL',
|
||||
],
|
||||
},
|
||||
'sources':
|
||||
[
|
||||
'<@(angle_translator_lib_hlsl_sources)',
|
||||
],
|
||||
}],
|
||||
],
|
||||
},
|
||||
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
#include "compiler/translator/TranslatorESSL.h"
|
||||
#include "compiler/translator/TranslatorGLSL.h"
|
||||
#ifdef ANGLE_ENABLE_HLSL
|
||||
#include "compiler/translator/TranslatorHLSL.h"
|
||||
#endif // ANGLE_ENABLE_HLSL
|
||||
|
||||
//
|
||||
// This function must be provided to create the actual
|
||||
|
@ -23,8 +25,15 @@ TCompiler* ConstructCompiler(
|
|||
return new TranslatorGLSL(type, spec);
|
||||
case SH_HLSL9_OUTPUT:
|
||||
case SH_HLSL11_OUTPUT:
|
||||
#ifdef ANGLE_ENABLE_HLSL
|
||||
return new TranslatorHLSL(type, spec, output);
|
||||
#else
|
||||
// This compiler is not supported in this
|
||||
// configuration. Return NULL per the ShConstructCompiler API.
|
||||
return NULL;
|
||||
#endif // ANGLE_ENABLE_HLSL
|
||||
default:
|
||||
// Unknown format. Return NULL per the ShConstructCompiler API.
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
|
||||
class TCompiler;
|
||||
class TDependencyGraph;
|
||||
#ifdef ANGLE_ENABLE_HLSL
|
||||
class TranslatorHLSL;
|
||||
#endif // ANGLE_ENABLE_HLSL
|
||||
|
||||
//
|
||||
// Helper function to identify specs that are based on the WebGL spec,
|
||||
|
@ -41,7 +43,9 @@ public:
|
|||
TShHandleBase();
|
||||
virtual ~TShHandleBase();
|
||||
virtual TCompiler* getAsCompiler() { return 0; }
|
||||
#ifdef ANGLE_ENABLE_HLSL
|
||||
virtual TranslatorHLSL* getAsTranslatorHLSL() { return 0; }
|
||||
#endif // ANGLE_ENABLE_HLSL
|
||||
|
||||
protected:
|
||||
// Memory allocator. Allocates and tracks memory required by the compiler.
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include "compiler/translator/SearchSymbol.h"
|
||||
|
||||
#include "compiler/translator/InfoSink.h"
|
||||
#include "compiler/translator/OutputHLSL.h"
|
||||
|
||||
namespace sh
|
||||
{
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
#include "compiler/translator/Compiler.h"
|
||||
#include "compiler/translator/InitializeDll.h"
|
||||
#include "compiler/translator/length_limits.h"
|
||||
#ifdef ANGLE_ENABLE_HLSL
|
||||
#include "compiler/translator/TranslatorHLSL.h"
|
||||
#endif // ANGLE_ENABLE_HLSL
|
||||
#include "compiler/translator/VariablePacker.h"
|
||||
#include "angle_gl.h"
|
||||
|
||||
|
@ -92,6 +94,7 @@ TCompiler *GetCompilerFromHandle(ShHandle handle)
|
|||
return base->getAsCompiler();
|
||||
}
|
||||
|
||||
#ifdef ANGLE_ENABLE_HLSL
|
||||
TranslatorHLSL *GetTranslatorHLSLFromHandle(ShHandle handle)
|
||||
{
|
||||
if (!handle)
|
||||
|
@ -99,6 +102,7 @@ TranslatorHLSL *GetTranslatorHLSLFromHandle(ShHandle handle)
|
|||
TShHandleBase *base = static_cast<TShHandleBase *>(handle);
|
||||
return base->getAsTranslatorHLSL();
|
||||
}
|
||||
#endif // ANGLE_ENABLE_HLSL
|
||||
|
||||
} // namespace anonymous
|
||||
|
||||
|
@ -327,6 +331,7 @@ bool ShGetInterfaceBlockRegister(const ShHandle handle,
|
|||
const std::string &interfaceBlockName,
|
||||
unsigned int *indexOut)
|
||||
{
|
||||
#ifdef ANGLE_ENABLE_HLSL
|
||||
ASSERT(indexOut);
|
||||
|
||||
TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
|
||||
|
@ -339,12 +344,16 @@ bool ShGetInterfaceBlockRegister(const ShHandle handle,
|
|||
|
||||
*indexOut = translator->getInterfaceBlockRegister(interfaceBlockName);
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif // ANGLE_ENABLE_HLSL
|
||||
}
|
||||
|
||||
bool ShGetUniformRegister(const ShHandle handle,
|
||||
const std::string &uniformName,
|
||||
unsigned int *indexOut)
|
||||
{
|
||||
#ifdef ANGLE_ENABLE_HLSL
|
||||
ASSERT(indexOut);
|
||||
TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
|
||||
ASSERT(translator);
|
||||
|
@ -356,4 +365,7 @@ bool ShGetUniformRegister(const ShHandle handle,
|
|||
|
||||
*indexOut = translator->getUniformRegister(uniformName);
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif // ANGLE_ENABLE_HLSL
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "common/utilities.h"
|
||||
#include "compiler/translator/StructureHLSL.h"
|
||||
#include "compiler/translator/UtilsHLSL.h"
|
||||
#include "compiler/translator/blocklayout.h"
|
||||
#include "compiler/translator/blocklayoutHLSL.h"
|
||||
#include "compiler/translator/util.h"
|
||||
|
||||
namespace sh
|
||||
|
|
|
@ -120,151 +120,4 @@ void Std140BlockEncoder::advanceOffset(GLenum type, unsigned int arraySize, bool
|
|||
}
|
||||
}
|
||||
|
||||
HLSLBlockEncoder::HLSLBlockEncoder(HLSLBlockEncoderStrategy strategy)
|
||||
: mEncoderStrategy(strategy),
|
||||
mTransposeMatrices(false)
|
||||
{
|
||||
}
|
||||
|
||||
void HLSLBlockEncoder::enterAggregateType()
|
||||
{
|
||||
nextRegister();
|
||||
}
|
||||
|
||||
void HLSLBlockEncoder::exitAggregateType()
|
||||
{
|
||||
}
|
||||
|
||||
void HLSLBlockEncoder::getBlockLayoutInfo(GLenum typeIn, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut)
|
||||
{
|
||||
GLenum type = (mTransposeMatrices ? gl::TransposeMatrixType(typeIn) : typeIn);
|
||||
|
||||
// We assume we are only dealing with 4 byte components (no doubles or half-words currently)
|
||||
ASSERT(gl::VariableComponentSize(gl::VariableComponentType(type)) == BytesPerComponent);
|
||||
|
||||
int matrixStride = 0;
|
||||
int arrayStride = 0;
|
||||
|
||||
// if variables are not to be packed, or we're about to
|
||||
// pack a matrix or array, skip to the start of the next
|
||||
// register
|
||||
if (!isPacked() ||
|
||||
gl::IsMatrixType(type) ||
|
||||
arraySize > 0)
|
||||
{
|
||||
nextRegister();
|
||||
}
|
||||
|
||||
if (gl::IsMatrixType(type))
|
||||
{
|
||||
matrixStride = ComponentsPerRegister;
|
||||
|
||||
if (arraySize > 0)
|
||||
{
|
||||
const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
|
||||
arrayStride = ComponentsPerRegister * numRegisters;
|
||||
}
|
||||
}
|
||||
else if (arraySize > 0)
|
||||
{
|
||||
arrayStride = ComponentsPerRegister;
|
||||
}
|
||||
else if (isPacked())
|
||||
{
|
||||
int numComponents = gl::VariableComponentCount(type);
|
||||
if ((numComponents + (mCurrentOffset % ComponentsPerRegister)) > ComponentsPerRegister)
|
||||
{
|
||||
nextRegister();
|
||||
}
|
||||
}
|
||||
|
||||
*matrixStrideOut = matrixStride;
|
||||
*arrayStrideOut = arrayStride;
|
||||
}
|
||||
|
||||
void HLSLBlockEncoder::advanceOffset(GLenum typeIn, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride)
|
||||
{
|
||||
GLenum type = (mTransposeMatrices ? gl::TransposeMatrixType(typeIn) : typeIn);
|
||||
|
||||
if (arraySize > 0)
|
||||
{
|
||||
mCurrentOffset += arrayStride * (arraySize - 1);
|
||||
}
|
||||
|
||||
if (gl::IsMatrixType(type))
|
||||
{
|
||||
ASSERT(matrixStride == ComponentsPerRegister);
|
||||
const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
|
||||
const int numComponents = gl::MatrixComponentCount(type, isRowMajorMatrix);
|
||||
mCurrentOffset += ComponentsPerRegister * (numRegisters - 1);
|
||||
mCurrentOffset += numComponents;
|
||||
}
|
||||
else if (isPacked())
|
||||
{
|
||||
mCurrentOffset += gl::VariableComponentCount(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
mCurrentOffset += ComponentsPerRegister;
|
||||
}
|
||||
}
|
||||
|
||||
void HLSLBlockEncoder::skipRegisters(unsigned int numRegisters)
|
||||
{
|
||||
mCurrentOffset += (numRegisters * ComponentsPerRegister);
|
||||
}
|
||||
|
||||
HLSLBlockEncoder::HLSLBlockEncoderStrategy HLSLBlockEncoder::GetStrategyFor(ShShaderOutput outputType)
|
||||
{
|
||||
switch (outputType)
|
||||
{
|
||||
case SH_HLSL9_OUTPUT: return ENCODE_LOOSE;
|
||||
case SH_HLSL11_OUTPUT: return ENCODE_PACKED;
|
||||
default: UNREACHABLE(); return ENCODE_PACKED;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ShaderVarType>
|
||||
void HLSLVariableRegisterCount(const ShaderVarType &variable, HLSLBlockEncoder *encoder)
|
||||
{
|
||||
if (variable.isStruct())
|
||||
{
|
||||
for (size_t arrayElement = 0; arrayElement < variable.elementCount(); arrayElement++)
|
||||
{
|
||||
encoder->enterAggregateType();
|
||||
|
||||
for (size_t fieldIndex = 0; fieldIndex < variable.fields.size(); fieldIndex++)
|
||||
{
|
||||
HLSLVariableRegisterCount(variable.fields[fieldIndex], encoder);
|
||||
}
|
||||
|
||||
encoder->exitAggregateType();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We operate only on varyings and uniforms, which do not have matrix layout qualifiers
|
||||
encoder->encodeType(variable.type, variable.arraySize, false);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int HLSLVariableRegisterCount(const Varying &variable, bool transposeMatrices)
|
||||
{
|
||||
HLSLBlockEncoder encoder(HLSLBlockEncoder::ENCODE_PACKED);
|
||||
encoder.setTransposeMatrices(transposeMatrices);
|
||||
HLSLVariableRegisterCount(variable, &encoder);
|
||||
|
||||
const size_t registerBytes = (encoder.BytesPerComponent * encoder.ComponentsPerRegister);
|
||||
return static_cast<unsigned int>(rx::roundUp<size_t>(encoder.getBlockSize(), registerBytes) / registerBytes);
|
||||
}
|
||||
|
||||
unsigned int HLSLVariableRegisterCount(const Uniform &variable, ShShaderOutput outputType)
|
||||
{
|
||||
HLSLBlockEncoder encoder(HLSLBlockEncoder::GetStrategyFor(outputType));
|
||||
HLSLVariableRegisterCount(variable, &encoder);
|
||||
|
||||
const size_t registerBytes = (encoder.BytesPerComponent * encoder.ComponentsPerRegister);
|
||||
return static_cast<unsigned int>(rx::roundUp<size_t>(encoder.getBlockSize(), registerBytes) / registerBytes);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -89,44 +89,6 @@ class COMPILER_EXPORT Std140BlockEncoder : public BlockLayoutEncoder
|
|||
virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
|
||||
};
|
||||
|
||||
// Block layout packed according to the D3D9 or default D3D10+ register packing rules
|
||||
// See http://msdn.microsoft.com/en-us/library/windows/desktop/bb509632(v=vs.85).aspx
|
||||
// The strategy should be ENCODE_LOOSE for D3D9 constant blocks, and ENCODE_PACKED
|
||||
// for everything else (D3D10+ constant blocks and all attributes/varyings).
|
||||
|
||||
class COMPILER_EXPORT HLSLBlockEncoder : public BlockLayoutEncoder
|
||||
{
|
||||
public:
|
||||
enum HLSLBlockEncoderStrategy
|
||||
{
|
||||
ENCODE_PACKED,
|
||||
ENCODE_LOOSE
|
||||
};
|
||||
|
||||
HLSLBlockEncoder(HLSLBlockEncoderStrategy strategy);
|
||||
|
||||
virtual void enterAggregateType();
|
||||
virtual void exitAggregateType();
|
||||
void skipRegisters(unsigned int numRegisters);
|
||||
|
||||
bool isPacked() const { return mEncoderStrategy == ENCODE_PACKED; }
|
||||
void setTransposeMatrices(bool enabled) { mTransposeMatrices = enabled; }
|
||||
|
||||
static HLSLBlockEncoderStrategy GetStrategyFor(ShShaderOutput outputType);
|
||||
|
||||
protected:
|
||||
virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut);
|
||||
virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
|
||||
|
||||
HLSLBlockEncoderStrategy mEncoderStrategy;
|
||||
bool mTransposeMatrices;
|
||||
};
|
||||
|
||||
// This method returns the number of used registers for a ShaderVariable. It is dependent on the HLSLBlockEncoder
|
||||
// class to count the number of used registers in a struct (which are individually packed according to the same rules).
|
||||
COMPILER_EXPORT unsigned int HLSLVariableRegisterCount(const Varying &variable, bool transposeMatrices);
|
||||
COMPILER_EXPORT unsigned int HLSLVariableRegisterCount(const Uniform &variable, ShShaderOutput outputType);
|
||||
|
||||
}
|
||||
|
||||
#endif // COMMON_BLOCKLAYOUT_H_
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
//
|
||||
// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
//
|
||||
// blocklayout.cpp:
|
||||
// Implementation for block layout classes and methods.
|
||||
//
|
||||
|
||||
#include "compiler/translator/blocklayoutHLSL.h"
|
||||
|
||||
#include "common/mathutil.h"
|
||||
#include "common/utilities.h"
|
||||
|
||||
namespace sh
|
||||
{
|
||||
|
||||
HLSLBlockEncoder::HLSLBlockEncoder(HLSLBlockEncoderStrategy strategy)
|
||||
: mEncoderStrategy(strategy),
|
||||
mTransposeMatrices(false)
|
||||
{
|
||||
}
|
||||
|
||||
void HLSLBlockEncoder::enterAggregateType()
|
||||
{
|
||||
nextRegister();
|
||||
}
|
||||
|
||||
void HLSLBlockEncoder::exitAggregateType()
|
||||
{
|
||||
}
|
||||
|
||||
void HLSLBlockEncoder::getBlockLayoutInfo(GLenum typeIn, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut)
|
||||
{
|
||||
GLenum type = (mTransposeMatrices ? gl::TransposeMatrixType(typeIn) : typeIn);
|
||||
|
||||
// We assume we are only dealing with 4 byte components (no doubles or half-words currently)
|
||||
ASSERT(gl::VariableComponentSize(gl::VariableComponentType(type)) == BytesPerComponent);
|
||||
|
||||
int matrixStride = 0;
|
||||
int arrayStride = 0;
|
||||
|
||||
// if variables are not to be packed, or we're about to
|
||||
// pack a matrix or array, skip to the start of the next
|
||||
// register
|
||||
if (!isPacked() ||
|
||||
gl::IsMatrixType(type) ||
|
||||
arraySize > 0)
|
||||
{
|
||||
nextRegister();
|
||||
}
|
||||
|
||||
if (gl::IsMatrixType(type))
|
||||
{
|
||||
matrixStride = ComponentsPerRegister;
|
||||
|
||||
if (arraySize > 0)
|
||||
{
|
||||
const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
|
||||
arrayStride = ComponentsPerRegister * numRegisters;
|
||||
}
|
||||
}
|
||||
else if (arraySize > 0)
|
||||
{
|
||||
arrayStride = ComponentsPerRegister;
|
||||
}
|
||||
else if (isPacked())
|
||||
{
|
||||
int numComponents = gl::VariableComponentCount(type);
|
||||
if ((numComponents + (mCurrentOffset % ComponentsPerRegister)) > ComponentsPerRegister)
|
||||
{
|
||||
nextRegister();
|
||||
}
|
||||
}
|
||||
|
||||
*matrixStrideOut = matrixStride;
|
||||
*arrayStrideOut = arrayStride;
|
||||
}
|
||||
|
||||
void HLSLBlockEncoder::advanceOffset(GLenum typeIn, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride)
|
||||
{
|
||||
GLenum type = (mTransposeMatrices ? gl::TransposeMatrixType(typeIn) : typeIn);
|
||||
|
||||
if (arraySize > 0)
|
||||
{
|
||||
mCurrentOffset += arrayStride * (arraySize - 1);
|
||||
}
|
||||
|
||||
if (gl::IsMatrixType(type))
|
||||
{
|
||||
ASSERT(matrixStride == ComponentsPerRegister);
|
||||
const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix);
|
||||
const int numComponents = gl::MatrixComponentCount(type, isRowMajorMatrix);
|
||||
mCurrentOffset += ComponentsPerRegister * (numRegisters - 1);
|
||||
mCurrentOffset += numComponents;
|
||||
}
|
||||
else if (isPacked())
|
||||
{
|
||||
mCurrentOffset += gl::VariableComponentCount(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
mCurrentOffset += ComponentsPerRegister;
|
||||
}
|
||||
}
|
||||
|
||||
void HLSLBlockEncoder::skipRegisters(unsigned int numRegisters)
|
||||
{
|
||||
mCurrentOffset += (numRegisters * ComponentsPerRegister);
|
||||
}
|
||||
|
||||
HLSLBlockEncoder::HLSLBlockEncoderStrategy HLSLBlockEncoder::GetStrategyFor(ShShaderOutput outputType)
|
||||
{
|
||||
switch (outputType)
|
||||
{
|
||||
case SH_HLSL9_OUTPUT: return ENCODE_LOOSE;
|
||||
case SH_HLSL11_OUTPUT: return ENCODE_PACKED;
|
||||
default: UNREACHABLE(); return ENCODE_PACKED;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ShaderVarType>
|
||||
void HLSLVariableRegisterCount(const ShaderVarType &variable, HLSLBlockEncoder *encoder)
|
||||
{
|
||||
if (variable.isStruct())
|
||||
{
|
||||
for (size_t arrayElement = 0; arrayElement < variable.elementCount(); arrayElement++)
|
||||
{
|
||||
encoder->enterAggregateType();
|
||||
|
||||
for (size_t fieldIndex = 0; fieldIndex < variable.fields.size(); fieldIndex++)
|
||||
{
|
||||
HLSLVariableRegisterCount(variable.fields[fieldIndex], encoder);
|
||||
}
|
||||
|
||||
encoder->exitAggregateType();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We operate only on varyings and uniforms, which do not have matrix layout qualifiers
|
||||
encoder->encodeType(variable.type, variable.arraySize, false);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int HLSLVariableRegisterCount(const Varying &variable, bool transposeMatrices)
|
||||
{
|
||||
HLSLBlockEncoder encoder(HLSLBlockEncoder::ENCODE_PACKED);
|
||||
encoder.setTransposeMatrices(transposeMatrices);
|
||||
HLSLVariableRegisterCount(variable, &encoder);
|
||||
|
||||
const size_t registerBytes = (encoder.BytesPerComponent * encoder.ComponentsPerRegister);
|
||||
return static_cast<unsigned int>(rx::roundUp<size_t>(encoder.getBlockSize(), registerBytes) / registerBytes);
|
||||
}
|
||||
|
||||
unsigned int HLSLVariableRegisterCount(const Uniform &variable, ShShaderOutput outputType)
|
||||
{
|
||||
HLSLBlockEncoder encoder(HLSLBlockEncoder::GetStrategyFor(outputType));
|
||||
HLSLVariableRegisterCount(variable, &encoder);
|
||||
|
||||
const size_t registerBytes = (encoder.BytesPerComponent * encoder.ComponentsPerRegister);
|
||||
return static_cast<unsigned int>(rx::roundUp<size_t>(encoder.getBlockSize(), registerBytes) / registerBytes);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
//
|
||||
// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
//
|
||||
// blocklayout.h:
|
||||
// Methods and classes related to uniform layout and packing in GLSL and HLSL.
|
||||
//
|
||||
|
||||
#ifndef COMMON_BLOCKLAYOUTHLSL_H_
|
||||
#define COMMON_BLOCKLAYOUTHLSL_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
#include "angle_gl.h"
|
||||
#include "blocklayout.h"
|
||||
#include <GLSLANG/ShaderLang.h>
|
||||
|
||||
namespace sh
|
||||
{
|
||||
// Block layout packed according to the D3D9 or default D3D10+ register packing rules
|
||||
// See http://msdn.microsoft.com/en-us/library/windows/desktop/bb509632(v=vs.85).aspx
|
||||
// The strategy should be ENCODE_LOOSE for D3D9 constant blocks, and ENCODE_PACKED
|
||||
// for everything else (D3D10+ constant blocks and all attributes/varyings).
|
||||
|
||||
class COMPILER_EXPORT HLSLBlockEncoder : public BlockLayoutEncoder
|
||||
{
|
||||
public:
|
||||
enum HLSLBlockEncoderStrategy
|
||||
{
|
||||
ENCODE_PACKED,
|
||||
ENCODE_LOOSE
|
||||
};
|
||||
|
||||
HLSLBlockEncoder(HLSLBlockEncoderStrategy strategy);
|
||||
|
||||
virtual void enterAggregateType();
|
||||
virtual void exitAggregateType();
|
||||
void skipRegisters(unsigned int numRegisters);
|
||||
|
||||
bool isPacked() const { return mEncoderStrategy == ENCODE_PACKED; }
|
||||
void setTransposeMatrices(bool enabled) { mTransposeMatrices = enabled; }
|
||||
|
||||
static HLSLBlockEncoderStrategy GetStrategyFor(ShShaderOutput outputType);
|
||||
|
||||
protected:
|
||||
virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut);
|
||||
virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
|
||||
|
||||
HLSLBlockEncoderStrategy mEncoderStrategy;
|
||||
bool mTransposeMatrices;
|
||||
};
|
||||
|
||||
// This method returns the number of used registers for a ShaderVariable. It is dependent on the HLSLBlockEncoder
|
||||
// class to count the number of used registers in a struct (which are individually packed according to the same rules).
|
||||
COMPILER_EXPORT unsigned int HLSLVariableRegisterCount(const Varying &variable, bool transposeMatrices);
|
||||
COMPILER_EXPORT unsigned int HLSLVariableRegisterCount(const Uniform &variable, ShShaderOutput outputType);
|
||||
|
||||
}
|
||||
|
||||
#endif // COMMON_BLOCKLAYOUTHLSL_H_
|
|
@ -9,7 +9,7 @@
|
|||
#include "libANGLE/renderer/d3d/DynamicHLSL.h"
|
||||
|
||||
#include "common/utilities.h"
|
||||
#include "compiler/translator/blocklayout.h"
|
||||
#include "compiler/translator/blocklayoutHLSL.h"
|
||||
#include "libANGLE/renderer/d3d/ShaderD3D.h"
|
||||
#include "libANGLE/renderer/d3d/RendererD3D.h"
|
||||
#include "libANGLE/Program.h"
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#ifndef LIBANGLE_RENDERER_D3D_PROGRAMD3D_H_
|
||||
#define LIBANGLE_RENDERER_D3D_PROGRAMD3D_H_
|
||||
|
||||
#include "compiler/translator/blocklayoutHLSL.h"
|
||||
#include "libANGLE/Constants.h"
|
||||
#include "libANGLE/renderer/ProgramImpl.h"
|
||||
#include "libANGLE/renderer/Workarounds.h"
|
||||
|
|
Загрузка…
Ссылка в новой задаче