Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 12, 2025
1 parent 90416ce commit a1ddf40
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
28 changes: 14 additions & 14 deletions Backends/Graphics5/Metal/Sources/kope/metal/commandlist.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void kope_metal_command_list_destroy(kope_g5_command_list *list) {}

void kope_metal_command_list_begin_render_pass(kope_g5_command_list *list, const kope_g5_render_pass_parameters *parameters) {
id<MTLTexture> texture = (__bridge id<MTLTexture>)parameters->color_attachments[0].texture.texture->metal.texture;

MTLRenderPassDescriptor *render_pass_descriptor = [MTLRenderPassDescriptor renderPassDescriptor];
render_pass_descriptor.colorAttachments[0].texture = texture;
render_pass_descriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
Expand All @@ -44,10 +44,10 @@ void kope_metal_command_list_end_render_pass(kope_g5_command_list *list) {

void kope_metal_command_list_present(kope_g5_command_list *list) {
id<MTLCommandBuffer> command_buffer = (__bridge id<MTLCommandBuffer>)list->metal.command_buffer;

CAMetalLayer *metal_layer = getMetalLayer();
id<CAMetalDrawable> drawable = [metal_layer nextDrawable];

[command_buffer presentDrawable:drawable];
}

Expand All @@ -60,14 +60,14 @@ void kope_metal_command_list_set_index_buffer(kope_g5_command_list *list, kope_g
void kope_metal_command_list_set_vertex_buffer(kope_g5_command_list *list, uint32_t slot, kope_metal_buffer *buffer, uint64_t offset, uint64_t size,
uint64_t stride) {
id<MTLBuffer> metal_buffer = (__bridge id<MTLBuffer>)buffer->buffer;

id<MTLRenderCommandEncoder> render_command_encoder = (__bridge id<MTLRenderCommandEncoder>)list->metal.render_command_encoder;
[render_command_encoder setVertexBuffer:metal_buffer offset:offset atIndex:slot];
}

void kope_metal_command_list_set_render_pipeline(kope_g5_command_list *list, kope_metal_render_pipeline *pipeline) {
id<MTLRenderPipelineState> metal_pipeline = (__bridge id<MTLRenderPipelineState>)pipeline->pipeline;

id<MTLRenderCommandEncoder> render_command_encoder = (__bridge id<MTLRenderCommandEncoder>)list->metal.render_command_encoder;
[render_command_encoder setRenderPipelineState:metal_pipeline];
}
Expand All @@ -77,17 +77,17 @@ void kope_metal_command_list_draw(kope_g5_command_list *list, uint32_t vertex_co
void kope_metal_command_list_draw_indexed(kope_g5_command_list *list, uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t base_vertex,
uint32_t first_instance) {
id<MTLBuffer> index_buffer = (__bridge id<MTLBuffer>)list->metal.index_buffer;

id<MTLRenderCommandEncoder> render_command_encoder = (__bridge id<MTLRenderCommandEncoder>)list->metal.render_command_encoder;

[render_command_encoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle
indexCount:index_count
indexType:(list->metal.sixteen_bit_indices ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32)
indexBuffer:index_buffer
indexBufferOffset:first_index
instanceCount:instance_count
baseVertex:base_vertex
baseInstance:first_instance];
indexCount:index_count
indexType:list->metal.sixteen_bit_indices ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32
indexBuffer:index_buffer
indexBufferOffset:first_index
instanceCount:instance_count
baseVertex:base_vertex
baseInstance:first_instance];
}

void kope_metal_command_list_set_descriptor_table(kope_g5_command_list *list, uint32_t table_index, kope_metal_descriptor_set *set,
Expand Down
2 changes: 1 addition & 1 deletion Backends/Graphics5/Metal/Sources/kope/metal/device.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ kope_g5_texture_format kope_metal_device_framebuffer_format(kope_g5_device *devi
void kope_metal_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list) {
id<MTLCommandBuffer> command_buffer = (__bridge id<MTLCommandBuffer>)list->metal.command_buffer;
[command_buffer commit];

id<MTLCommandQueue> command_queue = (__bridge id<MTLCommandQueue>)list->metal.command_queue;
command_buffer = [command_queue commandBuffer];
list->metal.command_buffer = (__bridge_retained void *)[command_queue commandBuffer];
Expand Down
20 changes: 11 additions & 9 deletions Backends/Graphics5/Metal/Sources/kope/metal/pipeline.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@
#include <kinc/log.h>

void kope_metal_render_pipeline_init(kope_metal_device *device, kope_metal_render_pipeline *pipe, const kope_metal_render_pipeline_parameters *parameters) {
id vertex_function = [getMetalLibrary() newFunctionWithName:[NSString stringWithCString:parameters->vertex.shader.function_name encoding:NSUTF8StringEncoding]];
id fragment_function = [getMetalLibrary() newFunctionWithName:[NSString stringWithCString:parameters->fragment.shader.function_name encoding:NSUTF8StringEncoding]];

id vertex_function = [getMetalLibrary() newFunctionWithName:[NSString stringWithCString:parameters->vertex.shader.function_name
encoding:NSUTF8StringEncoding]];
id fragment_function = [getMetalLibrary() newFunctionWithName:[NSString stringWithCString:parameters->fragment.shader.function_name
encoding:NSUTF8StringEncoding]];

MTLRenderPipelineDescriptor *render_pipeline_descriptor = [[MTLRenderPipelineDescriptor alloc] init];
render_pipeline_descriptor.vertexFunction = vertex_function;
render_pipeline_descriptor.fragmentFunction = fragment_function;

// TODO

NSError *errors = nil;
MTLRenderPipelineReflection *reflection = nil;
id<MTLDevice> metal_device = (__bridge id<MTLDevice>)device->device;

pipe->pipeline = (__bridge_retained void *)[metal_device newRenderPipelineStateWithDescriptor:render_pipeline_descriptor
options:MTLPipelineOptionBufferTypeInfo
reflection:&reflection
error:&errors];
options:MTLPipelineOptionBufferTypeInfo
reflection:&reflection
error:&errors];
}

void kope_metal_render_pipeline_destroy(kope_metal_render_pipeline *pipe) {}
Expand Down

0 comments on commit a1ddf40

Please sign in to comment.