当前位置: 首页 > 软件库 > 开发工具 > 编译器 >

nim2spirv

A SPIR-V backend for the Nim compiler
授权协议 Readme
开发语言 Nim
所属分类 开发工具、 编译器
软件类型 开源软件
地区 不详
投 递 者 宓弘壮
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

nim2spirv

A backend for the Nim compiler and standalone executable to compile Nim into SPIR-V.

Note: This is an early proof-of-concept and work-in-progress!

Goals

  • Make Nim an awesome shader language, closely mapping to SPIR-V concepts.
  • Share code between host program and shader modules by compiling .nim-files with both nim and nim2spirv.
  • Define a high-level shader DSL through the power meta-programming that
    • trivializes shader permutation management
    • abstracts API differences
    • exposes shader meta-data to the host program and authoring tools, by directly importing shader modules

Usage

This needs to built against a patched branch of the nim compiler:https://github.com/fragcolor-xyz/Nim/tree/nim2spirv

Use similarly to nim:

nim2spirv spirv test.nim
spirv-dis test.spv
spirv-opt -o test-opt.spv test.spv

Consume direcly with Vulkan or cross-compile with SPIRV-Cross.

Progress

Currently the following compiles and produces a valid SPIR-V module with a Vulkan vertex and fragment entry-point:

import shaders

type
  Data = object
    worldViewProjection {.rowMajor.}: Matrix4x4

var
  data {.uniform, descriptorSet: 0, binding: 0.}: Data

  position {.input, location: 0.}: Vector4
  normal {.input, location: 1.}: Vector3
  texCoordVIn {.input, location: 2.}: Vector2
  texCoordVOut {.output, location: 0.}: Vector2
  clipSpacePosition {.output, builtIn: Position.}: Vector4

  texCoord {.input, location: 0.}: Vector2
  color {.output, location: 0.}: Vector4

proc vsMain() {.stage: Vertex.} =
  clipSpacePosition = construct[Vector4](position.xyz, 1.0'f32) * data.worldViewProjection
  clipSpacePosition.y = -clipSpacePosition.y
  texCoordVOut = texCoordVIn

proc fsMain() {.stage: Fragment.} =
  color = construct[Vector4](texCoord.xy, 0.0'f32, 1.0'f32)

相关阅读

相关文章

相关问答

相关文档