From 7d8c72feb8041a6757a9dacb4e9d8017a689bec4 Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 28 Dec 2024 19:03:56 +1100 Subject: replace memset --- pipeline.cpp | 2 +- qstd/memory.c | 6 ++++++ qstd/memory.h | 2 ++ video.cpp | 28 ++++++++++++++-------------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/pipeline.cpp b/pipeline.cpp index b0a88eb..88b2009 100644 --- a/pipeline.cpp +++ b/pipeline.cpp @@ -40,7 +40,7 @@ Render_Pass& Pipeline_Builder::build_rp() { void Pipeline_Builder::begin(Device* dev) { pip = (Pipeline*)arena_alloc(arena, sizeof *pip); - memset(pip, 0, sizeof *pip); + zero(pip, sizeof *pip); if (dev) { Texture_Id backbuffer_id = dev->get_backbuffer(); Texture& backbuffer = dev->get_texture(backbuffer_id); diff --git a/qstd/memory.c b/qstd/memory.c index 81795d6..b12ec75 100644 --- a/qstd/memory.c +++ b/qstd/memory.c @@ -11,6 +11,12 @@ int align_size(int s, int a) { return (s + (a - 1)) & -a; } +void zero(void* buf, int size) { + int i; + for (i = 0; i < size; i++) + ((uint8_t*)buf)[i] = 0; +} + static uintptr_t align_address( uintptr_t ad, size_t al diff --git a/qstd/memory.h b/qstd/memory.h index 842cb49..c723131 100644 --- a/qstd/memory.h +++ b/qstd/memory.h @@ -4,6 +4,8 @@ int aligned(const void* p, int a); int align_size(int s, int a); +void zero(void* buf, int size); + typedef struct Arena { char* buf; int size, ptr; diff --git a/video.cpp b/video.cpp index 10680d8..f20fdb8 100644 --- a/video.cpp +++ b/video.cpp @@ -2150,7 +2150,7 @@ void Pipeline_Vk::init_stages( &scope, sizeof *sis * count ); - memset(sis, 0, sizeof *sis * count); + zero(sis, sizeof *sis * count); for (i = 0, count = 0; i < shader_type_count; i++) { if (shader.modules[i]) { auto& si = sis[i]; @@ -2178,7 +2178,7 @@ void Pipeline_Vk::init_vertex_input( &scope, sizeof vi ); - memset(&vi, 0, sizeof vi); + zero(&vi, sizeof vi); vi.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; vi.vertexBindingDescriptionCount = vf.binding_count; vi.pVertexBindingDescriptions = vf.bindings; @@ -2201,7 +2201,7 @@ void Pipeline_Vk::init_input_assembly( (void)dev; (void)desc; (void)info; - memset(&ia, 0, sizeof ia); + zero(&ia, sizeof ia); ia.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; ia.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; info.pInputAssemblyState = &ia; @@ -2226,9 +2226,9 @@ void Pipeline_Vk::init_viewport( &scope, sizeof viewport ); - memset(&vi, 0, sizeof vi); - memset(&scissor, 0, sizeof scissor); - memset(&viewport, 0, sizeof viewport); + zero(&vi, sizeof vi); + zero(&scissor, sizeof scissor); + zero(&viewport, sizeof viewport); scissor.offset.x = desc.scissor[0]; scissor.offset.y = desc.scissor[1]; scissor.extent.width = desc.scissor[2]; @@ -2260,7 +2260,7 @@ void Pipeline_Vk::init_rasterisation( ); (void)dev; (void)desc; - memset(&ri, 0, sizeof ri); + zero(&ri, sizeof ri); ri.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; ri.depthClampEnable = VK_FALSE; ri.rasterizerDiscardEnable = VK_FALSE; @@ -2285,7 +2285,7 @@ void Pipeline_Vk::init_msaa( ); (void)dev; (void)desc; - memset(&mi, 0, sizeof mi); + zero(&mi, sizeof mi); mi.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; mi.sampleShadingEnable = VK_FALSE; mi.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; @@ -2305,7 +2305,7 @@ void Pipeline_Vk::init_depthstencil( ); (void)dev; (void)desc; - memset(&ds, 0, sizeof ds); + zero(&ds, sizeof ds); ds.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; ds.depthTestEnable = VK_FALSE; ds.depthWriteEnable = VK_FALSE; @@ -2333,8 +2333,8 @@ void Pipeline_Vk::init_blending( ); (void)dev; (void)desc; - memset(&bi, 0, sizeof bi); - memset(&abs, 0, sizeof abs); + zero(&bi, sizeof bi); + zero(&abs, sizeof abs); abs.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | @@ -2365,7 +2365,7 @@ void Pipeline_Vk::init_descriptors( count * sizeof *descs ); VkDescriptorSetLayoutCreateInfo di{}; - memset(descs, 0, count * sizeof *descs); + zero(descs, count * sizeof *descs); for (i = 0; i < count; i++) { int j, stage; auto& dst = descs[i]; @@ -2612,8 +2612,8 @@ void Vertex_Format_Vk::init( dev->heap, attr_count * sizeof *attrs ); - memset(bindings, 0, binding_count * sizeof *bindings); - memset(attrs, 0, attr_count * sizeof *attrs); + zero(bindings, binding_count * sizeof *bindings); + zero(attrs, attr_count * sizeof *attrs); for (i = 0; i < binding_count; i++) { auto& dst = bindings[i]; const auto& src = desc.bindings[i]; -- cgit v1.2.3-54-g00ecf