David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 1 | // Copyright 2018 The Clspv Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // This translation unit defines all Clspv command line option variables. |
| 16 | |
| 17 | #include <llvm/Support/CommandLine.h> |
| 18 | |
| 19 | namespace { |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame^] | 20 | |
| 21 | // Should the compiler try to use direct buffer accesses within helper |
| 22 | // functions instead of passing pointers via function arguments? |
| 23 | llvm::cl::opt<bool> direct_buffer_access( |
| 24 | "direct-buffer-access", llvm::cl::init(false), |
| 25 | llvm::cl::desc( |
| 26 | "Helper functions access buffers directly instead of by pointers " |
| 27 | "in function arguments")); |
| 28 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 29 | // By default, reuse the same descriptor set number for all arguments. |
| 30 | // To turn that off, use -distinct-kernel-descriptor-sets |
| 31 | llvm::cl::opt<bool> distinct_kernel_descriptor_sets( |
| 32 | "distinct-kernel-descriptor-sets", llvm::cl::init(false), |
| 33 | llvm::cl::desc( |
| 34 | "Each kernel uses its own descriptor set for its arguments")); |
| 35 | |
| 36 | // TODO(dneto): As per Neil Henning suggestion, might not need this if |
| 37 | // you can trace the pointer back far enough to see that it's 32-bit |
| 38 | // aligned. However, even in the vstore_half case, you'll probably get |
| 39 | // better performance if you can rely on SPV_KHR_16bit_storage since in |
| 40 | // the alternate case you're using a (relaxed) atomic, and therefore |
| 41 | // have to write through to the cache. |
| 42 | llvm::cl::opt<bool> f16bit_storage( |
| 43 | "f16bit_storage", llvm::cl::init(false), |
| 44 | llvm::cl::desc("Assume the target supports SPV_KHR_16bit_storage")); |
| 45 | |
David Neto | b6e2e06 | 2018-04-25 10:32:06 -0400 | [diff] [blame] | 46 | llvm::cl::opt<bool> hack_initializers( |
| 47 | "hack-initializers", llvm::cl::init(false), |
| 48 | llvm::cl::desc( |
| 49 | "At the start of each kernel, explicitly write the initializer " |
| 50 | "value for a compiler-generated variable containing the workgroup " |
| 51 | "size. Required by some drivers to make the get_global_size builtin " |
| 52 | "function work when used with non-constant dimension index.")); |
| 53 | |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame^] | 54 | llvm::cl::opt<bool> hack_dis( |
| 55 | "hack-dis", llvm::cl::init(false), |
| 56 | llvm::cl::desc( |
| 57 | "Force use of a distinct image or sampler variable for each " |
| 58 | "image or sampler kernel argument. This prevents sharing " |
| 59 | "of resource variables.")); |
| 60 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 61 | llvm::cl::opt<bool> hack_inserts( |
| 62 | "hack-inserts", llvm::cl::init(false), |
| 63 | llvm::cl::desc( |
| 64 | "Avoid all single-index OpCompositInsert instructions " |
| 65 | "into struct types by using complete composite construction and " |
| 66 | "extractions")); |
| 67 | |
| 68 | // Some drivers don't like to see constant composite values constructed |
| 69 | // from scalar Undef values. Replace numeric scalar and vector Undef with |
| 70 | // corresponding OpConstantNull. We need to keep Undef for image values, |
| 71 | // for example. In the LLVM domain, image values are passed as pointer to |
| 72 | // struct. |
| 73 | // See https://github.com/google/clspv/issues/95 |
| 74 | llvm::cl::opt<bool> hack_undef( |
| 75 | "hack-undef", llvm::cl::init(false), |
| 76 | llvm::cl::desc("Use OpConstantNull instead of OpUndef for floating point, " |
| 77 | "integer, or vectors of them")); |
| 78 | |
| 79 | llvm::cl::opt<bool> |
| 80 | pod_ubo("pod-ubo", llvm::cl::init(false), |
| 81 | llvm::cl::desc("POD kernel arguments are in uniform buffers")); |
| 82 | |
David Neto | 8508264 | 2018-03-24 06:55:20 -0700 | [diff] [blame] | 83 | llvm::cl::opt<bool> module_constants_in_storage_buffer( |
| 84 | "module-constants-in-storage-buffer", llvm::cl::init(false), |
| 85 | llvm::cl::desc( |
| 86 | "Module-scope __constants are collected into a single storage buffer. " |
| 87 | "The binding and initialization data are reported in the descriptor " |
| 88 | "map.")); |
| 89 | |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 90 | llvm::cl::opt<bool> show_ids("show-ids", llvm::cl::init(false), |
| 91 | llvm::cl::desc("Show SPIR-V IDs for functions")); |
| 92 | |
| 93 | } // namespace |
| 94 | |
| 95 | namespace clspv { |
| 96 | namespace Option { |
| 97 | |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame^] | 98 | bool DirectBufferAccess() { return direct_buffer_access; } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 99 | bool DistinctKernelDescriptorSets() { return distinct_kernel_descriptor_sets; } |
| 100 | bool F16BitStorage() { return f16bit_storage; } |
David Neto | 862b7d8 | 2018-06-14 18:48:37 -0400 | [diff] [blame^] | 101 | bool HackDistinctImageSampler() { return hack_dis; } |
David Neto | b6e2e06 | 2018-04-25 10:32:06 -0400 | [diff] [blame] | 102 | bool HackInitializers() { return hack_initializers; } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 103 | bool HackInserts() { return hack_inserts; } |
| 104 | bool HackUndef() { return hack_undef; } |
David Neto | 8508264 | 2018-03-24 06:55:20 -0700 | [diff] [blame] | 105 | bool ModuleConstantsInStorageBuffer() { return module_constants_in_storage_buffer; } |
David Neto | 482550a | 2018-03-24 05:21:07 -0700 | [diff] [blame] | 106 | bool PodArgsInUniformBuffer() { return pod_ubo; } |
| 107 | bool ShowIDs() { return show_ids; } |
| 108 | |
| 109 | } // namespace Option |
| 110 | } // namespace clspv |