aboutsummaryrefslogtreecommitdiff
path: root/src/clspv_helper.cc
diff options
context:
space:
mode:
authoralan-baker <33432579+alan-baker@users.noreply.github.com>2019-07-19 15:35:22 -0400
committerGitHub <noreply@github.com>2019-07-19 15:35:22 -0400
commit695979920cd860460703787369a87987b837a0cf (patch)
treee0b5a3bb76ef165816c627e208cbe270768c5ce6 /src/clspv_helper.cc
parente7035ef87a71c70b15bb31af6708581f9ce78675 (diff)
downloadamber-695979920cd860460703787369a87987b837a0cf.tar.gz
Bind opencl buffers (#584)
Fixes #426 * New BIND subcommands to specify kernel args by name or ordinal * storage class specification is optional, but checked for consistency * clspv compiles parse descriptor map (partially) into Pipeline::ShaderInfo * Bindings updated before pipeline creation * added compiler and pipeline tests for new functionality * added new end-to-end test * Add documentation * Buffer storage class specification is now optional for OpenCL-C
Diffstat (limited to 'src/clspv_helper.cc')
-rw-r--r--src/clspv_helper.cc57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/clspv_helper.cc b/src/clspv_helper.cc
index 056b5d5..e0d853e 100644
--- a/src/clspv_helper.cc
+++ b/src/clspv_helper.cc
@@ -14,20 +14,73 @@
#include "src/clspv_helper.h"
+#include <utility>
+
+#include "clspv/ArgKind.h"
#include "clspv/Compiler.h"
namespace amber {
namespace clspvhelper {
-Result Compile(const std::string& src_str,
+Result Compile(Pipeline::ShaderInfo* shader_info,
std::vector<uint32_t>* generated_binary) {
- // TODO(alan-baker): Parse the descriptor map.
std::vector<clspv::version0::DescriptorMapEntry> entries;
+ const auto& src_str = shader_info->GetShader()->GetData();
if (clspv::CompileFromSourceString(src_str, "", "", generated_binary,
&entries)) {
return Result("Clspv compile failed");
}
+ for (auto& entry : entries) {
+ if (entry.kind != clspv::version0::DescriptorMapEntry::KernelArg) {
+ return Result(
+ "Only kernel argument descriptor entries are currently supported");
+ }
+
+ Pipeline::ShaderInfo::DescriptorMapEntry descriptor_entry;
+ descriptor_entry.descriptor_set = entry.descriptor_set;
+ descriptor_entry.binding = entry.binding;
+ descriptor_entry.pod_offset = 0;
+ descriptor_entry.pod_arg_size = 0;
+ switch (entry.kernel_arg_data.arg_kind) {
+ case clspv::ArgKind::Buffer:
+ descriptor_entry.kind =
+ Pipeline::ShaderInfo::DescriptorMapEntry::Kind::SSBO;
+ break;
+ case clspv::ArgKind::BufferUBO:
+ descriptor_entry.kind =
+ Pipeline::ShaderInfo::DescriptorMapEntry::Kind::UBO;
+ break;
+ case clspv::ArgKind::Pod:
+ descriptor_entry.kind =
+ Pipeline::ShaderInfo::DescriptorMapEntry::Kind::POD;
+ break;
+ case clspv::ArgKind::PodUBO:
+ descriptor_entry.kind =
+ Pipeline::ShaderInfo::DescriptorMapEntry::Kind::POD_UBO;
+ break;
+ case clspv::ArgKind::Local:
+ // Local arguments are handled via specialization constants.
+ break;
+ default:
+ return Result("Unsupported kernel argument descriptor entry");
+ }
+
+ if (entry.kernel_arg_data.arg_kind == clspv::ArgKind::Pod ||
+ entry.kernel_arg_data.arg_kind == clspv::ArgKind::PodUBO) {
+ if (entry.kernel_arg_data.pod_offset != 0)
+ return Result("Clustered PoD arguments are not currently supported");
+ descriptor_entry.pod_offset = entry.kernel_arg_data.pod_offset;
+ descriptor_entry.pod_arg_size = entry.kernel_arg_data.pod_arg_size;
+ }
+
+ descriptor_entry.arg_name = entry.kernel_arg_data.arg_name;
+ descriptor_entry.arg_ordinal = entry.kernel_arg_data.arg_ordinal;
+
+ shader_info->AddDescriptorEntry(entry.kernel_arg_data.kernel_name,
+ std::move(descriptor_entry));
+ }
+
return Result();
}