change to codegen for shader file

This commit is contained in:
Matthew 2025-08-16 08:46:44 +10:00
parent 1e49d7fc45
commit 3c32939615
5 changed files with 43 additions and 4 deletions

8
build.sh Normal file → Executable file
View File

@ -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

View File

@ -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,

BIN
vulkan_codegen Executable file

Binary file not shown.

32
vulkan_codegen.d Normal file
View File

@ -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();
}

BIN
vulkan_codegen.o Normal file

Binary file not shown.