Commit c5a83000 by Jamie Madill

Store multiple vertex executables in the program binary.

With dynamic vertex conversion the GPU, we will have different input layouts resulting in different executables. This patch adds a way of mapping the input layouts to vertex executables. BUG=angle:560 Change-Id: Ie36f2f8ac2dfcb96f562af577d31f57d6d89b447 Reviewed-on: https://chromium-review.googlesource.com/185192Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 5f562735
...@@ -2407,9 +2407,14 @@ void Context::applyState(GLenum drawMode) ...@@ -2407,9 +2407,14 @@ void Context::applyState(GLenum drawMode)
} }
// Applies the shaders and shader constants to the Direct3D 9 device // Applies the shaders and shader constants to the Direct3D 9 device
void Context::applyShaders(ProgramBinary *programBinary, bool rasterizerDiscard) void Context::applyShaders(ProgramBinary *programBinary)
{ {
mRenderer->applyShaders(programBinary, rasterizerDiscard); const VertexAttribute *vertexAttributes = getCurrentVertexArray()->getVertexAttributes();
VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS];
VertexFormat::GetInputLayout(inputLayout, programBinary, vertexAttributes, mState.vertexAttribCurrentValues);
mRenderer->applyShaders(programBinary, mState.rasterizer.rasterizerDiscard, inputLayout);
programBinary->applyUniforms(); programBinary->applyUniforms();
} }
...@@ -2879,7 +2884,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan ...@@ -2879,7 +2884,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan
return gl::error(err); return gl::error(err);
} }
applyShaders(programBinary, mState.rasterizer.rasterizerDiscard); applyShaders(programBinary);
applyTextures(programBinary); applyTextures(programBinary);
if (!applyUniformBuffers()) if (!applyUniformBuffers())
...@@ -2942,7 +2947,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid ...@@ -2942,7 +2947,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid
return gl::error(err); return gl::error(err);
} }
applyShaders(programBinary, mState.rasterizer.rasterizerDiscard); applyShaders(programBinary);
applyTextures(programBinary); applyTextures(programBinary);
if (!applyUniformBuffers()) if (!applyUniformBuffers())
......
...@@ -453,7 +453,7 @@ class Context ...@@ -453,7 +453,7 @@ class Context
bool applyRenderTarget(GLenum drawMode, bool ignoreViewport); bool applyRenderTarget(GLenum drawMode, bool ignoreViewport);
void applyState(GLenum drawMode); void applyState(GLenum drawMode);
void applyShaders(ProgramBinary *programBinary, bool rasterizerDiscard); void applyShaders(ProgramBinary *programBinary);
void applyTextures(ProgramBinary *programBinary); void applyTextures(ProgramBinary *programBinary);
void applyTextures(ProgramBinary *programBinary, SamplerType type); void applyTextures(ProgramBinary *programBinary, SamplerType type);
bool applyUniformBuffers(); bool applyUniformBuffers();
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "libGLESv2/Uniform.h" #include "libGLESv2/Uniform.h"
#include "libGLESv2/Shader.h" #include "libGLESv2/Shader.h"
#include "libGLESv2/Constants.h" #include "libGLESv2/Constants.h"
#include "libGLESv2/renderer/VertexDataManager.h"
namespace rx namespace rx
{ {
...@@ -65,7 +66,7 @@ class ProgramBinary : public RefCountObject ...@@ -65,7 +66,7 @@ class ProgramBinary : public RefCountObject
~ProgramBinary(); ~ProgramBinary();
rx::ShaderExecutable *getPixelExecutable() const; rx::ShaderExecutable *getPixelExecutable() const;
rx::ShaderExecutable *getVertexExecutable() const; rx::ShaderExecutable *getVertexExecutableForInputLayout(const VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS]);
rx::ShaderExecutable *getGeometryExecutable() const; rx::ShaderExecutable *getGeometryExecutable() const;
GLuint getAttributeLocation(const char *name); GLuint getAttributeLocation(const char *name);
...@@ -185,12 +186,30 @@ class ProgramBinary : public RefCountObject ...@@ -185,12 +186,30 @@ class ProgramBinary : public RefCountObject
static TextureType getTextureType(GLenum samplerType, InfoLog &infoLog); static TextureType getTextureType(GLenum samplerType, InfoLog &infoLog);
class VertexExecutable
{
public:
VertexExecutable(rx::Renderer *const renderer,
const VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS],
rx::ShaderExecutable *shaderExecutable);
bool matchesInputLayout(const VertexFormat attributes[gl::MAX_VERTEX_ATTRIBS]) const;
const VertexFormat *inputs() const { return mInputs; }
rx::ShaderExecutable *shaderExecutable() const { return mShaderExecutable; }
private:
VertexFormat mInputs[gl::MAX_VERTEX_ATTRIBS];
rx::ShaderExecutable *mShaderExecutable;
};
rx::Renderer *const mRenderer; rx::Renderer *const mRenderer;
DynamicHLSL *mDynamicHLSL; DynamicHLSL *mDynamicHLSL;
rx::ShaderExecutable *mPixelExecutable; std::string mVertexHLSL;
rx::ShaderExecutable *mVertexExecutable; rx::D3DWorkaroundType mVertexWorkarounds;
std::vector<VertexExecutable *> mVertexExecutables;
rx::ShaderExecutable *mGeometryExecutable; rx::ShaderExecutable *mGeometryExecutable;
rx::ShaderExecutable *mPixelExecutable;
sh::Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS]; sh::Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS];
int mSemanticIndex[MAX_VERTEX_ATTRIBS]; int mSemanticIndex[MAX_VERTEX_ATTRIBS];
......
...@@ -130,7 +130,7 @@ class Renderer ...@@ -130,7 +130,7 @@ class Renderer
bool ignoreViewport) = 0; bool ignoreViewport) = 0;
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0; virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
virtual void applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard) = 0; virtual void applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard, const gl::VertexFormat inputLayout[]) = 0;
virtual void applyUniforms(const gl::ProgramBinary &programBinary) = 0; virtual void applyUniforms(const gl::ProgramBinary &programBinary) = 0;
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0; virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[], virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
......
...@@ -22,6 +22,21 @@ ...@@ -22,6 +22,21 @@
namespace rx namespace rx
{ {
static void GetInputLayout(const TranslatedAttribute translatedAttributes[gl::MAX_VERTEX_ATTRIBS],
gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS])
{
for (unsigned int attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++)
{
const TranslatedAttribute &translatedAttribute = translatedAttributes[attributeIndex];
if (translatedAttributes[attributeIndex].active)
{
inputLayout[attributeIndex] = gl::VertexFormat(*translatedAttribute.attribute,
translatedAttribute.currentValueType);
}
}
}
const unsigned int InputLayoutCache::kMaxInputLayouts = 1024; const unsigned int InputLayoutCache::kMaxInputLayouts = 1024;
InputLayoutCache::InputLayoutCache() : mInputLayoutMap(kMaxInputLayouts, hashInputLayout, compareInputLayouts) InputLayoutCache::InputLayoutCache() : mInputLayoutMap(kMaxInputLayouts, hashInputLayout, compareInputLayouts)
...@@ -135,7 +150,9 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M ...@@ -135,7 +150,9 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
} }
else else
{ {
ShaderExecutable11 *shader = ShaderExecutable11::makeShaderExecutable11(programBinary->getVertexExecutable()); gl::VertexFormat shaderInputLayout[gl::MAX_VERTEX_ATTRIBS];
GetInputLayout(attributes, shaderInputLayout);
ShaderExecutable11 *shader = ShaderExecutable11::makeShaderExecutable11(programBinary->getVertexExecutableForInputLayout(shaderInputLayout));
D3D11_INPUT_ELEMENT_DESC descs[gl::MAX_VERTEX_ATTRIBS]; D3D11_INPUT_ELEMENT_DESC descs[gl::MAX_VERTEX_ATTRIBS];
for (unsigned int j = 0; j < ilKey.elementCount; ++j) for (unsigned int j = 0; j < ilKey.elementCount; ++j)
......
...@@ -1403,9 +1403,9 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic ...@@ -1403,9 +1403,9 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic
} }
} }
void Renderer11::applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard) void Renderer11::applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard, const gl::VertexFormat inputLayout[])
{ {
ShaderExecutable *vertexExe = programBinary->getVertexExecutable(); ShaderExecutable *vertexExe = programBinary->getVertexExecutableForInputLayout(inputLayout);
ShaderExecutable *pixelExe = programBinary->getPixelExecutable(); ShaderExecutable *pixelExe = programBinary->getPixelExecutable();
ShaderExecutable *geometryExe = programBinary->getGeometryExecutable(); ShaderExecutable *geometryExe = programBinary->getGeometryExecutable();
......
...@@ -75,7 +75,7 @@ class Renderer11 : public Renderer ...@@ -75,7 +75,7 @@ class Renderer11 : public Renderer
virtual bool applyPrimitiveType(GLenum mode, GLsizei count); virtual bool applyPrimitiveType(GLenum mode, GLsizei count);
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer); virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard); virtual void applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard, const gl::VertexFormat inputLayout[]);
virtual void applyUniforms(const gl::ProgramBinary &programBinary); virtual void applyUniforms(const gl::ProgramBinary &programBinary);
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[], virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances); GLint first, GLsizei count, GLsizei instances);
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "libGLESv2/renderer/d3d9/BufferStorage9.h" #include "libGLESv2/renderer/d3d9/BufferStorage9.h"
#include "libGLESv2/renderer/d3d9/Query9.h" #include "libGLESv2/renderer/d3d9/Query9.h"
#include "libGLESv2/renderer/d3d9/Fence9.h" #include "libGLESv2/renderer/d3d9/Fence9.h"
#include "libGLESv2/angletypes.h"
#include "libEGL/Display.h" #include "libEGL/Display.h"
...@@ -1722,11 +1723,11 @@ void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indi ...@@ -1722,11 +1723,11 @@ void Renderer9::drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indi
} }
} }
void Renderer9::applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard) void Renderer9::applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard, const gl::VertexFormat inputLayout[])
{ {
ASSERT(!rasterizerDiscard); ASSERT(!rasterizerDiscard);
ShaderExecutable *vertexExe = programBinary->getVertexExecutable(); ShaderExecutable *vertexExe = programBinary->getVertexExecutableForInputLayout(inputLayout);
ShaderExecutable *pixelExe = programBinary->getPixelExecutable(); ShaderExecutable *pixelExe = programBinary->getPixelExecutable();
IDirect3DVertexShader9 *vertexShader = (vertexExe ? ShaderExecutable9::makeShaderExecutable9(vertexExe)->getVertexShader() : NULL); IDirect3DVertexShader9 *vertexShader = (vertexExe ? ShaderExecutable9::makeShaderExecutable9(vertexExe)->getVertexShader() : NULL);
......
...@@ -58,17 +58,6 @@ class Renderer9 : public Renderer ...@@ -58,17 +58,6 @@ class Renderer9 : public Renderer
IDirect3DPixelShader9 *createPixelShader(const DWORD *function, size_t length); IDirect3DPixelShader9 *createPixelShader(const DWORD *function, size_t length);
HRESULT createVertexBuffer(UINT Length, DWORD Usage, IDirect3DVertexBuffer9 **ppVertexBuffer); HRESULT createVertexBuffer(UINT Length, DWORD Usage, IDirect3DVertexBuffer9 **ppVertexBuffer);
HRESULT createIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, IDirect3DIndexBuffer9 **ppIndexBuffer); HRESULT createIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, IDirect3DIndexBuffer9 **ppIndexBuffer);
#if 0
void *createTexture2D();
void *createTextureCube();
void *createQuery();
void *createIndexBuffer();
void *createVertexbuffer();
// state setup
void applyShaders();
void applyConstants();
#endif
virtual void generateSwizzle(gl::Texture *texture); virtual void generateSwizzle(gl::Texture *texture);
virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler); virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture); virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture);
...@@ -86,7 +75,7 @@ class Renderer9 : public Renderer ...@@ -86,7 +75,7 @@ class Renderer9 : public Renderer
bool ignoreViewport); bool ignoreViewport);
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer); virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard); virtual void applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard, const gl::VertexFormat inputLayout[]);
virtual void applyUniforms(const gl::ProgramBinary &programBinary); virtual void applyUniforms(const gl::ProgramBinary &programBinary);
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount); virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount);
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[], virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
......
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