Commit ecc73c25 authored by dyen's avatar dyen Committed by Commit bot

Optimized Texture::Update() function.

Texture::Update() was doing a lot of calculations that did not change
much per frame. Some of the calculations such as whether or not has
non-power of 2 dimensions has been moved to when the texture
levels are set since they do not change. Others are only recalculated
when a dirty bit is set.

BUG=420152
TEST=trybots

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

Cr-Commit-Position: refs/heads/master@{#299181}
parent 7dc1df31
...@@ -374,21 +374,22 @@ TextureDefinition::TextureDefinition( ...@@ -374,21 +374,22 @@ TextureDefinition::TextureDefinition(
usage_(texture->usage()), usage_(texture->usage()),
immutable_(texture->IsImmutable()) { immutable_(texture->IsImmutable()) {
// TODO // TODO
DCHECK(!texture->level_infos_.empty()); DCHECK(!texture->face_infos_.empty());
DCHECK(!texture->level_infos_[0].empty()); DCHECK(!texture->face_infos_[0].level_infos.empty());
DCHECK(!texture->NeedsMips()); DCHECK(!texture->NeedsMips());
DCHECK(texture->level_infos_[0][0].width); DCHECK(texture->face_infos_[0].level_infos[0].width);
DCHECK(texture->level_infos_[0][0].height); DCHECK(texture->face_infos_[0].level_infos[0].height);
const Texture::FaceInfo& first_face = texture->face_infos_[0];
scoped_refptr<gfx::GLImage> gl_image( scoped_refptr<gfx::GLImage> gl_image(
new GLImageSync(image_buffer_, new GLImageSync(image_buffer_,
gfx::Size(texture->level_infos_[0][0].width, gfx::Size(first_face.level_infos[0].width,
texture->level_infos_[0][0].height))); first_face.level_infos[0].height)));
texture->SetLevelImage(NULL, target, 0, gl_image.get()); texture->SetLevelImage(NULL, target, 0, gl_image.get());
// TODO: all levels // TODO: all levels
level_infos_.clear(); level_infos_.clear();
const Texture::LevelInfo& level = texture->level_infos_[0][0]; const Texture::LevelInfo& level = first_face.level_infos[0];
LevelInfo info(level.target, LevelInfo info(level.target,
level.internal_format, level.internal_format,
level.width, level.width,
...@@ -435,13 +436,13 @@ void TextureDefinition::UpdateTexture(Texture* texture) const { ...@@ -435,13 +436,13 @@ void TextureDefinition::UpdateTexture(Texture* texture) const {
// though. // though.
glFlush(); glFlush();
texture->level_infos_.resize(1); texture->face_infos_.resize(1);
for (size_t i = 0; i < level_infos_.size(); i++) { for (size_t i = 0; i < level_infos_.size(); i++) {
const LevelInfo& base_info = level_infos_[i][0]; const LevelInfo& base_info = level_infos_[i][0];
const size_t levels_needed = TextureManager::ComputeMipMapCount( const size_t levels_needed = TextureManager::ComputeMipMapCount(
base_info.target, base_info.width, base_info.height, base_info.depth); base_info.target, base_info.width, base_info.height, base_info.depth);
DCHECK(level_infos_.size() <= levels_needed); DCHECK(level_infos_.size() <= levels_needed);
texture->level_infos_[0].resize(levels_needed); texture->face_infos_[0].level_infos.resize(levels_needed);
for (size_t n = 0; n < level_infos_.size(); n++) { for (size_t n = 0; n < level_infos_.size(); n++) {
const LevelInfo& info = level_infos_[i][n]; const LevelInfo& info = level_infos_[i][n];
texture->SetLevelInfo(NULL, texture->SetLevelInfo(NULL,
......
...@@ -208,6 +208,14 @@ class GPU_EXPORT Texture { ...@@ -208,6 +208,14 @@ class GPU_EXPORT Texture {
uint32 estimated_size; uint32 estimated_size;
}; };
struct FaceInfo {
FaceInfo();
~FaceInfo();
GLsizei num_mip_levels;
std::vector<LevelInfo> level_infos;
};
// Set the info for a particular level. // Set the info for a particular level.
void SetLevelInfo( void SetLevelInfo(
const FeatureInfo* feature_info, const FeatureInfo* feature_info,
...@@ -276,6 +284,31 @@ class GPU_EXPORT Texture { ...@@ -276,6 +284,31 @@ class GPU_EXPORT Texture {
// Returns true if mipmaps can be generated by GL. // Returns true if mipmaps can be generated by GL.
bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; bool CanGenerateMipmaps(const FeatureInfo* feature_info) const;
// Returns true if any of the texture dimensions are not a power of two.
static bool TextureIsNPOT(GLsizei width, GLsizei height, GLsizei depth);
// Returns true if texture face is complete relative to the first face.
static bool TextureFaceComplete(const Texture::LevelInfo& first_face,
size_t face_index,
GLenum target,
GLenum internal_format,
GLsizei width,
GLsizei height,
GLsizei depth,
GLenum format,
GLenum type);
// Returns true if texture mip level is complete relative to first level.
static bool TextureMipComplete(const Texture::LevelInfo& level0_face,
GLenum target,
GLint level,
GLenum internal_format,
GLsizei width,
GLsizei height,
GLsizei depth,
GLenum format,
GLenum type);
// Sets the Texture's target // Sets the Texture's target
// Parameters: // Parameters:
// target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP or // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP or
...@@ -327,7 +360,7 @@ class GPU_EXPORT Texture { ...@@ -327,7 +360,7 @@ class GPU_EXPORT Texture {
MailboxManager* mailbox_manager_; MailboxManager* mailbox_manager_;
// Info about each face and level of texture. // Info about each face and level of texture.
std::vector<std::vector<LevelInfo> > level_infos_; std::vector<FaceInfo> face_infos_;
// The texture refs that point to this Texture. // The texture refs that point to this Texture.
typedef std::set<TextureRef*> RefSet; typedef std::set<TextureRef*> RefSet;
...@@ -344,6 +377,7 @@ class GPU_EXPORT Texture { ...@@ -344,6 +377,7 @@ class GPU_EXPORT Texture {
bool cleared_; bool cleared_;
int num_uncleared_mips_; int num_uncleared_mips_;
int num_npot_faces_;
// The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
GLenum target_; GLenum target_;
...@@ -362,9 +396,17 @@ class GPU_EXPORT Texture { ...@@ -362,9 +396,17 @@ class GPU_EXPORT Texture {
// Whether or not this texture is "texture complete" // Whether or not this texture is "texture complete"
bool texture_complete_; bool texture_complete_;
// Whether mip levels have changed and should be reverified.
bool texture_mips_dirty_;
bool texture_mips_complete_;
// Whether or not this texture is "cube complete" // Whether or not this texture is "cube complete"
bool cube_complete_; bool cube_complete_;
// Whether any level 0 faces have changed and should be reverified.
bool texture_level0_dirty_;
bool texture_level0_complete_;
// Whether or not this texture is non-power-of-two // Whether or not this texture is non-power-of-two
bool npot_; bool npot_;
......
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