Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Apr 23, 2024
1 parent e6eea48 commit ae25608
Show file tree
Hide file tree
Showing 9 changed files with 450 additions and 178 deletions.
3 changes: 0 additions & 3 deletions apps/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ const plGraphicsI* gptGfx = NULL;
const plDeviceI* gptDevice = NULL;
const plDebugApiI* gptDebug = NULL;
const plImageI* gptImage = NULL;
const plDrawStreamI* gptStream = NULL;
const plEcsI* gptEcs = NULL;
const plCameraI* gptCamera = NULL;
const plResourceI* gptResource = NULL;
Expand Down Expand Up @@ -136,7 +135,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptDebug = ptApiRegistry->first(PL_API_DEBUG);
gptImage = ptApiRegistry->first(PL_API_IMAGE);
gptStream = ptApiRegistry->first(PL_API_DRAW_STREAM);
gptEcs = ptApiRegistry->first(PL_API_ECS);
gptCamera = ptApiRegistry->first(PL_API_CAMERA);
gptResource = ptApiRegistry->first(PL_API_RESOURCE);
Expand Down Expand Up @@ -185,7 +183,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptDevice = ptApiRegistry->first(PL_API_DEVICE);
gptDebug = ptApiRegistry->first(PL_API_DEBUG);
gptImage = ptApiRegistry->first(PL_API_IMAGE);
gptStream = ptApiRegistry->first(PL_API_DRAW_STREAM);
gptEcs = ptApiRegistry->first(PL_API_ECS);
gptCamera = ptApiRegistry->first(PL_API_CAMERA);
gptResource = ptApiRegistry->first(PL_API_RESOURCE);
Expand Down
41 changes: 15 additions & 26 deletions extensions/pl_graphics_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,21 +508,21 @@ enum plDrawStreamBits
static void
pl_drawstream_cleanup(plDrawStream* ptStream)
{
memset(&ptStream->tCurrentDraw, 255, sizeof(plDraw));
memset(&ptStream->tCurrentDraw, 255, sizeof(plStreamDraw));
pl_sb_free(ptStream->sbtStream);
}

static void
pl_drawstream_reset(plDrawStream* ptStream)
{
memset(&ptStream->tCurrentDraw, 255, sizeof(plDraw));
memset(&ptStream->tCurrentDraw, 255, sizeof(plStreamDraw));
ptStream->tCurrentDraw.uIndexBuffer = UINT32_MAX - 1;
ptStream->tCurrentDraw.uDynamicBufferOffset = 0;
pl_sb_reset(ptStream->sbtStream);
}

static void
pl_drawstream_draw(plDrawStream* ptStream, plDraw tDraw)
pl_drawstream_draw(plDrawStream* ptStream, plStreamDraw tDraw)
{

uint32_t uDirtyMask = PL_DRAW_STREAM_BIT_NONE;
Expand All @@ -539,10 +539,10 @@ pl_drawstream_draw(plDrawStream* ptStream, plDraw tDraw)
uDirtyMask |= PL_DRAW_STREAM_BIT_DYNAMIC_OFFSET;
}

if(ptStream->tCurrentDraw.uDynamicBuffer != tDraw.uDynamicBuffer)
if(ptStream->tCurrentDraw.uBindGroup1 != tDraw.uBindGroup1)
{
ptStream->tCurrentDraw.uDynamicBuffer = tDraw.uDynamicBuffer;
uDirtyMask |= PL_DRAW_STREAM_BIT_DYNAMIC_BUFFER;
ptStream->tCurrentDraw.uBindGroup1 = tDraw.uBindGroup1;
uDirtyMask |= PL_DRAW_STREAM_BIT_BINDGROUP_1;
}

if(ptStream->tCurrentDraw.uBindGroup2 != tDraw.uBindGroup2)
Expand All @@ -551,10 +551,10 @@ pl_drawstream_draw(plDrawStream* ptStream, plDraw tDraw)
uDirtyMask |= PL_DRAW_STREAM_BIT_BINDGROUP_2;
}

if(ptStream->tCurrentDraw.uBindGroup1 != tDraw.uBindGroup1)
if(ptStream->tCurrentDraw.uDynamicBuffer != tDraw.uDynamicBuffer)
{
ptStream->tCurrentDraw.uBindGroup1 = tDraw.uBindGroup1;
uDirtyMask |= PL_DRAW_STREAM_BIT_BINDGROUP_1;
ptStream->tCurrentDraw.uDynamicBuffer = tDraw.uDynamicBuffer;
uDirtyMask |= PL_DRAW_STREAM_BIT_DYNAMIC_BUFFER;
}

