Skip to content

Commit

Permalink
[Metal] Blindly start fixing compute things while Xcode is updating
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Jan 17, 2024
1 parent b2e3c89 commit 97b08b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 117 deletions.
18 changes: 0 additions & 18 deletions Backends/Graphics5/Metal/Sources/kinc/backend/compute.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <kinc/compute/compute.h>
#include <kinc/graphics5/compute.h>
#include <kinc/graphics4/texture.h>
#include <kinc/math/core.h>

Expand All @@ -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<MTLCommandQueue> commandQueue;
static id<MTLCommandBuffer> commandBuffer;
static id<MTLComputeCommandEncoder> commandEncoder;
Expand All @@ -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<MTLFunction> function = (__bridge_transfer id<MTLFunction>)shader->impl._function;
function = nil;
shader->impl._function = NULL;
Expand All @@ -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;

{
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<MTLTexture> tex = (__bridge id<MTLTexture>)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<MTLComputePipelineState> pipeline = (__bridge id<MTLComputePipelineState>)shader->impl._pipeline;
[commandEncoder setComputePipelineState:pipeline];
Expand Down

0 comments on commit 97b08b8

Please sign in to comment.