From 8348fd411b80336dbf013305e861570c50d53f40 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 30 Sep 2019 13:22:18 -0400 Subject: Store formats in pipeline and scripts. (#677) This CL removes the unique_ptr from the probe and buffer classes and stores pointers instead. The lifetimes are managed by the pipeline and script objects. This removes the need to do the copy and assignment operators for the format class. --- src/pipeline.cc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/pipeline.cc') diff --git a/src/pipeline.cc b/src/pipeline.cc index 017a714..5d0d030 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -53,14 +53,7 @@ std::unique_ptr Pipeline::Clone() const { clone->index_buffer_ = index_buffer_; clone->fb_width_ = fb_width_; clone->fb_height_ = fb_height_; - - for (const auto& args : set_arg_values_) { - clone->set_arg_values_.push_back({}); - clone->set_arg_values_.back().name = args.name; - clone->set_arg_values_.back().ordinal = args.ordinal; - clone->set_arg_values_.back().fmt = MakeUnique(*args.fmt); - clone->set_arg_values_.back().value = args.value; - } + clone->set_arg_values_ = set_arg_values_; if (!opencl_pod_buffers_.empty()) { // Generate specific buffers for the clone. @@ -317,21 +310,27 @@ Result Pipeline::SetPushConstantBuffer(Buffer* buf) { return {}; } -std::unique_ptr Pipeline::GenerateDefaultColorAttachmentBuffer() const { +std::unique_ptr Pipeline::GenerateDefaultColorAttachmentBuffer() { FormatParser fp; + auto fmt = fp.Parse(kDefaultColorBufferFormat); std::unique_ptr buf = MakeUnique(BufferType::kColor); buf->SetName(kGeneratedColorBuffer); - buf->SetFormat(fp.Parse(kDefaultColorBufferFormat)); + buf->SetFormat(fmt.get()); + + formats_.push_back(std::move(fmt)); return buf; } -std::unique_ptr Pipeline::GenerateDefaultDepthAttachmentBuffer() const { +std::unique_ptr Pipeline::GenerateDefaultDepthAttachmentBuffer() { FormatParser fp; + auto fmt = fp.Parse(kDefaultDepthBufferFormat); std::unique_ptr buf = MakeUnique(BufferType::kDepth); buf->SetName(kGeneratedDepthBuffer); - buf->SetFormat(fp.Parse(kDefaultDepthBufferFormat)); + buf->SetFormat(fmt.get()); + + formats_.push_back(std::move(fmt)); return buf; } @@ -551,7 +550,9 @@ Result Pipeline::GenerateOpenCLPodBuffers() { // byte-based and it simplifies the logic for sizing below. FormatParser fp; auto fmt = fp.Parse("R8_UINT"); - buffer->SetFormat(std::move(fmt)); + buffer->SetFormat(fmt.get()); + formats_.push_back(std::move(fmt)); + buffer->SetName(GetName() + "_pod_buffer_" + std::to_string(descriptor_set) + "_" + std::to_string(binding)); @@ -567,6 +568,7 @@ Result Pipeline::GenerateOpenCLPodBuffers() { if (buffer->ValueCount() < offset + arg_size) { buffer->SetSizeInElements(offset + arg_size); } + // Check the data size. if (arg_size != arg_info.fmt->SizeInBytes()) { std::string message = "SET command uses incorrect data size: kernel " + @@ -578,6 +580,7 @@ Result Pipeline::GenerateOpenCLPodBuffers() { } return Result(message); } + Result r = buffer->SetDataWithOffset({arg_info.value}, offset); if (!r.IsSuccess()) return r; -- cgit v1.2.3