if(ptStream->tCurrentDraw.uIndexOffset != tDraw.uIndexOffset)
Expand Down Expand Up @@ -600,16 +600,16 @@ pl_drawstream_draw(plDrawStream* ptStream, plDraw tDraw)
}

pl_sb_push(ptStream->sbtStream, uDirtyMask);
if(uDirtyMask & PL_DRAW_STREAM_BIT_SHADER)
pl_sb_push(ptStream->sbtStream, ptStream->tCurrentDraw.uShaderVariant);
if(uDirtyMask & PL_DRAW_STREAM_BIT_DYNAMIC_OFFSET)
pl_sb_push(ptStream->sbtStream, ptStream->tCurrentDraw.uDynamicBufferOffset);
if(uDirtyMask & PL_DRAW_STREAM_BIT_DYNAMIC_BUFFER)
pl_sb_push(ptStream->sbtStream, ptStream->tCurrentDraw.uDynamicBuffer);
if(uDirtyMask & PL_DRAW_STREAM_BIT_BINDGROUP_2)
pl_sb_push(ptStream->sbtStream, ptStream->tCurrentDraw.uBindGroup2);
if(uDirtyMask & PL_DRAW_STREAM_BIT_BINDGROUP_1)
pl_sb_push(ptStream->sbtStream, ptStream->tCurrentDraw.uBindGroup1);
if(uDirtyMask & PL_DRAW_STREAM_BIT_SHADER)
pl_sb_push(ptStream->sbtStream, ptStream->tCurrentDraw.uShaderVariant);
if(uDirtyMask & PL_DRAW_STREAM_BIT_BINDGROUP_2)
pl_sb_push(ptStream->sbtStream, ptStream->tCurrentDraw.uBindGroup2);
if(uDirtyMask & PL_DRAW_STREAM_BIT_DYNAMIC_BUFFER)
pl_sb_push(ptStream->sbtStream, ptStream->tCurrentDraw.uDynamicBuffer);
if(uDirtyMask & PL_DRAW_STREAM_BIT_INDEX_OFFSET)
pl_sb_push(ptStream->sbtStream, ptStream->tCurrentDraw.uIndexOffset);
if(uDirtyMask & PL_DRAW_STREAM_BIT_VERTEX_OFFSET)
Expand All @@ -626,17 +626,6 @@ pl_drawstream_draw(plDrawStream* ptStream, plDraw tDraw)
pl_sb_push(ptStream->sbtStream, ptStream->tCurrentDraw.uInstanceCount);
}

static const plDrawStreamI*
pl_load_drawstream_api(void)
{
static const plDrawStreamI tApi = {
.reset = pl_drawstream_reset,
.draw = pl_drawstream_draw,
.cleanup = pl_drawstream_cleanup
};
return &tApi;
}

