Commit af4ffe0a by Jamie Madill Committed by Commit Bot

D3D11: Implement dirty bits for texture updates.

BUG=angleproject:1387 Change-Id: I5f759c3dc60b53a5d4f8a1dd1f4a1d3d5330bfda Reviewed-on: https://chromium-review.googlesource.com/648487 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 92515f44
......@@ -160,7 +160,7 @@ class Display final : angle::NonCopyable
bool isRobustResourceInitEnabled() const;
const gl::Context *getProxyContext() const { return mProxyContext.get(); }
gl::Context *getProxyContext() const { return mProxyContext.get(); }
private:
Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDevice);
......
......@@ -2293,8 +2293,6 @@ void State::setObjectDirty(GLenum target)
break;
case GL_TEXTURE:
case GL_SAMPLER:
mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
break;
case GL_PROGRAM:
mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS);
......
......@@ -706,11 +706,11 @@ GLuint ProgramD3D::getUsedSamplerRange(gl::SamplerType type) const
}
}
void ProgramD3D::updateSamplerMapping()
ProgramD3D::SamplerMapping ProgramD3D::updateSamplerMapping()
{
if (!mDirtySamplerMapping)
{
return;
return SamplerMapping::WasClean;
}
mDirtySamplerMapping = false;
......@@ -771,6 +771,8 @@ void ProgramD3D::updateSamplerMapping()
}
}
}
return SamplerMapping::WasDirty;
}
gl::LinkResult ProgramD3D::load(const gl::Context *context,
......
......@@ -163,7 +163,14 @@ class ProgramD3D : public ProgramImpl
const gl::Caps &caps) const;
GLenum getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const;
GLuint getUsedSamplerRange(gl::SamplerType type) const;
void updateSamplerMapping();
enum SamplerMapping
{
WasDirty,
WasClean,
};
SamplerMapping updateSamplerMapping();
bool usesPointSize() const { return mUsesPointSize; }
bool usesPointSpriteEmulation() const;
......
......@@ -694,10 +694,17 @@ void StateManager11::syncState(const gl::Context *context, const gl::State::Dirt
case gl::State::DIRTY_BIT_VERTEX_ARRAY_BINDING:
invalidateVertexBuffer();
break;
case gl::State::DIRTY_BIT_TEXTURE_BINDINGS:
invalidateTexturesAndSamplers();
break;
case gl::State::DIRTY_BIT_SAMPLER_BINDINGS:
invalidateTexturesAndSamplers();
break;
case gl::State::DIRTY_BIT_PROGRAM_EXECUTABLE:
{
invalidateVertexBuffer();
invalidateRenderTarget(context);
invalidateTexturesAndSamplers();
gl::VertexArray *vao = state.getVertexArray();
if (mIsMultiviewEnabled && vao != nullptr)
{
......@@ -1168,6 +1175,8 @@ void StateManager11::invalidateEverything(const gl::Context *context)
mAppliedIBOffset = 0;
mLastFirstVertex.reset();
invalidateTexturesAndSamplers();
}
void StateManager11::invalidateVertexBuffer()
......@@ -1183,6 +1192,11 @@ void StateManager11::invalidateViewport(const gl::Context *context)
mInternalDirtyBits.set(DIRTY_BIT_VIEWPORT_STATE);
}
void StateManager11::invalidateTexturesAndSamplers()
{
mInternalDirtyBits.set(DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE);
}
void StateManager11::setOneTimeRenderTarget(const gl::Context *context,
ID3D11RenderTargetView *rtv,
ID3D11DepthStencilView *dsv)
......@@ -1581,7 +1595,10 @@ gl::Error StateManager11::updateState(const gl::Context *context, GLenum drawMod
auto *programD3D = GetImplAs<ProgramD3D>(glState.getProgram());
// TODO(jmadill): Use dirty bits.
programD3D->updateSamplerMapping();
if (programD3D->updateSamplerMapping() == ProgramD3D::SamplerMapping::WasDirty)
{
invalidateTexturesAndSamplers();
}
// TODO(jmadill): Use dirty bits.
ANGLE_TRY(generateSwizzles(context));
......@@ -1640,15 +1657,15 @@ gl::Error StateManager11::updateState(const gl::Context *context, GLenum drawMod
case DIRTY_BIT_DEPTH_STENCIL_STATE:
ANGLE_TRY(syncDepthStencilState(glState));
break;
case DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE:
ANGLE_TRY(syncTextures(context));
break;
default:
UNREACHABLE();
break;
}
}
// TODO(jmadill): Use dirty bits.
ANGLE_TRY(syncTextures(context));
// This must happen after viewport sync, because the viewport affects builtin uniforms.
// TODO(jmadill): Use dirty bits.
ANGLE_TRY(programD3D->applyUniforms());
......
......@@ -150,6 +150,7 @@ class StateManager11 final : angle::NonCopyable
void invalidateVertexBuffer();
void invalidateEverything(const gl::Context *context);
void invalidateViewport(const gl::Context *context);
void invalidateTexturesAndSamplers();
// Called from VertexArray11::updateVertexAttribStorage.
void invalidateCurrentValueAttrib(size_t attribIndex);
......@@ -275,6 +276,7 @@ class StateManager11 final : angle::NonCopyable
DIRTY_BIT_RASTERIZER_STATE,
DIRTY_BIT_BLEND_STATE,
DIRTY_BIT_DEPTH_STENCIL_STATE,
DIRTY_BIT_TEXTURE_AND_SAMPLER_STATE,
DIRTY_BIT_INVALID,
DIRTY_BIT_MAX = DIRTY_BIT_INVALID,
};
......
......@@ -5,6 +5,7 @@
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
......@@ -216,20 +217,10 @@ TEST_P(PbufferTest, BindTexImage)
// size information is correctly updated.
TEST_P(PbufferTest, TextureSizeReset)
{
if (!mSupportsPbuffers)
{
std::cout << "Test skipped because Pbuffers are not supported." << std::endl;
return;
}
ANGLE_SKIP_TEST_IF(!mSupportsPbuffers);
ANGLE_SKIP_TEST_IF(!mSupportsBindTexImage);
if (!mSupportsBindTexImage)
{
std::cout << "Test skipped because Pbuffer does not support binding to RGBA textures." << std::endl;
return;
}
GLuint texture = 0;
glGenTextures(1, &texture);
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
......@@ -241,14 +232,15 @@ TEST_P(PbufferTest, TextureSizeReset)
glUniform1i(mTextureUniformLocation, 0);
// Fill the texture with white pixels
std::vector<GLubyte> whitePixels(mPbufferSize * mPbufferSize * 4, 255);
std::vector<GLColor> whitePixels(mPbufferSize * mPbufferSize, GLColor::white);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast<GLsizei>(mPbufferSize),
static_cast<GLsizei>(mPbufferSize), 0, GL_RGBA, GL_UNSIGNED_BYTE, &whitePixels[0]);
static_cast<GLsizei>(mPbufferSize), 0, GL_RGBA, GL_UNSIGNED_BYTE,
whitePixels.data());
EXPECT_GL_NO_ERROR();
// Draw the white texture and verify that the pixels are correct
drawQuad(mTextureProgram, "position", 0.5f);
EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
// Bind the EGL surface and draw with it, results are undefined since nothing has
// been written to it
......@@ -260,13 +252,13 @@ TEST_P(PbufferTest, TextureSizeReset)
// Clear the back buffer to a unique color (green)
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
// Unbind the EGL surface and try to draw with the texture again, the texture's size should
// now be zero and incomplete so the back buffer should be black
eglReleaseTexImage(window->getDisplay(), mPbuffer, EGL_BACK_BUFFER);
drawQuad(mTextureProgram, "position", 0.5f);
EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
}
// Bind a Pbuffer, redefine the texture, and verify it renders correctly
......
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