Commit 46d6c2b6 by Jamie Madill Committed by Commit Bot

D3D: Make some helper methods static.

A couple index data manager and Renderer helper methods didn't need to modify state or use any local member variables, so we can make them static to be more accessible from other parts of the code. BUG=angleproject:1156 Change-Id: I522d0dfd396f0fed7b5087e90dcb70a0f9502a75 Reviewed-on: https://chromium-review.googlesource.com/616782Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent a836b466
......@@ -139,20 +139,25 @@ IndexDataManager::~IndexDataManager()
SafeDelete(mStreamingBufferInt);
}
bool IndexDataManager::usePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled,
GLenum type)
// static
bool IndexDataManager::UsePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled,
GLenum type,
RendererClass rendererClass)
{
// We should never have to deal with primitive restart workaround issue with GL_UNSIGNED_INT
// indices, since we restrict it via MAX_ELEMENT_INDEX.
return (!primitiveRestartFixedIndexEnabled && type == GL_UNSIGNED_SHORT &&
mRendererClass == RENDERER_D3D11);
rendererClass == RENDERER_D3D11);
}
bool IndexDataManager::isStreamingIndexData(const gl::Context *context, GLenum srcType)
// static
bool IndexDataManager::IsStreamingIndexData(const gl::Context *context,
GLenum srcType,
RendererClass rendererClass)
{
const auto &glState = context->getGLState();
bool primitiveRestartWorkaround =
usePrimitiveRestartWorkaround(glState.isPrimitiveRestartEnabled(), srcType);
UsePrimitiveRestartWorkaround(glState.isPrimitiveRestartEnabled(), srcType, rendererClass);
gl::Buffer *glBuffer = glState.getVertexArray()->getElementArrayBuffer().get();
// Case 1: the indices are passed by pointer, which forces the streaming of index data
......@@ -208,7 +213,7 @@ gl::Error IndexDataManager::prepareIndexData(GLenum srcType,
translated->indexRange.vertexIndexCount < static_cast<size_t>(count) ||
translated->indexRange.end == gl::GetPrimitiveRestartIndex(srcType);
bool primitiveRestartWorkaround =
usePrimitiveRestartWorkaround(primitiveRestartFixedIndexEnabled, srcType) &&
UsePrimitiveRestartWorkaround(primitiveRestartFixedIndexEnabled, srcType, mRendererClass) &&
hasPrimitiveRestartIndex;
// We should never have to deal with MAX_UINT indices, since we restrict it via
......
......@@ -68,8 +68,12 @@ class IndexDataManager : angle::NonCopyable
explicit IndexDataManager(BufferFactoryD3D *factory, RendererClass rendererClass);
virtual ~IndexDataManager();
bool usePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled, GLenum type);
bool isStreamingIndexData(const gl::Context *context, GLenum srcType);
static bool UsePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled,
GLenum type,
RendererClass rendererClass);
static bool IsStreamingIndexData(const gl::Context *context,
GLenum srcType,
RendererClass rendererClass);
gl::Error prepareIndexData(GLenum srcType,
GLsizei count,
gl::Buffer *glBuffer,
......
......@@ -293,7 +293,7 @@ Serial RendererD3D::generateSerial()
return mSerialFactory.generate();
}
bool RendererD3D::instancedPointSpritesActive(ProgramD3D *programD3D, GLenum mode) const
bool InstancedPointSpritesActive(ProgramD3D *programD3D, GLenum mode)
{
return programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation() &&
mode == GL_POINTS;
......
......@@ -336,7 +336,6 @@ class RendererD3D : public BufferFactoryD3D
gl::TextureCapsMap *outTextureCaps,
gl::Extensions *outExtensions,
gl::Limitations *outLimitations) const = 0;
virtual bool instancedPointSpritesActive(ProgramD3D *programD3D, GLenum mode) const;
void cleanup();
......@@ -374,6 +373,7 @@ class RendererD3D : public BufferFactoryD3D
};
unsigned int GetBlendSampleMask(const gl::State &glState, int samples);
bool InstancedPointSpritesActive(ProgramD3D *programD3D, GLenum mode);
} // namespace rx
......
......@@ -360,6 +360,34 @@ void GetTriFanIndices(const void *indices,
}
}
bool DrawCallNeedsTranslation(const gl::Context *context, GLenum mode, GLenum type)
{
const auto &glState = context->getGLState();
const auto &vertexArray = glState.getVertexArray();
auto *vertexArray11 = GetImplAs<VertexArray11>(vertexArray);
// 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
// either since we need to simulate them in D3D.
if (vertexArray11->hasDynamicAttrib(context) || mode == GL_LINE_LOOP || mode == GL_TRIANGLE_FAN)
{
return true;
}
ProgramD3D *programD3D = GetImplAs<ProgramD3D>(glState.getProgram());
if (InstancedPointSpritesActive(programD3D, mode))
{
return true;
}
if (type != GL_NONE)
{
// Only non-streaming index data can be directly used to draw since they don't
// need the indices and count informations.
return IndexDataManager::IsStreamingIndexData(context, type, RENDERER_D3D11);
}
return false;
}
const uint32_t ScratchMemoryBufferLifetime = 1000;
} // anonymous namespace
......@@ -1801,7 +1829,7 @@ gl::Error Renderer11::drawElementsImpl(const gl::Context *context,
const auto &data = context->getContextState();
TranslatedIndexData indexInfo;
if (!drawCallNeedsTranslation(context, mode, type))
if (!DrawCallNeedsTranslation(context, mode, type))
{
ANGLE_TRY(applyIndexBuffer(data, nullptr, 0, mode, type, &indexInfo));
ANGLE_TRY(applyVertexBuffer(context, mode, 0, 0, 0, &indexInfo));
......@@ -1891,36 +1919,6 @@ gl::Error Renderer11::drawElementsImpl(const gl::Context *context,
return gl::NoError();
}
bool Renderer11::drawCallNeedsTranslation(const gl::Context *context,
GLenum mode,
GLenum type) const
{
const auto &glState = context->getGLState();
const auto &vertexArray = glState.getVertexArray();
auto *vertexArray11 = GetImplAs<VertexArray11>(vertexArray);
// 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
// either since we need to simulate them in D3D.
if (vertexArray11->hasDynamicAttrib(context) || mode == GL_LINE_LOOP || mode == GL_TRIANGLE_FAN)
{
return true;
}
ProgramD3D *programD3D = GetImplAs<ProgramD3D>(glState.getProgram());
if (instancedPointSpritesActive(programD3D, mode))
{
return true;
}
if (type != GL_NONE)
{
// Only non-streaming index data can be directly used to draw since they don't
// need the indices and count informations.
return mIndexDataManager->isStreamingIndexData(context, type);
}
return false;
}
gl::Error Renderer11::drawArraysIndirectImpl(const gl::Context *context,
GLenum mode,
const void *indirect)
......@@ -1937,7 +1935,7 @@ gl::Error Renderer11::drawArraysIndirectImpl(const gl::Context *context,
Buffer11 *storage = GetImplAs<Buffer11>(drawIndirectBuffer);
uintptr_t offset = reinterpret_cast<uintptr_t>(indirect);
if (!drawCallNeedsTranslation(context, mode, GL_NONE))
if (!DrawCallNeedsTranslation(context, mode, GL_NONE))
{
applyVertexBuffer(context, mode, 0, 0, 0, nullptr);
ID3D11Buffer *buffer = nullptr;
......@@ -1988,7 +1986,7 @@ gl::Error Renderer11::drawElementsIndirectImpl(const gl::Context *context,
uintptr_t offset = reinterpret_cast<uintptr_t>(indirect);
TranslatedIndexData indexInfo;
if (!drawCallNeedsTranslation(context, mode, type))
if (!DrawCallNeedsTranslation(context, mode, type))
{
ANGLE_TRY(applyIndexBuffer(contextState, nullptr, 0, mode, type, &indexInfo));
ANGLE_TRY(applyVertexBuffer(context, mode, 0, 0, 0, &indexInfo));
......
......@@ -546,8 +546,6 @@ class Renderer11 : public RendererD3D
d3d11::ANGLED3D11DeviceType getDeviceType() const;
bool drawCallNeedsTranslation(const gl::Context *context, GLenum mode, GLenum type) const;
HMODULE mD3d11Module;
HMODULE mDxgiModule;
HMODULE mDCompModule;
......
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