Commit dd5f27ee by Martin Radev Committed by Commit Bot

Make VertexBinding's member variables private

The patch decorates all members in VertexBinding as private and limits access to them only through getters and setters. This makes it easier to debug and keep track of any assignments to the class members. BUG=angleproject:2062 TEST=angle_end2end_tests Change-Id: Iddd49063d060f136bc9cf11c313a5af0931d433c Reviewed-on: https://chromium-review.googlesource.com/530786 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent cdadb3ff
...@@ -1976,19 +1976,19 @@ void State::getIntegeri_v(GLenum target, GLuint index, GLint *data) ...@@ -1976,19 +1976,19 @@ void State::getIntegeri_v(GLenum target, GLuint index, GLint *data)
break; break;
case GL_VERTEX_BINDING_BUFFER: case GL_VERTEX_BINDING_BUFFER:
ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
*data = mVertexArray->getVertexBinding(index).buffer.id(); *data = mVertexArray->getVertexBinding(index).getBuffer().id();
break; break;
case GL_VERTEX_BINDING_DIVISOR: case GL_VERTEX_BINDING_DIVISOR:
ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
*data = mVertexArray->getVertexBinding(index).divisor; *data = mVertexArray->getVertexBinding(index).getDivisor();
break; break;
case GL_VERTEX_BINDING_OFFSET: case GL_VERTEX_BINDING_OFFSET:
ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
*data = static_cast<GLuint>(mVertexArray->getVertexBinding(index).offset); *data = static_cast<GLuint>(mVertexArray->getVertexBinding(index).getOffset());
break; break;
case GL_VERTEX_BINDING_STRIDE: case GL_VERTEX_BINDING_STRIDE:
ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
*data = mVertexArray->getVertexBinding(index).stride; *data = mVertexArray->getVertexBinding(index).getStride();
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -2054,7 +2054,7 @@ bool State::hasMappedBuffer(GLenum target) const ...@@ -2054,7 +2054,7 @@ bool State::hasMappedBuffer(GLenum target) const
for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++) for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++)
{ {
const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex]; const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex];
auto *boundBuffer = vertexBindings[vertexAttrib.bindingIndex].buffer.get(); auto *boundBuffer = vertexBindings[vertexAttrib.bindingIndex].getBuffer().get();
if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped()) if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped())
{ {
return true; return true;
......
...@@ -30,7 +30,7 @@ VertexArrayState::~VertexArrayState() ...@@ -30,7 +30,7 @@ VertexArrayState::~VertexArrayState()
{ {
for (auto &binding : mVertexBindings) for (auto &binding : mVertexBindings)
{ {
binding.buffer.set(nullptr); binding.setBuffer(nullptr);
} }
mElementArrayBuffer.set(nullptr); mElementArrayBuffer.set(nullptr);
} }
...@@ -69,9 +69,9 @@ void VertexArray::detachBuffer(GLuint bufferName) ...@@ -69,9 +69,9 @@ void VertexArray::detachBuffer(GLuint bufferName)
{ {
for (auto &binding : mState.mVertexBindings) for (auto &binding : mState.mVertexBindings)
{ {
if (binding.buffer.id() == bufferName) if (binding.getBuffer().id() == bufferName)
{ {
binding.buffer.set(nullptr); binding.setBuffer(nullptr);
} }
} }
...@@ -110,9 +110,9 @@ void VertexArray::bindVertexBuffer(size_t bindingIndex, ...@@ -110,9 +110,9 @@ void VertexArray::bindVertexBuffer(size_t bindingIndex,
VertexBinding *binding = &mState.mVertexBindings[bindingIndex]; VertexBinding *binding = &mState.mVertexBindings[bindingIndex];
binding->buffer.set(boundBuffer); binding->setBuffer(boundBuffer);
binding->offset = offset; binding->setOffset(offset);
binding->stride = stride; binding->setStride(stride);
mDirtyBits.set(DIRTY_BIT_BINDING_0_BUFFER + bindingIndex); mDirtyBits.set(DIRTY_BIT_BINDING_0_BUFFER + bindingIndex);
} }
...@@ -128,7 +128,7 @@ void VertexArray::setVertexBindingDivisor(size_t bindingIndex, GLuint divisor) ...@@ -128,7 +128,7 @@ void VertexArray::setVertexBindingDivisor(size_t bindingIndex, GLuint divisor)
{ {
ASSERT(bindingIndex < getMaxBindings()); ASSERT(bindingIndex < getMaxBindings());
mState.mVertexBindings[bindingIndex].divisor = divisor; mState.mVertexBindings[bindingIndex].setDivisor(divisor);
mDirtyBits.set(DIRTY_BIT_BINDING_0_DIVISOR + bindingIndex); mDirtyBits.set(DIRTY_BIT_BINDING_0_DIVISOR + bindingIndex);
} }
......
...@@ -13,7 +13,7 @@ namespace gl ...@@ -13,7 +13,7 @@ namespace gl
// [OpenGL ES 3.1] (November 3, 2016) Section 20 Page 361 // [OpenGL ES 3.1] (November 3, 2016) Section 20 Page 361
// Table 20.2: Vertex Array Object State // Table 20.2: Vertex Array Object State
VertexBinding::VertexBinding() : stride(16u), divisor(0), offset(0) VertexBinding::VertexBinding() : mStride(16u), mDivisor(0), mOffset(0)
{ {
} }
...@@ -26,12 +26,12 @@ VertexBinding &VertexBinding::operator=(VertexBinding &&binding) ...@@ -26,12 +26,12 @@ VertexBinding &VertexBinding::operator=(VertexBinding &&binding)
{ {
if (this != &binding) if (this != &binding)
{ {
stride = binding.stride; mStride = binding.mStride;
divisor = binding.divisor; mDivisor = binding.mDivisor;
offset = binding.offset; mOffset = binding.mOffset;
mBuffer = binding.mBuffer;
buffer.set(binding.buffer.get()); binding.setBuffer(nullptr);
binding.buffer.set(nullptr);
} }
return *this; return *this;
} }
...@@ -103,13 +103,13 @@ size_t ComputeVertexAttributeStride(const VertexAttribute &attrib, const VertexB ...@@ -103,13 +103,13 @@ size_t ComputeVertexAttributeStride(const VertexAttribute &attrib, const VertexB
{ {
// In ES 3.1, VertexAttribPointer will store the type size in the binding stride. // In ES 3.1, VertexAttribPointer will store the type size in the binding stride.
// Hence, rendering always uses the binding's stride. // Hence, rendering always uses the binding's stride.
return attrib.enabled ? binding.stride : 16u; return attrib.enabled ? binding.getStride() : 16u;
} }
// Warning: you should ensure binding really matches attrib.bindingIndex before using this function. // Warning: you should ensure binding really matches attrib.bindingIndex before using this function.
GLintptr ComputeVertexAttributeOffset(const VertexAttribute &attrib, const VertexBinding &binding) GLintptr ComputeVertexAttributeOffset(const VertexAttribute &attrib, const VertexBinding &binding)
{ {
return attrib.relativeOffset + binding.offset; return attrib.relativeOffset + binding.getOffset();
} }
size_t ComputeVertexBindingElementCount(const VertexBinding &binding, size_t ComputeVertexBindingElementCount(const VertexBinding &binding,
...@@ -121,12 +121,13 @@ size_t ComputeVertexBindingElementCount(const VertexBinding &binding, ...@@ -121,12 +121,13 @@ size_t ComputeVertexBindingElementCount(const VertexBinding &binding,
// A vertex attribute with a positive divisor loads one instanced vertex for every set of // A vertex attribute with a positive divisor loads one instanced vertex for every set of
// non-instanced vertices, and the instanced vertex index advances once every "mDivisor" // non-instanced vertices, and the instanced vertex index advances once every "mDivisor"
// instances. // instances.
if (instanceCount > 0 && binding.divisor > 0) GLuint divisor = binding.getDivisor();
if (instanceCount > 0 && divisor > 0)
{ {
// When instanceDrawCount is not a multiple attrib.divisor, the division must round up. // When instanceDrawCount is not a multiple attrib.divisor, the division must round up.
// For instance, with 5 non-instanced vertices and a divisor equal to 3, we need 2 instanced // For instance, with 5 non-instanced vertices and a divisor equal to 3, we need 2 instanced
// vertices. // vertices.
return (instanceCount + binding.divisor - 1u) / binding.divisor; return (instanceCount + divisor - 1u) / divisor;
} }
return drawCount; return drawCount;
......
...@@ -16,19 +16,34 @@ namespace gl ...@@ -16,19 +16,34 @@ namespace gl
class VertexArray; class VertexArray;
// //
// Implementation of Generic Vertex Attribute Bindings for ES3.1 // Implementation of Generic Vertex Attribute Bindings for ES3.1. The members are intentionally made
// private in order to hide implementation details.
// //
struct VertexBinding final : private angle::NonCopyable class VertexBinding final : angle::NonCopyable
{ {
public:
VertexBinding(); VertexBinding();
explicit VertexBinding(VertexBinding &&binding); explicit VertexBinding(VertexBinding &&binding);
VertexBinding &operator=(VertexBinding &&binding); VertexBinding &operator=(VertexBinding &&binding);
GLuint stride; GLuint getStride() const { return mStride; }
GLuint divisor; void setStride(GLuint strideIn) { mStride = strideIn; }
GLintptr offset;
BindingPointer<Buffer> buffer; GLuint getDivisor() const { return mDivisor; }
void setDivisor(GLuint divisorIn) { mDivisor = divisorIn; }
GLintptr getOffset() const { return mOffset; }
void setOffset(GLintptr offsetIn) { mOffset = offsetIn; }
const BindingPointer<Buffer> &getBuffer() const { return mBuffer; }
void setBuffer(Buffer *bufferIn) { mBuffer.set(bufferIn); }
private:
GLuint mStride;
GLuint mDivisor;
GLintptr mOffset;
BindingPointer<Buffer> mBuffer;
}; };
// //
......
...@@ -383,10 +383,10 @@ void QueryVertexAttribBase(const VertexAttribute &attrib, ...@@ -383,10 +383,10 @@ void QueryVertexAttribBase(const VertexAttribute &attrib,
*params = ConvertFromGLboolean<ParamType>(attrib.normalized); *params = ConvertFromGLboolean<ParamType>(attrib.normalized);
break; break;
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
*params = ConvertFromGLuint<ParamType>(binding.buffer.id()); *params = ConvertFromGLuint<ParamType>(binding.getBuffer().id());
break; break;
case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
*params = ConvertFromGLuint<ParamType>(binding.divisor); *params = ConvertFromGLuint<ParamType>(binding.getDivisor());
break; break;
case GL_VERTEX_ATTRIB_ARRAY_INTEGER: case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
*params = ConvertFromGLboolean<ParamType>(attrib.pureInteger); *params = ConvertFromGLboolean<ParamType>(attrib.pureInteger);
......
...@@ -29,7 +29,7 @@ class Texture; ...@@ -29,7 +29,7 @@ class Texture;
struct TextureCaps; struct TextureCaps;
struct UniformBlock; struct UniformBlock;
struct VertexAttribute; struct VertexAttribute;
struct VertexBinding; class VertexBinding;
struct VertexAttribCurrentValueData; struct VertexAttribCurrentValueData;
void QueryFramebufferAttachmentParameteriv(const Framebuffer *framebuffer, void QueryFramebufferAttachmentParameteriv(const Framebuffer *framebuffer,
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
namespace gl namespace gl
{ {
struct VertexAttribute; struct VertexAttribute;
struct VertexBinding; class VertexBinding;
} }
namespace rx namespace rx
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
namespace gl namespace gl
{ {
struct VertexAttribute; struct VertexAttribute;
struct VertexBinding; class VertexBinding;
struct VertexAttribCurrentValueData; struct VertexAttribCurrentValueData;
} }
......
...@@ -63,7 +63,7 @@ bool DirectStoragePossible(const gl::VertexAttribute &attrib, const gl::VertexBi ...@@ -63,7 +63,7 @@ bool DirectStoragePossible(const gl::VertexAttribute &attrib, const gl::VertexBi
return false; return false;
} }
gl::Buffer *buffer = binding.buffer.get(); gl::Buffer *buffer = binding.getBuffer().get();
if (!buffer) if (!buffer)
{ {
return false; return false;
...@@ -149,7 +149,7 @@ VertexStorageType ClassifyAttributeStorage(const gl::VertexAttribute &attrib, ...@@ -149,7 +149,7 @@ VertexStorageType ClassifyAttributeStorage(const gl::VertexAttribute &attrib,
} }
// If specified with immediate data, we must use dynamic storage. // If specified with immediate data, we must use dynamic storage.
auto *buffer = binding.buffer.get(); auto *buffer = binding.getBuffer().get();
if (!buffer) if (!buffer)
{ {
return VertexStorageType::DYNAMIC; return VertexStorageType::DYNAMIC;
...@@ -248,7 +248,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, ...@@ -248,7 +248,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state,
translated->attribute = &attrib; translated->attribute = &attrib;
translated->binding = &binding; translated->binding = &binding;
translated->currentValueType = currentValueData.Type; translated->currentValueType = currentValueData.Type;
translated->divisor = binding.divisor; translated->divisor = binding.getDivisor();
switch (ClassifyAttributeStorage(attrib, binding)) switch (ClassifyAttributeStorage(attrib, binding))
{ {
...@@ -297,7 +297,7 @@ void VertexDataManager::StoreDirectAttrib(TranslatedAttribute *directAttrib) ...@@ -297,7 +297,7 @@ void VertexDataManager::StoreDirectAttrib(TranslatedAttribute *directAttrib)
const auto &attrib = *directAttrib->attribute; const auto &attrib = *directAttrib->attribute;
const auto &binding = *directAttrib->binding; const auto &binding = *directAttrib->binding;
gl::Buffer *buffer = binding.buffer.get(); gl::Buffer *buffer = binding.getBuffer().get();
BufferD3D *bufferD3D = buffer ? GetImplAs<BufferD3D>(buffer) : nullptr; BufferD3D *bufferD3D = buffer ? GetImplAs<BufferD3D>(buffer) : nullptr;
ASSERT(DirectStoragePossible(attrib, binding)); ASSERT(DirectStoragePossible(attrib, binding));
...@@ -309,7 +309,7 @@ void VertexDataManager::StoreDirectAttrib(TranslatedAttribute *directAttrib) ...@@ -309,7 +309,7 @@ void VertexDataManager::StoreDirectAttrib(TranslatedAttribute *directAttrib)
static_cast<unsigned int>(ComputeVertexAttributeOffset(attrib, binding)); static_cast<unsigned int>(ComputeVertexAttributeOffset(attrib, binding));
// Instanced vertices do not apply the 'start' offset // Instanced vertices do not apply the 'start' offset
directAttrib->usesFirstVertexOffset = (binding.divisor == 0); directAttrib->usesFirstVertexOffset = (binding.getDivisor() == 0);
} }
// static // static
...@@ -319,7 +319,7 @@ gl::Error VertexDataManager::StoreStaticAttrib(TranslatedAttribute *translated) ...@@ -319,7 +319,7 @@ gl::Error VertexDataManager::StoreStaticAttrib(TranslatedAttribute *translated)
const auto &attrib = *translated->attribute; const auto &attrib = *translated->attribute;
const auto &binding = *translated->binding; const auto &binding = *translated->binding;
gl::Buffer *buffer = binding.buffer.get(); gl::Buffer *buffer = binding.getBuffer().get();
ASSERT(buffer && attrib.enabled && !DirectStoragePossible(attrib, binding)); ASSERT(buffer && attrib.enabled && !DirectStoragePossible(attrib, binding));
BufferD3D *bufferD3D = GetImplAs<BufferD3D>(buffer); BufferD3D *bufferD3D = GetImplAs<BufferD3D>(buffer);
...@@ -370,7 +370,7 @@ gl::Error VertexDataManager::StoreStaticAttrib(TranslatedAttribute *translated) ...@@ -370,7 +370,7 @@ gl::Error VertexDataManager::StoreStaticAttrib(TranslatedAttribute *translated)
translated->baseOffset = streamOffset + firstElementOffset; translated->baseOffset = streamOffset + firstElementOffset;
// Instanced vertices do not apply the 'start' offset // Instanced vertices do not apply the 'start' offset
translated->usesFirstVertexOffset = (binding.divisor == 0); translated->usesFirstVertexOffset = (binding.getDivisor() == 0);
return gl::NoError(); return gl::NoError();
} }
...@@ -428,7 +428,7 @@ void VertexDataManager::PromoteDynamicAttribs( ...@@ -428,7 +428,7 @@ void VertexDataManager::PromoteDynamicAttribs(
ASSERT(dynamicAttrib.attribute && dynamicAttrib.binding); ASSERT(dynamicAttrib.attribute && dynamicAttrib.binding);
const auto &binding = *dynamicAttrib.binding; const auto &binding = *dynamicAttrib.binding;
gl::Buffer *buffer = binding.buffer.get(); gl::Buffer *buffer = binding.getBuffer().get();
if (buffer) if (buffer)
{ {
BufferD3D *bufferD3D = GetImplAs<BufferD3D>(buffer); BufferD3D *bufferD3D = GetImplAs<BufferD3D>(buffer);
...@@ -448,7 +448,7 @@ gl::Error VertexDataManager::reserveSpaceForAttrib(const TranslatedAttribute &tr ...@@ -448,7 +448,7 @@ gl::Error VertexDataManager::reserveSpaceForAttrib(const TranslatedAttribute &tr
ASSERT(!DirectStoragePossible(attrib, binding)); ASSERT(!DirectStoragePossible(attrib, binding));
gl::Buffer *buffer = binding.buffer.get(); gl::Buffer *buffer = binding.getBuffer().get();
BufferD3D *bufferD3D = buffer ? GetImplAs<BufferD3D>(buffer) : nullptr; BufferD3D *bufferD3D = buffer ? GetImplAs<BufferD3D>(buffer) : nullptr;
ASSERT(!bufferD3D || bufferD3D->getStaticVertexBuffer(attrib, binding) == nullptr); ASSERT(!bufferD3D || bufferD3D->getStaticVertexBuffer(attrib, binding) == nullptr);
...@@ -470,14 +470,14 @@ gl::Error VertexDataManager::storeDynamicAttrib(TranslatedAttribute *translated, ...@@ -470,14 +470,14 @@ gl::Error VertexDataManager::storeDynamicAttrib(TranslatedAttribute *translated,
const auto &attrib = *translated->attribute; const auto &attrib = *translated->attribute;
const auto &binding = *translated->binding; const auto &binding = *translated->binding;
gl::Buffer *buffer = binding.buffer.get(); gl::Buffer *buffer = binding.getBuffer().get();
ASSERT(buffer || attrib.pointer); ASSERT(buffer || attrib.pointer);
ASSERT(attrib.enabled); ASSERT(attrib.enabled);
BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : nullptr; BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : nullptr;
// Instanced vertices do not apply the 'start' offset // Instanced vertices do not apply the 'start' offset
GLint firstVertexIndex = (binding.divisor > 0 ? 0 : start); GLint firstVertexIndex = (binding.getDivisor() > 0 ? 0 : start);
// Compute source data pointer // Compute source data pointer
const uint8_t *sourceData = nullptr; const uint8_t *sourceData = nullptr;
......
...@@ -19,7 +19,7 @@ namespace gl ...@@ -19,7 +19,7 @@ namespace gl
{ {
class State; class State;
struct VertexAttribute; struct VertexAttribute;
struct VertexBinding; class VertexBinding;
struct VertexAttribCurrentValueData; struct VertexAttribCurrentValueData;
} }
......
...@@ -438,7 +438,8 @@ gl::Error InputLayoutCache::updateInputLayout(Renderer11 *renderer, ...@@ -438,7 +438,8 @@ gl::Error InputLayoutCache::updateInputLayout(Renderer11 *renderer,
state.getVertexAttribCurrentValue(static_cast<unsigned int>(attribIndex)); state.getVertexAttribCurrentValue(static_cast<unsigned int>(attribIndex));
gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib, currentValue.Type); gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib, currentValue.Type);
layout.addAttributeData(glslElementType, d3dSemantic, vertexFormatType, binding.divisor); layout.addAttributeData(glslElementType, d3dSemantic, vertexFormatType,
binding.getDivisor());
} }
const d3d11::InputLayout *inputLayout = nullptr; const d3d11::InputLayout *inputLayout = nullptr;
......
...@@ -4527,15 +4527,16 @@ gl::ErrorOrResult<unsigned int> Renderer11::getVertexSpaceRequired( ...@@ -4527,15 +4527,16 @@ gl::ErrorOrResult<unsigned int> Renderer11::getVertexSpaceRequired(
return 16u; return 16u;
} }
unsigned int elementCount = 0; unsigned int elementCount = 0;
if (instances == 0 || binding.divisor == 0) const unsigned int divisor = binding.getDivisor();
if (instances == 0 || divisor == 0)
{ {
elementCount = count; elementCount = count;
} }
else else
{ {
// Round up to divisor, if possible // Round up to divisor, if possible
elementCount = UnsignedCeilDivide(static_cast<unsigned int>(instances), binding.divisor); elementCount = UnsignedCeilDivide(static_cast<unsigned int>(instances), divisor);
} }
gl::VertexFormatType formatType = gl::GetVertexFormatType(attrib); gl::VertexFormatType formatType = gl::GetVertexFormatType(attrib);
......
...@@ -105,7 +105,7 @@ void VertexArray11::updateVertexAttribStorage(size_t attribIndex) ...@@ -105,7 +105,7 @@ void VertexArray11::updateVertexAttribStorage(size_t attribIndex)
} }
gl::Buffer *oldBufferGL = mCurrentBuffers[attribIndex].get(); gl::Buffer *oldBufferGL = mCurrentBuffers[attribIndex].get();
gl::Buffer *newBufferGL = binding.buffer.get(); gl::Buffer *newBufferGL = binding.getBuffer().get();
Buffer11 *oldBuffer11 = oldBufferGL ? GetImplAs<Buffer11>(oldBufferGL) : nullptr; Buffer11 *oldBuffer11 = oldBufferGL ? GetImplAs<Buffer11>(oldBufferGL) : nullptr;
Buffer11 *newBuffer11 = newBufferGL ? GetImplAs<Buffer11>(newBufferGL) : nullptr; Buffer11 *newBuffer11 = newBufferGL ? GetImplAs<Buffer11>(newBufferGL) : nullptr;
...@@ -130,7 +130,7 @@ void VertexArray11::updateVertexAttribStorage(size_t attribIndex) ...@@ -130,7 +130,7 @@ void VertexArray11::updateVertexAttribStorage(size_t attribIndex)
} }
} }
mOnBufferDataDirty[attribIndex].bind(newChannel); mOnBufferDataDirty[attribIndex].bind(newChannel);
mCurrentBuffers[attribIndex] = binding.buffer; mCurrentBuffers[attribIndex] = binding.getBuffer();
} }
} }
...@@ -169,7 +169,7 @@ gl::Error VertexArray11::updateDirtyAndDynamicAttribs(VertexDataManager *vertexD ...@@ -169,7 +169,7 @@ gl::Error VertexArray11::updateDirtyAndDynamicAttribs(VertexDataManager *vertexD
translatedAttrib->attribute = &attribs[dirtyAttribIndex]; translatedAttrib->attribute = &attribs[dirtyAttribIndex];
translatedAttrib->binding = &bindings[translatedAttrib->attribute->bindingIndex]; translatedAttrib->binding = &bindings[translatedAttrib->attribute->bindingIndex];
translatedAttrib->currentValueType = currentValue.Type; translatedAttrib->currentValueType = currentValue.Type;
translatedAttrib->divisor = translatedAttrib->binding->divisor; translatedAttrib->divisor = translatedAttrib->binding->getDivisor();
switch (mAttributeStorageTypes[dirtyAttribIndex]) switch (mAttributeStorageTypes[dirtyAttribIndex])
{ {
...@@ -204,7 +204,7 @@ gl::Error VertexArray11::updateDirtyAndDynamicAttribs(VertexDataManager *vertexD ...@@ -204,7 +204,7 @@ gl::Error VertexArray11::updateDirtyAndDynamicAttribs(VertexDataManager *vertexD
dynamicAttrib->attribute = &attribs[dynamicAttribIndex]; dynamicAttrib->attribute = &attribs[dynamicAttribIndex];
dynamicAttrib->binding = &bindings[dynamicAttrib->attribute->bindingIndex]; dynamicAttrib->binding = &bindings[dynamicAttrib->attribute->bindingIndex];
dynamicAttrib->currentValueType = currentValue.Type; dynamicAttrib->currentValueType = currentValue.Type;
dynamicAttrib->divisor = dynamicAttrib->binding->divisor; dynamicAttrib->divisor = dynamicAttrib->binding->getDivisor();
} }
return vertexDataManager->storeDynamicAttribs(&mTranslatedAttribs, activeDynamicAttribs, return vertexDataManager->storeDynamicAttribs(&mTranslatedAttribs, activeDynamicAttribs,
......
...@@ -122,7 +122,7 @@ gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attri ...@@ -122,7 +122,7 @@ gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attri
const uint8_t *input = sourceData; const uint8_t *input = sourceData;
if (instances == 0 || binding.divisor == 0) if (instances == 0 || binding.getDivisor() == 0)
{ {
input += inputStride * start; input += inputStride * start;
} }
......
...@@ -3034,15 +3034,16 @@ gl::ErrorOrResult<unsigned int> Renderer9::getVertexSpaceRequired(const gl::Vert ...@@ -3034,15 +3034,16 @@ gl::ErrorOrResult<unsigned int> Renderer9::getVertexSpaceRequired(const gl::Vert
const d3d9::VertexFormat &d3d9VertexInfo = const d3d9::VertexFormat &d3d9VertexInfo =
d3d9::GetVertexFormatInfo(getCapsDeclTypes(), vertexFormatType); d3d9::GetVertexFormatInfo(getCapsDeclTypes(), vertexFormatType);
unsigned int elementCount = 0; unsigned int elementCount = 0;
if (instances == 0 || binding.divisor == 0) const unsigned int divisor = binding.getDivisor();
if (instances == 0 || divisor == 0)
{ {
elementCount = static_cast<unsigned int>(count); elementCount = static_cast<unsigned int>(count);
} }
else else
{ {
// Round up to divisor, if possible // Round up to divisor, if possible
elementCount = UnsignedCeilDivide(static_cast<unsigned int>(instances), binding.divisor); elementCount = UnsignedCeilDivide(static_cast<unsigned int>(instances), divisor);
} }
if (d3d9VertexInfo.outputElementSize > std::numeric_limits<unsigned int>::max() / elementCount) if (d3d9VertexInfo.outputElementSize > std::numeric_limits<unsigned int>::max() / elementCount)
......
...@@ -94,7 +94,7 @@ gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib ...@@ -94,7 +94,7 @@ gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib
const uint8_t *input = sourceData; const uint8_t *input = sourceData;
if (instances == 0 || binding.divisor == 0) if (instances == 0 || binding.getDivisor() == 0)
{ {
input += inputStride * start; input += inputStride * start;
} }
......
...@@ -29,7 +29,7 @@ namespace ...@@ -29,7 +29,7 @@ namespace
// Warning: you should ensure binding really matches attrib.bindingIndex before using this function. // Warning: you should ensure binding really matches attrib.bindingIndex before using this function.
bool AttributeNeedsStreaming(const VertexAttribute &attrib, const VertexBinding &binding) bool AttributeNeedsStreaming(const VertexAttribute &attrib, const VertexBinding &binding)
{ {
return (attrib.enabled && binding.buffer.get() == nullptr); return (attrib.enabled && binding.getBuffer().get() == nullptr);
} }
bool SameVertexAttribFormat(const VertexAttribute &a, const VertexAttribute &b) bool SameVertexAttribFormat(const VertexAttribute &a, const VertexAttribute &b)
...@@ -40,7 +40,8 @@ bool SameVertexAttribFormat(const VertexAttribute &a, const VertexAttribute &b) ...@@ -40,7 +40,8 @@ bool SameVertexAttribFormat(const VertexAttribute &a, const VertexAttribute &b)
bool SameVertexBuffer(const VertexBinding &a, const VertexBinding &b) bool SameVertexBuffer(const VertexBinding &a, const VertexBinding &b)
{ {
return a.stride == b.stride && a.offset == b.offset && a.buffer.get() == b.buffer.get(); return a.getStride() == b.getStride() && a.getOffset() == b.getOffset() &&
a.getBuffer().get() == b.getBuffer().get();
} }
bool IsVertexAttribPointerSupported(size_t attribIndex, const VertexAttribute &attrib) bool IsVertexAttribPointerSupported(size_t attribIndex, const VertexAttribute &attrib)
...@@ -91,7 +92,7 @@ VertexArrayGL::~VertexArrayGL() ...@@ -91,7 +92,7 @@ VertexArrayGL::~VertexArrayGL()
mAppliedElementArrayBuffer.set(nullptr); mAppliedElementArrayBuffer.set(nullptr);
for (auto &binding : mAppliedBindings) for (auto &binding : mAppliedBindings)
{ {
binding.buffer.set(nullptr); binding.setBuffer(nullptr);
} }
} }
...@@ -356,7 +357,7 @@ gl::Error VertexArrayGL::streamAttributes(const gl::AttributesMask &activeAttrib ...@@ -356,7 +357,7 @@ gl::Error VertexArrayGL::streamAttributes(const gl::AttributesMask &activeAttrib
// Vertices do not apply the 'start' offset when the divisor is non-zero even when doing // Vertices do not apply the 'start' offset when the divisor is non-zero even when doing
// a non-instanced draw call // a non-instanced draw call
const size_t firstIndex = binding.divisor == 0 ? indexRange.start : 0; const size_t firstIndex = binding.getDivisor() == 0 ? indexRange.start : 0;
// Attributes using client memory ignore the VERTEX_ATTRIB_BINDING state. // Attributes using client memory ignore the VERTEX_ATTRIB_BINDING state.
// https://www.opengl.org/registry/specs/ARB/vertex_attrib_binding.txt // https://www.opengl.org/registry/specs/ARB/vertex_attrib_binding.txt
...@@ -470,13 +471,13 @@ void VertexArrayGL::updateAttribPointer(size_t attribIndex) ...@@ -470,13 +471,13 @@ void VertexArrayGL::updateAttribPointer(size_t attribIndex)
// If we need to stream, defer the attribPointer to the draw call. // If we need to stream, defer the attribPointer to the draw call.
// Skip the attribute that is disabled and uses a client memory pointer. // Skip the attribute that is disabled and uses a client memory pointer.
const Buffer *arrayBuffer = binding.buffer.get(); const Buffer *arrayBuffer = binding.getBuffer().get();
if (arrayBuffer == nullptr) if (arrayBuffer == nullptr)
{ {
// Mark the applied binding is using a client memory pointer by setting its buffer to // Mark the applied binding is using a client memory pointer by setting its buffer to
// nullptr so that if it doesn't use a client memory pointer later, there is no chance that // nullptr so that if it doesn't use a client memory pointer later, there is no chance that
// the caching will skip it. // the caching will skip it.
mAppliedBindings[bindingIndex].buffer.set(nullptr); mAppliedBindings[bindingIndex].setBuffer(nullptr);
return; return;
} }
...@@ -489,8 +490,8 @@ void VertexArrayGL::updateAttribPointer(size_t attribIndex) ...@@ -489,8 +490,8 @@ void VertexArrayGL::updateAttribPointer(size_t attribIndex)
const BufferGL *arrayBufferGL = GetImplAs<BufferGL>(arrayBuffer); const BufferGL *arrayBufferGL = GetImplAs<BufferGL>(arrayBuffer);
mStateManager->bindBuffer(GL_ARRAY_BUFFER, arrayBufferGL->getBufferID()); mStateManager->bindBuffer(GL_ARRAY_BUFFER, arrayBufferGL->getBufferID());
callVertexAttribPointer(static_cast<GLuint>(attribIndex), attrib, binding.stride, callVertexAttribPointer(static_cast<GLuint>(attribIndex), attrib, binding.getStride(),
binding.offset); binding.getOffset());
mAppliedAttributes[attribIndex].size = attrib.size; mAppliedAttributes[attribIndex].size = attrib.size;
mAppliedAttributes[attribIndex].type = attrib.type; mAppliedAttributes[attribIndex].type = attrib.type;
...@@ -500,9 +501,9 @@ void VertexArrayGL::updateAttribPointer(size_t attribIndex) ...@@ -500,9 +501,9 @@ void VertexArrayGL::updateAttribPointer(size_t attribIndex)
mAppliedAttributes[attribIndex].bindingIndex = bindingIndex; mAppliedAttributes[attribIndex].bindingIndex = bindingIndex;
mAppliedBindings[bindingIndex].stride = binding.stride; mAppliedBindings[bindingIndex].setStride(binding.getStride());
mAppliedBindings[bindingIndex].offset = binding.offset; mAppliedBindings[bindingIndex].setOffset(binding.getOffset());
mAppliedBindings[bindingIndex].buffer = binding.buffer; mAppliedBindings[bindingIndex].setBuffer(binding.getBuffer().get());
} }
void VertexArrayGL::callVertexAttribPointer(GLuint attribIndex, void VertexArrayGL::callVertexAttribPointer(GLuint attribIndex,
...@@ -528,9 +529,9 @@ void VertexArrayGL::updateAttribDivisor(size_t attribIndex) ...@@ -528,9 +529,9 @@ void VertexArrayGL::updateAttribDivisor(size_t attribIndex)
const GLuint bindingIndex = mData.getVertexAttribute(attribIndex).bindingIndex; const GLuint bindingIndex = mData.getVertexAttribute(attribIndex).bindingIndex;
ASSERT(attribIndex == bindingIndex); ASSERT(attribIndex == bindingIndex);
const GLuint divisor = mData.getVertexBinding(bindingIndex).divisor; const GLuint divisor = mData.getVertexBinding(bindingIndex).getDivisor();
if (mAppliedAttributes[attribIndex].bindingIndex == bindingIndex && if (mAppliedAttributes[attribIndex].bindingIndex == bindingIndex &&
mAppliedBindings[bindingIndex].divisor == divisor) mAppliedBindings[bindingIndex].getDivisor() == divisor)
{ {
return; return;
} }
...@@ -538,7 +539,7 @@ void VertexArrayGL::updateAttribDivisor(size_t attribIndex) ...@@ -538,7 +539,7 @@ void VertexArrayGL::updateAttribDivisor(size_t attribIndex)
mFunctions->vertexAttribDivisor(static_cast<GLuint>(attribIndex), divisor); mFunctions->vertexAttribDivisor(static_cast<GLuint>(attribIndex), divisor);
mAppliedAttributes[attribIndex].bindingIndex = bindingIndex; mAppliedAttributes[attribIndex].bindingIndex = bindingIndex;
mAppliedBindings[bindingIndex].divisor = divisor; mAppliedBindings[bindingIndex].setDivisor(divisor);
} }
void VertexArrayGL::syncState(const gl::Context *context, const VertexArray::DirtyBits &dirtyBits) void VertexArrayGL::syncState(const gl::Context *context, const VertexArray::DirtyBits &dirtyBits)
......
...@@ -108,8 +108,8 @@ gl::Error ContextVk::initPipeline() ...@@ -108,8 +108,8 @@ gl::Error ContextVk::initPipeline()
VkVertexInputBindingDescription bindingDesc; VkVertexInputBindingDescription bindingDesc;
bindingDesc.binding = static_cast<uint32_t>(vertexBindings.size()); bindingDesc.binding = static_cast<uint32_t>(vertexBindings.size());
bindingDesc.stride = static_cast<uint32_t>(gl::ComputeVertexAttributeTypeSize(attrib)); bindingDesc.stride = static_cast<uint32_t>(gl::ComputeVertexAttributeTypeSize(attrib));
bindingDesc.inputRate = bindingDesc.inputRate = (binding.getDivisor() > 0 ? VK_VERTEX_INPUT_RATE_INSTANCE
(binding.divisor > 0 ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX); : VK_VERTEX_INPUT_RATE_VERTEX);
gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib); gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib);
...@@ -300,7 +300,7 @@ gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint f ...@@ -300,7 +300,7 @@ gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint f
if (attrib.enabled) if (attrib.enabled)
{ {
// TODO(jmadill): Offset handling. // TODO(jmadill): Offset handling.
gl::Buffer *bufferGL = binding.buffer.get(); gl::Buffer *bufferGL = binding.getBuffer().get();
ASSERT(bufferGL); ASSERT(bufferGL);
BufferVk *bufferVk = GetImplAs<BufferVk>(bufferGL); BufferVk *bufferVk = GetImplAs<BufferVk>(bufferGL);
vertexHandles.push_back(bufferVk->getVkBuffer().getHandle()); vertexHandles.push_back(bufferVk->getVkBuffer().getHandle());
......
...@@ -59,7 +59,7 @@ bool ValidateDrawAttribs(ValidationContext *context, ...@@ -59,7 +59,7 @@ bool ValidateDrawAttribs(ValidationContext *context,
const VertexBinding &binding = vertexBindings[attrib.bindingIndex]; const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
// If we have no buffer, then we either get an error, or there are no more checks to be // If we have no buffer, then we either get an error, or there are no more checks to be
// done. // done.
gl::Buffer *buffer = binding.buffer.get(); gl::Buffer *buffer = binding.getBuffer().get();
if (!buffer) if (!buffer)
{ {
if (webglCompatibility || !state.areClientArraysEnabled()) if (webglCompatibility || !state.areClientArraysEnabled())
...@@ -91,13 +91,14 @@ bool ValidateDrawAttribs(ValidationContext *context, ...@@ -91,13 +91,14 @@ bool ValidateDrawAttribs(ValidationContext *context,
} }
GLint maxVertexElement = 0; GLint maxVertexElement = 0;
if (binding.divisor == 0) GLuint divisor = binding.getDivisor();
if (divisor == 0)
{ {
maxVertexElement = maxVertex; maxVertexElement = maxVertex;
} }
else else
{ {
maxVertexElement = (primcount - 1) / binding.divisor; maxVertexElement = (primcount - 1) / divisor;
} }
// We do manual overflow checks here instead of using safe_math.h because it was // We do manual overflow checks here instead of using safe_math.h because it was
...@@ -893,7 +894,7 @@ bool ValidateDrawInstancedANGLEAndWebGL(ValidationContext *context) ...@@ -893,7 +894,7 @@ bool ValidateDrawInstancedANGLEAndWebGL(ValidationContext *context)
{ {
const VertexAttribute &attrib = attribs[attributeIndex]; const VertexAttribute &attrib = attribs[attributeIndex];
const VertexBinding &binding = bindings[attrib.bindingIndex]; const VertexBinding &binding = bindings[attrib.bindingIndex];
if (program->isAttribLocationActive(attributeIndex) && binding.divisor == 0) if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0)
{ {
return true; return true;
} }
......
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