Skip to content

Commit

Permalink
Add refract intrinsic
Browse files Browse the repository at this point in the history
See: gpuweb/gpuweb#1901

Bug: tint:950
Change-Id: I6f00ab753a2ddf2374352ddf636e1abfebe86ba7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/56777
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
  • Loading branch information
ben-clayton authored and Tint LUCI CQ committed Jul 5, 2021
1 parent 892aaf3 commit b045521
Show file tree
Hide file tree
Showing 23 changed files with 1,833 additions and 1,240 deletions.
2,503 changes: 1,268 additions & 1,235 deletions src/intrinsic_table.inl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/intrinsics.def
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ fn pow(f32, f32) -> f32
fn pow<N: num>(vec<N, f32>, vec<N, f32>) -> vec<N, f32>
fn reflect(f32, f32) -> f32
fn reflect<N: num>(vec<N, f32>, vec<N, f32>) -> vec<N, f32>
fn refract<N: num>(vec<N, f32>, vec<N, f32>, f32) -> vec<N, f32>
fn reverseBits<T: iu32>(T) -> T
fn reverseBits<N: num, T: iu32>(vec<N, T>) -> vec<N, T>
fn round(f32) -> f32
Expand Down
9 changes: 4 additions & 5 deletions src/reader/spirv/function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ std::string GetGlslStd450FuncName(uint32_t ext_opcode) {
return "sign";
case GLSLstd450Reflect:
return "reflect";
case GLSLstd450Refract:
return "refract";
case GLSLstd450Round:
case GLSLstd450RoundEven:
return "round";
Expand Down Expand Up @@ -419,8 +421,6 @@ std::string GetGlslStd450FuncName(uint32_t ext_opcode) {
case GLSLstd450PackDouble2x32:
case GLSLstd450UnpackDouble2x32:

case GLSLstd450Refract:

case GLSLstd450FindILsb:
case GLSLstd450FindSMsb:
case GLSLstd450FindUMsb:
Expand Down Expand Up @@ -1055,9 +1055,8 @@ void FunctionEmitter::IncrementLocation(ast::DecorationList* decos) {
}
}

ast::Decoration* FunctionEmitter::SetLocation(
ast::DecorationList* decos,
ast::Decoration* replacement) {
ast::Decoration* FunctionEmitter::SetLocation(ast::DecorationList* decos,
ast::Decoration* replacement) {
if (!replacement) {
return nullptr;
}
Expand Down
5 changes: 5 additions & 0 deletions src/sem/intrinsic_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ IntrinsicType ParseIntrinsicType(const std::string& name) {
if (name == "reflect") {
return IntrinsicType::kReflect;
}
if (name == "refract") {
return IntrinsicType::kRefract;
}
if (name == "reverseBits") {
return IntrinsicType::kReverseBits;
}
Expand Down Expand Up @@ -436,6 +439,8 @@ const char* str(IntrinsicType i) {
return "pow";
case IntrinsicType::kReflect:
return "reflect";
case IntrinsicType::kRefract:
return "refract";
case IntrinsicType::kReverseBits:
return "reverseBits";
case IntrinsicType::kRound:
Expand Down
1 change: 1 addition & 0 deletions src/sem/intrinsic_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ enum class IntrinsicType {
kPack4x8unorm,
kPow,
kReflect,
kRefract,
kReverseBits,
kRound,
kSelect,
Expand Down
1 change: 1 addition & 0 deletions src/writer/hlsl/generator_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,7 @@ std::string GeneratorImpl::generate_builtin_name(
case sem::IntrinsicType::kNormalize:
case sem::IntrinsicType::kPow:
case sem::IntrinsicType::kReflect:
case sem::IntrinsicType::kRefract:
case sem::IntrinsicType::kRound:
case sem::IntrinsicType::kSign:
case sem::IntrinsicType::kSin:
Expand Down
1 change: 1 addition & 0 deletions src/writer/msl/generator_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ std::string GeneratorImpl::generate_builtin_name(
case sem::IntrinsicType::kNormalize:
case sem::IntrinsicType::kPow:
case sem::IntrinsicType::kReflect:
case sem::IntrinsicType::kRefract:
case sem::IntrinsicType::kSelect:
case sem::IntrinsicType::kSin:
case sem::IntrinsicType::kSinh:
Expand Down
2 changes: 2 additions & 0 deletions src/writer/spirv/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ uint32_t intrinsic_to_glsl_method(const sem::Intrinsic* intrinsic) {
return GLSLstd450Pow;
case IntrinsicType::kReflect:
return GLSLstd450Reflect;
case IntrinsicType::kRefract:
return GLSLstd450Refract;
case IntrinsicType::kRound:
return GLSLstd450RoundEven;
case IntrinsicType::kSign:
Expand Down
45 changes: 45 additions & 0 deletions test/intrinsics/gen/refract/7e02e6.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

////////////////////////////////////////////////////////////////////////////////
// File generated by tools/intrinsic-gen
// using the template:
// test/intrinsics/intrinsics.wgsl.tmpl
// and the intrinsic defintion file:
// src/intrinsics.def
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////


// fn refract(vec<4, f32>, vec<4, f32>, f32) -> vec<4, f32>
fn refract_7e02e6() {
var res: vec4<f32> = refract(vec4<f32>(), vec4<f32>(), 1.0);
}

[[stage(vertex)]]
fn vertex_main() -> [[builtin(position)]] vec4<f32> {
refract_7e02e6();
return vec4<f32>();
}

[[stage(fragment)]]
fn fragment_main() {
refract_7e02e6();
}

[[stage(compute), workgroup_size(1)]]
fn compute_main() {
refract_7e02e6();
}
24 changes: 24 additions & 0 deletions test/intrinsics/gen/refract/7e02e6.wgsl.expected.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
void refract_7e02e6() {
float4 res = refract(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), 1.0f);
}

struct tint_symbol {
float4 value : SV_Position;
};

tint_symbol vertex_main() {
refract_7e02e6();
const tint_symbol tint_symbol_1 = {float4(0.0f, 0.0f, 0.0f, 0.0f)};
return tint_symbol_1;
}

void fragment_main() {
refract_7e02e6();
return;
}

[numthreads(1, 1, 1)]
void compute_main() {
refract_7e02e6();
return;
}
27 changes: 27 additions & 0 deletions test/intrinsics/gen/refract/7e02e6.wgsl.expected.msl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <metal_stdlib>

using namespace metal;
struct tint_symbol {
float4 value [[position]];
};

void refract_7e02e6() {
float4 res = refract(float4(), float4(), 1.0f);
}

vertex tint_symbol vertex_main() {
refract_7e02e6();
tint_symbol const tint_symbol_1 = {.value=float4()};
return tint_symbol_1;
}

fragment void fragment_main() {
refract_7e02e6();
return;
}

kernel void compute_main() {
refract_7e02e6();
return;
}

67 changes: 67 additions & 0 deletions test/intrinsics/gen/refract/7e02e6.wgsl.expected.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 32
; Schema: 0
OpCapability Shader
%14 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %vertex_main "vertex_main" %tint_pointsize %tint_symbol_1
OpEntryPoint Fragment %fragment_main "fragment_main"
OpEntryPoint GLCompute %compute_main "compute_main"
OpExecutionMode %fragment_main OriginUpperLeft
OpExecutionMode %compute_main LocalSize 1 1 1
OpName %tint_pointsize "tint_pointsize"
OpName %tint_symbol_1 "tint_symbol_1"
OpName %refract_7e02e6 "refract_7e02e6"
OpName %res "res"
OpName %tint_symbol_2 "tint_symbol_2"
OpName %tint_symbol "tint_symbol"
OpName %vertex_main "vertex_main"
OpName %fragment_main "fragment_main"
OpName %compute_main "compute_main"
OpDecorate %tint_pointsize BuiltIn PointSize
OpDecorate %tint_symbol_1 BuiltIn Position
%float = OpTypeFloat 32
%_ptr_Output_float = OpTypePointer Output %float
%4 = OpConstantNull %float
%tint_pointsize = OpVariable %_ptr_Output_float Output %4
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%8 = OpConstantNull %v4float
%tint_symbol_1 = OpVariable %_ptr_Output_v4float Output %8
%void = OpTypeVoid
%9 = OpTypeFunction %void
%float_1 = OpConstant %float 1
%_ptr_Function_v4float = OpTypePointer Function %v4float
%18 = OpTypeFunction %void %v4float
%refract_7e02e6 = OpFunction %void None %9
%12 = OpLabel
%res = OpVariable %_ptr_Function_v4float Function %8
%13 = OpExtInst %v4float %14 Refract %8 %8 %float_1
OpStore %res %13
OpReturn
OpFunctionEnd
%tint_symbol_2 = OpFunction %void None %18
%tint_symbol = OpFunctionParameter %v4float
%21 = OpLabel
OpStore %tint_symbol_1 %tint_symbol
OpReturn
OpFunctionEnd
%vertex_main = OpFunction %void None %9
%23 = OpLabel
OpStore %tint_pointsize %float_1
%24 = OpFunctionCall %void %refract_7e02e6
%25 = OpFunctionCall %void %tint_symbol_2 %8
OpReturn
OpFunctionEnd
%fragment_main = OpFunction %void None %9
%27 = OpLabel
%28 = OpFunctionCall %void %refract_7e02e6
OpReturn
OpFunctionEnd
%compute_main = OpFunction %void None %9
%30 = OpLabel
%31 = OpFunctionCall %void %refract_7e02e6
OpReturn
OpFunctionEnd
19 changes: 19 additions & 0 deletions test/intrinsics/gen/refract/7e02e6.wgsl.expected.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fn refract_7e02e6() {
var res : vec4<f32> = refract(vec4<f32>(), vec4<f32>(), 1.0);
}

[[stage(vertex)]]
fn vertex_main() -> [[builtin(position)]] vec4<f32> {
refract_7e02e6();
return vec4<f32>();
}

[[stage(fragment)]]
fn fragment_main() {
refract_7e02e6();
}

[[stage(compute), workgroup_size(1)]]
fn compute_main() {
refract_7e02e6();
}
45 changes: 45 additions & 0 deletions test/intrinsics/gen/refract/cbc1d2.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

////////////////////////////////////////////////////////////////////////////////
// File generated by tools/intrinsic-gen
// using the template:
// test/intrinsics/intrinsics.wgsl.tmpl
// and the intrinsic defintion file:
// src/intrinsics.def
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////


// fn refract(vec<3, f32>, vec<3, f32>, f32) -> vec<3, f32>
fn refract_cbc1d2() {
var res: vec3<f32> = refract(vec3<f32>(), vec3<f32>(), 1.0);
}

[[stage(vertex)]]
fn vertex_main() -> [[builtin(position)]] vec4<f32> {
refract_cbc1d2();
return vec4<f32>();
}

[[stage(fragment)]]
fn fragment_main() {
refract_cbc1d2();
}

[[stage(compute), workgroup_size(1)]]
fn compute_main() {
refract_cbc1d2();
}
24 changes: 24 additions & 0 deletions test/intrinsics/gen/refract/cbc1d2.wgsl.expected.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
void refract_cbc1d2() {
float3 res = refract(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), 1.0f);
}

struct tint_symbol {
float4 value : SV_Position;
};

tint_symbol vertex_main() {
refract_cbc1d2();
const tint_symbol tint_symbol_1 = {float4(0.0f, 0.0f, 0.0f, 0.0f)};
return tint_symbol_1;
}

void fragment_main() {
refract_cbc1d2();
return;
}

[numthreads(1, 1, 1)]
void compute_main() {
refract_cbc1d2();
return;
}
27 changes: 27 additions & 0 deletions test/intrinsics/gen/refract/cbc1d2.wgsl.expected.msl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <metal_stdlib>

using namespace metal;
struct tint_symbol {
float4 value [[position]];
};

void refract_cbc1d2() {
float3 res = refract(float3(), float3(), 1.0f);
}

vertex tint_symbol vertex_main() {
refract_cbc1d2();
tint_symbol const tint_symbol_1 = {.value=float4()};
return tint_symbol_1;
}

fragment void fragment_main() {
refract_cbc1d2();
return;
}

kernel void compute_main() {
refract_cbc1d2();
return;
}

Loading

0 comments on commit b045521

Please sign in to comment.