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

Commit bf58df8

Browse files
authored
[Impeller] Fix validation errors in RendererTest. (#46076)
Vulkan validation was tripping on the fact that renderer tests were rendering to the root render pass. This root render pass doesn't contain a stencil buffer. However, `MakeDefaultPipelineDescriptor` assumes a stencil and color attachment. The other backends are resilient to this mismatch since there is no compat render pass created upfront. But Vulkan was sad. This should only happen in the low level tests. In the higher levels of the framework, we have variants that make sure there is a pipeline pass and render pass compatibility. Fixes validations of the kind: ``` --- Vulkan Debug Report ---------------------------------------- | Severity: Error | Type: { Validation } | ID Name: VUID-vkCmdDraw-renderPass-02684 | ID Number: 1349015333 | Queue Breadcrumbs: [NONE] | CMD Buffer Breadcrumbs: [NONE] | Related Objects: RenderPass [16305153808034431137] [Playground Render Pass], RenderPass [18100546345029861533] [Compat Render Pass: BoxFade Pipeline] | Trigger: Validation Error: [ VUID-vkCmdDraw-renderPass-02684 ] Object 0: handle = 0xe2478b00000000a1, name = Playground Render Pass, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xfb320f000000009d, name = Compat Render Pass: BoxFade Pipeline, type = VK_OBJECT_TYPE_RENDER_PASS; | MessageID = 0x50685725 | vkCmdDraw: RenderPasses incompatible between active render pass w/ VkRenderPass 0xe2478b00000000a1[Playground Render Pass] and pipeline state object w/ VkRenderPass 0xfb320f000000009d[Compat Render Pass: BoxFade Pipeline] Attachment 4294967295 is not compatible with 1: The first is unused while the second is not.. The Vulkan spec states: The current render pass must be compatible with the renderPass member of the VkGraphicsPipelineCreateInfo structure specified when creating the VkPipeline bound to VK_PIPELINE_BIND_POINT_GRAPHICS (https://vulkan.lunarg.com/doc/view/1.3.224.1/mac/1.3-extensions/vkspec.html#VUID-vkCmdDraw-renderPass-02684) ----------------------------------------------------------------- ```
1 parent 0d7db40 commit bf58df8

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

impeller/renderer/backend/vulkan/pipeline_library_vk.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ static vk::AttachmentDescription CreatePlaceholderAttachmentDescription(
7575
/// spec:
7676
/// https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/chap8.html#renderpass-compatibility
7777
///
78-
static vk::UniqueRenderPass CreateRenderPass(const vk::Device& device,
79-
const PipelineDescriptor& desc) {
78+
static vk::UniqueRenderPass CreateCompatRenderPassForPipeline(
79+
const vk::Device& device,
80+
const PipelineDescriptor& desc) {
8081
std::vector<vk::AttachmentDescription> attachments;
8182

8283
std::vector<vk::AttachmentReference> color_refs;
@@ -128,6 +129,13 @@ static vk::UniqueRenderPass CreateRenderPass(const vk::Device& device,
128129
return {};
129130
}
130131

132+
// This pass is not used with the render pass. It is only necessary to tell
133+
// Vulkan the expected render pass layout. The actual pass will be created
134+
// later during render pass setup and will need to be compatible with this
135+
// one.
136+
ContextVK::SetDebugName(device, pass.get(),
137+
"Compat Render Pass: " + desc.GetLabel());
138+
131139
return std::move(pass);
132140
}
133141

@@ -332,7 +340,8 @@ std::unique_ptr<PipelineVK> PipelineLibraryVK::CreatePipeline(
332340
return nullptr;
333341
}
334342

335-
auto render_pass = CreateRenderPass(strong_device->GetDevice(), desc);
343+
auto render_pass =
344+
CreateCompatRenderPassForPipeline(strong_device->GetDevice(), desc);
336345
if (render_pass) {
337346
pipeline_info.setBasePipelineHandle(VK_NULL_HANDLE);
338347
pipeline_info.setSubpass(0);

impeller/renderer/renderer_unittests.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) {
5858
auto desc = BoxPipelineBuilder::MakeDefaultPipelineDescriptor(*context);
5959
ASSERT_TRUE(desc.has_value());
6060
desc->SetSampleCount(SampleCount::kCount4);
61+
desc->SetStencilAttachmentDescriptors(std::nullopt);
6162

6263
// Vertex buffer.
6364
VertexBufferBuilder<VS::PerVertexData> vertex_builder;
@@ -130,6 +131,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) {
130131
desc->SetCullMode(CullMode::kBackFace);
131132
desc->SetWindingOrder(WindingOrder::kCounterClockwise);
132133
desc->SetSampleCount(SampleCount::kCount4);
134+
desc->SetStencilAttachmentDescriptors(std::nullopt);
133135
auto pipeline =
134136
context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
135137
ASSERT_TRUE(pipeline);
@@ -219,6 +221,7 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) {
219221
auto desc = BoxPipelineBuilder::MakeDefaultPipelineDescriptor(*context);
220222
ASSERT_TRUE(desc.has_value());
221223
desc->SetSampleCount(SampleCount::kCount4);
224+
desc->SetStencilAttachmentDescriptors(std::nullopt);
222225
auto box_pipeline =
223226
context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
224227
ASSERT_TRUE(box_pipeline);
@@ -420,7 +423,9 @@ TEST_P(RendererTest, CanRenderInstanced) {
420423
->GetPipelineLibrary()
421424
->GetPipeline(PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(
422425
*GetContext())
423-
->SetSampleCount(SampleCount::kCount4))
426+
->SetSampleCount(SampleCount::kCount4)
427+
.SetStencilAttachmentDescriptors(std::nullopt))
428+
424429
.Get();
425430
ASSERT_TRUE(pipeline && pipeline->IsValid());
426431

@@ -459,6 +464,7 @@ TEST_P(RendererTest, CanBlitTextureToTexture) {
459464
auto desc = PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(*context);
460465
ASSERT_TRUE(desc.has_value());
461466
desc->SetSampleCount(SampleCount::kCount4);
467+
desc->SetStencilAttachmentDescriptors(std::nullopt);
462468
auto mipmaps_pipeline =
463469
context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
464470
ASSERT_TRUE(mipmaps_pipeline);
@@ -571,6 +577,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) {
571577
auto desc = PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(*context);
572578
ASSERT_TRUE(desc.has_value());
573579
desc->SetSampleCount(SampleCount::kCount4);
580+
desc->SetStencilAttachmentDescriptors(std::nullopt);
574581
auto mipmaps_pipeline =
575582
context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
576583
ASSERT_TRUE(mipmaps_pipeline);
@@ -702,6 +709,7 @@ TEST_P(RendererTest, CanGenerateMipmaps) {
702709
auto desc = PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(*context);
703710
ASSERT_TRUE(desc.has_value());
704711
desc->SetSampleCount(SampleCount::kCount4);
712+
desc->SetStencilAttachmentDescriptors(std::nullopt);
705713
auto mipmaps_pipeline =
706714
context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
707715
ASSERT_TRUE(mipmaps_pipeline);
@@ -818,6 +826,7 @@ TEST_P(RendererTest, TheImpeller) {
818826
PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(*context);
819827
ASSERT_TRUE(pipeline_descriptor.has_value());
820828
pipeline_descriptor->SetSampleCount(SampleCount::kCount4);
829+
pipeline_descriptor->SetStencilAttachmentDescriptors(std::nullopt);
821830
auto pipeline =
822831
context->GetPipelineLibrary()->GetPipeline(pipeline_descriptor).Get();
823832
ASSERT_TRUE(pipeline && pipeline->IsValid());
@@ -878,6 +887,7 @@ TEST_P(RendererTest, ArrayUniforms) {
878887
PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(*context);
879888
ASSERT_TRUE(pipeline_descriptor.has_value());
880889
pipeline_descriptor->SetSampleCount(SampleCount::kCount4);
890+
pipeline_descriptor->SetStencilAttachmentDescriptors(std::nullopt);
881891
auto pipeline =
882892
context->GetPipelineLibrary()->GetPipeline(pipeline_descriptor).Get();
883893
ASSERT_TRUE(pipeline && pipeline->IsValid());
@@ -934,6 +944,7 @@ TEST_P(RendererTest, InactiveUniforms) {
934944
PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(*context);
935945
ASSERT_TRUE(pipeline_descriptor.has_value());
936946
pipeline_descriptor->SetSampleCount(SampleCount::kCount4);
947+
pipeline_descriptor->SetStencilAttachmentDescriptors(std::nullopt);
937948
auto pipeline =
938949
context->GetPipelineLibrary()->GetPipeline(pipeline_descriptor).Get();
939950
ASSERT_TRUE(pipeline && pipeline->IsValid());
@@ -1120,6 +1131,7 @@ TEST_P(RendererTest, StencilMask) {
11201131
ASSERT_TRUE(vertex_buffer);
11211132

11221133
desc->SetSampleCount(SampleCount::kCount4);
1134+
desc->SetStencilAttachmentDescriptors(std::nullopt);
11231135

11241136
auto bridge = CreateTextureForFixture("bay_bridge.jpg");
11251137
auto boston = CreateTextureForFixture("boston.jpg");

0 commit comments

Comments
 (0)