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() ...@@ -139,20 +139,25 @@ IndexDataManager::~IndexDataManager()
SafeDelete(mStreamingBufferInt); SafeDelete(mStreamingBufferInt);
} }
bool IndexDataManager::usePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled, // static
GLenum type) bool IndexDataManager::UsePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled,
GLenum type,
RendererClass rendererClass)
{ {
// We should never have to deal with primitive restart workaround issue with GL_UNSIGNED_INT // We should never have to deal with primitive restart workaround issue with GL_UNSIGNED_INT
// indices, since we restrict it via MAX_ELEMENT_INDEX. // indices, since we restrict it via MAX_ELEMENT_INDEX.
return (!primitiveRestartFixedIndexEnabled && type == GL_UNSIGNED_SHORT && 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(); const auto &glState = context->getGLState();
bool primitiveRestartWorkaround = bool primitiveRestartWorkaround =
usePrimitiveRestartWorkaround(glState.isPrimitiveRestartEnabled(), srcType); UsePrimitiveRestartWorkaround(glState.isPrimitiveRestartEnabled(), srcType, rendererClass);
gl::Buffer *glBuffer = glState.getVertexArray()->getElementArrayBuffer().get(); 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
...@@ -208,7 +213,7 @@ gl::Error IndexDataManager::prepareIndexData(GLenum srcType, ...@@ -208,7 +213,7 @@ gl::Error IndexDataManager::prepareIndexData(GLenum srcType,
translated->indexRange.vertexIndexCount < static_cast<size_t>(count) || translated->indexRange.vertexIndexCount < static_cast<size_t>(count) ||
translated->indexRange.end == gl::GetPrimitiveRestartIndex(srcType); translated->indexRange.end == gl::GetPrimitiveRestartIndex(srcType);
bool primitiveRestartWorkaround = bool primitiveRestartWorkaround =
usePrimitiveRestartWorkaround(primitiveRestartFixedIndexEnabled, srcType) && UsePrimitiveRestartWorkaround(primitiveRestartFixedIndexEnabled, srcType, mRendererClass) &&
hasPrimitiveRestartIndex; hasPrimitiveRestartIndex;
// We should never have to deal with MAX_UINT indices, since we restrict it via // We should never have to deal with MAX_UINT indices, since we restrict it via
......
...@@ -68,8 +68,12 @@ class IndexDataManager : angle::NonCopyable ...@@ -68,8 +68,12 @@ class IndexDataManager : angle::NonCopyable
explicit IndexDataManager(BufferFactoryD3D *factory, RendererClass rendererClass); explicit IndexDataManager(BufferFactoryD3D *factory, RendererClass rendererClass);
virtual ~IndexDataManager(); virtual ~IndexDataManager();
bool usePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled, GLenum type); static bool UsePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled,
bool isStreamingIndexData(const gl::Context *context, GLenum srcType); GLenum type,
RendererClass rendererClass);
static bool IsStreamingIndexData(const gl::Context *context,
GLenum srcType,
RendererClass rendererClass);
gl::Error prepareIndexData(GLenum srcType, gl::Error prepareIndexData(GLenum srcType,
GLsizei count, GLsizei count,
gl::Buffer *glBuffer, gl::Buffer *glBuffer,
......
...@@ -293,7 +293,7 @@ Serial RendererD3D::generateSerial() ...@@ -293,7 +293,7 @@ Serial RendererD3D::generateSerial()
return mSerialFactory.generate(); return mSerialFactory.generate();
} }
bool RendererD3D::instancedPointSpritesActive(ProgramD3D *programD3D, GLenum mode) const bool InstancedPointSpritesActive(ProgramD3D *programD3D, GLenum mode)
{ {
return programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation() && return programD3D->usesPointSize() && programD3D->usesInstancedPointSpriteEmulation() &&
mode == GL_POINTS; mode == GL_POINTS;
......
...@@ -336,7 +336,6 @@ class RendererD3D : public BufferFactoryD3D ...@@ -336,7 +336,6 @@ 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;
void cleanup(); void cleanup();
...@@ -374,6 +373,7 @@ class RendererD3D : public BufferFactoryD3D ...@@ -374,6 +373,7 @@ class RendererD3D : public BufferFactoryD3D
}; };
unsigned int GetBlendSampleMask(const gl::State &glState, int samples); unsigned int GetBlendSampleMask(const gl::State &glState, int samples);
bool InstancedPointSpritesActive(ProgramD3D *programD3D, GLenum mode);
} // namespace rx } // namespace rx
......
...@@ -360,6 +360,34 @@ void GetTriFanIndices(const void *indices, ...@@ -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; const uint32_t ScratchMemoryBufferLifetime = 1000;
} // anonymous namespace } // anonymous namespace
...@@ -1801,7 +1829,7 @@ gl::Error Renderer11::drawElementsImpl(const gl::Context *context, ...@@ -1801,7 +1829,7 @@ gl::Error Renderer11::drawElementsImpl(const gl::Context *context,
const auto &data = context->getContextState(); const auto &data = context->getContextState();
TranslatedIndexData indexInfo; TranslatedIndexData indexInfo;
if (!drawCallNeedsTranslation(context, mode, type)) if (!DrawCallNeedsTranslation(context, mode, type))
{ {
ANGLE_TRY(applyIndexBuffer(data, nullptr, 0, mode, type, &indexInfo)); ANGLE_TRY(applyIndexBuffer(data, nullptr, 0, mode, type, &indexInfo));
ANGLE_TRY(applyVertexBuffer(context, mode, 0, 0, 0, &indexInfo)); ANGLE_TRY(applyVertexBuffer(context, mode, 0, 0, 0, &indexInfo));
...@@ -1891,36 +1919,6 @@ gl::Error Renderer11::drawElementsImpl(const gl::Context *context, ...@@ -1891,36 +1919,6 @@ gl::Error Renderer11::drawElementsImpl(const gl::Context *context,
return gl::NoError(); 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, gl::Error Renderer11::drawArraysIndirectImpl(const gl::Context *context,
GLenum mode, GLenum mode,
const void *indirect) const void *indirect)
...@@ -1937,7 +1935,7 @@ gl::Error Renderer11::drawArraysIndirectImpl(const gl::Context *context, ...@@ -1937,7 +1935,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 (!drawCallNeedsTranslation(context, mode, GL_NONE)) if (!DrawCallNeedsTranslation(context, mode, GL_NONE))
{ {
applyVertexBuffer(context, mode, 0, 0, 0, nullptr); applyVertexBuffer(context, mode, 0, 0, 0, nullptr);
ID3D11Buffer *buffer = nullptr; ID3D11Buffer *buffer = nullptr;
...@@ -1988,7 +1986,7 @@ gl::Error Renderer11::drawElementsIndirectImpl(const gl::Context *context, ...@@ -1988,7 +1986,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 (!drawCallNeedsTranslation(context, mode, type)) if (!DrawCallNeedsTranslation(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));
......
...@@ -546,8 +546,6 @@ class Renderer11 : public RendererD3D ...@@ -546,8 +546,6 @@ class Renderer11 : public RendererD3D
d3d11::ANGLED3D11DeviceType getDeviceType() const; d3d11::ANGLED3D11DeviceType getDeviceType() const;
bool drawCallNeedsTranslation(const gl::Context *context, GLenum mode, GLenum type) const;
HMODULE mD3d11Module; HMODULE mD3d11Module;
HMODULE mDxgiModule; HMODULE mDxgiModule;
HMODULE mDCompModule; 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