From 97b08b82c0211aa8e3fad97de5d080843fc52a7f Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Wed, 17 Jan 2024 16:57:11 +0100 Subject: [PATCH] [Metal] Blindly start fixing compute things while Xcode is updating --- .../Metal/Sources/kinc/backend/compute.h | 18 --- .../Sources/kinc/backend/graphics5/compute.h | 8 ++ .../{compute.m => graphics5/compute.m.h} | 106 ++---------------- 3 files changed, 15 insertions(+), 117 deletions(-) delete mode 100644 Backends/Graphics5/Metal/Sources/kinc/backend/compute.h create mode 100644 Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.h rename Backends/Graphics5/Metal/Sources/kinc/backend/{compute.m => graphics5/compute.m.h} (50%) diff --git a/Backends/Graphics5/Metal/Sources/kinc/backend/compute.h b/Backends/Graphics5/Metal/Sources/kinc/backend/compute.h deleted file mode 100644 index 7aa5bb812..000000000 --- a/Backends/Graphics5/Metal/Sources/kinc/backend/compute.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include - -typedef struct { - uint32_t _offset; -} kinc_compute_constant_location_impl_t; - -typedef struct { - uint32_t _index; -} kinc_compute_texture_unit_impl_t; - -typedef struct { - char name[1024]; - void *_function; - void *_pipeline; - void *_reflection; -} kinc_compute_shader_impl_t; diff --git a/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.h b/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.h new file mode 100644 index 000000000..a2ff02b6a --- /dev/null +++ b/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.h @@ -0,0 +1,8 @@ +#pragma once + +typedef struct kinc_g5_compute_shader_impl { + char name[1024]; + void *_function; + void *_pipeline; + void *_reflection; +} kinc_g5_compute_shader_impl; diff --git a/Backends/Graphics5/Metal/Sources/kinc/backend/compute.m b/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.m.h similarity index 50% rename from Backends/Graphics5/Metal/Sources/kinc/backend/compute.m rename to Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.m.h index 951b4a6c3..3b9aa387b 100644 --- a/Backends/Graphics5/Metal/Sources/kinc/backend/compute.m +++ b/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.m.h @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -7,43 +7,6 @@ id getMetalDevice(void); id getMetalLibrary(void); -#define constantsSize 1024 * 4 -static uint8_t *constantsMemory; - -static void setFloat(uint8_t *constants, uint32_t offset, uint32_t size, float value) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value; -} - -static void setFloat2(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; -} - -static void setFloat3(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2, float value3) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; - floats[2] = value3; -} - -static void setFloat4(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2, float value3, float value4) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; - floats[2] = value3; - floats[3] = value4; -} - static id commandQueue; static id commandBuffer; static id commandEncoder; @@ -64,7 +27,7 @@ void shutdownMetalCompute(void) { commandQueue = nil; } -void kinc_compute_shader_destroy(kinc_compute_shader_t *shader) { +void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader) { id function = (__bridge_transfer id)shader->impl._function; function = nil; shader->impl._function = NULL; @@ -78,7 +41,7 @@ void kinc_compute_shader_destroy(kinc_compute_shader_t *shader) { shader->impl._reflection = NULL; } -void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int length) { +void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *_data, int length) { shader->impl.name[0] = 0; { @@ -126,8 +89,8 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le shader->impl._reflection = (__bridge_retained void *)reflection; } -kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_constant_location_t location; +kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_location(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_constant_location_t location; location.impl._offset = -1; MTLComputePipelineReflection *reflection = (__bridge MTLComputePipelineReflection *)shader->impl._reflection; @@ -150,8 +113,8 @@ kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_ return location; } -kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_texture_unit_t unit; +kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_texture_unit_t unit; unit.impl._index = -1; MTLComputePipelineReflection *reflection = (__bridge MTLComputePipelineReflection *)shader->impl._reflection; @@ -164,61 +127,6 @@ kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_sh return unit; } -void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value) {} - -void kinc_compute_set_int(kinc_compute_constant_location_t location, int value) {} - -void kinc_compute_set_float(kinc_compute_constant_location_t location, float value) { - setFloat(constantsMemory, location.impl._offset, 4, value); -} - -void kinc_compute_set_float2(kinc_compute_constant_location_t location, float value1, float value2) { - setFloat2(constantsMemory, location.impl._offset, 4 * 2, value1, value2); -} - -void kinc_compute_set_float3(kinc_compute_constant_location_t location, float value1, float value2, float value3) { - setFloat3(constantsMemory, location.impl._offset, 4 * 3, value1, value2, value3); -} - -void kinc_compute_set_float4(kinc_compute_constant_location_t location, float value1, float value2, float value3, float value4) { - setFloat4(constantsMemory, location.impl._offset, 4 * 4, value1, value2, value3, value4); -} - -void kinc_compute_set_floats(kinc_compute_constant_location_t location, float *values, int count) {} - -void kinc_compute_set_matrix4(kinc_compute_constant_location_t location, kinc_matrix4x4_t *value) {} - -void kinc_compute_set_matrix3(kinc_compute_constant_location_t location, kinc_matrix3x3_t *value) {} - -void kinc_compute_set_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture, kinc_compute_access_t access) { - id tex = (__bridge id)texture->impl._texture.impl._tex; - [commandEncoder setTexture:tex atIndex:unit.impl._index]; -} - -void kinc_compute_set_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *texture, kinc_compute_access_t access) {} - -void kinc_compute_set_sampled_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture) {} - -void kinc_compute_set_sampled_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target) {} - -void kinc_compute_set_sampled_depth_from_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target) {} - -void kinc_compute_set_texture_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} - -void kinc_compute_set_texture3d_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} - -void kinc_compute_set_texture_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture3d_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} - -void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} - void kinc_compute_set_shader(kinc_compute_shader_t *shader) { id pipeline = (__bridge id)shader->impl._pipeline; [commandEncoder setComputePipelineState:pipeline];