Merge pull request #648 from billhollings/master
CompilerMSL disable rasterization on buffer writes in vertex shader.
This commit is contained in:
Коммит
162eee6325
|
@ -0,0 +1,37 @@
|
|||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct _35
|
||||
{
|
||||
uint4 _m0[1024];
|
||||
};
|
||||
|
||||
struct _40
|
||||
{
|
||||
uint4 _m0[1024];
|
||||
};
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 gl_Position [[position]];
|
||||
};
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float4 m_17 [[attribute(0)]];
|
||||
};
|
||||
|
||||
vertex void main0(main0_in in [[stage_in]], constant _40& _42 [[buffer(0)]], device _35& _37 [[buffer(1)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
out.gl_Position = in.m_17;
|
||||
for (int _51 = 0; _51 < 1024; )
|
||||
{
|
||||
_37._m0[_51] = _42._m0[_51];
|
||||
_51++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
#include <metal_atomic>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct _23
|
||||
{
|
||||
uint _m0;
|
||||
};
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 gl_Position [[position]];
|
||||
};
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float4 m_17 [[attribute(0)]];
|
||||
};
|
||||
|
||||
vertex void main0(main0_in in [[stage_in]], device _23& _25 [[buffer(0)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
out.gl_Position = in.m_17;
|
||||
uint _29 = atomic_fetch_add_explicit((volatile device atomic_uint*)&_25._m0, 1u, memory_order_relaxed);
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct _35
|
||||
{
|
||||
uint4 _m0[1024];
|
||||
};
|
||||
|
||||
struct _40
|
||||
{
|
||||
uint4 _m0[1024];
|
||||
};
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 gl_Position [[position]];
|
||||
};
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float4 m_17 [[attribute(0)]];
|
||||
};
|
||||
|
||||
vertex void main0(main0_in in [[stage_in]], constant _40& _42 [[buffer(0)]], device _35& _37 [[buffer(1)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
out.gl_Position = in.m_17;
|
||||
for (int _22 = 0; _22 < 1024; _22++)
|
||||
{
|
||||
_37._m0[_22] = _42._m0[_22];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
#include <metal_atomic>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct _23
|
||||
{
|
||||
uint _m0;
|
||||
};
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 gl_Position [[position]];
|
||||
};
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float4 m_17 [[attribute(0)]];
|
||||
};
|
||||
|
||||
vertex void main0(main0_in in [[stage_in]], device _23& _25 [[buffer(0)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
out.gl_Position = in.m_17;
|
||||
uint _29 = atomic_fetch_add_explicit((volatile device atomic_uint*)&_25._m0, 1u, memory_order_relaxed);
|
||||
uint _22 = _29;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#version 450
|
||||
|
||||
layout(binding = 1, std430) writeonly buffer _33_35
|
||||
{
|
||||
uvec4 _m0[1024];
|
||||
} _35;
|
||||
|
||||
layout(binding = 0, std140) uniform _38_40
|
||||
{
|
||||
uvec4 _m0[1024];
|
||||
} _40;
|
||||
|
||||
layout(location = 0) in vec4 _14;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = _14;
|
||||
for (int _19 = 0; _19 < 1024; _19++)
|
||||
{
|
||||
_35._m0[_19] = _40._m0[_19];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#version 450
|
||||
|
||||
layout(binding = 0, std430) coherent buffer _19_21
|
||||
{
|
||||
uint _m0;
|
||||
} _21;
|
||||
|
||||
layout(location = 0) in vec4 _14;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = _14;
|
||||
uint _26 = atomicAdd(_21._m0, 1u);
|
||||
}
|
||||
|
|
@ -383,8 +383,8 @@ void CompilerMSL::preprocess_op_codes()
|
|||
add_pragma_line("#pragma clang diagnostic ignored \"-Wunused-variable\"");
|
||||
}
|
||||
|
||||
// Metal vertex functions that write to textures must disable rasterization and return void.
|
||||
if (preproc.uses_image_write)
|
||||
// Metal vertex functions that write to resources must disable rasterization and return void.
|
||||
if (preproc.uses_resource_write)
|
||||
is_rasterization_disabled = true;
|
||||
}
|
||||
|
||||
|
@ -3141,8 +3141,8 @@ string CompilerMSL::get_argument_address_space(const SPIRVariable &argument)
|
|||
|
||||
case StorageClassStorageBuffer:
|
||||
{
|
||||
auto flags = get_buffer_block_flags(argument);
|
||||
return flags.get(DecorationNonWritable) ? "const device" : "device";
|
||||
bool readonly = get_buffer_block_flags(argument).get(DecorationNonWritable);
|
||||
return readonly ? "const device" : "device";
|
||||
}
|
||||
|
||||
case StorageClassUniform:
|
||||
|
@ -3151,13 +3151,13 @@ string CompilerMSL::get_argument_address_space(const SPIRVariable &argument)
|
|||
if (type.basetype == SPIRType::Struct)
|
||||
{
|
||||
bool ssbo = has_decoration(type.self, DecorationBufferBlock);
|
||||
if (!ssbo)
|
||||
return "constant";
|
||||
else
|
||||
if (ssbo)
|
||||
{
|
||||
bool readonly = get_buffer_block_flags(argument).get(DecorationNonWritable);
|
||||
return readonly ? "const device" : "device";
|
||||
}
|
||||
else
|
||||
return "constant";
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -4039,13 +4039,16 @@ bool CompilerMSL::OpCodePreprocessor::handle(Op opcode, const uint32_t *args, ui
|
|||
break;
|
||||
|
||||
case OpImageWrite:
|
||||
uses_image_write = true;
|
||||
uses_resource_write = true;
|
||||
break;
|
||||
|
||||
case OpStore:
|
||||
check_resource_write(args[0]);
|
||||
break;
|
||||
|
||||
case OpAtomicExchange:
|
||||
case OpAtomicCompareExchange:
|
||||
case OpAtomicCompareExchangeWeak:
|
||||
case OpAtomicLoad:
|
||||
case OpAtomicIIncrement:
|
||||
case OpAtomicIDecrement:
|
||||
case OpAtomicIAdd:
|
||||
|
@ -4057,6 +4060,11 @@ bool CompilerMSL::OpCodePreprocessor::handle(Op opcode, const uint32_t *args, ui
|
|||
case OpAtomicAnd:
|
||||
case OpAtomicOr:
|
||||
case OpAtomicXor:
|
||||
uses_atomics = true;
|
||||
check_resource_write(args[2]);
|
||||
break;
|
||||
|
||||
case OpAtomicLoad:
|
||||
uses_atomics = true;
|
||||
break;
|
||||
|
||||
|
@ -4072,6 +4080,15 @@ bool CompilerMSL::OpCodePreprocessor::handle(Op opcode, const uint32_t *args, ui
|
|||
return true;
|
||||
}
|
||||
|
||||
// If the variable is a Uniform or StorageBuffer, mark that a resource has been written to.
|
||||
void CompilerMSL::OpCodePreprocessor::check_resource_write(uint32_t var_id)
|
||||
{
|
||||
auto *p_var = compiler.maybe_get_backing_variable(var_id);
|
||||
StorageClass sc = p_var ? p_var->storage : StorageClassMax;
|
||||
if (sc == StorageClassUniform || sc == StorageClassStorageBuffer)
|
||||
uses_resource_write = true;
|
||||
}
|
||||
|
||||
// Returns an enumeration of a SPIR-V function that needs to be output for certain Op codes.
|
||||
CompilerMSL::SPVFuncImpl CompilerMSL::OpCodePreprocessor::get_spv_func_impl(Op opcode, const uint32_t *args)
|
||||
{
|
||||
|
|
|
@ -403,12 +403,13 @@ protected:
|
|||
|
||||
bool handle(spv::Op opcode, const uint32_t *args, uint32_t length) override;
|
||||
CompilerMSL::SPVFuncImpl get_spv_func_impl(spv::Op opcode, const uint32_t *args);
|
||||
void check_resource_write(uint32_t var_id);
|
||||
|
||||
CompilerMSL &compiler;
|
||||
std::unordered_map<uint32_t, uint32_t> result_types;
|
||||
bool suppress_missing_prototypes = false;
|
||||
bool uses_atomics = false;
|
||||
bool uses_image_write = false;
|
||||
bool uses_resource_write = false;
|
||||
};
|
||||
|
||||
// Sorts the members of a SPIRType and associated Meta info based on a settable sorting
|
||||
|
|
Загрузка…
Ссылка в новой задаче