-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmrbgem.rake
More file actions
39 lines (35 loc) · 1.85 KB
/
Copy pathmrbgem.rake
File metadata and controls
39 lines (35 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
MRuby::Gem::Specification.new('mruby-gpu-narray') do |spec|
spec.license = 'MIT'
spec.authors = 'Yuji Teshima'
spec.version = '0.1.0'
spec.summary = 'GPU N-dimensional array (Numo-like) for mruby via Vulkan Compute'
# Only dependency is the Vulkan loader. No ncnn / SDL2 / glslang lib / OpenMP.
spec.linker.libraries << 'vulkan'
gem_dir = File.dirname(File.expand_path(__FILE__))
shader_dir = File.join(gem_dir, 'shader')
# Embed the absolute shader directory into a generated header so that
# GPU.init is optional (the first GPU op can lazily initialize). We write a
# header instead of a -D define to avoid shell quote-escaping fragility.
File.write(File.join(gem_dir, 'src', 'shader_dir.h'),
"/* auto-generated by mrbgem.rake -- do not edit, do not commit */\n" \
"#define GPU_NARRAY_SHADER_DIR \"#{shader_dir}\"\n")
# Compile the GLSL compute shaders to SPIR-V at build time, so that adding
# this gem "just works" with no manual `make -C shader` step. Requires
# glslangValidator on PATH (override with the GLSLANG env var). If it is
# missing we warn but keep building; the shaders can be compiled later with
# `make -C shader`.
glslang = ENV['GLSLANG'] || 'glslangValidator'
if system(glslang, '--version', out: File::NULL, err: File::NULL).nil?
warn "mruby-gpu-narray: '#{glslang}' not found on PATH; SPIR-V shaders were " \
"not compiled. Install glslang or run `make -C #{shader_dir}` before use."
else
Dir.glob(File.join(shader_dir, '*.comp')).sort.each do |comp|
spv = comp.sub(/\.comp\z/, '.spv')
next if File.exist?(spv) && File.mtime(spv) >= File.mtime(comp)
puts "GLSLANG #{File.basename(comp)} -> #{File.basename(spv)}"
unless system(glslang, '-V', comp, '-o', spv)
warn "mruby-gpu-narray: failed to compile #{comp} to SPIR-V"
end
end
end
end