Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Compute in Vulkan #42294

Merged
merged 17 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions impeller/playground/compute_playground_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ class ComputePlaygroundTest
FML_DISALLOW_COPY_AND_ASSIGN(ComputePlaygroundTest);
};

// TODO(dnfield): Remove this macro as Vulkan support reaches parith with Metal.
#define INSTANTIATE_COMPUTE_SUITE_WITH_VULKAN(playground) \
INSTANTIATE_TEST_SUITE_P( \
Compute, playground, \
::testing::Values(PlaygroundBackend::kMetal, \
PlaygroundBackend::kVulkan), \
[](const ::testing::TestParamInfo<ComputePlaygroundTest::ParamType>& \
info) { return PlaygroundBackendToString(info.param); });

#define INSTANTIATE_COMPUTE_SUITE(playground) \
INSTANTIATE_TEST_SUITE_P( \
Compute, playground, ::testing::Values(PlaygroundBackend::kMetal), \
Expand Down
19 changes: 17 additions & 2 deletions impeller/renderer/backend/vulkan/capabilities_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,19 @@ bool CapabilitiesVK::SetDevice(const vk::PhysicalDevice& device) {

device_properties_ = device.getProperties();

auto physical_properties_2 =
device.getProperties2<vk::PhysicalDeviceProperties2,
vk::PhysicalDeviceSubgroupProperties>();

// Currently shaders only want access to arithmetic subgroup features.
// If that changes this needs to get updated, and so does Metal (which right
// now assumes it from compile time flags based on the MSL target version).

supports_compute_subgroups_ =
!!(physical_properties_2.get<vk::PhysicalDeviceSubgroupProperties>()
.supportedOperations &
vk::SubgroupFeatureFlagBits::eArithmetic);

return true;
}

Expand Down Expand Up @@ -330,12 +343,14 @@ bool CapabilitiesVK::SupportsFramebufferFetch() const {

// |Capabilities|
bool CapabilitiesVK::SupportsCompute() const {
return false;
// Vulkan 1.1 requires support for compute.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, this will work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not wired up yet. But capabilities wise it is supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More specifically,

needs to get implemented for this to work in impeller, but the device will support it even though Impeller doesn't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll start crashing on drawPoints on Vulkan if this returns true before its completely ready?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, yes. I'm not sure how big of a deal that is. I could make this patch still return false here but true on supports subgroups for now...?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(We'll hit a codepath that ends up doing an IMPELLER_UNIMPLEMENTED which will abort)

return true;
}

// |Capabilities|
bool CapabilitiesVK::SupportsComputeSubgroups() const {
return false;
// Set by |SetDevice|.
return supports_compute_subgroups_;
}

// |Capabilities|
Expand Down
1 change: 1 addition & 0 deletions impeller/renderer/backend/vulkan/capabilities_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class CapabilitiesVK final : public Capabilities,
PixelFormat color_format_ = PixelFormat::kUnknown;
PixelFormat depth_stencil_format_ = PixelFormat::kUnknown;
vk::PhysicalDeviceProperties device_properties_;
bool supports_compute_subgroups_ = false;
bool is_valid_ = false;

bool HasExtension(const std::string& ext) const;
Expand Down
3 changes: 2 additions & 1 deletion impeller/renderer/compute_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void ComputePass::SetThreadGroupSize(const ISize& size) {

bool ComputePass::AddCommand(ComputeCommand command) {
if (!command) {
VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
VALIDATION_LOG
<< "Attempted to add an invalid command to the compute pass.";
return false;
}

Expand Down
9 changes: 9 additions & 0 deletions impeller/renderer/compute_subgroup_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ namespace testing {
using ComputeSubgroupTest = ComputePlaygroundTest;
INSTANTIATE_COMPUTE_SUITE(ComputeSubgroupTest);

using ComputeMetalAndVulkanSubgroupTest = ComputePlaygroundTest;
INSTANTIATE_COMPUTE_SUITE_WITH_VULKAN(ComputeMetalAndVulkanSubgroupTest);

TEST_P(ComputeMetalAndVulkanSubgroupTest, CapabilitiesSuportSubgroups) {
auto context = GetContext();
ASSERT_TRUE(context);
ASSERT_TRUE(context->GetCapabilities()->SupportsComputeSubgroups());
}

TEST_P(ComputeSubgroupTest, PathPlayground) {
// Renders stroked SVG paths in an interactive playground.
using SS = StrokeComputeShader;
Expand Down
9 changes: 9 additions & 0 deletions impeller/renderer/compute_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ namespace testing {
using ComputeTest = ComputePlaygroundTest;
INSTANTIATE_COMPUTE_SUITE(ComputeTest);

using ComputeMetalAndVulkanSubgroupTest = ComputePlaygroundTest;
INSTANTIATE_COMPUTE_SUITE_WITH_VULKAN(ComputeMetalAndVulkanSubgroupTest);

TEST_P(ComputeMetalAndVulkanSubgroupTest, CapabilitiesReportSupport) {
auto context = GetContext();
ASSERT_TRUE(context);
ASSERT_TRUE(context->GetCapabilities()->SupportsCompute());
}

TEST_P(ComputeTest, CanCreateComputePass) {
using CS = SampleComputeShader;
auto context = GetContext();
Expand Down