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 #include "gpu/command_buffer/service/program_manager.h" | 5 #include "gpu/command_buffer/service/program_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/numerics/safe_math.h" | 17 #include "base/numerics/safe_math.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 21 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
23 #include "gpu/command_buffer/service/feature_info.h" | 23 #include "gpu/command_buffer/service/feature_info.h" |
24 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 24 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
25 #include "gpu/command_buffer/service/gpu_switches.h" | 25 #include "gpu/command_buffer/service/gpu_switches.h" |
26 #include "gpu/command_buffer/service/program_cache.h" | 26 #include "gpu/command_buffer/service/program_cache.h" |
27 #include "gpu/command_buffer/service/shader_manager.h" | 27 #include "gpu/command_buffer/service/shader_manager.h" |
28 #include "third_party/re2/re2/re2.h" | 28 #include "third_party/re2/re2/re2.h" |
29 #include "ui/gl/gl_version_info.h" | |
29 | 30 |
30 using base::TimeDelta; | 31 using base::TimeDelta; |
31 using base::TimeTicks; | 32 using base::TimeTicks; |
32 | 33 |
33 namespace gpu { | 34 namespace gpu { |
34 namespace gles2 { | 35 namespace gles2 { |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 int ShaderTypeToIndex(GLenum shader_type) { | 39 int ShaderTypeToIndex(GLenum shader_type) { |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 | 624 |
624 void Program::ExecuteBindAttribLocationCalls() { | 625 void Program::ExecuteBindAttribLocationCalls() { |
625 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); | 626 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); |
626 it != bind_attrib_location_map_.end(); ++it) { | 627 it != bind_attrib_location_map_.end(); ++it) { |
627 const std::string* mapped_name = GetAttribMappedName(it->first); | 628 const std::string* mapped_name = GetAttribMappedName(it->first); |
628 if (mapped_name) | 629 if (mapped_name) |
629 glBindAttribLocation(service_id_, it->second, mapped_name->c_str()); | 630 glBindAttribLocation(service_id_, it->second, mapped_name->c_str()); |
630 } | 631 } |
631 } | 632 } |
632 | 633 |
634 void Program::ExecuteBindFragDataLocationIndexedCalls() { | |
635 Shader* fragment_shader = | |
636 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get(); | |
637 if (fragment_shader->shader_version() == 100 && | |
638 !feature_info().gl_version_info().is_es) { | |
639 // Map gl_SecondaryFragColorEXT / gl_SecondaryFragDataEXT of | |
640 // EXT_blend_func_extended to real | |
641 // color indexes, if underlying context is not ES. | |
642 | |
643 for (auto const& output_var : fragment_shader->output_variable_list()) { | |
644 const std::string& name = output_var.mappedName; | |
645 if (name == "gl_FragColor") { | |
646 DCHECK(output_var.location == -1); | |
Zhenyao Mo
2015/08/31 21:12:30
nit: Use DCHECK_EQ and DCHECK_NE here and below.
Kimmo Kinnunen
2015/09/24 13:16:28
Done.
| |
647 DCHECK(output_var.arraySize == 0u); | |
648 // We leave these unbound by not giving a binding name. The driver will | |
649 // bind this. | |
650 } else if (name == "gl_FragData") { | |
651 DCHECK(output_var.location == -1); | |
652 DCHECK(output_var.arraySize != 0u); | |
653 // We leave these unbound by not giving a binding name. The driver will | |
654 // bind this. | |
655 } else if (name == "gl_SecondaryFragColorEXT") { | |
656 DCHECK(feature_info().feature_flags().ext_blend_func_extended); | |
657 DCHECK(output_var.location == -1); | |
658 DCHECK(output_var.arraySize == 0u); | |
659 glBindFragDataLocationIndexed(service_id_, 0, 1, | |
660 "angle_SecondaryFragColor"); | |
661 } else if (name == "gl_SecondaryFragDataEXT") { | |
662 DCHECK(feature_info().feature_flags().ext_blend_func_extended); | |
663 DCHECK(output_var.location == -1); | |
664 DCHECK(output_var.arraySize != 0u); | |
665 glBindFragDataLocationIndexed(service_id_, 0, 1, | |
666 "angle_SecondaryFragData"); | |
667 } | |
668 } | |
669 } | |
670 } | |
671 | |
633 bool Program::Link(ShaderManager* manager, | 672 bool Program::Link(ShaderManager* manager, |
634 Program::VaryingsPackingOption varyings_packing_option, | 673 Program::VaryingsPackingOption varyings_packing_option, |
635 const ShaderCacheCallback& shader_callback) { | 674 const ShaderCacheCallback& shader_callback) { |
636 ClearLinkStatus(); | 675 ClearLinkStatus(); |
637 | 676 |
638 if (!AttachedShadersExist()) { | 677 if (!AttachedShadersExist()) { |
639 set_log_info("missing shaders"); | 678 set_log_info("missing shaders"); |
640 return false; | 679 return false; |
641 } | 680 } |
642 | 681 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
707 "attribute: " + conflicting_name; | 746 "attribute: " + conflicting_name; |
708 set_log_info(ProcessLogInfo(info_log).c_str()); | 747 set_log_info(ProcessLogInfo(info_log).c_str()); |
709 return false; | 748 return false; |
710 } | 749 } |
711 if (!CheckVaryingsPacking(varyings_packing_option)) { | 750 if (!CheckVaryingsPacking(varyings_packing_option)) { |
712 set_log_info("Varyings over maximum register limit"); | 751 set_log_info("Varyings over maximum register limit"); |
713 return false; | 752 return false; |
714 } | 753 } |
715 | 754 |
716 ExecuteBindAttribLocationCalls(); | 755 ExecuteBindAttribLocationCalls(); |
756 ExecuteBindFragDataLocationIndexedCalls(); | |
757 | |
717 before_time = TimeTicks::Now(); | 758 before_time = TimeTicks::Now(); |
718 if (cache && gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary) { | 759 if (cache && gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary) { |
719 glProgramParameteri(service_id(), | 760 glProgramParameteri(service_id(), |
720 PROGRAM_BINARY_RETRIEVABLE_HINT, | 761 PROGRAM_BINARY_RETRIEVABLE_HINT, |
721 GL_TRUE); | 762 GL_TRUE); |
722 } | 763 } |
723 glLinkProgram(service_id()); | 764 glLinkProgram(service_id()); |
724 } | 765 } |
725 | 766 |
726 GLint success = 0; | 767 GLint success = 0; |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1816 } | 1857 } |
1817 glGetActiveUniformsiv( | 1858 glGetActiveUniformsiv( |
1818 program, count, &indices[0], kPname[pname_index], ¶ms[0]); | 1859 program, count, &indices[0], kPname[pname_index], ¶ms[0]); |
1819 for (GLsizei ii = 0; ii < count; ++ii) { | 1860 for (GLsizei ii = 0; ii < count; ++ii) { |
1820 entries[kStride * ii + pname_index] = params[ii]; | 1861 entries[kStride * ii + pname_index] = params[ii]; |
1821 } | 1862 } |
1822 } | 1863 } |
1823 return true; | 1864 return true; |
1824 } | 1865 } |
1825 | 1866 |
1867 GLint Program::GetFragDataLocation(const std::string& original_name) const { | |
1868 DCHECK(IsValid()); | |
1869 Shader* shader = | |
1870 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get(); | |
1871 if (!shader->GetOutputVariableInfo(original_name)) { | |
1872 return -1; | |
1873 } | |
1874 return glGetFragDataLocation(service_id_, original_name.c_str()); | |
Zhenyao Mo
2015/08/31 21:12:30
This is incorrect (based on my understanding that
Kimmo Kinnunen
2015/09/24 13:16:27
Done.
| |
1875 } | |
1876 | |
1877 GLint Program::GetFragDataIndex(const std::string& original_name) const { | |
1878 DCHECK(IsValid()); | |
1879 Shader* shader = | |
1880 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get(); | |
1881 if (!shader->GetOutputVariableInfo(original_name)) { | |
1882 return -1; | |
1883 } | |
1884 return glGetFragDataIndex(service_id_, original_name.c_str()); | |
Zhenyao Mo
2015/08/31 21:12:31
Same here, pass down mapped_name to the driver.
P
Kimmo Kinnunen
2015/09/24 13:16:28
Done.
| |
1885 } | |
1886 | |
1826 void Program::TransformFeedbackVaryings(GLsizei count, | 1887 void Program::TransformFeedbackVaryings(GLsizei count, |
1827 const char* const* varyings, | 1888 const char* const* varyings, |
1828 GLenum buffer_mode) { | 1889 GLenum buffer_mode) { |
1829 transform_feedback_varyings_.clear(); | 1890 transform_feedback_varyings_.clear(); |
1830 for (GLsizei i = 0; i < count; ++i) { | 1891 for (GLsizei i = 0; i < count; ++i) { |
1831 transform_feedback_varyings_.push_back(std::string(varyings[i])); | 1892 transform_feedback_varyings_.push_back(std::string(varyings[i])); |
1832 } | 1893 } |
1833 transform_feedback_buffer_mode_ = buffer_mode; | 1894 transform_feedback_buffer_mode_ = buffer_mode; |
1834 } | 1895 } |
1835 | 1896 |
1836 Program::~Program() { | 1897 Program::~Program() { |
1837 if (manager_) { | 1898 if (manager_) { |
1838 if (manager_->have_context_) { | 1899 if (manager_->have_context_) { |
1839 glDeleteProgram(service_id()); | 1900 glDeleteProgram(service_id()); |
1840 } | 1901 } |
1841 manager_->StopTracking(this); | 1902 manager_->StopTracking(this); |
1842 manager_ = NULL; | 1903 manager_ = NULL; |
1843 } | 1904 } |
1844 } | 1905 } |
1845 | 1906 |
1846 ProgramManager::ProgramManager(ProgramCache* program_cache, | 1907 ProgramManager::ProgramManager(ProgramCache* program_cache, |
1847 uint32 max_varying_vectors, | 1908 uint32 max_varying_vectors, |
1909 uint32 max_dual_source_draw_buffers, | |
1848 FeatureInfo* feature_info) | 1910 FeatureInfo* feature_info) |
1849 : program_count_(0), | 1911 : program_count_(0), |
1850 have_context_(true), | 1912 have_context_(true), |
1851 program_cache_(program_cache), | 1913 program_cache_(program_cache), |
1852 max_varying_vectors_(max_varying_vectors), | 1914 max_varying_vectors_(max_varying_vectors), |
1915 max_dual_source_draw_buffers_(max_dual_source_draw_buffers), | |
1853 feature_info_(feature_info) {} | 1916 feature_info_(feature_info) {} |
1854 | 1917 |
1855 ProgramManager::~ProgramManager() { | 1918 ProgramManager::~ProgramManager() { |
1856 DCHECK(programs_.empty()); | 1919 DCHECK(programs_.empty()); |
1857 } | 1920 } |
1858 | 1921 |
1859 void ProgramManager::Destroy(bool have_context) { | 1922 void ProgramManager::Destroy(bool have_context) { |
1860 have_context_ = have_context; | 1923 have_context_ = have_context; |
1861 programs_.clear(); | 1924 programs_.clear(); |
1862 } | 1925 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1956 DCHECK(program); | 2019 DCHECK(program); |
1957 program->ClearUniforms(&zero_); | 2020 program->ClearUniforms(&zero_); |
1958 } | 2021 } |
1959 | 2022 |
1960 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { | 2023 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { |
1961 return index + element * 0x10000; | 2024 return index + element * 0x10000; |
1962 } | 2025 } |
1963 | 2026 |
1964 } // namespace gles2 | 2027 } // namespace gles2 |
1965 } // namespace gpu | 2028 } // namespace gpu |
OLD | NEW |