diff options
author | alan-baker <alanbaker@google.com> | 2019-07-23 16:12:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-23 16:12:32 -0400 |
commit | af34a92f54c9c43973d52d8b785cb3df207f18da (patch) | |
tree | be314eb1359fe3a6cd5d63032afd270b9ddee94d /src | |
parent | 7bc793fa18d8f8a518492ed75ed414683c704236 (diff) | |
download | amber-af34a92f54c9c43973d52d8b785cb3df207f18da.tar.gz |
Fix OpenCL pipeline derivatives (#593)
* SET commands properly cloned
* if cloned after buffers are generated, then the clone generates its
own buffers
* Updated tests
Diffstat (limited to 'src')
-rw-r--r-- | src/pipeline.cc | 6 | ||||
-rw-r--r-- | src/pipeline_test.cc | 86 |
2 files changed, 92 insertions, 0 deletions
diff --git a/src/pipeline.cc b/src/pipeline.cc index 87ff88b..26c6882 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -53,6 +53,12 @@ std::unique_ptr<Pipeline> Pipeline::Clone() const { clone->index_buffer_ = index_buffer_; clone->fb_width_ = fb_width_; clone->fb_height_ = fb_height_; + clone->set_arg_values_ = set_arg_values_; + if (!opencl_pod_buffers_.empty()) { + // Generate specific buffers for the clone. + clone->GenerateOpenCLPodBuffers(); + } + return clone; } diff --git a/src/pipeline_test.cc b/src/pipeline_test.cc index 8a0d2a5..c6e15d7 100644 --- a/src/pipeline_test.cc +++ b/src/pipeline_test.cc @@ -644,4 +644,90 @@ TEST_F(PipelineTest, OpenCLGeneratePodBuffersBadSize) { r.Error()); } +TEST_F(PipelineTest, OpenCLClone) { + Pipeline p(PipelineType::kCompute); + p.SetName("my_pipeline"); + + Shader cs(kShaderTypeCompute); + cs.SetFormat(kShaderFormatOpenCLC); + p.AddShader(&cs, kShaderTypeCompute); + p.SetShaderEntryPoint(&cs, "my_main"); + + // Descriptor map. + Pipeline::ShaderInfo::DescriptorMapEntry entry1; + entry1.kind = Pipeline::ShaderInfo::DescriptorMapEntry::Kind::POD; + entry1.descriptor_set = 4; + entry1.binding = 5; + entry1.arg_name = "arg_a"; + entry1.arg_ordinal = 0; + entry1.pod_offset = 0; + entry1.pod_arg_size = 4; + p.GetShaders()[0].AddDescriptorEntry("my_main", std::move(entry1)); + + Pipeline::ShaderInfo::DescriptorMapEntry entry2; + entry2.kind = Pipeline::ShaderInfo::DescriptorMapEntry::Kind::POD; + entry2.descriptor_set = 4; + entry2.binding = 5; + entry2.arg_name = "arg_b"; + entry2.arg_ordinal = 0; + entry2.pod_offset = 4; + entry2.pod_arg_size = 1; + p.GetShaders()[0].AddDescriptorEntry("my_main", std::move(entry2)); + + Pipeline::ShaderInfo::DescriptorMapEntry entry3; + entry3.kind = Pipeline::ShaderInfo::DescriptorMapEntry::Kind::POD; + entry3.descriptor_set = 4; + entry3.binding = 4; + entry3.arg_name = "arg_c"; + entry3.arg_ordinal = 0; + entry3.pod_offset = 0; + entry3.pod_arg_size = 4; + p.GetShaders()[0].AddDescriptorEntry("my_main", std::move(entry3)); + + // Set commands. + Value int_value; + int_value.SetIntValue(1); + DatumType int_type; + int_type.SetType(DataType::kInt32); + DatumType char_type; + char_type.SetType(DataType::kInt8); + + Pipeline::ArgSetInfo arg_info1; + arg_info1.name = "arg_a"; + arg_info1.ordinal = 99; + arg_info1.type = int_type; + arg_info1.value = int_value; + p.SetArg(std::move(arg_info1)); + + Pipeline::ArgSetInfo arg_info2; + arg_info2.name = "arg_b"; + arg_info2.ordinal = 99; + arg_info2.type = char_type; + arg_info2.value = int_value; + p.SetArg(std::move(arg_info2)); + + Pipeline::ArgSetInfo arg_info3; + arg_info3.name = "arg_c"; + arg_info3.ordinal = 99; + arg_info3.type = int_type; + arg_info3.value = int_value; + p.SetArg(std::move(arg_info3)); + + auto clone = p.Clone(); + auto r = clone->GenerateOpenCLPodBuffers(); + ASSERT_TRUE(r.IsSuccess()); + EXPECT_EQ(3U, clone->SetArgValues().size()); + EXPECT_EQ(2U, clone->GetBuffers().size()); + + const auto& b1 = clone->GetBuffers()[0]; + EXPECT_EQ(4U, b1.descriptor_set); + EXPECT_EQ(5U, b1.binding); + EXPECT_EQ(5U, b1.buffer->ValueCount()); + + const auto& b2 = clone->GetBuffers()[1]; + EXPECT_EQ(4U, b2.descriptor_set); + EXPECT_EQ(4U, b2.binding); + EXPECT_EQ(4U, b2.buffer->ValueCount()); +} + } // namespace amber |