Skip to content

Commit 603b915

Browse files
chinmaygardednfield
authored andcommitted
Add render pass and pipeline sample count validation.
1 parent 026dcd1 commit 603b915

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

impeller/renderer/backend/metal/pipeline_library_mtl.mm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
PipelineLibraryMTL::~PipelineLibraryMTL() = default;
1818

19-
// TODO(csg): Make PipelineDescriptor a struct and move this to formats_mtl.
2019
static MTLRenderPipelineDescriptor* GetMTLRenderPipelineDescriptor(
2120
const PipelineDescriptor& desc) {
2221
auto descriptor = [[MTLRenderPipelineDescriptor alloc] init];
2322
descriptor.label = @(desc.GetLabel().c_str());
24-
descriptor.sampleCount = desc.GetSampleCount();
23+
descriptor.sampleCount = static_cast<NSUInteger>(desc.GetSampleCount());
2524

2625
for (const auto& entry : desc.GetStageEntrypoints()) {
2726
if (entry.first == ShaderStage::kVertex) {
@@ -53,8 +52,6 @@
5352
descriptor.stencilAttachmentPixelFormat =
5453
ToMTLPixelFormat(desc.GetStencilPixelFormat());
5554

56-
descriptor.sampleCount = 4u;
57-
5855
return descriptor;
5956
}
6057

impeller/renderer/backend/metal/render_pass_mtl.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ static bool Bind(PassBindingsCache& pass,
388388
return true;
389389
};
390390

391+
const auto target_sample_count = render_target_.GetSampleCount();
392+
391393
fml::closure pop_debug_marker = [encoder]() { [encoder popDebugGroup]; };
392394
for (const auto& command : commands_) {
393395
if (command.index_count == 0u) {
@@ -401,6 +403,14 @@ static bool Bind(PassBindingsCache& pass,
401403
} else {
402404
auto_pop_debug_marker.Release();
403405
}
406+
407+
if (target_sample_count !=
408+
command.pipeline->GetDescriptor().GetSampleCount()) {
409+
VALIDATION_LOG << "Pipeline for command and the render target disagree "
410+
"on sample counts.";
411+
return false;
412+
}
413+
404414
pass_bindings.SetRenderPipelineState(
405415
PipelineMTL::Cast(*command.pipeline).GetMTLRenderPipelineState());
406416
pass_bindings.SetDepthStencilState(
@@ -447,6 +457,7 @@ static bool Bind(PassBindingsCache& pass,
447457

448458
bool RenderPassMTL::AddCommand(Command command) {
449459
if (!command) {
460+
VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
450461
return false;
451462
}
452463

impeller/renderer/pipeline_builder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ struct PipelineBuilder {
6969
FragmentShader::kEntrypointName, ShaderStage::kFragment);
7070

7171
if (!vertex_function || !fragment_function) {
72-
FML_LOG(ERROR) << "Could not resolve pipeline entrypoint(s) '"
72+
VALIDATION_LOG << "Could not resolve pipeline entrypoint(s) '"
7373
<< VertexShader::kEntrypointName << "' and '"
7474
<< FragmentShader::kEntrypointName
75-
<< "' for pipline named '" << VertexShader::kLabel
75+
<< "' for pipeline named '" << VertexShader::kLabel
7676
<< "'.";
7777
return false;
7878
}
@@ -86,7 +86,7 @@ struct PipelineBuilder {
8686
auto vertex_descriptor = std::make_shared<VertexDescriptor>();
8787
if (!vertex_descriptor->SetStageInputs(
8888
VertexShader::kAllShaderStageInputs)) {
89-
FML_LOG(ERROR)
89+
VALIDATION_LOG
9090
<< "Could not configure vertex descriptor for pipeline named '"
9191
<< VertexShader::kLabel << "'.";
9292
return false;

impeller/renderer/pipeline_descriptor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PipelineDescriptor& PipelineDescriptor::SetLabel(std::string label) {
6161
return *this;
6262
}
6363

64-
PipelineDescriptor& PipelineDescriptor::SetSampleCount(size_t samples) {
64+
PipelineDescriptor& PipelineDescriptor::SetSampleCount(SampleCount samples) {
6565
sample_count_ = samples;
6666
return *this;
6767
}

impeller/renderer/pipeline_descriptor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
3232

3333
const std::string& GetLabel() const;
3434

35-
PipelineDescriptor& SetSampleCount(size_t samples);
35+
PipelineDescriptor& SetSampleCount(SampleCount samples);
3636

37-
size_t GetSampleCount() const { return sample_count_; }
37+
SampleCount GetSampleCount() const { return sample_count_; }
3838

3939
PipelineDescriptor& AddStageEntrypoint(
4040
std::shared_ptr<const ShaderFunction> function);
@@ -97,7 +97,7 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
9797

9898
private:
9999
std::string label_;
100-
size_t sample_count_ = 1;
100+
SampleCount sample_count_ = SampleCount::kCount1;
101101
std::map<ShaderStage, std::shared_ptr<const ShaderFunction>> entrypoints_;
102102
std::map<size_t /* index */, ColorAttachmentDescriptor>
103103
color_attachment_descriptors_;

impeller/renderer/render_target.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ void RenderTarget::IterateAllAttachments(
101101
}
102102
}
103103

104+
SampleCount RenderTarget::GetSampleCount() const {
105+
if (auto found = colors_.find(0u); found != colors_.end()) {
106+
return found->second.texture->GetTextureDescriptor().sample_count;
107+
}
108+
return SampleCount::kCount1;
109+
}
110+
104111
bool RenderTarget::HasColorAttachment(size_t index) const {
105112
if (auto found = colors_.find(index); found != colors_.end()) {
106113
return true;

impeller/renderer/render_target.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ class RenderTarget {
2222
ISize size,
2323
std::string label = "Offscreen");
2424

25+
static RenderTarget CreateMSAA(const Context& context,
26+
std::shared_ptr<Texture> resolve_texture,
27+
std::string label = "Offscreen");
28+
2529
RenderTarget();
2630

2731
~RenderTarget();
2832

2933
bool IsValid() const;
3034

35+
SampleCount GetSampleCount() const;
36+
3137
bool HasColorAttachment(size_t index) const;
3238

3339
ISize GetRenderTargetSize() const;

0 commit comments

Comments
 (0)