CompilerMSL support platform semantics.

Support customizing MSL based on iOS or macOS platform.
Support SPIV-V containing multiple memory semantics.
This commit is contained in:
Bill Hollings 2017-12-26 13:39:07 -05:00
parent bcc96d8c70
commit 3fcdce08ab
2 changed files with 22 additions and 23 deletions

View File

@ -1559,34 +1559,18 @@ void CompilerMSL::emit_barrier(uint32_t id_exe_scope, uint32_t id_mem_scope, uin
string bar_stmt = "threadgroup_barrier(mem_flags::";
uint32_t mem_sem = id_mem_sem ? get<SPIRConstant>(id_mem_sem).scalar() : uint32_t(MemorySemanticsMaskNone);
switch (mem_sem)
{
case MemorySemanticsCrossWorkgroupMemoryMask:
if (mem_sem & MemorySemanticsCrossWorkgroupMemoryMask)
bar_stmt += "mem_device";
break;
case MemorySemanticsSubgroupMemoryMask:
case MemorySemanticsWorkgroupMemoryMask:
case MemorySemanticsAtomicCounterMemoryMask:
else if (mem_sem & (MemorySemanticsSubgroupMemoryMask | MemorySemanticsWorkgroupMemoryMask |
MemorySemanticsAtomicCounterMemoryMask))
bar_stmt += "mem_threadgroup";
break;
case MemorySemanticsImageMemoryMask:
else if (mem_sem & MemorySemanticsImageMemoryMask)
bar_stmt += "mem_texture";
break;
case MemorySemanticsAcquireMask:
case MemorySemanticsReleaseMask:
case MemorySemanticsAcquireReleaseMask:
case MemorySemanticsSequentiallyConsistentMask:
case MemorySemanticsUniformMemoryMask:
case MemorySemanticsMaskNone:
default:
else
bar_stmt += "mem_none";
break;
}
if (options.supports_msl_version(2))
if (options.is_ios() && options.supports_msl_version(2))
{
bar_stmt += ", ";

View File

@ -77,10 +77,25 @@ public:
// Options for compiling to Metal Shading Language
struct Options
{
typedef enum {
iOS,
macOS,
} Platform;
Platform platform = macOS;
uint32_t msl_version = make_msl_version(1, 2);
bool enable_point_size_builtin = true;
bool resolve_specialized_array_lengths = true;
bool is_ios()
{
return platform == iOS;
}
bool is_macos()
{
return platform == macOS;
}
void set_msl_version(uint32_t major, uint32_t minor = 0, uint32_t patch = 0)
{
msl_version = make_msl_version(major, minor, patch);