-
Notifications
You must be signed in to change notification settings - Fork 15
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2c8f03e
Initial SpirvValidator implementation
7737545
Implemented feedback + cleanup
edb068e
Merge
2844189
Before getting rid of tmp files in Validator and Optimizer
a59cb52
Spirv Optimizer and Validator now use stdin and stdout instead of tmp…
7de8201
Merge branch 'main' into SPIRV_INTEGRATION
8136017
Cleanup + added SpirvDisassembler
813dcbe
Cleanup
dbd90df
Merge branch 'main' into SPIRV_INTEGRATION
ee05d41
Major refactor and added SpirV Cross
807f638
Merge remote-tracking branch 'origin/main' into SPIRV_INTEGRATION
d7f4a9e
Moved SpirvTools integration into new module
af89377
Added tests for SpirvTools integration
73afe86
Merge branch 'main' into SPIRV_INTEGRATION
bf57da9
Changed formatting to adhere to scalafmt check
cd88348
More formatting to adhere to scalafmt check
de04cf3
Implementing feedback
ca64bdc
Merge branch 'main' into SPIRV_INTEGRATION
97a750b
Fix for JuliaSet
8923d32
Formatted to comply with scalafmt check
75fce31
Removed path lookup for Spirv Tools. If they are in path, they will work
c230d09
Merge branch 'main' into SPIRV_INTEGRATION
6ac7c40
More formatting
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+2.32 MB
...e2e-test/src/test/resources/io/computenode/cyfra/juliaset/julia_O_optimized.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/SpirvDisassembler.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package io.computenode.cyfra.runtime | ||
|
|
||
| import io.computenode.cyfra.utility.Logger.logger | ||
|
|
||
| import java.nio.ByteBuffer | ||
|
|
||
| object SpirvDisassembler extends SpirvTool { | ||
|
|
||
| override type SpirvError = SpirvDisassemblerError | ||
| protected override val toolName: SupportedSpirVTools = SupportedSpirVTools.Disassembler | ||
|
|
||
| def getDisassembledSpirv(shaderCode: ByteBuffer, options: Param*): Option[String] = { | ||
| getOS.flatMap { os => | ||
| getToolExecutableFromPath( | ||
| toolName, os) | ||
| } match { | ||
| case None => | ||
| logger.warn("Shader code will not be disassembled.") | ||
| None | ||
| case Some(executable) => | ||
| val cmd = Seq(executable) ++ options.flatMap(_.asStringParam.split(" ")) ++ Seq("-") | ||
| val (outputStream, errorStream, exitCode) = executeSpirvCmd(shaderCode, cmd) | ||
|
|
||
| if (exitCode == 0) { | ||
| logger.debug("SPIRV-Tools Disassembler succeeded.") | ||
| Some(outputStream.toString) | ||
| } else { | ||
| throw SpirvDisassemblerError(s"SPIRV-Tools Disassembler failed with exit code $exitCode. ${errorStream.toString}") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override protected def createError(message: String): SpirvDisassemblerError = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| SpirvDisassemblerError(message) | ||
|
|
||
| case class SpirvDisassemblerError(msg: String) extends RuntimeException(msg) | ||
|
|
||
| case object NoIndent extends FlagParam("--no-indent") | ||
|
|
||
| case object NoHeader extends FlagParam("--no-header") | ||
|
|
||
| case object RawId extends FlagParam("--raw-id") | ||
|
|
||
| case object NestedIndent extends FlagParam("--nested-indent") | ||
|
|
||
| case object ReorderBlocks extends FlagParam("--reorder-blocks") | ||
|
|
||
| case object Offsets extends FlagParam("--offsets") | ||
|
|
||
| case object Comment extends FlagParam("--comment") | ||
| } | ||
61 changes: 61 additions & 0 deletions
61
cyfra-runtime/src/main/scala/io/computenode/cyfra/runtime/SpirvOptimizer.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package io.computenode.cyfra.runtime | ||
|
|
||
| import io.computenode.cyfra.runtime.SpirvDisassembler.executeSpirvCmd | ||
| import io.computenode.cyfra.utility.Logger.logger | ||
|
|
||
| import java.nio.ByteBuffer | ||
|
|
||
| object SpirvOptimizer extends SpirvTool { | ||
|
|
||
| override type SpirvError = SpirvOptimizationError | ||
| protected override val toolName: SupportedSpirVTools = SupportedSpirVTools.Optimizer | ||
|
|
||
| def getOptimizedSpirv(shaderCode: ByteBuffer, optimization: Optimization): Option[ByteBuffer] = { | ||
| optimization match { | ||
| case Disable => None | ||
| case Enable(settings*) => | ||
| getOS.flatMap { os => | ||
| getToolExecutableFromPath( | ||
| toolName, os) | ||
| } match { | ||
| case None => | ||
| logger.warn("Shader code will not be optimized.") | ||
| None | ||
| case Some(executable) => | ||
| val cmd = Seq(executable) ++ settings.flatMap(_.asStringParam.split(" ")) ++ Seq("-", "-o", "-") | ||
| val (outputStream, errorStream, exitCode) = executeSpirvCmd(shaderCode, cmd) | ||
|
|
||
| if (exitCode == 0) { | ||
| logger.debug("SPIRV-Tools Optimizer succeeded.") | ||
| Some(toDirectBuffer(ByteBuffer.wrap(outputStream.toByteArray))) | ||
| } else { | ||
| throw SpirvOptimizationError(s"SPIRV-Tools Optimizer failed with exit code $exitCode.\n${errorStream.toString()}") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private def toDirectBuffer(buf: ByteBuffer): ByteBuffer = { | ||
| val direct = ByteBuffer.allocateDirect(buf.remaining()) | ||
| direct.put(buf) | ||
| direct.flip() | ||
| direct | ||
| } | ||
|
|
||
| override protected def createError(message: String): SpirvOptimizationError = | ||
| SpirvOptimizationError(message) | ||
|
|
||
| sealed trait Optimization | ||
|
|
||
| case class SpirvOptimizationError(msg: String) extends RuntimeException(msg) | ||
|
|
||
| case class TargetEnv(version: String) extends ParamWithArgs("--target-env", version) | ||
|
|
||
| case class Enable(settings: Param*) extends Optimization | ||
|
|
||
| case object O extends FlagParam("-O") | ||
|
|
||
| case object Os extends FlagParam("-Os") | ||
|
|
||
| case object Disable extends Optimization | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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