Commit 1da00653 by Qin Jiajia Committed by Commit Bot

Remove IndexRange in DrawElements functions

This change will remove IndexRange parameter in DrawElements functions. And calculate it until we truly need it. Meanwhile we add direct drawing path to avoid retrieving index range for DrawElements* functions in D3D11 backend. This change may not bring much performance improvement since we still need to retrieve index range in validation at the beginning of every DrawElements* call entry point. BUG=angleproject:1393 Change-Id: I86a8739c0893954c94eb398db62820ced7871565 Reviewed-on: https://chromium-review.googlesource.com/544634Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent a779b610
...@@ -1855,8 +1855,7 @@ void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsiz ...@@ -1855,8 +1855,7 @@ void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsiz
void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices) void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
{ {
syncRendererState(); syncRendererState();
const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value(); handleError(mImplementation->drawElements(this, mode, count, type, indices));
handleError(mImplementation->drawElements(this, mode, count, type, indices, indexRange));
} }
void Context::drawElementsInstanced(GLenum mode, void Context::drawElementsInstanced(GLenum mode,
...@@ -1866,9 +1865,8 @@ void Context::drawElementsInstanced(GLenum mode, ...@@ -1866,9 +1865,8 @@ void Context::drawElementsInstanced(GLenum mode,
GLsizei instances) GLsizei instances)
{ {
syncRendererState(); syncRendererState();
const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value(); handleError(
handleError(mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances, mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
indexRange));
} }
void Context::drawRangeElements(GLenum mode, void Context::drawRangeElements(GLenum mode,
...@@ -1879,9 +1877,7 @@ void Context::drawRangeElements(GLenum mode, ...@@ -1879,9 +1877,7 @@ void Context::drawRangeElements(GLenum mode,
const void *indices) const void *indices)
{ {
syncRendererState(); syncRendererState();
const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value(); handleError(mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
handleError(mImplementation->drawRangeElements(this, mode, start, end, count, type, indices,
indexRange));
} }
void Context::drawArraysIndirect(GLenum mode, const void *indirect) void Context::drawArraysIndirect(GLenum mode, const void *indirect)
......
...@@ -51,23 +51,20 @@ class ContextImpl : public GLImplFactory ...@@ -51,23 +51,20 @@ class ContextImpl : public GLImplFactory
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) = 0;
const gl::IndexRange &indexRange) = 0;
virtual gl::Error drawElementsInstanced(const gl::Context *context, virtual gl::Error drawElementsInstanced(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances) = 0;
const gl::IndexRange &indexRange) = 0;
virtual gl::Error drawRangeElements(const gl::Context *context, virtual gl::Error drawRangeElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLuint start, GLuint start,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) = 0;
const gl::IndexRange &indexRange) = 0;
virtual gl::Error drawArraysIndirect(const gl::Context *context, virtual gl::Error drawArraysIndirect(const gl::Context *context,
GLenum mode, GLenum mode,
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "common/utilities.h" #include "common/utilities.h"
#include "libANGLE/Buffer.h" #include "libANGLE/Buffer.h"
#include "libANGLE/Context.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/BufferD3D.h" #include "libANGLE/renderer/d3d/BufferD3D.h"
#include "libANGLE/renderer/d3d/IndexBuffer.h" #include "libANGLE/renderer/d3d/IndexBuffer.h"
...@@ -146,11 +148,12 @@ bool IndexDataManager::usePrimitiveRestartWorkaround(bool primitiveRestartFixedI ...@@ -146,11 +148,12 @@ bool IndexDataManager::usePrimitiveRestartWorkaround(bool primitiveRestartFixedI
mRendererClass == RENDERER_D3D11); mRendererClass == RENDERER_D3D11);
} }
bool IndexDataManager::isStreamingIndexData(bool primitiveRestartWorkaround, bool IndexDataManager::isStreamingIndexData(const gl::Context *context, GLenum srcType)
GLenum srcType,
gl::Buffer *glBuffer)
{ {
BufferD3D *buffer = glBuffer ? GetImplAs<BufferD3D>(glBuffer) : nullptr; const auto &glState = context->getGLState();
bool primitiveRestartWorkaround =
usePrimitiveRestartWorkaround(glState.isPrimitiveRestartEnabled(), srcType);
gl::Buffer *glBuffer = glState.getVertexArray()->getElementArrayBuffer().get();
// Case 1: the indices are passed by pointer, which forces the streaming of index data // Case 1: the indices are passed by pointer, which forces the streaming of index data
if (glBuffer == nullptr) if (glBuffer == nullptr)
...@@ -158,6 +161,7 @@ bool IndexDataManager::isStreamingIndexData(bool primitiveRestartWorkaround, ...@@ -158,6 +161,7 @@ bool IndexDataManager::isStreamingIndexData(bool primitiveRestartWorkaround,
return true; return true;
} }
BufferD3D *buffer = GetImplAs<BufferD3D>(glBuffer);
const GLenum dstType = (srcType == GL_UNSIGNED_INT || primitiveRestartWorkaround) const GLenum dstType = (srcType == GL_UNSIGNED_INT || primitiveRestartWorkaround)
? GL_UNSIGNED_INT ? GL_UNSIGNED_INT
: GL_UNSIGNED_SHORT; : GL_UNSIGNED_SHORT;
...@@ -175,7 +179,7 @@ bool IndexDataManager::isStreamingIndexData(bool primitiveRestartWorkaround, ...@@ -175,7 +179,7 @@ bool IndexDataManager::isStreamingIndexData(bool primitiveRestartWorkaround,
return true; return true;
} }
if ((staticBuffer->getBufferSize() != 0) && (staticBuffer->getIndexType() != dstType)) if ((staticBuffer->getBufferSize() == 0) || (staticBuffer->getIndexType() != dstType))
{ {
return true; return true;
} }
......
...@@ -69,9 +69,7 @@ class IndexDataManager : angle::NonCopyable ...@@ -69,9 +69,7 @@ class IndexDataManager : angle::NonCopyable
virtual ~IndexDataManager(); virtual ~IndexDataManager();
bool usePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled, GLenum type); bool usePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled, GLenum type);
bool isStreamingIndexData(bool primitiveRestartWorkaround, bool isStreamingIndexData(const gl::Context *context, GLenum srcType);
GLenum srcType,
gl::Buffer *glBuffer);
gl::Error prepareIndexData(GLenum srcType, gl::Error prepareIndexData(GLenum srcType,
GLsizei count, GLsizei count,
gl::Buffer *glBuffer, gl::Buffer *glBuffer,
......
...@@ -293,6 +293,12 @@ Serial RendererD3D::generateSerial() ...@@ -293,6 +293,12 @@ Serial RendererD3D::generateSerial()
return mSerialFactory.generate(); return mSerialFactory.generate();
} }
bool RendererD3D::instancedPointSpritesActive(ProgramD3D *programD3D, GLenum mode) const
{
return programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation() &&
mode == GL_POINTS;
}
unsigned int GetBlendSampleMask(const gl::State &glState, int samples) unsigned int GetBlendSampleMask(const gl::State &glState, int samples)
{ {
unsigned int mask = 0; unsigned int mask = 0;
......
...@@ -336,6 +336,11 @@ class RendererD3D : public BufferFactoryD3D ...@@ -336,6 +336,11 @@ class RendererD3D : public BufferFactoryD3D
gl::TextureCapsMap *outTextureCaps, gl::TextureCapsMap *outTextureCaps,
gl::Extensions *outExtensions, gl::Extensions *outExtensions,
gl::Limitations *outLimitations) const = 0; gl::Limitations *outLimitations) const = 0;
virtual bool instancedPointSpritesActive(ProgramD3D *programD3D, GLenum mode) const;
// Support direct drawing with the drawing parameters.
virtual bool supportsDirectDrawing(const gl::Context *context,
GLenum mode,
GLenum type) const = 0;
void cleanup(); void cleanup();
......
...@@ -167,10 +167,9 @@ gl::Error Context11::drawElements(const gl::Context *context, ...@@ -167,10 +167,9 @@ gl::Error Context11::drawElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
return mRenderer->genericDrawElements(context, mode, count, type, indices, 0, indexRange); return mRenderer->genericDrawElements(context, mode, count, type, indices, 0);
} }
gl::Error Context11::drawElementsInstanced(const gl::Context *context, gl::Error Context11::drawElementsInstanced(const gl::Context *context,
...@@ -178,11 +177,9 @@ gl::Error Context11::drawElementsInstanced(const gl::Context *context, ...@@ -178,11 +177,9 @@ gl::Error Context11::drawElementsInstanced(const gl::Context *context,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances)
const gl::IndexRange &indexRange)
{ {
return mRenderer->genericDrawElements(context, mode, count, type, indices, instances, return mRenderer->genericDrawElements(context, mode, count, type, indices, instances);
indexRange);
} }
gl::Error Context11::drawRangeElements(const gl::Context *context, gl::Error Context11::drawRangeElements(const gl::Context *context,
...@@ -191,10 +188,9 @@ gl::Error Context11::drawRangeElements(const gl::Context *context, ...@@ -191,10 +188,9 @@ gl::Error Context11::drawRangeElements(const gl::Context *context,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
return mRenderer->genericDrawElements(context, mode, count, type, indices, 0, indexRange); return mRenderer->genericDrawElements(context, mode, count, type, indices, 0);
} }
gl::Error Context11::drawArraysIndirect(const gl::Context *context, gl::Error Context11::drawArraysIndirect(const gl::Context *context,
......
...@@ -78,23 +78,20 @@ class Context11 : public ContextImpl ...@@ -78,23 +78,20 @@ class Context11 : public ContextImpl
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) override;
const gl::IndexRange &indexRange) override;
gl::Error drawElementsInstanced(const gl::Context *context, gl::Error drawElementsInstanced(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances) override;
const gl::IndexRange &indexRange) override;
gl::Error drawRangeElements(const gl::Context *context, gl::Error drawRangeElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLuint start, GLuint start,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) override;
const gl::IndexRange &indexRange) override;
gl::Error drawArraysIndirect(const gl::Context *context, gl::Error drawArraysIndirect(const gl::Context *context,
GLenum mode, GLenum mode,
const void *indirect) override; const void *indirect) override;
......
...@@ -1792,14 +1792,43 @@ gl::Error Renderer11::drawArraysImpl(const gl::Context *context, ...@@ -1792,14 +1792,43 @@ gl::Error Renderer11::drawArraysImpl(const gl::Context *context,
return gl::NoError(); return gl::NoError();
} }
gl::Error Renderer11::drawElementsImpl(const gl::ContextState &data, gl::Error Renderer11::drawElementsImpl(const gl::Context *context,
const TranslatedIndexData &indexInfo,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances) GLsizei instances)
{ {
const auto &data = context->getContextState();
TranslatedIndexData indexInfo;
if (supportsDirectDrawing(context, mode, type))
{
ANGLE_TRY(applyIndexBuffer(data, nullptr, 0, mode, type, &indexInfo));
ANGLE_TRY(applyVertexBuffer(context, mode, 0, 0, 0, &indexInfo));
const gl::Type &typeInfo = gl::GetTypeInfo(type);
unsigned int startIndexLocation =
static_cast<unsigned int>(reinterpret_cast<const uintptr_t>(indices)) / typeInfo.bytes;
if (instances > 0)
{
mDeviceContext->DrawIndexedInstanced(count, instances, startIndexLocation, 0, 0);
}
else
{
mDeviceContext->DrawIndexed(count, startIndexLocation, 0);
}
return gl::NoError();
}
const gl::IndexRange &indexRange =
context->getParams<gl::HasIndexRange>().getIndexRange().value();
indexInfo.indexRange = indexRange;
ANGLE_TRY(applyIndexBuffer(data, indices, count, mode, type, &indexInfo));
size_t vertexCount = indexInfo.indexRange.vertexCount();
ANGLE_TRY(applyVertexBuffer(context, mode, static_cast<GLsizei>(indexInfo.indexRange.start),
static_cast<GLsizei>(vertexCount), instances, &indexInfo));
int startVertex = static_cast<int>(indexInfo.indexRange.start); int startVertex = static_cast<int>(indexInfo.indexRange.start);
int baseVertex = -startVertex; int baseVertex = -startVertex;
...@@ -1863,12 +1892,12 @@ gl::Error Renderer11::drawElementsImpl(const gl::ContextState &data, ...@@ -1863,12 +1892,12 @@ gl::Error Renderer11::drawElementsImpl(const gl::ContextState &data,
return gl::NoError(); return gl::NoError();
} }
bool Renderer11::supportsFastIndirectDraw(const gl::Context *context, GLenum mode, GLenum type) bool Renderer11::supportsDirectDrawing(const gl::Context *context, GLenum mode, GLenum type) const
{ {
const auto &glState = context->getGLState(); const auto &glState = context->getGLState();
const auto &vertexArray = glState.getVertexArray(); const auto &vertexArray = glState.getVertexArray();
auto *vertexArray11 = GetImplAs<VertexArray11>(vertexArray); auto *vertexArray11 = GetImplAs<VertexArray11>(vertexArray);
// Indirect drawing doesn't support dynamic attribute storage since it needs the first and count // Direct drawing doesn't support dynamic attribute storage since it needs the first and count
// to translate when applyVertexBuffer. GL_LINE_LOOP and GL_TRIANGLE_FAN are not supported // to translate when applyVertexBuffer. GL_LINE_LOOP and GL_TRIANGLE_FAN are not supported
// either since we need to simulate them in D3D. // either since we need to simulate them in D3D.
if (vertexArray11->hasDynamicAttrib(context) || mode == GL_LINE_LOOP || mode == GL_TRIANGLE_FAN) if (vertexArray11->hasDynamicAttrib(context) || mode == GL_LINE_LOOP || mode == GL_TRIANGLE_FAN)
...@@ -1876,18 +1905,17 @@ bool Renderer11::supportsFastIndirectDraw(const gl::Context *context, GLenum mod ...@@ -1876,18 +1905,17 @@ bool Renderer11::supportsFastIndirectDraw(const gl::Context *context, GLenum mod
return false; return false;
} }
ProgramD3D *programD3D = GetImplAs<ProgramD3D>(glState.getProgram());
if (instancedPointSpritesActive(programD3D, mode))
{
return false;
}
if (type != GL_NONE) if (type != GL_NONE)
{ {
gl::Buffer *elementArrayBuffer = vertexArray->getElementArrayBuffer().get(); // Only non-streaming index data can be directly used to draw since they don't
ASSERT(elementArrayBuffer); // need the indices and count informations.
// Only non-streaming index data can be directly used to do indirect draw since they don't return !mIndexDataManager->isStreamingIndexData(context, type);
// need the indices and count informations. Here we don't check whether it really has
// primitive restart index in it since it also needs to know the index range and count.
// So, for all other situations, we fall back to normal draw instead of indirect draw.
bool primitiveRestartWorkaround = mIndexDataManager->usePrimitiveRestartWorkaround(
glState.isPrimitiveRestartEnabled(), type);
return !mIndexDataManager->isStreamingIndexData(primitiveRestartWorkaround, type,
elementArrayBuffer);
} }
return true; return true;
} }
...@@ -1908,7 +1936,7 @@ gl::Error Renderer11::drawArraysIndirectImpl(const gl::Context *context, ...@@ -1908,7 +1936,7 @@ gl::Error Renderer11::drawArraysIndirectImpl(const gl::Context *context,
Buffer11 *storage = GetImplAs<Buffer11>(drawIndirectBuffer); Buffer11 *storage = GetImplAs<Buffer11>(drawIndirectBuffer);
uintptr_t offset = reinterpret_cast<uintptr_t>(indirect); uintptr_t offset = reinterpret_cast<uintptr_t>(indirect);
if (supportsFastIndirectDraw(context, mode, GL_NONE)) if (supportsDirectDrawing(context, mode, GL_NONE))
{ {
applyVertexBuffer(context, mode, 0, 0, 0, nullptr); applyVertexBuffer(context, mode, 0, 0, 0, nullptr);
ID3D11Buffer *buffer = nullptr; ID3D11Buffer *buffer = nullptr;
...@@ -1959,7 +1987,7 @@ gl::Error Renderer11::drawElementsIndirectImpl(const gl::Context *context, ...@@ -1959,7 +1987,7 @@ gl::Error Renderer11::drawElementsIndirectImpl(const gl::Context *context,
uintptr_t offset = reinterpret_cast<uintptr_t>(indirect); uintptr_t offset = reinterpret_cast<uintptr_t>(indirect);
TranslatedIndexData indexInfo; TranslatedIndexData indexInfo;
if (supportsFastIndirectDraw(context, mode, type)) if (supportsDirectDrawing(context, mode, type))
{ {
ANGLE_TRY(applyIndexBuffer(contextState, nullptr, 0, mode, type, &indexInfo)); ANGLE_TRY(applyIndexBuffer(contextState, nullptr, 0, mode, type, &indexInfo));
ANGLE_TRY(applyVertexBuffer(context, mode, 0, 0, 0, &indexInfo)); ANGLE_TRY(applyVertexBuffer(context, mode, 0, 0, 0, &indexInfo));
...@@ -4229,8 +4257,7 @@ gl::Error Renderer11::genericDrawElements(const gl::Context *context, ...@@ -4229,8 +4257,7 @@ gl::Error Renderer11::genericDrawElements(const gl::Context *context,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances)
const gl::IndexRange &indexRange)
{ {
const auto &data = context->getContextState(); const auto &data = context->getContextState();
const auto &glState = data.getState(); const auto &glState = data.getState();
...@@ -4250,24 +4277,16 @@ gl::Error Renderer11::genericDrawElements(const gl::Context *context, ...@@ -4250,24 +4277,16 @@ gl::Error Renderer11::genericDrawElements(const gl::Context *context,
ANGLE_TRY(mStateManager.updateState(context, mode)); ANGLE_TRY(mStateManager.updateState(context, mode));
TranslatedIndexData indexInfo;
indexInfo.indexRange = indexRange;
ANGLE_TRY(applyIndexBuffer(data, indices, count, mode, type, &indexInfo));
applyTransformFeedbackBuffers(data); applyTransformFeedbackBuffers(data);
// Transform feedback is not allowed for DrawElements, this error should have been caught at the // Transform feedback is not allowed for DrawElements, this error should have been caught at the
// API validation layer. // API validation layer.
ASSERT(!glState.isTransformFeedbackActiveUnpaused()); ASSERT(!glState.isTransformFeedbackActiveUnpaused());
size_t vertexCount = indexInfo.indexRange.vertexCount();
ANGLE_TRY(applyVertexBuffer(context, mode, static_cast<GLsizei>(indexInfo.indexRange.start),
static_cast<GLsizei>(vertexCount), instances, &indexInfo));
ANGLE_TRY(programD3D->applyUniformBuffers(data)); ANGLE_TRY(programD3D->applyUniformBuffers(data));
if (!skipDraw(data, mode)) if (!skipDraw(data, mode))
{ {
ANGLE_TRY(drawElementsImpl(data, indexInfo, mode, count, type, indices, instances)); ANGLE_TRY(drawElementsImpl(context, mode, count, type, indices, instances));
} }
return gl::NoError(); return gl::NoError();
......
...@@ -404,8 +404,7 @@ class Renderer11 : public RendererD3D ...@@ -404,8 +404,7 @@ class Renderer11 : public RendererD3D
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances);
const gl::IndexRange &indexRange);
gl::Error genericDrawIndirect(const gl::Context *context, gl::Error genericDrawIndirect(const gl::Context *context,
GLenum mode, GLenum mode,
...@@ -471,14 +470,17 @@ class Renderer11 : public RendererD3D ...@@ -471,14 +470,17 @@ class Renderer11 : public RendererD3D
gl::Error clearRenderTarget(RenderTargetD3D *renderTarget, gl::Error clearRenderTarget(RenderTargetD3D *renderTarget,
const gl::ColorF &clearValues) override; const gl::ColorF &clearValues) override;
protected:
// Support direct drawing with the drawing parameters.
bool supportsDirectDrawing(const gl::Context *context, GLenum mode, GLenum type) const override;
private: private:
gl::Error drawArraysImpl(const gl::Context *context, gl::Error drawArraysImpl(const gl::Context *context,
GLenum mode, GLenum mode,
GLint startVertex, GLint startVertex,
GLsizei count, GLsizei count,
GLsizei instances); GLsizei instances);
gl::Error drawElementsImpl(const gl::ContextState &data, gl::Error drawElementsImpl(const gl::Context *context,
const TranslatedIndexData &indexInfo,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
...@@ -490,9 +492,6 @@ class Renderer11 : public RendererD3D ...@@ -490,9 +492,6 @@ class Renderer11 : public RendererD3D
GLenum type, GLenum type,
const void *indirect); const void *indirect);
// Support directly using indirect draw buffer.
bool supportsFastIndirectDraw(const gl::Context *context, GLenum mode, GLenum type);
void generateCaps(gl::Caps *outCaps, void generateCaps(gl::Caps *outCaps,
gl::TextureCapsMap *outTextureCaps, gl::TextureCapsMap *outTextureCaps,
gl::Extensions *outExtensions, gl::Extensions *outExtensions,
......
...@@ -153,10 +153,9 @@ gl::Error Context9::drawElements(const gl::Context *context, ...@@ -153,10 +153,9 @@ gl::Error Context9::drawElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
return mRenderer->genericDrawElements(context, mode, count, type, indices, 0, indexRange); return mRenderer->genericDrawElements(context, mode, count, type, indices, 0);
} }
gl::Error Context9::drawElementsInstanced(const gl::Context *context, gl::Error Context9::drawElementsInstanced(const gl::Context *context,
...@@ -164,11 +163,9 @@ gl::Error Context9::drawElementsInstanced(const gl::Context *context, ...@@ -164,11 +163,9 @@ gl::Error Context9::drawElementsInstanced(const gl::Context *context,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances)
const gl::IndexRange &indexRange)
{ {
return mRenderer->genericDrawElements(context, mode, count, type, indices, instances, return mRenderer->genericDrawElements(context, mode, count, type, indices, instances);
indexRange);
} }
gl::Error Context9::drawRangeElements(const gl::Context *context, gl::Error Context9::drawRangeElements(const gl::Context *context,
...@@ -177,10 +174,9 @@ gl::Error Context9::drawRangeElements(const gl::Context *context, ...@@ -177,10 +174,9 @@ gl::Error Context9::drawRangeElements(const gl::Context *context,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
return mRenderer->genericDrawElements(context, mode, count, type, indices, 0, indexRange); return mRenderer->genericDrawElements(context, mode, count, type, indices, 0);
} }
gl::Error Context9::drawArraysIndirect(const gl::Context *context, gl::Error Context9::drawArraysIndirect(const gl::Context *context,
......
...@@ -78,23 +78,20 @@ class Context9 : public ContextImpl ...@@ -78,23 +78,20 @@ class Context9 : public ContextImpl
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) override;
const gl::IndexRange &indexRange) override;
gl::Error drawElementsInstanced(const gl::Context *context, gl::Error drawElementsInstanced(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances) override;
const gl::IndexRange &indexRange) override;
gl::Error drawRangeElements(const gl::Context *context, gl::Error drawRangeElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLuint start, GLuint start,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) override;
const gl::IndexRange &indexRange) override;
gl::Error drawArraysIndirect(const gl::Context *context, gl::Error drawArraysIndirect(const gl::Context *context,
GLenum mode, GLenum mode,
const void *indirect) override; const void *indirect) override;
......
...@@ -1412,14 +1412,24 @@ gl::Error Renderer9::drawArraysImpl(const gl::ContextState &data, ...@@ -1412,14 +1412,24 @@ gl::Error Renderer9::drawArraysImpl(const gl::ContextState &data,
} }
} }
gl::Error Renderer9::drawElementsImpl(const gl::ContextState &data, gl::Error Renderer9::drawElementsImpl(const gl::Context *context,
const TranslatedIndexData &indexInfo,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei /*instances*/) GLsizei instances)
{ {
const auto &data = context->getContextState();
TranslatedIndexData indexInfo;
const gl::IndexRange &indexRange =
context->getParams<gl::HasIndexRange>().getIndexRange().value();
indexInfo.indexRange = indexRange;
ANGLE_TRY(applyIndexBuffer(data, indices, count, mode, type, &indexInfo));
size_t vertexCount = indexInfo.indexRange.vertexCount();
ANGLE_TRY(applyVertexBuffer(data.getState(), mode,
static_cast<GLsizei>(indexInfo.indexRange.start),
static_cast<GLsizei>(vertexCount), instances, &indexInfo));
startScene(); startScene();
int minIndex = static_cast<int>(indexInfo.indexRange.start); int minIndex = static_cast<int>(indexInfo.indexRange.start);
...@@ -1437,7 +1447,6 @@ gl::Error Renderer9::drawElementsImpl(const gl::ContextState &data, ...@@ -1437,7 +1447,6 @@ gl::Error Renderer9::drawElementsImpl(const gl::ContextState &data,
} }
else else
{ {
size_t vertexCount = indexInfo.indexRange.vertexCount();
for (int i = 0; i < mRepeatDraw; i++) for (int i = 0; i < mRepeatDraw; i++)
{ {
mDevice->DrawIndexedPrimitive(mPrimitiveType, -minIndex, minIndex, mDevice->DrawIndexedPrimitive(mPrimitiveType, -minIndex, minIndex,
...@@ -3112,8 +3121,7 @@ gl::Error Renderer9::genericDrawElements(const gl::Context *context, ...@@ -3112,8 +3121,7 @@ gl::Error Renderer9::genericDrawElements(const gl::Context *context,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances)
const gl::IndexRange &indexRange)
{ {
const auto &data = context->getContextState(); const auto &data = context->getContextState();
gl::Program *program = context->getGLState().getProgram(); gl::Program *program = context->getGLState().getProgram();
...@@ -3130,10 +3138,7 @@ gl::Error Renderer9::genericDrawElements(const gl::Context *context, ...@@ -3130,10 +3138,7 @@ gl::Error Renderer9::genericDrawElements(const gl::Context *context,
ANGLE_TRY(updateState(context, mode)); ANGLE_TRY(updateState(context, mode));
TranslatedIndexData indexInfo;
indexInfo.indexRange = indexRange;
ANGLE_TRY(applyIndexBuffer(data, indices, count, mode, type, &indexInfo));
applyTransformFeedbackBuffers(data.getState()); applyTransformFeedbackBuffers(data.getState());
// Transform feedback is not allowed for DrawElements, this error should have been caught at the // Transform feedback is not allowed for DrawElements, this error should have been caught at the
...@@ -3141,17 +3146,13 @@ gl::Error Renderer9::genericDrawElements(const gl::Context *context, ...@@ -3141,17 +3146,13 @@ gl::Error Renderer9::genericDrawElements(const gl::Context *context,
// layer. // layer.
ASSERT(!data.getState().isTransformFeedbackActiveUnpaused()); ASSERT(!data.getState().isTransformFeedbackActiveUnpaused());
size_t vertexCount = indexInfo.indexRange.vertexCount();
ANGLE_TRY(applyVertexBuffer(data.getState(), mode,
static_cast<GLsizei>(indexInfo.indexRange.start),
static_cast<GLsizei>(vertexCount), instances, &indexInfo));
ANGLE_TRY(applyTextures(context)); ANGLE_TRY(applyTextures(context));
ANGLE_TRY(applyShaders(context, mode)); ANGLE_TRY(applyShaders(context, mode));
ANGLE_TRY(programD3D->applyUniformBuffers(data)); ANGLE_TRY(programD3D->applyUniformBuffers(data));
if (!skipDraw(data, mode)) if (!skipDraw(data, mode))
{ {
ANGLE_TRY(drawElementsImpl(data, indexInfo, mode, count, type, indices, instances)); ANGLE_TRY(drawElementsImpl(context, mode, count, type, indices, instances));
} }
return gl::NoError(); return gl::NoError();
...@@ -3196,6 +3197,13 @@ gl::Error Renderer9::genericDrawArrays(const gl::Context *context, ...@@ -3196,6 +3197,13 @@ gl::Error Renderer9::genericDrawArrays(const gl::Context *context,
return gl::NoError(); return gl::NoError();
} }
bool Renderer9::supportsDirectDrawing(const gl::Context *context, GLenum mode, GLenum type) const
{
// TODO(jiajia.qin@intel.com): Add direct drawing for d3d9
UNIMPLEMENTED();
return false;
}
FramebufferImpl *Renderer9::createDefaultFramebuffer(const gl::FramebufferState &state) FramebufferImpl *Renderer9::createDefaultFramebuffer(const gl::FramebufferState &state)
{ {
return new Framebuffer9(state, this); return new Framebuffer9(state, this);
......
...@@ -382,8 +382,7 @@ class Renderer9 : public RendererD3D ...@@ -382,8 +382,7 @@ class Renderer9 : public RendererD3D
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances);
const gl::IndexRange &indexRange);
// Necessary hack for default framebuffers in D3D. // Necessary hack for default framebuffers in D3D.
FramebufferImpl *createDefaultFramebuffer(const gl::FramebufferState &state) override; FramebufferImpl *createDefaultFramebuffer(const gl::FramebufferState &state) override;
...@@ -398,14 +397,17 @@ class Renderer9 : public RendererD3D ...@@ -398,14 +397,17 @@ class Renderer9 : public RendererD3D
gl::Error clearRenderTarget(RenderTargetD3D *renderTarget, gl::Error clearRenderTarget(RenderTargetD3D *renderTarget,
const gl::ColorF &clearValues) override; const gl::ColorF &clearValues) override;
protected:
// Support direct drawing with the drawing parameters.
bool supportsDirectDrawing(const gl::Context *context, GLenum mode, GLenum type) const override;
private: private:
gl::Error drawArraysImpl(const gl::ContextState &data, gl::Error drawArraysImpl(const gl::ContextState &data,
GLenum mode, GLenum mode,
GLint startVertex, GLint startVertex,
GLsizei count, GLsizei count,
GLsizei instances); GLsizei instances);
gl::Error drawElementsImpl(const gl::ContextState &data, gl::Error drawElementsImpl(const gl::Context *context,
const TranslatedIndexData &indexInfo,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
......
...@@ -170,10 +170,9 @@ gl::Error ContextGL::drawElements(const gl::Context *context, ...@@ -170,10 +170,9 @@ gl::Error ContextGL::drawElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
return mRenderer->drawElements(context, mode, count, type, indices, indexRange); return mRenderer->drawElements(context, mode, count, type, indices);
} }
gl::Error ContextGL::drawElementsInstanced(const gl::Context *context, gl::Error ContextGL::drawElementsInstanced(const gl::Context *context,
...@@ -181,11 +180,9 @@ gl::Error ContextGL::drawElementsInstanced(const gl::Context *context, ...@@ -181,11 +180,9 @@ gl::Error ContextGL::drawElementsInstanced(const gl::Context *context,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances)
const gl::IndexRange &indexRange)
{ {
return mRenderer->drawElementsInstanced(context, mode, count, type, indices, instances, return mRenderer->drawElementsInstanced(context, mode, count, type, indices, instances);
indexRange);
} }
gl::Error ContextGL::drawRangeElements(const gl::Context *context, gl::Error ContextGL::drawRangeElements(const gl::Context *context,
...@@ -194,11 +191,9 @@ gl::Error ContextGL::drawRangeElements(const gl::Context *context, ...@@ -194,11 +191,9 @@ gl::Error ContextGL::drawRangeElements(const gl::Context *context,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
return mRenderer->drawRangeElements(context, mode, start, end, count, type, indices, return mRenderer->drawRangeElements(context, mode, start, end, count, type, indices);
indexRange);
} }
gl::Error ContextGL::drawArraysIndirect(const gl::Context *context, gl::Error ContextGL::drawArraysIndirect(const gl::Context *context,
......
...@@ -86,23 +86,20 @@ class ContextGL : public ContextImpl ...@@ -86,23 +86,20 @@ class ContextGL : public ContextImpl
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) override;
const gl::IndexRange &indexRange) override;
gl::Error drawElementsInstanced(const gl::Context *context, gl::Error drawElementsInstanced(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances) override;
const gl::IndexRange &indexRange) override;
gl::Error drawRangeElements(const gl::Context *context, gl::Error drawRangeElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLuint start, GLuint start,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) override;
const gl::IndexRange &indexRange) override;
gl::Error drawArraysIndirect(const gl::Context *context, gl::Error drawArraysIndirect(const gl::Context *context,
GLenum mode, GLenum mode,
const void *indirect) override; const void *indirect) override;
......
...@@ -282,8 +282,7 @@ gl::Error RendererGL::drawElements(const gl::Context *context, ...@@ -282,8 +282,7 @@ gl::Error RendererGL::drawElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
const void *drawIndexPtr = nullptr; const void *drawIndexPtr = nullptr;
ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices, 0, &drawIndexPtr)); ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices, 0, &drawIndexPtr));
...@@ -301,8 +300,7 @@ gl::Error RendererGL::drawElementsInstanced(const gl::Context *context, ...@@ -301,8 +300,7 @@ gl::Error RendererGL::drawElementsInstanced(const gl::Context *context,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances)
const gl::IndexRange &indexRange)
{ {
const void *drawIndexPointer = nullptr; const void *drawIndexPointer = nullptr;
ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices, instances, ANGLE_TRY(mStateManager->setDrawElementsState(context, count, type, indices, instances,
...@@ -322,8 +320,7 @@ gl::Error RendererGL::drawRangeElements(const gl::Context *context, ...@@ -322,8 +320,7 @@ gl::Error RendererGL::drawRangeElements(const gl::Context *context,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
const void *drawIndexPointer = nullptr; const void *drawIndexPointer = nullptr;
ANGLE_TRY( ANGLE_TRY(
......
...@@ -62,23 +62,20 @@ class RendererGL : angle::NonCopyable ...@@ -62,23 +62,20 @@ class RendererGL : angle::NonCopyable
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices);
const gl::IndexRange &indexRange);
gl::Error drawElementsInstanced(const gl::Context *context, gl::Error drawElementsInstanced(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances);
const gl::IndexRange &indexRange);
gl::Error drawRangeElements(const gl::Context *context, gl::Error drawRangeElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLuint start, GLuint start,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices);
const gl::IndexRange &indexRange);
gl::Error drawArraysIndirect(const gl::Context *context, GLenum mode, const void *indirect); gl::Error drawArraysIndirect(const gl::Context *context, GLenum mode, const void *indirect);
gl::Error drawElementsIndirect(const gl::Context *context, gl::Error drawElementsIndirect(const gl::Context *context,
GLenum mode, GLenum mode,
......
...@@ -113,8 +113,7 @@ gl::Error ContextNULL::drawElements(const gl::Context *context, ...@@ -113,8 +113,7 @@ gl::Error ContextNULL::drawElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
return gl::NoError(); return gl::NoError();
} }
...@@ -124,8 +123,7 @@ gl::Error ContextNULL::drawElementsInstanced(const gl::Context *context, ...@@ -124,8 +123,7 @@ gl::Error ContextNULL::drawElementsInstanced(const gl::Context *context,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances)
const gl::IndexRange &indexRange)
{ {
return gl::NoError(); return gl::NoError();
} }
...@@ -136,8 +134,7 @@ gl::Error ContextNULL::drawRangeElements(const gl::Context *context, ...@@ -136,8 +134,7 @@ gl::Error ContextNULL::drawRangeElements(const gl::Context *context,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
return gl::NoError(); return gl::NoError();
} }
......
...@@ -57,23 +57,20 @@ class ContextNULL : public ContextImpl ...@@ -57,23 +57,20 @@ class ContextNULL : public ContextImpl
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) override;
const gl::IndexRange &indexRange) override;
gl::Error drawElementsInstanced(const gl::Context *context, gl::Error drawElementsInstanced(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances) override;
const gl::IndexRange &indexRange) override;
gl::Error drawRangeElements(const gl::Context *context, gl::Error drawRangeElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLuint start, GLuint start,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) override;
const gl::IndexRange &indexRange) override;
gl::Error drawArraysIndirect(const gl::Context *context, gl::Error drawArraysIndirect(const gl::Context *context,
GLenum mode, GLenum mode,
const void *indirect) override; const void *indirect) override;
......
...@@ -340,8 +340,7 @@ gl::Error ContextVk::drawElements(const gl::Context *context, ...@@ -340,8 +340,7 @@ gl::Error ContextVk::drawElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return gl::InternalError(); return gl::InternalError();
...@@ -352,8 +351,7 @@ gl::Error ContextVk::drawElementsInstanced(const gl::Context *context, ...@@ -352,8 +351,7 @@ gl::Error ContextVk::drawElementsInstanced(const gl::Context *context,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances)
const gl::IndexRange &indexRange)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
return gl::InternalError(); return gl::InternalError();
...@@ -365,8 +363,7 @@ gl::Error ContextVk::drawRangeElements(const gl::Context *context, ...@@ -365,8 +363,7 @@ gl::Error ContextVk::drawRangeElements(const gl::Context *context,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices)
const gl::IndexRange &indexRange)
{ {
return gl::NoError(); return gl::NoError();
} }
......
...@@ -46,23 +46,20 @@ class ContextVk : public ContextImpl, public ResourceVk ...@@ -46,23 +46,20 @@ class ContextVk : public ContextImpl, public ResourceVk
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) override;
const gl::IndexRange &indexRange) override;
gl::Error drawElementsInstanced(const gl::Context *context, gl::Error drawElementsInstanced(const gl::Context *context,
GLenum mode, GLenum mode,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices,
GLsizei instances, GLsizei instances) override;
const gl::IndexRange &indexRange) override;
gl::Error drawRangeElements(const gl::Context *context, gl::Error drawRangeElements(const gl::Context *context,
GLenum mode, GLenum mode,
GLuint start, GLuint start,
GLuint end, GLuint end,
GLsizei count, GLsizei count,
GLenum type, GLenum type,
const void *indices, const void *indices) override;
const gl::IndexRange &indexRange) override;
gl::Error drawArraysIndirect(const gl::Context *context, gl::Error drawArraysIndirect(const gl::Context *context,
GLenum mode, GLenum mode,
const void *indirect) override; const void *indirect) override;
......
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