Add render pass and pipeline sample count validation.

This commit is contained in:
Chinmay Garde
2021-12-01 10:21:38 -08:00
committed by Dan Field
parent f9d781df9b
commit faff08173b
7 changed files with 32 additions and 11 deletions

View File

@@ -16,12 +16,11 @@ PipelineLibraryMTL::PipelineLibraryMTL(id<MTLDevice> device)
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) {
@@ -53,8 +52,6 @@ static MTLRenderPipelineDescriptor* GetMTLRenderPipelineDescriptor(
descriptor.stencilAttachmentPixelFormat =
ToMTLPixelFormat(desc.GetStencilPixelFormat());
descriptor.sampleCount = 4u;
return descriptor;
}

View File

@@ -388,6 +388,8 @@ bool RenderPassMTL::EncodeCommands(Allocator& allocator,
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) {
@@ -401,6 +403,14 @@ bool RenderPassMTL::EncodeCommands(Allocator& allocator,
} 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(
@@ -447,6 +457,7 @@ bool RenderPassMTL::EncodeCommands(Allocator& allocator,
bool RenderPassMTL::AddCommand(Command command) {
if (!command) {
VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
return false;
}

View File

@@ -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;
}
@@ -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;

View File

@@ -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;
}

View File

@@ -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);
@@ -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_;

View File

@@ -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;

View File

@@ -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;