Skip to content

Commit 05ade3b

Browse files
author
marcin-zlakowski
committed
post merge fix
1 parent 5a65c09 commit 05ade3b

8 files changed

Lines changed: 140 additions & 262 deletions

File tree

cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/SpirvProgramCompiler.scala

Lines changed: 114 additions & 220 deletions
Large diffs are not rendered by default.

cyfra-e2e-test/src/test/scala/io/computenode/cyfra/ArithmeticTests.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ArithmeticsE2eTest extends munit.FunSuite:
3232
val result = gmem.map(gf).asInstanceOf[IntMem].toArray
3333

3434
// With negative values and mod, Scala and Vulkan behave differently
35-
val expected = inArr.map: n =>
35+
val expected = inArr.map: n =>
3636
val res = ((n + 2) * (n - 3) / 5) % 7
3737
res + (if res < 0 then 7 else 0)
3838

@@ -51,8 +51,8 @@ class ArithmeticsE2eTest extends munit.FunSuite:
5151
val v2 = Algebra.vec4.tupled(f2)
5252
val v3 = Algebra.vec4.tupled(f3)
5353

54-
val gf: GFunction[GStruct.Empty, Vec4[Float32], Float32] = GFunction:
55-
v4 => (-v4).*(sc).+(v1).-(v2).dot(v3)
54+
val gf: GFunction[GStruct.Empty, Vec4[Float32], Float32] = GFunction: v4 =>
55+
(-v4).*(sc).+(v1).-(v2).dot(v3)
5656

5757
val inArr: Array[fRGBA] = (0 to 1023)
5858
.map(_.toFloat)

cyfra-e2e-test/src/test/scala/io/computenode/cyfra/FunctionsTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ class FunctionsE2eTest extends munit.FunSuite:
5858
val dotted = n.pro(f)
5959
val k = 1.0f - eta * eta * (1.0f - dotted * dotted)
6060
if k < 0.0 then (0f, 0f, 0f, 0f)
61-
else f.scl(eta).sub(n.scl(eta * dotted + math.sqrt(k).toFloat))
61+
else f.scl(eta).sub(n.scl(eta * dotted + math.sqrt(k).toFloat))
6262

6363
def floatMix(a: Float, b: Float, t: Float): Float = a * (1 - t) + b * t
64-
def vecMix(a: fRGBA, b: fRGBA, t: Float): fRGBA = (a.scl(1 - t)).add(b.scl(t))
64+
def vecMix(a: fRGBA, b: fRGBA, t: Float): fRGBA = a.scl(1 - t).add(b.scl(t))
6565
def scalaClamp(f: Float, from: Float, to: Float) = math.min(math.max(f, from), to)
6666
def scalaSmooth(e0: Float, e1: Float, x: Float): Float =
6767
val t = scalaClamp((x - e0) / (e1 - e0), 0f, 1f)

cyfra-e2e-test/src/test/scala/io/computenode/cyfra/GSeqTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GseqE2eTest extends munit.FunSuite:
2424
.zip(expected)
2525
.foreach: (res, exp) =>
2626
assert(Math.abs(res - exp) < 0.001f, s"Expected $exp but got $res")
27-
27+
2828
test("GSeq of takeWhile filter count"):
2929
val gf: GFunction[GStruct.Empty, Int32, Int32] = GFunction: n =>
3030
GSeq

cyfra-e2e-test/src/test/scala/io/computenode/cyfra/GStructTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ class GStructE2eTest extends munit.FunSuite:
5050
GSeq
5151
.gen(custom1, c => Custom(c.f * 2f, c.v.*(2f)))
5252
.limit(3)
53-
.fold[Float32](0f, (f, c) => f + c.f * (c.v.w + c.v.x + c.v.y + c.v.z))
54-
+ fl
53+
.fold[Float32](0f, (f, c) => f + c.f * (c.v.w + c.v.x + c.v.y + c.v.z)) + fl
5554

5655
val inArr = (0 to 255).map(_.toFloat).toArray
5756
val gmem = FloatMem(inArr)

cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/GContext.scala

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import java.nio.channels.FileChannel
2222
import java.util.concurrent.Executors
2323
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
2424

25-
2625
class GContext:
2726

2827
Configuration.STACK_SIZE.set(1024) // fix lwjgl stack size
@@ -31,20 +30,13 @@ class GContext:
3130

3231
implicit val ec: ExecutionContextExecutor = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(16))
3332

