-
Notifications
You must be signed in to change notification settings - Fork 11
Initial SpirvTools integration #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| import scala.language.postfixOps | ||
|
|
||
| class MVPContext extends GContext { | ||
| implicit val ec: ExecutionContextExecutor = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(16)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add parameter to MVPContext that defaults to true instead of env
| dumpSpvToFile(shaderCode, "program.spv") | ||
|
|
||
| if (SpirvValidator.isSpirvValidationEnabled) | ||
| SpirvValidator.validateSpirv(Paths.get("program.spv")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to dump to tmp file instead
|
|
||
| if (SpirvValidator.isSpirvValidationEnabled) | ||
| SpirvValidator.validateSpirv(Paths.get("program.spv")) | ||
| // SpirvValidator.corruptSpirvFile(Paths.get("program.spv"), Paths.get("corrupted_program.spv")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets remove those comments
| case None => true | ||
| } | ||
|
|
||
| def corruptSpirvFile(originalSpirvFilePath: Path, corruptedSpirvFilePath: Path): Unit = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this before merging
|
Let's also add a test for this |
|
|
||
| exitCode match { | ||
| case 0 => | ||
| println("SPIRV-Tools Validator succeeded!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we have a Logger in Utility. Let's do logger.debug instead of println here
| } | ||
|
|
||
| case None => | ||
| println("Validator executable not found.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no need to print here as we do it already when finding
| } finally { | ||
| Try(Files.deleteIfExists(tmpSpirvPath)).recover { | ||
| case e: Exception => | ||
| println(s"Failed to delete tmp spv file: ${e.getMessage}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here logger.error
| exitCode match | ||
| case 0 => Some(validatorName) | ||
| case _ => | ||
| println(s"Warning: SPIRV-Tools Validator wasn't found in system path.\n${stderr.toString()}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here logger.warn
| H <: Value : Tag : FromExpr, | ||
| R <: Value : Tag : FromExpr | ||
| ](function: GFunction[G, H, R]): ComputePipeline = { | ||
| ](function: GFunction[G, H, R], enableSpirvValidation: Boolean = true): ComputePipeline = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move that param to GContext as discussed
| val processIO = new ProcessIO( | ||
| in => { | ||
| try { | ||
| val buf = new Array[Byte](1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code is repeated n times over the files, let's maybe move it to some function
| arr | ||
| } | ||
|
|
||
| val inputStream = new ByteArrayInputStream(inputBytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that overall we do the same thing for all the tools, but with just a different binary, so that could also be merged if I'm not wrong
| import java.nio.ByteBuffer | ||
| import scala.sys.process.* | ||
|
|
||
| class SpirvDisassemblerError(msg: String) extends RuntimeException(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be a case class and it would be better to put it in companion object (it's a convention to limit top-level definitions that are named differently than the file)
| new ComputePipeline(shader, vkContext) | ||
| } | ||
|
|
||
| def time[R](block: => R): R = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have this somewhere, like in Util object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to find it
|
|
||
| test("Render julia set optimized"): | ||
| given GContext = new GContext(spirvOptimization = Enable(O)) | ||
| val dim = 4096 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here code is repeated, we can have just one function that requires GContext and is called from both those tests
| val processIO = new ProcessIO( | ||
| in => { | ||
| try { | ||
| val buf = new Array[Byte](1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still repeated 3 times I think
| } | ||
| } | ||
|
|
||
| override protected def createError(message: String): SpirvDisassemblerError = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's jsut get rid of all that and just do some SpirvToolException
# Conflicts: # cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/GContext.scala
cyfra-examples/src/main/scala/io/computenode/samples/cyfra/foton/AnimatedJulia.scala
Outdated
Show resolved
Hide resolved
cyfra-foton/src/main/scala/io/computenode/cyfra/foton/animation/AnimatedFunctionRenderer.scala
Outdated
Show resolved
Hide resolved
cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/GContext.scala
Outdated
Show resolved
Hide resolved
cyfra-spirv-tools/src/main/scala/io/computenode/cyfra/spirvtools/SpirvTool.scala
Outdated
Show resolved
Hide resolved
cyfra-spirv-tools/src/main/scala/io/computenode/cyfra/spirvtools/SpirvCross.scala
Outdated
Show resolved
Hide resolved
cyfra-spirv-tools/src/main/scala/io/computenode/cyfra/spirvtools/SpirvTool.scala
Outdated
Show resolved
Hide resolved
cyfra-spirv-tools/src/main/scala/io/computenode/cyfra/spirvtools/SpirvTool.scala
Outdated
Show resolved
Hide resolved
cyfra-spirv-tools/src/main/scala/io/computenode/cyfra/spirvtools/SpirvToolsRunner.scala
Outdated
Show resolved
Hide resolved
cyfra-spirv-tools/src/main/scala/io/computenode/cyfra/spirvtools/SpirvTool.scala
Outdated
Show resolved
Hide resolved
cyfra-spirv-tools/src/main/scala/io/computenode/cyfra/spirvtools/SpirvTool.scala
Outdated
Show resolved
Hide resolved
# Conflicts: # cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/juliaset/JuliaSet.scala
# Conflicts: # cyfra-e2e-test/src/test/resources/io/computenode/cyfra/e2e/juliaset/julia.png # cyfra-e2e-test/src/test/resources/io/computenode/cyfra/juliaset/julia.png # cyfra-e2e-test/src/test/resources/julia.png # cyfra-e2e-test/src/test/scala/io/computenode/cyfra/e2e/juliaset/JuliaSet.scala # cyfra-examples/src/main/scala/io/computenode/samples/cyfra/foton/AnimatedJulia.scala # cyfra-foton/src/main/scala/io/computenode/cyfra/foton/animation/AnimatedFunctionRenderer.scala # cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/GContext.scala
SpirvTools are now integrated into the flow.
For validator to work you need spirv-val executable in system path. It is part of https://github.com/KhronosGroup/SPIRV-Tools. If you want to disable validation completely then you need to set env variable CYFRA_DISABLE_SPIRV_VALIDATION to on.