Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/OpenCLCOnVulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,15 @@ shader is as follows:
ID is reported in the descriptor map file, generated via the `-descriptormap`
option.

The shaders produced use the GLSL450 memory model. As such, there is an assumption of
#### Memory Model

The default shaders produced use the GLSL450 memory model. As such, there is an assumption of
no aliasing by default. The compiler does not generate *Aliased* decorations
currently. Users should be aware of this and ensure they are not relying on aliasing.

`vulkan-memory-model` option could be used to produce Vulkan memory model shaders. Memory scopes for loads and stores in this mode will be decided
according to the pointer type.

#### Embedded Reflection Instructions

Clspv embeds reflection information via use of the [NonSemantic.ClspvReflection](http://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/master/nonsemantic/NonSemantic.ClspvReflection.html)
Expand Down
3 changes: 3 additions & 0 deletions include/clspv/Option.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ Vec3ToVec4SupportClass Vec3ToVec4();
// Returns true if opaque pointers are enabled
bool OpaquePointers();

// Returns true if vulkan memory model is enabled
bool VulkanMemoryModel();

// Returns true if the debug information should be generated
bool DebugInfo();

Expand Down
7 changes: 7 additions & 0 deletions lib/Option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ static llvm::cl::opt<bool>
llvm::cl::desc("Use opaque pointers"),
llvm::cl::init(false));

static llvm::cl::opt<bool>
vulkan_memory_model("vulkan-memory-model",
llvm::cl::desc("Use vulkan memory model"),
llvm::cl::init(false));

static llvm::cl::opt<bool>
debug_info("g", llvm::cl::init(false),
llvm::cl::desc("Produce debug information."));
Expand Down Expand Up @@ -500,6 +505,8 @@ Vec3ToVec4SupportClass Vec3ToVec4() {

bool OpaquePointers() { return opaque_pointers; }

bool VulkanMemoryModel() { return vulkan_memory_model; }

bool DebugInfo() { return debug_info; }

std::set<FeatureMacro> EnabledFeatureMacros() { return enabled_feature_macros; }
Expand Down
29 changes: 22 additions & 7 deletions lib/ReplaceOpenCLBuiltinPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3510,9 +3510,21 @@ bool ReplaceOpenCLBuiltinPass::replaceAtomics(Function &F, spv::Op Op) {

// We need to map the OpenCL constants to the SPIR-V equivalents.
const auto ConstantScopeDevice = ConstantInt::get(IntTy, spv::ScopeDevice);
const auto ConstantMemorySemantics = ConstantInt::get(
IntTy, spv::MemorySemanticsUniformMemoryMask |
spv::MemorySemanticsSequentiallyConsistentMask);
auto EqualMemorySemanticsMask =
clspv::Option::VulkanMemoryModel()
? spv::MemorySemanticsAcquireReleaseMask
: spv::MemorySemanticsSequentiallyConsistentMask;
auto UnEqualMemorySemanticsMask =
clspv::Option::VulkanMemoryModel()
? spv::MemorySemanticsAcquireMask
: spv::MemorySemanticsSequentiallyConsistentMask;

const auto EqualConstantMemorySemantics =
ConstantInt::get(IntTy, spv::MemorySemanticsUniformMemoryMask |
EqualMemorySemanticsMask);
const auto UnEqualConstantMemorySemantics =
ConstantInt::get(IntTy, spv::MemorySemanticsUniformMemoryMask |
UnEqualMemorySemanticsMask);

SmallVector<Value *, 5> Params;

Expand All @@ -3523,11 +3535,11 @@ bool ReplaceOpenCLBuiltinPass::replaceAtomics(Function &F, spv::Op Op) {
Params.push_back(ConstantScopeDevice);

// The memory semantics.
Params.push_back(ConstantMemorySemantics);
Params.push_back(EqualConstantMemorySemantics);

if (2 < CI->arg_size()) {
// The unequal memory semantics.
Params.push_back(ConstantMemorySemantics);
Params.push_back(UnEqualConstantMemorySemantics);

// The value.
Params.push_back(CI->getArgOperand(2));
Expand All @@ -3548,9 +3560,12 @@ bool ReplaceOpenCLBuiltinPass::replaceAtomics(Function &F,
return replaceCallsWithValue(F, [&](CallInst *CI) {
auto align = F.getParent()->getDataLayout().getABITypeAlign(
CI->getArgOperand(1)->getType());
auto MemorySemantics = clspv::Option::VulkanMemoryModel()
? AtomicOrdering::AcquireRelease
: AtomicOrdering::SequentiallyConsistent;

return new AtomicRMWInst(Op, CI->getArgOperand(0), CI->getArgOperand(1),
align, AtomicOrdering::SequentiallyConsistent,
SyncScope::System, CI);
align, MemorySemantics, SyncScope::System, CI);
});
}

Expand Down
Loading