minor cleanup

This commit is contained in:
2023-06-28 19:54:41 +10:00
parent b72891a283
commit 7db7f91563
2 changed files with 16 additions and 18 deletions

View File

@ -1,6 +1,6 @@
#include "draw.h" #include "draw.h"
#include "metalShader.h"
#include "metal_shader_types.h" #include "metal_shader_types.h"
#include "metalShader.h"
#include "maths.h" #include "maths.h"
#include <SDL_metal.h> #include <SDL_metal.h>
@ -33,7 +33,7 @@
@end @end
#define DRAWLIST_CHUNK_SIZE 480 #define DRAWLIST_CHUNK_SIZE 480
#define DRAWLIST_INIT_SIZE (DRAWLIST_CHUNK_SIZE) #define DRAWLIST_INIT_SIZE (DRAWLIST_CHUNK_SIZE * 3)
@implementation MetalRenderer @implementation MetalRenderer
{ {
@ -43,7 +43,7 @@
CAMetalLayer* _layer; CAMetalLayer* _layer;
id<MTLCommandQueue> _queue; id<MTLCommandQueue> _queue;
MTLRenderPassDescriptor* _passDesc; MTLRenderPassDescriptor* _passDesc;
id<MTLRenderPipelineState> _pso; // gonna fine u on the belgrave & lillydale line id<MTLRenderPipelineState> _pso;
MTLViewport _viewport; MTLViewport _viewport;
vector_float4 _drawColourF; vector_float4 _drawColourF;
@ -74,9 +74,11 @@
// Get Metal device // Get Metal device
#if 1 #if 1
// Default device
_dev = MTLCreateSystemDefaultDevice(); _dev = MTLCreateSystemDefaultDevice();
fprintf(stderr, "Default MTL device \"%s\"\n", [_dev.name UTF8String]); fprintf(stderr, "Default MTL device \"%s\"\n", [_dev.name UTF8String]);
#else #else
// Non-low power device
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices(); NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
for (id<MTLDevice> i in devices) for (id<MTLDevice> i in devices)
{ {
@ -98,13 +100,13 @@
_passDesc.colorAttachments[0].storeAction = MTLStoreActionStore; _passDesc.colorAttachments[0].storeAction = MTLStoreActionStore;
[self setClear:self.drawColour]; // passDesc.colorAttachments[0].clearColor = curColour [self setClear:self.drawColour]; // passDesc.colorAttachments[0].clearColor = curColour
// Compile shady bois // Compile shaders
__autoreleasing NSError* booboo = nil; __autoreleasing NSError* err = nil;
dispatch_data_t shaderData = dispatch_data_create(shader_metallib, SHADER_METALLIB_SIZE, nil, nil); dispatch_data_t shaderData = dispatch_data_create(shader_metallib, SHADER_METALLIB_SIZE, nil, nil);
id<MTLLibrary> lib = [_dev newLibraryWithData:shaderData error:&booboo]; id<MTLLibrary> lib = [_dev newLibraryWithData:shaderData error:&err];
if (!lib) 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; return nil;
} }
id<MTLFunction> vertPrg = [lib newFunctionWithName:@"vertexMain"]; id<MTLFunction> vertPrg = [lib newFunctionWithName:@"vertexMain"];
@ -115,10 +117,10 @@
pipeDesc.vertexFunction = vertPrg; pipeDesc.vertexFunction = vertPrg;
pipeDesc.fragmentFunction = fragPrg; pipeDesc.fragmentFunction = fragPrg;
pipeDesc.colorAttachments[0].pixelFormat = _layer.pixelFormat; pipeDesc.colorAttachments[0].pixelFormat = _layer.pixelFormat;
_pso = [_dev newRenderPipelineStateWithDescriptor:pipeDesc error:&booboo]; _pso = [_dev newRenderPipelineStateWithDescriptor:pipeDesc error:&err];
if (!_pso) 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; return nil;
} }
[pipeDesc release]; [pipeDesc release];
@ -149,7 +151,6 @@
// (Re)allocate and return new reserve size // (Re)allocate and return new reserve size
unsigned newReserve = newCapacity * nsz; unsigned newReserve = newCapacity * nsz;
*buf = realloc(*buf, newReserve); *buf = realloc(*buf, newReserve);
printf("buffer %p %u -> %u\n", *buf, reserve, newReserve);
return newReserve; return newReserve;
} }
@ -158,7 +159,6 @@
if (*buf && length <= [*buf length]) if (*buf && length <= [*buf length])
return; return;
printf("mtlBuf %p %lu -> %u\n", (void*)buf, (unsigned long)[*buf length], length);
id<MTLBuffer> new = [_dev newBufferWithLength:length options:MTLResourceStorageModeManaged]; id<MTLBuffer> new = [_dev newBufferWithLength:length options:MTLResourceStorageModeManaged];
if (*buf) if (*buf)
{ {
@ -304,9 +304,8 @@
} }
[enc endEncoding]; [enc endEncoding];
[cmdBuf presentDrawable:rt]; // u go to software premieres [cmdBuf presentDrawable:rt];
[cmdBuf commit]; // is that linus torvolds? [cmdBuf commit];
// hear songs on pandora radiowo
[self clearVerticesAndIndices]; [self clearVerticesAndIndices];
} }

View File

@ -11,8 +11,7 @@ typedef struct { float x, y; } vertex;
enum { ATTRIB_VERTPOS, NUM_ATTRIBS }; enum { ATTRIB_VERTPOS, NUM_ATTRIBS };
static const char* const attribNames[] = static const char* const attribNames[] =
{ {
[ATTRIB_VERTPOS] = "inPos", [ATTRIB_VERTPOS] = "inPos"
// [ATTRIB_COLOUR] = "inColour"
}; };
@ -284,7 +283,7 @@ void SetDrawViewport(size size)
static int drawCount = 0; static int drawCount = 0;
static void FlushDrawBuffers() static void FlushDrawBuffers(void)
{ {
if (!drawListCount) if (!drawListCount)
return; return;
@ -310,7 +309,7 @@ static void UnpackColour(GLfloat* out)
out[3] = (GLfloat)((colour & 0x000000FF)) * mul; out[3] = (GLfloat)((colour & 0x000000FF)) * mul;
} }
static void UpdateDrawColour() static void UpdateDrawColour(void)
{ {
FlushDrawBuffers(); // Flush anything that might still be in the buffer FlushDrawBuffers(); // Flush anything that might still be in the buffer
GLfloat draw[4]; UnpackColour(draw); // Convert packed RGBA32 to float GLfloat draw[4]; UnpackColour(draw); // Convert packed RGBA32 to float