diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c6c78d3..c47d94a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: pull_request: jobs: - format: + format_and_compile: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -19,4 +19,4 @@ jobs: with: jvm: graalvm-java21 apps: sbt - - run: sbt "formatCheckAll" \ No newline at end of file + - run: sbt "formatCheckAll; compile" diff --git a/.scalafmt.conf b/.scalafmt.conf index 99311d4f..482486d5 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -8,6 +8,7 @@ optIn.configStyleArguments = false rewrite.rules = [RedundantBraces, RedundantParens, SortModifiers, PreferCurlyFors, Imports] rewrite.sortModifiers.preset = styleGuide rewrite.trailingCommas.style = always +rewrite.scala3.convertToNewSyntax = true indent.defnSite = 2 newlines.inInterpolation = "avoid" diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/BlockBuilder.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/BlockBuilder.scala index 60d68892..26086ae9 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/BlockBuilder.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/BlockBuilder.scala @@ -11,10 +11,10 @@ import scala.quoted.Expr private[cyfra] object BlockBuilder: - def buildBlock(tree: E[_], providedExprIds: Set[Int] = Set.empty): List[E[_]] = - val allVisited = mutable.Map[Int, E[_]]() + def buildBlock(tree: E[?], providedExprIds: Set[Int] = Set.empty): List[E[?]] = + val allVisited = mutable.Map[Int, E[?]]() val inDegrees = mutable.Map[Int, Int]().withDefaultValue(0) - val q = mutable.Queue[E[_]]() + val q = mutable.Queue[E[?]]() q.enqueue(tree) allVisited(tree.treeid) = tree @@ -28,8 +28,8 @@ private[cyfra] object BlockBuilder: allVisited(childId) = child q.enqueue(child) - val l = mutable.ListBuffer[E[_]]() - val roots = mutable.Queue[E[_]]() + val l = mutable.ListBuffer[E[?]]() + val roots = mutable.Queue[E[?]]() allVisited.values.foreach: node => if inDegrees(node.treeid) == 0 then roots.enqueue(node) diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/Context.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/Context.scala index e5a647b2..a8fb18d2 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/Context.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/Context.scala @@ -18,7 +18,7 @@ private[cyfra] case class Context( voidFuncTypeRef: Int = -1, workerIndexRef: Int = -1, uniformVarRef: Int = -1, - constRefs: Map[(Tag[_], Any), Int] = Map(), + constRefs: Map[(Tag[?], Any), Int] = Map(), exprRefs: Map[Int, Int] = Map(), inBufferBlocks: List[ArrayBufferBlock] = List(), outBufferBlocks: List[ArrayBufferBlock] = List(), diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/Opcodes.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/Opcodes.scala index 0fa61949..38809183 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/Opcodes.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/Opcodes.scala @@ -18,7 +18,7 @@ private[cyfra] object Opcodes { def length = 1 - override def toString = s"Word(${bytes.mkString(", ")}${if (bytes.length == 4) s" [i = ${BigInt(bytes).toInt}])" else ""}" + override def toString = s"Word(${bytes.mkString(", ")}${if bytes.length == 4 then s" [i = ${BigInt(bytes).toInt}])" else ""}" } private[cyfra] case class WordVariable(name: String) extends Words { diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/SpirvTypes.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/SpirvTypes.scala index 76c527ab..122f6505 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/SpirvTypes.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/SpirvTypes.scala @@ -13,13 +13,13 @@ private[cyfra] object SpirvTypes: val UInt32Tag = summon[Tag[UInt32]] val Float32Tag = summon[Tag[Float32]] val GBooleanTag = summon[Tag[GBoolean]] - val Vec2TagWithoutArgs = summon[Tag[Vec2[_]]].tag.withoutArgs - val Vec3TagWithoutArgs = summon[Tag[Vec3[_]]].tag.withoutArgs - val Vec4TagWithoutArgs = summon[Tag[Vec4[_]]].tag.withoutArgs - val Vec2Tag = summon[Tag[Vec2[_]]] - val Vec3Tag = summon[Tag[Vec3[_]]] - val Vec4Tag = summon[Tag[Vec4[_]]] - val VecTag = summon[Tag[Vec[_]]] + val Vec2TagWithoutArgs = summon[Tag[Vec2[?]]].tag.withoutArgs + val Vec3TagWithoutArgs = summon[Tag[Vec3[?]]].tag.withoutArgs + val Vec4TagWithoutArgs = summon[Tag[Vec4[?]]].tag.withoutArgs + val Vec2Tag = summon[Tag[Vec2[?]]] + val Vec3Tag = summon[Tag[Vec3[?]]] + val Vec4Tag = summon[Tag[Vec4[?]]] + val VecTag = summon[Tag[Vec[?]]] val LInt32Tag = Int32Tag.tag val LUInt32Tag = UInt32Tag.tag @@ -37,7 +37,7 @@ private[cyfra] object SpirvTypes: type Vec3C[T <: Value] = Vec3[T] type Vec4C[T <: Value] = Vec4[T] - def scalarTypeDefInsn(tag: Tag[_], typeDefIndex: Int) = tag match { + def scalarTypeDefInsn(tag: Tag[?], typeDefIndex: Int) = tag match { case Int32Tag => Instruction(Op.OpTypeInt, List(ResultRef(typeDefIndex), IntWord(32), IntWord(1))) case UInt32Tag => Instruction(Op.OpTypeInt, List(ResultRef(typeDefIndex), IntWord(32), IntWord(0))) case Float32Tag => Instruction(Op.OpTypeFloat, List(ResultRef(typeDefIndex), IntWord(32))) @@ -57,9 +57,9 @@ private[cyfra] object SpirvTypes: case v if v <:< LVecTag => vecSize(v) * typeStride(v.typeArgs.head) - def typeStride(tag: Tag[_]): Int = typeStride(tag.tag) + def typeStride(tag: Tag[?]): Int = typeStride(tag.tag) - def toWord(tpe: Tag[_], value: Any): Words = tpe match { + def toWord(tpe: Tag[?], value: Any): Words = tpe match { case t if t == Int32Tag => IntWord(value.asInstanceOf[Int]) case t if t == UInt32Tag => @@ -73,7 +73,7 @@ private[cyfra] object SpirvTypes: Word(intToBytes(java.lang.Float.floatToIntBits(fl)).reverse.toArray) } - def defineScalarTypes(types: List[Tag[_]], context: Context): (List[Words], Context) = + def defineScalarTypes(types: List[Tag[?]], context: Context): (List[Words], Context) = val basicTypes = List(Int32Tag, Float32Tag, UInt32Tag, GBooleanTag) (basicTypes ::: types).distinct.foldLeft((List[Words](), context)) { case ((words, ctx), valType) => val typeDefIndex = ctx.nextResultId diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/DSLCompiler.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/DSLCompiler.scala index e48a6b2d..c0a5d315 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/DSLCompiler.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/DSLCompiler.scala @@ -26,31 +26,29 @@ import scala.util.Random private[cyfra] object DSLCompiler: // TODO: Not traverse same fn scopes for each fn call - private def getAllExprsFlattened(root: E[_], visitDetached: Boolean): List[E[_]] = + private def getAllExprsFlattened(root: E[?], visitDetached: Boolean): List[E[?]] = var blockI = 0 - val allScopesCache = mutable.Map[Int, List[E[_]]]() + val allScopesCache = mutable.Map[Int, List[E[?]]]() val visited = mutable.Set[Int]() @tailrec - def getAllScopesExprsAcc(toVisit: List[E[_]], acc: List[E[_]] = Nil): List[E[_]] = toVisit match + def getAllScopesExprsAcc(toVisit: List[E[?]], acc: List[E[?]] = Nil): List[E[?]] = toVisit match case Nil => acc case e :: tail if visited.contains(e.treeid) => getAllScopesExprsAcc(tail, acc) case e :: tail => - if (allScopesCache.contains(root.treeid)) - return allScopesCache(root.treeid) + if allScopesCache.contains(root.treeid) then return allScopesCache(root.treeid) val eScopes = e.introducedScopes val filteredScopes = if visitDetached then eScopes else eScopes.filterNot(_.isDetached) val newToVisit = toVisit ::: e.exprDependencies ::: filteredScopes.map(_.expr) val result = e.exprDependencies ::: filteredScopes.map(_.expr) ::: acc visited += e.treeid blockI += 1 - if (blockI % 100 == 0) - allScopesCache.update(e.treeid, result) + if blockI % 100 == 0 then allScopesCache.update(e.treeid, result) getAllScopesExprsAcc(newToVisit, result) val result = root :: getAllScopesExprsAcc(root :: Nil) allScopesCache(root.treeid) = result result - def compile(tree: Value, inTypes: List[Tag[_]], outTypes: List[Tag[_]], uniformSchema: GStructSchema[_]): ByteBuffer = + def compile(tree: Value, inTypes: List[Tag[?]], outTypes: List[Tag[?]], uniformSchema: GStructSchema[?]): ByteBuffer = val treeExpr = tree.tree val allExprs = getAllExprsFlattened(treeExpr, visitDetached = true) val typesInCode = allExprs.map(_.tag).distinct @@ -59,8 +57,8 @@ private[cyfra] object DSLCompiler: val (typeDefs, typedContext) = defineScalarTypes(scalarTypes, Context.initialContext) val structsInCode = (allExprs.collect { - case cs: ComposeStruct[_] => cs.resultSchema - case gf: GetField[_, _] => gf.resultSchema + case cs: ComposeStruct[?] => cs.resultSchema + case gf: GetField[?, ?] => gf.resultSchema } :+ uniformSchema).distinct val (structDefs, structCtx) = defineStructTypes(structsInCode, typedContext) val structNames = getStructNames(structsInCode, structCtx) diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/ExpressionCompiler.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/ExpressionCompiler.scala index 11a6ac3d..cf7bc758 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/ExpressionCompiler.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/ExpressionCompiler.scala @@ -25,22 +25,22 @@ private[cyfra] object ExpressionCompiler: val UniformStructRefTag = "uniform_struct" def UniformStructRef[G <: Value: Tag] = Dynamic(UniformStructRefTag) - private def binaryOpOpcode(expr: BinaryOpExpression[_]) = expr match - case _: Sum[_] => (Op.OpIAdd, Op.OpFAdd) - case _: Diff[_] => (Op.OpISub, Op.OpFSub) - case _: Mul[_] => (Op.OpIMul, Op.OpFMul) - case _: Div[_] => (Op.OpSDiv, Op.OpFDiv) - case _: Mod[_] => (Op.OpSMod, Op.OpFMod) - - private def compileBinaryOpExpression(bexpr: BinaryOpExpression[_], ctx: Context): (List[Instruction], Context) = + private def binaryOpOpcode(expr: BinaryOpExpression[?]) = expr match + case _: Sum[?] => (Op.OpIAdd, Op.OpFAdd) + case _: Diff[?] => (Op.OpISub, Op.OpFSub) + case _: Mul[?] => (Op.OpIMul, Op.OpFMul) + case _: Div[?] => (Op.OpSDiv, Op.OpFDiv) + case _: Mod[?] => (Op.OpSMod, Op.OpFMod) + + private def compileBinaryOpExpression(bexpr: BinaryOpExpression[?], ctx: Context): (List[Instruction], Context) = val tpe = bexpr.tag val typeRef = ctx.valueTypeMap(tpe.tag) val subOpcode = tpe match { case i if i.tag <:< summon[Tag[IntType]].tag || i.tag <:< summon[Tag[UIntType]].tag || - (i.tag <:< summon[Tag[Vec[_]]].tag && i.tag.typeArgs.head <:< summon[Tag[IntType]].tag) => + (i.tag <:< summon[Tag[Vec[?]]].tag && i.tag.typeArgs.head <:< summon[Tag[IntType]].tag) => binaryOpOpcode(bexpr)._1 - case f if f.tag <:< summon[Tag[FloatType]].tag || (f.tag <:< summon[Tag[Vec[_]]].tag && f.tag.typeArgs.head <:< summon[Tag[FloatType]].tag) => + case f if f.tag <:< summon[Tag[FloatType]].tag || (f.tag <:< summon[Tag[Vec[?]]].tag && f.tag.typeArgs.head <:< summon[Tag[FloatType]].tag) => binaryOpOpcode(bexpr)._2 } val instructions = List( @@ -52,39 +52,39 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (bexpr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - private def compileConvertExpression(cexpr: ConvertExpression[_, _], ctx: Context): (List[Instruction], Context) = + private def compileConvertExpression(cexpr: ConvertExpression[?, ?], ctx: Context): (List[Instruction], Context) = val tpe = cexpr.tag val typeRef = ctx.valueTypeMap(tpe.tag) val tfOpcode = (cexpr.fromTag, cexpr) match { - case (from, _: ToFloat32[_]) if from.tag =:= Int32Tag.tag => Op.OpConvertSToF - case (from, _: ToFloat32[_]) if from.tag =:= UInt32Tag.tag => Op.OpConvertUToF - case (from, _: ToInt32[_]) if from.tag =:= Float32Tag.tag => Op.OpConvertFToS - case (from, _: ToUInt32[_]) if from.tag =:= Float32Tag.tag => Op.OpConvertFToU - case (from, _: ToInt32[_]) if from.tag =:= UInt32Tag.tag => Op.OpBitcast - case (from, _: ToUInt32[_]) if from.tag =:= Int32Tag.tag => Op.OpBitcast + case (from, _: ToFloat32[?]) if from.tag =:= Int32Tag.tag => Op.OpConvertSToF + case (from, _: ToFloat32[?]) if from.tag =:= UInt32Tag.tag => Op.OpConvertUToF + case (from, _: ToInt32[?]) if from.tag =:= Float32Tag.tag => Op.OpConvertFToS + case (from, _: ToUInt32[?]) if from.tag =:= Float32Tag.tag => Op.OpConvertFToU + case (from, _: ToInt32[?]) if from.tag =:= UInt32Tag.tag => Op.OpBitcast + case (from, _: ToUInt32[?]) if from.tag =:= Int32Tag.tag => Op.OpBitcast } val instructions = List(Instruction(tfOpcode, List(ResultRef(typeRef), ResultRef(ctx.nextResultId), ResultRef(ctx.exprRefs(cexpr.a.treeid))))) val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (cexpr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - def comparisonOp(comparisonOpExpression: ComparisonOpExpression[_]) = + def comparisonOp(comparisonOpExpression: ComparisonOpExpression[?]) = comparisonOpExpression match - case _: GreaterThan[_] => (Op.OpSGreaterThan, Op.OpFOrdGreaterThan) - case _: LessThan[_] => (Op.OpSLessThan, Op.OpFOrdLessThan) - case _: GreaterThanEqual[_] => (Op.OpSGreaterThanEqual, Op.OpFOrdGreaterThanEqual) - case _: LessThanEqual[_] => (Op.OpSLessThanEqual, Op.OpFOrdLessThanEqual) - case _: Equal[_] => (Op.OpIEqual, Op.OpFOrdEqual) + case _: GreaterThan[?] => (Op.OpSGreaterThan, Op.OpFOrdGreaterThan) + case _: LessThan[?] => (Op.OpSLessThan, Op.OpFOrdLessThan) + case _: GreaterThanEqual[?] => (Op.OpSGreaterThanEqual, Op.OpFOrdGreaterThanEqual) + case _: LessThanEqual[?] => (Op.OpSLessThanEqual, Op.OpFOrdLessThanEqual) + case _: Equal[?] => (Op.OpIEqual, Op.OpFOrdEqual) - private def compileBitwiseExpression(bexpr: BitwiseOpExpression[_], ctx: Context): (List[Instruction], Context) = + private def compileBitwiseExpression(bexpr: BitwiseOpExpression[?], ctx: Context): (List[Instruction], Context) = val tpe = bexpr.tag val typeRef = ctx.valueTypeMap(tpe.tag) val subOpcode = bexpr match { - case _: BitwiseAnd[_] => Op.OpBitwiseAnd - case _: BitwiseOr[_] => Op.OpBitwiseOr - case _: BitwiseXor[_] => Op.OpBitwiseXor - case _: BitwiseNot[_] => Op.OpNot - case _: ShiftLeft[_] => Op.OpShiftLeftLogical - case _: ShiftRight[_] => Op.OpShiftRightLogical + case _: BitwiseAnd[?] => Op.OpBitwiseAnd + case _: BitwiseOr[?] => Op.OpBitwiseOr + case _: BitwiseXor[?] => Op.OpBitwiseXor + case _: BitwiseNot[?] => Op.OpNot + case _: ShiftLeft[?] => Op.OpShiftLeftLogical + case _: ShiftRight[?] => Op.OpShiftRightLogical } val instructions = List( Instruction(subOpcode, List(ResultRef(typeRef), ResultRef(ctx.nextResultId)) ::: bexpr.exprDependencies.map(d => ResultRef(ctx.exprRefs(d.treeid)))), @@ -92,15 +92,14 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (bexpr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - def compileBlock(tree: E[_], ctx: Context): (List[Words], Context) = { + def compileBlock(tree: E[?], ctx: Context): (List[Words], Context) = { @tailrec - def compileExpressions(exprs: List[E[_]], ctx: Context, acc: List[Words]): (List[Words], Context) = { - if (exprs.isEmpty) (acc, ctx) + def compileExpressions(exprs: List[E[?]], ctx: Context, acc: List[Words]): (List[Words], Context) = { + if exprs.isEmpty then (acc, ctx) else { val expr = exprs.head - if (ctx.exprRefs.contains(expr.treeid)) - compileExpressions(exprs.tail, ctx, acc) + if ctx.exprRefs.contains(expr.treeid) then compileExpressions(exprs.tail, ctx, acc) else { val name: Option[String] = expr.of match @@ -119,17 +118,16 @@ private[cyfra] object ExpressionCompiler: case d @ Dynamic(UniformStructRefTag) => (Nil, ctx.copy(exprRefs = ctx.exprRefs + (d.treeid -> ctx.uniformVarRef))) - case c: ConvertExpression[_, _] => + case c: ConvertExpression[?, ?] => compileConvertExpression(c, ctx) - case b: BinaryOpExpression[_] => + case b: BinaryOpExpression[?] => compileBinaryOpExpression(b, ctx) - case negate: Negate[_] => + case negate: Negate[?] => val op = - if (negate.tag.tag <:< summon[Tag[FloatType]].tag || - (negate.tag.tag <:< summon[Tag[Vec[_]]].tag && negate.tag.tag.typeArgs.head <:< summon[Tag[FloatType]].tag)) - Op.OpFNegate + if negate.tag.tag <:< summon[Tag[FloatType]].tag || + (negate.tag.tag <:< summon[Tag[Vec[?]]].tag && negate.tag.tag.typeArgs.head <:< summon[Tag[FloatType]].tag) then Op.OpFNegate else Op.OpSNegate val instructions = List( Instruction(op, List(ResultRef(ctx.valueTypeMap(negate.tag.tag)), ResultRef(ctx.nextResultId), ResultRef(ctx.exprRefs(negate.a.treeid)))), @@ -137,7 +135,7 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (negate.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - case bo: BitwiseOpExpression[_] => + case bo: BitwiseOpExpression[?] => compileBitwiseExpression(bo, ctx) case and: And => @@ -180,7 +178,7 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (expr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - case sp: ScalarProd[_, _] => + case sp: ScalarProd[?, ?] => val instructions = List( Instruction( Op.OpVectorTimesScalar, @@ -195,7 +193,7 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (expr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - case dp: DotProd[_, _] => + case dp: DotProd[?, ?] => val instructions = List( Instruction( Op.OpDot, @@ -210,9 +208,9 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (dp.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - case co: ComparisonOpExpression[_] => + case co: ComparisonOpExpression[?] => val (intOp, floatOp) = comparisonOp(co) - val op = if (co.operandTag.tag <:< summon[Tag[FloatType]].tag) floatOp else intOp + val op = if co.operandTag.tag <:< summon[Tag[FloatType]].tag then floatOp else intOp val instructions = List( Instruction( op, @@ -227,7 +225,7 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (expr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - case e: ExtractScalar[_, _] => + case e: ExtractScalar[?, ?] => val instructions = List( Instruction( Op.OpVectorExtractDynamic, @@ -243,7 +241,7 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (expr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - case composeVec2: ComposeVec2[_] => + case composeVec2: ComposeVec2[?] => val instructions = List( Instruction( Op.OpCompositeConstruct, @@ -258,7 +256,7 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (expr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - case composeVec3: ComposeVec3[_] => + case composeVec3: ComposeVec3[?] => val instructions = List( Instruction( Op.OpCompositeConstruct, @@ -274,7 +272,7 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (expr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - case composeVec4: ComposeVec4[_] => + case composeVec4: ComposeVec4[?] => val instructions = List( Instruction( Op.OpCompositeConstruct, @@ -291,10 +289,10 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (expr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (instructions, updatedContext) - case fc: ExtFunctionCall[_] => + case fc: ExtFunctionCall[?] => compileExtFunctionCall(fc, ctx) - case fc: FunctionCall[_] => + case fc: FunctionCall[?] => compileFunctionCall(fc, ctx) case ga @ GArrayElem(index, i) => @@ -314,14 +312,14 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (expr.treeid -> (ctx.nextResultId + 1)), nextResultId = ctx.nextResultId + 2) (instructions, updatedContext) - case when: WhenExpr[_] => + case when: WhenExpr[?] => compileWhen(when, ctx) - case fd: GSeq.FoldSeq[_, _] => + case fd: GSeq.FoldSeq[?, ?] => GSeqCompiler.compileFold(fd, ctx) - case cs: ComposeStruct[_] => - val schema = cs.resultSchema.asInstanceOf[GStructSchema[_]] + case cs: ComposeStruct[?] => + val schema = cs.resultSchema.asInstanceOf[GStructSchema[?]] val fields = cs.fields val insns: List[Instruction] = List( Instruction( @@ -348,7 +346,7 @@ private[cyfra] object ExpressionCompiler: ) val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (expr.treeid -> (ctx.nextResultId + 1)), nextResultId = ctx.nextResultId + 2) (insns, updatedContext) - case gf: GetField[_, _] => + case gf: GetField[?, ?] => val insns: List[Instruction] = List( Instruction( Op.OpCompositeExtract, @@ -363,7 +361,7 @@ private[cyfra] object ExpressionCompiler: val updatedContext = ctx.copy(exprRefs = ctx.exprRefs + (expr.treeid -> ctx.nextResultId), nextResultId = ctx.nextResultId + 1) (insns, updatedContext) - case ph: PhantomExpression[_] => (List(), ctx) + case ph: PhantomExpression[?] => (List(), ctx) } val ctxWithName = updatedCtx.copy(exprNames = updatedCtx.exprNames ++ name.map(n => (updatedCtx.nextResultId - 1, n)).toMap) compileExpressions(exprs.tail, ctxWithName, acc ::: instructions) diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/ExtFunctionCompiler.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/ExtFunctionCompiler.scala index 50c4f047..e5fbc7b1 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/ExtFunctionCompiler.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/ExtFunctionCompiler.scala @@ -35,7 +35,7 @@ private[cyfra] object ExtFunctionCompiler: Functions.Log -> GlslOp.Log, ) - def compileExtFunctionCall(call: Expression.ExtFunctionCall[_], ctx: Context): (List[Instruction], Context) = + def compileExtFunctionCall(call: Expression.ExtFunctionCall[?], ctx: Context): (List[Instruction], Context) = val fnOp = fnOpMap(call.fn) val tp = call.tag val typeRef = ctx.valueTypeMap(tp.tag) diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/FunctionCompiler.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/FunctionCompiler.scala index e3714465..83e9cd6b 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/FunctionCompiler.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/FunctionCompiler.scala @@ -17,10 +17,10 @@ import izumi.reflect.macrortti.LightTypeTag private[cyfra] object FunctionCompiler: - case class SprivFunction(sourceFn: FnIdentifier, functionId: Int, body: Expression[_], inputArgs: List[Expression[_]]): + case class SprivFunction(sourceFn: FnIdentifier, functionId: Int, body: Expression[?], inputArgs: List[Expression[?]]): def returnType: LightTypeTag = body.tag.tag - def compileFunctionCall(call: Expression.FunctionCall[_], ctx: Context): (List[Instruction], Context) = + def compileFunctionCall(call: Expression.FunctionCall[?], ctx: Context): (List[Instruction], Context) = val (ctxWithFn, fn) = if ctx.functions.contains(call.fn) then val fn = ctx.functions(call.fn) (ctx, fn) diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/GSeqCompiler.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/GSeqCompiler.scala index 0819a631..769893f2 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/GSeqCompiler.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/GSeqCompiler.scala @@ -10,7 +10,7 @@ import io.computenode.cyfra.spirv.SpirvTypes.* private[cyfra] object GSeqCompiler: - def compileFold(fold: FoldSeq[_, _], ctx: Context): (List[Words], Context) = + def compileFold(fold: FoldSeq[?, ?], ctx: Context): (List[Words], Context) = val loopBack = ctx.nextResultId val mergeBlock = ctx.nextResultId + 1 val continueTarget = ctx.nextResultId + 2 @@ -46,7 +46,7 @@ private[cyfra] object GSeqCompiler: val foldZeroPointerType = ctx.funPointerTypeMap(foldZeroType) val foldFnExpr = fold.fnExpr - def generateSeqOps(seqExprs: List[(ElemOp[_], E[_])], context: Context, elemRef: Int): (List[Words], Context) = + def generateSeqOps(seqExprs: List[(ElemOp[?], E[?])], context: Context, elemRef: Int): (List[Words], Context) = val withElemRefCtx = context.copy(exprRefs = context.exprRefs + (fold.seq.currentElemExprTreeId -> elemRef)) seqExprs match { case Nil => // No more transformations, so reduce ops now diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/GStructCompiler.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/GStructCompiler.scala index 693fa04a..8275708c 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/GStructCompiler.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/GStructCompiler.scala @@ -10,7 +10,7 @@ import scala.collection.mutable private[cyfra] object GStructCompiler: - def defineStructTypes(schemas: List[GStructSchema[_]], context: Context): (List[Words], Context) = + def defineStructTypes(schemas: List[GStructSchema[?]], context: Context): (List[Words], Context) = val sortedSchemas = sortSchemasDag(schemas.distinctBy(_.structTag)) sortedSchemas.foldLeft((List[Words](), context)) { case ((words, ctx), schema) => ( @@ -29,7 +29,7 @@ private[cyfra] object GStructCompiler: ) } - def getStructNames(schemas: List[GStructSchema[_]], context: Context): List[Words] = + def getStructNames(schemas: List[GStructSchema[?]], context: Context): List[Words] = schemas.flatMap { schema => val structName = schema.structTag.tag.shortName val structType = context.valueTypeMap(schema.structTag.tag) @@ -38,14 +38,14 @@ private[cyfra] object GStructCompiler: } } - private def sortSchemasDag(schemas: List[GStructSchema[_]]): List[GStructSchema[_]] = + private def sortSchemasDag(schemas: List[GStructSchema[?]]): List[GStructSchema[?]] = val schemaMap = schemas.map(s => s.structTag.tag -> s).toMap val visited = mutable.Set[LightTypeTag]() val stack = mutable.Stack[LightTypeTag]() - val sorted = mutable.ListBuffer[GStructSchema[_]]() + val sorted = mutable.ListBuffer[GStructSchema[?]]() def visit(tag: LightTypeTag): Unit = - if !visited.contains(tag) && tag <:< summon[Tag[GStruct[_]]].tag then + if !visited.contains(tag) && tag <:< summon[Tag[GStruct[?]]].tag then visited += tag stack.push(tag) schemaMap(tag).fields.map(_._3.tag).foreach(visit) diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/SpirvProgramCompiler.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/SpirvProgramCompiler.scala index 4fb533c3..a5798505 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/SpirvProgramCompiler.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/SpirvProgramCompiler.scala @@ -18,7 +18,7 @@ private[cyfra] object SpirvProgramCompiler: case _ => false } - def compileMain(tree: Value, resultType: Tag[_], ctx: Context): (List[Words], Context) = { + def compileMain(tree: Value, resultType: Tag[?], ctx: Context): (List[Words], Context) = { val init = List( Instruction(Op.OpFunction, List(ResultRef(ctx.voidTypeRef), ResultRef(MAIN_FUNC_REF), SamplerAddressingMode.None, ResultRef(VOID_FUNC_TYPE_REF))), @@ -104,7 +104,7 @@ private[cyfra] object SpirvProgramCompiler: (voidDef, ctxWithVoid) } - def initAndDecorateUniforms(ins: List[Tag[_]], outs: List[Tag[_]], context: Context): (List[Words], List[Words], Context) = { + def initAndDecorateUniforms(ins: List[Tag[?]], outs: List[Tag[?]], context: Context): (List[Words], List[Words], Context) = { val (inDecor, inDef, inCtx) = createAndInitBlocks(ins, in = true, context) val (outDecor, outDef, outCtx) = createAndInitBlocks(outs, in = false, inCtx) val (voidsDef, voidCtx) = defineVoids(outCtx) @@ -130,7 +130,7 @@ private[cyfra] object SpirvProgramCompiler: (definitionInstructions, context.copy(nextResultId = context.nextResultId + 3)) } - def createAndInitBlocks(blocks: List[Tag[_]], in: Boolean, context: Context): (List[Words], List[Words], Context) = { + def createAndInitBlocks(blocks: List[Tag[?]], in: Boolean, context: Context): (List[Words], List[Words], Context) = { val (decoration, definition, newContext) = blocks.foldLeft((List[Words](), List[Words](), context)) { case ((decAcc, insnAcc, ctx), tpe) => val block = ArrayBufferBlock(ctx.nextResultId, ctx.nextResultId + 1, ctx.nextResultId + 2, ctx.nextResultId + 3, ctx.nextBinding) @@ -150,7 +150,7 @@ private[cyfra] object SpirvProgramCompiler: ) val contextWithBlock = - if (in) ctx.copy(inBufferBlocks = block :: ctx.inBufferBlocks) else ctx.copy(outBufferBlocks = block :: ctx.outBufferBlocks) + if in then ctx.copy(inBufferBlocks = block :: ctx.inBufferBlocks) else ctx.copy(outBufferBlocks = block :: ctx.outBufferBlocks) ( decAcc ::: decorationInstructions, insnAcc ::: definitionInstructions, @@ -160,18 +160,18 @@ private[cyfra] object SpirvProgramCompiler: (decoration, definition, newContext) } - def getBlockNames(context: Context, uniformSchema: GStructSchema[_]): List[Words] = + def getBlockNames(context: Context, uniformSchema: GStructSchema[?]): List[Words] = def namesForBlock(block: ArrayBufferBlock, tpe: String): List[Words] = Instruction(Op.OpName, List(ResultRef(block.structTypeRef), Text(s"Buffer$tpe"))) :: Instruction(Op.OpName, List(ResultRef(block.blockVarRef), Text(s"data$tpe"))) :: Nil // todo name uniform context.inBufferBlocks.flatMap(namesForBlock(_, "In")) ::: context.outBufferBlocks.flatMap(namesForBlock(_, "Out")) - def createAndInitUniformBlock(schema: GStructSchema[_], ctx: Context): (List[Words], List[Words], Context) = - def totalStride(gs: GStructSchema[_]): Int = gs.fields + def createAndInitUniformBlock(schema: GStructSchema[?], ctx: Context): (List[Words], List[Words], Context) = + def totalStride(gs: GStructSchema[?]): Int = gs.fields .map: case (_, fromExpr, t) if t <:< gs.gStructTag => - val constructor = fromExpr.asInstanceOf[GStructConstructor[_]] + val constructor = fromExpr.asInstanceOf[GStructConstructor[?]] totalStride(constructor.schema) case (_, _, t) => typeStride(t) @@ -182,7 +182,7 @@ private[cyfra] object SpirvProgramCompiler: case ((acc, offset), ((name, fromExpr, tag), idx)) => val stride = if tag <:< schema.gStructTag then - val constructor = fromExpr.asInstanceOf[GStructConstructor[_]] + val constructor = fromExpr.asInstanceOf[GStructConstructor[?]] totalStride(constructor.schema) else typeStride(tag) val offsetDecoration = Instruction(Op.OpMemberDecorate, List(ResultRef(uniformStructTypeRef), IntWord(idx), Decoration.Offset, IntWord(offset))) @@ -214,7 +214,7 @@ private[cyfra] object SpirvProgramCompiler: ) val predefinedConsts = List((Int32Tag, 0), (UInt32Tag, 0), (Int32Tag, 1)) - def defineConstants(exprs: List[E[_]], ctx: Context): (List[Words], Context) = { + def defineConstants(exprs: List[E[?]], ctx: Context): (List[Words], Context) = { val consts = (exprs.collect { case c @ Const(x) => (c.tag, x) diff --git a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/WhenCompiler.scala b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/WhenCompiler.scala index 8fe7eda7..1976788b 100644 --- a/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/WhenCompiler.scala +++ b/cyfra-compiler/src/main/scala/io/computenode/cyfra/spirv/compilers/WhenCompiler.scala @@ -11,8 +11,8 @@ import io.computenode.cyfra.spirv.SpirvTypes.* private[cyfra] object WhenCompiler: - def compileWhen(when: WhenExpr[_], ctx: Context): (List[Words], Context) = { - def compileCases(ctx: Context, resultVar: Int, conditions: List[E[_]], thenCodes: List[E[_]], elseCode: E[_]): (List[Words], Context) = + def compileWhen(when: WhenExpr[?], ctx: Context): (List[Words], Context) = { + def compileCases(ctx: Context, resultVar: Int, conditions: List[E[?]], thenCodes: List[E[?]], elseCode: E[?]): (List[Words], Context) = (conditions, thenCodes) match { case (Nil, Nil) => val (elseInstructions, elseCtx) = compileBlock(elseCode, ctx) diff --git a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Algebra.scala b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Algebra.scala index 03be9714..ff863778 100644 --- a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Algebra.scala +++ b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Algebra.scala @@ -49,7 +49,7 @@ object Algebra: trait ScalarModable[T <: Scalar: FromExpr: Tag]: def mod(a: T, b: T)(using Source): T = summon[FromExpr[T]].fromExpr(Mod(a, b)) - extension [T <: Scalar: ScalarModable: Tag](a: T) inline def mod(b: T)(using Source): T = summon[ScalarModable[T]].mod(a, b) + extension [T <: Scalar: ScalarModable: Tag](a: T) inline infix def mod(b: T)(using Source): T = summon[ScalarModable[T]].mod(a, b) trait Comparable[T <: Scalar: FromExpr: Tag]: def greaterThan(a: T, b: T)(using Source): GBoolean = GBoolean(GreaterThan(a, b)) @@ -80,26 +80,26 @@ object Algebra: inline def asFloat(using Source): Float32 = Float32(ToFloat32(u32)) inline def signed(using Source): Int32 = Int32(ToInt32(u32)) - trait VectorSummable[V <: Vec[_]: FromExpr: Tag]: + trait VectorSummable[V <: Vec[?]: FromExpr: Tag]: def sum(a: V, b: V)(using Source): V = summon[FromExpr[V]].fromExpr(Sum(a, b)) - extension [V <: Vec[_]: VectorSummable: Tag](a: V) + extension [V <: Vec[?]: VectorSummable: Tag](a: V) @targetName("addVector") inline def +(b: V)(using Source): V = summon[VectorSummable[V]].sum(a, b) - trait VectorDiffable[V <: Vec[_]: FromExpr: Tag]: + trait VectorDiffable[V <: Vec[?]: FromExpr: Tag]: def diff(a: V, b: V)(using Source): V = summon[FromExpr[V]].fromExpr(Diff(a, b)) - extension [V <: Vec[_]: VectorDiffable: Tag](a: V) + extension [V <: Vec[?]: VectorDiffable: Tag](a: V) @targetName("subVector") inline def -(b: V)(using Source): V = summon[VectorDiffable[V]].diff(a, b) trait VectorDotable[S <: Scalar: FromExpr: Tag, V <: Vec[S]: Tag]: def dot(a: V, b: V)(using Source): S = summon[FromExpr[S]].fromExpr(DotProd[S, V](a, b)) extension [S <: Scalar: Tag, V <: Vec[S]: Tag](a: V)(using VectorDotable[S, V]) - def dot(b: V)(using Source): S = summon[VectorDotable[S, V]].dot(a, b) + infix def dot(b: V)(using Source): S = summon[VectorDotable[S, V]].dot(a, b) - trait VectorCrossable[V <: Vec[_]: FromExpr: Tag]: + trait VectorCrossable[V <: Vec[?]: FromExpr: Tag]: def cross(a: V, b: V)(using Source): V = summon[FromExpr[V]].fromExpr(ExtFunctionCall(Cross, List(a, b))) - extension [V <: Vec[_]: VectorCrossable: Tag](a: V) def cross(b: V)(using Source): V = summon[VectorCrossable[V]].cross(a, b) + extension [V <: Vec[?]: VectorCrossable: Tag](a: V) infix def cross(b: V)(using Source): V = summon[VectorCrossable[V]].cross(a, b) trait VectorScalarMulable[S <: Scalar: Tag, V <: Vec[S]: FromExpr: Tag]: def mul(a: V, b: S)(using Source): V = summon[FromExpr[V]].fromExpr(ScalarProd[S, V](a, b)) @@ -108,9 +108,9 @@ object Algebra: extension [S <: Scalar: Tag, V <: Vec[S]: Tag](s: S)(using VectorScalarMulable[S, V]) def *(v: V)(using Source): V = summon[VectorScalarMulable[S, V]].mul(v, s) - trait VectorNegatable[V <: Vec[_]: FromExpr: Tag]: + trait VectorNegatable[V <: Vec[?]: FromExpr: Tag]: def negate(a: V)(using Source): V = summon[FromExpr[V]].fromExpr(Negate(a)) - extension [V <: Vec[_]: VectorNegatable: Tag](a: V) + extension [V <: Vec[?]: VectorNegatable: Tag](a: V) @targetName("negateVector") def unary_-(using Source): V = summon[VectorNegatable[V]].negate(a) diff --git a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Control.scala b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Control.scala index 4ef7c37c..68a5c1b4 100644 --- a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Control.scala +++ b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Control.scala @@ -22,7 +22,7 @@ object Control: ): def elseWhen(cond: GBoolean)(t: T): When[T] = When(when, thenCode, otherConds :+ Scope(cond.tree), otherCases :+ Scope(t.tree.asInstanceOf[E[T]]), name) - def otherwise(t: T): T = + infix def otherwise(t: T): T = summon[FromExpr[T]] .fromExpr(WhenExpr(when, Scope(thenCode.tree.asInstanceOf[E[T]]), otherConds, otherCases, Scope(t.tree.asInstanceOf[E[T]])))(using name) diff --git a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Expression.scala b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Expression.scala index 5355a10f..4866d7c8 100644 --- a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Expression.scala +++ b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Expression.scala @@ -18,25 +18,25 @@ trait Expression[T <: Value: Tag] extends Product: .map(e => s"#${e.treeid}") .mkString("[", ", ", "]") override def toString: String = s"${this.productPrefix}(${of.fold("")(v => s"name = ${v.source}, ")}children=$childrenStrings, id=$treeid)" - private def exploreDeps(children: List[Any]): (List[Expression[_]], List[Scope[_]]) = (for (elem <- children) yield elem match { - case b: Scope[_] => + private def exploreDeps(children: List[Any]): (List[Expression[?]], List[Scope[?]]) = (for (elem <- children) yield elem match { + case b: Scope[?] => (None, Some(b)) - case x: Expression[_] => + case x: Expression[?] => (Some(x), None) case x: Value => (Some(x.tree), None) case list: List[Any] => - (exploreDeps(list.collect { case v: Value => v })._1, exploreDeps(list.collect { case s: Scope[_] => s })._2) + (exploreDeps(list.collect { case v: Value => v })._1, exploreDeps(list.collect { case s: Scope[?] => s })._2) case _ => (None, None) - }).foldLeft((List.empty[Expression[_]], List.empty[Scope[_]])) { case ((acc, blockAcc), (newExprs, newBlocks)) => + }).foldLeft((List.empty[Expression[?]], List.empty[Scope[?]])) { case ((acc, blockAcc), (newExprs, newBlocks)) => (acc ::: newExprs.iterator.toList, blockAcc ::: newBlocks.iterator.toList) } - def exprDependencies: List[Expression[_]] = exploreDeps(this.productIterator.toList)._1 - def introducedScopes: List[Scope[_]] = exploreDeps(this.productIterator.toList)._2 + def exprDependencies: List[Expression[?]] = exploreDeps(this.productIterator.toList)._1 + def introducedScopes: List[Scope[?]] = exploreDeps(this.productIterator.toList)._2 object Expression: trait CustomTreeId: - self: Expression[_] => + self: Expression[?] => override val treeid: Int trait PhantomExpression[T <: Value: Tag] extends Expression[T] @@ -85,7 +85,7 @@ object Expression: case class Or(a: GBoolean, b: GBoolean) extends Expression[GBoolean] case class Not(a: GBoolean) extends Expression[GBoolean] - case class ExtractScalar[V <: Vec[_]: Tag, S <: Scalar: Tag](a: V, i: Int32) extends Expression[S] + case class ExtractScalar[V <: Vec[?]: Tag, S <: Scalar: Tag](a: V, i: Int32) extends Expression[S] sealed trait ConvertExpression[F <: Scalar: Tag, T <: Scalar: Tag] extends Expression[T] { def fromTag: Tag[F] = summon[Tag[F]] diff --git a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Functions.scala b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Functions.scala index 8a5be4df..3d58bfd5 100644 --- a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Functions.scala +++ b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Functions.scala @@ -44,7 +44,7 @@ object Functions: case object Pow extends FunctionName def pow(v: Float32, p: Float32)(using Source): Float32 = Float32(ExtFunctionCall(Pow, List(v, p))) - def pow[V <: Vec[_]: Tag: FromExpr](v: V, p: V)(using Source): V = + def pow[V <: Vec[?]: Tag: FromExpr](v: V, p: V)(using Source): V = summon[FromExpr[V]].fromExpr(ExtFunctionCall(Pow, List(v, p))) case object Smoothstep extends FunctionName diff --git a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/GSeq.scala b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/GSeq.scala index 1cdc0a7a..20987310 100644 --- a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/GSeq.scala +++ b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/GSeq.scala @@ -13,8 +13,8 @@ import java.util.Base64 import scala.util.Random class GSeq[T <: Value: Tag: FromExpr]( - val uninitSource: Expression[_] => GSeqStream[_], - val elemOps: List[GSeq.ElemOp[_]], + val uninitSource: Expression[?] => GSeqStream[?], + val elemOps: List[GSeq.ElemOp[?]], val limit: Option[Int], val name: Source, val currentElemExprTreeId: Int = treeidState.getAndIncrement(), @@ -22,7 +22,7 @@ class GSeq[T <: Value: Tag: FromExpr]( ): def copyWithDynamicTrees[R <: Value: Tag: FromExpr]( - elemOps: List[GSeq.ElemOp[_]] = elemOps, + elemOps: List[GSeq.ElemOp[?]] = elemOps, limit: Option[Int] = limit, currentElemExprTreeId: Int = currentElemExprTreeId, aggregateElemExprTreeId: Int = aggregateElemExprTreeId, @@ -67,14 +67,14 @@ object GSeq: val first = when(i === 0) { xs(0) } - (if (xs.length == 1) - first + (if xs.length == 1 then first else xs.init.zipWithIndex.tail.foldLeft(first) { case (acc, (x, j)) => acc.elseWhen(i === j) { x } - }).otherwise(xs.last) + } + ).otherwise(xs.last) } .limit(xs.length) @@ -86,16 +86,16 @@ object GSeq: sealed trait ElemOp[T <: Value: Tag]: def tag: Tag[T] = summon[Tag[T]] - def fn: Expression[_] + def fn: Expression[?] - case class MapOp[T <: Value: Tag, R <: Value: Tag](fn: Expression[_]) extends ElemOp[R] + case class MapOp[T <: Value: Tag, R <: Value: Tag](fn: Expression[?]) extends ElemOp[R] case class FilterOp[T <: Value: Tag](fn: Expression[GBoolean]) extends ElemOp[T] case class TakeUntilOp[T <: Value: Tag](fn: Expression[GBoolean]) extends ElemOp[T] sealed trait GSeqSource[T <: Value: Tag] - case class GSeqStream[T <: Value: Tag](init: T, next: Expression[_]) extends GSeqSource[T] + case class GSeqStream[T <: Value: Tag](init: T, next: Expression[?]) extends GSeqSource[T] - case class FoldSeq[R <: Value: Tag, T <: Value: Tag](zero: R, fn: Expression[_], seq: GSeq[T]) extends Expression[R]: + case class FoldSeq[R <: Value: Tag, T <: Value: Tag](zero: R, fn: Expression[?], seq: GSeq[T]) extends Expression[R]: val zeroExpr = zero.tree val fnExpr = fn val streamInitExpr = seq.source.init.tree @@ -104,6 +104,6 @@ object GSeq: val limitExpr = ConstInt32(seq.limit.getOrElse(throw new IllegalArgumentException("Reduce on infinite stream is not supported"))) - override val exprDependencies: List[E[_]] = List(zeroExpr, streamInitExpr, limitExpr) - override val introducedScopes: List[Scope[_]] = Scope(fnExpr)(using fnExpr.tag) :: Scope(streamNextExpr)(using streamNextExpr.tag) :: + override val exprDependencies: List[E[?]] = List(zeroExpr, streamInitExpr, limitExpr) + override val introducedScopes: List[Scope[?]] = Scope(fnExpr)(using fnExpr.tag) :: Scope(streamNextExpr)(using streamNextExpr.tag) :: seqExprs.map(e => Scope(e)(using e.tag)) diff --git a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/GStruct.scala b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/GStruct.scala index 9cd48151..101c5582 100644 --- a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/GStruct.scala +++ b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/GStruct.scala @@ -21,7 +21,7 @@ abstract class GStruct[T <: GStruct[T]: Tag: GStructSchema] extends Value with P private[dsl] var _name = Source("Unknown") override def source: Source = _name -case class GStructSchema[T <: GStruct[T]: Tag](fields: List[(String, FromExpr[_], Tag[_])], dependsOn: Option[E[T]], fromTuple: (Tuple, Source) => T): +case class GStructSchema[T <: GStruct[T]: Tag](fields: List[(String, FromExpr[?], Tag[?])], dependsOn: Option[E[T]], fromTuple: (Tuple, Source) => T): given GStructSchema[T] = this val structTag = summon[Tag[T]] @@ -48,7 +48,7 @@ case class GStructSchema[T <: GStruct[T]: Tag](fields: List[(String, FromExpr[_] this.copy(dependsOn = Some(e)), ) - val gStructTag = summon[Tag[GStruct[_]]] + val gStructTag = summon[Tag[GStruct[?]]] trait GStructConstructor[T <: GStruct[T]] extends FromExpr[T]: def schema: GStructSchema[T] @@ -81,8 +81,8 @@ object GStructSchema: // quick prove that all fields <:< value summonAll[Tuple.Map[m.MirroredElemTypes, [f] =>> f <:< Value]] // get (name, tag) pairs for all fields - val elemTags: List[Tag[_]] = summonAll[Tuple.Map[m.MirroredElemTypes, TagOf]].toList.asInstanceOf[List[Tag[_]]] - val elemFromExpr: List[FromExpr[_]] = summonAll[Tuple.Map[m.MirroredElemTypes, [f] =>> FromExprOf[f]]].toList.asInstanceOf[List[FromExpr[_]]] + val elemTags: List[Tag[?]] = summonAll[Tuple.Map[m.MirroredElemTypes, TagOf]].toList.asInstanceOf[List[Tag[?]]] + val elemFromExpr: List[FromExpr[?]] = summonAll[Tuple.Map[m.MirroredElemTypes, [f] =>> FromExprOf[f]]].toList.asInstanceOf[List[FromExpr[?]]] val elemNames: List[String] = constValueTuple[m.MirroredElemLabels].toList.asInstanceOf[List[String]] val elements = elemNames.lazyZip(elemFromExpr).lazyZip(elemTags).toList GStructSchema[T]( diff --git a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Value.scala b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Value.scala index 8357f6ab..91b3a9f4 100644 --- a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Value.scala +++ b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/Value.scala @@ -7,7 +7,7 @@ import io.computenode.cyfra.dsl.macros.Source import izumi.reflect.Tag trait Value: - def tree: E[_] + def tree: E[?] def source: Source private[cyfra] def treeid: Int = tree.treeid protected def init() = diff --git a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/FnCall.scala b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/FnCall.scala index b6af5e2c..f5ad184c 100644 --- a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/FnCall.scala +++ b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/FnCall.scala @@ -45,7 +45,7 @@ object FnCall: case None => quotes.reflect.report.errorAndAbort(s"Expected pure function") def isPure(using Quotes)(defdef: quotes.reflect.DefDef): Boolean = - import quotes.reflect._ + import quotes.reflect.* val returnType = defdef.returnTpt.tpe val paramSets = defdef.termParamss if paramSets.length > 1 then return false diff --git a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/Source.scala b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/Source.scala index 0ab74246..e6212397 100644 --- a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/Source.scala +++ b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/Source.scala @@ -20,7 +20,7 @@ object Source: } def valueName(using Quotes): Expr[String] = - import quotes.reflect._ + import quotes.reflect.* val ownerOpt = actualOwner(Symbol.spliceOwner) ownerOpt match case Some(owner) => @@ -32,7 +32,7 @@ object Source: def findOwner(using Quotes)(owner: quotes.reflect.Symbol, skipIf: quotes.reflect.Symbol => Boolean): Option[quotes.reflect.Symbol] = { import quotes.reflect.* var owner0 = owner - while (skipIf(owner0)) + while skipIf(owner0) do if owner0 == Symbol.noSymbol then return None owner0 = owner0.owner Some(owner0) @@ -46,10 +46,8 @@ object Source: private def adjustName(s: String): String = // Required to get the same name from dotty - if (s.startsWith("")) - s.stripSuffix("$>") + ">" - else - s + if s.startsWith("") then s.stripSuffix("$>") + ">" + else s sealed trait Chunk object Chunk: diff --git a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/Util.scala b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/Util.scala index b3aba9d2..c06c2198 100644 --- a/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/Util.scala +++ b/cyfra-dsl/src/main/scala/io/computenode/cyfra/dsl/macros/Util.scala @@ -7,11 +7,11 @@ object Util: isSyntheticAlt(s) def isSyntheticAlt(using Quotes)(s: quotes.reflect.Symbol) = { - import quotes.reflect._ + import quotes.reflect.* s.flags.is(Flags.Synthetic) || s.isClassConstructor || s.isLocalDummy || isScala2Macro(s) || s.name.startsWith("x$proxy") } def isScala2Macro(using Quotes)(s: quotes.reflect.Symbol) = { - import quotes.reflect._ + import quotes.reflect.* (s.flags.is(Flags.Macro) && s.owner.flags.is(Flags.Scala2x)) || (s.flags.is(Flags.Macro) && !s.flags.is(Flags.Inline)) } def isSyntheticName(name: String) = diff --git a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/ArithmeticTests.scala b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/ArithmeticTests.scala similarity index 100% rename from cyfra-e2e-test/src/test/scala/io/computenode/cyfra/ArithmeticTests.scala rename to cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/ArithmeticTests.scala diff --git a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/FunctionsTests.scala b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/FunctionsTests.scala similarity index 100% rename from cyfra-e2e-test/src/test/scala/io/computenode/cyfra/FunctionsTests.scala rename to cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/FunctionsTests.scala diff --git a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/GSeqTests.scala b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/GSeqTests.scala similarity index 100% rename from cyfra-e2e-test/src/test/scala/io/computenode/cyfra/GSeqTests.scala rename to cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/GSeqTests.scala diff --git a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/GStructTests.scala b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/GStructTests.scala similarity index 100% rename from cyfra-e2e-test/src/test/scala/io/computenode/cyfra/GStructTests.scala rename to cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/GStructTests.scala diff --git a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/ImageTests.scala b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/ImageTests.scala similarity index 98% rename from cyfra-e2e-test/src/test/scala/io/computenode/cyfra/ImageTests.scala rename to cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/ImageTests.scala index 7e1fc6e8..20aea0e4 100644 --- a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/ImageTests.scala +++ b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/ImageTests.scala @@ -1,4 +1,4 @@ -package io.computenode.cyfra +package io.computenode.cyfra.e2e import com.diogonunes.jcolor.Ansi.colorize import com.diogonunes.jcolor.Attribute diff --git a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/WhenTests.scala b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/WhenTests.scala similarity index 100% rename from cyfra-e2e-test/src/test/scala/io/computenode/cyfra/WhenTests.scala rename to cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/WhenTests.scala diff --git a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/juliaset/JuliaSet.scala b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/juliaset/JuliaSet.scala similarity index 96% rename from cyfra-e2e-test/src/test/scala/io/computenode/cyfra/juliaset/JuliaSet.scala rename to cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/juliaset/JuliaSet.scala index e049b165..30556b58 100644 --- a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/juliaset/JuliaSet.scala +++ b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/juliaset/JuliaSet.scala @@ -1,4 +1,4 @@ -package io.computenode.cyfra.juliaset +package io.computenode.cyfra.e2e.juliaset import io.computenode.cyfra.dsl.{*, given} import io.computenode.cyfra.* @@ -16,6 +16,7 @@ import java.nio.file.Files import scala.concurrent.ExecutionContext.Implicits import scala.concurrent.duration.DurationInt import scala.concurrent.{Await, ExecutionContext} +import io.computenode.cyfra.e2e.ImageTests class JuliaSet extends FunSuite: given GContext = new GContext() diff --git a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/vulkan/SequenceExecutorTest.scala b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/vulkan/SequenceExecutorTest.scala similarity index 94% rename from cyfra-e2e-test/src/test/scala/io/computenode/cyfra/vulkan/SequenceExecutorTest.scala rename to cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/vulkan/SequenceExecutorTest.scala index 0762413c..87fa10cb 100644 --- a/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/vulkan/SequenceExecutorTest.scala +++ b/cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/vulkan/SequenceExecutorTest.scala @@ -1,9 +1,10 @@ -package io.computenode.cyfra.vulkan +package io.computenode.cyfra.e2e.vulkan import io.computenode.cyfra.vulkan.compute.{Binding, ComputePipeline, InputBufferSize, LayoutInfo, LayoutSet, Shader} import io.computenode.cyfra.vulkan.executor.BufferAction.{LoadFrom, LoadTo} import io.computenode.cyfra.vulkan.executor.SequenceExecutor import io.computenode.cyfra.vulkan.executor.SequenceExecutor.{ComputationSequence, Compute, Dependency, LayoutLocation} +import io.computenode.cyfra.vulkan.VulkanContext import munit.FunSuite import org.lwjgl.BufferUtils diff --git a/cyfra-examples/src/main/scala/io/computenode/samples/cyfra/oldsamples/Raytracing.scala b/cyfra-examples/src/main/scala/io/computenode/samples/cyfra/oldsamples/Raytracing.scala index 89b3d2d5..ff60b4b2 100644 --- a/cyfra-examples/src/main/scala/io/computenode/samples/cyfra/oldsamples/Raytracing.scala +++ b/cyfra-examples/src/main/scala/io/computenode/samples/cyfra/oldsamples/Raytracing.scala @@ -131,16 +131,14 @@ def main = val existingSpheres = mutable.Set.empty[((Float, Float, Float), Float)] def randomSphere(iter: Int = 0): Sphere = { - if (iter > 1000) - throw new Exception("Could not find a non-intersecting sphere") + if iter > 1000 then throw new Exception("Could not find a non-intersecting sphere") def nextFloatAny = rd.nextFloat() * 2f - 1f def nextFloatPos = rd.nextFloat() val center = (nextFloatAny * 10, nextFloatAny * 10, nextFloatPos * 10 + 8f) val radius = nextFloatPos + 1.5f - if (existingSpheres.exists(s => scalaTwoSpheresIntersect(s._1, s._2, center, radius))) - randomSphere(iter + 1) + if existingSpheres.exists(s => scalaTwoSpheresIntersect(s._1, s._2, center, radius)) then randomSphere(iter + 1) else { existingSpheres.add((center, radius)) def color = (nextFloatPos * 0.5f + 0.5f, nextFloatPos * 0.5f + 0.5f, nextFloatPos * 0.5f + 0.5f) diff --git a/cyfra-foton/src/main/scala/io/computenode/cyfra/foton/animation/AnimationRenderer.scala b/cyfra-foton/src/main/scala/io/computenode/cyfra/foton/animation/AnimationRenderer.scala index e50cf55f..f46068dc 100644 --- a/cyfra-foton/src/main/scala/io/computenode/cyfra/foton/animation/AnimationRenderer.scala +++ b/cyfra-foton/src/main/scala/io/computenode/cyfra/foton/animation/AnimationRenderer.scala @@ -18,7 +18,7 @@ import java.nio.file.{Path, Paths} import scala.concurrent.Await import scala.concurrent.duration.DurationInt -trait AnimationRenderer[S <: AnimationRenderer.Scene, F <: GFunction[_, Vec4[Float32], Vec4[Float32]]](params: AnimationRenderer.Parameters): +trait AnimationRenderer[S <: AnimationRenderer.Scene, F <: GFunction[?, Vec4[Float32], Vec4[Float32]]](params: AnimationRenderer.Parameters): private val msPerFrame = 1000.0f / params.framesPerSecond diff --git a/cyfra-foton/src/main/scala/io/computenode/cyfra/foton/rt/shapes/ShapeCollection.scala b/cyfra-foton/src/main/scala/io/computenode/cyfra/foton/rt/shapes/ShapeCollection.scala index 4f1a42a0..22ff6e0d 100644 --- a/cyfra-foton/src/main/scala/io/computenode/cyfra/foton/rt/shapes/ShapeCollection.scala +++ b/cyfra-foton/src/main/scala/io/computenode/cyfra/foton/rt/shapes/ShapeCollection.scala @@ -35,7 +35,7 @@ class ShapeCollection(val boxes: List[Box], val spheres: List[Sphere], val quads case _ => assert(false, "Unknown shape type: Broken sealed hierarchy") def testRay(rayPos: Vec3[Float32], rayDir: Vec3[Float32], noHit: RayHitInfo): RayHitInfo = - def testShapeType[T <: GStruct[T] with Shape: FromExpr: Tag: TestRay](shapes: List[T], currentHit: RayHitInfo): RayHitInfo = + def testShapeType[T <: GStruct[T] & Shape: FromExpr: Tag: TestRay](shapes: List[T], currentHit: RayHitInfo): RayHitInfo = val testRay = summon[TestRay[T]] if shapes.isEmpty then currentHit else GSeq.of(shapes).fold(currentHit, (currentHit, shape) => testRay.testRay(shape, rayPos, rayDir, currentHit)) diff --git a/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/Executable.scala b/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/Executable.scala index 3151cf17..164458bf 100644 --- a/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/Executable.scala +++ b/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/Executable.scala @@ -6,5 +6,5 @@ import io.computenode.cyfra.runtime.mem.{GMem, RamGMem} import scala.concurrent.Future trait Executable[H <: Value, R <: Value] { - def execute(input: GMem[H], output: RamGMem[R, _]): Future[Unit] + def execute(input: GMem[H], output: RamGMem[R, ?]): Future[Unit] } diff --git a/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/GFunction.scala b/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/GFunction.scala index 8871460c..17ba5f79 100644 --- a/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/GFunction.scala +++ b/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/GFunction.scala @@ -8,8 +8,8 @@ import izumi.reflect.Tag case class GFunction[G <: GStruct[G]: GStructSchema: Tag, H <: Value: Tag: FromExpr, R <: Value: Tag: FromExpr](fn: (G, Int32, GArray[H]) => R)( implicit context: GContext, ) { - def arrayInputs: List[Tag[_]] = List(summon[Tag[H]]) - def arrayOutputs: List[Tag[_]] = List(summon[Tag[R]]) + def arrayInputs: List[Tag[?]] = List(summon[Tag[H]]) + def arrayOutputs: List[Tag[?]] = List(summon[Tag[R]]) val pipeline: ComputePipeline = context.compile(this) } diff --git a/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/mem/GMem.scala b/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/mem/GMem.scala index 69b2c984..10cc0398 100644 --- a/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/mem/GMem.scala +++ b/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/mem/GMem.scala @@ -24,9 +24,9 @@ trait GMem[H <: Value]: object GMem: type fRGBA = (Float, Float, Float, Float) - def totalStride(gs: GStructSchema[_]): Int = gs.fields.map { + def totalStride(gs: GStructSchema[?]): Int = gs.fields.map { case (_, fromExpr, t) if t <:< gs.gStructTag => - val constructor = fromExpr.asInstanceOf[GStructConstructor[_]] + val constructor = fromExpr.asInstanceOf[GStructConstructor[?]] totalStride(constructor.schema) case (_, _, t) => typeStride(t) diff --git a/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/mem/Vec4FloatMem.scala b/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/mem/Vec4FloatMem.scala index bd418ede..710781ea 100644 --- a/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/mem/Vec4FloatMem.scala +++ b/cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/mem/Vec4FloatMem.scala @@ -11,8 +11,7 @@ class Vec4FloatMem(val size: Int, protected val data: ByteBuffer) extends RamGMe def toArray: Array[fRGBA] = { val res = data.asFloatBuffer() val result = new Array[fRGBA](size) - for (i <- 0 until size) - result(i) = (res.get(), res.get(), res.get(), res.get()) + for i <- 0 until size do result(i) = (res.get(), res.get(), res.get(), res.get()) result } diff --git a/cyfra-utility/src/main/scala/io/computenode/cyfra/utility/ImageUtility.scala b/cyfra-utility/src/main/scala/io/computenode/cyfra/utility/ImageUtility.scala index a1dfc18a..81478b63 100644 --- a/cyfra-utility/src/main/scala/io/computenode/cyfra/utility/ImageUtility.scala +++ b/cyfra-utility/src/main/scala/io/computenode/cyfra/utility/ImageUtility.scala @@ -9,8 +9,8 @@ object ImageUtility { def renderToImage(arr: Array[(Float, Float, Float, Float)], n: Int, location: Path): Unit = renderToImage(arr, n, n, location) def renderToImage(arr: Array[(Float, Float, Float, Float)], w: Int, h: Int, location: Path): Unit = { val image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB) - for (y <- 0 until h) - for (x <- 0 until w) { + for y <- 0 until h do + for x <- 0 until w do { val (r, g, b, _) = arr(y * w + x) def clip(f: Float) = Math.min(1.0f, Math.max(0.0f, f)) val (iR, iG, iB) = ((clip(r) * 255).toInt, (clip(g) * 255).toInt, (clip(b) * 255).toInt) diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/VulkanContext.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/VulkanContext.scala index cfb5ea56..a12e1c7e 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/VulkanContext.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/VulkanContext.scala @@ -17,7 +17,7 @@ private[cyfra] object VulkanContext { private[cyfra] class VulkanContext { val instance: Instance = new Instance(ValidationLayers) - val debugCallback: Option[DebugCallback] = if (ValidationLayers) Some(new DebugCallback(instance)) else None + val debugCallback: Option[DebugCallback] = if ValidationLayers then Some(new DebugCallback(instance)) else None val device: Device = new Device(instance) val computeQueue: Queue = new Queue(device.computeQueueFamily, 0, device) val allocator: Allocator = new Allocator(instance, device) diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/command/Fence.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/command/Fence.scala index ce46ac25..85c4ac96 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/command/Fence.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/command/Fence.scala @@ -34,8 +34,7 @@ private[cyfra] class Fence(device: Device, flags: Int = 0, onDestroy: () => Unit def isSignaled: Boolean = { val result = vkGetFenceStatus(device.get, handle) - if (!(result == VK_SUCCESS || result == VK_NOT_READY)) - throw new VulkanAssertionError("Failed to get fence status", result) + if !(result == VK_SUCCESS || result == VK_NOT_READY) then throw new VulkanAssertionError("Failed to get fence status", result) result == VK_SUCCESS } @@ -51,8 +50,7 @@ private[cyfra] class Fence(device: Device, flags: Int = 0, onDestroy: () => Unit def block(timeout: Long): Boolean = { val err = vkWaitForFences(device.get, handle, true, timeout); - if (err != VK_SUCCESS && err != VK_TIMEOUT) - throw new VulkanAssertionError("Failed to wait for fences", err); + if err != VK_SUCCESS && err != VK_TIMEOUT then throw new VulkanAssertionError("Failed to wait for fences", err); err == VK_SUCCESS; } } diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/compute/ComputePipeline.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/compute/ComputePipeline.scala index aeddd7f4..ca2456de 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/compute/ComputePipeline.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/compute/ComputePipeline.scala @@ -24,7 +24,7 @@ private[cyfra] class ComputePipeline(val computeShader: Shader, context: VulkanC .sType$Default() .pNext(0) .flags(0) - .pSetLayouts(stack.longs(descriptorSetLayouts.map(_._1): _*)) + .pSetLayouts(stack.longs(descriptorSetLayouts.map(_._1)*)) .pPushConstantRanges(null) val pPipelineLayout = stack.callocLong(1) diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/DebugCallback.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/DebugCallback.scala index c4d26edc..c09a1e7a 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/DebugCallback.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/DebugCallback.scala @@ -66,8 +66,7 @@ private[cyfra] class DebugCallback(instance: Instance) extends VulkanObjectHandl val pCallback = BufferUtils.createLongBuffer(1) val err = vkCreateDebugReportCallbackEXT(instance.get, dbgCreateInfo, null, pCallback) val callbackHandle = pCallback.get(0) - if (err != VK_SUCCESS) - throw new VulkanAssertionError("Failed to create DebugCallback", err) + if err != VK_SUCCESS then throw new VulkanAssertionError("Failed to create DebugCallback", err) callbackHandle } } diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/Device.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/Device.scala index 17744b7a..fe3e519c 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/Device.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/Device.scala @@ -29,8 +29,7 @@ private[cyfra] class Device(instance: Instance) extends VulkanObject { val pPhysicalDeviceCount = stack.callocInt(1) check(vkEnumeratePhysicalDevices(instance.get, pPhysicalDeviceCount, null), "Failed to get number of physical devices") val deviceCount = pPhysicalDeviceCount.get(0) - if (deviceCount == 0) - throw new AssertionError("Failed to find GPUs with Vulkan support") + if deviceCount == 0 then throw new AssertionError("Failed to find GPUs with Vulkan support") val pPhysicalDevices = stack.callocPointer(deviceCount) check(vkEnumeratePhysicalDevices(instance.get, pPhysicalDeviceCount, pPhysicalDevices), "Failed to get physical devices") @@ -132,7 +131,7 @@ private[cyfra] class Device(instance: Instance) extends VulkanObject { .pQueueCreateInfos(pQueueCreateInfo) .ppEnabledExtensionNames(ppExtensionNames) - if (instance.enabledLayers.contains(ValidationLayer)) { + if instance.enabledLayers.contains(ValidationLayer) then { val ppValidationLayers = stack.callocPointer(1).put(stack.ASCII(ValidationLayer)) pCreateInfo.ppEnabledLayerNames(ppValidationLayers.flip()) } diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/Instance.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/Instance.scala index 036edff0..3d1e8da4 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/Instance.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/core/Instance.scala @@ -82,8 +82,8 @@ private[cyfra] class Instance(enableValidationLayers: Boolean) extends VulkanObj lazy val enabledLayers: Seq[String] = List .empty[String] .pipe { x => - if (Instance.layers.contains(ValidationLayer) && enableValidationLayers) ValidationLayer +: x - else if (enableValidationLayers) + if Instance.layers.contains(ValidationLayer) && enableValidationLayers then ValidationLayer +: x + else if enableValidationLayers then logger.error("Validation layers requested but not available") x else x @@ -109,13 +109,11 @@ private[cyfra] class Instance(enableValidationLayers: Boolean) extends VulkanObj } val extensions = mutable.Buffer.from(Instance.MoltenVkExtensions) - if (enableValidationLayers) - extensions.addAll(Instance.ValidationLayersExtensions) + if enableValidationLayers then extensions.addAll(Instance.ValidationLayersExtensions) val filteredExtensions = extensions.filter(ext => availableExtensions.contains(ext).tap { x => - if (!x) - logger.warn(s"Requested Vulkan instance extension '$ext' is not available") + if !x then logger.warn(s"Requested Vulkan instance extension '$ext' is not available") }, ) diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/AbstractExecutor.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/AbstractExecutor.scala index 332ec5fb..a55e4a36 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/AbstractExecutor.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/AbstractExecutor.scala @@ -46,7 +46,7 @@ private[cyfra] abstract class AbstractExecutor(dataLength: Int, val bufferAction VMA_MEMORY_USAGE_UNKNOWN, allocator, ) - for (i <- bufferActions.indices if bufferActions(i) == BufferAction.LoadTo) do { + for i <- bufferActions.indices if bufferActions(i) == BufferAction.LoadTo do { val buffer = input(i) Buffer.copyBuffer(buffer, stagingBuffer, buffer.remaining()) Buffer.copyBuffer(stagingBuffer, buffers(i), buffer.remaining(), commandPool).block().destroy() diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/MapExecutor.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/MapExecutor.scala index aedc82a4..0d88ff41 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/MapExecutor.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/MapExecutor.scala @@ -54,7 +54,7 @@ private[cyfra] class MapExecutor(dataLength: Int, bufferActions: Seq[BufferActio pushStack { stack => vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, computePipeline.get) - val pDescriptorSets = stack.longs(descriptorSets.map(_.get): _*) + val pDescriptorSets = stack.longs(descriptorSets.map(_.get)*) vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, computePipeline.pipelineLayout, 0, pDescriptorSets, null) val workgroup = shader.workgroupDimensions diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/SequenceExecutor.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/SequenceExecutor.scala index 1c960d53..86126ebd 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/SequenceExecutor.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/executor/SequenceExecutor.scala @@ -87,7 +87,7 @@ private[cyfra] class SequenceExecutor(computeSequence: ComputationSequence, cont check(vkBeginCommandBuffer(commandBuffer, commandBufferBeginInfo), "Failed to begin recording command buffer") computeSequence.sequence.foreach { case Compute(pipeline, _) => - if (pipelinesHasDependencies(pipeline)) + if pipelinesHasDependencies(pipeline) then val memoryBarrier = VkMemoryBarrier2 .calloc(1, stack) .sType$Default() @@ -105,7 +105,7 @@ private[cyfra] class SequenceExecutor(computeSequence: ComputationSequence, cont vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline.get) - val pDescriptorSets = stack.longs(pipelineToDescriptorSets(pipeline).map(_.get): _*) + val pDescriptorSets = stack.longs(pipelineToDescriptorSets(pipeline).map(_.get)*) vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline.pipelineLayout, 0, pDescriptorSets, null) val workgroup = pipeline.computeShader.workgroupDimensions diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/Util.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/Util.scala index 92a82681..9065f490 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/Util.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/Util.scala @@ -7,5 +7,5 @@ import scala.util.Using object Util { def pushStack[T](f: MemoryStack => T): T = Using(MemoryStack.stackPush())(f).get - def check(err: Int, message: String = ""): Unit = if (err != VK_SUCCESS) throw new VulkanAssertionError(message, err) + def check(err: Int, message: String = ""): Unit = if err != VK_SUCCESS then throw new VulkanAssertionError(message, err) } diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/VulkanObject.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/VulkanObject.scala index 76e66722..efecc480 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/VulkanObject.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/VulkanObject.scala @@ -7,8 +7,7 @@ private[cyfra] abstract class VulkanObject { protected var alive: Boolean = true def destroy(): Unit = { - if (!alive) - throw new IllegalStateException() + if !alive then throw new IllegalStateException() close() alive = false } diff --git a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/VulkanObjectHandle.scala b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/VulkanObjectHandle.scala index e465f040..9ea98538 100644 --- a/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/VulkanObjectHandle.scala +++ b/cyfra-vulkan/src/main/scala/io/computenode/cyfra/vulkan/util/VulkanObjectHandle.scala @@ -7,8 +7,6 @@ private[cyfra] abstract class VulkanObjectHandle extends VulkanObject { protected val handle: Long def get: Long = - if (!alive) - throw new IllegalStateException() - else - handle + if !alive then throw new IllegalStateException() + else handle }