Hash :
10bed9fc
Author :
Date :
2017-06-05T12:59:22
Minor optimizations to DynamicHLSL. This makes us use std::ostringstream in more places, instead of string concatenation. BUG=chromium:697758 Change-Id: Ifdcaa2e7e119664fc9cfdc566ea13b519a294714 Reviewed-on: https://chromium-review.googlesource.com/521729 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
//
// Copyright (c) 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.
//
// DynamicHLSL.h: Interface for link and run-time HLSL generation
//
#ifndef LIBANGLE_RENDERER_D3D_DYNAMICHLSL_H_
#define LIBANGLE_RENDERER_D3D_DYNAMICHLSL_H_
#include <map>
#include <vector>
#include "angle_gl.h"
#include "common/angleutils.h"
#include "libANGLE/Constants.h"
#include "libANGLE/Program.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/RendererD3D.h"
namespace sh
{
struct Attribute;
struct ShaderVariable;
}
namespace gl
{
class InfoLog;
struct VariableLocation;
class VaryingPacking;
struct VertexAttribute;
}
namespace rx
{
class ProgramD3DMetadata;
class ShaderD3D;
struct PixelShaderOutputVariable
{
PixelShaderOutputVariable() {}
PixelShaderOutputVariable(GLenum typeIn,
const std::string &nameIn,
const std::string &sourceIn,
size_t outputIndexIn)
: type(typeIn), name(nameIn), source(sourceIn), outputIndex(outputIndexIn)
{
}
GLenum type = GL_NONE;
std::string name;
std::string source;
size_t outputIndex = 0;
};
struct BuiltinVarying final : private angle::NonCopyable
{
BuiltinVarying();
std::string str() const;
void enableSystem(const std::string &systemValueSemantic);
void enable(const std::string &semanticVal, unsigned int indexVal);
bool enabled;
std::string semantic;
unsigned int index;
bool systemValue;
};
struct BuiltinInfo
{
BuiltinVarying dxPosition;
BuiltinVarying glPosition;
BuiltinVarying glFragCoord;
BuiltinVarying glPointCoord;
BuiltinVarying glPointSize;
};
inline std::string GetVaryingSemantic(int majorShaderModel, bool programUsesPointSize)
{
// SM3 reserves the TEXCOORD semantic for point sprite texcoords (gl_PointCoord)
// In D3D11 we manually compute gl_PointCoord in the GS.
return ((programUsesPointSize && majorShaderModel < 4) ? "COLOR" : "TEXCOORD");
}
class BuiltinVaryingsD3D
{
public:
BuiltinVaryingsD3D(const ProgramD3DMetadata &metadata, const gl::VaryingPacking &packing);
bool usesPointSize() const { return mBuiltinInfo[SHADER_VERTEX].glPointSize.enabled; }
const BuiltinInfo &operator[](ShaderType shaderType) const { return mBuiltinInfo[shaderType]; }
BuiltinInfo &operator[](ShaderType shaderType) { return mBuiltinInfo[shaderType]; }
private:
void updateBuiltins(ShaderType shaderType,
const ProgramD3DMetadata &metadata,
const gl::VaryingPacking &packing);
std::array<BuiltinInfo, SHADER_TYPE_MAX> mBuiltinInfo;
};
class DynamicHLSL : angle::NonCopyable
{
public:
explicit DynamicHLSL(RendererD3D *const renderer);
std::string generateVertexShaderForInputLayout(
const std::string &sourceShader,
const gl::InputLayout &inputLayout,
const std::vector<sh::Attribute> &shaderAttributes) const;
std::string generatePixelShaderForOutputSignature(
const std::string &sourceShader,
const std::vector<PixelShaderOutputVariable> &outputVariables,
bool usesFragDepth,
const std::vector<GLenum> &outputLayout) const;
void generateShaderLinkHLSL(const gl::Context *context,
const gl::ProgramState &programData,
const ProgramD3DMetadata &programMetadata,
const gl::VaryingPacking &varyingPacking,
const BuiltinVaryingsD3D &builtinsD3D,
std::string *pixelHLSL,
std::string *vertexHLSL) const;
std::string generateComputeShaderLinkHLSL(const gl::Context *context,
const gl::ProgramState &programData) const;
std::string generateGeometryShaderPreamble(const gl::VaryingPacking &varyingPacking,
const BuiltinVaryingsD3D &builtinsD3D) const;
std::string generateGeometryShaderHLSL(gl::PrimitiveType primitiveType,
const gl::ContextState &data,
const gl::ProgramState &programData,
const bool useViewScale,
const std::string &preambleString) const;
void getPixelShaderOutputKey(const gl::ContextState &data,
const gl::ProgramState &programData,
const ProgramD3DMetadata &metadata,
std::vector<PixelShaderOutputVariable> *outPixelShaderKey);
private:
RendererD3D *const mRenderer;
void generateVaryingLinkHLSL(const gl::VaryingPacking &varyingPacking,
const BuiltinInfo &builtins,
bool programUsesPointSize,
std::ostringstream &hlslStream) const;
static void GenerateAttributeConversionHLSL(gl::VertexFormatType vertexFormatType,
const sh::ShaderVariable &shaderAttrib,
std::ostringstream &outStream);
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_DYNAMICHLSL_H_