Merge pull request #684 from cdavis5e/msl-builtin-vector-cast

MSL: Cast uses of builtin vectors to their declared SPIR-V type.
This commit is contained in:
Hans-Kristian Arntzen 2018-09-11 19:59:58 +02:00 коммит произвёл GitHub
Родитель af907fe496 6757ef8512
Коммит 403011e973
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 421 добавлений и 6 удалений

Просмотреть файл

@ -18,8 +18,8 @@ uint2 spvTexelBufferCoord(uint tc)
kernel void main0(constant cb5_struct& cb0_5 [[buffer(1)]], texture2d<uint, access::write> u0 [[texture(0)]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]]) kernel void main0(constant cb5_struct& cb0_5 [[buffer(1)]], texture2d<uint, access::write> u0 [[texture(0)]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
{ {
uint _44 = as_type<uint>(as_type<float>(gl_LocalInvocationID.x << 4)) >> 2u; uint _44 = as_type<uint>(as_type<float>(int(gl_LocalInvocationID.x) << 4)) >> 2u;
uint4 _51 = as_type<uint4>(cb0_5._m0[uint(as_type<int>(as_type<float>(gl_LocalInvocationID.x))) + 1u]); uint4 _51 = as_type<uint4>(cb0_5._m0[uint(as_type<int>(as_type<float>(int(gl_LocalInvocationID.x)))) + 1u]);
u0.write(_51.xxxx, spvTexelBufferCoord(_44)); u0.write(_51.xxxx, spvTexelBufferCoord(_44));
u0.write(_51.yyyy, spvTexelBufferCoord((_44 + 1u))); u0.write(_51.yyyy, spvTexelBufferCoord((_44 + 1u)));
u0.write(_51.zzzz, spvTexelBufferCoord((_44 + 2u))); u0.write(_51.zzzz, spvTexelBufferCoord((_44 + 2u)));

Просмотреть файл

@ -0,0 +1,28 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
constant uint3 gl_WorkGroupSize = uint3(16u, 16u, 1u);
struct cb1_struct
{
float4 _m0[1];
};
kernel void main0(constant cb1_struct& cb0_1 [[buffer(0)]], texture2d<float, access::write> u0 [[texture(1)]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
{
int2 _46 = int2(u0.get_width(), u0.get_height()) >> int2(uint2(4u));
int _99;
_99 = 0;
for (; _99 < _46.y; _99++)
{
for (int _100 = 0; _100 < _46.x; )
{
u0.write(cb0_1._m0[0].xxxx, uint2(((_46 * int3(gl_LocalInvocationID).xy) + int2(_99, _100))));
_100++;
continue;
}
}
}

Просмотреть файл

@ -0,0 +1,28 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
constant uint3 gl_WorkGroupSize = uint3(16u, 16u, 1u);
struct cb1_struct
{
float4 _m0[1];
};
kernel void main0(constant cb1_struct& cb0_1 [[buffer(0)]], texture2d<float, access::write> u0 [[texture(1)]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
{
int2 _40 = int2(u0.get_width(), u0.get_height()) >> int2(uint2(4u));
int _82;
_82 = 0;
for (; _82 < _40.y; _82++)
{
for (int _83 = 0; _83 < _40.x; )
{
u0.write(cb0_1._m0[0].xxxx, uint2(((_40 * int3(gl_LocalInvocationID).xy) + int2(_82, _83))));
_83++;
continue;
}
}
}

Просмотреть файл

@ -19,8 +19,8 @@ uint2 spvTexelBufferCoord(uint tc)
kernel void main0(constant cb5_struct& cb0_5 [[buffer(1)]], texture2d<uint, access::write> u0 [[texture(0)]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]]) kernel void main0(constant cb5_struct& cb0_5 [[buffer(1)]], texture2d<uint, access::write> u0 [[texture(0)]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
{ {
float4 r0; float4 r0;
r0.x = as_type<float>(gl_LocalInvocationID.x << 4); r0.x = as_type<float>(int(gl_LocalInvocationID.x) << 4);
r0.y = as_type<float>(gl_LocalInvocationID.x); r0.y = as_type<float>(int(gl_LocalInvocationID.x));
uint _44 = as_type<uint>(r0.x) >> 2u; uint _44 = as_type<uint>(r0.x) >> 2u;
uint4 _51 = as_type<uint4>(cb0_5._m0[uint(as_type<int>(r0.y)) + 1u]); uint4 _51 = as_type<uint4>(cb0_5._m0[uint(as_type<int>(r0.y)) + 1u]);
u0.write(_51.xxxx, spvTexelBufferCoord(_44)); u0.write(_51.xxxx, spvTexelBufferCoord(_44));

Просмотреть файл

@ -0,0 +1,33 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
constant uint3 gl_WorkGroupSize = uint3(16u, 16u, 1u);
struct cb1_struct
{
float4 _m0[1];
};
int2 get_texcoord(thread const int2& base, thread const int2& index, thread uint3& gl_LocalInvocationID)
{
return (base * int3(gl_LocalInvocationID).xy) + index;
}
kernel void main0(constant cb1_struct& cb0_1 [[buffer(0)]], texture2d<float, access::write> u0 [[texture(1)]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
{
int2 r0 = int2(int2(u0.get_width(), u0.get_height()) >> int2(uint2(4u)));
for (int i = 0; i < r0.y; i++)
{
for (int j = 0; j < r0.x; j++)
{
int2 param = r0;
int2 param_1 = int2(i, j);
u0.write(cb0_1._m0[0].xxxx, uint2(get_texcoord(param, param_1, gl_LocalInvocationID)));
}
}
}

Просмотреть файл

@ -0,0 +1,24 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
constant uint3 gl_WorkGroupSize = uint3(16u, 16u, 1u);
struct cb1_struct
{
float4 _m0[1];
};
kernel void main0(constant cb1_struct& cb0_1 [[buffer(0)]], texture2d<float, access::write> u0 [[texture(1)]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
{
int2 r0 = int2(int2(u0.get_width(), u0.get_height()) >> int2(uint2(4u)));
for (int i = 0; i < r0.y; i++)
{
for (int j = 0; j < r0.x; j++)
{
u0.write(cb0_1._m0[0].xxxx, uint2(((r0 * int3(gl_LocalInvocationID).xy) + int2(i, j))));
}
}
}

Просмотреть файл

@ -0,0 +1,147 @@
; SPIR-V
; Version: 1.3
; Generator: Khronos Glslang Reference Front End; 6
; Bound: 90
; Schema: 0
OpCapability Shader
OpCapability ImageQuery
OpCapability StorageImageWriteWithoutFormat
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %gl_LocalInvocationID
OpExecutionMode %main LocalSize 16 16 1
OpSource GLSL 450
OpName %main "main"
OpName %get_texcoord_vi2_vi2_ "get_texcoord(vi2;vi2;"
OpName %base "base"
OpName %index "index"
OpName %gl_LocalInvocationID "gl_LocalInvocationID"
OpName %r0 "r0"
OpName %u0 "u0"
OpName %i "i"
OpName %j "j"
OpName %param "param"
OpName %param_0 "param"
OpName %cb1_struct "cb1_struct"
OpMemberName %cb1_struct 0 "_m0"
OpName %cb0_1 "cb0_1"
OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId
OpDecorate %u0 DescriptorSet 0
OpDecorate %u0 Binding 1
OpDecorate %u0 NonReadable
OpDecorate %_arr_v4float_uint_1 ArrayStride 16
OpMemberDecorate %cb1_struct 0 Offset 0
OpDecorate %cb1_struct Block
OpDecorate %cb0_1 DescriptorSet 0
OpDecorate %cb0_1 Binding 0
OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
%void = OpTypeVoid
%3 = OpTypeFunction %void
%int = OpTypeInt 32 1
%v2int = OpTypeVector %int 2
%_ptr_Function_v2int = OpTypePointer Function %v2int
%9 = OpTypeFunction %v2int %_ptr_Function_v2int %_ptr_Function_v2int
%v3int = OpTypeVector %int 3
%_ptr_Input_v3int = OpTypePointer Input %v3int
%gl_LocalInvocationID = OpVariable %_ptr_Input_v3int Input
%uint = OpTypeInt 32 0
%v2uint = OpTypeVector %uint 2
%float = OpTypeFloat 32
%30 = OpTypeImage %float 2D 0 0 0 2 Unknown
%_ptr_UniformConstant_30 = OpTypePointer UniformConstant %30
%u0 = OpVariable %_ptr_UniformConstant_30 UniformConstant
%uint_4 = OpConstant %uint 4
%_ptr_Function_int = OpTypePointer Function %int
%int_0 = OpConstant %int 0
%uint_1 = OpConstant %uint 1
%bool = OpTypeBool
%uint_0 = OpConstant %uint 0
%v4float = OpTypeVector %float 4
%_arr_v4float_uint_1 = OpTypeArray %v4float %uint_1
%cb1_struct = OpTypeStruct %_arr_v4float_uint_1
%_ptr_Uniform_cb1_struct = OpTypePointer Uniform %cb1_struct
%cb0_1 = OpVariable %_ptr_Uniform_cb1_struct Uniform
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int_1 = OpConstant %int 1
%uint_16 = OpConstant %uint 16
%v3uint = OpTypeVector %uint 3
%gl_WorkGroupSize = OpConstantComposite %v3uint %uint_16 %uint_16 %uint_1
%main = OpFunction %void None %3
%5 = OpLabel
%r0 = OpVariable %_ptr_Function_v2int Function
%i = OpVariable %_ptr_Function_int Function
%j = OpVariable %_ptr_Function_int Function
%param = OpVariable %_ptr_Function_v2int Function
%param_0 = OpVariable %_ptr_Function_v2int Function
%33 = OpLoad %30 %u0
%34 = OpImageQuerySize %v2int %33
%36 = OpCompositeConstruct %v2uint %uint_4 %uint_4
%37 = OpShiftRightArithmetic %v2int %34 %36
%38 = OpCompositeExtract %int %37 0
%39 = OpCompositeExtract %int %37 1
%40 = OpCompositeConstruct %v2int %38 %39
OpStore %r0 %40
OpStore %i %int_0
OpBranch %44
%44 = OpLabel
OpLoopMerge %46 %47 None
OpBranch %48
%48 = OpLabel
%49 = OpLoad %int %i
%51 = OpAccessChain %_ptr_Function_int %r0 %uint_1
%52 = OpLoad %int %51
%54 = OpSLessThan %bool %49 %52
OpBranchConditional %54 %45 %46
%45 = OpLabel
OpStore %j %int_0
OpBranch %56
%56 = OpLabel
OpLoopMerge %58 %59 None
OpBranch %60
%60 = OpLabel
%61 = OpLoad %int %j
%63 = OpAccessChain %_ptr_Function_int %r0 %uint_0
%64 = OpLoad %int %63
%65 = OpSLessThan %bool %61 %64
OpBranchConditional %65 %57 %58
%57 = OpLabel
%66 = OpLoad %30 %u0
%67 = OpLoad %int %i
%68 = OpLoad %int %j
%69 = OpCompositeConstruct %v2int %67 %68
%71 = OpLoad %v2int %r0
OpStore %param %71
OpStore %param_0 %69
%73 = OpFunctionCall %v2int %get_texcoord_vi2_vi2_ %param %param_0
%80 = OpAccessChain %_ptr_Uniform_v4float %cb0_1 %int_0 %int_0
%81 = OpLoad %v4float %80
%82 = OpVectorShuffle %v4float %81 %81 0 0 0 0
OpImageWrite %66 %73 %82
OpBranch %59
%59 = OpLabel
%83 = OpLoad %int %j
%85 = OpIAdd %int %83 %int_1
OpStore %j %85
OpBranch %56
%58 = OpLabel
OpBranch %47
%47 = OpLabel
%86 = OpLoad %int %i
%87 = OpIAdd %int %86 %int_1
OpStore %i %87
OpBranch %44
%46 = OpLabel
OpReturn
OpFunctionEnd
%get_texcoord_vi2_vi2_ = OpFunction %v2int None %9
%base = OpFunctionParameter %_ptr_Function_v2int
%index = OpFunctionParameter %_ptr_Function_v2int
%13 = OpLabel
%14 = OpLoad %v2int %base
%20 = OpLoad %v3int %gl_LocalInvocationID
%21 = OpVectorShuffle %v2int %20 %20 0 1
%23 = OpIMul %v2int %14 %21
%24 = OpLoad %v2int %index
%25 = OpIAdd %v2int %23 %24
OpReturnValue %25
OpFunctionEnd

Просмотреть файл

@ -0,0 +1,128 @@
; SPIR-V
; Version: 1.3
; Generator: Khronos Glslang Reference Front End; 6
; Bound: 78
; Schema: 0
OpCapability Shader
OpCapability ImageQuery
OpCapability StorageImageWriteWithoutFormat
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %gl_LocalInvocationID
OpExecutionMode %main LocalSize 16 16 1
OpSource GLSL 450
OpName %main "main"
OpName %r0 "r0"
OpName %u0 "u0"
OpName %i "i"
OpName %j "j"
OpName %gl_LocalInvocationID "gl_LocalInvocationID"
OpName %cb1_struct "cb1_struct"
OpMemberName %cb1_struct 0 "_m0"
OpName %cb0_1 "cb0_1"
OpDecorate %u0 DescriptorSet 0
OpDecorate %u0 Binding 1
OpDecorate %u0 NonReadable
OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId
OpDecorate %_arr_v4float_uint_1 ArrayStride 16
OpMemberDecorate %cb1_struct 0 Offset 0
OpDecorate %cb1_struct Block
OpDecorate %cb0_1 DescriptorSet 0
OpDecorate %cb0_1 Binding 0
OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
%void = OpTypeVoid
%3 = OpTypeFunction %void
%int = OpTypeInt 32 1
%v2int = OpTypeVector %int 2
%_ptr_Function_v2int = OpTypePointer Function %v2int
%float = OpTypeFloat 32
%11 = OpTypeImage %float 2D 0 0 0 2 Unknown
%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
%u0 = OpVariable %_ptr_UniformConstant_11 UniformConstant
%uint = OpTypeInt 32 0
%uint_4 = OpConstant %uint 4
%v2uint = OpTypeVector %uint 2
%_ptr_Function_int = OpTypePointer Function %int
%int_0 = OpConstant %int 0
%uint_1 = OpConstant %uint 1
%bool = OpTypeBool
%uint_0 = OpConstant %uint 0
%v3int = OpTypeVector %int 3
%_ptr_Input_v3int = OpTypePointer Input %v3int
%gl_LocalInvocationID = OpVariable %_ptr_Input_v3int Input
%v4float = OpTypeVector %float 4
%_arr_v4float_uint_1 = OpTypeArray %v4float %uint_1
%cb1_struct = OpTypeStruct %_arr_v4float_uint_1
%_ptr_Uniform_cb1_struct = OpTypePointer Uniform %cb1_struct
%cb0_1 = OpVariable %_ptr_Uniform_cb1_struct Uniform
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int_1 = OpConstant %int 1
%uint_16 = OpConstant %uint 16
%v3uint = OpTypeVector %uint 3
%gl_WorkGroupSize = OpConstantComposite %v3uint %uint_16 %uint_16 %uint_1
%main = OpFunction %void None %3
%5 = OpLabel
%r0 = OpVariable %_ptr_Function_v2int Function
%i = OpVariable %_ptr_Function_int Function
%j = OpVariable %_ptr_Function_int Function
%14 = OpLoad %11 %u0
%15 = OpImageQuerySize %v2int %14
%19 = OpCompositeConstruct %v2uint %uint_4 %uint_4
%20 = OpShiftRightArithmetic %v2int %15 %19
%21 = OpCompositeExtract %int %20 0
%22 = OpCompositeExtract %int %20 1
%23 = OpCompositeConstruct %v2int %21 %22
OpStore %r0 %23
OpStore %i %int_0
OpBranch %27
%27 = OpLabel
OpLoopMerge %29 %30 None
OpBranch %31
%31 = OpLabel
%32 = OpLoad %int %i
%34 = OpAccessChain %_ptr_Function_int %r0 %uint_1
%35 = OpLoad %int %34
%37 = OpSLessThan %bool %32 %35
OpBranchConditional %37 %28 %29
%28 = OpLabel
OpStore %j %int_0
OpBranch %39
%39 = OpLabel
OpLoopMerge %41 %42 None
OpBranch %43
%43 = OpLabel
%44 = OpLoad %int %j
%46 = OpAccessChain %_ptr_Function_int %r0 %uint_0
%47 = OpLoad %int %46
%48 = OpSLessThan %bool %44 %47
OpBranchConditional %48 %40 %41
%40 = OpLabel
%49 = OpLoad %11 %u0
%50 = OpLoad %v2int %r0
%54 = OpLoad %v3int %gl_LocalInvocationID
%55 = OpVectorShuffle %v2int %54 %54 0 1
%57 = OpIMul %v2int %50 %55
%58 = OpLoad %int %i
%59 = OpLoad %int %j
%60 = OpCompositeConstruct %v2int %58 %59
%61 = OpIAdd %v2int %57 %60
%68 = OpAccessChain %_ptr_Uniform_v4float %cb0_1 %int_0 %int_0
%69 = OpLoad %v4float %68
%70 = OpVectorShuffle %v4float %69 %69 0 0 0 0
OpImageWrite %49 %61 %70
OpBranch %42
%42 = OpLabel
%71 = OpLoad %int %j
%73 = OpIAdd %int %71 %int_1
OpStore %j %73
OpBranch %39
%41 = OpLabel
OpBranch %30
%30 = OpLabel
%74 = OpLoad %int %i
%75 = OpIAdd %int %74 %int_1
OpStore %i %75
OpBranch %27
%29 = OpLabel
OpReturn
OpFunctionEnd

Просмотреть файл

@ -4545,11 +4545,38 @@ void CompilerMSL::remap_constexpr_sampler(uint32_t id, const MSLConstexprSampler
constexpr_samplers[id] = sampler; constexpr_samplers[id] = sampler;
} }
// MSL always declares builtins with their SPIR-V type. void CompilerMSL::bitcast_from_builtin_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type)
void CompilerMSL::bitcast_from_builtin_load(uint32_t, std::string &, const SPIRType &)
{ {
auto *var = maybe_get_backing_variable(source_id);
if (var)
source_id = var->self;
// Only interested in standalone builtin variables.
if (!has_decoration(source_id, DecorationBuiltIn))
return;
auto builtin = static_cast<BuiltIn>(get_decoration(source_id, DecorationBuiltIn));
auto expected_type = expr_type.basetype;
switch (builtin)
{
case BuiltInGlobalInvocationId:
case BuiltInLocalInvocationId:
case BuiltInWorkgroupId:
case BuiltInLocalInvocationIndex:
case BuiltInWorkgroupSize:
case BuiltInNumWorkgroups:
expected_type = SPIRType::UInt;
break;
default:
break;
}
if (expected_type != expr_type.basetype)
expr = bitcast_expression(expr_type, expected_type, expr);
} }
// MSL always declares output builtins with the SPIR-V type.
void CompilerMSL::bitcast_to_builtin_store(uint32_t, std::string &, const SPIRType &) void CompilerMSL::bitcast_to_builtin_store(uint32_t, std::string &, const SPIRType &)
{ {
} }