Commit 97ee6548 by Jamie Madill Committed by Commit Bot

Shunt more code to StateManager11.

Previously the Renderer11 would call directly into the state manager sync methods. Instead make a single updateState method, and make several state sync methods private to the manager. Also rename them to clarify they're for syncing state, not for direct use. BUG=angleproject:1156 Change-Id: I94880a744e7ade3895fa2a312a2436ba4ef38dba Reviewed-on: https://chromium-review.googlesource.com/529705Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent fb05bcba
......@@ -204,8 +204,8 @@ LinkResult MemoryProgramCache::Deserialize(const Context *context,
"All bits of DrawBufferMask can be contained in an uint32_t");
state->mActiveOutputVariables = stream.readInt<uint32_t>();
unsigned int low = stream.readInt<unsigned int>();
unsigned int high = stream.readInt<unsigned int>();
unsigned int low = stream.readInt<unsigned int>();
unsigned int high = stream.readInt<unsigned int>();
state->mSamplerUniformRange = RangeUI(low, high);
unsigned int samplerCount = stream.readInt<unsigned int>();
......
......@@ -54,43 +54,6 @@ void RendererD3D::cleanup()
mIncompleteTextures.clear();
}
unsigned int RendererD3D::GetBlendSampleMask(const gl::ContextState &data, int samples)
{
const auto &glState = data.getState();
unsigned int mask = 0;
if (glState.isSampleCoverageEnabled())
{
GLfloat coverageValue = glState.getSampleCoverageValue();
if (coverageValue != 0)
{
float threshold = 0.5f;
for (int i = 0; i < samples; ++i)
{
mask <<= 1;
if ((i + 1) * coverageValue >= threshold)
{
threshold += 1.0f;
mask |= 1;
}
}
}
bool coverageInvert = glState.getSampleCoverageInvert();
if (coverageInvert)
{
mask = ~mask;
}
}
else
{
mask = 0xFFFFFFFF;
}
return mask;
}
// For each Direct3D sampler of either the pixel or vertex stage,
// looks up the corresponding OpenGL texture image unit and texture type,
// and sets the texture and its addressing/filtering state (or NULL when inactive).
......@@ -385,4 +348,41 @@ bool RendererD3D::isRobustResourceInitEnabled() const
return mDisplay->isRobustResourceInitEnabled();
}
unsigned int GetBlendSampleMask(const gl::ContextState &data, int samples)
{
const auto &glState = data.getState();
unsigned int mask = 0;
if (glState.isSampleCoverageEnabled())
{
GLfloat coverageValue = glState.getSampleCoverageValue();
if (coverageValue != 0)
{
float threshold = 0.5f;
for (int i = 0; i < samples; ++i)
{
mask <<= 1;
if ((i + 1) * coverageValue >= threshold)
{
threshold += 1.0f;
mask |= 1;
}
}
}
bool coverageInvert = glState.getSampleCoverageInvert();
if (coverageInvert)
{
mask = ~mask;
}
}
else
{
mask = 0xFFFFFFFF;
}
return mask;
}
} // namespace rx
......@@ -293,7 +293,6 @@ class RendererD3D : public BufferFactoryD3D
void cleanup();
static unsigned int GetBlendSampleMask(const gl::ContextState &data, int samples);
// dirtyPointer is a special value that will make the comparison with any valid pointer fail and force the renderer to re-apply the state.
gl::Error applyTextures(GLImplFactory *implFactory, const gl::ContextState &data);
......@@ -338,6 +337,8 @@ class RendererD3D : public BufferFactoryD3D
angle::WorkerThreadPool mWorkerThreadPool;
};
unsigned int GetBlendSampleMask(const gl::ContextState &data, int samples);
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_RENDERERD3D_H_
......@@ -1653,58 +1653,6 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data,
return gl::NoError();
}
gl::Error Renderer11::updateState(const gl::Context *context, GLenum drawMode)
{
const auto &data = context->getContextState();
const auto &glState = data.getState();
// Applies the render target surface, depth stencil surface, viewport rectangle and
// scissor rectangle to the renderer
gl::Framebuffer *framebuffer = glState.getDrawFramebuffer();
ASSERT(framebuffer && !framebuffer->hasAnyDirtyBit() && framebuffer->cachedComplete());
ANGLE_TRY(mStateManager.syncFramebuffer(context, framebuffer));
// Set the present path state
auto firstColorAttachment = framebuffer->getFirstColorbuffer();
const bool presentPathFastActive = UsePresentPathFast(this, firstColorAttachment);
mStateManager.updatePresentPath(presentPathFastActive, firstColorAttachment);
// Setting viewport state
mStateManager.setViewport(&data.getCaps(), glState.getViewport(), glState.getNearPlane(),
glState.getFarPlane());
// Setting scissor state
mStateManager.setScissorRectangle(glState.getScissor(), glState.isScissorTestEnabled());
// Applying rasterizer state to D3D11 device
// Since framebuffer->getSamples will return the original samples which may be different with
// the sample counts that we set in render target view, here we use renderTarget->getSamples to
// get the actual samples.
GLsizei samples = 0;
if (firstColorAttachment)
{
ASSERT(firstColorAttachment->isAttached());
RenderTarget11 *renderTarget = nullptr;
ANGLE_TRY(firstColorAttachment->getRenderTarget(&renderTarget));
samples = renderTarget->getSamples();
}
gl::RasterizerState rasterizer = glState.getRasterizerState();
rasterizer.pointDrawMode = (drawMode == GL_POINTS);
rasterizer.multiSample = (samples != 0);
ANGLE_TRY(mStateManager.setRasterizerState(rasterizer));
// Setting blend state
unsigned int mask = GetBlendSampleMask(data, samples);
ANGLE_TRY(mStateManager.setBlendState(framebuffer, glState.getBlendState(),
glState.getBlendColor(), mask));
// Setting depth stencil state
ANGLE_TRY(mStateManager.setDepthStencilState(glState));
return gl::NoError();
}
bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count, bool usesPointSize)
{
D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED;
......@@ -4622,7 +4570,7 @@ gl::Error Renderer11::genericDrawElements(const gl::Context *context,
return gl::NoError();
}
ANGLE_TRY(updateState(context, mode));
ANGLE_TRY(mStateManager.updateState(context, mode));
TranslatedIndexData indexInfo;
indexInfo.indexRange = indexRange;
......@@ -4670,7 +4618,7 @@ gl::Error Renderer11::genericDrawArrays(const gl::Context *context,
return gl::NoError();
}
ANGLE_TRY(updateState(context, mode));
ANGLE_TRY(mStateManager.updateState(context, mode));
ANGLE_TRY(applyTransformFeedbackBuffers(data));
ANGLE_TRY(applyVertexBuffer(glState, mode, first, count, instances, nullptr));
ANGLE_TRY(applyTextures(context->getImplementation(), data));
......@@ -4705,7 +4653,7 @@ gl::Error Renderer11::genericDrawIndirect(const gl::Context *context,
ANGLE_TRY(generateSwizzles(data));
applyPrimitiveType(mode, 0, usesPointSize);
ANGLE_TRY(updateState(context, mode));
ANGLE_TRY(mStateManager.updateState(context, mode));
ANGLE_TRY(applyTransformFeedbackBuffers(data));
ASSERT(!glState.isTransformFeedbackActiveUnpaused());
ANGLE_TRY(applyTextures(context->getImplementation(), data));
......
......@@ -148,8 +148,6 @@ class Renderer11 : public RendererD3D
const std::vector<GLint> &vertexUniformBuffers,
const std::vector<GLint> &fragmentUniformBuffers) override;
gl::Error updateState(const gl::Context *context, GLenum drawMode);
bool applyPrimitiveType(GLenum mode, GLsizei count, bool usesPointSize);
gl::Error applyUniforms(const ProgramD3D &programD3D,
GLenum drawMode,
......
......@@ -10,11 +10,12 @@
#include "common/bitset_utils.h"
#include "common/utilities.h"
#include "libANGLE/Context.h"
#include "libANGLE/Query.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/renderer/d3d/d3d11/Framebuffer11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
namespace rx
{
......@@ -235,8 +236,8 @@ void StateManager11::setViewportBounds(const int width, const int height)
}
}
void StateManager11::updatePresentPath(bool presentPathFastActive,
const gl::FramebufferAttachment *framebufferAttachment)
void StateManager11::syncPresentPath(bool presentPathFastActive,
const gl::FramebufferAttachment *framebufferAttachment)
{
const int colorBufferHeight =
framebufferAttachment ? framebufferAttachment->getSize().height : 0;
......@@ -500,10 +501,10 @@ void StateManager11::syncState(const gl::State &state, const gl::State::DirtyBit
// TODO(jmadill): Input layout and vertex buffer state.
}
gl::Error StateManager11::setBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask)
gl::Error StateManager11::syncBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask)
{
if (!mBlendStateIsDirty && sampleMask == mCurSampleMask)
{
......@@ -547,7 +548,7 @@ gl::Error StateManager11::setBlendState(const gl::Framebuffer *framebuffer,
return gl::NoError();
}
gl::Error StateManager11::setDepthStencilState(const gl::State &glState)
gl::Error StateManager11::syncDepthStencilState(const gl::State &glState)
{
const auto &fbo = *glState.getDrawFramebuffer();
......@@ -622,7 +623,7 @@ gl::Error StateManager11::setDepthStencilState(const gl::State &glState)
return gl::NoError();
}
gl::Error StateManager11::setRasterizerState(const gl::RasterizerState &rasterState)
gl::Error StateManager11::syncRasterizerState(const gl::RasterizerState &rasterState)
{
// TODO: Remove pointDrawMode and multiSample from gl::RasterizerState.
if (!mRasterizerStateIsDirty && rasterState.pointDrawMode == mCurRasterState.pointDrawMode &&
......@@ -666,7 +667,7 @@ gl::Error StateManager11::setRasterizerState(const gl::RasterizerState &rasterSt
return gl::NoError();
}
void StateManager11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled)
void StateManager11::syncScissorRectangle(const gl::Rectangle &scissor, bool enabled)
{
if (!mScissorStateIsDirty)
return;
......@@ -693,10 +694,10 @@ void StateManager11::setScissorRectangle(const gl::Rectangle &scissor, bool enab
mScissorStateIsDirty = false;
}
void StateManager11::setViewport(const gl::Caps *caps,
const gl::Rectangle &viewport,
float zNear,
float zFar)
void StateManager11::syncViewport(const gl::Caps *caps,
const gl::Rectangle &viewport,
float zNear,
float zFar)
{
if (!mViewportStateIsDirty)
return;
......@@ -1233,4 +1234,55 @@ void StateManager11::setSingleVertexBuffer(const d3d11::Buffer *buffer, UINT str
}
}
gl::Error StateManager11::updateState(const gl::Context *context, GLenum drawMode)
{
const auto &data = context->getContextState();
const auto &glState = data.getState();
// Applies the render target surface, depth stencil surface, viewport rectangle and
// scissor rectangle to the renderer
gl::Framebuffer *framebuffer = glState.getDrawFramebuffer();
ASSERT(framebuffer && !framebuffer->hasAnyDirtyBit() && framebuffer->cachedComplete());
ANGLE_TRY(syncFramebuffer(context, framebuffer));
// Set the present path state
auto firstColorAttachment = framebuffer->getFirstColorbuffer();
const bool presentPathFastActive = UsePresentPathFast(mRenderer, firstColorAttachment);
syncPresentPath(presentPathFastActive, firstColorAttachment);
// Setting viewport state
syncViewport(&data.getCaps(), glState.getViewport(), glState.getNearPlane(),
glState.getFarPlane());
// Setting scissor state
syncScissorRectangle(glState.getScissor(), glState.isScissorTestEnabled());
// Applying rasterizer state to D3D11 device
// Since framebuffer->getSamples will return the original samples which may be different with
// the sample counts that we set in render target view, here we use renderTarget->getSamples to
// get the actual samples.
GLsizei samples = 0;
if (firstColorAttachment)
{
ASSERT(firstColorAttachment->isAttached());
RenderTarget11 *renderTarget = nullptr;
ANGLE_TRY(firstColorAttachment->getRenderTarget(&renderTarget));
samples = renderTarget->getSamples();
}
gl::RasterizerState rasterizer = glState.getRasterizerState();
rasterizer.pointDrawMode = (drawMode == GL_POINTS);
rasterizer.multiSample = (samples != 0);
ANGLE_TRY(syncRasterizerState(rasterizer));
// Setting blend state
unsigned int mask = GetBlendSampleMask(data, samples);
ANGLE_TRY(syncBlendState(framebuffer, glState.getBlendState(), glState.getBlendColor(), mask));
// Setting depth stencil state
ANGLE_TRY(syncDepthStencilState(glState));
return gl::NoError();
}
} // namespace rx
......@@ -57,22 +57,6 @@ class StateManager11 final : angle::NonCopyable
void deinitialize();
void syncState(const gl::State &state, const gl::State::DirtyBits &dirtyBits);
gl::Error setBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask);
gl::Error setDepthStencilState(const gl::State &glState);
gl::Error setRasterizerState(const gl::RasterizerState &rasterState);
void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
void setViewport(const gl::Caps *caps, const gl::Rectangle &viewport, float zNear, float zFar);
void updatePresentPath(bool presentPathFastActive,
const gl::FramebufferAttachment *framebufferAttachment);
const dx_VertexConstants11 &getVertexConstants() const { return mVertexConstants; }
const dx_PixelConstants11 &getPixelConstants() const { return mPixelConstants; }
const dx_ComputeConstants11 &getComputeConstants() const { return mComputeConstants; }
......@@ -86,8 +70,6 @@ class StateManager11 final : angle::NonCopyable
ID3D11ShaderResourceView *srv);
gl::Error clearTextures(gl::SamplerType samplerType, size_t rangeStart, size_t rangeEnd);
gl::Error syncFramebuffer(const gl::Context *context, gl::Framebuffer *framebuffer);
void invalidateRenderTarget();
void invalidateBoundViews();
void invalidateVertexBuffer();
......@@ -119,6 +101,8 @@ class StateManager11 final : angle::NonCopyable
void setSingleVertexBuffer(const d3d11::Buffer *buffer, UINT stride, UINT offset);
gl::Error updateState(const gl::Context *context, GLenum drawMode);
private:
void setViewportBounds(const int width, const int height);
void unsetConflictingSRVs(gl::SamplerType shaderType,
......@@ -127,6 +111,24 @@ class StateManager11 final : angle::NonCopyable
void unsetConflictingAttachmentResources(const gl::FramebufferAttachment *attachment,
ID3D11Resource *resource);
gl::Error syncBlendState(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState,
const gl::ColorF &blendColor,
unsigned int sampleMask);
gl::Error syncDepthStencilState(const gl::State &glState);
gl::Error syncRasterizerState(const gl::RasterizerState &rasterState);
void syncScissorRectangle(const gl::Rectangle &scissor, bool enabled);
void syncViewport(const gl::Caps *caps, const gl::Rectangle &viewport, float zNear, float zFar);
void syncPresentPath(bool presentPathFastActive,
const gl::FramebufferAttachment *framebufferAttachment);
gl::Error syncFramebuffer(const gl::Context *context, gl::Framebuffer *framebuffer);
Renderer11 *mRenderer;
// Blend State
......
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