diff --git a/include/shady/runtime.h b/include/shady/runtime.h index 509ed7fdc..68aa75a80 100644 --- a/include/shady/runtime.h +++ b/include/shady/runtime.h @@ -11,8 +11,8 @@ typedef struct { bool allow_no_devices; } RuntimeConfig; -RuntimeConfig default_runtime_config(); -void cli_parse_runtime_config(RuntimeConfig* config, int* pargc, char** argv); +RuntimeConfig shd_rt_default_config(); +void shd_rt_cli_parse_runtime_config(RuntimeConfig* config, int* pargc, char** argv); typedef struct Runtime_ Runtime; typedef struct Device_ Device; @@ -20,35 +20,35 @@ typedef struct Program_ Program; typedef struct Command_ Command; typedef struct Buffer_ Buffer; -Runtime* initialize_runtime(RuntimeConfig config); -void shutdown_runtime(Runtime*); +Runtime* shd_rt_initialize(RuntimeConfig config); +void shd_rt_shutdown(Runtime* runtime); -size_t device_count(Runtime*); -Device* get_device(Runtime*, size_t i); -Device* get_an_device(Runtime*); -const char* get_device_name(Device*); +size_t shd_rt_device_count(Runtime* r); +Device* shd_rt_get_device(Runtime* r, size_t i); +Device* shd_rt_get_an_device(Runtime* r); +const char* shd_rt_get_device_name(Device* d); typedef struct CompilerConfig_ CompilerConfig; typedef struct Module_ Module; -Program* new_program_from_module(Runtime*, const CompilerConfig*, Module*); +Program* shd_rt_new_program_from_module(Runtime* runtime, const CompilerConfig* base_config, Module* mod); typedef struct { uint64_t* profiled_gpu_time; } ExtraKernelOptions; -Command* launch_kernel(Program*, Device*, const char* entry_point, int dimx, int dimy, int dimz, int args_count, void** args, ExtraKernelOptions*); -bool wait_completion(Command*); +Command* shd_rt_launch_kernel(Program* p, Device* d, const char* entry_point, int dimx, int dimy, int dimz, int args_count, void** args, ExtraKernelOptions* extra_options); +bool shd_rt_wait_completion(Command* cmd); -Buffer* allocate_buffer_device(Device*, size_t); -bool can_import_host_memory(Device*); -Buffer* import_buffer_host(Device*, void*, size_t); -void destroy_buffer(Buffer*); +Buffer* shd_rt_allocate_buffer_device(Device* device, size_t bytes); +bool shd_rt_can_import_host_memory(Device* device); +Buffer* shd_rt_import_buffer_host(Device* device, void* ptr, size_t bytes); +void shd_rt_destroy_buffer(Buffer* buf); -void* get_buffer_host_pointer(Buffer* buf); -uint64_t get_buffer_device_pointer(Buffer* buf); +void* shd_rt_get_buffer_host_pointer(Buffer* buf); +uint64_t shd_rt_get_buffer_device_pointer(Buffer* buf); -bool copy_to_buffer(Buffer* dst, size_t buffer_offset, void* src, size_t size); -bool copy_from_buffer(Buffer* src, size_t buffer_offset, void* dst, size_t size); +bool shd_rt_copy_to_buffer(Buffer* dst, size_t buffer_offset, void* src, size_t size); +bool shd_rt_copy_from_buffer(Buffer* src, size_t buffer_offset, void* dst, size_t size); #endif diff --git a/samples/aobench/ao_main.c b/samples/aobench/ao_main.c index b5ba969a7..aa57a9a5f 100644 --- a/samples/aobench/ao_main.c +++ b/samples/aobench/ao_main.c @@ -98,8 +98,8 @@ void render_device(Args* args, TEXEL_T *img, int w, int h, int nsubsamples, Stri shd_info_print("Shady checkerboard test starting...\n"); - Runtime* runtime = initialize_runtime(args->runtime_config); - Device* device = get_device(runtime, args->common_app_args.device); + Runtime* runtime = shd_rt_initialize(args->runtime_config); + Device* device = shd_rt_get_device(runtime, args->common_app_args.device); assert(device); img[0] = 69; @@ -107,49 +107,49 @@ void render_device(Args* args, TEXEL_T *img, int w, int h, int nsubsamples, Stri Buffer* buf; if (import_memory) - buf = import_buffer_host(device, img, sizeof(*img) * WIDTH * HEIGHT * 3); + buf = shd_rt_import_buffer_host(device, img, sizeof(*img) * WIDTH * HEIGHT * 3); else - buf = allocate_buffer_device(device, sizeof(*img) * WIDTH * HEIGHT * 3); + buf = shd_rt_allocate_buffer_device(device, sizeof(*img) * WIDTH * HEIGHT * 3); - uint64_t buf_addr = get_buffer_device_pointer(buf); + uint64_t buf_addr = shd_rt_get_buffer_device_pointer(buf); shd_info_print("Device-side address is: %zu\n", buf_addr); Module* m; CHECK(shd_driver_load_source_file_from_filename(&args->compiler_config, path, "aobench", &m) == NoError, return); - Program* program = new_program_from_module(runtime, &args->compiler_config, m); + Program* program = shd_rt_new_program_from_module(runtime, &args->compiler_config, m); // run it twice to compile everything and benefit from caches - wait_completion(launch_kernel(program, device, "aobench_kernel", WIDTH / BLOCK_SIZE, HEIGHT / BLOCK_SIZE, 1, 1, (void*[]) { &buf_addr }, NULL)); + shd_rt_wait_completion(shd_rt_launch_kernel(program, device, "aobench_kernel", WIDTH / BLOCK_SIZE, HEIGHT / BLOCK_SIZE, 1, 1, (void* []) { &buf_addr }, NULL)); uint64_t tsn = shd_get_time_nano(); uint64_t profiled_gpu_time = 0; ExtraKernelOptions extra_kernel_options = { .profiled_gpu_time = &profiled_gpu_time }; - wait_completion(launch_kernel(program, device, "aobench_kernel", WIDTH / BLOCK_SIZE, HEIGHT / BLOCK_SIZE, 1, 1, (void*[]) { &buf_addr }, &extra_kernel_options)); + shd_rt_wait_completion(shd_rt_launch_kernel(program, device, "aobench_kernel", WIDTH / BLOCK_SIZE, HEIGHT / BLOCK_SIZE, 1, 1, (void* []) { &buf_addr }, &extra_kernel_options)); uint64_t tpn = shd_get_time_nano(); shd_info_print("device rendering took %dus (gpu time: %dus)\n", (tpn - tsn) / 1000, profiled_gpu_time / 1000); if (!import_memory) - copy_from_buffer(buf, 0, img, sizeof(*img) * WIDTH * HEIGHT * 3); + shd_rt_copy_from_buffer(buf, 0, img, sizeof(*img) * WIDTH * HEIGHT * 3); shd_debug_print("data %d\n", (int) img[0]); - destroy_buffer(buf); + shd_rt_destroy_buffer(buf); - shutdown_runtime(runtime); + shd_rt_shutdown(runtime); } int main(int argc, char **argv) { shd_log_set_level(INFO); Args args = { .compiler_config = shd_default_compiler_config(), - .runtime_config = default_runtime_config(), + .runtime_config = shd_rt_default_config(), }; args.compiler_config.input_cf.restructure_with_heuristics = true; shd_parse_common_args(&argc, argv); shd_parse_compiler_config_args(&args.compiler_config, &argc, argv); - cli_parse_runtime_config(&args.runtime_config, &argc, argv); + shd_rt_cli_parse_runtime_config(&args.runtime_config, &argc, argv); cli_parse_common_app_arguments(&args.common_app_args, &argc, argv); bool do_host = false, do_ispc = false, do_device = false, do_all = true; diff --git a/samples/checkerboard/checkerboard.c b/samples/checkerboard/checkerboard.c index 214eb6e01..42a9905e8 100644 --- a/samples/checkerboard/checkerboard.c +++ b/samples/checkerboard/checkerboard.c @@ -44,25 +44,25 @@ int main(int argc, char **argv) shd_log_set_level(INFO); CompilerConfig compiler_config = shd_default_compiler_config(); - RuntimeConfig runtime_config = default_runtime_config(); + RuntimeConfig runtime_config = shd_rt_default_config(); shd_parse_common_args(&argc, argv); shd_parse_compiler_config_args(&compiler_config, &argc, argv); - cli_parse_runtime_config(&runtime_config, &argc, argv); + shd_rt_cli_parse_runtime_config(&runtime_config, &argc, argv); shd_info_print("Shady checkerboard test starting...\n"); - Runtime* runtime = initialize_runtime(runtime_config); - Device* device = get_device(runtime, 0); + Runtime* runtime = shd_rt_initialize(runtime_config); + Device* device = shd_rt_get_device(runtime, 0); assert(device); img[0] = 69; shd_info_print("malloc'd address is: %zu\n", (size_t) img); int buf_size = sizeof(uint8_t) * WIDTH * HEIGHT * 3; - Buffer* buf = allocate_buffer_device(device, buf_size); - copy_to_buffer(buf, 0, img, buf_size); - uint64_t buf_addr = get_buffer_device_pointer(buf); + Buffer* buf = shd_rt_allocate_buffer_device(device, buf_size); + shd_rt_copy_to_buffer(buf, 0, img, buf_size); + uint64_t buf_addr = shd_rt_get_buffer_device_pointer(buf); shd_info_print("Device-side address is: %zu\n", buf_addr); @@ -72,16 +72,16 @@ int main(int argc, char **argv) if (shd_driver_load_source_file(&compiler_config, SrcSlim, sizeof(checkerboard_kernel_src), checkerboard_kernel_src, "checkerboard", &m) != NoError) shd_error("Failed to load checkerboard module"); - Program* program = new_program_from_module(runtime, &compiler_config, m); + Program* program = shd_rt_new_program_from_module(runtime, &compiler_config, m); - wait_completion(launch_kernel(program, device, "checkerboard", 16, 16, 1, 1, (void*[]) { &buf_addr }, NULL)); + shd_rt_wait_completion(shd_rt_launch_kernel(program, device, "checkerboard", 16, 16, 1, 1, (void* []) { &buf_addr }, NULL)); - copy_from_buffer(buf, 0, img, buf_size); + shd_rt_copy_from_buffer(buf, 0, img, buf_size); shd_info_print("data %d\n", (int) img[0]); - destroy_buffer(buf); + shd_rt_destroy_buffer(buf); - shutdown_runtime(runtime); + shd_rt_shutdown(runtime); saveppm("checkerboard.ppm", WIDTH, HEIGHT, img); shd_destroy_ir_arena(a); free(img); diff --git a/src/runtime/cuda/cuda_runtime.c b/src/runtime/cuda/cuda_runtime.c index 225943a1a..6d079528d 100644 --- a/src/runtime/cuda/cuda_runtime.c +++ b/src/runtime/cuda/cuda_runtime.c @@ -34,7 +34,7 @@ bool cuda_command_wait(CudaCommand* command) { return true; } -CudaCommand* shd_cuda_launch_kernel(CudaDevice* device, Program* p, String entry_point, int dimx, int dimy, int dimz, int args_count, void** args, ExtraKernelOptions* options) { +static CudaCommand* shd_cuda_launch_kernel(CudaDevice* device, Program* p, String entry_point, int dimx, int dimy, int dimz, int args_count, void** args, ExtraKernelOptions* options) { CudaKernel* kernel = shd_cuda_get_specialized_program(device, p, entry_point); CudaCommand* cmd = calloc(sizeof(CudaCommand), 1); @@ -76,9 +76,9 @@ static CudaDevice* create_cuda_device(CudaBackend* b, int ordinal) { .base = { .get_name = (const char*(*)(Device*)) cuda_device_get_name, .cleanup = (void(*)(Device*)) cuda_device_cleanup, - .allocate_buffer = (Buffer* (*)(Device*, size_t)) shd_cuda_allocate_buffer, - .can_import_host_memory = (bool (*)(Device*)) shd_cuda_can_import_host_memory, - .import_host_memory_as_buffer = (Buffer* (*)(Device*, void*, size_t)) shd_cuda_import_host_memory, + .allocate_buffer = (Buffer* (*)(Device*, size_t)) shd_rt_cuda_allocate_buffer, + .can_import_host_memory = (bool (*)(Device*)) shd_rt_cuda_can_import_host_memory, + .import_host_memory_as_buffer = (Buffer* (*)(Device*, void*, size_t)) shd_rt_cuda_import_host_memory, .launch_kernel = (Command*(*)(Device*, Program*, String, int, int, int, int, void**, ExtraKernelOptions*)) shd_cuda_launch_kernel, }, .handle = handle, @@ -108,7 +108,7 @@ static bool probe_cuda_devices(CudaBackend* b) { return true; } -Backend* initialize_cuda_backend(Runtime* base) { +Backend* shd_rt_initialize_cuda_backend(Runtime* base) { CudaBackend* backend = malloc(sizeof(CudaBackend)); memset(backend, 0, sizeof(CudaBackend)); backend->base = (Backend) { diff --git a/src/runtime/cuda/cuda_runtime_buffer.c b/src/runtime/cuda/cuda_runtime_buffer.c index dd9991bac..c1af084ca 100644 --- a/src/runtime/cuda/cuda_runtime_buffer.c +++ b/src/runtime/cuda/cuda_runtime_buffer.c @@ -45,7 +45,7 @@ static CudaBuffer* new_buffer_common(size_t size) { return buffer; } -CudaBuffer* shd_cuda_allocate_buffer(CudaDevice* device, size_t size) { +CudaBuffer* shd_rt_cuda_allocate_buffer(CudaDevice* device, size_t size) { CUdeviceptr device_ptr; CHECK_CUDA(cuMemAlloc(&device_ptr, size), return NULL); CudaBuffer* buffer = new_buffer_common(size); @@ -56,7 +56,7 @@ CudaBuffer* shd_cuda_allocate_buffer(CudaDevice* device, size_t size) { return buffer; } -CudaBuffer* shd_cuda_import_host_memory(CudaDevice* device, void* host_ptr, size_t size) { +CudaBuffer* shd_rt_cuda_import_host_memory(CudaDevice* device, void* host_ptr, size_t size) { CUdeviceptr device_ptr; CHECK_CUDA(cuMemHostRegister(host_ptr, size, CU_MEMHOSTREGISTER_DEVICEMAP), return NULL); CHECK_CUDA(cuMemHostGetDevicePointer(&device_ptr, host_ptr, 0), return NULL); @@ -68,6 +68,6 @@ CudaBuffer* shd_cuda_import_host_memory(CudaDevice* device, void* host_ptr, size return buffer; } -bool shd_cuda_can_import_host_memory(CudaDevice* d) { +bool shd_rt_cuda_can_import_host_memory(CudaDevice* d) { return true; } diff --git a/src/runtime/cuda/cuda_runtime_private.h b/src/runtime/cuda/cuda_runtime_private.h index db8fc4687..6e17f677d 100644 --- a/src/runtime/cuda/cuda_runtime_private.h +++ b/src/runtime/cuda/cuda_runtime_private.h @@ -62,11 +62,11 @@ typedef struct { CUfunction entry_point_function; } CudaKernel; -CudaBuffer* shd_cuda_allocate_buffer(CudaDevice*, size_t size); -CudaBuffer* shd_cuda_import_host_memory(CudaDevice*, void* host_ptr, size_t size); -bool shd_cuda_can_import_host_memory(CudaDevice*); +CudaBuffer* shd_rt_cuda_allocate_buffer(CudaDevice*, size_t size); +CudaBuffer* shd_rt_cuda_import_host_memory(CudaDevice*, void* host_ptr, size_t size); +bool shd_rt_cuda_can_import_host_memory(CudaDevice*); -CudaKernel* shd_cuda_get_specialized_program(CudaDevice*, Program*, String ep); -bool shd_cuda_destroy_specialized_kernel(CudaKernel*); +CudaKernel* shd_rt_cuda_get_specialized_program(CudaDevice*, Program*, String ep); +bool shd_rt_cuda_destroy_specialized_kernel(CudaKernel*); #endif diff --git a/src/runtime/cuda/cuda_runtime_program.c b/src/runtime/cuda/cuda_runtime_program.c index 2cf520191..4c3a460e4 100644 --- a/src/runtime/cuda/cuda_runtime_program.c +++ b/src/runtime/cuda/cuda_runtime_program.c @@ -146,7 +146,7 @@ static CudaKernel* create_specialized_program(CudaDevice* device, SpecProgramKey return kernel; } -CudaKernel* shd_cuda_get_specialized_program(CudaDevice* device, Program* program, String entry_point) { +CudaKernel* shd_rt_cuda_get_specialized_program(CudaDevice* device, Program* program, String entry_point) { SpecProgramKey key = { .base = program, .entry_point = entry_point }; CudaKernel** found = find_value_dict(SpecProgramKey, CudaKernel*, device->specialized_programs, key); if (found) @@ -157,7 +157,7 @@ CudaKernel* shd_cuda_get_specialized_program(CudaDevice* device, Program* progra return spec; } -bool shd_cuda_destroy_specialized_kernel(CudaKernel* kernel) { +bool shd_rt_cuda_destroy_specialized_kernel(CudaKernel* kernel) { free(kernel->cuda_code); free(kernel->ptx); CHECK_CUDA(cuModuleUnload(kernel->cuda_module), return false); diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 6a1185bed..a3e8d08db 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -6,7 +6,7 @@ #include #include -Runtime* initialize_runtime(RuntimeConfig config) { +Runtime* shd_rt_initialize(RuntimeConfig config) { Runtime* runtime = malloc(sizeof(Runtime)); memset(runtime, 0, sizeof(Runtime)); runtime->config = config; @@ -15,12 +15,12 @@ Runtime* initialize_runtime(RuntimeConfig config) { runtime->programs = shd_new_list(Program*); #if VK_BACKEND_PRESENT - Backend* vk_backend = initialize_vk_backend(runtime); + Backend* vk_backend = shd_rt_initialize_vk_backend(runtime); CHECK(vk_backend, goto init_fail_free); shd_list_append(Backend*, runtime->backends, vk_backend); #endif #if CUDA_BACKEND_PRESENT - Backend* cuda_backend = initialize_cuda_backend(runtime); + Backend* cuda_backend = shd_rt_initialize_cuda_backend(runtime); CHECK(cuda_backend, goto init_fail_free); append_list(Backend*, runtime->backends, cuda_backend); #endif @@ -34,7 +34,7 @@ Runtime* initialize_runtime(RuntimeConfig config) { return NULL; } -void shutdown_runtime(Runtime* runtime) { +void shd_rt_shutdown(Runtime* runtime) { if (!runtime) return; // TODO force wait outstanding dispatches ? @@ -45,7 +45,7 @@ void shutdown_runtime(Runtime* runtime) { shd_destroy_list(runtime->devices); for (size_t i = 0; i < shd_list_count(runtime->programs); i++) { - unload_program(shd_read_list(Program*, runtime->programs)[i]); + shd_rt_unload_program(shd_read_list(Program*, runtime->programs)[i]); } shd_destroy_list(runtime->programs); @@ -56,44 +56,39 @@ void shutdown_runtime(Runtime* runtime) { free(runtime); } -size_t device_count(Runtime* r) { +size_t shd_rt_device_count(Runtime* r) { return shd_list_count(r->devices); } -Device* get_device(Runtime* r, size_t i) { - assert(i < device_count(r)); +Device* shd_rt_get_device(Runtime* r, size_t i) { + assert(i < shd_rt_device_count(r)); return shd_read_list(Device*, r->devices)[i]; } -Device* get_an_device(Runtime* r) { - assert(device_count(r) > 0); - return get_device(r, 0); +Device* shd_rt_get_an_device(Runtime* r) { + assert(shd_rt_device_count(r) > 0); + return shd_rt_get_device(r, 0); } // Virtual functions ... -const char* get_device_name(Device* d) { return d->get_name(d); } +const char* shd_rt_get_device_name(Device* d) { return d->get_name(d); } -Command* launch_kernel(Program* p, Device* d, const char* entry_point, int dimx, int dimy, int dimz, int args_count, void** args, ExtraKernelOptions* extra_options) { +Command* shd_rt_launch_kernel(Program* p, Device* d, const char* entry_point, int dimx, int dimy, int dimz, int args_count, void** args, ExtraKernelOptions* extra_options) { return d->launch_kernel(d, p, entry_point, dimx, dimy, dimz, args_count, args, extra_options); } -bool wait_completion(Command* cmd) { return cmd->wait_for_completion(cmd); } +bool shd_rt_wait_completion(Command* cmd) { return cmd->wait_for_completion(cmd); } -bool can_import_host_memory(Device* device) { return device->can_import_host_memory(device); } +bool shd_rt_can_import_host_memory(Device* device) { return device->can_import_host_memory(device); } -Buffer* allocate_buffer_device(Device* device, size_t bytes) { return device->allocate_buffer(device, bytes); } -Buffer* import_buffer_host(Device* device, void* ptr, size_t bytes) { return device->import_host_memory_as_buffer(device, ptr, bytes); } +Buffer* shd_rt_allocate_buffer_device(Device* device, size_t bytes) { return device->allocate_buffer(device, bytes); } +Buffer* shd_rt_import_buffer_host(Device* device, void* ptr, size_t bytes) { return device->import_host_memory_as_buffer(device, ptr, bytes); } -void destroy_buffer(Buffer* buf) { buf->destroy(buf); } +void shd_rt_destroy_buffer(Buffer* buf) { buf->destroy(buf); } -void* get_buffer_host_pointer(Buffer* buf) { return buf->get_host_ptr(buf); } -uint64_t get_buffer_device_pointer(Buffer* buf) { return buf->get_device_ptr(buf); } +void* shd_rt_get_buffer_host_pointer(Buffer* buf) { return buf->get_host_ptr(buf); } +uint64_t shd_rt_get_buffer_device_pointer(Buffer* buf) { return buf->get_device_ptr(buf); } -bool copy_to_buffer(Buffer* dst, size_t buffer_offset, void* src, size_t size) { - return dst->copy_into(dst, buffer_offset, src, size); -} - -bool copy_from_buffer(Buffer* src, size_t buffer_offset, void* dst, size_t size) { - return src->copy_from(src, buffer_offset, dst, size); -} +bool shd_rt_copy_to_buffer(Buffer* dst, size_t buffer_offset, void* src, size_t size) { return dst->copy_into(dst, buffer_offset, src, size); } +bool shd_rt_copy_from_buffer(Buffer* src, size_t buffer_offset, void* dst, size_t size) { return src->copy_from(src, buffer_offset, dst, size); } diff --git a/src/runtime/runtime_cli.c b/src/runtime/runtime_cli.c index 7762f7b23..8c9f53e09 100644 --- a/src/runtime/runtime_cli.c +++ b/src/runtime/runtime_cli.c @@ -3,7 +3,7 @@ #include "log.h" -RuntimeConfig default_runtime_config() { +RuntimeConfig shd_rt_default_config() { return (RuntimeConfig) { #ifndef NDEBUG .dump_spv = true, @@ -18,7 +18,7 @@ RuntimeConfig default_runtime_config() { F(config->use_validation, api-validation) \ F(config->dump_spv, dump-spv) \ -void cli_parse_runtime_config(RuntimeConfig* config, int* pargc, char** argv) { +void shd_rt_cli_parse_runtime_config(RuntimeConfig* config, int* pargc, char** argv) { int argc = *pargc; bool help = false; diff --git a/src/runtime/runtime_private.h b/src/runtime/runtime_private.h index 988bdfe7c..8b8a504a4 100644 --- a/src/runtime/runtime_private.h +++ b/src/runtime/runtime_private.h @@ -64,9 +64,9 @@ struct Buffer_ { bool (*copy_from)(Buffer* src, size_t buffer_offset, void* dst, size_t bytes); }; -void unload_program(Program*); +void shd_rt_unload_program(Program* program); -Backend* initialize_vk_backend(Runtime*); -Backend* initialize_cuda_backend(Runtime*); +Backend* shd_rt_initialize_vk_backend(Runtime*); +Backend* shd_rt_shd_rt_initialize_cuda_backend(Runtime*); #endif diff --git a/src/runtime/runtime_program.c b/src/runtime/runtime_program.c index 0641b826f..8f8792689 100644 --- a/src/runtime/runtime_program.c +++ b/src/runtime/runtime_program.c @@ -10,7 +10,7 @@ #include #include -Program* new_program_from_module(Runtime* runtime, const CompilerConfig* base_config, Module* mod) { +Program* shd_rt_new_program_from_module(Runtime* runtime, const CompilerConfig* base_config, Module* mod) { Program* program = calloc(1, sizeof(Program)); program->runtime = runtime; program->base_config = base_config; @@ -22,7 +22,7 @@ Program* new_program_from_module(Runtime* runtime, const CompilerConfig* base_co return program; } -Program* load_program(Runtime* runtime, const CompilerConfig* base_config, const char* program_src) { +Program* shd_rt_load_program(Runtime* runtime, const CompilerConfig* base_config, const char* program_src) { Module* module; int err = shd_driver_load_source_file(base_config, SrcShadyIR, strlen(program_src), program_src, "my_module", @@ -31,12 +31,12 @@ Program* load_program(Runtime* runtime, const CompilerConfig* base_config, const return NULL; } - Program* program = new_program_from_module(runtime, base_config, module); + Program* program = shd_rt_new_program_from_module(runtime, base_config, module); program->arena = shd_module_get_arena(module); return program; } -Program* load_program_from_disk(Runtime* runtime, const CompilerConfig* base_config, const char* path) { +Program* shd_rt_load_program_from_disk(Runtime* runtime, const CompilerConfig* base_config, const char* path) { Module* module; int err = shd_driver_load_source_file_from_filename(base_config, path, "my_module", &module); @@ -44,12 +44,12 @@ Program* load_program_from_disk(Runtime* runtime, const CompilerConfig* base_con return NULL; } - Program* program = new_program_from_module(runtime, base_config, module); + Program* program = shd_rt_new_program_from_module(runtime, base_config, module); program->arena = shd_module_get_arena(module); return program; } -void unload_program(Program* program) { +void shd_rt_unload_program(Program* program) { // TODO iterate over the specialized stuff if (program->arena) // if the program owns an arena shd_destroy_ir_arena(program->arena); diff --git a/src/runtime/runtime_test.c b/src/runtime/runtime_test.c index 29aad2219..a5ce05432 100644 --- a/src/runtime/runtime_test.c +++ b/src/runtime/runtime_test.c @@ -32,18 +32,18 @@ int main(int argc, char* argv[]) { shd_log_set_level(INFO); Args args = { .driver_config = shd_default_driver_config(), - .runtime_config = default_runtime_config(), + .runtime_config = shd_rt_default_config(), }; cli_parse_common_app_arguments(&args.common_app_args, &argc, argv); shd_parse_common_args(&argc, argv); - cli_parse_runtime_config(&args.runtime_config, &argc, argv); + shd_rt_cli_parse_runtime_config(&args.runtime_config, &argc, argv); shd_parse_compiler_config_args(&args.driver_config.config, &argc, argv); shd_driver_parse_input_files(args.driver_config.input_filenames, &argc, argv); shd_info_print("Shady runtime test starting...\n"); - Runtime* runtime = initialize_runtime(args.runtime_config); - Device* device = get_device(runtime, args.common_app_args.device); + Runtime* runtime = shd_rt_initialize(args.runtime_config); + Device* device = shd_rt_get_device(runtime, args.common_app_args.device); assert(device); Program* program; @@ -54,27 +54,27 @@ int main(int argc, char* argv[]) { Module* module; shd_driver_load_source_file(&args.driver_config.config, SrcSlim, strlen(default_shader), default_shader, "runtime_test", &module); - program = new_program_from_module(runtime, &args.driver_config.config, module); + program = shd_rt_new_program_from_module(runtime, &args.driver_config.config, module); } else { Module* module = shd_new_module(arena, "my_module"); int err = shd_driver_load_source_files(&args.driver_config, module); if (err) return err; - program = new_program_from_module(runtime, &args.driver_config.config, module); + program = shd_rt_new_program_from_module(runtime, &args.driver_config.config, module); } int32_t stuff[] = { 42, 42, 42, 42 }; - Buffer* buffer = allocate_buffer_device(device, sizeof(stuff)); - copy_to_buffer(buffer, 0, stuff, sizeof(stuff)); - copy_from_buffer(buffer, 0, stuff, sizeof(stuff)); + Buffer* buffer = shd_rt_allocate_buffer_device(device, sizeof(stuff)); + shd_rt_copy_to_buffer(buffer, 0, stuff, sizeof(stuff)); + shd_rt_copy_from_buffer(buffer, 0, stuff, sizeof(stuff)); int32_t a0 = 42; - uint64_t a1 = get_buffer_device_pointer(buffer); - wait_completion(launch_kernel(program, device, args.driver_config.config.specialization.entry_point ? args.driver_config.config.specialization.entry_point : "my_kernel", 1, 1, 1, 2, (void*[]) { &a0, &a1 }, NULL)); + uint64_t a1 = shd_rt_get_buffer_device_pointer(buffer); + shd_rt_wait_completion(shd_rt_launch_kernel(program, device, args.driver_config.config.specialization.entry_point ? args.driver_config.config.specialization.entry_point : "my_kernel", 1, 1, 1, 2, (void* []) { &a0, &a1 }, NULL)); - destroy_buffer(buffer); + shd_rt_destroy_buffer(buffer); - shutdown_runtime(runtime); + shd_rt_shutdown(runtime); if (arena) shd_destroy_ir_arena(arena); shd_destroy_driver_config(&args.driver_config); diff --git a/src/runtime/vulkan/vk_runtime.c b/src/runtime/vulkan/vk_runtime.c index ac694126f..dcb324dde 100644 --- a/src/runtime/vulkan/vk_runtime.c +++ b/src/runtime/vulkan/vk_runtime.c @@ -134,7 +134,7 @@ static void shutdown_vulkan_runtime(VkrBackend* backend) { free(backend); } -Backend* initialize_vk_backend(Runtime* base) { +Backend* shd_rt_initialize_vk_backend(Runtime* base) { VkrBackend* backend = malloc(sizeof(VkrBackend)); memset(backend, 0, sizeof(VkrBackend)); backend->base = (Backend) { @@ -143,7 +143,7 @@ Backend* initialize_vk_backend(Runtime* base) { }; CHECK(initialize_vk_instance(backend), goto init_fail_free) - probe_vkr_devices(backend); + shd_rt_vk_probe_devices(backend); shd_info_print("Shady Vulkan backend successfully initialized !\n"); return &backend->base; diff --git a/src/runtime/vulkan/vk_runtime_buffer.c b/src/runtime/vulkan/vk_runtime_buffer.c index 211dc88c5..ccbdea544 100644 --- a/src/runtime/vulkan/vk_runtime_buffer.c +++ b/src/runtime/vulkan/vk_runtime_buffer.c @@ -37,7 +37,7 @@ static uint32_t find_suitable_memory_type(VkrDevice* device, uint32_t memory_typ static Buffer make_base_buffer(VkrDevice*); -VkrBuffer* vkr_allocate_buffer_device_(VkrDevice* device, size_t size, AllocHeap heap) { +static VkrBuffer* vkr_allocate_buffer_device_(VkrDevice* device, size_t size, AllocHeap heap) { if (!device->caps.features.buffer_device_address.bufferDeviceAddress) { shd_error_print("device buffers require VK_KHR_buffer_device_address\n"); return NULL; @@ -102,7 +102,7 @@ VkrBuffer* vkr_allocate_buffer_device_(VkrDevice* device, size_t size, AllocHeap return NULL; } -VkrBuffer* vkr_allocate_buffer_device(VkrDevice* device, size_t size) { +VkrBuffer* shd_rt_vk_allocate_buffer_device(VkrDevice* device, size_t size) { return vkr_allocate_buffer_device_(device, size, AllocDeviceLocal); } @@ -120,11 +120,11 @@ static bool vkr_can_import_host_memory_(VkrDevice* device, bool log) { return true; } -bool vkr_can_import_host_memory(VkrDevice* device) { +bool shd_rt_vk_can_import_host_memory(VkrDevice* device) { return vkr_can_import_host_memory_(device, false); } -VkrBuffer* vkr_import_buffer_host(VkrDevice* device, void* ptr, size_t size) { +VkrBuffer* shd_rt_vk_import_buffer_host(VkrDevice* device, void* ptr, size_t size) { if (!vkr_can_import_host_memory_(device, true)) { shd_error_die(); } @@ -218,7 +218,7 @@ VkrBuffer* vkr_import_buffer_host(VkrDevice* device, void* ptr, size_t size) { return NULL; } -void vkr_destroy_buffer(VkrBuffer* buffer) { +void shd_rt_vk_destroy_buffer(VkrBuffer* buffer) { vkDestroyBuffer(buffer->device->device, buffer->buffer, NULL); vkFreeMemory(buffer->device->device, buffer->memory, NULL); } @@ -236,19 +236,19 @@ static void* vkr_get_buffer_host_pointer(VkrBuffer* buf) { } static VkrCommand* submit_buffer_copy(VkrDevice* device, VkBuffer src, size_t src_offset, VkBuffer dst, size_t dst_offset, size_t size) { - VkrCommand* commands = vkr_begin_command(device); + VkrCommand* commands = shd_rt_vk_begin_command(device); if (!commands) return NULL; vkCmdCopyBuffer(commands->cmd_buf, src, dst, 1, (VkBufferCopy[]) { { .srcOffset = src_offset, .dstOffset = dst_offset, .size = size } }); - if (!vkr_submit_command(commands)) + if (!shd_rt_vk_submit_command(commands)) goto err_post_commands_create; return commands; err_post_commands_create: - vkr_destroy_command(commands); + shd_rt_vk_destroy_command(commands); return NULL; } @@ -264,15 +264,15 @@ static bool vkr_copy_to_buffer_fallback(VkrBuffer* dst, size_t buffer_offset, vo CHECK_VK(vkMapMemory(device->device, src_buf->memory, src_buf->offset, src_buf->size, 0, &mapped), goto err_post_buffer_create); memcpy(mapped, src, size); - if (!wait_completion((Command*) submit_buffer_copy(device, src_buf->buffer, src_buf->offset, dst->buffer, dst->offset + buffer_offset, size))) + if (!shd_rt_wait_completion((Command*) submit_buffer_copy(device, src_buf->buffer, src_buf->offset, dst->buffer, dst->offset + buffer_offset, size))) goto err_post_buffer_create; vkUnmapMemory(device->device, src_buf->memory); - vkr_destroy_buffer(src_buf); + shd_rt_vk_destroy_buffer(src_buf); return true; err_post_buffer_create: - vkr_destroy_buffer(src_buf); + shd_rt_vk_destroy_buffer(src_buf); return false; } @@ -287,16 +287,16 @@ static bool vkr_copy_from_buffer_fallback(VkrBuffer* src, size_t buffer_offset, void* mapped; CHECK_VK(vkMapMemory(device->device, dst_buf->memory, dst_buf->offset, dst_buf->size, 0, &mapped), goto err_post_buffer_create); - if (!wait_completion((Command*) submit_buffer_copy(device, src->buffer, src->offset + buffer_offset, dst_buf->buffer, dst_buf->offset, size))) + if (!shd_rt_wait_completion((Command*) submit_buffer_copy(device, src->buffer, src->offset + buffer_offset, dst_buf->buffer, dst_buf->offset, size))) goto err_post_buffer_create; memcpy(dst, mapped, size); vkUnmapMemory(device->device, dst_buf->memory); - vkr_destroy_buffer(dst_buf); + shd_rt_vk_destroy_buffer(dst_buf); return true; err_post_buffer_create: - vkr_destroy_buffer(dst_buf); + shd_rt_vk_destroy_buffer(dst_buf); return false; } @@ -304,18 +304,18 @@ static bool vkr_copy_to_buffer_importing(VkrBuffer* dst, size_t buffer_offset, v CHECK(dst->base.backend_tag == VulkanRuntimeBackend, return false); VkrDevice* device = dst->device; - VkrBuffer* src_buf = vkr_import_buffer_host(device, src, size); + VkrBuffer* src_buf = shd_rt_vk_import_buffer_host(device, src, size); if (!src_buf) return false; - if (!wait_completion((Command*) submit_buffer_copy(device, src_buf->buffer, src_buf->offset, dst->buffer, dst->offset + buffer_offset, size))) + if (!shd_rt_wait_completion((Command*) submit_buffer_copy(device, src_buf->buffer, src_buf->offset, dst->buffer, dst->offset + buffer_offset, size))) goto err_post_buffer_import; - vkr_destroy_buffer(src_buf); + shd_rt_vk_destroy_buffer(src_buf); return true; err_post_buffer_import: - vkr_destroy_buffer(src_buf); + shd_rt_vk_destroy_buffer(src_buf); return false; } @@ -323,31 +323,31 @@ static bool vkr_copy_from_buffer_importing(VkrBuffer* src, size_t buffer_offset, CHECK(src->base.backend_tag == VulkanRuntimeBackend, return false); VkrDevice* device = src->device; - VkrBuffer* dst_buf = vkr_import_buffer_host(device, dst, size); + VkrBuffer* dst_buf = shd_rt_vk_import_buffer_host(device, dst, size); if (!dst_buf) return false; - if (!wait_completion((Command*) submit_buffer_copy(device, src->buffer, src->offset + buffer_offset, dst_buf->buffer, dst_buf->offset, size))) + if (!shd_rt_wait_completion((Command*) submit_buffer_copy(device, src->buffer, src->offset + buffer_offset, dst_buf->buffer, dst_buf->offset, size))) goto err_post_buffer_import; - vkr_destroy_buffer(dst_buf); + shd_rt_vk_destroy_buffer(dst_buf); return true; err_post_buffer_import: - vkr_destroy_buffer(dst_buf); + shd_rt_vk_destroy_buffer(dst_buf); return false; } static Buffer make_base_buffer(VkrDevice* device) { Buffer buffer = { .backend_tag = VulkanRuntimeBackend, - .destroy = (void(*)(Buffer*)) vkr_destroy_buffer, + .destroy = (void (*)(Buffer*)) shd_rt_vk_destroy_buffer, .get_device_ptr = (uint64_t(*)(Buffer*)) vkr_get_buffer_device_pointer, .get_host_ptr = (void*(*)(Buffer*)) vkr_get_buffer_host_pointer, .copy_into = (bool(*)(Buffer*, size_t, void*, size_t)) vkr_copy_to_buffer_fallback, .copy_from = (bool(*)(Buffer*, size_t, void*, size_t)) vkr_copy_from_buffer_fallback, }; - if (vkr_can_import_host_memory(device)) { + if (shd_rt_vk_can_import_host_memory(device)) { buffer.copy_from = (bool(*)(Buffer*, size_t, void*, size_t)) vkr_copy_from_buffer_importing; buffer.copy_into = (bool(*)(Buffer*, size_t, void*, size_t)) vkr_copy_to_buffer_importing; } diff --git a/src/runtime/vulkan/vk_runtime_device.c b/src/runtime/vulkan/vk_runtime_device.c index 662069586..b03e9c569 100644 --- a/src/runtime/vulkan/vk_runtime_device.c +++ b/src/runtime/vulkan/vk_runtime_device.c @@ -291,7 +291,7 @@ static void shutdown_vkr_device(VkrDevice* device) { SpecProgramKey k; VkrSpecProgram* sp; while (shd_dict_iter(device->specialized_programs, &i, &k, &sp)) { - destroy_specialized_program(sp); + shd_rt_vk_destroy_specialized_program(sp); } shd_destroy_dict(device->specialized_programs); vkDestroyCommandPool(device->device, device->cmd_pool, NULL); @@ -301,7 +301,7 @@ static void shutdown_vkr_device(VkrDevice* device) { static const char* get_vkr_device_name(VkrDevice* device) { return device->caps.properties.base.properties.deviceName; } -bool probe_vkr_devices(VkrBackend* runtime) { +bool shd_rt_vk_probe_devices(VkrBackend* runtime) { uint32_t devices_count; CHECK_VK(vkEnumeratePhysicalDevices(runtime->instance, &devices_count, NULL), return false) LARRAY(VkPhysicalDevice, available_devices, devices_count); @@ -321,10 +321,10 @@ bool probe_vkr_devices(VkrBackend* runtime) { device->base = (Device) { .cleanup = (void(*)(Device*)) shutdown_vkr_device, .get_name = (String(*)(Device*)) get_vkr_device_name, - .allocate_buffer = (Buffer*(*)(Device*, size_t)) vkr_allocate_buffer_device, - .import_host_memory_as_buffer = (Buffer*(*)(Device*, void*, size_t)) vkr_import_buffer_host, - .launch_kernel = (Command*(*)(Device*, Program*, String, int, int, int, int, void**, ExtraKernelOptions*)) vkr_launch_kernel, - .can_import_host_memory = (bool(*)(Device*)) vkr_can_import_host_memory, + .allocate_buffer = (Buffer* (*)(Device*, size_t)) shd_rt_vk_allocate_buffer_device, + .import_host_memory_as_buffer = (Buffer* (*)(Device*, void*, size_t)) shd_rt_vk_import_buffer_host, + .launch_kernel = (Command* (*)(Device*, Program*, String, int, int, int, int, void**, ExtraKernelOptions*)) shd_rt_vk_launch_kernel, + .can_import_host_memory = (bool (*)(Device*)) shd_rt_vk_can_import_host_memory, }; shd_list_append(Device*, runtime->base.runtime->devices, device); } diff --git a/src/runtime/vulkan/vk_runtime_dispatch.c b/src/runtime/vulkan/vk_runtime_dispatch.c index bcf69f244..3207410f5 100644 --- a/src/runtime/vulkan/vk_runtime_dispatch.c +++ b/src/runtime/vulkan/vk_runtime_dispatch.c @@ -30,7 +30,7 @@ static void bind_program_resources(VkrCommand* cmd, VkrSpecProgram* prog) { write_descriptor_sets[write_descriptor_sets_count] = (VkWriteDescriptorSet) { .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = NULL, - .descriptorType = as_to_descriptor_type(resource->as), + .descriptorType = shd_rt_vk_as_to_descriptor_type(resource->as), .descriptorCount = 1, .dstSet = prog->sets[resource->set], .dstBinding = resource->binding, @@ -53,18 +53,18 @@ static void bind_program_resources(VkrCommand* cmd, VkrSpecProgram* prog) { static Command make_command_base() { return (Command) { - .wait_for_completion = (bool(*)(Command*)) vkr_wait_completion, + .wait_for_completion = (bool (*)(Command*)) shd_rt_vk_wait_completion, }; } -VkrCommand* vkr_launch_kernel(VkrDevice* device, Program* program, String entry_point, int dimx, int dimy, int dimz, int args_count, void** args, ExtraKernelOptions* options) { +VkrCommand* shd_rt_vk_launch_kernel(VkrDevice* device, Program* program, String entry_point, int dimx, int dimy, int dimz, int args_count, void** args, ExtraKernelOptions* options) { assert(program && device); - VkrSpecProgram* prog = get_specialized_program(program, entry_point, device); + VkrSpecProgram* prog = shd_rt_vk_get_specialized_program(program, entry_point, device); shd_debug_print("Dispatching kernel on %s\n", device->caps.properties.base.properties.deviceName); - VkrCommand* cmd = vkr_begin_command(device); + VkrCommand* cmd = shd_rt_vk_begin_command(device); if (!cmd) return NULL; @@ -102,17 +102,17 @@ VkrCommand* vkr_launch_kernel(VkrDevice* device, Program* program, String entry_ vkCmdWriteTimestamp(cmd->cmd_buf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, cmd->query_pool, 1); } - if (!vkr_submit_command(cmd)) + if (!shd_rt_vk_submit_command(cmd)) goto err_post_commands_create; return cmd; err_post_commands_create: - vkr_destroy_command(cmd); + shd_rt_vk_destroy_command(cmd); return NULL; } -VkrCommand* vkr_begin_command(VkrDevice* device) { +VkrCommand* shd_rt_vk_begin_command(VkrDevice* device) { VkrCommand* cmd = calloc(1, sizeof(VkrCommand)); cmd->base = make_command_base(); cmd->device = device; @@ -141,7 +141,7 @@ VkrCommand* vkr_begin_command(VkrDevice* device) { return NULL; } -bool vkr_submit_command(VkrCommand* cmd) { +bool shd_rt_vk_submit_command(VkrCommand* cmd) { CHECK_VK(vkEndCommandBuffer(cmd->cmd_buf), return false); CHECK_VK(vkCreateFence(cmd->device->device, &(VkFenceCreateInfo) { @@ -168,7 +168,7 @@ bool vkr_submit_command(VkrCommand* cmd) { return false; } -bool vkr_wait_completion(VkrCommand* cmd) { +bool shd_rt_vk_wait_completion(VkrCommand* cmd) { assert(cmd->submitted && "Command must be submitted before they can be waited on"); CHECK_VK(vkWaitForFences(cmd->device->device, 1, (VkFence[]) { cmd->done_fence }, true, UINT32_MAX), return false); if (cmd->profiled_gpu_time) { @@ -176,11 +176,11 @@ bool vkr_wait_completion(VkrCommand* cmd) { CHECK_VK(vkGetQueryPoolResults(cmd->device->device, cmd->query_pool, 0, 2, sizeof(uint64_t) * 2, ts, sizeof(uint64_t), VK_QUERY_RESULT_64_BIT), {}); *cmd->profiled_gpu_time = (ts[1] - ts[0]) * cmd->device->caps.properties.base.properties.limits.timestampPeriod; } - vkr_destroy_command(cmd); + shd_rt_vk_destroy_command(cmd); return true; } -void vkr_destroy_command(VkrCommand* cmd) { +void shd_rt_vk_destroy_command(VkrCommand* cmd) { if (cmd->submitted) vkDestroyFence(cmd->device->device, cmd->done_fence, NULL); if (cmd->query_pool) diff --git a/src/runtime/vulkan/vk_runtime_private.h b/src/runtime/vulkan/vk_runtime_private.h index 62fa6dd7a..4625cf1e6 100644 --- a/src/runtime/vulkan/vk_runtime_private.h +++ b/src/runtime/vulkan/vk_runtime_private.h @@ -156,7 +156,7 @@ struct VkrDevice_ { struct Dict* specialized_programs; }; -bool probe_vkr_devices(VkrBackend*); +bool shd_rt_vk_probe_devices(VkrBackend* runtime); typedef struct VkrBuffer_ { Buffer base; @@ -169,10 +169,10 @@ typedef struct VkrBuffer_ { void* host_ptr; } VkrBuffer; -VkrBuffer* vkr_allocate_buffer_device(VkrDevice* device, size_t size); -VkrBuffer* vkr_import_buffer_host(VkrDevice* device, void* ptr, size_t size); -bool vkr_can_import_host_memory(VkrDevice* device); -void vkr_destroy_buffer(VkrBuffer* buffer); +VkrBuffer* shd_rt_vk_allocate_buffer_device(VkrDevice* device, size_t size); +VkrBuffer* shd_rt_vk_import_buffer_host(VkrDevice* device, void* ptr, size_t size); +bool shd_rt_vk_can_import_host_memory(VkrDevice* device); +void shd_rt_vk_destroy_buffer(VkrBuffer* buffer); typedef struct VkrCommand_ VkrCommand; @@ -187,12 +187,12 @@ struct VkrCommand_ { VkQueryPool query_pool; }; -VkrCommand* vkr_begin_command(VkrDevice* device); -bool vkr_submit_command(VkrCommand* commands); -void vkr_destroy_command(VkrCommand* commands); -bool vkr_wait_completion(VkrCommand* cmd); +VkrCommand* shd_rt_vk_begin_command(VkrDevice* device); +bool shd_rt_vk_submit_command(VkrCommand* cmd); +void shd_rt_vk_destroy_command(VkrCommand* cmd); +bool shd_rt_vk_wait_completion(VkrCommand* cmd); -VkrCommand* vkr_launch_kernel(VkrDevice* device, Program* program, String entry_point, int dimx, int dimy, int dimz, int args_count, void** args, ExtraKernelOptions*); +VkrCommand* shd_rt_vk_launch_kernel(VkrDevice* device, Program* program, String entry_point, int dimx, int dimy, int dimz, int args_count, void** args, ExtraKernelOptions* options); typedef struct ProgramResourceInfo_ ProgramResourceInfo; struct ProgramResourceInfo_ { @@ -221,7 +221,7 @@ typedef struct { #define MAX_DESCRIPTOR_SETS 4 -VkDescriptorType as_to_descriptor_type(AddressSpace as); +VkDescriptorType shd_rt_vk_as_to_descriptor_type(AddressSpace as); struct VkrSpecProgram_ { SpecProgramKey key; @@ -248,8 +248,8 @@ struct VkrSpecProgram_ { VkDescriptorSet sets[MAX_DESCRIPTOR_SETS]; }; -VkrSpecProgram* get_specialized_program(Program*, String ep, VkrDevice*); -void destroy_specialized_program(VkrSpecProgram*); +VkrSpecProgram* shd_rt_vk_get_specialized_program(Program* program, String entry_point, VkrDevice* device); +void shd_rt_vk_destroy_specialized_program(VkrSpecProgram* spec); static inline void append_pnext(VkBaseOutStructure* s, void* n) { while (s->pNext != NULL) diff --git a/src/runtime/vulkan/vk_runtime_program.c b/src/runtime/vulkan/vk_runtime_program.c index fdab0e0bb..a60354969 100644 --- a/src/runtime/vulkan/vk_runtime_program.c +++ b/src/runtime/vulkan/vk_runtime_program.c @@ -33,7 +33,7 @@ static void add_binding(VkDescriptorSetLayoutCreateInfo* layout_create_info, Gro shd_growy_append_object(bindings_lists[set], binding); } -VkDescriptorType as_to_descriptor_type(AddressSpace as) { +VkDescriptorType shd_rt_vk_as_to_descriptor_type(AddressSpace as) { switch (as) { case AsUniform: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; case AsShaderStorageBufferObject: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; @@ -145,14 +145,14 @@ static bool extract_resources_layout(VkrSpecProgram* program, VkDescriptorSetLay } } - if (vkr_can_import_host_memory(program->device)) + if (shd_rt_vk_can_import_host_memory(program->device)) res_info->host_backed_allocation = true; else res_info->staging = calloc(1, res_info->size); VkDescriptorSetLayoutBinding vk_binding = { .binding = binding, - .descriptorType = as_to_descriptor_type(as), + .descriptorType = shd_rt_vk_as_to_descriptor_type(as), .descriptorCount = 1, .stageFlags = VK_SHADER_STAGE_ALL, .pImmutableSamplers = NULL, @@ -432,7 +432,7 @@ static void flush_staged_data(VkrSpecProgram* program) { for (size_t i = 0; i < program->resources.num_resources; i++) { ProgramResourceInfo* resource = program->resources.resources[i]; if (resource->staging) { - copy_to_buffer((Buffer*) resource->buffer, 0, resource->buffer, resource->size); + shd_rt_copy_to_buffer((Buffer*) resource->buffer, 0, resource->buffer, resource->size); free(resource->staging); } } @@ -443,18 +443,18 @@ static bool prepare_resources(VkrSpecProgram* program) { ProgramResourceInfo* resource = program->resources.resources[i]; if (resource->host_backed_allocation) { - assert(vkr_can_import_host_memory(program->device)); + assert(shd_rt_vk_can_import_host_memory(program->device)); resource->host_ptr = shd_alloc_aligned(resource->size, program->device->caps.properties.external_memory_host.minImportedHostPointerAlignment); - resource->buffer = vkr_import_buffer_host(program->device, resource->host_ptr, resource->size); + resource->buffer = shd_rt_vk_import_buffer_host(program->device, resource->host_ptr, resource->size); } else { - resource->buffer = vkr_allocate_buffer_device(program->device, resource->size); + resource->buffer = shd_rt_vk_allocate_buffer_device(program->device, resource->size); } if (resource->default_data) { - copy_to_buffer((Buffer*) resource->buffer, 0, resource->default_data, resource->size); + shd_rt_copy_to_buffer((Buffer*) resource->buffer, 0, resource->default_data, resource->size); } else { char* zeroes = calloc(1, resource->size); - copy_to_buffer((Buffer*) resource->buffer, 0, zeroes, resource->size); + shd_rt_copy_to_buffer((Buffer*) resource->buffer, 0, zeroes, resource->size); free(zeroes); } @@ -464,7 +464,7 @@ static bool prepare_resources(VkrSpecProgram* program) { dst = resource->parent->staging; } assert(dst); - *((uint64_t*) (dst + resource->offset)) = get_buffer_device_pointer((Buffer*) resource->buffer); + *((uint64_t*) (dst + resource->offset)) = shd_rt_get_buffer_device_pointer((Buffer*) resource->buffer); } } @@ -491,7 +491,7 @@ static VkrSpecProgram* create_specialized_program(SpecProgramKey key, VkrDevice* return spec_program; } -VkrSpecProgram* get_specialized_program(Program* program, String entry_point, VkrDevice* device) { +VkrSpecProgram* shd_rt_vk_get_specialized_program(Program* program, String entry_point, VkrDevice* device) { SpecProgramKey key = { .base = program, .entry_point = entry_point }; VkrSpecProgram** found = shd_dict_find_value(SpecProgramKey, VkrSpecProgram*, device->specialized_programs, key); if (found) @@ -502,7 +502,7 @@ VkrSpecProgram* get_specialized_program(Program* program, String entry_point, Vk return spec; } -void destroy_specialized_program(VkrSpecProgram* spec) { +void shd_rt_vk_destroy_specialized_program(VkrSpecProgram* spec) { vkDestroyPipeline(spec->device->device, spec->pipeline, NULL); for (size_t set = 0; set < MAX_DESCRIPTOR_SETS; set++) vkDestroyDescriptorSetLayout(spec->device->device, spec->set_layouts[set], NULL); @@ -515,7 +515,7 @@ void destroy_specialized_program(VkrSpecProgram* spec) { for (size_t i = 0; i < spec->resources.num_resources; i++) { ProgramResourceInfo* resource = spec->resources.resources[i]; if (resource->buffer) - vkr_destroy_buffer(resource->buffer); + shd_rt_vk_destroy_buffer(resource->buffer); if (resource->host_ptr && resource->host_backed_allocation) shd_free_aligned(resource->host_ptr); } diff --git a/zhady/shady.i b/zhady/shady.i index f2db06444..58d910071 100644 --- a/zhady/shady.i +++ b/zhady/shady.i @@ -11,6 +11,13 @@ * bb #include "shady/runtime.h" + +* d + +* r + +* runtime + #include "shady/driver.h" * mod