aboutsummaryrefslogtreecommitdiff
path: root/src/clspv_helper.cc
diff options
context:
space:
mode:
authoralan-baker <alanbaker@google.com>2019-12-17 20:28:37 -0500
committerGitHub <noreply@github.com>2019-12-17 20:28:37 -0500
commit044f29f46f49bf0ee53bcb5e50a1f378a0e476e7 (patch)
treef34749d4ac6072e37fa52cbb32ef97e73be7c44e /src/clspv_helper.cc
parent4a85632e1372809a84fbdfcf6cbbc87d1159b396 (diff)
downloadamber-044f29f46f49bf0ee53bcb5e50a1f378a0e476e7.tar.gz
Auto-generate OpenCL literal samplers (#759)
* Parse literal sampler descriptor map entries * add them to the pipeline sampler info * Before generating engine pipelines, create the sampler objects for the literal samplers * Tests
Diffstat (limited to 'src/clspv_helper.cc')
-rw-r--r--src/clspv_helper.cc111
1 files changed, 59 insertions, 52 deletions
diff --git a/src/clspv_helper.cc b/src/clspv_helper.cc
index f4c48c9..3dbb696 100644
--- a/src/clspv_helper.cc
+++ b/src/clspv_helper.cc
@@ -23,6 +23,7 @@ namespace amber {
namespace clspvhelper {
Result Compile(Pipeline::ShaderInfo* shader_info,
+ Pipeline* pipeline,
std::vector<uint32_t>* generated_binary) {
std::vector<clspv::version0::DescriptorMapEntry> entries;
const auto& src_str = shader_info->GetShader()->GetData();
@@ -36,63 +37,69 @@ Result Compile(Pipeline::ShaderInfo* shader_info,
}
for (auto& entry : entries) {
- if (entry.kind != clspv::version0::DescriptorMapEntry::KernelArg) {
- return Result(
- "Only kernel argument descriptor entries are currently supported");
+ if (entry.kind == clspv::version0::DescriptorMapEntry::Constant) {
+ return Result("Constant descriptor entries are not 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::ReadOnlyImage:
- descriptor_entry.kind =
- Pipeline::ShaderInfo::DescriptorMapEntry::Kind::RO_IMAGE;
- break;
- case clspv::ArgKind::WriteOnlyImage:
- descriptor_entry.kind =
- Pipeline::ShaderInfo::DescriptorMapEntry::Kind::WO_IMAGE;
- break;
- case clspv::ArgKind::Sampler:
- descriptor_entry.kind =
- Pipeline::ShaderInfo::DescriptorMapEntry::Kind::SAMPLER;
- break;
- case clspv::ArgKind::Local:
- // Local arguments are handled via specialization constants.
- break;
- default:
- return Result("Unsupported kernel argument descriptor entry");
- }
+ if (entry.kind == clspv::version0::DescriptorMapEntry::KernelArg) {
+ 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::ReadOnlyImage:
+ descriptor_entry.kind =
+ Pipeline::ShaderInfo::DescriptorMapEntry::Kind::RO_IMAGE;
+ break;
+ case clspv::ArgKind::WriteOnlyImage:
+ descriptor_entry.kind =
+ Pipeline::ShaderInfo::DescriptorMapEntry::Kind::WO_IMAGE;
+ break;
+ case clspv::ArgKind::Sampler:
+ descriptor_entry.kind =
+ Pipeline::ShaderInfo::DescriptorMapEntry::Kind::SAMPLER;
+ 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) {
- descriptor_entry.pod_offset = entry.kernel_arg_data.pod_offset;
- descriptor_entry.pod_arg_size = entry.kernel_arg_data.pod_arg_size;
- }
+ if (entry.kernel_arg_data.arg_kind == clspv::ArgKind::Pod ||
+ entry.kernel_arg_data.arg_kind == clspv::ArgKind::PodUBO) {
+ 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;
+ 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));
+ shader_info->AddDescriptorEntry(entry.kernel_arg_data.kernel_name,
+ std::move(descriptor_entry));
+ } else {
+ assert(entry.kind == clspv::version0::DescriptorMapEntry::Sampler);
+ // Create a new sampler info.
+ pipeline->AddSampler(entry.sampler_data.mask, entry.descriptor_set,
+ entry.binding);
+ }
}
return Result();