34-
def compile[
35-
G <: GStruct[G] : Tag : GStructSchema,
36-
H <: Value : Tag : FromExpr,
37-
R <: Value : Tag : FromExpr
38-
](function: GFunction[G, H, R]): ComputePipeline = {
33+
def compile[G <: GStruct[G]: Tag: GStructSchema, H <: Value: Tag: FromExpr, R <: Value: Tag: FromExpr](
34+
function: GFunction[G, H, R],
35+
): ComputePipeline = {
3936
val uniformStructSchema = summon[GStructSchema[G]]
4037
val uniformStruct = uniformStructSchema.fromTree(UniformStructRef)
41-
val tree = function
42-
.fn
43-
.apply(
44-
uniformStruct,
45-
WorkerIndex,
46-
GArray[H](0)
47-
)
38+
val tree = function.fn
39+
.apply(uniformStruct, WorkerIndex, GArray[H](0))
4840
val shaderCode = DSLCompiler.compile(tree, function.arrayInputs, function.arrayOutputs, uniformStructSchema)
4941
dumpSpvToFile(shaderCode, "program.spv") // TODO remove before release
5042
val inOut = 0 to 1 map (Binding(_, InputBufferSize(typeStride(summon[Tag[H]]))))
@@ -60,22 +52,18 @@ class GContext:
6052
fc.close()
6153
code.rewind()
6254

63-
def execute[
64-
G <: GStruct[G] : Tag : GStructSchema,
65-
H <: Value,
66-
R <: Value
67-
](mem: GMem[H], fn: GFunction[G, H, R])(using uniformContext: UniformContext[G]): GMem[R] =
55+
def execute[G <: GStruct[G]: Tag: GStructSchema, H <: Value, R <: Value](mem: GMem[H], fn: GFunction[G, H, R])(using
56+
uniformContext: UniformContext[G],
57+
): GMem[R] =
6858
val isUniformEmpty = uniformContext.uniform.schema.fields.isEmpty
69-
val actions = Map(
70-
LayoutLocation(0, 0) -> BufferAction.LoadTo,
71-
LayoutLocation(0, 1) -> BufferAction.LoadFrom
72-
) ++ (
73-
if isUniformEmpty then Map.empty
74-
else Map(LayoutLocation(0, 2) -> BufferAction.LoadTo)
75-
)
59+
val actions = Map(LayoutLocation(0, 0) -> BufferAction.LoadTo, LayoutLocation(0, 1) -> BufferAction.LoadFrom) ++
60+
(
61+
if isUniformEmpty then Map.empty
62+
else Map(LayoutLocation(0, 2) -> BufferAction.LoadTo)
63+
)
7664
val sequence = ComputationSequence(Seq(Compute(fn.pipeline, actions)), Seq.empty)
7765
val executor = new SequenceExecutor(sequence, vkContext)
78-
66+
7967
val data = mem.toReadOnlyBuffer
8068
val inData =
8169
if isUniformEmpty then Seq(data)
@@ -94,4 +82,3 @@ class GContext:
9482
case t if t == Tag[Vec4[Float32]] =>
9583
new Vec4FloatMem(mem.size, out.head).asInstanceOf[GMem[R]]
9684
case _ => assert(false, "Supported output types are Float32 and Vec4[Float32]")
97-

cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/mem/GMem.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ import java.nio.ByteBuffer
1616
trait GMem[H <: Value]:
1717
def size: Int
1818
def toReadOnlyBuffer: ByteBuffer
19-
def map[
20-
G <: GStruct[G] : Tag : GStructSchema,
21-
R <: Value : FromExpr : Tag
22-
](fn: GFunction[G, H, R])(using context: GContext, uc: UniformContext[G]): GMem[R] =
19+
def map[G <: GStruct[G]: Tag: GStructSchema, R <: Value: FromExpr: Tag](
20+
fn: GFunction[G, H, R],
21+
)(using context: GContext, uc: UniformContext[G]): GMem[R] =
2322
context.execute(this, fn)
2423

2524
object GMem:
@@ -36,7 +35,7 @@ object GMem:
3635
def serializeUniform(g: GStruct[?]): ByteBuffer = {
3736
val data = BufferUtils.createByteBuffer(totalStride(g.schema))
3837
g.productIterator.foreach {
39-
case Int32(ConstInt32(i)) => data.putInt(i)
38+
case Int32(ConstInt32(i)) => data.putInt(i)
4039
case Float32(ConstFloat32(f)) => data.putFloat(f)
4140
case Vec4(ComposeVec4(Float32(ConstFloat32(x)), Float32(ConstFloat32(y)), Float32(ConstFloat32(z)), Float32(ConstFloat32(a)))) =>
4241
data.putFloat(x)

cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/mem/IntMem.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class IntMem(val size: Int, protected val data: ByteBuffer) extends RamGMem[Int3
1313
res.get(result)
1414
result
1515

16-
1716
object IntMem:
1817
val IntSize = 4
1918

@@ -24,6 +23,6 @@ object IntMem:
2423
data.rewind()
2524
new IntMem(size, data)
2625

27-
def apply(size: Int): IntMem =
26+
def apply(size: Int): IntMem =
2827
val data = BufferUtils.createByteBuffer(size * IntSize)
2928
new IntMem(size, data)

0 commit comments

Comments
 (0)