From 4ced44e3d571fdad017bdbf6f1e1834f67cfa963 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Wed, 15 Feb 2023 10:13:55 -0800 Subject: [PATCH 1/2] [Impeller] align SSBOs to 16 bytes to fix iOS shader validation issue. --- impeller/entity/contents/gradient_generator.h | 4 ++++ impeller/entity/contents/linear_gradient_contents.cc | 2 +- impeller/entity/contents/radial_gradient_contents.cc | 2 +- impeller/entity/contents/sweep_gradient_contents.cc | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/impeller/entity/contents/gradient_generator.h b/impeller/entity/contents/gradient_generator.h index 36f81e087d63f..366dfa511885e 100644 --- a/impeller/entity/contents/gradient_generator.h +++ b/impeller/entity/contents/gradient_generator.h @@ -20,6 +20,10 @@ namespace impeller { class Context; +/// Lower iOS version require alignment to be a multiple of 16, so the alignof +/// operator will not give correct results for most structs. +constexpr size_t kSSBOAlignOf = 16u; + /** * @brief Create a host visible texture that contains the gradient defined * by the provided gradient data. diff --git a/impeller/entity/contents/linear_gradient_contents.cc b/impeller/entity/contents/linear_gradient_contents.cc index 9ac82f82ffb8e..d4bcd5f9e6400 100644 --- a/impeller/entity/contents/linear_gradient_contents.cc +++ b/impeller/entity/contents/linear_gradient_contents.cc @@ -135,7 +135,7 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer, gradient_info.colors_length = colors.size(); auto color_buffer = host_buffer.Emplace( - colors.data(), colors.size() * sizeof(StopData), alignof(StopData)); + colors.data(), colors.size() * sizeof(StopData), kSSBOAlignOf); VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * diff --git a/impeller/entity/contents/radial_gradient_contents.cc b/impeller/entity/contents/radial_gradient_contents.cc index 5a5d7b0c5999f..e8b8125da62fc 100644 --- a/impeller/entity/contents/radial_gradient_contents.cc +++ b/impeller/entity/contents/radial_gradient_contents.cc @@ -71,7 +71,7 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer, gradient_info.colors_length = colors.size(); auto color_buffer = host_buffer.Emplace( - colors.data(), colors.size() * sizeof(StopData), alignof(StopData)); + colors.data(), colors.size() * sizeof(StopData), kSSBOAlignOf); VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * diff --git a/impeller/entity/contents/sweep_gradient_contents.cc b/impeller/entity/contents/sweep_gradient_contents.cc index 5c21614851885..1b74ca796894f 100644 --- a/impeller/entity/contents/sweep_gradient_contents.cc +++ b/impeller/entity/contents/sweep_gradient_contents.cc @@ -77,7 +77,7 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer, gradient_info.colors_length = colors.size(); auto color_buffer = host_buffer.Emplace( - colors.data(), colors.size() * sizeof(StopData), alignof(StopData)); + colors.data(), colors.size() * sizeof(StopData), kSSBOAlignOf); VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * From 7bd8d7869b3b8be6643d9a324efa4ca437a8fdb5 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Thu, 16 Feb 2023 10:38:54 -0800 Subject: [PATCH 2/2] use DefaultUniformAlignment --- impeller/entity/contents/gradient_generator.h | 4 ---- impeller/entity/contents/linear_gradient_contents.cc | 5 +++-- impeller/entity/contents/radial_gradient_contents.cc | 5 +++-- impeller/entity/contents/sweep_gradient_contents.cc | 5 +++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/impeller/entity/contents/gradient_generator.h b/impeller/entity/contents/gradient_generator.h index 366dfa511885e..36f81e087d63f 100644 --- a/impeller/entity/contents/gradient_generator.h +++ b/impeller/entity/contents/gradient_generator.h @@ -20,10 +20,6 @@ namespace impeller { class Context; -/// Lower iOS version require alignment to be a multiple of 16, so the alignof -/// operator will not give correct results for most structs. -constexpr size_t kSSBOAlignOf = 16u; - /** * @brief Create a host visible texture that contains the gradient defined * by the provided gradient data. diff --git a/impeller/entity/contents/linear_gradient_contents.cc b/impeller/entity/contents/linear_gradient_contents.cc index d4bcd5f9e6400..02d583e4686ca 100644 --- a/impeller/entity/contents/linear_gradient_contents.cc +++ b/impeller/entity/contents/linear_gradient_contents.cc @@ -134,8 +134,9 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer, auto colors = CreateGradientColors(colors_, stops_); gradient_info.colors_length = colors.size(); - auto color_buffer = host_buffer.Emplace( - colors.data(), colors.size() * sizeof(StopData), kSSBOAlignOf); + auto color_buffer = + host_buffer.Emplace(colors.data(), colors.size() * sizeof(StopData), + DefaultUniformAlignment()); VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * diff --git a/impeller/entity/contents/radial_gradient_contents.cc b/impeller/entity/contents/radial_gradient_contents.cc index e8b8125da62fc..3b475c29d3c10 100644 --- a/impeller/entity/contents/radial_gradient_contents.cc +++ b/impeller/entity/contents/radial_gradient_contents.cc @@ -70,8 +70,9 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer, auto colors = CreateGradientColors(colors_, stops_); gradient_info.colors_length = colors.size(); - auto color_buffer = host_buffer.Emplace( - colors.data(), colors.size() * sizeof(StopData), kSSBOAlignOf); + auto color_buffer = + host_buffer.Emplace(colors.data(), colors.size() * sizeof(StopData), + DefaultUniformAlignment()); VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * diff --git a/impeller/entity/contents/sweep_gradient_contents.cc b/impeller/entity/contents/sweep_gradient_contents.cc index 1b74ca796894f..897913c7c157c 100644 --- a/impeller/entity/contents/sweep_gradient_contents.cc +++ b/impeller/entity/contents/sweep_gradient_contents.cc @@ -76,8 +76,9 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer, auto colors = CreateGradientColors(colors_, stops_); gradient_info.colors_length = colors.size(); - auto color_buffer = host_buffer.Emplace( - colors.data(), colors.size() * sizeof(StopData), kSSBOAlignOf); + auto color_buffer = + host_buffer.Emplace(colors.data(), colors.size() * sizeof(StopData), + DefaultUniformAlignment()); VS::FrameInfo frame_info; frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *