-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Account for vec3 padding in Metal #181563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
afd5386
6f31d9c
1a223c3
32678fd
da9c5c7
686d632
89cef18
bc33acc
b277883
4ad9fc9
98c1785
0c8de5d
f20fbb5
22c3665
66933a0
964aabb
fb98434
9f5ea0b
7ecb72c
5f77232
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,14 +6,37 @@ | |
|
|
||
| namespace impeller { | ||
|
|
||
| size_t RuntimeUniformDescription::GetSize() const { | ||
| size_t size = dimensions.rows * dimensions.cols * bit_width / 8u; | ||
| size_t RuntimeUniformDescription::GetDartSize() const { | ||
| size_t size = 0; | ||
| if (!padding_layout.empty()) { | ||
| for (impeller::RuntimePaddingType byte_type : padding_layout) { | ||
| if (byte_type == RuntimePaddingType::kFloat) { | ||
| size += sizeof(float); | ||
| } | ||
| } | ||
| } else { | ||
| size = dimensions.rows * dimensions.cols * bit_width / 8u; | ||
| } | ||
| if (array_elements.value_or(0) > 0) { | ||
| // Covered by check on the line above. | ||
| // NOLINTNEXTLINE(bugprone-unchecked-optional-access) | ||
| size *= array_elements.value(); | ||
| } | ||
| return size; | ||
| } | ||
|
|
||
| size_t RuntimeUniformDescription::GetGPUSize() const { | ||
| size_t size = 0; | ||
| if (padding_layout.empty()) { | ||
| size = dimensions.rows * dimensions.cols * bit_width / 8u; | ||
| } else { | ||
| size = sizeof(float) * padding_layout.size(); | ||
| } | ||
| if (array_elements.value_or(0) > 0) { | ||
| // Covered by check on the line above. | ||
| // NOLINTNEXTLINE(bugprone-unchecked-optional-access) | ||
| size *= array_elements.value(); | ||
| } | ||
| size += sizeof(float) * struct_layout.size(); | ||
| return size; | ||
| } | ||
|
Comment on lines
+9
to
41
Contributor
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.
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. Omg now please call me handsome as well |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,35 +24,48 @@ | |
|
|
||
| namespace impeller { | ||
|
|
||
| namespace { | ||
| constexpr char kPaddingType = 0; | ||
| constexpr char kFloatType = 1; | ||
| } // namespace | ||
|
|
||
| // static | ||
| BufferView RuntimeEffectContents::EmplaceVulkanUniform( | ||
| const std::shared_ptr<const std::vector<uint8_t>>& input_data, | ||
| BufferView RuntimeEffectContents::EmplaceUniform( | ||
| const uint8_t* source_data, | ||
| HostBuffer& data_host_buffer, | ||
| const RuntimeUniformDescription& uniform, | ||
| size_t minimum_uniform_alignment) { | ||
| // TODO(jonahwilliams): rewrite this to emplace directly into | ||
| // HostBuffer. | ||
| std::vector<float> uniform_buffer; | ||
| uniform_buffer.reserve(uniform.struct_layout.size()); | ||
| size_t uniform_byte_index = 0u; | ||
| for (char byte_type : uniform.struct_layout) { | ||
| if (byte_type == kPaddingType) { | ||
| uniform_buffer.push_back(0.f); | ||
| } else { | ||
| FML_DCHECK(byte_type == kFloatType); | ||
| uniform_buffer.push_back(reinterpret_cast<const float*>( | ||
| input_data->data())[uniform_byte_index++]); | ||
| } | ||
| const RuntimeUniformDescription& uniform) { | ||
| size_t minimum_uniform_alignment = | ||
| data_host_buffer.GetMinimumUniformAlignment(); | ||
| size_t alignment = std::max(uniform.bit_width / 8, minimum_uniform_alignment); | ||
|
|
||
| if (uniform.padding_layout.empty()) { | ||
| return data_host_buffer.Emplace(source_data, uniform.GetGPUSize(), | ||
| alignment); | ||
| } | ||
|
|
||
| // If the uniform has a padding layout, we need to repack the data. | ||
| // We can do this by using the EmplaceProc to write directly to the | ||
| // HostBuffer. | ||
| return data_host_buffer.Emplace( | ||
| reinterpret_cast<const void*>(uniform_buffer.data()), | ||
| sizeof(float) * uniform_buffer.size(), minimum_uniform_alignment); | ||
| uniform.GetGPUSize(), alignment, | ||
| [&uniform, source_data](uint8_t* destination) { | ||
| size_t count = uniform.array_elements.value_or(1); | ||
| if (count == 0) { | ||
| // Make sure to run at least once. | ||
| count = 1; | ||
| } | ||
| size_t uniform_byte_index = 0u; | ||
| size_t struct_float_index = 0u; | ||
| auto* float_destination = reinterpret_cast<float*>(destination); | ||
| auto* float_source = reinterpret_cast<const float*>(source_data); | ||
|
|
||
| for (size_t i = 0; i < count; i++) { | ||
| for (RuntimePaddingType byte_type : uniform.padding_layout) { | ||
| if (byte_type == RuntimePaddingType::kPadding) { | ||
| float_destination[struct_float_index++] = 0.f; | ||
| } else { | ||
| FML_DCHECK(byte_type == RuntimePaddingType::kFloat); | ||
| float_destination[struct_float_index++] = | ||
| float_source[uniform_byte_index++]; | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
Comment on lines
27
to
+68
Contributor
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. |
||
| } | ||
|
|
||
| void RuntimeEffectContents::SetRuntimeStage( | ||
|
|
@@ -284,12 +297,8 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer, | |
| << "Uniform " << uniform.name | ||
| << " had unexpected type kFloat for Vulkan backend."; | ||
|
|
||
| size_t alignment = | ||
| std::max(uniform.bit_width / 8, | ||
| data_host_buffer.GetMinimumUniformAlignment()); | ||
| BufferView buffer_view = | ||
| data_host_buffer.Emplace(uniform_data_->data() + buffer_offset, | ||
| uniform.GetSize(), alignment); | ||
| BufferView buffer_view = EmplaceUniform( | ||
| uniform_data_->data() + buffer_offset, data_host_buffer, uniform); | ||
|
|
||
| ShaderUniformSlot uniform_slot; | ||
| uniform_slot.name = uniform.name.c_str(); | ||
|
|
@@ -298,7 +307,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer, | |
| DescriptorType::kUniformBuffer, uniform_slot, | ||
| std::move(metadata), std::move(buffer_view)); | ||
| buffer_index++; | ||
| buffer_offset += uniform.GetSize(); | ||
| buffer_offset += uniform.GetDartSize(); | ||
| buffer_location++; | ||
| break; | ||
| } | ||
|
|
@@ -309,12 +318,10 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer, | |
| uniform_slot.binding = uniform.location; | ||
| uniform_slot.name = uniform.name.c_str(); | ||
|
|
||
| pass.BindResource(ShaderStage::kFragment, | ||
| DescriptorType::kUniformBuffer, uniform_slot, | ||
| nullptr, | ||
| EmplaceVulkanUniform( | ||
| uniform_data_, data_host_buffer, uniform, | ||
| data_host_buffer.GetMinimumUniformAlignment())); | ||
| pass.BindResource( | ||
| ShaderStage::kFragment, DescriptorType::kUniformBuffer, | ||
| uniform_slot, nullptr, | ||
| EmplaceUniform(uniform_data_->data(), data_host_buffer, uniform)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.