Commit 97ab26fc by Jamie Madill Committed by Commit Bot

Move DrawCallParams to the gl front-end.

Previously called DrawCallVertexParams. This params helper will be passed into the VertexArray state sync method so we can handle vertex attribute updates directly in the VertexArray implementation instead of deferring the updates to the draw call, where the draw call implementation method would have access to the draw call params. Also includes the full range of draw parameters to DrawCallParams so we can use it in more places. Refactoring change only, subsequent work will contain more refactoring and lead to code cleanups and easier dependent state updates for the VertexArray implementation classes. Bug: angleproject:2389 Change-Id: Ia84f8af54ae51eca94d8fb6f5b8adc88b8d981a7 Reviewed-on: https://chromium-review.googlesource.com/948787 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 87db7c52
...@@ -20,6 +20,7 @@ namespace gl ...@@ -20,6 +20,7 @@ namespace gl
constexpr ParamTypeInfo ParamsBase::TypeInfo; constexpr ParamTypeInfo ParamsBase::TypeInfo;
constexpr ParamTypeInfo HasIndexRange::TypeInfo; constexpr ParamTypeInfo HasIndexRange::TypeInfo;
// HasIndexRange implementation.
HasIndexRange::HasIndexRange() HasIndexRange::HasIndexRange()
: ParamsBase(nullptr), mContext(nullptr), mCount(0), mType(GL_NONE), mIndices(nullptr) : ParamsBase(nullptr), mContext(nullptr), mCount(0), mType(GL_NONE), mIndices(nullptr)
{ {
...@@ -65,4 +66,147 @@ const Optional<IndexRange> &HasIndexRange::getIndexRange() const ...@@ -65,4 +66,147 @@ const Optional<IndexRange> &HasIndexRange::getIndexRange() const
return mIndexRange; return mIndexRange;
} }
// DrawCallParams implementation.
// Called by DrawArrays.
DrawCallParams::DrawCallParams(GLenum mode,
GLint firstVertex,
GLsizei vertexCount,
GLsizei instances)
: mMode(mode),
mHasIndexRange(nullptr),
mFirstVertex(firstVertex),
mVertexCount(vertexCount),
mIndexCount(0),
mBaseVertex(0),
mType(GL_NONE),
mIndices(nullptr),
mInstances(instances),
mIndirect(nullptr)
{
}
// Called by DrawElements.
DrawCallParams::DrawCallParams(GLenum mode,
const HasIndexRange &hasIndexRange,
GLint indexCount,
GLenum type,
const void *indices,
GLint baseVertex,
GLsizei instances)
: mMode(mode),
mHasIndexRange(&hasIndexRange),
mFirstVertex(0),
mVertexCount(0),
mIndexCount(indexCount),
mBaseVertex(baseVertex),
mType(type),
mIndices(indices),
mInstances(instances),
mIndirect(nullptr)
{
}
// Called by DrawArraysIndirect.
DrawCallParams::DrawCallParams(GLenum mode, const void *indirect)
: mMode(mode),
mHasIndexRange(nullptr),
mFirstVertex(0),
mVertexCount(0),
mIndexCount(0),
mBaseVertex(0),
mType(GL_NONE),
mIndices(nullptr),
mInstances(0),
mIndirect(indirect)
{
}
// Called by DrawElementsIndirect.
DrawCallParams::DrawCallParams(GLenum mode, GLenum type, const void *indirect)
: mMode(mode),
mHasIndexRange(nullptr),
mFirstVertex(0),
mVertexCount(0),
mIndexCount(0),
mBaseVertex(0),
mType(type),
mIndices(nullptr),
mInstances(0),
mIndirect(indirect)
{
}
GLenum DrawCallParams::mode() const
{
return mMode;
}
GLint DrawCallParams::firstVertex() const
{
// In some cases we can know the first vertex will be fixed at zero, if we're on the "fast
// path". In these cases the index range is not resolved. If the first vertex is not zero,
// however, then it must be because the index range is resolved. This only applies to the
// D3D11 back-end currently.
ASSERT(mFirstVertex == 0 || mHasIndexRange == nullptr);
return mFirstVertex;
}
GLsizei DrawCallParams::vertexCount() const
{
ASSERT(!mHasIndexRange);
return mVertexCount;
}
GLsizei DrawCallParams::indexCount() const
{
ASSERT(isDrawElements());
return mIndexCount;
}
GLint DrawCallParams::baseVertex() const
{
return mBaseVertex;
}
GLenum DrawCallParams::type() const
{
ASSERT(isDrawElements());
return mType;
}
const void *DrawCallParams::indices() const
{
return mIndices;
}
GLsizei DrawCallParams::instances() const
{
return mInstances;
}
const void *DrawCallParams::indirect() const
{
return mIndirect;
}
bool DrawCallParams::isDrawElements() const
{
return (mType != GL_NONE);
}
void DrawCallParams::ensureIndexRangeResolved() const
{
if (mHasIndexRange == nullptr)
{
return;
}
// This call will resolve the index range.
const gl::IndexRange &indexRange = mHasIndexRange->getIndexRange().value();
mFirstVertex = mBaseVertex + static_cast<GLint>(indexRange.start);
mVertexCount = static_cast<GLsizei>(indexRange.vertexCount());
mHasIndexRange = nullptr;
}
} // namespace gl } // namespace gl
...@@ -90,6 +90,60 @@ class HasIndexRange : public ParamsBase ...@@ -90,6 +90,60 @@ class HasIndexRange : public ParamsBase
mutable Optional<IndexRange> mIndexRange; mutable Optional<IndexRange> mIndexRange;
}; };
// Helper class that encompasses draw call parameters. It uses the HasIndexRange
// helper class to only pull index range info lazily to prevent unnecessary readback.
// It is also used when syncing state for the VertexArray implementation, since the
// vertex and index buffer updates depend on draw call parameters.
class DrawCallParams final : angle::NonCopyable
{
public:
// Called by DrawArrays.
DrawCallParams(GLenum mode, GLint firstVertex, GLsizei vertexCount, GLsizei instances);
// Called by DrawElements.
DrawCallParams(GLenum mode,
const HasIndexRange &hasIndexRange,
GLint indexCount,
GLenum type,
const void *indices,
GLint baseVertex,
GLsizei instances);
// Called by DrawArraysIndirect.
DrawCallParams(GLenum mode, const void *indirect);
// Called by DrawElementsIndirect.
DrawCallParams(GLenum mode, GLenum type, const void *indirect);
// It should be possible to also use an overload to handle the 'slow' indirect draw path.
// TODO(jmadill): Indirect draw slow path overload.
GLenum mode() const;
GLint firstVertex() const;
GLsizei vertexCount() const;
GLsizei indexCount() const;
GLint baseVertex() const;
GLenum type() const;
const void *indices() const;
GLsizei instances() const;
const void *indirect() const;
void ensureIndexRangeResolved() const;
bool isDrawElements() const;
private:
GLenum mMode;
mutable const HasIndexRange *mHasIndexRange;
mutable GLint mFirstVertex;
mutable GLsizei mVertexCount;
GLint mIndexCount;
GLint mBaseVertex;
GLenum mType;
const void *mIndices;
GLsizei mInstances;
const void *mIndirect;
};
// Entry point funcs essentially re-map different entry point parameter arrays into // Entry point funcs essentially re-map different entry point parameter arrays into
// the format the parameter type class expects. For example, for HasIndexRange, for the // the format the parameter type class expects. For example, for HasIndexRange, for the
// various indexed draw calls, they drop parameters that aren't useful and re-arrange // various indexed draw calls, they drop parameters that aren't useful and re-arrange
......
...@@ -307,9 +307,8 @@ gl::Error InputLayoutCache::updateInputLayout( ...@@ -307,9 +307,8 @@ gl::Error InputLayoutCache::updateInputLayout(
Renderer11 *renderer, Renderer11 *renderer,
const gl::State &state, const gl::State &state,
const std::vector<const TranslatedAttribute *> &currentAttributes, const std::vector<const TranslatedAttribute *> &currentAttributes,
GLenum mode,
const AttribIndexArray &sortedSemanticIndices, const AttribIndexArray &sortedSemanticIndices,
const DrawCallVertexParams &vertexParams) const gl::DrawCallParams &drawCallParams)
{ {
gl::Program *program = state.getProgram(); gl::Program *program = state.getProgram();
const auto &shaderAttributes = program->getAttributes(); const auto &shaderAttributes = program->getAttributes();
...@@ -318,7 +317,8 @@ gl::Error InputLayoutCache::updateInputLayout( ...@@ -318,7 +317,8 @@ gl::Error InputLayoutCache::updateInputLayout(
ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program); ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program);
bool programUsesInstancedPointSprites = bool programUsesInstancedPointSprites =
programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation(); programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation();
bool instancedPointSpritesActive = programUsesInstancedPointSprites && (mode == GL_POINTS); bool instancedPointSpritesActive =
programUsesInstancedPointSprites && (drawCallParams.mode() == GL_POINTS);
if (programUsesInstancedPointSprites) if (programUsesInstancedPointSprites)
{ {
...@@ -330,7 +330,7 @@ gl::Error InputLayoutCache::updateInputLayout( ...@@ -330,7 +330,7 @@ gl::Error InputLayoutCache::updateInputLayout(
layout.flags |= PackedAttributeLayout::FLAG_INSTANCED_SPRITES_ACTIVE; layout.flags |= PackedAttributeLayout::FLAG_INSTANCED_SPRITES_ACTIVE;
} }
if (vertexParams.instances() > 0) if (drawCallParams.instances() > 0)
{ {
layout.flags |= PackedAttributeLayout::FLAG_INSTANCED_RENDERING_ACTIVE; layout.flags |= PackedAttributeLayout::FLAG_INSTANCED_RENDERING_ACTIVE;
} }
...@@ -371,8 +371,8 @@ gl::Error InputLayoutCache::updateInputLayout( ...@@ -371,8 +371,8 @@ gl::Error InputLayoutCache::updateInputLayout(
angle::TrimCache(mLayoutCache.max_size() / 2, kGCLimit, "input layout", &mLayoutCache); angle::TrimCache(mLayoutCache.max_size() / 2, kGCLimit, "input layout", &mLayoutCache);
d3d11::InputLayout newInputLayout; d3d11::InputLayout newInputLayout;
ANGLE_TRY(createInputLayout(renderer, sortedSemanticIndices, currentAttributes, mode, ANGLE_TRY(createInputLayout(renderer, sortedSemanticIndices, currentAttributes, program,
program, vertexParams, &newInputLayout)); drawCallParams, &newInputLayout));
auto insertIt = mLayoutCache.Put(layout, std::move(newInputLayout)); auto insertIt = mLayoutCache.Put(layout, std::move(newInputLayout));
inputLayout = &insertIt->second; inputLayout = &insertIt->second;
...@@ -387,9 +387,8 @@ gl::Error InputLayoutCache::createInputLayout( ...@@ -387,9 +387,8 @@ gl::Error InputLayoutCache::createInputLayout(
Renderer11 *renderer, Renderer11 *renderer,
const AttribIndexArray &sortedSemanticIndices, const AttribIndexArray &sortedSemanticIndices,
const std::vector<const TranslatedAttribute *> &currentAttributes, const std::vector<const TranslatedAttribute *> &currentAttributes,
GLenum mode,
gl::Program *program, gl::Program *program,
const DrawCallVertexParams &vertexParams, const gl::DrawCallParams &drawCallParams,
d3d11::InputLayout *inputLayoutOut) d3d11::InputLayout *inputLayoutOut)
{ {
ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program); ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program);
...@@ -440,17 +439,17 @@ gl::Error InputLayoutCache::createInputLayout( ...@@ -440,17 +439,17 @@ gl::Error InputLayoutCache::createInputLayout(
// simultaneously, so a non-instanced element must exist. // simultaneously, so a non-instanced element must exist.
GLsizei numIndicesPerInstance = 0; GLsizei numIndicesPerInstance = 0;
if (vertexParams.instances() > 0) if (drawCallParams.instances() > 0)
{ {
// This may trigger an evaluation of the index range. // This may trigger an evaluation of the index range.
numIndicesPerInstance = vertexParams.vertexCount(); numIndicesPerInstance = drawCallParams.vertexCount();
} }
for (size_t elementIndex = 0; elementIndex < inputElementCount; ++elementIndex) for (size_t elementIndex = 0; elementIndex < inputElementCount; ++elementIndex)
{ {
// If rendering points and instanced pointsprite emulation is being used, the // If rendering points and instanced pointsprite emulation is being used, the
// inputClass is required to be configured as per instance data // inputClass is required to be configured as per instance data
if (mode == GL_POINTS) if (drawCallParams.mode() == GL_POINTS)
{ {
inputElements[elementIndex].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA; inputElements[elementIndex].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
inputElements[elementIndex].InstanceDataStepRate = 1; inputElements[elementIndex].InstanceDataStepRate = 1;
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
namespace rx namespace rx
{ {
class DrawCallVertexParams;
struct PackedAttributeLayout struct PackedAttributeLayout
{ {
PackedAttributeLayout(); PackedAttributeLayout();
...@@ -104,17 +103,15 @@ class InputLayoutCache : angle::NonCopyable ...@@ -104,17 +103,15 @@ class InputLayoutCache : angle::NonCopyable
gl::Error updateInputLayout(Renderer11 *renderer, gl::Error updateInputLayout(Renderer11 *renderer,
const gl::State &state, const gl::State &state,
const std::vector<const TranslatedAttribute *> &currentAttributes, const std::vector<const TranslatedAttribute *> &currentAttributes,
GLenum mode,
const AttribIndexArray &sortedSemanticIndices, const AttribIndexArray &sortedSemanticIndices,
const DrawCallVertexParams &vertexParams); const gl::DrawCallParams &drawCallParams);
private: private:
gl::Error createInputLayout(Renderer11 *renderer, gl::Error createInputLayout(Renderer11 *renderer,
const AttribIndexArray &sortedSemanticIndices, const AttribIndexArray &sortedSemanticIndices,
const std::vector<const TranslatedAttribute *> &currentAttributes, const std::vector<const TranslatedAttribute *> &currentAttributes,
GLenum mode,
gl::Program *program, gl::Program *program,
const DrawCallVertexParams &vertexParams, const gl::DrawCallParams &drawCallParams,
d3d11::InputLayout *inputLayoutOut); d3d11::InputLayout *inputLayoutOut);
// Starting cache size. // Starting cache size.
......
...@@ -1510,8 +1510,8 @@ gl::Error Renderer11::drawArrays(const gl::Context *context, ...@@ -1510,8 +1510,8 @@ gl::Error Renderer11::drawArrays(const gl::Context *context,
return gl::NoError(); return gl::NoError();
} }
DrawCallVertexParams vertexParams(startVertex, count, instances); gl::DrawCallParams drawCallParams(mode, startVertex, count, instances);
ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, false)); ANGLE_TRY(mStateManager.applyVertexBuffer(context, drawCallParams));
if (glState.isTransformFeedbackActiveUnpaused()) if (glState.isTransformFeedbackActiveUnpaused())
{ {
...@@ -1644,15 +1644,16 @@ gl::Error Renderer11::drawElements(const gl::Context *context, ...@@ -1644,15 +1644,16 @@ gl::Error Renderer11::drawElements(const gl::Context *context,
const auto &lazyIndexRange = context->getParams<gl::HasIndexRange>(); const auto &lazyIndexRange = context->getParams<gl::HasIndexRange>();
DrawCallVertexParams vertexParams(lazyIndexRange, 0, instances); gl::DrawCallParams drawCallParams(mode, lazyIndexRange, count, type, indices, 0, instances);
bool usePrimitiveRestartWorkaround = bool usePrimitiveRestartWorkaround =
UsePrimitiveRestartWorkaround(glState.isPrimitiveRestartEnabled(), type); UsePrimitiveRestartWorkaround(glState.isPrimitiveRestartEnabled(), type);
ANGLE_TRY(mStateManager.applyIndexBuffer(context, indices, count, type, lazyIndexRange, ANGLE_TRY(mStateManager.applyIndexBuffer(context, indices, count, type, lazyIndexRange,
usePrimitiveRestartWorkaround)); usePrimitiveRestartWorkaround));
ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, true)); ANGLE_TRY(mStateManager.applyVertexBuffer(context, drawCallParams));
int startVertex = static_cast<int>(vertexParams.firstVertex()); int startVertex = static_cast<int>(drawCallParams.firstVertex());
int baseVertex = -startVertex; int baseVertex = -startVertex;
const gl::Program *program = glState.getProgram(); const gl::Program *program = glState.getProgram();
...@@ -1706,7 +1707,7 @@ gl::Error Renderer11::drawElements(const gl::Context *context, ...@@ -1706,7 +1707,7 @@ gl::Error Renderer11::drawElements(const gl::Context *context,
// efficent code path. Instanced rendering of emulated pointsprites requires a loop to draw each // efficent code path. Instanced rendering of emulated pointsprites requires a loop to draw each
// batch of points. An offset into the instanced data buffer is calculated and applied on each // batch of points. An offset into the instanced data buffer is calculated and applied on each
// iteration to ensure all instances are rendered correctly. // iteration to ensure all instances are rendered correctly.
GLsizei elementsToRender = vertexParams.vertexCount(); GLsizei elementsToRender = drawCallParams.vertexCount();
// Each instance being rendered requires the inputlayout cache to reapply buffers and offsets. // Each instance being rendered requires the inputlayout cache to reapply buffers and offsets.
for (GLsizei i = 0; i < instances; i++) for (GLsizei i = 0; i < instances; i++)
...@@ -1737,8 +1738,8 @@ gl::Error Renderer11::drawArraysIndirect(const gl::Context *context, ...@@ -1737,8 +1738,8 @@ gl::Error Renderer11::drawArraysIndirect(const gl::Context *context,
if (!DrawCallNeedsTranslation(context, mode)) if (!DrawCallNeedsTranslation(context, mode))
{ {
DrawCallVertexParams vertexParams(0, 0, 0); gl::DrawCallParams drawCallParams(mode, indirect);
ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, false)); ANGLE_TRY(mStateManager.applyVertexBuffer(context, drawCallParams));
ID3D11Buffer *buffer = nullptr; ID3D11Buffer *buffer = nullptr;
ANGLE_TRY_RESULT(storage->getBuffer(context, BUFFER_USAGE_INDIRECT), buffer); ANGLE_TRY_RESULT(storage->getBuffer(context, BUFFER_USAGE_INDIRECT), buffer);
mDeviceContext->DrawInstancedIndirect(buffer, static_cast<unsigned int>(offset)); mDeviceContext->DrawInstancedIndirect(buffer, static_cast<unsigned int>(offset));
...@@ -1754,8 +1755,8 @@ gl::Error Renderer11::drawArraysIndirect(const gl::Context *context, ...@@ -1754,8 +1755,8 @@ gl::Error Renderer11::drawArraysIndirect(const gl::Context *context,
GLuint instances = args->instanceCount; GLuint instances = args->instanceCount;
GLuint first = args->first; GLuint first = args->first;
DrawCallVertexParams vertexParams(first, count, instances); gl::DrawCallParams drawCallParams(mode, first, count, instances);
ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, false)); ANGLE_TRY(mStateManager.applyVertexBuffer(context, drawCallParams));
if (mode == GL_LINE_LOOP) if (mode == GL_LINE_LOOP)
{ {
...@@ -1796,8 +1797,8 @@ gl::Error Renderer11::drawElementsIndirect(const gl::Context *context, ...@@ -1796,8 +1797,8 @@ gl::Error Renderer11::drawElementsIndirect(const gl::Context *context,
{ {
ANGLE_TRY(mStateManager.applyIndexBuffer(context, nullptr, 0, type, gl::HasIndexRange(), ANGLE_TRY(mStateManager.applyIndexBuffer(context, nullptr, 0, type, gl::HasIndexRange(),
usePrimitiveRestartWorkaround)); usePrimitiveRestartWorkaround));
DrawCallVertexParams vertexParams(0, 0, 0); gl::DrawCallParams drawCallParams(mode, type, indirect);
ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, true)); ANGLE_TRY(mStateManager.applyVertexBuffer(context, drawCallParams));
ID3D11Buffer *buffer = nullptr; ID3D11Buffer *buffer = nullptr;
ANGLE_TRY_RESULT(storage->getBuffer(context, BUFFER_USAGE_INDIRECT), buffer); ANGLE_TRY_RESULT(storage->getBuffer(context, BUFFER_USAGE_INDIRECT), buffer);
mDeviceContext->DrawIndexedInstancedIndirect(buffer, static_cast<unsigned int>(offset)); mDeviceContext->DrawIndexedInstancedIndirect(buffer, static_cast<unsigned int>(offset));
...@@ -1821,17 +1822,18 @@ gl::Error Renderer11::drawElementsIndirect(const gl::Context *context, ...@@ -1821,17 +1822,18 @@ gl::Error Renderer11::drawElementsIndirect(const gl::Context *context,
reinterpret_cast<const void *>(static_cast<uintptr_t>(firstIndex * typeInfo.bytes)); reinterpret_cast<const void *>(static_cast<uintptr_t>(firstIndex * typeInfo.bytes));
gl::HasIndexRange lazyIndexRange(const_cast<gl::Context *>(context), count, type, indices); gl::HasIndexRange lazyIndexRange(const_cast<gl::Context *>(context), count, type, indices);
DrawCallVertexParams vertexParams(lazyIndexRange, baseVertex, instances); gl::DrawCallParams drawCallParams(mode, lazyIndexRange, count, type, indices, baseVertex,
instances);
// We must explicitly resolve the index range for the slow-path indirect drawElements to make // We must explicitly resolve the index range for the slow-path indirect drawElements to make
// sure we are using the correct 'baseVertex'. This parameter does not exist for the direct // sure we are using the correct 'baseVertex'. This parameter does not exist for the direct
// drawElements. // drawElements.
vertexParams.ensureIndexRangeResolved(); drawCallParams.ensureIndexRangeResolved();
ANGLE_TRY(mStateManager.applyIndexBuffer(context, indices, count, type, lazyIndexRange, ANGLE_TRY(mStateManager.applyIndexBuffer(context, indices, count, type, lazyIndexRange,
usePrimitiveRestartWorkaround)); usePrimitiveRestartWorkaround));
ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, vertexParams, true)); ANGLE_TRY(mStateManager.applyVertexBuffer(context, drawCallParams));
int baseVertexLocation = -static_cast<int>(lazyIndexRange.getIndexRange().value().start); int baseVertexLocation = -static_cast<int>(lazyIndexRange.getIndexRange().value().start);
......
...@@ -2655,9 +2655,7 @@ gl::Error StateManager11::syncProgram(const gl::Context *context, GLenum drawMod ...@@ -2655,9 +2655,7 @@ gl::Error StateManager11::syncProgram(const gl::Context *context, GLenum drawMod
} }
gl::Error StateManager11::applyVertexBuffer(const gl::Context *context, gl::Error StateManager11::applyVertexBuffer(const gl::Context *context,
GLenum mode, const gl::DrawCallParams &drawCallParams)
const DrawCallVertexParams &vertexParams,
bool isIndexedRendering)
{ {
const auto &state = context->getGLState(); const auto &state = context->getGLState();
const gl::VertexArray *vertexArray = state.getVertexArray(); const gl::VertexArray *vertexArray = state.getVertexArray();
...@@ -2666,16 +2664,16 @@ gl::Error StateManager11::applyVertexBuffer(const gl::Context *context, ...@@ -2666,16 +2664,16 @@ gl::Error StateManager11::applyVertexBuffer(const gl::Context *context,
if (mVertexAttribsNeedTranslation) if (mVertexAttribsNeedTranslation)
{ {
ANGLE_TRY(vertexArray11->updateDirtyAndDynamicAttribs(context, &mVertexDataManager, ANGLE_TRY(vertexArray11->updateDirtyAndDynamicAttribs(context, &mVertexDataManager,
vertexParams)); drawCallParams));
mInputLayoutIsDirty = true; mInputLayoutIsDirty = true;
// Determine if we need to update attribs on the next draw. // Determine if we need to update attribs on the next draw.
mVertexAttribsNeedTranslation = (vertexArray11->hasActiveDynamicAttrib(context)); mVertexAttribsNeedTranslation = (vertexArray11->hasActiveDynamicAttrib(context));
} }
if (!mLastFirstVertex.valid() || mLastFirstVertex.value() != vertexParams.firstVertex()) if (!mLastFirstVertex.valid() || mLastFirstVertex.value() != drawCallParams.firstVertex())
{ {
mLastFirstVertex = vertexParams.firstVertex(); mLastFirstVertex = drawCallParams.firstVertex();
mInputLayoutIsDirty = true; mInputLayoutIsDirty = true;
} }
...@@ -2710,12 +2708,13 @@ gl::Error StateManager11::applyVertexBuffer(const gl::Context *context, ...@@ -2710,12 +2708,13 @@ gl::Error StateManager11::applyVertexBuffer(const gl::Context *context,
} }
// Update the applied input layout by querying the cache. // Update the applied input layout by querying the cache.
ANGLE_TRY(mInputLayoutCache.updateInputLayout(mRenderer, state, mCurrentAttributes, mode, ANGLE_TRY(mInputLayoutCache.updateInputLayout(mRenderer, state, mCurrentAttributes,
sortedSemanticIndices, vertexParams)); sortedSemanticIndices, drawCallParams));
// Update the applied vertex buffers. // Update the applied vertex buffers.
ANGLE_TRY(mInputLayoutCache.applyVertexBuffers(context, mCurrentAttributes, mode, ANGLE_TRY(mInputLayoutCache.applyVertexBuffers(
vertexParams.firstVertex(), isIndexedRendering)); context, mCurrentAttributes, drawCallParams.mode(), drawCallParams.firstVertex(),
drawCallParams.isDrawElements()));
// InputLayoutCache::applyVertexBuffers calls through to the Bufer11 to get the native vertex // InputLayoutCache::applyVertexBuffers calls through to the Bufer11 to get the native vertex
// buffer (ID3D11Buffer *). Because we allocate these buffers lazily, this will trigger // buffer (ID3D11Buffer *). Because we allocate these buffers lazily, this will trigger
...@@ -2724,7 +2723,7 @@ gl::Error StateManager11::applyVertexBuffer(const gl::Context *context, ...@@ -2724,7 +2723,7 @@ gl::Error StateManager11::applyVertexBuffer(const gl::Context *context,
// update on the second draw call. // update on the second draw call.
// Hence we clear the flags here, after we've applied vertex data, since we know everything // Hence we clear the flags here, after we've applied vertex data, since we know everything
// is clean. This is a bit of a hack. // is clean. This is a bit of a hack.
vertexArray11->clearDirtyAndPromoteDynamicAttribs(context, vertexParams); vertexArray11->clearDirtyAndPromoteDynamicAttribs(context, drawCallParams);
mInputLayoutIsDirty = false; mInputLayoutIsDirty = false;
return gl::NoError(); return gl::NoError();
...@@ -3181,65 +3180,6 @@ gl::Error StateManager11::syncTransformFeedbackBuffers(const gl::Context *contex ...@@ -3181,65 +3180,6 @@ gl::Error StateManager11::syncTransformFeedbackBuffers(const gl::Context *contex
return gl::NoError(); return gl::NoError();
} }
// DrawCallVertexParams implementation.
DrawCallVertexParams::DrawCallVertexParams(GLint firstVertex,
GLsizei vertexCount,
GLsizei instances)
: mHasIndexRange(nullptr),
mFirstVertex(firstVertex),
mVertexCount(vertexCount),
mInstances(instances),
mBaseVertex(0)
{
}
// Use when in a drawElements call.
DrawCallVertexParams::DrawCallVertexParams(const gl::HasIndexRange &hasIndexRange,
GLint baseVertex,
GLsizei instances)
: mHasIndexRange(&hasIndexRange),
mFirstVertex(baseVertex),
mVertexCount(0),
mInstances(instances),
mBaseVertex(baseVertex)
{
}
GLint DrawCallVertexParams::firstVertex() const
{
// In some cases we can know the first vertex will be fixed at zero, if we're on the "fast
// path". In these cases the index range is not resolved. If the first vertex is not zero,
// however, then it must be because the index range is resolved.
ASSERT(mFirstVertex == 0 || mHasIndexRange == nullptr);
return mFirstVertex;
}
GLsizei DrawCallVertexParams::vertexCount() const
{
ASSERT(mHasIndexRange == nullptr);
return mVertexCount;
}
GLsizei DrawCallVertexParams::instances() const
{
return mInstances;
}
void DrawCallVertexParams::ensureIndexRangeResolved() const
{
if (mHasIndexRange == nullptr)
{
return;
}
// This call will resolve the index range.
const gl::IndexRange &indexRange = mHasIndexRange->getIndexRange().value();
mFirstVertex = mBaseVertex + static_cast<GLint>(indexRange.start);
mVertexCount = static_cast<GLsizei>(indexRange.vertexCount());
mHasIndexRange = nullptr;
}
// OnConstantBufferDirtyReceiver implementation. // OnConstantBufferDirtyReceiver implementation.
StateManager11::OnConstantBufferDirtyReceiver::OnConstantBufferDirtyReceiver() StateManager11::OnConstantBufferDirtyReceiver::OnConstantBufferDirtyReceiver()
{ {
......
...@@ -141,34 +141,6 @@ class ShaderConstants11 : angle::NonCopyable ...@@ -141,34 +141,6 @@ class ShaderConstants11 : angle::NonCopyable
int mNumActiveCSSamplers; int mNumActiveCSSamplers;
}; };
class DrawCallVertexParams final : angle::NonCopyable
{
public:
// Use when in a drawArrays call.
DrawCallVertexParams(GLint firstVertex, GLsizei vertexCount, GLsizei instances);
// Use when in a drawElements call.
DrawCallVertexParams(const gl::HasIndexRange &hasIndexRange,
GLint baseVertex,
GLsizei instances);
// It should be possible to also use an overload to handle the 'slow' indirect draw path.
// TODO(jmadill): Indirect draw slow path overload.
GLint firstVertex() const;
GLsizei vertexCount() const;
GLsizei instances() const;
void ensureIndexRangeResolved() const;
private:
mutable const gl::HasIndexRange *mHasIndexRange;
mutable GLint mFirstVertex;
mutable GLsizei mVertexCount;
GLsizei mInstances;
GLint mBaseVertex;
};
class StateManager11 final : angle::NonCopyable class StateManager11 final : angle::NonCopyable
{ {
public: public:
...@@ -267,9 +239,7 @@ class StateManager11 final : angle::NonCopyable ...@@ -267,9 +239,7 @@ class StateManager11 final : angle::NonCopyable
// Not handled by an internal dirty bit because of the extra draw parameters. // Not handled by an internal dirty bit because of the extra draw parameters.
gl::Error applyVertexBuffer(const gl::Context *context, gl::Error applyVertexBuffer(const gl::Context *context,
GLenum mode, const gl::DrawCallParams &drawCallParams);
const DrawCallVertexParams &vertexParams,
bool isIndexedRendering);
gl::Error applyIndexBuffer(const gl::Context *context, gl::Error applyIndexBuffer(const gl::Context *context,
const void *indices, const void *indices,
......
...@@ -262,7 +262,7 @@ bool VertexArray11::hasActiveDynamicAttrib(const gl::Context *context) ...@@ -262,7 +262,7 @@ bool VertexArray11::hasActiveDynamicAttrib(const gl::Context *context)
gl::Error VertexArray11::updateDirtyAndDynamicAttribs(const gl::Context *context, gl::Error VertexArray11::updateDirtyAndDynamicAttribs(const gl::Context *context,
VertexDataManager *vertexDataManager, VertexDataManager *vertexDataManager,
const DrawCallVertexParams &vertexParams) const gl::DrawCallParams &drawCallParams)
{ {
flushAttribUpdates(context); flushAttribUpdates(context);
...@@ -315,7 +315,7 @@ gl::Error VertexArray11::updateDirtyAndDynamicAttribs(const gl::Context *context ...@@ -315,7 +315,7 @@ gl::Error VertexArray11::updateDirtyAndDynamicAttribs(const gl::Context *context
if (mDynamicAttribsMask.any()) if (mDynamicAttribsMask.any())
{ {
vertexParams.ensureIndexRangeResolved(); drawCallParams.ensureIndexRangeResolved();
auto activeDynamicAttribs = (mDynamicAttribsMask & activeLocations); auto activeDynamicAttribs = (mDynamicAttribsMask & activeLocations);
if (activeDynamicAttribs.none()) if (activeDynamicAttribs.none())
...@@ -337,8 +337,8 @@ gl::Error VertexArray11::updateDirtyAndDynamicAttribs(const gl::Context *context ...@@ -337,8 +337,8 @@ gl::Error VertexArray11::updateDirtyAndDynamicAttribs(const gl::Context *context
} }
ANGLE_TRY(vertexDataManager->storeDynamicAttribs( ANGLE_TRY(vertexDataManager->storeDynamicAttribs(
context, &mTranslatedAttribs, activeDynamicAttribs, vertexParams.firstVertex(), context, &mTranslatedAttribs, activeDynamicAttribs, drawCallParams.firstVertex(),
vertexParams.vertexCount(), vertexParams.instances())); drawCallParams.vertexCount(), drawCallParams.instances()));
} }
return gl::NoError(); return gl::NoError();
...@@ -373,7 +373,7 @@ void VertexArray11::onSubjectStateChange(const gl::Context *context, ...@@ -373,7 +373,7 @@ void VertexArray11::onSubjectStateChange(const gl::Context *context,
} }
void VertexArray11::clearDirtyAndPromoteDynamicAttribs(const gl::Context *context, void VertexArray11::clearDirtyAndPromoteDynamicAttribs(const gl::Context *context,
const DrawCallVertexParams &vertexParams) const gl::DrawCallParams &drawCallParams)
{ {
const gl::State &state = context->getGLState(); const gl::State &state = context->getGLState();
const gl::Program *program = state.getProgram(); const gl::Program *program = state.getProgram();
...@@ -385,7 +385,7 @@ void VertexArray11::clearDirtyAndPromoteDynamicAttribs(const gl::Context *contex ...@@ -385,7 +385,7 @@ void VertexArray11::clearDirtyAndPromoteDynamicAttribs(const gl::Context *contex
if (activeDynamicAttribs.any()) if (activeDynamicAttribs.any())
{ {
VertexDataManager::PromoteDynamicAttribs(context, mTranslatedAttribs, activeDynamicAttribs, VertexDataManager::PromoteDynamicAttribs(context, mTranslatedAttribs, activeDynamicAttribs,
vertexParams.vertexCount()); drawCallParams.vertexCount());
} }
} }
......
...@@ -32,9 +32,9 @@ class VertexArray11 : public angle::ObserverInterface, public VertexArrayImpl ...@@ -32,9 +32,9 @@ class VertexArray11 : public angle::ObserverInterface, public VertexArrayImpl
bool hasActiveDynamicAttrib(const gl::Context *context); bool hasActiveDynamicAttrib(const gl::Context *context);
gl::Error updateDirtyAndDynamicAttribs(const gl::Context *context, gl::Error updateDirtyAndDynamicAttribs(const gl::Context *context,
VertexDataManager *vertexDataManager, VertexDataManager *vertexDataManager,
const DrawCallVertexParams &vertexParams); const gl::DrawCallParams &drawCallParams);
void clearDirtyAndPromoteDynamicAttribs(const gl::Context *context, void clearDirtyAndPromoteDynamicAttribs(const gl::Context *context,
const DrawCallVertexParams &vertexParams); const gl::DrawCallParams &drawCallParams);
const std::vector<TranslatedAttribute> &getTranslatedAttribs() const; const std::vector<TranslatedAttribute> &getTranslatedAttribs() const;
......
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