Skip to content

Commit

Permalink
Add failing unit test due to topological sort
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Feb 24, 2022
1 parent 372dbcf commit 1b82362
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 67 deletions.
1 change: 1 addition & 0 deletions src/Tests/FShade.GLSL.Tests/FShade.GLSL.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Compile Include="Utilities.fs" />
<Compile Include="ConstantFolding.fs" />
<Compile Include="SimpleTests.fs" />
<Compile Include="Raytracing.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
105 changes: 105 additions & 0 deletions src/Tests/FShade.GLSL.Tests/Raytracing.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
module Raytracing

open System
open Aardvark.Base
open FShade
open NUnit.Framework
open FShade.Tests

type UniformScope with
member x.SomeUniform : V3d = uniform?SomeUniform
member x.OutputBuffer : Image2d<Formats.rgba32f> = uniform?OutputBuffer
member x.Flags : RayFlags = uniform?Flags

type Payload =
{
color : V3d
depth : int
}

let scene =
scene { accelerationStructure uniform?RaytracingScene }

[<ReflectedDefinition>]
let trace (input : RayHitInput<Payload>) =
if input.payload.depth < 16 then
let payload = { color = V3d.Zero; depth = input.payload.depth + 1}
let result = scene.TraceRay(input.ray.origin, input.ray.direction, payload, flags = uniform.Flags)
result.color
else
V3d.Zero

[<ReflectedDefinition>]
let whatever() =
V4d(uniform.SomeUniform, 1.0)


[<Test>]
let ``Reflected functions``() =
Setup.Run()

let raygenShader (input : RayGenerationInput) =
raygen {
uniform.OutputBuffer.[input.work.id.XY] <- whatever()
}

let chitShader (input : RayHitInput<Payload>) =
closestHit {
return { color = trace input; depth = 0 }
}

let chitShaderShadow (input : RayHitInput<Payload>) =
closestHit {
let shadowed = scene.TraceRay<bool>(V3d.Zero, V3d.XAxis)
if shadowed then
return { color = V3d.Zero; depth = 0 }
else
return { color = trace input; depth = 0 }
}

let effect =
let hitgroupMain =
hitgroup {
closestHit ("1", chitShader)
closestHit ("2", chitShader)
}

let hitgroupShadow =
hitgroup { closestHit chitShaderShadow }

raytracingEffect {
raygen raygenShader
hitgroup ("Main", hitgroupMain)
hitgroup ("Shadow", hitgroupShadow)
}

GLSL.shouldCompileRaytracing effect

[<Test>]
let ``Simple uniform access in reflected function``() =
Setup.Run()

let raygenShader =
raygen {
()
}

let chitShader =
closestHit {
return whatever()
}

let effect =
let hitgroup1 =
hitgroup { closestHit chitShader }

let hitgroup2 =
hitgroup { closestHit chitShader }

raytracingEffect {
raygen raygenShader
hitgroup ("1", hitgroup1)
hitgroup ("2", hitgroup2)
}

GLSL.shouldCompileRaytracing effect
67 changes: 0 additions & 67 deletions src/Tests/FShade.GLSL.Tests/SimpleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,73 +1372,6 @@ let ``Non-static sampler``() =

GLSL.shouldCompile [Effect.ofFunction fs]

type UniformScope with
member x.OutputBuffer : Image2d<Formats.rgba32f> = uniform?OutputBuffer
member x.Flags : RayFlags = uniform?Flags

type Payload =
{
color : V3d
depth : int
}

let scene =
scene { accelerationStructure uniform?RaytracingScene }

[<ReflectedDefinition>]
let trace (input : RayHitInput<Payload>) =
if input.payload.depth < 16 then
let payload = { color = V3d.Zero; depth = input.payload.depth + 1}
let result = scene.TraceRay(input.ray.origin, input.ray.direction, payload, flags = uniform.Flags)
result.color
else
V3d.Zero

[<ReflectedDefinition>]
let whatever() =
V4d(uniform.SomeUniform, 1.0)

[<Test>]
let ``Raytracing with Reflected Functions``() =
Setup.Run()

let raygenShader (input : RayGenerationInput) =
raygen {
uniform.OutputBuffer.[input.work.id.XY] <- whatever()
}

let chitShader (input : RayHitInput<Payload>) =
closestHit {
return { color = trace input; depth = 0 }
}

let chitShaderShadow (input : RayHitInput<Payload>) =
closestHit {
let shadowed = scene.TraceRay<bool>(V3d.Zero, V3d.XAxis)
if shadowed then
return { color = V3d.Zero; depth = 0 }
else
return { color = trace input; depth = 0 }
}

let effect =
let hitgroupMain =
hitgroup {
closestHit ("1", chitShader)
closestHit ("2", chitShader)
}

let hitgroupShadow =
hitgroup { closestHit chitShaderShadow }

raytracingEffect {
raygen raygenShader
hitgroup ("Main", hitgroupMain)
hitgroup ("Shadow", hitgroupShadow)
}

GLSL.shouldCompileRaytracing effect

//[<EntryPoint>]
//let main args =
// ``New Intrinsics``()
Expand Down

0 comments on commit 1b82362

Please sign in to comment.