Skip to content

Commit

Permalink
Revert of Optimize GLES2DecoderImpl::ApplyDirtyState. (https://codere…
Browse files Browse the repository at this point in the history
…view.chromium.org/245923008/)

Reason for revert:
Failing compile on win64 debug waterfall bot

gpu\command_buffer\service\gles2_cmd_decoder_unittest.cc : fatalerror C1128: number of sections exceeded object file format limit : compile with /bigobj

link: http://build.chromium.org/p/chromium.win/builders/Win%20x64%20Builder%20%28dbg%29/builds/7743

Original issue's description:
> Optimize GLES2DecoderImpl::ApplyDirtyState.
> 
> ApplyDirtyState can on average 30% of the time of GLES2
> draw calls.  It previously set Color, Depth, Stencil masks
> and several enables without checking if they changed.
> 
> This change caches values used in ApplyDirtyState among
> other places, and adds ContextState methods for setting
> state with cache checks.
> 
> New cached state aware Set methods:
>  * ContextState::SetDeviceCapabilityState
>  * ContextState::SetDeviceColorMask
>  * ContextState::SetDeviceDepthMask
>  * ContextState::SetDeviceStencilMaskSeparate
> 
> Testing:
>  * gpu_unit tests now run both with cache on and off (ignore_cached_state_for_test = true)
>    to validate behavior independent of cache layering.
>  * New tests specific for caching behavior:
>  ** GLES2DecoderManualInitTest.ContextStateCapabilityCaching
>  ** GLES2DecoderManualInitTest.CachedColorMask
>  ** GLES2DecoderManualInitTest.CachedDepthMask
>  ** GLES2DecoderManualInitTest.CachedStencilMask
> 
> BUG=347364
> 
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=267450

TBR=piman@chromium.org,jbates@chromium.org,oetuaho@nvidia.com,vmiura@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=347364

