Commit 76b10c9a by Geoff Lang

Use dynamically sized containers for texture and sampler bindings.

BUG=angle:685 Change-Id: I7af97a95deee69fbdebca2b57403244f45516e67 Reviewed-on: https://chromium-review.googlesource.com/216564Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent ac7579c2
...@@ -115,10 +115,7 @@ class Context ...@@ -115,10 +115,7 @@ class Context
void bindArrayBuffer(GLuint buffer); void bindArrayBuffer(GLuint buffer);
void bindElementArrayBuffer(GLuint buffer); void bindElementArrayBuffer(GLuint buffer);
void bindTexture2D(GLuint texture); void bindTexture(GLenum target, GLuint texture);
void bindTextureCubeMap(GLuint texture);
void bindTexture3D(GLuint texture);
void bindTexture2DArray(GLuint texture);
void bindReadFramebuffer(GLuint framebuffer); void bindReadFramebuffer(GLuint framebuffer);
void bindDrawFramebuffer(GLuint framebuffer); void bindDrawFramebuffer(GLuint framebuffer);
void bindRenderbuffer(GLuint renderbuffer); void bindRenderbuffer(GLuint renderbuffer);
...@@ -170,7 +167,7 @@ class Context ...@@ -170,7 +167,7 @@ class Context
Texture3D *getTexture3D() const; Texture3D *getTexture3D() const;
Texture2DArray *getTexture2DArray() const; Texture2DArray *getTexture2DArray() const;
Texture *getSamplerTexture(unsigned int sampler, TextureType type) const; Texture *getSamplerTexture(unsigned int sampler, GLenum type) const;
bool isSampler(GLuint samplerName) const; bool isSampler(GLuint samplerName) const;
...@@ -237,9 +234,9 @@ class Context ...@@ -237,9 +234,9 @@ class Context
void applyRenderTarget(GLenum drawMode, bool ignoreViewport); void applyRenderTarget(GLenum drawMode, bool ignoreViewport);
void applyState(GLenum drawMode); void applyState(GLenum drawMode);
void applyShaders(ProgramBinary *programBinary, bool transformFeedbackActive); void applyShaders(ProgramBinary *programBinary, bool transformFeedbackActive);
void applyTextures(SamplerType shaderType, Texture *textures[], TextureType *textureTypes, SamplerState *samplers, void applyTextures(ProgramBinary *programBinary, SamplerType shaderType, const FramebufferTextureSerialArray &framebufferSerials,
size_t textureCount, const FramebufferTextureSerialArray& framebufferSerials,
size_t framebufferSerialCount); size_t framebufferSerialCount);
void applyTextures(ProgramBinary *programBinary);
bool applyUniformBuffers(); bool applyUniformBuffers();
bool applyTransformFeedbackBuffers(); bool applyTransformFeedbackBuffers();
void markTransformFeedbackUsage(); void markTransformFeedbackUsage();
...@@ -252,10 +249,10 @@ class Context ...@@ -252,10 +249,10 @@ class Context
void detachTransformFeedback(GLuint transformFeedback); void detachTransformFeedback(GLuint transformFeedback);
void detachSampler(GLuint sampler); void detachSampler(GLuint sampler);
void generateSwizzles(Texture *textures[], size_t count); void generateSwizzles(ProgramBinary *programBinary, SamplerType type);
size_t getCurrentTexturesAndSamplerStates(ProgramBinary *programBinary, SamplerType type, Texture **outTextures, void generateSwizzles(ProgramBinary *programBinary);
TextureType *outTextureTypes, SamplerState *outSamplers);
Texture *getIncompleteTexture(TextureType type); Texture *getIncompleteTexture(GLenum type);
bool skipDraw(GLenum drawMode); bool skipDraw(GLenum drawMode);
...@@ -276,10 +273,9 @@ class Context ...@@ -276,10 +273,9 @@ class Context
int mClientVersion; int mClientVersion;
BindingPointer<Texture2D> mTexture2DZero; typedef std::map< GLenum, BindingPointer<Texture> > TextureMap;
BindingPointer<TextureCubeMap> mTextureCubeMapZero; TextureMap mZeroTextures;
BindingPointer<Texture3D> mTexture3DZero; TextureMap mIncompleteTextures;
BindingPointer<Texture2DArray> mTexture2DArrayZero;
typedef std::unordered_map<GLuint, Framebuffer*> FramebufferMap; typedef std::unordered_map<GLuint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap; FramebufferMap mFramebufferMap;
...@@ -306,8 +302,6 @@ class Context ...@@ -306,8 +302,6 @@ class Context
std::string mExtensionString; std::string mExtensionString;
std::vector<std::string> mExtensionStrings; std::vector<std::string> mExtensionStrings;
BindingPointer<Texture> mIncompleteTextures[TEXTURE_TYPE_COUNT];
// Recorded errors // Recorded errors
typedef std::set<GLenum> ErrorSet; typedef std::set<GLenum> ErrorSet;
ErrorSet mErrors; ErrorSet mErrors;
......
...@@ -110,7 +110,7 @@ class ProgramBinary : public RefCountObject ...@@ -110,7 +110,7 @@ class ProgramBinary : public RefCountObject
int getSemanticIndex(int attributeIndex); int getSemanticIndex(int attributeIndex);
GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex, const Caps &caps); GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex, const Caps &caps);
TextureType getSamplerTextureType(SamplerType type, unsigned int samplerIndex); GLenum getSamplerTextureType(SamplerType type, unsigned int samplerIndex);
GLint getUsedSamplerRange(SamplerType type); GLint getUsedSamplerRange(SamplerType type);
bool usesPointSize() const; bool usesPointSize() const;
bool usesPointSpriteEmulation() const; bool usesPointSpriteEmulation() const;
...@@ -205,7 +205,7 @@ class ProgramBinary : public RefCountObject ...@@ -205,7 +205,7 @@ class ProgramBinary : public RefCountObject
bool active; bool active;
GLint logicalTextureUnit; GLint logicalTextureUnit;
TextureType textureType; GLenum textureType;
}; };
void reset(); void reset();
...@@ -227,7 +227,7 @@ class ProgramBinary : public RefCountObject ...@@ -227,7 +227,7 @@ class ProgramBinary : public RefCountObject
bool indexSamplerUniform(const LinkedUniform &uniform, InfoLog &infoLog, const Caps &caps); bool indexSamplerUniform(const LinkedUniform &uniform, InfoLog &infoLog, const Caps &caps);
bool indexUniforms(InfoLog &infoLog, const Caps &caps); bool indexUniforms(InfoLog &infoLog, const Caps &caps);
static bool assignSamplers(unsigned int startSamplerIndex, GLenum samplerType, unsigned int samplerCount, static bool assignSamplers(unsigned int startSamplerIndex, GLenum samplerType, unsigned int samplerCount,
Sampler *outArray, GLuint *usedRange, unsigned int limit); std::vector<Sampler> &outSamplers, GLuint *outUsedRange);
bool areMatchingInterfaceBlocks(InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock, const sh::InterfaceBlock &fragmentInterfaceBlock); bool areMatchingInterfaceBlocks(InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock, const sh::InterfaceBlock &fragmentInterfaceBlock);
bool linkUniformBlocks(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader, const Caps &caps); bool linkUniformBlocks(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader, const Caps &caps);
bool gatherTransformFeedbackLinkedVaryings(InfoLog &infoLog, const std::vector<LinkedVarying> &linkedVaryings, bool gatherTransformFeedbackLinkedVaryings(InfoLog &infoLog, const std::vector<LinkedVarying> &linkedVaryings,
...@@ -303,8 +303,8 @@ class ProgramBinary : public RefCountObject ...@@ -303,8 +303,8 @@ class ProgramBinary : public RefCountObject
GLenum mTransformFeedbackBufferMode; GLenum mTransformFeedbackBufferMode;
std::vector<LinkedVarying> mTransformFeedbackLinkedVaryings; std::vector<LinkedVarying> mTransformFeedbackLinkedVaryings;
Sampler mSamplersPS[MAX_TEXTURE_IMAGE_UNITS]; std::vector<Sampler> mSamplersPS;
Sampler mSamplersVS[IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; std::vector<Sampler> mSamplersVS;
GLuint mUsedVertexSamplerRange; GLuint mUsedVertexSamplerRange;
GLuint mUsedPixelSamplerRange; GLuint mUsedPixelSamplerRange;
bool mUsesPointSize; bool mUsesPointSize;
......
...@@ -366,25 +366,25 @@ void ResourceManager::checkBufferAllocation(unsigned int buffer) ...@@ -366,25 +366,25 @@ void ResourceManager::checkBufferAllocation(unsigned int buffer)
} }
} }
void ResourceManager::checkTextureAllocation(GLuint texture, TextureType type) void ResourceManager::checkTextureAllocation(GLuint texture, GLenum type)
{ {
if (!getTexture(texture) && texture != 0) if (!getTexture(texture) && texture != 0)
{ {
Texture *textureObject; Texture *textureObject;
if (type == TEXTURE_2D) if (type == GL_TEXTURE_2D)
{ {
textureObject = new Texture2D(mRenderer->createTexture(GL_TEXTURE_2D), texture); textureObject = new Texture2D(mRenderer->createTexture(GL_TEXTURE_2D), texture);
} }
else if (type == TEXTURE_CUBE) else if (type == GL_TEXTURE_CUBE_MAP)
{ {
textureObject = new TextureCubeMap(mRenderer->createTexture(GL_TEXTURE_CUBE_MAP), texture); textureObject = new TextureCubeMap(mRenderer->createTexture(GL_TEXTURE_CUBE_MAP), texture);
} }
else if (type == TEXTURE_3D) else if (type == GL_TEXTURE_3D)
{ {
textureObject = new Texture3D(mRenderer->createTexture(GL_TEXTURE_3D), texture); textureObject = new Texture3D(mRenderer->createTexture(GL_TEXTURE_3D), texture);
} }
else if (type == TEXTURE_2D_ARRAY) else if (type == GL_TEXTURE_2D_ARRAY)
{ {
textureObject = new Texture2DArray(mRenderer->createTexture(GL_TEXTURE_2D_ARRAY), texture); textureObject = new Texture2DArray(mRenderer->createTexture(GL_TEXTURE_2D_ARRAY), texture);
} }
......
...@@ -65,11 +65,11 @@ class ResourceManager ...@@ -65,11 +65,11 @@ class ResourceManager
Renderbuffer *getRenderbuffer(GLuint handle); Renderbuffer *getRenderbuffer(GLuint handle);
Sampler *getSampler(GLuint handle); Sampler *getSampler(GLuint handle);
FenceSync *getFenceSync(GLuint handle); FenceSync *getFenceSync(GLuint handle);
void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer); void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
void checkBufferAllocation(unsigned int buffer); void checkBufferAllocation(unsigned int buffer);
void checkTextureAllocation(GLuint texture, TextureType type); void checkTextureAllocation(GLuint texture, GLenum type);
void checkRenderbufferAllocation(GLuint renderbuffer); void checkRenderbufferAllocation(GLuint renderbuffer);
void checkSamplerAllocation(GLuint sampler); void checkSamplerAllocation(GLuint sampler);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "libGLESv2/State.h" #include "libGLESv2/State.h"
#include "libGLESv2/Context.h" #include "libGLESv2/Context.h"
#include "libGLESv2/Caps.h"
#include "libGLESv2/VertexArray.h" #include "libGLESv2/VertexArray.h"
#include "libGLESv2/Query.h" #include "libGLESv2/Query.h"
#include "libGLESv2/Framebuffer.h" #include "libGLESv2/Framebuffer.h"
...@@ -18,8 +19,18 @@ ...@@ -18,8 +19,18 @@
namespace gl namespace gl
{ {
State::State() State::State()
{ {
}
State::~State()
{
reset();
}
void State::initialize(const Caps& caps, GLuint clientVersion)
{
mContext = NULL; mContext = NULL;
setClearColor(0.0f, 0.0f, 0.0f, 0.0f); setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
...@@ -65,7 +76,7 @@ State::State() ...@@ -65,7 +76,7 @@ State::State()
mDepthStencil.stencilMask = -1; mDepthStencil.stencilMask = -1;
mDepthStencil.stencilWritemask = -1; mDepthStencil.stencilWritemask = -1;
mDepthStencil.stencilBackFunc = GL_ALWAYS; mDepthStencil.stencilBackFunc = GL_ALWAYS;
mDepthStencil.stencilBackMask = - 1; mDepthStencil.stencilBackMask = -1;
mDepthStencil.stencilBackWritemask = -1; mDepthStencil.stencilBackWritemask = -1;
mDepthStencil.stencilFail = GL_KEEP; mDepthStencil.stencilFail = GL_KEEP;
mDepthStencil.stencilPassDepthFail = GL_KEEP; mDepthStencil.stencilPassDepthFail = GL_KEEP;
...@@ -97,18 +108,24 @@ State::State() ...@@ -97,18 +108,24 @@ State::State()
mBlend.colorMaskBlue = true; mBlend.colorMaskBlue = true;
mBlend.colorMaskAlpha = true; mBlend.colorMaskAlpha = true;
mActiveSampler = 0;
const GLfloat defaultFloatValues[] = { 0.0f, 0.0f, 0.0f, 1.0f }; const GLfloat defaultFloatValues[] = { 0.0f, 0.0f, 0.0f, 1.0f };
for (int attribIndex = 0; attribIndex < MAX_VERTEX_ATTRIBS; attribIndex++) for (int attribIndex = 0; attribIndex < MAX_VERTEX_ATTRIBS; attribIndex++)
{ {
mVertexAttribCurrentValues[attribIndex].setFloatValues(defaultFloatValues); mVertexAttribCurrentValues[attribIndex].setFloatValues(defaultFloatValues);
} }
for (unsigned int textureUnit = 0; textureUnit < ArraySize(mSamplers); textureUnit++) mSamplerTextures[GL_TEXTURE_2D].resize(caps.maxCombinedTextureImageUnits);
mSamplerTextures[GL_TEXTURE_CUBE_MAP].resize(caps.maxCombinedTextureImageUnits);
if (clientVersion >= 3)
{ {
mSamplers[textureUnit].set(NULL); // TODO: These could also be enabled via extension
mSamplerTextures[GL_TEXTURE_2D_ARRAY].resize(caps.maxCombinedTextureImageUnits);
mSamplerTextures[GL_TEXTURE_3D].resize(caps.maxCombinedTextureImageUnits);
} }
mActiveSampler = 0; mSamplers.resize(caps.maxCombinedTextureImageUnits);
mActiveQueries[GL_ANY_SAMPLES_PASSED].set(NULL); mActiveQueries[GL_ANY_SAMPLES_PASSED].set(NULL);
mActiveQueries[GL_ANY_SAMPLES_PASSED_CONSERVATIVE].set(NULL); mActiveQueries[GL_ANY_SAMPLES_PASSED_CONSERVATIVE].set(NULL);
...@@ -121,15 +138,20 @@ State::State() ...@@ -121,15 +138,20 @@ State::State()
mDrawFramebuffer = NULL; mDrawFramebuffer = NULL;
} }
State::~State() void State::reset()
{ {
for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++)
{ {
for (int sampler = 0; sampler < IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++) TextureBindingVector &textureVector = bindingVec->second;
for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
{ {
mSamplerTexture[type][sampler].set(NULL); textureVector[textureIdx].set(NULL);
} }
} }
for (size_t samplerIdx = 0; samplerIdx < mSamplers.size(); samplerIdx++)
{
mSamplers[samplerIdx].set(NULL);
}
const GLfloat defaultFloatValues[] = { 0.0f, 0.0f, 0.0f, 1.0f }; const GLfloat defaultFloatValues[] = { 0.0f, 0.0f, 0.0f, 1.0f };
for (int attribIndex = 0; attribIndex < MAX_VERTEX_ATTRIBS; attribIndex++) for (int attribIndex = 0; attribIndex < MAX_VERTEX_ATTRIBS; attribIndex++)
...@@ -583,26 +605,26 @@ unsigned int State::getActiveSampler() const ...@@ -583,26 +605,26 @@ unsigned int State::getActiveSampler() const
return mActiveSampler; return mActiveSampler;
} }
void State::setSamplerTexture(TextureType type, Texture *texture) void State::setSamplerTexture(GLenum type, Texture *texture)
{ {
mSamplerTexture[type][mActiveSampler].set(texture); mSamplerTextures[type][mActiveSampler].set(texture);
} }
Texture *State::getSamplerTexture(unsigned int sampler, TextureType type) const Texture *State::getSamplerTexture(unsigned int sampler, GLenum type) const
{ {
GLuint texid = mSamplerTexture[type][sampler].id(); const BindingPointer<Texture>& binding = mSamplerTextures.at(type)[sampler];
if (texid == 0) // Special case: 0 refers to default textures held by Context if (binding.id() == 0) // Special case: 0 refers to default textures held by Context
{ {
return NULL; return NULL;
} }
return mSamplerTexture[type][sampler].get(); return binding.get();
} }
GLuint State::getSamplerTextureId(unsigned int sampler, TextureType type) const GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const
{ {
return mSamplerTexture[type][sampler].id(); return mSamplerTextures.at(type)[sampler].id();
} }
void State::detachTexture(GLuint texture) void State::detachTexture(GLuint texture)
...@@ -616,13 +638,15 @@ void State::detachTexture(GLuint texture) ...@@ -616,13 +638,15 @@ void State::detachTexture(GLuint texture)
// If a texture object is deleted, it is as if all texture units which are bound to that texture object are // If a texture object is deleted, it is as if all texture units which are bound to that texture object are
// rebound to texture object zero // rebound to texture object zero
for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++)
{ {
for (int sampler = 0; sampler < IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++) TextureBindingVector &textureVector = bindingVec->second;
for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
{ {
if (mSamplerTexture[type][sampler].id() == texture) BindingPointer<Texture> &binding = textureVector[textureIdx];
if (binding.id() == texture)
{ {
mSamplerTexture[type][sampler].set(NULL); binding.set(NULL);
} }
} }
} }
...@@ -650,7 +674,7 @@ void State::setSamplerBinding(GLuint textureUnit, Sampler *sampler) ...@@ -650,7 +674,7 @@ void State::setSamplerBinding(GLuint textureUnit, Sampler *sampler)
GLuint State::getSamplerId(GLuint textureUnit) const GLuint State::getSamplerId(GLuint textureUnit) const
{ {
ASSERT(textureUnit < ArraySize(mSamplers)); ASSERT(textureUnit < mSamplers.size());
return mSamplers[textureUnit].id(); return mSamplers[textureUnit].id();
} }
...@@ -665,11 +689,12 @@ void State::detachSampler(GLuint sampler) ...@@ -665,11 +689,12 @@ void State::detachSampler(GLuint sampler)
// If a sampler object that is currently bound to one or more texture units is // If a sampler object that is currently bound to one or more texture units is
// deleted, it is as though BindSampler is called once for each texture unit to // deleted, it is as though BindSampler is called once for each texture unit to
// which the sampler is bound, with unit set to the texture unit and sampler set to zero. // which the sampler is bound, with unit set to the texture unit and sampler set to zero.
for (unsigned int textureUnit = 0; textureUnit < ArraySize(mSamplers); textureUnit++) for (size_t textureUnit = 0; textureUnit < mSamplers.size(); textureUnit++)
{ {
if (mSamplers[textureUnit].id() == sampler) BindingPointer<Sampler> &samplerBinding = mSamplers[textureUnit];
if (samplerBinding.id() == sampler)
{ {
mSamplers[textureUnit].set(NULL); samplerBinding.set(NULL);
} }
} }
} }
...@@ -1308,19 +1333,19 @@ void State::getIntegerv(GLenum pname, GLint *params) ...@@ -1308,19 +1333,19 @@ void State::getIntegerv(GLenum pname, GLint *params)
break; break;
case GL_TEXTURE_BINDING_2D: case GL_TEXTURE_BINDING_2D:
ASSERT(mActiveSampler < mContext->getCaps().maxCombinedTextureImageUnits); ASSERT(mActiveSampler < mContext->getCaps().maxCombinedTextureImageUnits);
*params = mSamplerTexture[TEXTURE_2D][mActiveSampler].id(); *params = mSamplerTextures.at(GL_TEXTURE_2D)[mActiveSampler].id();
break; break;
case GL_TEXTURE_BINDING_CUBE_MAP: case GL_TEXTURE_BINDING_CUBE_MAP:
ASSERT(mActiveSampler < mContext->getCaps().maxCombinedTextureImageUnits); ASSERT(mActiveSampler < mContext->getCaps().maxCombinedTextureImageUnits);
*params = mSamplerTexture[TEXTURE_CUBE][mActiveSampler].id(); *params = mSamplerTextures.at(GL_TEXTURE_CUBE_MAP)[mActiveSampler].id();
break; break;
case GL_TEXTURE_BINDING_3D: case GL_TEXTURE_BINDING_3D:
ASSERT(mActiveSampler <mContext->getCaps().maxCombinedTextureImageUnits); ASSERT(mActiveSampler <mContext->getCaps().maxCombinedTextureImageUnits);
*params = mSamplerTexture[TEXTURE_3D][mActiveSampler].id(); *params = mSamplerTextures.at(GL_TEXTURE_3D)[mActiveSampler].id();
break; break;
case GL_TEXTURE_BINDING_2D_ARRAY: case GL_TEXTURE_BINDING_2D_ARRAY:
ASSERT(mActiveSampler < mContext->getCaps().maxCombinedTextureImageUnits); ASSERT(mActiveSampler < mContext->getCaps().maxCombinedTextureImageUnits);
*params = mSamplerTexture[TEXTURE_2D_ARRAY][mActiveSampler].id(); *params = mSamplerTextures.at(GL_TEXTURE_2D_ARRAY)[mActiveSampler].id();
break; break;
case GL_UNIFORM_BUFFER_BINDING: case GL_UNIFORM_BUFFER_BINDING:
*params = mGenericUniformBuffer.id(); *params = mGenericUniformBuffer.id();
......
...@@ -24,6 +24,7 @@ namespace gl ...@@ -24,6 +24,7 @@ namespace gl
class Query; class Query;
class VertexArray; class VertexArray;
class Context; class Context;
struct Caps;
class State class State
{ {
...@@ -31,6 +32,9 @@ class State ...@@ -31,6 +32,9 @@ class State
State(); State();
~State(); ~State();
void initialize(const Caps& caps, GLuint clientVersion);
void reset();
void setContext(Context *context) { mContext = context; } void setContext(Context *context) { mContext = context; }
// State chunk getters // State chunk getters
...@@ -126,9 +130,9 @@ class State ...@@ -126,9 +130,9 @@ class State
// Texture binding & active texture unit manipulation // Texture binding & active texture unit manipulation
void setActiveSampler(unsigned int active); void setActiveSampler(unsigned int active);
unsigned int getActiveSampler() const; unsigned int getActiveSampler() const;
void setSamplerTexture(TextureType type, Texture *texture); void setSamplerTexture(GLenum type, Texture *texture);
Texture *getSamplerTexture(unsigned int sampler, TextureType type) const; Texture *getSamplerTexture(unsigned int sampler, GLenum type) const;
GLuint getSamplerTextureId(unsigned int sampler, TextureType type) const; GLuint getSamplerTextureId(unsigned int sampler, GLenum type) const;
void detachTexture(GLuint texture); void detachTexture(GLuint texture);
// Sampler object binding manipulation // Sampler object binding manipulation
...@@ -272,7 +276,6 @@ class State ...@@ -272,7 +276,6 @@ class State
float mNearZ; float mNearZ;
float mFarZ; float mFarZ;
unsigned int mActiveSampler; // Active texture unit selector - GL_TEXTURE0
BindingPointer<Buffer> mArrayBuffer; BindingPointer<Buffer> mArrayBuffer;
Framebuffer *mReadFramebuffer; Framebuffer *mReadFramebuffer;
Framebuffer *mDrawFramebuffer; Framebuffer *mDrawFramebuffer;
...@@ -283,8 +286,15 @@ class State ...@@ -283,8 +286,15 @@ class State
VertexAttribCurrentValueData mVertexAttribCurrentValues[MAX_VERTEX_ATTRIBS]; // From glVertexAttrib VertexAttribCurrentValueData mVertexAttribCurrentValues[MAX_VERTEX_ATTRIBS]; // From glVertexAttrib
VertexArray *mVertexArray; VertexArray *mVertexArray;
BindingPointer<Texture> mSamplerTexture[TEXTURE_TYPE_COUNT][IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS]; // Texture and sampler bindings
BindingPointer<Sampler> mSamplers[IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS]; size_t mActiveSampler; // Active texture unit selector - GL_TEXTURE0
typedef std::vector< BindingPointer<Texture> > TextureBindingVector;
typedef std::map<GLenum, TextureBindingVector> TextureBindingMap;
TextureBindingMap mSamplerTextures;
typedef std::vector< BindingPointer<Sampler> > SamplerBindingVector;
SamplerBindingVector mSamplers;
typedef std::map< GLenum, BindingPointer<Query> > ActiveQueryMap; typedef std::map< GLenum, BindingPointer<Query> > ActiveQueryMap;
ActiveQueryMap mActiveQueries; ActiveQueryMap mActiveQueries;
......
...@@ -19,17 +19,6 @@ class ProgramBinary; ...@@ -19,17 +19,6 @@ class ProgramBinary;
struct VertexAttribute; struct VertexAttribute;
struct VertexAttribCurrentValueData; struct VertexAttribCurrentValueData;
enum TextureType
{
TEXTURE_2D,
TEXTURE_CUBE,
TEXTURE_3D,
TEXTURE_2D_ARRAY,
TEXTURE_TYPE_COUNT,
TEXTURE_UNKNOWN
};
enum SamplerType enum SamplerType
{ {
SAMPLER_PIXEL, SAMPLER_PIXEL,
......
...@@ -15,12 +15,8 @@ namespace gl ...@@ -15,12 +15,8 @@ namespace gl
enum enum
{ {
MAX_VERTEX_ATTRIBS = 16, MAX_VERTEX_ATTRIBS = 16,
MAX_TEXTURE_IMAGE_UNITS = 16,
// Implementation upper limits, real maximums depend on the hardware // Implementation upper limits, real maximums depend on the hardware
IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS = 16,
IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS = MAX_TEXTURE_IMAGE_UNITS + IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS,
IMPLEMENTATION_MAX_VARYING_VECTORS = 32, IMPLEMENTATION_MAX_VARYING_VECTORS = 32,
IMPLEMENTATION_MAX_DRAW_BUFFERS = 8, IMPLEMENTATION_MAX_DRAW_BUFFERS = 8,
IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS = IMPLEMENTATION_MAX_DRAW_BUFFERS + 2, // 2 extra for depth and/or stencil buffers IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS = IMPLEMENTATION_MAX_DRAW_BUFFERS + 2, // 2 extra for depth and/or stencil buffers
......
...@@ -265,35 +265,24 @@ void __stdcall glBindTexture(GLenum target, GLuint texture) ...@@ -265,35 +265,24 @@ void __stdcall glBindTexture(GLenum target, GLuint texture)
switch (target) switch (target)
{ {
case GL_TEXTURE_2D: case GL_TEXTURE_2D:
context->bindTexture2D(texture);
return;
case GL_TEXTURE_CUBE_MAP: case GL_TEXTURE_CUBE_MAP:
context->bindTextureCubeMap(texture); break;
return;
case GL_TEXTURE_3D: case GL_TEXTURE_3D:
if (context->getClientVersion() < 3)
{
context->recordError(gl::Error(GL_INVALID_ENUM));
return;
}
context->bindTexture3D(texture);
return;
case GL_TEXTURE_2D_ARRAY: case GL_TEXTURE_2D_ARRAY:
if (context->getClientVersion() < 3) if (context->getClientVersion() < 3)
{ {
context->recordError(gl::Error(GL_INVALID_ENUM)); context->recordError(gl::Error(GL_INVALID_ENUM));
return; return;
} }
context->bindTexture2DArray(texture); break;
return;
default: default:
context->recordError(gl::Error(GL_INVALID_ENUM)); context->recordError(gl::Error(GL_INVALID_ENUM));
return; return;
} }
context->bindTexture(target, texture);
} }
} }
......
...@@ -315,6 +315,17 @@ void Renderer11::initializeDevice() ...@@ -315,6 +315,17 @@ void Renderer11::initializeDevice()
ASSERT(!mPixelTransfer); ASSERT(!mPixelTransfer);
mPixelTransfer = new PixelTransfer11(this); mPixelTransfer = new PixelTransfer11(this);
const gl::Caps &rendererCaps = getRendererCaps();
mForceSetVertexSamplerStates.resize(rendererCaps.maxVertexTextureImageUnits);
mCurVertexSamplerStates.resize(rendererCaps.maxVertexTextureImageUnits);
mForceSetPixelSamplerStates.resize(rendererCaps.maxTextureImageUnits);
mCurPixelSamplerStates.resize(rendererCaps.maxTextureImageUnits);
mCurVertexSRVs.resize(rendererCaps.maxVertexTextureImageUnits);
mCurPixelSRVs.resize(rendererCaps.maxTextureImageUnits);
markAllStateDirty(); markAllStateDirty();
} }
...@@ -324,7 +335,7 @@ int Renderer11::generateConfigs(ConfigDesc **configDescList) ...@@ -324,7 +335,7 @@ int Renderer11::generateConfigs(ConfigDesc **configDescList)
unsigned int numDepthFormats = ArraySize(DepthStencilFormats); unsigned int numDepthFormats = ArraySize(DepthStencilFormats);
(*configDescList) = new ConfigDesc[numRenderFormats * numDepthFormats]; (*configDescList) = new ConfigDesc[numRenderFormats * numDepthFormats];
int numConfigs = 0; int numConfigs = 0;
for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++) for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++)
{ {
const d3d11::DXGIFormat &renderTargetFormatInfo = d3d11::GetDXGIFormatInfo(RenderTargetFormats[formatIndex]); const d3d11::DXGIFormat &renderTargetFormatInfo = d3d11::GetDXGIFormatInfo(RenderTargetFormats[formatIndex]);
...@@ -1556,12 +1567,15 @@ void Renderer11::markAllStateDirty() ...@@ -1556,12 +1567,15 @@ void Renderer11::markAllStateDirty()
mDepthStencilInitialized = false; mDepthStencilInitialized = false;
mRenderTargetDescInitialized = false; mRenderTargetDescInitialized = false;
for (int i = 0; i < gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; i++) ASSERT(mForceSetVertexSamplerStates.size() == mCurVertexSRVs.size());
for (int i = 0; i < mForceSetVertexSamplerStates.size(); i++)
{ {
mForceSetVertexSamplerStates[i] = true; mForceSetVertexSamplerStates[i] = true;
mCurVertexSRVs[i] = NULL; mCurVertexSRVs[i] = NULL;
} }
for (int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++)
ASSERT(mForceSetPixelSamplerStates.size() == mCurPixelSRVs.size());
for (int i = 0; i < mForceSetPixelSamplerStates.size(); i++)
{ {
mForceSetPixelSamplerStates[i] = true; mForceSetPixelSamplerStates[i] = true;
mCurPixelSRVs[i] = NULL; mCurPixelSRVs[i] = NULL;
......
...@@ -245,15 +245,15 @@ class Renderer11 : public Renderer ...@@ -245,15 +245,15 @@ class Renderer11 : public Renderer
rx::RenderTarget::Desc mRenderTargetDesc; rx::RenderTarget::Desc mRenderTargetDesc;
// Currently applied sampler states // Currently applied sampler states
bool mForceSetVertexSamplerStates[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; std::vector<bool> mForceSetVertexSamplerStates;
gl::SamplerState mCurVertexSamplerStates[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; std::vector<gl::SamplerState> mCurVertexSamplerStates;
bool mForceSetPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS]; std::vector<bool> mForceSetPixelSamplerStates;
gl::SamplerState mCurPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS]; std::vector<gl::SamplerState> mCurPixelSamplerStates;
// Currently applied textures // Currently applied textures
ID3D11ShaderResourceView *mCurVertexSRVs[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; std::vector<ID3D11ShaderResourceView*> mCurVertexSRVs;
ID3D11ShaderResourceView *mCurPixelSRVs[gl::MAX_TEXTURE_IMAGE_UNITS]; std::vector<ID3D11ShaderResourceView*> mCurPixelSRVs;
// Currently applied blend state // Currently applied blend state
bool mForceSetBlendState; bool mForceSetBlendState;
......
...@@ -944,7 +944,7 @@ void GenerateCaps(ID3D11Device *device, gl::Caps *caps, gl::TextureCapsMap *text ...@@ -944,7 +944,7 @@ void GenerateCaps(ID3D11Device *device, gl::Caps *caps, gl::TextureCapsMap *text
static_cast<GLint64>(caps->maxFragmentUniformComponents); static_cast<GLint64>(caps->maxFragmentUniformComponents);
caps->maxVaryingComponents = GetMaximumVertexOutputVectors(featureLevel) * 4; caps->maxVaryingComponents = GetMaximumVertexOutputVectors(featureLevel) * 4;
caps->maxVaryingVectors = GetMaximumVertexOutputVectors(featureLevel); caps->maxVaryingVectors = GetMaximumVertexOutputVectors(featureLevel);
caps->maxCombinedTextureImageUnits = caps->maxVertexTextureImageUnits + caps->maxFragmentInputComponents; caps->maxCombinedTextureImageUnits = caps->maxVertexTextureImageUnits + caps->maxTextureImageUnits;
// Transform feedback limits // Transform feedback limits
caps->maxTransformFeedbackInterleavedComponents = GetMaximumStreamOutputInterleavedComponenets(featureLevel); caps->maxTransformFeedbackInterleavedComponents = GetMaximumStreamOutputInterleavedComponenets(featureLevel);
......
...@@ -379,6 +379,17 @@ void Renderer9::initializeDevice() ...@@ -379,6 +379,17 @@ void Renderer9::initializeDevice()
mDevice->SetRenderState(D3DRS_POINTSIZE_MAX, 0x3F800000); // 1.0f mDevice->SetRenderState(D3DRS_POINTSIZE_MAX, 0x3F800000); // 1.0f
} }
const gl::Caps &rendererCaps = getRendererCaps();
mForceSetVertexSamplerStates.resize(rendererCaps.maxVertexTextureImageUnits);
mCurVertexSamplerStates.resize(rendererCaps.maxVertexTextureImageUnits);
mForceSetPixelSamplerStates.resize(rendererCaps.maxTextureImageUnits);
mCurPixelSamplerStates.resize(rendererCaps.maxTextureImageUnits);
mCurVertexTextureSerials.resize(rendererCaps.maxVertexTextureImageUnits);
mCurPixelTextureSerials.resize(rendererCaps.maxTextureImageUnits);
markAllStateDirty(); markAllStateDirty();
mSceneStarted = false; mSceneStarted = false;
...@@ -633,8 +644,8 @@ void Renderer9::generateSwizzle(gl::Texture *texture) ...@@ -633,8 +644,8 @@ void Renderer9::generateSwizzle(gl::Texture *texture)
void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) void Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState)
{ {
bool *forceSetSamplers = (type == gl::SAMPLER_PIXEL) ? mForceSetPixelSamplerStates : mForceSetVertexSamplerStates; std::vector<bool> &forceSetSamplers = (type == gl::SAMPLER_PIXEL) ? mForceSetPixelSamplerStates : mForceSetVertexSamplerStates;
gl::SamplerState *appliedSamplers = (type == gl::SAMPLER_PIXEL) ? mCurPixelSamplerStates: mCurVertexSamplerStates; std::vector<gl::SamplerState> &appliedSamplers = (type == gl::SAMPLER_PIXEL) ? mCurPixelSamplerStates: mCurVertexSamplerStates;
if (forceSetSamplers[index] || memcmp(&samplerState, &appliedSamplers[index], sizeof(gl::SamplerState)) != 0) if (forceSetSamplers[index] || memcmp(&samplerState, &appliedSamplers[index], sizeof(gl::SamplerState)) != 0)
{ {
...@@ -668,7 +679,7 @@ void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture ...@@ -668,7 +679,7 @@ void Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *texture
unsigned int serial = 0; unsigned int serial = 0;
bool forceSetTexture = false; bool forceSetTexture = false;
unsigned int *appliedSerials = (type == gl::SAMPLER_PIXEL) ? mCurPixelTextureSerials : mCurVertexTextureSerials; std::vector<unsigned int> &appliedSerials = (type == gl::SAMPLER_PIXEL) ? mCurPixelTextureSerials : mCurVertexTextureSerials;
if (texture) if (texture)
{ {
...@@ -2022,12 +2033,15 @@ void Renderer9::markAllStateDirty() ...@@ -2022,12 +2033,15 @@ void Renderer9::markAllStateDirty()
mForceSetViewport = true; mForceSetViewport = true;
mForceSetBlendState = true; mForceSetBlendState = true;
for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; i++) ASSERT(mForceSetVertexSamplerStates.size() == mCurVertexTextureSerials.size());
for (unsigned int i = 0; i < mForceSetVertexSamplerStates.size(); i++)
{ {
mForceSetVertexSamplerStates[i] = true; mForceSetVertexSamplerStates[i] = true;
mCurVertexTextureSerials[i] = 0; mCurVertexTextureSerials[i] = 0;
} }
for (unsigned int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++)
ASSERT(mForceSetPixelSamplerStates.size() == mCurPixelTextureSerials.size());
for (unsigned int i = 0; i < mForceSetPixelSamplerStates.size(); i++)
{ {
mForceSetPixelSamplerStates[i] = true; mForceSetPixelSamplerStates[i] = true;
mCurPixelTextureSerials[i] = 0; mCurPixelTextureSerials[i] = 0;
...@@ -3082,12 +3096,9 @@ TextureImpl *Renderer9::createTexture(GLenum target) ...@@ -3082,12 +3096,9 @@ TextureImpl *Renderer9::createTexture(GLenum target)
{ {
switch(target) switch(target)
{ {
case GL_TEXTURE_2D: return new TextureD3D_2D(this); case GL_TEXTURE_2D: return new TextureD3D_2D(this);
case GL_TEXTURE_CUBE_MAP: return new TextureD3D_Cube(this); case GL_TEXTURE_CUBE_MAP: return new TextureD3D_Cube(this);
case GL_TEXTURE_3D: return new TextureD3D_3D(this); default: UNREACHABLE();
case GL_TEXTURE_2D_ARRAY: return new TextureD3D_2DArray(this);
default:
UNREACHABLE();
} }
return NULL; return NULL;
......
...@@ -295,15 +295,15 @@ class Renderer9 : public Renderer ...@@ -295,15 +295,15 @@ class Renderer9 : public Renderer
GLuint mCurSampleMask; GLuint mCurSampleMask;
// Currently applied sampler states // Currently applied sampler states
bool mForceSetVertexSamplerStates[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; std::vector<bool> mForceSetVertexSamplerStates;
gl::SamplerState mCurVertexSamplerStates[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; std::vector<gl::SamplerState> mCurVertexSamplerStates;
bool mForceSetPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS]; std::vector<bool> mForceSetPixelSamplerStates;
gl::SamplerState mCurPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS]; std::vector<gl::SamplerState> mCurPixelSamplerStates;
// Currently applied textures // Currently applied textures
unsigned int mCurVertexTextureSerials[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; std::vector<unsigned int> mCurVertexTextureSerials;
unsigned int mCurPixelTextureSerials[gl::MAX_TEXTURE_IMAGE_UNITS]; std::vector<unsigned int> mCurPixelTextureSerials;
unsigned int mAppliedIBSerial; unsigned int mAppliedIBSerial;
IDirect3DVertexShader9 *mAppliedVertexShader; IDirect3DVertexShader9 *mAppliedVertexShader;
......
...@@ -436,7 +436,7 @@ void GenerateCaps(IDirect3D9 *d3d9, IDirect3DDevice9 *device, D3DDEVTYPE deviceT ...@@ -436,7 +436,7 @@ void GenerateCaps(IDirect3D9 *d3d9, IDirect3DDevice9 *device, D3DDEVTYPE deviceT
// Aggregate shader limits // Aggregate shader limits
caps->maxVaryingVectors = caps->maxVertexOutputComponents / 4; caps->maxVaryingVectors = caps->maxVertexOutputComponents / 4;
caps->maxCombinedTextureImageUnits = caps->maxVertexTextureImageUnits + caps->maxFragmentInputComponents; caps->maxCombinedTextureImageUnits = caps->maxVertexTextureImageUnits + caps->maxTextureImageUnits;
// Transform feedback limits // Transform feedback limits
caps->maxTransformFeedbackInterleavedComponents = 0; caps->maxTransformFeedbackInterleavedComponents = 0;
......
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