Skip to content

Commit

Permalink
Add render pass and pipeline sample count validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 026dcd1 commit 603b915
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
5 changes: 1 addition & 4 deletions impeller/renderer/backend/metal/pipeline_library_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

PipelineLibraryMTL::~PipelineLibraryMTL() = default;

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

for (const auto& entry : desc.GetStageEntrypoints()) {
if (entry.first == ShaderStage::kVertex) {
Expand Down Expand Up @@ -53,8 +52,6 @@
descriptor.stencilAttachmentPixelFormat =
ToMTLPixelFormat(desc.GetStencilPixelFormat());

descriptor.sampleCount = 4u;

return descriptor;
}

Expand Down
11 changes: 11 additions & 0 deletions impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ static bool Bind(PassBindingsCache& pass,
return true;
};

const auto target_sample_count = render_target_.GetSampleCount();

fml::closure pop_debug_marker = [encoder]() { [encoder popDebugGroup]; };
for (const auto& command : commands_) {
if (command.index_count == 0u) {
Expand All @@ -401,6 +403,14 @@ static bool Bind(PassBindingsCache& pass,
} else {
auto_pop_debug_marker.Release();
}

if (target_sample_count !=
command.pipeline->GetDescriptor().GetSampleCount()) {
VALIDATION_LOG << "Pipeline for command and the render target disagree "
"on sample counts.";
return false;
}

pass_bindings.SetRenderPipelineState(
PipelineMTL::Cast(*command.pipeline).GetMTLRenderPipelineState());
pass_bindings.SetDepthStencilState(
Expand Down Expand Up @@ -447,6 +457,7 @@ static bool Bind(PassBindingsCache& pass,

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

Expand Down
6 changes: 3 additions & 3 deletions impeller/renderer/pipeline_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ struct PipelineBuilder {
FragmentShader::kEntrypointName, ShaderStage::kFragment);

if (!vertex_function || !fragment_function) {
FML_LOG(ERROR) << "Could not resolve pipeline entrypoint(s) '"
VALIDATION_LOG << "Could not resolve pipeline entrypoint(s) '"
<< VertexShader::kEntrypointName << "' and '"
<< FragmentShader::kEntrypointName
<< "' for pipline named '" << VertexShader::kLabel
<< "' for pipeline named '" << VertexShader::kLabel
<< "'.";
return false;
}
Expand All @@ -86,7 +86,7 @@ struct PipelineBuilder {
auto vertex_descriptor = std::make_shared<VertexDescriptor>();
if (!vertex_descriptor->SetStageInputs(
VertexShader::kAllShaderStageInputs)) {
FML_LOG(ERROR)
VALIDATION_LOG
<< "Could not configure vertex descriptor for pipeline named '"
<< VertexShader::kLabel << "'.";
return false;
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/pipeline_descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ PipelineDescriptor& PipelineDescriptor::SetLabel(std::string label) {
return *this;
}

PipelineDescriptor& PipelineDescriptor::SetSampleCount(size_t samples) {
PipelineDescriptor& PipelineDescriptor::SetSampleCount(SampleCount samples) {
sample_count_ = samples;
return *this;
}
Expand Down
6 changes: 3 additions & 3 deletions impeller/renderer/pipeline_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {

const std::string& GetLabel() const;

PipelineDescriptor& SetSampleCount(size_t samples);
PipelineDescriptor& SetSampleCount(SampleCount samples);

size_t GetSampleCount() const { return sample_count_; }
SampleCount GetSampleCount() const { return sample_count_; }

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

private:
std::string label_;
size_t sample_count_ = 1;
SampleCount sample_count_ = SampleCount::kCount1;
std::map<ShaderStage, std::shared_ptr<const ShaderFunction>> entrypoints_;
std::map<size_t /* index */, ColorAttachmentDescriptor>
color_attachment_descriptors_;
Expand Down
7 changes: 7 additions & 0 deletions impeller/renderer/render_target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ void RenderTarget::IterateAllAttachments(
}
}

SampleCount RenderTarget::GetSampleCount() const {
if (auto found = colors_.find(0u); found != colors_.end()) {
return found->second.texture->GetTextureDescriptor().sample_count;
}
return SampleCount::kCount1;
}

bool RenderTarget::HasColorAttachment(size_t index) const {
if (auto found = colors_.find(index); found != colors_.end()) {
return true;
Expand Down
6 changes: 6 additions & 0 deletions impeller/renderer/render_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ class RenderTarget {
ISize size,
std::string label = "Offscreen");

static RenderTarget CreateMSAA(const Context& context,
std::shared_ptr<Texture> resolve_texture,
std::string label = "Offscreen");

RenderTarget();

~RenderTarget();

bool IsValid() const;

SampleCount GetSampleCount() const;

bool HasColorAttachment(size_t index) const;

ISize GetRenderTargetSize() const;
Expand Down

0 comments on commit 603b915

Please sign in to comment.