Review URL: https://codereview.chromium.org/262793002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267465 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tapted@chromium.org committed May 1, 2014
1 parent 6d0431a commit 6781638
Show file tree
Hide file tree
Showing 17 changed files with 1,191 additions and 1,821 deletions.
221 changes: 57 additions & 164 deletions gpu/command_buffer/build_gles2_cmd_buffer.py

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions gpu/command_buffer/service/context_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace gles2 {

namespace {

static void EnableDisable(GLenum pname, bool enable) {
void EnableDisable(GLenum pname, bool enable) {
if (enable) {
glEnable(pname);
} else {
Expand Down Expand Up @@ -92,7 +92,6 @@ ContextState::ContextState(FeatureInfo* feature_info,
Logger* logger)
: active_texture_unit(0),
pack_reverse_row_order(false),
ignore_cached_state(false),
fbo_binding_for_scissor_workaround_dirty_(false),
feature_info_(feature_info),
error_state_(ErrorState::Create(error_state_client, logger)) {
Expand Down
43 changes: 0 additions & 43 deletions gpu/command_buffer/service/context_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ struct GPU_EXPORT ContextState {

void Initialize();

void SetIgnoreCachedStateForTest(bool ignore) {
ignore_cached_state = ignore;
}

void RestoreState(const ContextState* prev_state) const;
void InitCapabilities(const ContextState* prev_state) const;
void InitState(const ContextState* prev_state) const;
Expand All @@ -130,44 +126,6 @@ struct GPU_EXPORT ContextState {
GLenum pname, GLfloat* params, GLsizei* num_written) const;
bool GetEnabled(GLenum cap) const;

inline void SetDeviceColorMask(GLboolean red,
GLboolean green,
GLboolean blue,
GLboolean alpha) {
if (cached_color_mask_red == red && cached_color_mask_green == green &&
cached_color_mask_blue == blue && cached_color_mask_alpha == alpha &&
!ignore_cached_state)
return;
cached_color_mask_red = red;
cached_color_mask_green = green;
cached_color_mask_blue = blue;
cached_color_mask_alpha = alpha;
glColorMask(red, green, blue, alpha);
}

inline void SetDeviceDepthMask(GLboolean mask) {
if (cached_depth_mask == mask && !ignore_cached_state)
return;
cached_depth_mask = mask;
glDepthMask(mask);
}

inline void SetDeviceStencilMaskSeparate(GLenum op, GLuint mask) {
if (op == GL_FRONT) {
if (cached_stencil_front_writemask == mask && !ignore_cached_state)
return;
cached_stencil_front_writemask = mask;
} else if (op == GL_BACK) {
if (cached_stencil_back_writemask == mask && !ignore_cached_state)
return;
cached_stencil_back_writemask = mask;
} else {
NOTREACHED();
return;
}
glStencilMaskSeparate(op, mask);
}

ErrorState* GetErrorState();

#include "gpu/command_buffer/service/context_state_autogen.h"
Expand Down Expand Up @@ -204,7 +162,6 @@ struct GPU_EXPORT ContextState {
QueryMap current_queries;

bool pack_reverse_row_order;
bool ignore_cached_state;

mutable bool fbo_binding_for_scissor_workaround_dirty_;
FeatureInfo* feature_info_;
Expand Down
74 changes: 0 additions & 74 deletions gpu/command_buffer/service/context_state_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,14 @@
struct EnableFlags {
EnableFlags();
bool blend;
bool cached_blend;
bool cull_face;
bool cached_cull_face;
bool depth_test;
bool cached_depth_test;
bool dither;
bool cached_dither;
bool polygon_offset_fill;
bool cached_polygon_offset_fill;
bool sample_alpha_to_coverage;
bool cached_sample_alpha_to_coverage;
bool sample_coverage;
bool cached_sample_coverage;
bool scissor_test;
bool cached_scissor_test;
bool stencil_test;
bool cached_stencil_test;
};

GLfloat blend_color_red;
Expand All @@ -51,17 +42,12 @@ GLfloat color_clear_alpha;
GLclampf depth_clear;
GLint stencil_clear;
GLboolean color_mask_red;
GLboolean cached_color_mask_red;
GLboolean color_mask_green;
GLboolean cached_color_mask_green;
GLboolean color_mask_blue;
GLboolean cached_color_mask_blue;
GLboolean color_mask_alpha;
GLboolean cached_color_mask_alpha;
GLenum cull_mode;
GLenum depth_func;
GLboolean depth_mask;
GLboolean cached_depth_mask;
GLclampf z_near;
GLclampf z_far;
GLenum front_face;
Expand All @@ -85,9 +71,7 @@ GLenum stencil_back_func;
GLint stencil_back_ref;
GLuint stencil_back_mask;
GLuint stencil_front_writemask;
GLuint cached_stencil_front_writemask;
GLuint stencil_back_writemask;
GLuint cached_stencil_back_writemask;
GLenum stencil_front_fail_op;
GLenum stencil_front_z_fail_op;
GLenum stencil_front_z_pass_op;
Expand All @@ -99,62 +83,4 @@ GLint viewport_y;
GLsizei viewport_width;
GLsizei viewport_height;

inline void SetDeviceCapabilityState(GLenum cap, bool enable) {
switch (cap) {
case GL_BLEND:
if (enable_flags.cached_blend == enable && !ignore_cached_state)
return;
enable_flags.cached_blend = enable;
break;
case GL_CULL_FACE:
if (enable_flags.cached_cull_face == enable && !ignore_cached_state)
return;
enable_flags.cached_cull_face = enable;
break;
case GL_DEPTH_TEST:
if (enable_flags.cached_depth_test == enable && !ignore_cached_state)
return;
enable_flags.cached_depth_test = enable;
break;
case GL_DITHER:
if (enable_flags.cached_dither == enable && !ignore_cached_state)
return;
enable_flags.cached_dither = enable;
break;
case GL_POLYGON_OFFSET_FILL:
if (enable_flags.cached_polygon_offset_fill == enable &&
!ignore_cached_state)
return;
enable_flags.cached_polygon_offset_fill = enable;
break;
case GL_SAMPLE_ALPHA_TO_COVERAGE:
if (enable_flags.cached_sample_alpha_to_coverage == enable &&
!ignore_cached_state)
return;
enable_flags.cached_sample_alpha_to_coverage = enable;
break;
case GL_SAMPLE_COVERAGE:
if (enable_flags.cached_sample_coverage == enable && !ignore_cached_state)
return;
enable_flags.cached_sample_coverage = enable;
break;
case GL_SCISSOR_TEST:
if (enable_flags.cached_scissor_test == enable && !ignore_cached_state)
return;
enable_flags.cached_scissor_test = enable;
break;
case GL_STENCIL_TEST:
if (enable_flags.cached_stencil_test == enable && !ignore_cached_state)
return;
enable_flags.cached_stencil_test = enable;
break;
default:
NOTREACHED();
return;
}
if (enable)
glEnable(cap);
else
glDisable(cap);
}
#endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_AUTOGEN_H_
124 changes: 48 additions & 76 deletions gpu/command_buffer/service/context_state_impl_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,14 @@

ContextState::EnableFlags::EnableFlags()
: blend(false),
cached_blend(false),
cull_face(false),
cached_cull_face(false),
depth_test(false),
cached_depth_test(false),
dither(true),
cached_dither(true),
polygon_offset_fill(false),
cached_polygon_offset_fill(false),
sample_alpha_to_coverage(false),
cached_sample_alpha_to_coverage(false),
sample_coverage(false),
cached_sample_coverage(false),
scissor_test(false),
cached_scissor_test(false),
stencil_test(false),
cached_stencil_test(false) {
stencil_test(false) {
}

void ContextState::Initialize() {
Expand All @@ -51,17 +42,12 @@ void ContextState::Initialize() {
depth_clear = 1.0f;
stencil_clear = 0;
color_mask_red = true;
cached_color_mask_red = true;
color_mask_green = true;
cached_color_mask_green = true;
color_mask_blue = true;
cached_color_mask_blue = true;
color_mask_alpha = true;
cached_color_mask_alpha = true;
cull_mode = GL_BACK;
depth_func = GL_LESS;
depth_mask = true;
cached_depth_mask = true;
z_near = 0.0f;
z_far = 1.0f;
front_face = GL_CCW;
Expand All @@ -85,9 +71,7 @@ void ContextState::Initialize() {
stencil_back_ref = 0;
stencil_back_mask = 0xFFFFFFFFU;
stencil_front_writemask = 0xFFFFFFFFU;
cached_stencil_front_writemask = 0xFFFFFFFFU;
stencil_back_writemask = 0xFFFFFFFFU;
cached_stencil_back_writemask = 0xFFFFFFFFU;
stencil_front_fail_op = GL_KEEP;
stencil_front_z_fail_op = GL_KEEP;
stencil_front_z_pass_op = GL_KEEP;
Expand All @@ -102,45 +86,39 @@ void ContextState::Initialize() {

void ContextState::InitCapabilities(const ContextState* prev_state) const {
if (prev_state) {
if (prev_state->enable_flags.cached_blend != enable_flags.cached_blend)
EnableDisable(GL_BLEND, enable_flags.cached_blend);
if (prev_state->enable_flags.cached_cull_face !=
enable_flags.cached_cull_face)
EnableDisable(GL_CULL_FACE, enable_flags.cached_cull_face);
if (prev_state->enable_flags.cached_depth_test !=
enable_flags.cached_depth_test)
EnableDisable(GL_DEPTH_TEST, enable_flags.cached_depth_test);
if (prev_state->enable_flags.cached_dither != enable_flags.cached_dither)
EnableDisable(GL_DITHER, enable_flags.cached_dither);
if (prev_state->enable_flags.cached_polygon_offset_fill !=
enable_flags.cached_polygon_offset_fill)
EnableDisable(GL_POLYGON_OFFSET_FILL,
enable_flags.cached_polygon_offset_fill);
if (prev_state->enable_flags.cached_sample_alpha_to_coverage !=
enable_flags.cached_sample_alpha_to_coverage)
if (prev_state->enable_flags.blend != enable_flags.blend)
EnableDisable(GL_BLEND, enable_flags.blend);
if (prev_state->enable_flags.cull_face != enable_flags.cull_face)
EnableDisable(GL_CULL_FACE, enable_flags.cull_face);
if (prev_state->enable_flags.depth_test != enable_flags.depth_test)
EnableDisable(GL_DEPTH_TEST, enable_flags.depth_test);
if (prev_state->enable_flags.dither != enable_flags.dither)
EnableDisable(GL_DITHER, enable_flags.dither);
if (prev_state->enable_flags.polygon_offset_fill !=
enable_flags.polygon_offset_fill)
EnableDisable(GL_POLYGON_OFFSET_FILL, enable_flags.polygon_offset_fill);
if (prev_state->enable_flags.sample_alpha_to_coverage !=
enable_flags.sample_alpha_to_coverage)
EnableDisable(GL_SAMPLE_ALPHA_TO_COVERAGE,
enable_flags.cached_sample_alpha_to_coverage);
if (prev_state->enable_flags.cached_sample_coverage !=
enable_flags.cached_sample_coverage)
EnableDisable(GL_SAMPLE_COVERAGE, enable_flags.cached_sample_coverage);
if (prev_state->enable_flags.cached_scissor_test !=
enable_flags.cached_scissor_test)
EnableDisable(GL_SCISSOR_TEST, enable_flags.cached_scissor_test);
if (prev_state->enable_flags.cached_stencil_test !=
enable_flags.cached_stencil_test)
EnableDisable(GL_STENCIL_TEST, enable_flags.cached_stencil_test);
enable_flags.sample_alpha_to_coverage);
if (prev_state->enable_flags.sample_coverage !=
enable_flags.sample_coverage)
EnableDisable(GL_SAMPLE_COVERAGE, enable_flags.sample_coverage);
if (prev_state->enable_flags.scissor_test != enable_flags.scissor_test)
EnableDisable(GL_SCISSOR_TEST, enable_flags.scissor_test);
if (prev_state->enable_flags.stencil_test != enable_flags.stencil_test)
EnableDisable(GL_STENCIL_TEST, enable_flags.stencil_test);
} else {
EnableDisable(GL_BLEND, enable_flags.cached_blend);
EnableDisable(GL_CULL_FACE, enable_flags.cached_cull_face);
EnableDisable(GL_DEPTH_TEST, enable_flags.cached_depth_test);
EnableDisable(GL_DITHER, enable_flags.cached_dither);
EnableDisable(GL_POLYGON_OFFSET_FILL,
enable_flags.cached_polygon_offset_fill);
EnableDisable(GL_BLEND, enable_flags.blend);
EnableDisable(GL_CULL_FACE, enable_flags.cull_face);
EnableDisable(GL_DEPTH_TEST, enable_flags.depth_test);
EnableDisable(GL_DITHER, enable_flags.dither);
EnableDisable(GL_POLYGON_OFFSET_FILL, enable_flags.polygon_offset_fill);
EnableDisable(GL_SAMPLE_ALPHA_TO_COVERAGE,
enable_flags.cached_sample_alpha_to_coverage);
EnableDisable(GL_SAMPLE_COVERAGE, enable_flags.cached_sample_coverage);
EnableDisable(GL_SCISSOR_TEST, enable_flags.cached_scissor_test);
EnableDisable(GL_STENCIL_TEST, enable_flags.cached_stencil_test);
enable_flags.sample_alpha_to_coverage);
EnableDisable(GL_SAMPLE_COVERAGE, enable_flags.sample_coverage);
EnableDisable(GL_SCISSOR_TEST, enable_flags.scissor_test);
EnableDisable(GL_STENCIL_TEST, enable_flags.stencil_test);
}
}

Expand Down Expand Up @@ -177,20 +155,18 @@ void ContextState::InitState(const ContextState* prev_state) const {
glClearDepth(depth_clear);
if ((stencil_clear != prev_state->stencil_clear))
glClearStencil(stencil_clear);
if ((cached_color_mask_red != prev_state->cached_color_mask_red) ||
(cached_color_mask_green != prev_state->cached_color_mask_green) ||
(cached_color_mask_blue != prev_state->cached_color_mask_blue) ||
(cached_color_mask_alpha != prev_state->cached_color_mask_alpha))
glColorMask(cached_color_mask_red,
cached_color_mask_green,
cached_color_mask_blue,
cached_color_mask_alpha);
if ((color_mask_red != prev_state->color_mask_red) ||
(color_mask_green != prev_state->color_mask_green) ||
(color_mask_blue != prev_state->color_mask_blue) ||
(color_mask_alpha != prev_state->color_mask_alpha))
glColorMask(
color_mask_red, color_mask_green, color_mask_blue, color_mask_alpha);
if ((cull_mode != prev_state->cull_mode))
glCullFace(cull_mode);
if ((depth_func != prev_state->depth_func))
glDepthFunc(depth_func);
if ((cached_depth_mask != prev_state->cached_depth_mask))
glDepthMask(cached_depth_mask);
if ((depth_mask != prev_state->depth_mask))
glDepthMask(depth_mask);
if ((z_near != prev_state->z_near) || (z_far != prev_state->z_far))
glDepthRange(z_near, z_far);
if ((front_face != prev_state->front_face))
Expand Down Expand Up @@ -229,12 +205,10 @@ void ContextState::InitState(const ContextState* prev_state) const {
(stencil_back_mask != prev_state->stencil_back_mask))
glStencilFuncSeparate(
GL_BACK, stencil_back_func, stencil_back_ref, stencil_back_mask);
if ((cached_stencil_front_writemask !=
prev_state->cached_stencil_front_writemask))
glStencilMaskSeparate(GL_FRONT, cached_stencil_front_writemask);
if ((cached_stencil_back_writemask !=
prev_state->cached_stencil_back_writemask))
glStencilMaskSeparate(GL_BACK, cached_stencil_back_writemask);
if ((stencil_front_writemask != prev_state->stencil_front_writemask))
glStencilMaskSeparate(GL_FRONT, stencil_front_writemask);
if ((stencil_back_writemask != prev_state->stencil_back_writemask))
glStencilMaskSeparate(GL_BACK, stencil_back_writemask);
if ((stencil_front_fail_op != prev_state->stencil_front_fail_op) ||
(stencil_front_z_fail_op != prev_state->stencil_front_z_fail_op) ||
(stencil_front_z_pass_op != prev_state->stencil_front_z_pass_op))
Expand Down Expand Up @@ -268,13 +242,11 @@ void ContextState::InitState(const ContextState* prev_state) const {
color_clear_alpha);
glClearDepth(depth_clear);
glClearStencil(stencil_clear);
glColorMask(cached_color_mask_red,
cached_color_mask_green,
cached_color_mask_blue,
cached_color_mask_alpha);
glColorMask(
color_mask_red, color_mask_green, color_mask_blue, color_mask_alpha);
glCullFace(cull_mode);
glDepthFunc(depth_func);
glDepthMask(cached_depth_mask);
glDepthMask(depth_mask);
glDepthRange(z_near, z_far);
glFrontFace(front_face);
glHint(GL_GENERATE_MIPMAP_HINT, hint_generate_mipmap);
Expand All @@ -291,8 +263,8 @@ void ContextState::InitState(const ContextState* prev_state) const {
GL_FRONT, stencil_front_func, stencil_front_ref, stencil_front_mask);
glStencilFuncSeparate(
GL_BACK, stencil_back_func, stencil_back_ref, stencil_back_mask);
glStencilMaskSeparate(GL_FRONT, cached_stencil_front_writemask);
glStencilMaskSeparate(GL_BACK, cached_stencil_back_writemask);
glStencilMaskSeparate(GL_FRONT, stencil_front_writemask);
glStencilMaskSeparate(GL_BACK, stencil_back_writemask);
glStencilOpSeparate(GL_FRONT,
stencil_front_fail_op,
stencil_front_z_fail_op,
Expand Down
Loading

0 comments on commit 6781638

Please sign in to comment.