Fixed binding offsets for uniform and transform feedback buffers
There was some confusion between buffer mapping and size and offset
buffer binding arguments, which are distinct, but were represented
by the same Buffer class members. Added OffsetBindingPointer to solve
the issue and removed setOffset/setSize from the Buffer class, which
should not have existed in the first place (only the mapRange/unmap
functions should be allowed to modify these values, for now).
Change-Id: Iacecd17cfb90d0a229d9edf62a463c8acf31f07a
Reviewed-on: https://swiftshader-review.googlesource.com/4590
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/common/Object.hpp b/src/OpenGL/common/Object.hpp
index 14b2975..0dbe07a 100644
--- a/src/OpenGL/common/Object.hpp
+++ b/src/OpenGL/common/Object.hpp
@@ -31,7 +31,7 @@
virtual void addRef();
virtual void release();
-
+
private:
volatile int referenceCount;
};
@@ -61,7 +61,7 @@
ASSERT(!object); // Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up. Assign null to all binding pointers to make the reference count go to zero.
}
- ObjectType *operator=(ObjectType *newObject)
+ ObjectType *operator=(ObjectType *newObject)
{
if(newObject) newObject->addRef();
if(object) object->release();
@@ -71,7 +71,7 @@
return object;
}
- ObjectType *operator=(const BindingPointer<ObjectType> &other)
+ ObjectType *operator=(const BindingPointer<ObjectType> &other)
{
return operator=(other.object);
}
diff --git a/src/OpenGL/libGLESv2/Buffer.h b/src/OpenGL/libGLESv2/Buffer.h
index 1f509ec..b5e47cb 100644
--- a/src/OpenGL/libGLESv2/Buffer.h
+++ b/src/OpenGL/libGLESv2/Buffer.h
@@ -44,8 +44,6 @@
GLsizeiptr length() const { return mLength; }
GLbitfield access() const { return mAccess; }
- void setOffset(GLintptr offset) { mOffset = offset; }
- void setSize(size_t size) { mSize = size; }
void* mapRange(GLintptr offset, GLsizeiptr length, GLbitfield access);
bool unmap();
void flushMappedRange(GLintptr offset, GLsizeiptr length) {}
@@ -62,6 +60,28 @@
GLbitfield mAccess;
};
+class UniformBufferBinding
+{
+public:
+ UniformBufferBinding() : offset(0), size(0) { }
+
+ void set(Buffer *newUniformBuffer, int newOffset = 0, int newSize = 0)
+ {
+ uniformBuffer = newUniformBuffer;
+ offset = newOffset;
+ size = newSize;
+ }
+
+ int getOffset() const { return offset; }
+ int getSize() const { return size; }
+ const gl::BindingPointer<Buffer>& get() const { return uniformBuffer; }
+
+private:
+ gl::BindingPointer<Buffer> uniformBuffer;
+ int offset;
+ int size;
+};
+
}
#endif // LIBGLESV2_BUFFER_H_
diff --git a/src/OpenGL/libGLESv2/Context.cpp b/src/OpenGL/libGLESv2/Context.cpp
index af69141..04ec7f8 100644
--- a/src/OpenGL/libGLESv2/Context.cpp
+++ b/src/OpenGL/libGLESv2/Context.cpp
@@ -1293,12 +1293,7 @@
mResourceManager->checkBufferAllocation(buffer);
Buffer* bufferObject = getBuffer(buffer);
- if(bufferObject)
- {
- bufferObject->setOffset(offset);
- bufferObject->setSize(size);
- }
- mState.uniformBuffers[index] = bufferObject;
+ mState.uniformBuffers[index].set(bufferObject, offset, size);
}
void Context::bindGenericTransformFeedbackBuffer(GLuint buffer)
@@ -1313,12 +1308,7 @@
mResourceManager->checkBufferAllocation(buffer);
Buffer* bufferObject = getBuffer(buffer);
- if(bufferObject)
- {
- bufferObject->setOffset(offset);
- bufferObject->setSize(size);
- }
- getTransformFeedback()->setBuffer(index, bufferObject);
+ getTransformFeedback()->setBuffer(index, bufferObject, offset, size);
}
bool Context::bindTransformFeedback(GLuint id)
diff --git a/src/OpenGL/libGLESv2/Context.h b/src/OpenGL/libGLESv2/Context.h
index eb4e810..cf06cfb 100644
--- a/src/OpenGL/libGLESv2/Context.h
+++ b/src/OpenGL/libGLESv2/Context.h
@@ -44,7 +44,6 @@
struct TranslatedIndexData;
class Device;
-class Buffer;
class Shader;
class Program;
class Texture;
@@ -378,7 +377,7 @@
gl::BindingPointer<Buffer> pixelPackBuffer;
gl::BindingPointer<Buffer> pixelUnpackBuffer;
gl::BindingPointer<Buffer> genericUniformBuffer;
- gl::BindingPointer<Buffer> uniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];
+ UniformBufferBinding uniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];
GLuint readFramebuffer;
GLuint drawFramebuffer;
diff --git a/src/OpenGL/libGLESv2/Program.cpp b/src/OpenGL/libGLESv2/Program.cpp
index 28b5571..17719a6 100644
--- a/src/OpenGL/libGLESv2/Program.cpp
+++ b/src/OpenGL/libGLESv2/Program.cpp
@@ -284,7 +284,7 @@
int Program::getAttributeStream(int attributeIndex)
{
ASSERT(attributeIndex >= 0 && attributeIndex < MAX_VERTEX_ATTRIBS);
-
+
return attributeStream[attributeIndex];
}
@@ -485,7 +485,7 @@
{
return false; // Attempting to write an array to a non-array uniform is an INVALID_OPERATION
}
-
+
count = std::min(size - (int)uniformIndex[location].element, count);
int index = numElements - 1;
@@ -672,7 +672,7 @@
{
return false; // Attempting to write an array to a non-array uniform is an INVALID_OPERATION
}
-
+
count = std::min(size - (int)uniformIndex[location].element, count);
if(targetUniform->type == GL_INT || targetUniform->type == GL_UNSIGNED_INT || IsSamplerUniform(targetUniform->type))
@@ -729,7 +729,7 @@
{
return false; // Attempting to write an array to a non-array uniform is an INVALID_OPERATION
}
-
+
count = std::min(size - (int)uniformIndex[location].element, count);
int index = numElements - 1;
@@ -791,7 +791,7 @@
{
return false; // Attempting to write an array to a non-array uniform is an INVALID_OPERATION
}
-
+
count = std::min(size - (int)uniformIndex[location].element, count);
if(targetUniform->type == GL_INT || targetUniform->type == GL_UNSIGNED_INT || IsSamplerUniform(targetUniform->type))
@@ -848,7 +848,7 @@
{
return false; // Attempting to write an array to a non-array uniform is an INVALID_OPERATION
}
-
+
count = std::min(size - (int)uniformIndex[location].element, count);
int index = numElements - 1;
@@ -1132,7 +1132,7 @@
}
}
- void Program::applyUniformBuffers(gl::BindingPointer<Buffer>* uniformBuffers)
+ void Program::applyUniformBuffers(UniformBufferBinding* uniformBuffers)
{
GLint vertexUniformBuffers[IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS];
GLint fragmentUniformBuffers[IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS];
@@ -1175,9 +1175,9 @@
for(unsigned int bufferBindingIndex = 0; bufferBindingIndex < IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS; ++bufferBindingIndex)
{
int index = vertexUniformBuffers[bufferBindingIndex];
- device->VertexProcessor::setUniformBuffer(bufferBindingIndex, (index != -1) ? uniformBuffers[index]->getResource() : nullptr, 0);
+ device->VertexProcessor::setUniformBuffer(bufferBindingIndex, (index != -1) ? uniformBuffers[index].get()->getResource() : nullptr, (index != -1) ? uniformBuffers[index].getOffset() : 0);
index = fragmentUniformBuffers[bufferBindingIndex];
- device->PixelProcessor::setUniformBuffer(bufferBindingIndex, (index != -1) ? uniformBuffers[index]->getResource() : nullptr, 0);
+ device->PixelProcessor::setUniformBuffer(bufferBindingIndex, (index != -1) ? uniformBuffers[index].get()->getResource() : nullptr, (index != -1) ? uniformBuffers[index].getOffset() : 0);
}
}
@@ -1256,7 +1256,7 @@
if(components >= 1) pixelBinary->semantic[in + i][0] = sw::Shader::Semantic();
if(components >= 2) pixelBinary->semantic[in + i][1] = sw::Shader::Semantic();
if(components >= 3) pixelBinary->semantic[in + i][2] = sw::Shader::Semantic();
- if(components >= 4) pixelBinary->semantic[in + i][3] = sw::Shader::Semantic();
+ if(components >= 4) pixelBinary->semantic[in + i][3] = sw::Shader::Semantic();
}
}
@@ -1316,7 +1316,7 @@
vertexBinary = new sw::VertexShader(vertexShader->getVertexShader());
pixelBinary = new sw::PixelShader(fragmentShader->getPixelShader());
-
+
if(!linkVaryings())
{
return;
@@ -1467,7 +1467,7 @@
if(IsSamplerUniform(type))
{
int index = registerIndex;
-
+
do
{
if(shader == GL_VERTEX_SHADER)
@@ -1510,7 +1510,7 @@
if(index < MAX_TEXTURE_IMAGE_UNITS)
{
samplersPS[index].active = true;
-
+
switch(type)
{
default: UNREACHABLE(type);
@@ -2307,7 +2307,7 @@
return linked;
}
- bool Program::isValidated() const
+ bool Program::isValidated() const
{
return validated;
}
@@ -2685,7 +2685,7 @@
{
resetInfoLog();
- if(!isLinked())
+ if(!isLinked())
{
appendToInfoLog("Program has not been successfully linked.");
validated = false;
@@ -2722,7 +2722,7 @@
if(samplersPS[i].active)
{
unsigned int unit = samplersPS[i].logicalTextureUnit;
-
+
if(unit >= MAX_COMBINED_TEXTURE_IMAGE_UNITS)
{
if(logErrors)
@@ -2757,7 +2757,7 @@
if(samplersVS[i].active)
{
unsigned int unit = samplersVS[i].logicalTextureUnit;
-
+
if(unit >= MAX_COMBINED_TEXTURE_IMAGE_UNITS)
{
if(logErrors)
diff --git a/src/OpenGL/libGLESv2/Program.h b/src/OpenGL/libGLESv2/Program.h
index 86a861e..641b415 100644
--- a/src/OpenGL/libGLESv2/Program.h
+++ b/src/OpenGL/libGLESv2/Program.h
@@ -167,7 +167,7 @@
void dirtyAllUniforms();
void applyUniforms();
- void applyUniformBuffers(gl::BindingPointer<Buffer>* uniformBuffers);
+ void applyUniformBuffers(UniformBufferBinding* uniformBuffers);
void link();
bool isLinked() const;
diff --git a/src/OpenGL/libGLESv2/TransformFeedback.cpp b/src/OpenGL/libGLESv2/TransformFeedback.cpp
index e69f9ad..d71c748 100644
--- a/src/OpenGL/libGLESv2/TransformFeedback.cpp
+++ b/src/OpenGL/libGLESv2/TransformFeedback.cpp
@@ -13,8 +13,6 @@
#include "TransformFeedback.h"
-#include "Buffer.h"
-
namespace es2
{
@@ -28,7 +26,7 @@
mGenericBuffer = NULL;
for(int i = 0; i < MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS; ++i)
{
- mBuffer[i] = NULL;
+ mBuffer[i].set(nullptr);
}
}
@@ -39,7 +37,7 @@
Buffer* TransformFeedback::getBuffer(GLuint index) const
{
- return mBuffer[index];
+ return mBuffer[index].get();
}
bool TransformFeedback::isActive() const
@@ -80,16 +78,12 @@
void TransformFeedback::setBuffer(GLuint index, Buffer* buffer)
{
- mBuffer[index] = buffer;
+ mBuffer[index].set(buffer);
}
void TransformFeedback::setBuffer(GLuint index, Buffer* buffer, GLintptr offset, GLsizeiptr size)
{
- mBuffer[index] = buffer;
- if(buffer)
- {
- buffer->mapRange(offset, size, buffer->access());
- }
+ mBuffer[index].set(buffer, offset, size);
}
void TransformFeedback::detachBuffer(GLuint buffer)
@@ -101,9 +95,9 @@
for(int i = 0; i < MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS; ++i)
{
- if(mBuffer[i].name() == buffer)
+ if(mBuffer[i].get().name() == buffer)
{
- mBuffer[i] = NULL;
+ mBuffer[i].set(nullptr);
}
}
}
diff --git a/src/OpenGL/libGLESv2/TransformFeedback.h b/src/OpenGL/libGLESv2/TransformFeedback.h
index ab86604..631f17f 100644
--- a/src/OpenGL/libGLESv2/TransformFeedback.h
+++ b/src/OpenGL/libGLESv2/TransformFeedback.h
@@ -14,6 +14,7 @@
#ifndef LIBGLESV2_TRANSFORM_FEEDBACK_H_
#define LIBGLESV2_TRANSFORM_FEEDBACK_H_
+#include "Buffer.h"
#include "common/Object.hpp"
#include "Renderer/Renderer.hpp"
@@ -21,7 +22,6 @@
namespace es2
{
-class Buffer;
class TransformFeedback : public gl::NamedObject
{
@@ -46,7 +46,7 @@
private:
gl::BindingPointer<Buffer> mGenericBuffer;
- gl::BindingPointer<Buffer> mBuffer[MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS];
+ UniformBufferBinding mBuffer[MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS];
bool mActive;
bool mPaused;