static uint32_t
pl__format_stride(plFormat tFormat)
{
Expand Down
68 changes: 47 additions & 21 deletions extensions/pl_graphics_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ typedef struct _plGraphicsI plGraphicsI;
#define PL_API_DEVICE "PL_API_DEVICE"
typedef struct _plDeviceI plDeviceI;

#define PL_API_DRAW_STREAM "PL_API_DRAW_STREAM"
typedef struct _plDrawStreamI plDrawStreamI;

//-----------------------------------------------------------------------------
// [SECTION] includes
//-----------------------------------------------------------------------------
Expand All @@ -102,11 +99,14 @@ typedef struct _plDrawStreamI plDrawStreamI;
typedef struct _plDevice plDevice;
typedef struct _plBuffer plBuffer;
typedef struct _plSwapchain plSwapchain;
typedef struct _plGraphicsDesc plGraphicsDesc;
typedef struct _plGraphics plGraphics;
typedef struct _plDraw plDraw;
typedef struct _plStreamDraw plStreamDraw;
typedef struct _plDispatch plDispatch;
typedef struct _plDrawArea plDrawArea;
typedef struct _plDrawStream plDrawStream;
typedef struct _plDraw plDraw;
typedef struct _plDrawIndex plDrawIndex;
typedef struct _plGraphicsState plGraphicsState;
typedef struct _plBlendState plBlendState;
typedef struct _plSpecializationConstant plSpecializationConstant;
Expand Down Expand Up @@ -213,13 +213,6 @@ typedef struct _plWindow plWindow;
// [SECTION] public api structs
//-----------------------------------------------------------------------------

typedef struct _plDrawStreamI
{
void (*reset) (plDrawStream*);
void (*cleanup)(plDrawStream*);
void (*draw) (plDrawStream*, plDraw);
} plDrawStreamI;

typedef struct _plDeviceI
{

Expand Down Expand Up @@ -251,7 +244,6 @@ typedef struct _plDeviceI
void (*destroy_bind_group) (plDevice*, plBindGroupHandle);
plBindGroup* (*get_bind_group) (plDevice*, plBindGroupHandle); // do not store


// render passes
plRenderPassLayoutHandle (*create_render_pass_layout) (plDevice*, const plRenderPassLayoutDescription*);
plRenderPassHandle (*create_render_pass) (plDevice*, const plRenderPassDescription*, const plRenderPassAttachments*);
Expand Down Expand Up @@ -285,7 +277,7 @@ typedef struct _plDeviceI

typedef struct _plGraphicsI
{
void (*initialize)(plWindow*, plGraphics*);
void (*initialize)(plWindow*, const plGraphicsDesc*, plGraphics*);
void (*resize) (plGraphics*);
void (*cleanup) (plGraphics*);
void (*setup_ui) (plGraphics*, plRenderPassHandle);
Expand All @@ -309,13 +301,25 @@ typedef struct _plGraphicsI
plRenderEncoder (*begin_render_pass) (plGraphics*, plCommandBuffer*, plRenderPassHandle);
void (*next_subpass) (plRenderEncoder*);
void (*end_render_pass) (plRenderEncoder*);
void (*draw_subpass) (plRenderEncoder*, uint32_t uAreaCount, plDrawArea*);
void (*bind_graphics_bind_groups)(plRenderEncoder*, plShaderHandle, uint32_t uFirst, uint32_t uCount, const plBindGroupHandle*);

void (*draw_stream) (plRenderEncoder*, uint32_t uAreaCount, plDrawArea*);
void (*bind_graphics_bind_groups)(plRenderEncoder*, plShaderHandle, uint32_t uFirst, uint32_t uCount, const plBindGroupHandle*, plDynamicBinding*);
void (*set_viewport) (plRenderEncoder*, plRenderViewport*);
void (*set_scissor_region) (plRenderEncoder*, plScissor*);
void (*bind_vertex_buffer) (plRenderEncoder*, plBufferHandle);
void (*draw) (plRenderEncoder*, uint32_t uCount, const plDraw*);
void (*draw_indexed) (plRenderEncoder*, uint32_t uCount, const plDrawIndex*);
void (*bind_shader) (plRenderEncoder*, plShaderHandle);

// draw stream
void (*reset_draw_stream) (plDrawStream*);
void (*cleanup_draw_stream)(plDrawStream*);
void (*add_to_stream) (plDrawStream*, plStreamDraw);

// compute encoder
plComputeEncoder (*begin_compute_pass) (plGraphics*, plCommandBuffer*);
void (*end_compute_pass) (plComputeEncoder*);
void (*dispatch) (plComputeEncoder*, uint32_t uDispatchCount, plDispatch*);
void (*bind_compute_shader) (plComputeEncoder*, plComputeShaderHandle);
void (*bind_compute_bind_groups)(plComputeEncoder*, plComputeShaderHandle, uint32_t uFirst, uint32_t uCount, const plBindGroupHandle*);

// blit encoder
Expand Down Expand Up @@ -699,10 +703,9 @@ typedef struct _plDispatch
uint32_t uGroupCountX;
uint32_t uGroupCountY;
uint32_t uGroupCountZ;
plComputeShaderHandle tShader;
} plDispatch;

typedef struct _plDraw
typedef struct _plStreamDraw
{
uint32_t uDynamicBuffer;
uint32_t uVertexBuffer;
Expand All @@ -716,14 +719,32 @@ typedef struct _plDraw
uint32_t uDynamicBufferOffset;
uint32_t uInstanceStart;
uint32_t uInstanceCount;
} plDraw;
} plStreamDraw;

typedef struct _plDrawStream
{
plDraw tCurrentDraw;
uint32_t* sbtStream;
plStreamDraw tCurrentDraw;
uint32_t* sbtStream;
} plDrawStream;

typedef struct _plDraw
{
uint32_t uVertexStart;
uint32_t uVertexCount;
uint32_t uInstance;
uint32_t uInstanceCount;
} plDraw;

typedef struct _plDrawIndex
{
uint32_t uIndexStart;
uint32_t uIndexCount;
uint32_t uVertexStart;
uint32_t uInstance;
uint32_t uInstanceCount;
plBufferHandle tIndexBuffer;
} plDrawIndex;

typedef struct _plSpecializationConstant
{
uint32_t uID;
Expand Down Expand Up @@ -872,6 +893,11 @@ typedef struct _plSwapchain
void* _pInternalData;
} plSwapchain;

typedef struct _plGraphicsDesc
{
bool bEnableValidation;
} plGraphicsDesc;

typedef struct _plGraphics
{
plDevice tDevice;
Expand Down
Loading

0 comments on commit ae25608

Please sign in to comment.