This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] create a 300 es variant of all GLES shaders to support UBO binding. #56960
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1ad1f94
ubo baby.
4fe533c
move to method on shell, null check ubo lookup.
5f46d14
more updates.
dd05a42
add missing override.
bd1e80d
one more override.
f2442f2
++
678fb0e
Merge branch 'main' of github.com:flutter/engine into do_ubo_baby
854355c
cleanups.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ enum class RuntimeStageBackend { | |
| kSkSL, | ||
| kMetal, | ||
| kOpenGLES, | ||
| kOpenGLES3, | ||
| kVulkan, | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| #include <vector> | ||
|
|
||
| #include "impeller/base/validation.h" | ||
| #include "impeller/core/buffer_view.h" | ||
| #include "impeller/core/device_buffer.h" | ||
| #include "impeller/core/shader_types.h" | ||
| #include "impeller/renderer/backend/gles/device_buffer_gles.h" | ||
| #include "impeller/renderer/backend/gles/formats_gles.h" | ||
|
|
@@ -101,6 +103,38 @@ bool BufferBindingsGLES::ReadUniformsBindings(const ProcTableGLES& gl, | |
| if (!gl.IsProgram(program)) { | ||
| return false; | ||
| } | ||
| program_handle_ = program; | ||
| if (gl.GetDescription()->GetGlVersion().IsAtLeast(Version{3, 0, 0})) { | ||
| return ReadUniformsBindingsV3(gl, program); | ||
| } | ||
| return ReadUniformsBindingsV2(gl, program); | ||
| } | ||
|
|
||
| bool BufferBindingsGLES::ReadUniformsBindingsV3(const ProcTableGLES& gl, | ||
| GLuint program) { | ||
| program_handle_ = program; | ||
| GLint uniform_blocks = 0; | ||
| gl.GetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &uniform_blocks); | ||
| for (GLint i = 0; i < uniform_blocks; i++) { | ||
| GLint name_length = 0; | ||
| gl.GetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_NAME_LENGTH, | ||
| &name_length); | ||
|
|
||
| std::vector<GLchar> name; | ||
| name.resize(name_length); | ||
| GLint length = 0; | ||
| gl.GetActiveUniformBlockName(program, i, name_length, &length, name.data()); | ||
|
|
||
| GLuint block_index = gl.GetUniformBlockIndex(program, name.data()); | ||
| ubo_locations_[std::string{name.data(), static_cast<size_t>(length)}] = | ||
| std::make_pair(block_index, i); | ||
| } | ||
| use_ubo_ = true; | ||
| return ReadUniformsBindingsV2(gl, program); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nicely done. |
||
| } | ||
|
|
||
| bool BufferBindingsGLES::ReadUniformsBindingsV2(const ProcTableGLES& gl, | ||
| GLuint program) { | ||
| GLint max_name_size = 0; | ||
| gl.GetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_size); | ||
|
|
||
|
|
@@ -139,6 +173,9 @@ bool BufferBindingsGLES::ReadUniformsBindings(const ProcTableGLES& gl, | |
|
|
||
| auto location = gl.GetUniformLocation(program, name.data()); | ||
| if (location == -1) { | ||
| if (use_ubo_) { | ||
| continue; | ||
| } | ||
| VALIDATION_LOG << "Could not query the location of an active uniform."; | ||
| return false; | ||
| } | ||
|
|
@@ -280,8 +317,47 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl, | |
| } | ||
| const DeviceBufferGLES& device_buffer_gles = | ||
| DeviceBufferGLES::Cast(*device_buffer); | ||
|
|
||
| if (use_ubo_) { | ||
| return BindUniformBufferV3(gl, buffer.resource, metadata, | ||
| device_buffer_gles); | ||
| } | ||
| return BindUniformBufferV2(gl, buffer.resource, metadata, device_buffer_gles); | ||
| } | ||
|
|
||
| bool BufferBindingsGLES::BindUniformBufferV3( | ||
| const ProcTableGLES& gl, | ||
| const BufferView& buffer, | ||
| const ShaderMetadata* metadata, | ||
| const DeviceBufferGLES& device_buffer_gles) { | ||
| absl::flat_hash_map<std::string, std::pair<GLint, GLuint>>::iterator it = | ||
| ubo_locations_.find(metadata->name); | ||
| if (it == ubo_locations_.end()) { | ||
| return BindUniformBufferV2(gl, buffer, metadata, device_buffer_gles); | ||
| } | ||
| const auto& [block_index, binding_point] = it->second; | ||
| gl.UniformBlockBinding(program_handle_, block_index, binding_point); | ||
|
|
||
| if (!device_buffer_gles.BindAndUploadDataIfNecessary( | ||
| DeviceBufferGLES::BindingType::kUniformBuffer)) { | ||
| return false; | ||
| } | ||
| auto handle = device_buffer_gles.GetHandle(); | ||
| if (!handle.has_value()) { | ||
| return false; | ||
| } | ||
| gl.BindBufferRange(GL_UNIFORM_BUFFER, binding_point, handle.value(), | ||
| buffer.GetRange().offset, buffer.GetRange().length); | ||
| return true; | ||
| } | ||
|
|
||
| bool BufferBindingsGLES::BindUniformBufferV2( | ||
| const ProcTableGLES& gl, | ||
| const BufferView& buffer, | ||
| const ShaderMetadata* metadata, | ||
| const DeviceBufferGLES& device_buffer_gles) { | ||
| const uint8_t* buffer_ptr = | ||
| device_buffer_gles.GetBufferData() + buffer.resource.GetRange().offset; | ||
| device_buffer_gles.GetBufferData() + buffer.GetRange().offset; | ||
|
|
||
| if (metadata->members.empty()) { | ||
| VALIDATION_LOG << "Uniform buffer had no members. This is currently " | ||
|
|
@@ -320,64 +396,46 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl, | |
| reinterpret_cast<const GLfloat*>(array_element_buffer.data()); | ||
| } | ||
|
|
||
| switch (member.type) { | ||
| case ShaderType::kFloat: | ||
| switch (member.size) { | ||
| case sizeof(Matrix): | ||
| gl.UniformMatrix4fv(location, // location | ||
| element_count, // count | ||
| GL_FALSE, // normalize | ||
| buffer_data // data | ||
| ); | ||
| continue; | ||
| case sizeof(Vector4): | ||
| gl.Uniform4fv(location, // location | ||
| element_count, // count | ||
| buffer_data // data | ||
| ); | ||
| continue; | ||
| case sizeof(Vector3): | ||
| gl.Uniform3fv(location, // location | ||
| element_count, // count | ||
| buffer_data // data | ||
| ); | ||
| continue; | ||
| case sizeof(Vector2): | ||
| gl.Uniform2fv(location, // location | ||
| element_count, // count | ||
| buffer_data // data | ||
| ); | ||
| continue; | ||
| case sizeof(Scalar): | ||
| gl.Uniform1fv(location, // location | ||
| element_count, // count | ||
| buffer_data // data | ||
| ); | ||
| continue; | ||
| } | ||
| VALIDATION_LOG << "Size " << member.size | ||
| << " could not be mapped ShaderType::kFloat for key: " | ||
| << member.name; | ||
| case ShaderType::kBoolean: | ||
| case ShaderType::kSignedByte: | ||
| case ShaderType::kUnsignedByte: | ||
| case ShaderType::kSignedShort: | ||
| case ShaderType::kUnsignedShort: | ||
| case ShaderType::kSignedInt: | ||
| case ShaderType::kUnsignedInt: | ||
| case ShaderType::kSignedInt64: | ||
| case ShaderType::kUnsignedInt64: | ||
| case ShaderType::kAtomicCounter: | ||
| case ShaderType::kUnknown: | ||
| case ShaderType::kVoid: | ||
| case ShaderType::kHalfFloat: | ||
| case ShaderType::kDouble: | ||
| case ShaderType::kStruct: | ||
| case ShaderType::kImage: | ||
| case ShaderType::kSampledImage: | ||
| case ShaderType::kSampler: | ||
| VALIDATION_LOG << "Could not bind uniform buffer data for key: " | ||
| << member.name << " : " << static_cast<int>(member.type); | ||
| if (member.type != ShaderType::kFloat) { | ||
| VALIDATION_LOG << "Could not bind uniform buffer data for key: " | ||
| << member.name << " : " << static_cast<int>(member.type); | ||
| return false; | ||
| } | ||
|
|
||
| switch (member.size) { | ||
| case sizeof(Matrix): | ||
| gl.UniformMatrix4fv(location, // location | ||
| element_count, // count | ||
| GL_FALSE, // normalize | ||
| buffer_data // data | ||
| ); | ||
| continue; | ||
| case sizeof(Vector4): | ||
| gl.Uniform4fv(location, // location | ||
| element_count, // count | ||
| buffer_data // data | ||
| ); | ||
| continue; | ||
| case sizeof(Vector3): | ||
| gl.Uniform3fv(location, // location | ||
| element_count, // count | ||
| buffer_data // data | ||
| ); | ||
| continue; | ||
| case sizeof(Vector2): | ||
| gl.Uniform2fv(location, // location | ||
| element_count, // count | ||
| buffer_data // data | ||
| ); | ||
| continue; | ||
| case sizeof(Scalar): | ||
| gl.Uniform1fv(location, // location | ||
| element_count, // count | ||
| buffer_data // data | ||
| ); | ||
| continue; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| default: | ||
| VALIDATION_LOG << "Invalid member size binding: " << member.size; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Paranoid note: Does the name include the NULL terminator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetActiveUniformBlock.xhtml it does