diff --git a/base/sources/backends/direct3d12_gpu.c b/base/sources/backends/direct3d12_gpu.c index e205d266..51deef73 100644 --- a/base/sources/backends/direct3d12_gpu.c +++ b/base/sources/backends/direct3d12_gpu.c @@ -384,14 +384,14 @@ void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t *depth gpu_scissor(0, 0, target->width, target->height); if (flags & GPU_CLEAR_COLOR) { - float clearColor[] = {((color & 0x00ff0000) >> 16) / 255.0f, - ((color & 0x0000ff00) >> 8) / 255.0f, - (color & 0x000000ff) / 255.0f, - ((color & 0xff000000) >> 24) / 255.0f}; + float clear_color[] = {((color & 0x00ff0000) >> 16) / 255.0f, + ((color & 0x0000ff00) >> 8) / 255.0f, + (color & 0x000000ff) / 255.0f, + ((color & 0xff000000) >> 24) / 255.0f}; D3D12_CPU_DESCRIPTOR_HANDLE handle; target->impl.rtv_descriptor_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart(target->impl.rtv_descriptor_heap, &handle); - command_list->lpVtbl->ClearRenderTargetView(command_list, handle, clearColor, 0, NULL); + command_list->lpVtbl->ClearRenderTargetView(command_list, handle, clear_color, 0, NULL); } if (flags & GPU_CLEAR_DEPTH && depth_buffer != NULL) { D3D12_CPU_DESCRIPTOR_HANDLE handle; @@ -672,10 +672,6 @@ void gpu_set_texture(int unit, gpu_texture_t *texture) { current_textures[unit] = texture; } -void gpu_pipeline_init(gpu_pipeline_t *pipe) { - gpu_internal_pipeline_init(pipe); -} - void gpu_pipeline_destroy(gpu_pipeline_t *pipe) { if (pipe->impl.pso != NULL) { pipe->impl.pso->lpVtbl->Release(pipe->impl.pso); diff --git a/base/sources/backends/metal_gpu.h b/base/sources/backends/metal_gpu.h index da16ed3d..ca51827e 100644 --- a/base/sources/backends/metal_gpu.h +++ b/base/sources/backends/metal_gpu.h @@ -1,10 +1,6 @@ #pragma once -struct gpu_shader; - typedef struct { - struct gpu_shader *vertex_shader; - struct gpu_shader *fragment_shader; void *_pipeline; void *_depth; } gpu_pipeline_impl_t; diff --git a/base/sources/backends/metal_gpu.m b/base/sources/backends/metal_gpu.m index 02e277e1..897ff647 100644 --- a/base/sources/backends/metal_gpu.m +++ b/base/sources/backends/metal_gpu.m @@ -395,11 +395,6 @@ void gpu_set_texture(int unit, gpu_texture_t *texture) { [command_encoder useResource:tex usage:MTLResourceUsageRead stages:MTLRenderStageVertex|MTLRenderStageFragment]; } -void gpu_pipeline_init(gpu_pipeline_t *pipeline) { - memset(&pipeline->impl, 0, sizeof(pipeline->impl)); - gpu_internal_pipeline_init(pipeline); -} - void gpu_pipeline_destroy(gpu_pipeline_t *pipeline) { id pipe = (__bridge_transfer id)pipeline->impl._pipeline; pipe = nil; @@ -424,77 +419,77 @@ void gpu_pipeline_compile(gpu_pipeline_t *pipeline) { pipeline->fragment_shader->impl.mtl_function = (__bridge_retained void *)[library newFunctionWithName:[NSString stringWithCString:pipeline->fragment_shader->impl.name encoding:NSUTF8StringEncoding]]; assert(pipeline->fragment_shader->impl.mtl_function); - MTLRenderPipelineDescriptor *renderPipelineDesc = [[MTLRenderPipelineDescriptor alloc] init]; - renderPipelineDesc.vertexFunction = (__bridge id)pipeline->vertex_shader->impl.mtl_function; - renderPipelineDesc.fragmentFunction = (__bridge id)pipeline->fragment_shader->impl.mtl_function; + MTLRenderPipelineDescriptor *render_pipeline_desc = [[MTLRenderPipelineDescriptor alloc] init]; + render_pipeline_desc.vertexFunction = (__bridge id)pipeline->vertex_shader->impl.mtl_function; + render_pipeline_desc.fragmentFunction = (__bridge id)pipeline->fragment_shader->impl.mtl_function; for (int i = 0; i < pipeline->color_attachment_count; ++i) { - renderPipelineDesc.colorAttachments[i].pixelFormat = convert_texture_format(pipeline->color_attachment[i]); - renderPipelineDesc.colorAttachments[i].blendingEnabled = + render_pipeline_desc.colorAttachments[i].pixelFormat = convert_texture_format(pipeline->color_attachment[i]); + render_pipeline_desc.colorAttachments[i].blendingEnabled = pipeline->blend_source != GPU_BLEND_ONE || pipeline->blend_destination != GPU_BLEND_ZERO || pipeline->alpha_blend_source != GPU_BLEND_ONE || pipeline->alpha_blend_destination != GPU_BLEND_ZERO; - renderPipelineDesc.colorAttachments[i].sourceRGBBlendFactor = convert_blending_factor(pipeline->blend_source); - renderPipelineDesc.colorAttachments[i].destinationRGBBlendFactor = convert_blending_factor(pipeline->blend_destination); - renderPipelineDesc.colorAttachments[i].rgbBlendOperation = MTLBlendOperationAdd; - renderPipelineDesc.colorAttachments[i].sourceAlphaBlendFactor = convert_blending_factor(pipeline->alpha_blend_source); - renderPipelineDesc.colorAttachments[i].destinationAlphaBlendFactor = convert_blending_factor(pipeline->alpha_blend_destination); - renderPipelineDesc.colorAttachments[i].alphaBlendOperation = MTLBlendOperationAdd; - renderPipelineDesc.colorAttachments[i].writeMask = + render_pipeline_desc.colorAttachments[i].sourceRGBBlendFactor = convert_blending_factor(pipeline->blend_source); + render_pipeline_desc.colorAttachments[i].destinationRGBBlendFactor = convert_blending_factor(pipeline->blend_destination); + render_pipeline_desc.colorAttachments[i].rgbBlendOperation = MTLBlendOperationAdd; + render_pipeline_desc.colorAttachments[i].sourceAlphaBlendFactor = convert_blending_factor(pipeline->alpha_blend_source); + render_pipeline_desc.colorAttachments[i].destinationAlphaBlendFactor = convert_blending_factor(pipeline->alpha_blend_destination); + render_pipeline_desc.colorAttachments[i].alphaBlendOperation = MTLBlendOperationAdd; + render_pipeline_desc.colorAttachments[i].writeMask = (pipeline->color_write_mask_red[i] ? MTLColorWriteMaskRed : 0) | (pipeline->color_write_mask_green[i] ? MTLColorWriteMaskGreen : 0) | (pipeline->color_write_mask_blue[i] ? MTLColorWriteMaskBlue : 0) | (pipeline->color_write_mask_alpha[i] ? MTLColorWriteMaskAlpha : 0); } - renderPipelineDesc.depthAttachmentPixelFormat = pipeline->depth_attachment_bits > 0 ? MTLPixelFormatDepth32Float : MTLPixelFormatInvalid; + render_pipeline_desc.depthAttachmentPixelFormat = pipeline->depth_attachment_bits > 0 ? MTLPixelFormatDepth32Float : MTLPixelFormatInvalid; float offset = 0; - MTLVertexDescriptor *vertexDescriptor = [[MTLVertexDescriptor alloc] init]; + MTLVertexDescriptor *vertex_descriptor = [[MTLVertexDescriptor alloc] init]; for (int i = 0; i < pipeline->input_layout->size; ++i) { - vertexDescriptor.attributes[i].bufferIndex = 0; - vertexDescriptor.attributes[i].offset = offset; + vertex_descriptor.attributes[i].bufferIndex = 0; + vertex_descriptor.attributes[i].offset = offset; offset += gpu_vertex_data_size(pipeline->input_layout->elements[i].data); switch (pipeline->input_layout->elements[i].data) { case GPU_VERTEX_DATA_F32_1X: - vertexDescriptor.attributes[i].format = MTLVertexFormatFloat; + vertex_descriptor.attributes[i].format = MTLVertexFormatFloat; break; case GPU_VERTEX_DATA_F32_2X: - vertexDescriptor.attributes[i].format = MTLVertexFormatFloat2; + vertex_descriptor.attributes[i].format = MTLVertexFormatFloat2; break; case GPU_VERTEX_DATA_F32_3X: - vertexDescriptor.attributes[i].format = MTLVertexFormatFloat3; + vertex_descriptor.attributes[i].format = MTLVertexFormatFloat3; break; case GPU_VERTEX_DATA_F32_4X: - vertexDescriptor.attributes[i].format = MTLVertexFormatFloat4; + vertex_descriptor.attributes[i].format = MTLVertexFormatFloat4; break; case GPU_VERTEX_DATA_I16_2X_NORM: - vertexDescriptor.attributes[i].format = MTLVertexFormatShort2Normalized; + vertex_descriptor.attributes[i].format = MTLVertexFormatShort2Normalized; break; case GPU_VERTEX_DATA_I16_4X_NORM: - vertexDescriptor.attributes[i].format = MTLVertexFormatShort4Normalized; + vertex_descriptor.attributes[i].format = MTLVertexFormatShort4Normalized; break; } } - vertexDescriptor.layouts[0].stride = offset; - vertexDescriptor.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex; + vertex_descriptor.layouts[0].stride = offset; + vertex_descriptor.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex; - renderPipelineDesc.vertexDescriptor = vertexDescriptor; + render_pipeline_desc.vertexDescriptor = vertex_descriptor; NSError *errors = nil; MTLRenderPipelineReflection *reflection = nil; pipeline->impl._pipeline = (__bridge_retained void *)[ - device newRenderPipelineStateWithDescriptor:renderPipelineDesc + device newRenderPipelineStateWithDescriptor:render_pipeline_desc options:MTLPipelineOptionBufferTypeInfo reflection:&reflection error:&errors]; - MTLDepthStencilDescriptor *depthStencilDescriptor = [MTLDepthStencilDescriptor new]; - depthStencilDescriptor.depthCompareFunction = convert_compare_mode(pipeline->depth_mode); - depthStencilDescriptor.depthWriteEnabled = pipeline->depth_write; - pipeline->impl._depth = (__bridge_retained void *)[device newDepthStencilStateWithDescriptor:depthStencilDescriptor]; + MTLDepthStencilDescriptor *depth_descriptor = [MTLDepthStencilDescriptor new]; + depth_descriptor.depthCompareFunction = convert_compare_mode(pipeline->depth_mode); + depth_descriptor.depthWriteEnabled = pipeline->depth_write; + pipeline->impl._depth = (__bridge_retained void *)[device newDepthStencilStateWithDescriptor:depth_descriptor]; } void gpu_shader_destroy(gpu_shader_t *shader) { diff --git a/base/sources/backends/vulkan_gpu.c b/base/sources/backends/vulkan_gpu.c index 817422d3..3d114e3c 100644 --- a/base/sources/backends/vulkan_gpu.c +++ b/base/sources/backends/vulkan_gpu.c @@ -1120,14 +1120,14 @@ void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t * dept int count = 0; VkClearAttachment attachments[2]; if (flags & GPU_CLEAR_COLOR) { - VkClearColorValue clearColor = {0}; - clearColor.float32[0] = ((color & 0x00ff0000) >> 16) / 255.0f; - clearColor.float32[1] = ((color & 0x0000ff00) >> 8) / 255.0f; - clearColor.float32[2] = (color & 0x000000ff) / 255.0f; - clearColor.float32[3] = ((color & 0xff000000) >> 24) / 255.0f; + VkClearColorValue clear_color = {0}; + clear_color.float32[0] = ((color & 0x00ff0000) >> 16) / 255.0f; + clear_color.float32[1] = ((color & 0x0000ff00) >> 8) / 255.0f; + clear_color.float32[2] = (color & 0x000000ff) / 255.0f; + clear_color.float32[3] = ((color & 0xff000000) >> 24) / 255.0f; attachments[count].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; attachments[count].colorAttachment = 0; - attachments[count].clearValue.color = clearColor; + attachments[count].clearValue.color = clear_color; count++; } if (flags & GPU_CLEAR_DEPTH) { @@ -1136,7 +1136,7 @@ void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t * dept attachments[count].clearValue.depthStencil.stencil = 0; count++; } - VkClearRect clearRect = { + VkClearRect clear_rect = { .rect.offset.x = 0, .rect.offset.y = 0, .rect.extent.width = targets[0]->width, @@ -1144,7 +1144,7 @@ void gpu_begin_internal(gpu_texture_t **targets, int count, gpu_texture_t * dept .baseArrayLayer = 0, .layerCount = 1, }; - vkCmdClearAttachments(command_buffer, count, attachments, 1, &clearRect); + vkCmdClearAttachments(command_buffer, count, attachments, 1, &clear_rect); } } @@ -1421,10 +1421,6 @@ void gpu_set_texture(int unit, gpu_texture_t *texture) { current_textures[unit] = texture; } -void gpu_pipeline_init(gpu_pipeline_t *pipeline) { - gpu_internal_pipeline_init(pipeline); -} - void gpu_pipeline_destroy(gpu_pipeline_t *pipeline) { vkDestroyPipeline(device, pipeline->impl.pipeline, NULL); vkDestroyPipelineLayout(device, pipeline->impl.pipeline_layout, NULL); diff --git a/base/sources/backends/webgpu_gpu.c b/base/sources/backends/webgpu_gpu.c index ffcbe578..50439b19 100644 --- a/base/sources/backends/webgpu_gpu.c +++ b/base/sources/backends/webgpu_gpu.c @@ -147,10 +147,6 @@ void gpu_render_target_init(gpu_texture_t *target, int width, int height, gpu_te void gpu_render_target_init_framebuffer(gpu_texture_t *target, int width, int height, gpu_texture_format_t format) {} -void gpu_pipeline_init(gpu_pipeline_t *pipe) { - gpu_internal_pipeline_init(pipe); -} - void gpu_pipeline_compile(gpu_pipeline_t *pipe) { WGPUColorTargetState csDesc; memset(&csDesc, 0, sizeof(csDesc)); diff --git a/base/sources/iron_draw.c b/base/sources/iron_draw.c index 1d4c58a9..2901ec00 100644 --- a/base/sources/iron_draw.c +++ b/base/sources/iron_draw.c @@ -512,16 +512,14 @@ bool draw_font_get_baked_quad(draw_font_t *font, int size, draw_font_aligned_qua void draw_string(const char *text, float x, float y) { draw_font_image_t *img = draw_font_get_image_internal(draw_font, draw_font_size); - gpu_texture_t *tex = img->tex; - float xpos = x; float ypos = y + img->baseline; draw_font_aligned_quad_t q; - // gpu_set_pipeline(draw_custom_pipeline != NULL ? draw_custom_pipeline : _draw_current != NULL ? &text_pipeline_rt : &text_pipeline); - // gpu_set_vertex_buffer(&rect_vertex_buffer); - // gpu_set_index_buffer(&rect_index_buffer); - // gpu_set_texture(text_tex_unit, tex); + gpu_set_pipeline(draw_custom_pipeline != NULL ? draw_custom_pipeline : _draw_current != NULL ? &text_pipeline_rt : &text_pipeline); + gpu_set_vertex_buffer(&rect_vertex_buffer); + gpu_set_index_buffer(&rect_index_buffer); + gpu_set_texture(text_tex_unit, img->tex); for (int i = 0; text[i] != 0; ) { int l = 0; @@ -530,17 +528,8 @@ void draw_string(const char *text, float x, float y) { if (draw_font_get_baked_quad(draw_font, draw_font_size, &q, codepoint, xpos, ypos)) { xpos += q.xadvance; - - // - gpu_set_pipeline(draw_custom_pipeline != NULL ? draw_custom_pipeline : _draw_current != NULL ? &text_pipeline_rt : &text_pipeline); - gpu_set_vertex_buffer(&rect_vertex_buffer); - gpu_set_index_buffer(&rect_index_buffer); - gpu_set_texture(text_tex_unit, tex); - // - gpu_set_float4(text_pos_loc, q.x0 / vw(), q.y0 / vh(), (q.x1 - q.x0) / vw(), (q.y1 - q.y0) / vh()); gpu_set_float4(text_tex_loc, q.s0, q.t0, q.s1 - q.s0, q.t1 - q.t0); - gpu_set_matrix4(text_p_loc, draw_projection_matrix); gpu_set_float4(text_col_loc, _draw_color_r(draw_color) / 255.0, _draw_color_g(draw_color) / 255.0, _draw_color_b(draw_color) / 255.0, _draw_color_a(draw_color) / 255.0); gpu_draw(); diff --git a/base/sources/iron_gpu.c b/base/sources/iron_gpu.c index 3a391bf6..9d0022df 100644 --- a/base/sources/iron_gpu.c +++ b/base/sources/iron_gpu.c @@ -223,7 +223,7 @@ void gpu_vertex_structure_add(gpu_vertex_structure_t *structure, const char *nam structure->size++; } -void gpu_internal_pipeline_init(gpu_pipeline_t *pipe) { +void gpu_pipeline_init(gpu_pipeline_t *pipe) { pipe->input_layout = NULL; pipe->vertex_shader = NULL; pipe->fragment_shader = NULL; diff --git a/base/sources/iron_gpu.h b/base/sources/iron_gpu.h index 902e88ba..04f3c916 100644 --- a/base/sources/iron_gpu.h +++ b/base/sources/iron_gpu.h @@ -184,7 +184,6 @@ void *gpu_index_buffer_lock(gpu_buffer_t *buffer); void gpu_index_buffer_unlock(gpu_buffer_t *buffer); void gpu_pipeline_init(gpu_pipeline_t *pipeline); -void gpu_internal_pipeline_init(gpu_pipeline_t *pipeline); void gpu_pipeline_destroy(gpu_pipeline_t *pipeline); void gpu_pipeline_compile(gpu_pipeline_t *pipeline); void gpu_shader_init(gpu_shader_t *shader, const void *source, size_t length, gpu_shader_type_t type);