diff --git a/src/draw_metal.m b/src/draw_metal.m index fe5d9b2..44900b7 100644 --- a/src/draw_metal.m +++ b/src/draw_metal.m @@ -1,6 +1,6 @@ #include "draw.h" -#include "metalShader.h" #include "metal_shader_types.h" +#include "metalShader.h" #include "maths.h" #include @@ -33,7 +33,7 @@ @end #define DRAWLIST_CHUNK_SIZE 480 -#define DRAWLIST_INIT_SIZE (DRAWLIST_CHUNK_SIZE) +#define DRAWLIST_INIT_SIZE (DRAWLIST_CHUNK_SIZE * 3) @implementation MetalRenderer { @@ -43,7 +43,7 @@ CAMetalLayer* _layer; id _queue; MTLRenderPassDescriptor* _passDesc; - id _pso; // gonna fine u on the belgrave & lillydale line + id _pso; MTLViewport _viewport; vector_float4 _drawColourF; @@ -74,9 +74,11 @@ // Get Metal device #if 1 + // Default device _dev = MTLCreateSystemDefaultDevice(); fprintf(stderr, "Default MTL device \"%s\"\n", [_dev.name UTF8String]); #else + // Non-low power device NSArray>* devices = MTLCopyAllDevices(); for (id i in devices) { @@ -98,13 +100,13 @@ _passDesc.colorAttachments[0].storeAction = MTLStoreActionStore; [self setClear:self.drawColour]; // passDesc.colorAttachments[0].clearColor = curColour - // Compile shady bois - __autoreleasing NSError* booboo = nil; + // Compile shaders + __autoreleasing NSError* err = nil; dispatch_data_t shaderData = dispatch_data_create(shader_metallib, SHADER_METALLIB_SIZE, nil, nil); - id lib = [_dev newLibraryWithData:shaderData error:&booboo]; + id lib = [_dev newLibraryWithData:shaderData error:&err]; if (!lib) { - fprintf(stderr, "Metal shader compilation failed:\n%s\n", [[booboo localizedDescription] UTF8String]); + fprintf(stderr, "Metal shader compilation failed:\n%s\n", [[err localizedDescription] UTF8String]); return nil; } id vertPrg = [lib newFunctionWithName:@"vertexMain"]; @@ -115,10 +117,10 @@ pipeDesc.vertexFunction = vertPrg; pipeDesc.fragmentFunction = fragPrg; pipeDesc.colorAttachments[0].pixelFormat = _layer.pixelFormat; - _pso = [_dev newRenderPipelineStateWithDescriptor:pipeDesc error:&booboo]; + _pso = [_dev newRenderPipelineStateWithDescriptor:pipeDesc error:&err]; if (!_pso) { - fprintf(stderr, "Your Myki has expired and u have been slapped with a $237 fine: %s\n", [[booboo localizedDescription] UTF8String]); + fprintf(stderr, "Pipeline state creation failed: %s\n", [[err localizedDescription] UTF8String]); return nil; } [pipeDesc release]; @@ -149,7 +151,6 @@ // (Re)allocate and return new reserve size unsigned newReserve = newCapacity * nsz; *buf = realloc(*buf, newReserve); - printf("buffer %p %u -> %u\n", *buf, reserve, newReserve); return newReserve; } @@ -158,7 +159,6 @@ if (*buf && length <= [*buf length]) return; - printf("mtlBuf %p %lu -> %u\n", (void*)buf, (unsigned long)[*buf length], length); id new = [_dev newBufferWithLength:length options:MTLResourceStorageModeManaged]; if (*buf) { @@ -304,9 +304,8 @@ } [enc endEncoding]; - [cmdBuf presentDrawable:rt]; // u go to software premieres - [cmdBuf commit]; // is that linus torvolds? - // hear songs on pandora radiowo + [cmdBuf presentDrawable:rt]; + [cmdBuf commit]; [self clearVerticesAndIndices]; } diff --git a/src/draw_opengl_core.c b/src/draw_opengl_core.c index 0ec5132..fd4816a 100644 --- a/src/draw_opengl_core.c +++ b/src/draw_opengl_core.c @@ -11,8 +11,7 @@ typedef struct { float x, y; } vertex; enum { ATTRIB_VERTPOS, NUM_ATTRIBS }; static const char* const attribNames[] = { - [ATTRIB_VERTPOS] = "inPos", -// [ATTRIB_COLOUR] = "inColour" + [ATTRIB_VERTPOS] = "inPos" }; @@ -284,7 +283,7 @@ void SetDrawViewport(size size) static int drawCount = 0; -static void FlushDrawBuffers() +static void FlushDrawBuffers(void) { if (!drawListCount) return; @@ -310,7 +309,7 @@ static void UnpackColour(GLfloat* out) out[3] = (GLfloat)((colour & 0x000000FF)) * mul; } -static void UpdateDrawColour() +static void UpdateDrawColour(void) { FlushDrawBuffers(); // Flush anything that might still be in the buffer GLfloat draw[4]; UnpackColour(draw); // Convert packed RGBA32 to float