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

Commit b5d2c05

Browse files
authored
[Impeller] Enable SSBOs in the Vulkan backend. (#40908)
[Impeller] Enable SSBOs in the Vulkan backend.
1 parent 37ea80f commit b5d2c05

File tree

8 files changed

+42
-14
lines changed

8 files changed

+42
-14
lines changed

impeller/compiler/code_gen_template.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ std::move({{ arg.argument_name }}){% if not loop.is_last %}, {% endif %}
162162
{% for buffer in buffers %}
163163
DescriptorSetLayout{
164164
{{buffer.binding}}, // binding = {{buffer.binding}}
165-
DescriptorType::kUniformBuffer, // descriptor_type = Uniform Buffer
165+
{{buffer.descriptor_type}}, // descriptor_type = {{buffer.descriptor_type}}
166166
{{to_shader_stage(shader_stage)}}, // shader_stage = {{to_shader_stage(shader_stage)}}
167167
},
168168
{% endfor %}
169169
{% for sampled_image in sampled_images %}
170170
DescriptorSetLayout{
171171
{{sampled_image.binding}}, // binding = {{sampled_image.binding}}
172-
DescriptorType::kSampledImage, // descriptor_type = Sampled Image
172+
{{sampled_image.descriptor_type}}, // descriptor_type = {{sampled_image.descriptor_type}}
173173
{{to_shader_stage(shader_stage)}}, // shader_stage = {{to_shader_stage(shader_stage)}}
174174
},
175175
{% endfor %}

impeller/compiler/reflector.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const {
205205
if (auto uniform_buffers_json =
206206
ReflectResources(shader_resources.uniform_buffers);
207207
uniform_buffers_json.has_value()) {
208-
for (const auto& uniform_buffer : uniform_buffers_json.value()) {
208+
for (auto uniform_buffer : uniform_buffers_json.value()) {
209+
uniform_buffer["descriptor_type"] = "DescriptorType::kUniformBuffer";
209210
buffers.emplace_back(std::move(uniform_buffer));
210211
}
211212
} else {
@@ -214,7 +215,8 @@ std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const {
214215
if (auto storage_buffers_json =
215216
ReflectResources(shader_resources.storage_buffers);
216217
storage_buffers_json.has_value()) {
217-
for (const auto& uniform_buffer : storage_buffers_json.value()) {
218+
for (auto uniform_buffer : storage_buffers_json.value()) {
219+
uniform_buffer["descriptor_type"] = "DescriptorType::kStorageBuffer";
218220
buffers.emplace_back(std::move(uniform_buffer));
219221
}
220222
} else {
@@ -244,12 +246,15 @@ std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const {
244246
}
245247
auto& sampled_images = root["sampled_images"] = nlohmann::json::array_t{};
246248
for (auto value : combined_sampled_images.value()) {
249+
value["descriptor_type"] = "DescriptorType::kSampledImage";
247250
sampled_images.emplace_back(std::move(value));
248251
}
249252
for (auto value : images.value()) {
253+
value["descriptor_type"] = "DescriptorType::kImage";
250254
sampled_images.emplace_back(std::move(value));
251255
}
252256
for (auto value : samplers.value()) {
257+
value["descriptor_type"] = "DescriptorType::kSampledSampler";
253258
sampled_images.emplace_back(std::move(value));
254259
}
255260
}

impeller/compiler/spirv_compiler.cc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,22 @@ static void SetDefaultLimitations(shaderc::CompileOptions& compiler_opts) {
208208
}
209209

210210
static void SetBindingBaseOffset(shaderc::CompileOptions& options) {
211-
constexpr uint32_t kFragBindingBase = 128;
212-
constexpr size_t kNumUniformKinds =
213-
static_cast<int>(shaderc_uniform_kind::shaderc_uniform_kind_buffer) + 1;
214-
for (size_t uniform_kind = 0; uniform_kind < kNumUniformKinds;
215-
uniform_kind++) {
211+
constexpr uint32_t kBindingBaseOffset = 64;
212+
static const shaderc_uniform_kind kUniformKinds[] = {
213+
shaderc_uniform_kind::shaderc_uniform_kind_sampler,
214+
shaderc_uniform_kind::shaderc_uniform_kind_texture,
215+
shaderc_uniform_kind::shaderc_uniform_kind_image,
216+
shaderc_uniform_kind::shaderc_uniform_kind_buffer, // UBOs
217+
shaderc_uniform_kind::shaderc_uniform_kind_storage_buffer, // SSBOs
218+
};
219+
220+
for (size_t i = 0u; i < sizeof(kUniformKinds) / sizeof(shaderc_uniform_kind);
221+
i++) {
216222
options.SetBindingBaseForStage(
217-
ToShaderCShaderKind(SourceType::kFragmentShader),
218-
static_cast<shaderc_uniform_kind>(uniform_kind), kFragBindingBase);
223+
shaderc_shader_kind::shaderc_fragment_shader, //
224+
kUniformKinds[i], //
225+
kBindingBaseOffset //
226+
);
219227
}
220228
}
221229

impeller/core/shader_types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ struct SampledImageSlot {
125125
};
126126

127127
enum class DescriptorType {
128-
kSampledImage,
129128
kUniformBuffer,
129+
kStorageBuffer,
130+
kSampledImage,
131+
kImage,
132+
kSampler,
130133
};
131134

132135
struct DescriptorSetLayout {

impeller/renderer/backend/vulkan/capabilities_vk.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ bool CapabilitiesVK::SupportsOffscreenMSAA() const {
310310

311311
// |Capabilities|
312312
bool CapabilitiesVK::SupportsSSBO() const {
313-
return false;
313+
return true;
314314
}
315315

316316
// |Capabilities|

impeller/renderer/backend/vulkan/debug_report_vk.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ DebugReportVK::Result DebugReportVK::OnDebugCallback(
183183
VALIDATION_LOG << stream.str();
184184
}
185185

186-
return Result::kAbort;
186+
return Result::kContinue;
187187
}
188188

189189
} // namespace impeller

impeller/renderer/backend/vulkan/descriptor_pool_vk.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ static vk::UniqueDescriptorPool CreatePool(const vk::Device& device,
1919
std::vector<vk::DescriptorPoolSize> pools = {
2020
{vk::DescriptorType::eCombinedImageSampler, pool_count},
2121
{vk::DescriptorType::eUniformBuffer, pool_count},
22+
{vk::DescriptorType::eStorageBuffer, pool_count},
23+
{vk::DescriptorType::eSampledImage, pool_count},
24+
{vk::DescriptorType::eSampler, pool_count},
2225
};
2326

2427
vk::DescriptorPoolCreateInfo pool_info;

impeller/renderer/backend/vulkan/formats_vk.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ constexpr vk::DescriptorSetLayoutBinding ToVKDescriptorSetLayoutBinding(
279279
case DescriptorType::kUniformBuffer:
280280
desc_type = vk::DescriptorType::eUniformBuffer;
281281
break;
282+
case DescriptorType::kStorageBuffer:
283+
desc_type = vk::DescriptorType::eStorageBuffer;
284+
break;
285+
case DescriptorType::kImage:
286+
desc_type = vk::DescriptorType::eSampledImage;
287+
break;
288+
case DescriptorType::kSampler:
289+
desc_type = vk::DescriptorType::eSampler;
290+
break;
282291
}
283292
binding.descriptorType = desc_type;
284293
binding.stageFlags = ToVkShaderStage(layout.shader_stage);

0 commit comments

Comments
 (0)