Commit 1f750d1e by Jamie Madill Committed by Commit Bot

Even more inlining and micro-optimization.

Improves perf by about 3-4% on the Vulkan VBO state change test. Bug: angleproject:3014 Change-Id: If4415e503cd883cf7de6387bf1ebbca0e5fc994e Reviewed-on: https://chromium-review.googlesource.com/c/1393907 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent c8c7d400
......@@ -1362,12 +1362,6 @@ void State::bindVertexBuffer(const Context *context,
mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
}
void State::setVertexAttribBinding(const Context *context, GLuint attribIndex, GLuint bindingIndex)
{
getVertexArray()->setVertexAttribBinding(context, attribIndex, bindingIndex);
mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
}
void State::setVertexAttribFormat(GLuint attribIndex,
GLint size,
VertexAttribType type,
......@@ -1549,17 +1543,6 @@ const OffsetBindingPointer<Buffer> &State::getIndexedShaderStorageBuffer(size_t
return mShaderStorageBuffers[index];
}
Buffer *State::getTargetBuffer(BufferBinding target) const
{
switch (target)
{
case BufferBinding::ElementArray:
return getVertexArray()->getElementArrayBuffer();
default:
return mBoundBuffers[target].get();
}
}
angle::Result State::detachBuffer(const Context *context, const Buffer *buffer)
{
if (!buffer->isBound())
......
......@@ -320,7 +320,17 @@ class State : angle::NonCopyable
(this->*(kBufferSetters[target]))(context, buffer);
}
Buffer *getTargetBuffer(BufferBinding target) const;
ANGLE_INLINE Buffer *getTargetBuffer(BufferBinding target) const
{
switch (target)
{
case BufferBinding::ElementArray:
return getVertexArray()->getElementArrayBuffer();
default:
return mBoundBuffers[target].get();
}
}
angle::Result setIndexedBufferBinding(const Context *context,
BufferBinding target,
GLuint index,
......@@ -393,7 +403,13 @@ class State : angle::NonCopyable
bool normalized,
bool pureInteger,
GLuint relativeOffset);
void setVertexAttribBinding(const Context *context, GLuint attribIndex, GLuint bindingIndex);
void setVertexAttribBinding(const Context *context, GLuint attribIndex, GLuint bindingIndex)
{
mVertexArray->setVertexAttribBinding(context, attribIndex, bindingIndex);
mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
}
void setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor);
// Pixel pack state manipulation
......
......@@ -128,11 +128,6 @@ angle::Result BufferVk::mapImpl(ContextVk *contextVk, void **mapPtr)
return angle::Result::Continue;
}
GLint64 BufferVk::getSize()
{
return mState.getSize();
}
angle::Result BufferVk::mapRange(const gl::Context *context,
size_t offset,
size_t length,
......
......@@ -10,6 +10,7 @@
#ifndef LIBANGLE_RENDERER_VULKAN_BUFFERVK_H_
#define LIBANGLE_RENDERER_VULKAN_BUFFERVK_H_
#include "libANGLE/Buffer.h"
#include "libANGLE/Observer.h"
#include "libANGLE/renderer/BufferImpl.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
......@@ -54,7 +55,8 @@ class BufferVk : public BufferImpl
size_t count,
bool primitiveRestartEnabled,
gl::IndexRange *outRange) override;
GLint64 getSize();
GLint64 getSize() const { return mState.getSize(); }
const vk::BufferHelper &getBuffer() const
{
......
......@@ -464,22 +464,6 @@ void CommandBuffer::endRenderPass()
vkCmdEndRenderPass(mHandle);
}
void CommandBuffer::bindPipeline(VkPipelineBindPoint pipelineBindPoint,
const vk::Pipeline &pipeline)
{
ASSERT(valid() && pipeline.valid());
vkCmdBindPipeline(mHandle, pipelineBindPoint, pipeline.getHandle());
}
void CommandBuffer::bindVertexBuffers(uint32_t firstBinding,
uint32_t bindingCount,
const VkBuffer *buffers,
const VkDeviceSize *offsets)
{
ASSERT(valid());
vkCmdBindVertexBuffers(mHandle, firstBinding, bindingCount, buffers, offsets);
}
void CommandBuffer::bindIndexBuffer(const VkBuffer &buffer,
VkDeviceSize offset,
VkIndexType indexType)
......
......@@ -266,6 +266,8 @@ class WrappedObject : angle::NonCopyable
HandleT mHandle;
};
// TODO(jmadill): Inline all the methods in the wrapper classes. http://anglebug.com/3014
class MemoryProperties final : angle::NonCopyable
{
public:
......@@ -293,6 +295,20 @@ class CommandPool final : public WrappedObject<CommandPool, VkCommandPool>
VkResult init(VkDevice device, const VkCommandPoolCreateInfo &createInfo);
};
class Pipeline final : public WrappedObject<Pipeline, VkPipeline>
{
public:
Pipeline();
void destroy(VkDevice device);
VkResult initGraphics(VkDevice device,
const VkGraphicsPipelineCreateInfo &createInfo,
const PipelineCache &pipelineCacheVk);
VkResult initCompute(VkDevice device,
const VkComputePipelineCreateInfo &createInfo,
const PipelineCache &pipelineCacheVk);
};
// Helper class that wraps a Vulkan command buffer.
class CommandBuffer : public WrappedObject<CommandBuffer, VkCommandBuffer>
{
......@@ -404,11 +420,21 @@ class CommandBuffer : public WrappedObject<CommandBuffer, VkCommandBuffer>
vkCmdDispatch(mHandle, groupCountX, groupCountY, groupCountZ);
}
void bindPipeline(VkPipelineBindPoint pipelineBindPoint, const Pipeline &pipeline);
void bindPipeline(VkPipelineBindPoint pipelineBindPoint, const Pipeline &pipeline)
{
ASSERT(valid() && pipeline.valid());
vkCmdBindPipeline(mHandle, pipelineBindPoint, pipeline.getHandle());
}
void bindVertexBuffers(uint32_t firstBinding,
uint32_t bindingCount,
const VkBuffer *buffers,
const VkDeviceSize *offsets);
const VkDeviceSize *offsets)
{
ASSERT(valid());
vkCmdBindVertexBuffers(mHandle, firstBinding, bindingCount, buffers, offsets);
}
void bindIndexBuffer(const VkBuffer &buffer, VkDeviceSize offset, VkIndexType indexType);
void bindDescriptorSets(VkPipelineBindPoint bindPoint,
const PipelineLayout &layout,
......@@ -588,20 +614,6 @@ class PipelineCache final : public WrappedObject<PipelineCache, VkPipelineCache>
VkResult getCacheData(VkDevice device, size_t *cacheSize, void *cacheData);
};
class Pipeline final : public WrappedObject<Pipeline, VkPipeline>
{
public:
Pipeline();
void destroy(VkDevice device);
VkResult initGraphics(VkDevice device,
const VkGraphicsPipelineCreateInfo &createInfo,
const PipelineCache &pipelineCacheVk);
VkResult initCompute(VkDevice device,
const VkComputePipelineCreateInfo &createInfo,
const PipelineCache &pipelineCacheVk);
};
class DescriptorSetLayout final : public WrappedObject<DescriptorSetLayout, VkDescriptorSetLayout>
{
public:
......
......@@ -4675,73 +4675,6 @@ bool ValidateLineWidth(Context *context, GLfloat width)
return true;
}
bool ValidateVertexAttribPointer(Context *context,
GLuint index,
GLint size,
VertexAttribType type,
GLboolean normalized,
GLsizei stride,
const void *ptr)
{
if (!ValidateFloatVertexFormat(context, index, size, type))
{
return false;
}
if (stride < 0)
{
context->validationError(GL_INVALID_VALUE, kNegativeStride);
return false;
}
const Caps &caps = context->getCaps();
if (context->getClientVersion() >= ES_3_1)
{
if (stride > caps.maxVertexAttribStride)
{
context->validationError(GL_INVALID_VALUE, kExceedsMaxVertexAttribStride);
return false;
}
if (index >= caps.maxVertexAttribBindings)
{
context->validationError(GL_INVALID_VALUE, kExceedsMaxVertexAttribBindings);
return false;
}
}
// [OpenGL ES 3.0.2] Section 2.8 page 24:
// An INVALID_OPERATION error is generated when a non-zero vertex array object
// is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
// and the pointer argument is not NULL.
bool nullBufferAllowed = context->getState().areClientArraysEnabled() &&
context->getState().getVertexArray()->id() == 0;
if (!nullBufferAllowed && context->getState().getTargetBuffer(BufferBinding::Array) == 0 &&
ptr != nullptr)
{
context->validationError(GL_INVALID_OPERATION, kClientDataInVertexArray);
return false;
}
if (context->getExtensions().webglCompatibility)
{
// WebGL 1.0 [Section 6.14] Fixed point support
// The WebGL API does not support the GL_FIXED data type.
if (type == VertexAttribType::Fixed)
{
context->validationError(GL_INVALID_ENUM, kFixedNotInWebGL);
return false;
}
if (!ValidateWebGLVertexAttribPointer(context, type, normalized, stride, ptr, false))
{
return false;
}
}
return true;
}
bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar)
{
if (context->getExtensions().webglCompatibility && zNear > zFar)
......
......@@ -54,6 +54,73 @@ ANGLE_INLINE bool ValidateDrawElements(Context *context,
{
return ValidateDrawElementsCommon(context, mode, count, type, indices, 1);
}
ANGLE_INLINE bool ValidateVertexAttribPointer(Context *context,
GLuint index,
GLint size,
VertexAttribType type,
GLboolean normalized,
GLsizei stride,
const void *ptr)
{
if (!ValidateFloatVertexFormat(context, index, size, type))
{
return false;
}
if (stride < 0)
{
context->validationError(GL_INVALID_VALUE, err::kNegativeStride);
return false;
}
if (context->getClientVersion() >= ES_3_1)
{
const Caps &caps = context->getCaps();
if (stride > caps.maxVertexAttribStride)
{
context->validationError(GL_INVALID_VALUE, err::kExceedsMaxVertexAttribStride);
return false;
}
if (index >= caps.maxVertexAttribBindings)
{
context->validationError(GL_INVALID_VALUE, err::kExceedsMaxVertexAttribBindings);
return false;
}
}
// [OpenGL ES 3.0.2] Section 2.8 page 24:
// An INVALID_OPERATION error is generated when a non-zero vertex array object
// is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
// and the pointer argument is not NULL.
bool nullBufferAllowed = context->getState().areClientArraysEnabled() &&
context->getState().getVertexArray()->id() == 0;
if (!nullBufferAllowed && context->getState().getTargetBuffer(BufferBinding::Array) == 0 &&
ptr != nullptr)
{
context->validationError(GL_INVALID_OPERATION, err::kClientDataInVertexArray);
return false;
}
if (context->getExtensions().webglCompatibility)
{
// WebGL 1.0 [Section 6.14] Fixed point support
// The WebGL API does not support the GL_FIXED data type.
if (type == VertexAttribType::Fixed)
{
context->validationError(GL_INVALID_ENUM, err::kFixedNotInWebGL);
return false;
}
if (!ValidateWebGLVertexAttribPointer(context, type, normalized, stride, ptr, false))
{
return false;
}
}
return true;
}
} // namespace gl
#endif // LIBANGLE_VALIDATION_ES2_H_
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