add shader backend + support for multiple shader formats

This commit is contained in:
2026-08-01 00:41:50 -07:00
parent 1a7b777b0f
commit fee46730b1
9 changed files with 195 additions and 23 deletions
+52
View File
@@ -0,0 +1,52 @@
package engine
import "core:fmt"
import "core:os"
import sdl "vendor:sdl3"
choose_shader_runtime :: proc(device: ^sdl.GPUDevice) -> (Shader_Runtime, bool) {
supported := sdl.GetGPUShaderFormats(device)
if .MSL in supported {
return {
backend = .Metal_MSL,
format = {.MSL},
shader_dir = "shaders/metal",
entrypoint = "main",
},
true
}
if .DXIL in supported {
return {
backend = .DSD12_DXIL,
format = {.DXIL},
shader_dir = "shaders/d3d12",
entrypoint = "main",
},
true
}
if .SPIRV in supported {
return {
backend = .Vulkan_SPIRV,
format = {.SPIRV},
shader_dir = "shaders/vulkan",
entrypoint = "main",
},
true
}
fmt.eprintfln("No supported shader format from device {got %v}", supported)
return {}, false
}
load_shader_blob :: proc(path: string) -> ([]u8, bool) {
data, err := os.read_entire_file(path, context.allocator)
if err != nil {
fmt.eprintfln("failed to read shader %s: %v", path, err)
return nil, false
}
return data, true
}