Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: gpu/command_buffer/service/texture_manager.h

Issue 1505343003: Updating texture validation to account for sampler objects in ES3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed DCHECK that was causing bots to fail Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <list> 9 #include <list>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "gpu/command_buffer/service/feature_info.h" 16 #include "gpu/command_buffer/service/feature_info.h"
17 #include "gpu/command_buffer/service/gl_utils.h" 17 #include "gpu/command_buffer/service/gl_utils.h"
18 #include "gpu/command_buffer/service/memory_tracking.h" 18 #include "gpu/command_buffer/service/memory_tracking.h"
19 #include "gpu/command_buffer/service/sampler_manager.h"
19 #include "gpu/gpu_export.h" 20 #include "gpu/gpu_export.h"
20 #include "ui/gfx/geometry/rect.h" 21 #include "ui/gfx/geometry/rect.h"
21 #include "ui/gl/gl_image.h" 22 #include "ui/gl/gl_image.h"
22 23
23 namespace gpu { 24 namespace gpu {
24 namespace gles2 { 25 namespace gles2 {
25 26
26 class GLES2Decoder; 27 class GLES2Decoder;
27 struct ContextState; 28 struct ContextState;
28 struct DecoderFramebufferState; 29 struct DecoderFramebufferState;
(...skipping 19 matching lines...) Expand all
48 // contents of the image and using it as a target will modify the image. 49 // contents of the image and using it as a target will modify the image.
49 BOUND, 50 BOUND,
50 // Image state is set to COPIED if the contents of the image has been 51 // Image state is set to COPIED if the contents of the image has been
51 // copied to the texture. Sampling from the texture will be equivalent 52 // copied to the texture. Sampling from the texture will be equivalent
52 // to sampling out the image (assuming image has not been changed since 53 // to sampling out the image (assuming image has not been changed since
53 // it was copied). Using the texture as a target for drawing will only 54 // it was copied). Using the texture as a target for drawing will only
54 // modify the texture and not the image. 55 // modify the texture and not the image.
55 COPIED 56 COPIED
56 }; 57 };
57 58
58 explicit Texture(GLuint service_id); 59 Texture(GLuint service_id, bool is_es3_enabled);
60
61 const SamplerState* sampler_state() const {
62 return &sampler_state_;
63 }
59 64
60 GLenum min_filter() const { 65 GLenum min_filter() const {
61 return min_filter_; 66 return sampler_state_.min_filter;
62 } 67 }
63 68
64 GLenum mag_filter() const { 69 GLenum mag_filter() const {
65 return mag_filter_; 70 return sampler_state_.mag_filter;
66 } 71 }
67 72
68 GLenum wrap_r() const { 73 GLenum wrap_r() const {
69 return wrap_r_; 74 return sampler_state_.wrap_r;
70 } 75 }
71 76
72 GLenum wrap_s() const { 77 GLenum wrap_s() const {
73 return wrap_s_; 78 return sampler_state_.wrap_s;
74 } 79 }
75 80
76 GLenum wrap_t() const { 81 GLenum wrap_t() const {
77 return wrap_t_; 82 return sampler_state_.wrap_t;
78 } 83 }
79 84
80 GLenum usage() const { 85 GLenum usage() const {
81 return usage_; 86 return usage_;
82 } 87 }
83 88
84 GLenum compare_func() const { 89 GLenum compare_func() const {
85 return compare_func_; 90 return sampler_state_.compare_func;
86 } 91 }
87 92
88 GLenum compare_mode() const { 93 GLenum compare_mode() const {
89 return compare_mode_; 94 return sampler_state_.compare_mode;
90 } 95 }
91 96
92 GLfloat max_lod() const { 97 GLfloat max_lod() const {
93 return max_lod_; 98 return sampler_state_.max_lod;
94 } 99 }
95 100
96 GLfloat min_lod() const { 101 GLfloat min_lod() const {
97 return min_lod_; 102 return sampler_state_.min_lod;
98 } 103 }
99 104
100 GLint base_level() const { 105 GLint base_level() const {
101 return base_level_; 106 return base_level_;
102 } 107 }
103 108
104 GLint max_level() const { 109 GLint max_level() const {
105 return max_level_; 110 return max_level_;
106 } 111 }
107 112
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 return estimated_size() > 0; 220 return estimated_size() > 0;
216 } 221 }
217 222
218 // Initialize TEXTURE_MAX_ANISOTROPY to 1 if we haven't done so yet. 223 // Initialize TEXTURE_MAX_ANISOTROPY to 1 if we haven't done so yet.
219 void InitTextureMaxAnisotropyIfNeeded(GLenum target); 224 void InitTextureMaxAnisotropyIfNeeded(GLenum target);
220 225
221 void DumpLevelMemory(base::trace_event::ProcessMemoryDump* pmd, 226 void DumpLevelMemory(base::trace_event::ProcessMemoryDump* pmd,
222 uint64_t client_tracing_id, 227 uint64_t client_tracing_id,
223 const std::string& dump_name) const; 228 const std::string& dump_name) const;
224 229
230 // Whether the texture has been defined
231 bool IsES3Enabled() const {
232 return is_es3_enabled_;
233 }
234
225 private: 235 private:
226 friend class MailboxManagerImpl; 236 friend class MailboxManagerImpl;
227 friend class MailboxManagerSync; 237 friend class MailboxManagerSync;
228 friend class MailboxManagerTest; 238 friend class MailboxManagerTest;
229 friend class TextureDefinition; 239 friend class TextureDefinition;
230 friend class TextureManager; 240 friend class TextureManager;
231 friend class TextureRef; 241 friend class TextureRef;
232 friend class TextureTestHelper; 242 friend class TextureTestHelper;
233 243
234 ~Texture(); 244 ~Texture();
235 void AddTextureRef(TextureRef* ref); 245 void AddTextureRef(TextureRef* ref);
236 void RemoveTextureRef(TextureRef* ref, bool have_context); 246 void RemoveTextureRef(TextureRef* ref, bool have_context);
237 MemoryTypeTracker* GetMemTracker(); 247 MemoryTypeTracker* GetMemTracker();
238 248
239 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it 249 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it
240 // depends on context support for non-power-of-two textures (i.e. will be 250 // depends on context support for non-power-of-two textures (i.e. will be
241 // renderable if NPOT support is in the context, otherwise not, e.g. texture 251 // renderable if NPOT support is in the context, otherwise not, e.g. texture
242 // with a NPOT level). ALWAYS means it doesn't depend on context features 252 // with a NPOT level). ALWAYS means it doesn't depend on context features
243 // (e.g. complete POT), NEVER means it's not renderable regardless (e.g. 253 // (e.g. complete POT), NEVER means it's not renderable regardless (e.g.
244 // incomplete). 254 // incomplete).
245 enum CanRenderCondition { 255 enum CanRenderCondition {
246 CAN_RENDER_ALWAYS, 256 CAN_RENDER_ALWAYS,
247 CAN_RENDER_NEVER, 257 CAN_RENDER_NEVER,
248 CAN_RENDER_ONLY_IF_NPOT 258 CAN_RENDER_ONLY_IF_NPOT,
259 CAN_RENDER_WITH_VALID_SAMPLER
249 }; 260 };
250 261
251 struct LevelInfo { 262 struct LevelInfo {
252 LevelInfo(); 263 LevelInfo();
253 LevelInfo(const LevelInfo& rhs); 264 LevelInfo(const LevelInfo& rhs);
254 ~LevelInfo(); 265 ~LevelInfo();
255 266
256 gfx::Rect cleared_rect; 267 gfx::Rect cleared_rect;
257 GLenum target; 268 GLenum target;
258 GLint level; 269 GLint level;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Returns GL_NO_ERROR on success. Otherwise the error to generate. 344 // Returns GL_NO_ERROR on success. Otherwise the error to generate.
334 GLenum SetParameteri( 345 GLenum SetParameteri(
335 const FeatureInfo* feature_info, GLenum pname, GLint param); 346 const FeatureInfo* feature_info, GLenum pname, GLint param);
336 GLenum SetParameterf( 347 GLenum SetParameterf(
337 const FeatureInfo* feature_info, GLenum pname, GLfloat param); 348 const FeatureInfo* feature_info, GLenum pname, GLfloat param);
338 349
339 // Makes each of the mip levels as though they were generated. 350 // Makes each of the mip levels as though they were generated.
340 bool MarkMipmapsGenerated(const FeatureInfo* feature_info); 351 bool MarkMipmapsGenerated(const FeatureInfo* feature_info);
341 352
342 bool NeedsMips() const { 353 bool NeedsMips() const {
343 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; 354 return sampler_state_.min_filter != GL_NEAREST &&
355 sampler_state_.min_filter != GL_LINEAR;
344 } 356 }
345 357
346 // True if this texture meets all the GLES2 criteria for rendering. 358 // True if this texture meets all the GLES2 criteria for rendering.
347 // See section 3.8.2 of the GLES2 spec. 359 // See section 3.8.2 of the GLES2 spec.
348 bool CanRender(const FeatureInfo* feature_info) const; 360 bool CanRender(const FeatureInfo* feature_info) const;
361 bool CanRenderWithSampler(const FeatureInfo* feature_info,
362 const SamplerState* sampler_state) const;
349 363
350 // Returns true if mipmaps can be generated by GL. 364 // Returns true if mipmaps can be generated by GL.
351 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; 365 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const;
352 366
353 // Returns true if any of the texture dimensions are not a power of two. 367 // Returns true if any of the texture dimensions are not a power of two.
354 static bool TextureIsNPOT(GLsizei width, GLsizei height, GLsizei depth); 368 static bool TextureIsNPOT(GLsizei width, GLsizei height, GLsizei depth);
355 369
356 // Returns true if texture face is complete relative to the first face. 370 // Returns true if texture face is complete relative to the first face.
357 static bool TextureFaceComplete(const Texture::LevelInfo& first_face, 371 static bool TextureFaceComplete(const Texture::LevelInfo& first_face,
358 size_t face_index, 372 size_t face_index,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 bool cleared_; 459 bool cleared_;
446 460
447 int num_uncleared_mips_; 461 int num_uncleared_mips_;
448 int num_npot_faces_; 462 int num_npot_faces_;
449 463
450 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. 464 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
451 // Or GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3). 465 // Or GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3).
452 GLenum target_; 466 GLenum target_;
453 467
454 // Texture parameters. 468 // Texture parameters.
455 GLenum min_filter_; 469 SamplerState sampler_state_;
456 GLenum mag_filter_;
457 GLenum wrap_r_;
458 GLenum wrap_s_;
459 GLenum wrap_t_;
460 GLenum usage_; 470 GLenum usage_;
461 GLenum compare_func_;
462 GLenum compare_mode_;
463 GLfloat max_lod_;
464 GLfloat min_lod_;
465 GLint base_level_; 471 GLint base_level_;
466 GLint max_level_; 472 GLint max_level_;
467 473
468 // The maximum level that has been set. 474 // The maximum level that has been set.
469 GLint max_level_set_; 475 GLint max_level_set_;
470 476
471 // Whether or not this texture is "texture complete" 477 // Whether or not this texture is "texture complete"
472 bool texture_complete_; 478 bool texture_complete_;
473 479
474 // Whether mip levels have changed and should be reverified. 480 // Whether mip levels have changed and should be reverified.
(...skipping 23 matching lines...) Expand all
498 504
499 // Size in bytes this texture is assumed to take in memory. 505 // Size in bytes this texture is assumed to take in memory.
500 uint32 estimated_size_; 506 uint32 estimated_size_;
501 507
502 // Cache of the computed CanRenderCondition flag. 508 // Cache of the computed CanRenderCondition flag.
503 CanRenderCondition can_render_condition_; 509 CanRenderCondition can_render_condition_;
504 510
505 // Whether we have initialized TEXTURE_MAX_ANISOTROPY to 1. 511 // Whether we have initialized TEXTURE_MAX_ANISOTROPY to 1.
506 bool texture_max_anisotropy_initialized_; 512 bool texture_max_anisotropy_initialized_;
507 513
514 // Whether this texture was created by an ES3 context
515 bool is_es3_enabled_;
516
508 DISALLOW_COPY_AND_ASSIGN(Texture); 517 DISALLOW_COPY_AND_ASSIGN(Texture);
509 }; 518 };
510 519
511 // This class represents a texture in a client context group. It's mostly 1:1 520 // This class represents a texture in a client context group. It's mostly 1:1
512 // with a client id, though it can outlive the client id if it's still bound to 521 // with a client id, though it can outlive the client id if it's still bound to
513 // a FBO or another context when destroyed. 522 // a FBO or another context when destroyed.
514 // Multiple TextureRef can point to the same texture with cross-context sharing. 523 // Multiple TextureRef can point to the same texture with cross-context sharing.
515 class GPU_EXPORT TextureRef : public base::RefCounted<TextureRef> { 524 class GPU_EXPORT TextureRef : public base::RefCounted<TextureRef> {
516 public: 525 public:
517 TextureRef(TextureManager* manager, GLuint client_id, Texture* texture); 526 TextureRef(TextureManager* manager, GLuint client_id, Texture* texture);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat); 676 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat);
668 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat); 677 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat);
669 678
670 // Checks if a dimensions are valid for a given target. 679 // Checks if a dimensions are valid for a given target.
671 bool ValidForTarget( 680 bool ValidForTarget(
672 GLenum target, GLint level, 681 GLenum target, GLint level,
673 GLsizei width, GLsizei height, GLsizei depth); 682 GLsizei width, GLsizei height, GLsizei depth);
674 683
675 // True if this texture meets all the GLES2 criteria for rendering. 684 // True if this texture meets all the GLES2 criteria for rendering.
676 // See section 3.8.2 of the GLES2 spec. 685 // See section 3.8.2 of the GLES2 spec.
677 bool CanRender(const TextureRef* ref) const { 686 bool CanRender(
687 const TextureRef* ref) const {
678 return ref->texture()->CanRender(feature_info_.get()); 688 return ref->texture()->CanRender(feature_info_.get());
679 } 689 }
680 690
691 bool CanRenderWithSampler(
692 const TextureRef* ref, const SamplerState* sampler_state) const {
693 return ref->texture()->CanRenderWithSampler(
694 feature_info_.get(), sampler_state);
695 }
696
681 // Returns true if mipmaps can be generated by GL. 697 // Returns true if mipmaps can be generated by GL.
682 bool CanGenerateMipmaps(const TextureRef* ref) const { 698 bool CanGenerateMipmaps(const TextureRef* ref) const {
683 return ref->texture()->CanGenerateMipmaps(feature_info_.get()); 699 return ref->texture()->CanGenerateMipmaps(feature_info_.get());
684 } 700 }
685 701
686 // Sets the Texture's target 702 // Sets the Texture's target
687 // Parameters: 703 // Parameters:
688 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP 704 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP
689 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3) 705 // GL_TEXTURE_2D_ARRAY or GL_TEXTURE_3D (for GLES3)
690 // max_levels: The maximum levels this type of target can have. 706 // max_levels: The maximum levels this type of target can have.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 case GL_TEXTURE_EXTERNAL_OES: 783 case GL_TEXTURE_EXTERNAL_OES:
768 return default_textures_[kExternalOES].get(); 784 return default_textures_[kExternalOES].get();
769 case GL_TEXTURE_RECTANGLE_ARB: 785 case GL_TEXTURE_RECTANGLE_ARB:
770 return default_textures_[kRectangleARB].get(); 786 return default_textures_[kRectangleARB].get();
771 default: 787 default:
772 NOTREACHED(); 788 NOTREACHED();
773 return NULL; 789 return NULL;
774 } 790 }
775 } 791 }
776 792
777 bool HaveUnrenderableTextures() const { 793 bool NeedsTextureRenderChecks() const {
778 return num_unrenderable_textures_ > 0; 794 return feature_info_->IsES3Enabled() || num_unrenderable_textures_ > 0;
779 } 795 }
780 796
781 bool HaveUnsafeTextures() const { 797 bool HaveUnsafeTextures() const {
782 return num_unsafe_textures_ > 0; 798 return num_unsafe_textures_ > 0;
783 } 799 }
784 800
785 bool HaveUnclearedMips() const { 801 bool HaveUnclearedMips() const {
786 return num_uncleared_mips_ > 0; 802 return num_uncleared_mips_ > 0;
787 } 803 }
788 804
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 private: 1035 private:
1020 DecoderTextureState* texture_state_; 1036 DecoderTextureState* texture_state_;
1021 base::TimeTicks begin_time_; 1037 base::TimeTicks begin_time_;
1022 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer); 1038 DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer);
1023 }; 1039 };
1024 1040
1025 } // namespace gles2 1041 } // namespace gles2
1026 } // namespace gpu 1042 } // namespace gpu
1027 1043
1028 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 1044 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698