Add support for OpQuantizeF16.

This commit is contained in:
Hans-Kristian Arntzen 2016-05-31 16:56:15 +02:00
parent c172a3507c
commit 81a8fc1952
3 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer SSBO0
{
float scalar;
vec2 vec2_val;
vec3 vec3_val;
vec4 vec4_val;
} _4;
void main()
{
_4.scalar = unpackHalf2x16(packHalf2x16(vec2(_4.scalar))).x;
_4.vec2_val = unpackHalf2x16(packHalf2x16(_4.vec2_val));
_4.vec3_val = vec3(unpackHalf2x16(packHalf2x16(_4.vec3_val.xy)), unpackHalf2x16(packHalf2x16(_4.vec3_val.zz)).x);
_4.vec4_val = vec4(unpackHalf2x16(packHalf2x16(_4.vec4_val.xy)), unpackHalf2x16(packHalf2x16(_4.vec4_val.zw)));
}

View File

@ -0,0 +1,67 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 1
; Bound: 38
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %4 "main"
OpExecutionMode %4 LocalSize 1 1 1
OpSource ESSL 310
OpName %4 "main"
OpName %10 "SSBO0"
OpMemberName %10 0 "scalar"
OpMemberName %10 1 "vec2_val"
OpMemberName %10 2 "vec3_val"
OpMemberName %10 3 "vec4_val"
OpName %12 ""
OpMemberDecorate %10 0 Offset 0
OpMemberDecorate %10 1 Offset 8
OpMemberDecorate %10 2 Offset 16
OpMemberDecorate %10 3 Offset 32
OpDecorate %10 BufferBlock
OpDecorate %12 DescriptorSet 0
OpDecorate %12 Binding 0
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypeVector %6 2
%8 = OpTypeVector %6 3
%9 = OpTypeVector %6 4
%10 = OpTypeStruct %6 %7 %8 %9
%11 = OpTypePointer Uniform %10
%12 = OpVariable %11 Uniform
%13 = OpTypeInt 32 1
%14 = OpConstant %13 0
%15 = OpTypePointer Uniform %6
%20 = OpConstant %13 1
%21 = OpTypePointer Uniform %7
%26 = OpConstant %13 2
%27 = OpTypePointer Uniform %8
%32 = OpConstant %13 3
%33 = OpTypePointer Uniform %9
%4 = OpFunction %2 None %3
%5 = OpLabel
%16 = OpAccessChain %15 %12 %14
%17 = OpLoad %6 %16
%18 = OpQuantizeToF16 %6 %17
%19 = OpAccessChain %15 %12 %14
OpStore %19 %18
%22 = OpAccessChain %21 %12 %20
%23 = OpLoad %7 %22
%24 = OpQuantizeToF16 %7 %23
%25 = OpAccessChain %21 %12 %20
OpStore %25 %24
%28 = OpAccessChain %27 %12 %26
%29 = OpLoad %8 %28
%30 = OpQuantizeToF16 %8 %29
%31 = OpAccessChain %27 %12 %26
OpStore %31 %30
%34 = OpAccessChain %33 %12 %32
%35 = OpLoad %9 %34
%36 = OpQuantizeToF16 %9 %35
%37 = OpAccessChain %33 %12 %32
OpStore %37 %36
OpReturn
OpFunctionEnd

View File

@ -3241,6 +3241,45 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
break;
}
case OpQuantizeToF16:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
uint32_t arg = ops[2];
string op;
auto &type = get<SPIRType>(result_type);
switch (type.vecsize)
{
case 1:
op = join("unpackHalf2x16(packHalf2x16(vec2(", to_expression(arg), "))).x");
break;
case 2:
op = join("unpackHalf2x16(packHalf2x16(", to_expression(arg), "))");
break;
case 3:
{
auto op0 = join("unpackHalf2x16(packHalf2x16(", to_expression(arg), ".xy))");
auto op1 = join("unpackHalf2x16(packHalf2x16(", to_expression(arg), ".zz)).x");
op = join("vec3(", op0, ", ", op1, ")");
break;
}
case 4:
{
auto op0 = join("unpackHalf2x16(packHalf2x16(", to_expression(arg), ".xy))");
auto op1 = join("unpackHalf2x16(packHalf2x16(", to_expression(arg), ".zw))");
op = join("vec4(", op0, ", ", op1, ")");
break;
}
default:
throw CompilerError("Illegal argument to OpQuantizeToF16.");
}
emit_op(result_type, id, op, should_forward(arg), false);
break;
}
// Derivatives
case OpDPdx:
UFOP(dFdx);