OLD | NEW |
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_PROGRAM_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 396 |
397 // See member declaration for details. | 397 // See member declaration for details. |
398 // The data are only valid after a successful link. | 398 // The data are only valid after a successful link. |
399 uint32_t fragment_output_type_mask() const { | 399 uint32_t fragment_output_type_mask() const { |
400 return fragment_output_type_mask_; | 400 return fragment_output_type_mask_; |
401 } | 401 } |
402 uint32_t fragment_output_written_mask() const { | 402 uint32_t fragment_output_written_mask() const { |
403 return fragment_output_written_mask_; | 403 return fragment_output_written_mask_; |
404 } | 404 } |
405 | 405 |
| 406 // The data are only valid after a successful link. |
| 407 // Return 16 attributes' base types, in which the attribute |
| 408 // specified by argument 'loc' located. |
| 409 uint32_t vertex_input_base_type_mask(GLuint loc) const { |
| 410 DCHECK(loc < max_vertex_attribs_); |
| 411 return vertex_input_base_type_mask_[loc / 16]; |
| 412 } |
| 413 // Return 16 attributes' type written masks, in which the |
| 414 // attribute specified by argument 'loc' located. |
| 415 uint32_t vertex_input_type_written_mask(GLuint loc) const { |
| 416 DCHECK(loc < max_vertex_attribs_); |
| 417 return vertex_input_type_written_mask_[loc / 16]; |
| 418 } |
| 419 |
406 // Update uniform block binding after a successful glUniformBlockBinding(). | 420 // Update uniform block binding after a successful glUniformBlockBinding(). |
407 void SetUniformBlockBinding(GLuint index, GLuint binding); | 421 void SetUniformBlockBinding(GLuint index, GLuint binding); |
408 | 422 |
409 const std::vector<UniformBlockSizeInfo>& uniform_block_size_info() const { | 423 const std::vector<UniformBlockSizeInfo>& uniform_block_size_info() const { |
410 return uniform_block_size_info_; | 424 return uniform_block_size_info_; |
411 } | 425 } |
412 | 426 |
413 private: | 427 private: |
414 friend class base::RefCounted<Program>; | 428 friend class base::RefCounted<Program>; |
415 friend class ProgramManager; | 429 friend class ProgramManager; |
(...skipping 24 matching lines...) Expand all Loading... |
440 | 454 |
441 // Resets the program. | 455 // Resets the program. |
442 void Reset(); | 456 void Reset(); |
443 | 457 |
444 // Updates the program info after a successful link. | 458 // Updates the program info after a successful link. |
445 void Update(); | 459 void Update(); |
446 void UpdateUniforms(); | 460 void UpdateUniforms(); |
447 void UpdateFragmentInputs(); | 461 void UpdateFragmentInputs(); |
448 void UpdateProgramOutputs(); | 462 void UpdateProgramOutputs(); |
449 void UpdateFragmentOutputBaseTypes(); | 463 void UpdateFragmentOutputBaseTypes(); |
| 464 void UpdateVertexInputBaseTypes(); |
450 void UpdateUniformBlockSizeInfo(); | 465 void UpdateUniformBlockSizeInfo(); |
451 | 466 |
452 // Process the program log, replacing the hashed names with original names. | 467 // Process the program log, replacing the hashed names with original names. |
453 std::string ProcessLogInfo(const std::string& log); | 468 std::string ProcessLogInfo(const std::string& log); |
454 | 469 |
455 // Updates the program log info from GL | 470 // Updates the program log info from GL |
456 void UpdateLogInfo(); | 471 void UpdateLogInfo(); |
457 | 472 |
458 // Clears all the uniforms. | 473 // Clears all the uniforms. |
459 void ClearUniforms(std::vector<uint8_t>* zero_buffer); | 474 void ClearUniforms(std::vector<uint8_t>* zero_buffer); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 // entry is the info about UniformBlock with index 0, etc. | 573 // entry is the info about UniformBlock with index 0, etc. |
559 std::vector<UniformBlockSizeInfo> uniform_block_size_info_; | 574 std::vector<UniformBlockSizeInfo> uniform_block_size_info_; |
560 | 575 |
561 // Fragment output variable base types: FLOAT, INT, or UINT. | 576 // Fragment output variable base types: FLOAT, INT, or UINT. |
562 // We have up to 16 outputs, each is encoded into 2 bits, total 32 bits: | 577 // We have up to 16 outputs, each is encoded into 2 bits, total 32 bits: |
563 // the lowest 2 bits for location 0, the highest 2 bits for location 15. | 578 // the lowest 2 bits for location 0, the highest 2 bits for location 15. |
564 uint32_t fragment_output_type_mask_; | 579 uint32_t fragment_output_type_mask_; |
565 // Same layout as above, 2 bits per location, 0x03 if a location is occupied | 580 // Same layout as above, 2 bits per location, 0x03 if a location is occupied |
566 // by an output variable, 0x00 if not. | 581 // by an output variable, 0x00 if not. |
567 uint32_t fragment_output_written_mask_; | 582 uint32_t fragment_output_written_mask_; |
| 583 |
| 584 uint32_t max_vertex_attribs_; |
| 585 // Vertex input attrib base types: FLOAT, INT, or UINT. |
| 586 // Each base type is encoded into 2 bits, the lowest 2 bits for location 0, |
| 587 // the highest 2 bits for location (max_vertex_attribs_ - 1). |
| 588 std::vector<uint32_t> vertex_input_base_type_mask_; |
| 589 // Same layout as above, 2 bits per location, 0x03 if a location is set |
| 590 // by vertexAttrib API, 0x00 if not. |
| 591 std::vector<uint32_t> vertex_input_type_written_mask_; |
568 }; | 592 }; |
569 | 593 |
570 // Tracks the Programs. | 594 // Tracks the Programs. |
571 // | 595 // |
572 // NOTE: To support shared resources an instance of this class will | 596 // NOTE: To support shared resources an instance of this class will |
573 // need to be shared by multiple GLES2Decoders. | 597 // need to be shared by multiple GLES2Decoders. |
574 class GPU_EXPORT ProgramManager { | 598 class GPU_EXPORT ProgramManager { |
575 public: | 599 public: |
576 ProgramManager(ProgramCache* program_cache, | 600 ProgramManager(ProgramCache* program_cache, |
577 uint32_t max_varying_vectors, | 601 uint32_t max_varying_vectors, |
578 uint32_t max_draw_buffers, | 602 uint32_t max_draw_buffers, |
579 uint32_t max_dual_source_draw_buffers, | 603 uint32_t max_dual_source_draw_buffers, |
| 604 uint32_t max_vertex_attribs, |
580 const GpuPreferences& gpu_preferences, | 605 const GpuPreferences& gpu_preferences, |
581 FeatureInfo* feature_info); | 606 FeatureInfo* feature_info); |
582 ~ProgramManager(); | 607 ~ProgramManager(); |
583 | 608 |
584 // Must call before destruction. | 609 // Must call before destruction. |
585 void Destroy(bool have_context); | 610 void Destroy(bool have_context); |
586 | 611 |
587 // Creates a new program. | 612 // Creates a new program. |
588 Program* CreateProgram(GLuint client_id, GLuint service_id); | 613 Program* CreateProgram(GLuint client_id, GLuint service_id); |
589 | 614 |
(...skipping 28 matching lines...) Expand all Loading... |
618 static int32_t MakeFakeLocation(int32_t index, int32_t element); | 643 static int32_t MakeFakeLocation(int32_t index, int32_t element); |
619 | 644 |
620 uint32_t max_varying_vectors() const { return max_varying_vectors_; } | 645 uint32_t max_varying_vectors() const { return max_varying_vectors_; } |
621 | 646 |
622 uint32_t max_draw_buffers() const { return max_draw_buffers_; } | 647 uint32_t max_draw_buffers() const { return max_draw_buffers_; } |
623 | 648 |
624 uint32_t max_dual_source_draw_buffers() const { | 649 uint32_t max_dual_source_draw_buffers() const { |
625 return max_dual_source_draw_buffers_; | 650 return max_dual_source_draw_buffers_; |
626 } | 651 } |
627 | 652 |
| 653 uint32_t max_vertex_attribs() const { return max_vertex_attribs_; } |
| 654 |
628 private: | 655 private: |
629 friend class Program; | 656 friend class Program; |
630 | 657 |
631 void StartTracking(Program* program); | 658 void StartTracking(Program* program); |
632 void StopTracking(Program* program); | 659 void StopTracking(Program* program); |
633 | 660 |
634 void RemoveProgramInfoIfUnused( | 661 void RemoveProgramInfoIfUnused( |
635 ShaderManager* shader_manager, Program* program); | 662 ShaderManager* shader_manager, Program* program); |
636 | 663 |
637 // Info for each "successfully linked" program by service side program Id. | 664 // Info for each "successfully linked" program by service side program Id. |
638 // TODO(gman): Choose a faster container. | 665 // TODO(gman): Choose a faster container. |
639 typedef std::map<GLuint, scoped_refptr<Program> > ProgramMap; | 666 typedef std::map<GLuint, scoped_refptr<Program> > ProgramMap; |
640 ProgramMap programs_; | 667 ProgramMap programs_; |
641 | 668 |
642 // Counts the number of Program allocated with 'this' as its manager. | 669 // Counts the number of Program allocated with 'this' as its manager. |
643 // Allows to check no Program will outlive this. | 670 // Allows to check no Program will outlive this. |
644 unsigned int program_count_; | 671 unsigned int program_count_; |
645 | 672 |
646 bool have_context_; | 673 bool have_context_; |
647 | 674 |
648 // Used to clear uniforms. | 675 // Used to clear uniforms. |
649 std::vector<uint8_t> zero_; | 676 std::vector<uint8_t> zero_; |
650 | 677 |
651 ProgramCache* program_cache_; | 678 ProgramCache* program_cache_; |
652 | 679 |
653 uint32_t max_varying_vectors_; | 680 uint32_t max_varying_vectors_; |
654 uint32_t max_draw_buffers_; | 681 uint32_t max_draw_buffers_; |
655 uint32_t max_dual_source_draw_buffers_; | 682 uint32_t max_dual_source_draw_buffers_; |
| 683 uint32_t max_vertex_attribs_; |
656 | 684 |
657 const GpuPreferences& gpu_preferences_; | 685 const GpuPreferences& gpu_preferences_; |
658 scoped_refptr<FeatureInfo> feature_info_; | 686 scoped_refptr<FeatureInfo> feature_info_; |
659 | 687 |
660 DISALLOW_COPY_AND_ASSIGN(ProgramManager); | 688 DISALLOW_COPY_AND_ASSIGN(ProgramManager); |
661 }; | 689 }; |
662 | 690 |
663 inline const FeatureInfo& Program::feature_info() const { | 691 inline const FeatureInfo& Program::feature_info() const { |
664 return *manager_->feature_info_.get(); | 692 return *manager_->feature_info_.get(); |
665 } | 693 } |
666 | 694 |
667 } // namespace gles2 | 695 } // namespace gles2 |
668 } // namespace gpu | 696 } // namespace gpu |
669 | 697 |
670 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ | 698 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
OLD | NEW |