Skip to content

Commit bfbde17

Browse files
committed
First version of core refactor
1 parent 6b9de69 commit bfbde17

File tree

32 files changed

+1090
-144
lines changed

32 files changed

+1090
-144
lines changed

cyfra-core/src/main/scala/io/computenode/cyfra/core/Allocation.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package io.computenode.cyfra.core
22

3+
import io.computenode.cyfra.core.binding.{GBinding, GBuffer, GUniform}
4+
import io.computenode.cyfra.core.expression.Value
35
import io.computenode.cyfra.core.layout.{Layout, LayoutBinding}
4-
import io.computenode.cyfra.dsl.Value
5-
import io.computenode.cyfra.dsl.Value.FromExpr
6-
import io.computenode.cyfra.dsl.binding.{GBinding, GBuffer, GUniform}
7-
import io.computenode.cyfra.dsl.struct.{GStruct, GStructSchema}
86
import izumi.reflect.Tag
97

108
import java.nio.ByteBuffer
@@ -21,11 +19,11 @@ trait Allocation:
2119
def execute(params: Params, layout: EL): RL
2220

2321
extension (buffers: GBuffer.type)
24-
def apply[T <: Value: {Tag, FromExpr}](length: Int): GBuffer[T]
22+
def apply[T: Value](length: Int): GBuffer[T]
2523

26-
def apply[T <: Value: {Tag, FromExpr}](buff: ByteBuffer): GBuffer[T]
24+
def apply[T: Value](buff: ByteBuffer): GBuffer[T]
2725

2826
extension (buffers: GUniform.type)
29-
def apply[T <: GStruct[T]: {Tag, FromExpr, GStructSchema}](buff: ByteBuffer): GUniform[T]
27+
def apply[T: Value](buff: ByteBuffer): GUniform[T]
3028

31-
def apply[T <: GStruct[T]: {Tag, FromExpr, GStructSchema}](): GUniform[T]
29+
def apply[T: Value](): GUniform[T]

cyfra-core/src/main/scala/io/computenode/cyfra/core/GioProgram.scala renamed to cyfra-core/src/main/scala/io/computenode/cyfra/core/ExpressionProgram.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package io.computenode.cyfra.core
22

33
import io.computenode.cyfra.core.GProgram.*
44
import io.computenode.cyfra.core.layout.*
5-
import io.computenode.cyfra.dsl.Value.GBoolean
6-
import io.computenode.cyfra.dsl.gio.GIO
5+
import io.computenode.cyfra.core.expression.ExpressionBlock
76
import izumi.reflect.Tag
87

