add some utilities for double buffering
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "utils/gryphn_error_code.h"
|
#include "utils/gryphn_error_code.h"
|
||||||
|
#include "utils/lists/gryphn_array_list.h"
|
||||||
#include <core/gryphn_handles.h>
|
#include <core/gryphn_handles.h>
|
||||||
|
|
||||||
typedef enum gnIndexType {
|
typedef enum gnIndexType {
|
||||||
@@ -30,8 +31,11 @@ struct gnBuffer_t {
|
|||||||
gnBufferInfo info;
|
gnBufferInfo info;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
typedef void* gnBufferMemory;
|
||||||
|
GN_ARRAY_LIST(gnBuffer);
|
||||||
|
GN_ARRAY_LIST(gnBufferMemory);
|
||||||
|
|
||||||
gnReturnCode gnCreateBuffer(gnBufferHandle* buffer, gnOutputDeviceHandle device, gnBufferInfo info);
|
gnReturnCode gnCreateBuffer(gnBufferHandle* buffer, gnOutputDeviceHandle device, gnBufferInfo info);
|
||||||
void gnBufferData(gnBufferHandle buffer, size_t dataSize, void* data);
|
void gnBufferData(gnBufferHandle buffer, size_t dataSize, gnBufferMemory data);
|
||||||
void* gnMapBuffer(gnBufferHandle buffer);
|
gnBufferMemory gnMapBuffer(gnBufferHandle buffer);
|
||||||
void gnDestroyBuffer(gnBufferHandle buffer);
|
void gnDestroyBuffer(gnBufferHandle buffer);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#include "gryphn_command_buffer.h"
|
#include "gryphn_command_buffer.h"
|
||||||
#include "core/gryphn_platform_functions.h"
|
#include "core/gryphn_platform_functions.h"
|
||||||
|
|
||||||
gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
buffers[i] = malloc(sizeof(struct gnCommandBuffer_t));
|
buffers[i] = malloc(sizeof(struct gnCommandBuffer_t));
|
||||||
buffers[i]->commandPool = commandPool;
|
buffers[i]->commandPool = commandPool;
|
||||||
@@ -9,6 +9,14 @@ gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers,
|
|||||||
return commandPool->commandFunctions->_gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool);
|
return commandPool->commandFunctions->_gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gnReturnCode gnCommandPoolAllocateCommandBuffersFromList(gnCommandBufferArrayList buffers, uint32_t count, gnCommandPoolHandle commandPool) {
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
buffers.data[i] = malloc(sizeof(struct gnCommandBuffer_t));
|
||||||
|
buffers.data[i]->commandPool = commandPool;
|
||||||
|
}
|
||||||
|
return gnCommandPoolAllocateCommandBuffersFromPointer(buffers.data, count, commandPool);
|
||||||
|
}
|
||||||
|
|
||||||
void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer) {
|
void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer) {
|
||||||
commandBuffer->commandPool->commandFunctions->_gnResetCommandBuffer(commandBuffer);
|
commandBuffer->commandPool->commandFunctions->_gnResetCommandBuffer(commandBuffer);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "utils/gryphn_error_code.h"
|
#include "utils/gryphn_error_code.h"
|
||||||
|
#include "utils/lists/gryphn_array_list.h"
|
||||||
#include "core/gryphn_handles.h"
|
#include "core/gryphn_handles.h"
|
||||||
|
|
||||||
#ifdef GN_REVEAL_IMPL
|
#ifdef GN_REVEAL_IMPL
|
||||||
@@ -10,7 +11,17 @@ struct gnCommandBuffer_t {
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool);
|
GN_ARRAY_LIST(gnCommandBuffer);
|
||||||
|
|
||||||
|
gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool);
|
||||||
|
// will reserve the space for ${count} number of elements
|
||||||
|
gnReturnCode gnCommandPoolAllocateCommandBuffersFromList(gnCommandBufferArrayList buffers, uint32_t count, gnCommandPoolHandle commandPool);
|
||||||
|
|
||||||
|
#define gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool) \
|
||||||
|
_Generic((buffers), \
|
||||||
|
gnCommandBufferArrayList: gnCommandPoolAllocateCommandBuffersFromList, \
|
||||||
|
default: gnCommandPoolAllocateCommandBuffersFromPointer \
|
||||||
|
)(buffers, count, commandPool)
|
||||||
|
|
||||||
void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer);
|
void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer);
|
||||||
gnReturnCode gnBeginCommandBuffer(gnCommandBufferHandle commandBuffer);
|
gnReturnCode gnBeginCommandBuffer(gnCommandBufferHandle commandBuffer);
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "utils/gryphn_bool.h"
|
#include "utils/gryphn_bool.h"
|
||||||
#include "utils/gryphn_error_code.h"
|
#include "utils/gryphn_error_code.h"
|
||||||
|
#include "utils/lists/gryphn_array_list.h"
|
||||||
#include "core/gryphn_handles.h"
|
#include "core/gryphn_handles.h"
|
||||||
|
|
||||||
#ifdef GN_REVEAL_IMPL
|
#ifdef GN_REVEAL_IMPL
|
||||||
@@ -11,6 +12,7 @@ struct gnFence_t {
|
|||||||
gnBool signaled;
|
gnBool signaled;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
GN_ARRAY_LIST(gnFence);
|
||||||
|
|
||||||
gnReturnCode gnCreateFence(gnFenceHandle* fence, gnOutputDeviceHandle device);
|
gnReturnCode gnCreateFence(gnFenceHandle* fence, gnOutputDeviceHandle device);
|
||||||
void gnSignalFence(gnFenceHandle fence);
|
void gnSignalFence(gnFenceHandle fence);
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "core/gryphn_handles.h"
|
#include "core/gryphn_handles.h"
|
||||||
#include "utils/gryphn_error_code.h"
|
#include "utils/gryphn_error_code.h"
|
||||||
|
#include "utils/lists/gryphn_array_list.h"
|
||||||
|
|
||||||
#ifdef GN_REVEAL_IMPL
|
#ifdef GN_REVEAL_IMPL
|
||||||
struct gnSemaphore_t {
|
struct gnSemaphore_t {
|
||||||
@@ -8,6 +9,7 @@ struct gnSemaphore_t {
|
|||||||
gnOutputDeviceHandle device;
|
gnOutputDeviceHandle device;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
GN_ARRAY_LIST(gnSemaphore);
|
||||||
|
|
||||||
gnReturnCode gnCreateSemaphore(gnSemaphore* semaphore, struct gnOutputDevice_t* device);
|
gnReturnCode gnCreateSemaphore(gnSemaphore* semaphore, struct gnOutputDevice_t* device);
|
||||||
void gnDestroySemaphore(gnSemaphore semaphore);
|
void gnDestroySemaphore(gnSemaphore semaphore);
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
#include "utils/lists/gryphn_array_list.h"
|
||||||
#include "core/gryphn_handles.h"
|
#include "core/gryphn_handles.h"
|
||||||
|
|
||||||
typedef struct gnBufferUniformInfo {
|
typedef struct gnBufferUniformInfo {
|
||||||
@@ -16,5 +17,6 @@ struct gnUniform_t {
|
|||||||
gnUniformPool pool;
|
gnUniformPool pool;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
GN_ARRAY_LIST(gnUniform)
|
||||||
|
|
||||||
void gnUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo bufferInfo);
|
void gnUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo bufferInfo);
|
||||||
|
@@ -11,11 +11,15 @@ gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// you own this memory now
|
// you own this memory now
|
||||||
gnUniform* gnUniformPoolAllocateUniforms(gnUniformPool pool, const gnUniformLayout layout) {
|
gnUniformArrayList gnUniformPoolAllocateUniforms(gnUniformPool pool, const gnUniformLayout layout, uint32_t count) {
|
||||||
gnUniform* uniforms = pool->device->deviceFunctions->_gnUniformPoolAllocateUniforms(pool, layout);
|
gnUniform* uniforms = pool->device->deviceFunctions->_gnUniformPoolAllocateUniforms(pool, layout);
|
||||||
for (int i = 0; i < layout.uniformBindingCount; i++)
|
for (int i = 0; i < layout.uniformBindingCount; i++)
|
||||||
uniforms[i]->pool = pool;
|
uniforms[i]->pool = pool;
|
||||||
return uniforms;
|
|
||||||
|
gnUniformArrayList list = gnUniformArrayListCreate();
|
||||||
|
gnUniformArrayListResize(&list, layout.uniformBindingCount);
|
||||||
|
for (int i = 0; i < layout.uniformBindingCount; i++) list.data[i] = uniforms[i];
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnDestroyUniformPool(gnUniformPool pool) {
|
void gnDestroyUniformPool(gnUniformPool pool) {
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
#include "core/gryphn_handles.h"
|
#include "core/gryphn_handles.h"
|
||||||
#include "utils/gryphn_error_code.h"
|
#include "utils/gryphn_error_code.h"
|
||||||
#include "core/uniforms/gryphn_uniform_layout.h"
|
#include "core/uniforms/gryphn_uniform_layout.h"
|
||||||
|
#include "core/uniforms/gryphn_uniform.h"
|
||||||
|
|
||||||
#ifdef GN_REVEAL_IMPL
|
#ifdef GN_REVEAL_IMPL
|
||||||
struct gnUniformPool_t {
|
struct gnUniformPool_t {
|
||||||
@@ -11,5 +12,5 @@ struct gnUniformPool_t {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device);
|
gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device);
|
||||||
gnUniform* gnUniformPoolAllocateUniforms(gnUniformPool pool, const gnUniformLayout layout);
|
gnUniformArrayList gnUniformPoolAllocateUniforms(gnUniformPool pool, const gnUniformLayout layout);
|
||||||
void gnDestroyUniformPool(gnUniformPool pool);
|
void gnDestroyUniformPool(gnUniformPool pool);
|
||||||
|
Reference in New Issue
Block a user