diff options
Diffstat (limited to 'src/3rdparty/angle/src/libANGLE/renderer/d3d/ProgramD3D.h')
-rw-r--r-- | src/3rdparty/angle/src/libANGLE/renderer/d3d/ProgramD3D.h | 329 |
1 files changed, 221 insertions, 108 deletions
diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/ProgramD3D.h b/src/3rdparty/angle/src/libANGLE/renderer/d3d/ProgramD3D.h index 3dfe52db1c..829757a73e 100644 --- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/ProgramD3D.h +++ b/src/3rdparty/angle/src/libANGLE/renderer/d3d/ProgramD3D.h @@ -17,7 +17,7 @@ #include "libANGLE/formatutils.h" #include "libANGLE/renderer/ProgramImpl.h" #include "libANGLE/renderer/d3d/DynamicHLSL.h" -#include "libANGLE/renderer/d3d/WorkaroundsD3D.h" +#include "platform/WorkaroundsD3D.h" namespace rx { @@ -32,52 +32,71 @@ class ShaderExecutableD3D; #endif // Helper struct representing a single shader uniform -struct D3DUniform : angle::NonCopyable +// TODO(jmadill): Make uniform blocks shared between all programs, so we don't need separate +// register indices. +struct D3DUniform : private angle::NonCopyable { - D3DUniform(GLenum typeIn, + D3DUniform(GLenum type, const std::string &nameIn, - unsigned int arraySizeIn, + const std::vector<unsigned int> &arraySizesIn, bool defaultBlock); ~D3DUniform(); bool isSampler() const; - unsigned int elementCount() const { return std::max(1u, arraySize); } + + bool isArray() const { return !arraySizes.empty(); } + unsigned int getArraySizeProduct() const; + bool isReferencedByVertexShader() const; bool isReferencedByFragmentShader() const; + bool isReferencedByComputeShader() const; - // Duplicated from the GL layer - GLenum type; - std::string name; - unsigned int arraySize; + const uint8_t *firstNonNullData() const; + const uint8_t *getDataPtrToElement(size_t elementIndex) const; - // Pointer to a system copy of the data. - // TODO(jmadill): remove this in favor of gl::LinkedUniform::data(). - uint8_t *data; + // Duplicated from the GL layer + const gl::UniformTypeInfo &typeInfo; + std::string name; // Names of arrays don't include [0], unlike at the GL layer. + std::vector<unsigned int> arraySizes; - // Has the data been updated since the last sync? - bool dirty; + // Pointer to a system copies of the data. Separate pointers for each uniform storage type. + uint8_t *vsData; + uint8_t *psData; + uint8_t *csData; // Register information. unsigned int vsRegisterIndex; unsigned int psRegisterIndex; + unsigned int csRegisterIndex; unsigned int registerCount; // Register "elements" are used for uniform structs in ES3, to appropriately identify single // uniforms // inside aggregate types, which are packed according C-like structure rules. unsigned int registerElement; + + // Special buffer for sampler values. + std::vector<GLint> mSamplerData; }; struct D3DUniformBlock { - D3DUniformBlock() : vsRegisterIndex(GL_INVALID_INDEX), psRegisterIndex(GL_INVALID_INDEX) {} + D3DUniformBlock() + : vsRegisterIndex(GL_INVALID_INDEX), + psRegisterIndex(GL_INVALID_INDEX), + csRegisterIndex(GL_INVALID_INDEX) + { + } bool vertexStaticUse() const { return vsRegisterIndex != GL_INVALID_INDEX; } bool fragmentStaticUse() const { return psRegisterIndex != GL_INVALID_INDEX; } + bool computeStaticUse() const { return csRegisterIndex != GL_INVALID_INDEX; } + unsigned int vsRegisterIndex; unsigned int psRegisterIndex; + unsigned int csRegisterIndex; }; struct D3DVarying final @@ -97,24 +116,24 @@ struct D3DVarying final unsigned int outputSlot; }; -class ProgramD3DMetadata : angle::NonCopyable +class ProgramD3DMetadata final : angle::NonCopyable { public: - ProgramD3DMetadata(int rendererMajorShaderModel, - const std::string &shaderModelSuffix, - bool usesInstancedPointSpriteEmulation, - bool usesViewScale, + ProgramD3DMetadata(RendererD3D *renderer, const ShaderD3D *vertexShader, const ShaderD3D *fragmentShader); int getRendererMajorShaderModel() const; - bool usesBroadcast(const gl::Data &data) const; - bool usesFragDepth(const gl::Program::Data &programData) const; + bool usesBroadcast(const gl::ContextState &data) const; + bool usesFragDepth() const; bool usesPointCoord() const; bool usesFragCoord() const; bool usesPointSize() const; bool usesInsertedPointCoordValue() const; bool usesViewScale() const; + bool hasANGLEMultiviewEnabled() const; + bool usesViewID() const; + bool canSelectViewInVertexShader() const; bool addsPointCoordToVertexShader() const; bool usesTransformFeedbackGLPosition() const; bool usesSystemValuePointSize() const; @@ -127,6 +146,9 @@ class ProgramD3DMetadata : angle::NonCopyable const std::string mShaderModelSuffix; const bool mUsesInstancedPointSpriteEmulation; const bool mUsesViewScale; + const bool mHasANGLEMultiviewEnabled; + const bool mUsesViewID; + const bool mCanSelectViewInVertexShader; const ShaderD3D *mVertexShader; const ShaderD3D *mFragmentShader; }; @@ -134,10 +156,8 @@ class ProgramD3DMetadata : angle::NonCopyable class ProgramD3D : public ProgramImpl { public: - typedef int SemanticIndexArray[gl::MAX_VERTEX_ATTRIBS]; - - ProgramD3D(const gl::Program::Data &data, RendererD3D *renderer); - virtual ~ProgramD3D(); + ProgramD3D(const gl::ProgramState &data, RendererD3D *renderer); + ~ProgramD3D() override; const std::vector<PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; } @@ -145,116 +165,157 @@ class ProgramD3D : public ProgramImpl unsigned int samplerIndex, const gl::Caps &caps) const; GLenum getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const; - GLint getUsedSamplerRange(gl::SamplerType type) const; - void updateSamplerMapping(); + GLuint getUsedSamplerRange(gl::SamplerType type) const; + + enum SamplerMapping + { + WasDirty, + WasClean, + }; + + SamplerMapping updateSamplerMapping(); bool usesPointSize() const { return mUsesPointSize; } bool usesPointSpriteEmulation() const; bool usesGeometryShader(GLenum drawMode) const; + bool usesGeometryShaderForPointSpriteEmulation() const; bool usesInstancedPointSpriteEmulation() const; - LinkResult load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) override; - gl::Error save(gl::BinaryOutputStream *stream) override; + gl::LinkResult load(const gl::Context *context, + gl::InfoLog &infoLog, + gl::BinaryInputStream *stream) override; + void save(const gl::Context *context, gl::BinaryOutputStream *stream) override; void setBinaryRetrievableHint(bool retrievable) override; + void setSeparable(bool separable) override; - gl::Error getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, - ShaderExecutableD3D **outExectuable); - gl::Error getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputLayout, - ShaderExecutableD3D **outExectuable, - gl::InfoLog *infoLog); - gl::Error getVertexExecutableForInputLayout(const gl::InputLayout &inputLayout, - ShaderExecutableD3D **outExectuable, - gl::InfoLog *infoLog); - gl::Error getGeometryExecutableForPrimitiveType(const gl::Data &data, + gl::Error getVertexExecutableForCachedInputLayout(ShaderExecutableD3D **outExectuable, + gl::InfoLog *infoLog); + gl::Error getGeometryExecutableForPrimitiveType(const gl::Context *context, GLenum drawMode, ShaderExecutableD3D **outExecutable, gl::InfoLog *infoLog); - - LinkResult link(const gl::Data &data, gl::InfoLog &infoLog) override; + gl::Error getPixelExecutableForCachedOutputLayout(ShaderExecutableD3D **outExectuable, + gl::InfoLog *infoLog); + gl::Error getComputeExecutable(ShaderExecutableD3D **outExecutable); + gl::LinkResult link(const gl::Context *context, + const gl::ProgramLinkedResources &resources, + gl::InfoLog &infoLog) override; GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) override; - bool getUniformBlockSize(const std::string &blockName, size_t *sizeOut) const override; - bool getUniformBlockMemberInfo(const std::string &memberUniformName, - sh::BlockMemberInfo *memberInfoOut) const override; + void setPathFragmentInputGen(const std::string &inputName, + GLenum genMode, + GLint components, + const GLfloat *coeffs) override; void initializeUniformStorage(); - gl::Error applyUniforms(GLenum drawMode); - gl::Error applyUniformBuffers(const gl::Data &data); + void updateUniformBufferCache(const gl::Caps &caps, + unsigned int reservedVertex, + unsigned int reservedFragment); + const std::vector<GLint> &getVertexUniformBufferCache() const; + const std::vector<GLint> &getFragmentUniformBufferCache() const; + void dirtyAllUniforms(); - void setUniform1fv(GLint location, GLsizei count, const GLfloat *v); - void setUniform2fv(GLint location, GLsizei count, const GLfloat *v); - void setUniform3fv(GLint location, GLsizei count, const GLfloat *v); - void setUniform4fv(GLint location, GLsizei count, const GLfloat *v); - void setUniform1iv(GLint location, GLsizei count, const GLint *v); - void setUniform2iv(GLint location, GLsizei count, const GLint *v); - void setUniform3iv(GLint location, GLsizei count, const GLint *v); - void setUniform4iv(GLint location, GLsizei count, const GLint *v); - void setUniform1uiv(GLint location, GLsizei count, const GLuint *v); - void setUniform2uiv(GLint location, GLsizei count, const GLuint *v); - void setUniform3uiv(GLint location, GLsizei count, const GLuint *v); - void setUniform4uiv(GLint location, GLsizei count, const GLuint *v); + void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override; + void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override; + void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override; + void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) override; + void setUniform1iv(GLint location, GLsizei count, const GLint *v) override; + void setUniform2iv(GLint location, GLsizei count, const GLint *v) override; + void setUniform3iv(GLint location, GLsizei count, const GLint *v) override; + void setUniform4iv(GLint location, GLsizei count, const GLint *v) override; + void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) override; + void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) override; + void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) override; + void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) override; void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, - const GLfloat *value); + const GLfloat *value) override; void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, - const GLfloat *value); + const GLfloat *value) override; void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, - const GLfloat *value); + const GLfloat *value) override; void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, - const GLfloat *value); + const GLfloat *value) override; void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, - const GLfloat *value); + const GLfloat *value) override; void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, - const GLfloat *value); + const GLfloat *value) override; void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, - const GLfloat *value); + const GLfloat *value) override; void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, - const GLfloat *value); + const GLfloat *value) override; void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, - const GLfloat *value); + const GLfloat *value) override; + + void getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const override; + void getUniformiv(const gl::Context *context, GLint location, GLint *params) const override; + void getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const override; void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) override; - const UniformStorageD3D &getVertexUniformStorage() const { return *mVertexUniformStorage; } - const UniformStorageD3D &getFragmentUniformStorage() const { return *mFragmentUniformStorage; } + UniformStorageD3D &getVertexUniformStorage() const { return *mVertexUniformStorage.get(); } + UniformStorageD3D &getFragmentUniformStorage() const { return *mFragmentUniformStorage.get(); } + UniformStorageD3D &getComputeUniformStorage() const { return *mComputeUniformStorage.get(); } unsigned int getSerial() const; - void sortAttributesByLayout( - const std::vector<TranslatedAttribute> &unsortedAttributes, - int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS], - const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const; - const SemanticIndexArray &getSemanticIndexes() const { return mSemanticIndexes; } - const SemanticIndexArray &getAttributesByLayout() const { return mAttributesByLayout; } + const AttribIndexArray &getAttribLocationToD3DSemantics() const + { + return mAttribLocationToD3DSemantic; + } - void updateCachedInputLayout(const gl::State &state); - const gl::InputLayout &getCachedInputLayout() const { return mCachedInputLayout; } + void updateCachedInputLayout(Serial associatedSerial, const gl::State &state); + void updateCachedOutputLayout(const gl::Context *context, const gl::Framebuffer *framebuffer); bool isSamplerMappingDirty() { return mDirtySamplerMapping; } + // Checks if we need to recompile certain shaders. + bool hasVertexExecutableForCachedInputLayout(); + bool hasGeometryExecutableForPrimitiveType(GLenum drawMode); + bool hasPixelExecutableForCachedOutputLayout(); + + bool areVertexUniformsDirty() const { return mVertexUniformsDirty; } + bool areFragmentUniformsDirty() const { return mFragmentUniformsDirty; } + bool areComputeUniformsDirty() const { return mComputeUniformsDirty; } + const std::vector<D3DUniform *> &getD3DUniforms() const { return mD3DUniforms; } + void markUniformsClean(); + private: + // These forward-declared tasks are used for multi-thread shader compiles. + class GetExecutableTask; + class GetVertexExecutableTask; + class GetPixelExecutableTask; + class GetGeometryExecutableTask; + class VertexExecutable { public: - typedef std::vector<bool> Signature; + enum HLSLAttribType + { + FLOAT, + UNSIGNED_INT, + SIGNED_INT, + }; + + typedef std::vector<HLSLAttribType> Signature; VertexExecutable(const gl::InputLayout &inputLayout, const Signature &signature, @@ -271,6 +332,8 @@ class ProgramD3D : public ProgramImpl ShaderExecutableD3D *shaderExecutable() const { return mShaderExecutable; } private: + static HLSLAttribType GetAttribType(GLenum type); + gl::InputLayout mInputs; Signature mSignature; ShaderExecutableD3D *mShaderExecutable; @@ -307,62 +370,105 @@ class ProgramD3D : public ProgramImpl typedef std::map<std::string, D3DUniform *> D3DUniformMap; - void defineUniformsAndAssignRegisters(); + void defineUniformsAndAssignRegisters(const gl::Context *context); void defineUniformBase(const gl::Shader *shader, const sh::Uniform &uniform, D3DUniformMap *uniformMap); + void defineStructUniformFields(GLenum shaderType, + const std::vector<sh::ShaderVariable> &fields, + const std::string &namePrefix, + sh::HLSLBlockEncoder *encoder, + D3DUniformMap *uniformMap); + void defineArrayOfStructsUniformFields(GLenum shaderType, + const sh::ShaderVariable &uniform, + unsigned int arrayNestingIndex, + const std::string &prefix, + sh::HLSLBlockEncoder *encoder, + D3DUniformMap *uniformMap); + void defineArrayUniformElements(GLenum shaderType, + const sh::ShaderVariable &uniform, + const std::string &fullName, + sh::HLSLBlockEncoder *encoder, + D3DUniformMap *uniformMap); void defineUniform(GLenum shaderType, const sh::ShaderVariable &uniform, const std::string &fullName, sh::HLSLBlockEncoder *encoder, D3DUniformMap *uniformMap); void assignAllSamplerRegisters(); - void assignSamplerRegisters(const D3DUniform *d3dUniform); + void assignSamplerRegisters(size_t uniformIndex); static void AssignSamplers(unsigned int startSamplerIndex, - GLenum samplerType, + const gl::UniformTypeInfo &typeInfo, unsigned int samplerCount, std::vector<Sampler> &outSamplers, GLuint *outUsedRange); + template <typename DestT> + void getUniformInternal(GLint location, DestT *dataOut) const; + + template <typename T> + void setUniformImpl(const gl::VariableLocation &locationInfo, + GLsizei count, + const T *v, + uint8_t *targetData, + GLenum uniformType); + template <typename T> - void setUniform(GLint location, GLsizei count, const T *v, GLenum targetUniformType); + void setUniformInternal(GLint location, GLsizei count, const T *v, GLenum uniformType); template <int cols, int rows> - void setUniformMatrixfv(GLint location, - GLsizei count, - GLboolean transpose, - const GLfloat *value, - GLenum targetUniformType); + bool setUniformMatrixfvImpl(GLint location, + GLsizei count, + GLboolean transpose, + const GLfloat *value, + uint8_t *targetData, + GLenum targetUniformType); - LinkResult compileProgramExecutables(const gl::Data &data, gl::InfoLog &infoLog); + template <int cols, int rows> + void setUniformMatrixfvInternal(GLint location, + GLsizei count, + GLboolean transpose, + const GLfloat *value, + GLenum targetUniformType); - void gatherTransformFeedbackVaryings(const VaryingPacking &varyings); + gl::LinkResult compileProgramExecutables(const gl::Context *context, gl::InfoLog &infoLog); + gl::LinkResult compileComputeExecutable(const gl::Context *context, gl::InfoLog &infoLog); + + void gatherTransformFeedbackVaryings(const gl::VaryingPacking &varyings, + const BuiltinInfo &builtins); D3DUniform *getD3DUniformByName(const std::string &name); D3DUniform *getD3DUniformFromLocation(GLint location); + const D3DUniform *getD3DUniformFromLocation(GLint location) const; - void initSemanticIndex(); - void initAttributesByLayout(); + void initAttribLocationsToD3DSemantic(const gl::Context *context); void reset(); - void assignUniformBlockRegisters(); + void initializeUniformBlocks(); + + void updateCachedInputLayoutFromShader(const gl::Context *context); + void updateCachedOutputLayoutFromShader(); + void updateCachedVertexExecutableIndex(); + void updateCachedPixelExecutableIndex(); - void initUniformBlockInfo(); - size_t getUniformBlockInfo(const sh::InterfaceBlock &interfaceBlock); + void linkResources(const gl::Context *context, const gl::ProgramLinkedResources &resources); RendererD3D *mRenderer; DynamicHLSL *mDynamicHLSL; - std::vector<VertexExecutable *> mVertexExecutables; - std::vector<PixelExecutable *> mPixelExecutables; - std::vector<ShaderExecutableD3D *> mGeometryExecutables; + std::vector<std::unique_ptr<VertexExecutable>> mVertexExecutables; + std::vector<std::unique_ptr<PixelExecutable>> mPixelExecutables; + std::vector<std::unique_ptr<ShaderExecutableD3D>> mGeometryExecutables; + std::unique_ptr<ShaderExecutableD3D> mComputeExecutable; std::string mVertexHLSL; - D3DCompilerWorkarounds mVertexWorkarounds; + angle::CompilerWorkaroundsD3D mVertexWorkarounds; std::string mPixelHLSL; - D3DCompilerWorkarounds mPixelWorkarounds; + angle::CompilerWorkaroundsD3D mPixelWorkarounds; bool mUsesFragDepth; + bool mHasANGLEMultiviewEnabled; + bool mUsesViewID; std::vector<PixelShaderOutputVariable> mPixelShaderKey; // Common code for all dynamic geometry shaders. Consists mainly of the GS input and output @@ -373,20 +479,23 @@ class ProgramD3D : public ProgramImpl bool mUsesPointSize; bool mUsesFlatInterpolation; - UniformStorageD3D *mVertexUniformStorage; - UniformStorageD3D *mFragmentUniformStorage; + std::unique_ptr<UniformStorageD3D> mVertexUniformStorage; + std::unique_ptr<UniformStorageD3D> mFragmentUniformStorage; + std::unique_ptr<UniformStorageD3D> mComputeUniformStorage; std::vector<Sampler> mSamplersPS; std::vector<Sampler> mSamplersVS; + std::vector<Sampler> mSamplersCS; GLuint mUsedVertexSamplerRange; GLuint mUsedPixelSamplerRange; + GLuint mUsedComputeSamplerRange; bool mDirtySamplerMapping; - // Cache for getPixelExecutableForFramebuffer - std::vector<GLenum> mPixelShaderOutputFormatCache; + // Cache for pixel shader output layout to save reallocations. + std::vector<GLenum> mPixelShaderOutputLayoutCache; + Optional<size_t> mCachedPixelExecutableIndex; - SemanticIndexArray mSemanticIndexes; - SemanticIndexArray mAttributesByLayout; + AttribIndexArray mAttribLocationToD3DSemantic; unsigned int mSerial; @@ -394,17 +503,21 @@ class ProgramD3D : public ProgramImpl std::vector<GLint> mFragmentUBOCache; VertexExecutable::Signature mCachedVertexSignature; gl::InputLayout mCachedInputLayout; + Optional<size_t> mCachedVertexExecutableIndex; std::vector<D3DVarying> mStreamOutVaryings; std::vector<D3DUniform *> mD3DUniforms; std::vector<D3DUniformBlock> mD3DUniformBlocks; - std::map<std::string, sh::BlockMemberInfo> mBlockInfo; - std::map<std::string, size_t> mBlockDataSizes; + bool mVertexUniformsDirty; + bool mFragmentUniformsDirty; + bool mComputeUniformsDirty; static unsigned int issueSerial(); static unsigned int mCurrentSerial; + + Serial mCurrentVertexArrayStateSerial; }; -} +} // namespace rx #endif // LIBANGLE_RENDERER_D3D_PROGRAMD3D_H_ |