Skip to content

Commit

Permalink
Implement packHalf2x16/unpackHalf2x16 on MSL.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKristian-Work committed Mar 12, 2018
1 parent ae2680c commit 4979d10
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
25 changes: 25 additions & 0 deletions reference/opt/shaders-msl/frag/fp16-packing.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct main0_in
{
float2 FP32 [[user(locn1)]];
uint FP16 [[user(locn0)]];
};

struct main0_out
{
float2 FP32Out [[color(0)]];
uint FP16Out [[color(1)]];
};

fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.FP32Out = float2(as_type<half2>(in.FP16));
out.FP16Out = as_type<uint>(half2(in.FP32));
return out;
}

25 changes: 25 additions & 0 deletions reference/shaders-msl/frag/fp16-packing.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct main0_in
{
float2 FP32 [[user(locn1)]];
uint FP16 [[user(locn0)]];
};

struct main0_out
{
float2 FP32Out [[color(0)]];
uint FP16Out [[color(1)]];
};

fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.FP32Out = float2(as_type<half2>(in.FP16));
out.FP16Out = as_type<uint>(half2(in.FP32));
return out;
}

12 changes: 12 additions & 0 deletions shaders-msl/frag/fp16-packing.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 450

layout(location = 0) flat in uint FP16;
layout(location = 1) flat in vec2 FP32;
layout(location = 0) out vec2 FP32Out;
layout(location = 1) out uint FP16Out;

void main()
{
FP32Out = unpackHalf2x16(FP16);
FP16Out = packHalf2x16(FP32);
}
2 changes: 1 addition & 1 deletion spirv_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7284,7 +7284,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
uint32_t id = ops[1];
string expr;
expr = join("uvec4(unpackUint2x32(ballotARB(" + to_expression(ops[2]) + ")), 0u, 0u)");
emit_op(result_type, id, expr, true);
emit_op(result_type, id, expr, should_forward(ops[2]));

require_extension("GL_ARB_shader_ballot");
inherit_expression_dependencies(id, ops[2]);
Expand Down
14 changes: 12 additions & 2 deletions spirv_msl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2081,9 +2081,14 @@ void CompilerMSL::emit_glsl_op(uint32_t result_type, uint32_t id, uint32_t eop,
case GLSLstd450PackUnorm2x16:
emit_unary_func_op(result_type, id, args[0], "pack_float_to_unorm2x16");
break;

case GLSLstd450PackHalf2x16:
emit_unary_func_op(result_type, id, args[0], "unsupported_GLSLstd450PackHalf2x16"); // Currently unsupported
{
auto expr = join("as_type<uint>(half2(", to_expression(args[0]), "))");
emit_op(result_type, id, expr, should_forward(args[0]));
inherit_expression_dependencies(id, args[0]);
break;
}

case GLSLstd450UnpackSnorm4x8:
emit_unary_func_op(result_type, id, args[0], "unpack_snorm4x8_to_float");
Expand All @@ -2097,9 +2102,14 @@ void CompilerMSL::emit_glsl_op(uint32_t result_type, uint32_t id, uint32_t eop,
case GLSLstd450UnpackUnorm2x16:
emit_unary_func_op(result_type, id, args[0], "unpack_unorm2x16_to_float");
break;

case GLSLstd450UnpackHalf2x16:
emit_unary_func_op(result_type, id, args[0], "unsupported_GLSLstd450UnpackHalf2x16"); // Currently unsupported
{
auto expr = join("float2(as_type<half2>(", to_expression(args[0]), "))");
emit_op(result_type, id, expr, should_forward(args[0]));
inherit_expression_dependencies(id, args[0]);
break;
}

case GLSLstd450PackDouble2x32:
emit_unary_func_op(result_type, id, args[0], "unsupported_GLSLstd450PackDouble2x32"); // Currently unsupported
Expand Down

0 comments on commit 4979d10

Please sign in to comment.