9-
case class GioProgram[Params, L <: Layout: {LayoutBinding, LayoutStruct}](
10-
body: L => GIO[?],
8+
case class ExpressionProgram[Params, L <: Layout: {LayoutBinding, LayoutStruct}](
9+
body: L => ExpressionBlock[Unit],
1110
layout: InitProgramLayout => Params => L,
1211
dispatch: (L, Params) => ProgramDispatch,
1312
workgroupSize: WorkDimensions,

cyfra-core/src/main/scala/io/computenode/cyfra/core/GBufferRegion.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import io.computenode.cyfra.core.Allocation
44
import io.computenode.cyfra.core.GBufferRegion.MapRegion
55
import io.computenode.cyfra.core.GProgram.BufferLengthSpec
66
import io.computenode.cyfra.core.layout.{Layout, LayoutBinding}
7-
import io.computenode.cyfra.dsl.Value
8-
import io.computenode.cyfra.dsl.Value.FromExpr
9-
import io.computenode.cyfra.dsl.binding.GBuffer
7+
import io.computenode.cyfra.core.expression.Value
8+
import io.computenode.cyfra.core.binding.GBuffer
109
import izumi.reflect.Tag
1110

1211
import scala.util.chaining.given

cyfra-core/src/main/scala/io/computenode/cyfra/core/GExecution.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package io.computenode.cyfra.core
22

33
import io.computenode.cyfra.core.GExecution.*
44
import io.computenode.cyfra.core.layout.*
5-
import io.computenode.cyfra.dsl.binding.GBuffer
6-
import io.computenode.cyfra.dsl.gio.GIO
7-
import io.computenode.cyfra.dsl.struct.{GStruct, GStructSchema}
5+
import io.computenode.cyfra.core.binding.GBuffer
86
import izumi.reflect.Tag
97
import GExecution.*
108

cyfra-core/src/main/scala/io/computenode/cyfra/core/GProgram.scala

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package io.computenode.cyfra.core
22

33
import io.computenode.cyfra.core.layout.{Layout, LayoutBinding, LayoutStruct}
4-
import io.computenode.cyfra.dsl.gio.GIO
54

65
import java.nio.ByteBuffer
76
import GProgram.*
8-
import io.computenode.cyfra.dsl.{Expression, Value}
9-
import io.computenode.cyfra.dsl.Value.{FromExpr, GBoolean, Int32}
10-
import io.computenode.cyfra.dsl.binding.{GBinding, GBuffer, GUniform}
11-
import io.computenode.cyfra.dsl.struct.{GStruct, GStructSchema}
12-
import io.computenode.cyfra.dsl.struct.GStruct.Empty
7+
import io.computenode.cyfra.core.binding.GUniform
8+
import io.computenode.cyfra.core.binding.GBuffer
9+
import io.computenode.cyfra.core.binding.GBinding
10+
import io.computenode.cyfra.core.expression.{ExpressionBlock, Value}
1311
import izumi.reflect.Tag
1412

1513
import java.io.FileInputStream
@@ -33,8 +31,8 @@ object GProgram:
3331
layout: InitProgramLayout ?=> Params => L,
3432
dispatch: (L, Params) => ProgramDispatch,
3533
workgroupSize: WorkDimensions = (128, 1, 1),
36-
)(body: L => GIO[?]): GProgram[Params, L] =
37-
new GioProgram[Params, L](body, s => layout(using s), dispatch, workgroupSize)
34+
)(body: L => ExpressionBlock[Unit]): GProgram[Params, L] =
35+
new ExpressionProgram[Params, L](body, s => layout(using s), dispatch, workgroupSize)
3836

3937
def fromSpirvFile[Params, L <: Layout: {LayoutBinding, LayoutStruct}](
4038
layout: InitProgramLayout ?=> Params => L,
@@ -49,16 +47,16 @@ object GProgram:
4947
bb.flip()
5048
SpirvProgram(layout, dispatch, bb)
5149

52-
private[cyfra] class BufferLengthSpec[T <: Value: {Tag, FromExpr}](val length: Int) extends GBuffer[T]:
50+
private[cyfra] class BufferLengthSpec[T: Value](val length: Int) extends GBuffer[T]:
5351
private[cyfra] def materialise()(using Allocation): GBuffer[T] = GBuffer.apply[T](length)
54-
private[cyfra] class DynamicUniform[T <: GStruct[T]: {Tag, FromExpr, GStructSchema}]() extends GUniform[T]
52+
private[cyfra] class DynamicUniform[T: Value]() extends GUniform[T]
5553

5654
trait InitProgramLayout:
5755
extension (_buffers: GBuffer.type)
58-
def apply[T <: Value: {Tag, FromExpr}](length: Int): GBuffer[T] =
56+
def apply[T: Value](length: Int): GBuffer[T] =
5957
BufferLengthSpec[T](length)
6058

6159
extension (_uniforms: GUniform.type)
62-
def apply[T <: GStruct[T]: {Tag, FromExpr, GStructSchema}](): GUniform[T] =
60+
def apply[T: Value](): GUniform[T] =
6361
DynamicUniform[T]()
64-
def apply[T <: GStruct[?]: {Tag, FromExpr, GStructSchema}](value: T): GUniform[T]
62+
def apply[T: Value](value: T): GUniform[T]

cyfra-core/src/main/scala/io/computenode/cyfra/core/SpirvProgram.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import io.computenode.cyfra.core.layout.{Layout, LayoutBinding, LayoutStruct}
44
import io.computenode.cyfra.core.GProgram.{InitProgramLayout, ProgramDispatch, WorkDimensions}
55
import io.computenode.cyfra.core.SpirvProgram.Operation.ReadWrite
66
import io.computenode.cyfra.core.SpirvProgram.{Binding, ShaderLayout}
7-
import io.computenode.cyfra.dsl.Value
8-
import io.computenode.cyfra.dsl.Value.{FromExpr, GBoolean}
9-
import io.computenode.cyfra.dsl.binding.GBinding
10-
import io.computenode.cyfra.dsl.gio.GIO
7+
import io.computenode.cyfra.core.expression.Value
8+
import io.computenode.cyfra.core.binding.GBinding
119
import izumi.reflect.Tag
1210

1311
import java.io.File
@@ -44,7 +42,7 @@ case class SpirvProgram[Params, L <: Layout: {LayoutBinding, LayoutStruct}] priv
4442
)
4543
val layout = shaderBindings(summon[LayoutStruct[L]].layoutRef)
4644
layout.flatten.foreach: binding =>
47-
md.update(binding.binding.tag.toString.getBytes)
45+
// md.update(binding.binding.tag.toString.getBytes)
4846
md.update(binding.operation.toString.getBytes)
4947
val digest = md.digest()
5048
val bb = java.nio.ByteBuffer.wrap(digest)
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package io.computenode.cyfra.core.binding
22

