diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index c046154..9cc5786 --- a/build.sh +++ b/build.sh @@ -41,3 +41,11 @@ shader_stage="-fshader-stage=comp" base_name=$(basename -- "$shader" .glsl) $shader_compiler $shader_flags $shader_stage $shader "${shader_out}${base_name}.spv" + +if [ -x "$(command -v ldc2)" ]; then d_compiler="ldc2"; +elif [ -x "$(command -v dmd)" ]; then d_compiler="dmd"; +else echo "Unable to find D compiler"; exit -1; fi; + +$codegen_src="${script_dir}/vulkan_codegen.d" + +$d_compiler $codegen_src $build/$base_name.spv diff --git a/vulkan.d b/vulkan.d index a910f30..48e8da7 100644 --- a/vulkan.d +++ b/vulkan.d @@ -7,6 +7,7 @@ import core.stdc.string : strcmp, memcpy; import core.stdc.stdio : Printf = printf; import std.format : sformat; import std.math.rounding : Ceil = ceil; +import vulkan_shader; debug { @@ -366,8 +367,6 @@ struct Vulkan BufferView a_buffer_view; ImageView aux_image; - u8[] convert_shader_bytes; - alias queues this; } @@ -404,7 +403,6 @@ Init(PlatformHandles platform_handles, u64 permanent_mem, u64 frame_mem, u8[] co CreateArena(frame_mem), ], platform_handles: platform_handles, - convert_shader_bytes: conv_shader, }; Push(&vk, SI.Renderer); @@ -554,8 +552,9 @@ InitConversionPipeline(Vulkan* vk) offset: 0, } ]; + CompPipelineInfo conv_info = { - shader: vk.convert_shader_bytes, + shader: CONVERT_SHADER_BYTES, layout: vk.conv_pipeline_layout, spec: { data: &channels, diff --git a/vulkan_codegen b/vulkan_codegen new file mode 100755 index 0000000..3e07ea2 Binary files /dev/null and b/vulkan_codegen differ diff --git a/vulkan_codegen.d b/vulkan_codegen.d new file mode 100644 index 0000000..7bcd287 --- /dev/null +++ b/vulkan_codegen.d @@ -0,0 +1,32 @@ +import std.file; +import std.string; +import std.path; +import std.stdio; + +void main(string[] argv) +{ + assert(argv.length > 1, "No argument provided"); + + ubyte[] shader_bytes = cast(ubyte[])read(argv[1]); + + string p = __FILE__.absolutePath; + string codegen_name = chomp(p, baseName(p)) ~ "vulkan_shader.d"; + writefln("%s %s", p, codegen_name); + auto f = File(codegen_name); + + f.writeln("const u8[] CONVERT_SHADER_BYTES = ["); + + foreach(i, b; shader_bytes) + { + if (i % 50 == 0) + { + f.writefln(""); + } + + f.write("%d, ", b); + } + + f.writeln("];"); + + f.close(); +} diff --git a/vulkan_codegen.o b/vulkan_codegen.o new file mode 100644 index 0000000..e3b6942 Binary files /dev/null and b/vulkan_codegen.o differ