summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-28 19:03:56 +1100
committerquou <quou@disroot.org>2024-12-28 19:03:56 +1100
commit7d8c72feb8041a6757a9dacb4e9d8017a689bec4 (patch)
tree95bcd40f12c2eef3640bee5ee032705db774f230
parentd7a511e6a4cea46e1de05f868e7eb81ebdee7b80 (diff)
replace memset
-rw-r--r--pipeline.cpp2
-rw-r--r--qstd/memory.c6
-rw-r--r--qstd/memory.h2
-rw-r--r--video.cpp28
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];