3-
import io.computenode.cyfra.dsl.Value
4-
import io.computenode.cyfra.dsl.Value.FromExpr
5-
import io.computenode.cyfra.dsl.binding.GBuffer
63
import izumi.reflect.Tag
7-
import izumi.reflect.macrortti.LightTypeTag
4+
import io.computenode.cyfra.core.expression.Value
85

9-
case class BufferRef[T <: Value: {Tag, FromExpr}](layoutOffset: Int, valueTag: Tag[T]) extends GBuffer[T]
6+
case class BufferRef[T: Value](layoutOffset: Int, valueTag: Tag[T]) extends GBuffer[T]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.computenode.cyfra.core.binding
2+
3+
import io.computenode.cyfra.core.expression.Value
4+
5+
sealed trait GBinding[T: Value]
6+
7+
object GBinding
8+
9+
trait GBuffer[T: Value] extends GBinding[T]
10+
11+
object GBuffer
12+
13+
trait GUniform[T: Value] extends GBinding[T]
14+
15+
object GUniform:
16+
class ParamUniform[T: Value] extends GUniform[T]
17+
def fromParams[T: Value]: ParamUniform[T] = ParamUniform[T]()
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package io.computenode.cyfra.core.binding
22

3-
import io.computenode.cyfra.dsl.Value
4-
import io.computenode.cyfra.dsl.Value.FromExpr
5-
import io.computenode.cyfra.dsl.binding.{GBuffer, GUniform}
6-
import io.computenode.cyfra.dsl.struct.{GStruct, GStructSchema}
73
import izumi.reflect.Tag
8-
import izumi.reflect.macrortti.LightTypeTag
4+
import io.computenode.cyfra.core.expression.Value
95

