nim2spirv 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
nim2spirv 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
nim2spirv 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 Readme
开发语言 Nim
操作系统 跨平台
软件类型 开源软件
所属分类 开发工具编译器
开源组织
地区 不详
投 递 者 首席测试
适用人群 未知
收录时间 2021-11-08

软件简介

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)
展开阅读全文

代码

评论

点击引领话题📣 发布并加入讨论🔥
暂无内容
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
0 评论
0 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部