Merge pull request #455 from KhronosGroup/fix-452

Implement OpFRem.
This commit is contained in:
Hans-Kristian Arntzen 2018-02-15 14:48:25 +01:00 committed by GitHub
commit 218b0a5ca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 285 additions and 3 deletions

View File

@ -0,0 +1,29 @@
static float4 FragColor;
static float4 vA;
static float4 vB;
struct SPIRV_Cross_Input
{
float4 vA : TEXCOORD0;
float4 vB : TEXCOORD1;
};
struct SPIRV_Cross_Output
{
float4 FragColor : SV_Target0;
};
void frag_main()
{
FragColor = fmod(vA, vB);
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
vA = stage_input.vA;
vB = stage_input.vB;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;
return stage_output;
}

View File

@ -0,0 +1,23 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_in
{
float4 vB [[user(locn1)]];
float4 vA [[user(locn0)]];
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.FragColor = fmod(in.vA, in.vB);
return out;
}

View File

@ -0,0 +1,13 @@
#version 310 es
precision mediump float;
precision highp int;
layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec4 vA;
layout(location = 1) in vec4 vB;
void main()
{
FragColor = vA - vB * trunc(vA / vB);
}

View File

@ -0,0 +1,29 @@
static float4 FragColor;
static float4 vA;
static float4 vB;
struct SPIRV_Cross_Input
{
float4 vA : TEXCOORD0;
float4 vB : TEXCOORD1;
};
struct SPIRV_Cross_Output
{
float4 FragColor : SV_Target0;
};
void frag_main()
{
FragColor = fmod(vA, vB);
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
vA = stage_input.vA;
vB = stage_input.vB;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;
return stage_output;
}

View File

@ -0,0 +1,23 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_in
{
float4 vB [[user(locn1)]];
float4 vA [[user(locn0)]];
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.FragColor = fmod(in.vA, in.vB);
return out;
}

View File

@ -0,0 +1,13 @@
#version 310 es
precision mediump float;
precision highp int;
layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec4 vA;
layout(location = 1) in vec4 vB;
void main()
{
FragColor = vA - vB * trunc(vA / vB);
}

View File

@ -0,0 +1,41 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 3
; Bound: 16
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %FragColor %vA %vB
OpExecutionMode %main OriginUpperLeft
OpSource ESSL 310
OpName %main "main"
OpName %FragColor "FragColor"
OpName %vA "vA"
OpName %vB "vB"
OpDecorate %FragColor RelaxedPrecision
OpDecorate %FragColor Location 0
OpDecorate %vA RelaxedPrecision
OpDecorate %vA Location 0
OpDecorate %12 RelaxedPrecision
OpDecorate %vB RelaxedPrecision
OpDecorate %vB Location 1
OpDecorate %14 RelaxedPrecision
OpDecorate %15 RelaxedPrecision
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%FragColor = OpVariable %_ptr_Output_v4float Output
%_ptr_Input_v4float = OpTypePointer Input %v4float
%vA = OpVariable %_ptr_Input_v4float Input
%vB = OpVariable %_ptr_Input_v4float Input
%main = OpFunction %void None %3
%5 = OpLabel
%12 = OpLoad %v4float %vA
%14 = OpLoad %v4float %vB
%15 = OpFRem %v4float %12 %14
OpStore %FragColor %15
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,41 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 3
; Bound: 16
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %FragColor %vA %vB
OpExecutionMode %main OriginUpperLeft
OpSource ESSL 310
OpName %main "main"
OpName %FragColor "FragColor"
OpName %vA "vA"
OpName %vB "vB"
OpDecorate %FragColor RelaxedPrecision
OpDecorate %FragColor Location 0
OpDecorate %vA RelaxedPrecision
OpDecorate %vA Location 0
OpDecorate %12 RelaxedPrecision
OpDecorate %vB RelaxedPrecision
OpDecorate %vB Location 1
OpDecorate %14 RelaxedPrecision
OpDecorate %15 RelaxedPrecision
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%FragColor = OpVariable %_ptr_Output_v4float Output
%_ptr_Input_v4float = OpTypePointer Input %v4float
%vA = OpVariable %_ptr_Input_v4float Input
%vB = OpVariable %_ptr_Input_v4float Input
%main = OpFunction %void None %3
%5 = OpLabel
%12 = OpLoad %v4float %vA
%14 = OpLoad %v4float %vB
%15 = OpFRem %v4float %12 %14
OpStore %FragColor %15
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,41 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 3
; Bound: 16
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %FragColor %vA %vB
OpExecutionMode %main OriginUpperLeft
OpSource ESSL 310
OpName %main "main"
OpName %FragColor "FragColor"
OpName %vA "vA"
OpName %vB "vB"
OpDecorate %FragColor RelaxedPrecision
OpDecorate %FragColor Location 0
OpDecorate %vA RelaxedPrecision
OpDecorate %vA Location 0
OpDecorate %12 RelaxedPrecision
OpDecorate %vB RelaxedPrecision
OpDecorate %vB Location 1
OpDecorate %14 RelaxedPrecision
OpDecorate %15 RelaxedPrecision
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%FragColor = OpVariable %_ptr_Output_v4float Output
%_ptr_Input_v4float = OpTypePointer Input %v4float
%vA = OpVariable %_ptr_Input_v4float Input
%vB = OpVariable %_ptr_Input_v4float Input
%main = OpFunction %void None %3
%5 = OpLabel
%12 = OpLoad %v4float %vA
%14 = OpLoad %v4float %vB
%15 = OpFRem %v4float %12 %14
OpStore %FragColor %15
OpReturn
OpFunctionEnd

View File

@ -5909,6 +5909,28 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
BFOP(mod);
break;
case OpFRem:
{
if (is_legacy())
SPIRV_CROSS_THROW("OpFRem requires trunc() and is only supported on non-legacy targets. A workaround is "
"needed for legacy.");
uint32_t result_type = ops[0];
uint32_t result_id = ops[1];
uint32_t op0 = ops[2];
uint32_t op1 = ops[3];
// Needs special handling.
bool forward = should_forward(op0) && should_forward(op1);
auto expr = join(to_enclosed_expression(op0), " - ", to_enclosed_expression(op1), " * ", "trunc(",
to_enclosed_expression(op0), " / ", to_enclosed_expression(op1), ")");
emit_op(result_type, result_id, expr, forward);
inherit_expression_dependencies(result_id, op0);
inherit_expression_dependencies(result_id, op1);
break;
}
// Relational
case OpAny:
UFOP(any);

View File

@ -3224,6 +3224,10 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
break;
}
case OpFRem:
emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], "fmod");
break;
case OpImage:
{
uint32_t result_type = ops[0];

View File

@ -18,8 +18,8 @@
#include "GLSL.std.450.h"
#include <algorithm>
#include <numeric>
#include <assert.h>
#include <numeric>
using namespace spv;
using namespace spirv_cross;
@ -66,8 +66,7 @@ void CompilerMSL::build_implicit_builtins()
auto &var = id.get<SPIRVariable>();
if (var.storage == StorageClassInput &&
meta[var.self].decoration.builtin &&
if (var.storage == StorageClassInput && meta[var.self].decoration.builtin &&
meta[var.self].decoration.builtin_type == BuiltInFragCoord)
{
builtin_frag_coord_id = var.self;
@ -1486,6 +1485,10 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
UFOP(popcount);
break;
case OpFRem:
BFOP(fmod);
break;
// Atomics
case OpAtomicExchange:
{