10-
case class UniformRef[T <: GStruct[?]: {Tag, FromExpr, GStructSchema}](layoutOffset: Int, valueTag: Tag[T]) extends GUniform[T]
6+
case class UniformRef[T: Value](layoutOffset: Int, valueTag: Tag[T]) extends GUniform[T]
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package io.computenode.cyfra.core.expression
2+
3+
import io.computenode.cyfra.core.expression.*
4+
5+
abstract class BuildInFunction[-R](val isPure: Boolean):
6+
override def toString: String = s"builtin ${this.getClass.getSimpleName.replace("$", "")}"
7+
8+
object BuildInFunction:
9+
abstract class BuildInFunction0[-R](isPure: Boolean) extends BuildInFunction[R](isPure)
10+
abstract class BuildInFunction1[-A1, -R](isPure: Boolean) extends BuildInFunction[R](isPure)
11+
abstract class BuildInFunction1R[-R](isPure: Boolean) extends BuildInFunction1[R, R](isPure)
12+
abstract class BuildInFunction2[-A1, -A2, -R](isPure: Boolean) extends BuildInFunction[R](isPure)
13+
abstract class BuildInFunction2R[-R](isPure: Boolean) extends BuildInFunction2[R, R, R](isPure)
14+
abstract class BuildInFunction3[-A1, -A2, -A3, -R](isPure: Boolean) extends BuildInFunction[R](isPure)
15+
abstract class BuildInFunction4[-A1, -A2, -A3, -A4, -R](isPure: Boolean) extends BuildInFunction[R](isPure)
16+
17+
// Concreate type operations
18+
case object Add extends BuildInFunction2R[Any](true)
19+
case object Sub extends BuildInFunction2R[Any](true)
20+
case object Mul extends BuildInFunction2R[Any](true)
21+
case object Div extends BuildInFunction2R[Any](true)
22+
case object Mod extends BuildInFunction2R[Any](true)
23+
24+
// Negative type operations
25+
case object Neg extends BuildInFunction1R[Any](true)
26+
case object Rem extends BuildInFunction2R[Any](true)
27+
28+
// Vector/Matrix operations
29+
case object VectorTimesScalar extends BuildInFunction2[Any, Any, Any](true)
30+
case object MatrixTimesScalar extends BuildInFunction2[Any, Any, Any](true)
31+
case object VectorTimesMatrix extends BuildInFunction2[Any, Any, Any](true)
32+
case object MatrixTimesVector extends BuildInFunction2[Any, Any, Any](true)
33+
case object MatrixTimesMatrix extends BuildInFunction2R[Any](true)
34+
case object OuterProduct extends BuildInFunction2[Any, Any, Any](true)
35+
case object Dot extends BuildInFunction2[Any, Any, Any](true)
36+
37+
// Bitwise operations
38+
case object ShiftRightLogical extends BuildInFunction2R[Any](true)
39+
case object ShiftRightArithmetic extends BuildInFunction2R[Any](true)
40+
case object ShiftLeftLogical extends BuildInFunction2R[Any](true)
41+
case object BitwiseOr extends BuildInFunction2R[Any](true)
42+
case object BitwiseXor extends BuildInFunction2R[Any](true)
43+
case object BitwiseAnd extends BuildInFunction2R[Any](true)
44+
case object BitwiseNot extends BuildInFunction1R[Any](true)
45+
case object BitFieldInsert extends BuildInFunction4[Any, Any, Any, Any, Any](true)
46+
case object BitFieldSExtract extends BuildInFunction3[Any, Any, Any, Any](true)
47+
case object BitFieldUExtract extends BuildInFunction3[Any, Any, Any, Any](true)
48+
case object BitReverse extends BuildInFunction1R[Any](true)
49+
case object BitCount extends BuildInFunction1[Any, Any](true)
50+
51+
// Logical operations on booleans
52+
case object LogicalAny extends BuildInFunction1[Any, Bool](true)
53+
case object LogicalAll extends BuildInFunction1[Any, Bool](true)
54+
case object LogicalEqual extends BuildInFunction2R[Any](true)
55+
case object LogicalNotEqual extends BuildInFunction2R[Any](true)
56+
case object LogicalOr extends BuildInFunction2R[Any](true)
57+
case object LogicalAnd extends BuildInFunction2R[Any](true)
58+
case object LogicalNot extends BuildInFunction1R[Any](true)
59+
60+
// Floating-point checks
61+
case object IsNan extends BuildInFunction1[Any, Any](true)
62+
case object IsInf extends BuildInFunction1[Any, Any](true)
63+
case object IsFinite extends BuildInFunction1[Any, Any](true)
64+
case object IsNormal extends BuildInFunction1[Any, Any](true)
65+
case object SignBitSet extends BuildInFunction1[Any, Any](true)
66+
67+
// Comparisons
68+
case object Equal extends BuildInFunction2[Any, Any, Any](true)
69+
case object NotEqual extends BuildInFunction2[Any, Any, Any](true)
70+
case object LessThan extends BuildInFunction2[Any, Any, Any](true)
71+
case object GreaterThan extends BuildInFunction2[Any, Any, Any](true)
72+
case object LessThanEqual extends BuildInFunction2[Any, Any, Any](true)
73+
case object GreaterThanEqual extends BuildInFunction2[Any, Any, Any](true)
74+
75+
// Select
76+
case object Select extends BuildInFunction3[Any, Any, Any, Any](true)

0 commit comments

Comments
 (0)