Skip to content

Commit

Permalink
some init instance stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
recp committed Oct 3, 2023
1 parent 7bd834e commit 0a62e6e
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 26 deletions.
2 changes: 1 addition & 1 deletion include/gpu/api/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {
struct GPUApi;

typedef struct GPUApiInstance {
GPUInstance *(*createInstance)(struct GPUApi *__restrict api, void * __restrict unused);
GPUInstance *(*createInstance)(struct GPUApi * __restrict api, GPUInitParams * __restrict params);
} GPUApiInstance;

#ifdef __cplusplus
Expand Down
25 changes: 23 additions & 2 deletions include/gpu/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,34 @@ extern "C" {

#include "common.h"

typedef enum GPUFeatures {
GPU_FEATURE_NONE = 0,
GPU_FEATURE_SURFACE,
GPU_FEATURE_SWAPCHAIN,
GPU_FEATURE_DEFAULT = GPU_FEATURE_SURFACE | GPU_FEATURE_SWAPCHAIN
} GPUFeatures;

typedef struct GPUInitParams {
GPUFeatures requiredFeatures; /* DEFAULT */
GPUFeatures optionalFeatures; /* NONE */
bool validation; /* false, Vulkan validation layers */
bool validation_usebreak; /* false */
} GPUInitParams;

typedef struct GPUInstance {
void *_priv;
void *_priv;
GPUInitParams *initParams; /* read-only */
uint32_t validationError;
} GPUInstance;

/*!
* @brief creates GPU instance by specified params, features, options if possible
*
* @param[in] params init params, NULL to default.
*/
GPU_EXPORT
GPUInstance*
GPUCreateInstance(void * __restrict unused);
GPUCreateInstance(GPUInitParams * __restrict params);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

GPU_EXPORT
GPUInstance*
GPUCreateInstance(void * __restrict unused) {
GPUCreateInstance(GPUInitParams * __restrict params) {
GPUApi *api;

if (!(api = gpuActiveGPUApi()))
return NULL;

return api->instance.createInstance(api, unused);
return api->instance.createInstance(api, params);
}
3 changes: 2 additions & 1 deletion src/backend/dx12/impl/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

GPU_HIDE
GPUInstance *
dx12_createInstance(struct GPUApi *__restrict api, void *__restrict unused) {
dx12_createInstance(struct GPUApi * __restrict api,
GPUInitParams * __restrict params) {
GPUInstance *inst;
inst = calloc(1, sizeof(*inst));
return inst;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/mt/impl/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

GPU_HIDE
GPUInstance*
mt_createInstance(GPUApi * __restrict api, void * __restrict unused) {
mt_createInstance(GPUApi * __restrict api, GPUInitParams * __restrict params) {
GPUInstance *inst;

return NULL;
Expand Down
4 changes: 4 additions & 0 deletions src/backend/vk/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@

#include "../../common.h"
#include <stdarg.h>
#include <assert.h>
#include <inttypes.h>

#ifdef ANDROID
# include "vulkan_wrapper.h"
#else
# include <vulkan/vulkan.h>
#endif

#include "object_type_string_helper.h"

#define APP_SHORT_NAME "libgpu"
#define APP_LONG_NAME "libgpu"

Expand Down
Loading

0 comments on commit 0a62e6e

Please sign in to comment.