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