Skip to content

Commit

Permalink
WIP win
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan hoffstadt committed Jun 6, 2024
1 parent 12fda58 commit e0c6842
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 104 deletions.
48 changes: 32 additions & 16 deletions extensions/pl_draw_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2752,10 +2752,14 @@ pl__get_3d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, p
#endif

const plShaderDescription t3DShaderDesc = {
.szVertexShaderByteCodeSize = uVertexShaderSize,
.szPixelShaderByteCodeSize = uPixelShaderSize,
.puVertexShaderByteCode = puVertexShaderCode,
.puPixelShaderByteCode = puPixelShaderCode,
.tPixelShader = {
.szCodeSize = uPixelShaderSize,
.puCode = puPixelShaderCode,
},
.tVertexShader = {
.szCodeSize = uVertexShaderSize,
.puCode = puVertexShaderCode,
},
.tGraphicsState = {
.ulDepthWriteEnabled = tFlags & PL_DRAW_FLAG_DEPTH_WRITE,
.ulDepthMode = tFlags & PL_DRAW_FLAG_DEPTH_TEST ? PL_COMPARE_MODE_LESS : PL_COMPARE_MODE_ALWAYS,
Expand Down Expand Up @@ -2816,10 +2820,14 @@ pl__get_3d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, p
#endif

const plShaderDescription t3DLineShaderDesc = {
.szVertexShaderByteCodeSize = uVertexShaderSize,
.szPixelShaderByteCodeSize = uPixelShaderSize,
.puVertexShaderByteCode = puVertexShaderCode,
.puPixelShaderByteCode = puPixelShaderCode,
.tPixelShader = {
.szCodeSize = uPixelShaderSize,
.puCode = puPixelShaderCode,
},
.tVertexShader = {
.szCodeSize = uVertexShaderSize,
.puCode = puVertexShaderCode,
},
.tGraphicsState = {
.ulDepthWriteEnabled = tFlags & PL_DRAW_FLAG_DEPTH_WRITE,
.ulDepthMode = tFlags & PL_DRAW_FLAG_DEPTH_TEST ? PL_COMPARE_MODE_LESS : PL_COMPARE_MODE_ALWAYS,
Expand Down Expand Up @@ -2904,10 +2912,14 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u
#endif

const plShaderDescription tRegularShaderDesc = {
.szVertexShaderByteCodeSize = uVertexShaderSize,
.szPixelShaderByteCodeSize = uPixelShaderSize,
.puVertexShaderByteCode = puVertexShaderCode,
.puPixelShaderByteCode = puPixelShaderCode,
.tPixelShader = {
.szCodeSize = uPixelShaderSize,
.puCode = puPixelShaderCode,
},
.tVertexShader = {
.szCodeSize = uVertexShaderSize,
.puCode = puVertexShaderCode,
},
.tGraphicsState = {
.ulDepthWriteEnabled = 0,
.ulDepthMode = PL_COMPARE_MODE_ALWAYS,
Expand Down Expand Up @@ -2983,10 +2995,14 @@ pl__get_2d_pipeline(plRenderPassHandle tRenderPass, uint32_t uMSAASampleCount, u
#endif

const plShaderDescription tSecondaryShaderDesc = {
.szVertexShaderByteCodeSize = uVertexShaderSize,
.szPixelShaderByteCodeSize = uPixelShaderSize,
.puVertexShaderByteCode = puVertexShaderCode,
.puPixelShaderByteCode = puPixelShaderCode,
.tPixelShader = {
.szCodeSize = uPixelShaderSize,
.puCode = puPixelShaderCode,
},
.tVertexShader = {
.szCodeSize = uVertexShaderSize,
.puCode = puVertexShaderCode,
},
.tGraphicsState = {
.ulDepthWriteEnabled = 0,
.ulDepthMode = PL_COMPARE_MODE_ALWAYS,
Expand Down
38 changes: 25 additions & 13 deletions extensions/pl_graphics_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ typedef struct _plDrawIndex plDrawIndex;
typedef struct _plGraphicsState plGraphicsState;
typedef struct _plBlendState plBlendState;
typedef struct _plSpecializationConstant plSpecializationConstant;
typedef struct _plShaderModule plShaderModule;
typedef struct _plShaderDescription plShaderDescription;
typedef struct _plShader plShader;
typedef struct _plComputeShaderDescription plComputeShaderDescription;
Expand Down Expand Up @@ -191,6 +192,7 @@ typedef int plBufferUsage; // -> enum _plBufferUsage // Enum:
typedef int plTextureUsage; // -> enum _plTextureUsage // Enum:
typedef int plMeshFormatFlags; // -> enum _plMeshFormatFlags // Flags:
typedef int plStageFlags; // -> enum _plStageFlags // Flags:
typedef int plShaderModuleFlags; // -> enum _plShaderModuleFlags // Flags:
typedef int plCullMode; // -> enum _plCullMode // Enum:
typedef int plFilter; // -> enum _plFilter // Enum:
typedef int plWrapMode; // -> enum _plWrapMode // Enum:
Expand Down Expand Up @@ -702,6 +704,14 @@ typedef struct _plVertexBufferBinding
plVertexAttributes atAttributes[PL_MAX_VERTEX_ATTRIBUTES];
} plVertexBufferBinding;

typedef struct _plShaderModule
{
size_t szCodeSize;
uint8_t* puCode;
const char* pcEntryFunc;
plShaderModuleFlags tFlags;
} plShaderModule;

typedef struct _plShaderDescription
{
plSpecializationConstant atConstants[PL_MAX_SHADER_SPECIALIZATION_CONSTANTS];
Expand All @@ -711,13 +721,9 @@ typedef struct _plShaderDescription
plBlendState atBlendStates[PL_MAX_RENDER_TARGETS];
uint32_t uBlendStateCount;
plVertexBufferBinding tVertexBufferBinding;
size_t szVertexShaderByteCodeSize;
uint8_t* puVertexShaderByteCode;
size_t szPixelShaderByteCodeSize;
uint8_t* puPixelShaderByteCode;
plShaderModule tVertexShader;
plShaderModule tPixelShader;
const void* pTempConstantData;
const char* pcVertexShaderEntryFunc;
const char* pcPixelShaderEntryFunc;
plBindGroupLayout atBindGroupLayouts[3];
uint32_t uBindGroupLayoutCount;
plRenderPassLayoutHandle tRenderPassLayout;
Expand All @@ -730,9 +736,7 @@ typedef struct _plShader

typedef struct _plComputeShaderDescription
{
size_t szShaderByteCodeSize;
uint8_t* puShaderByteCode;
const char* pcShaderEntryFunc;
plShaderModule tShaderModule;
plBindGroupLayout atBindGroupLayouts[3];
uint32_t uBindGroupLayoutCount;
plSpecializationConstant atConstants[PL_MAX_SHADER_SPECIALIZATION_CONSTANTS];
Expand Down Expand Up @@ -907,12 +911,20 @@ typedef struct _plGraphics
// [SECTION] enums
//-----------------------------------------------------------------------------

enum _plShaderModuleFlags
{
PL_SHADER_MODULE_FLAGS_NONE = 0,
PL_SHADER_MODULE_FLAGS_SPIRV = 0,
PL_SHADER_MODULE_FLAGS_METAL = 1 << 0,
PL_SHADER_MODULE_FLAGS_GLSL = 1 << 1
};

enum _plStageFlags
{
PL_STAGE_NONE = 1 << 0,
PL_STAGE_VERTEX = 1 << 1,
PL_STAGE_PIXEL = 1 << 2,
PL_STAGE_COMPUTE = 1 << 3,
PL_STAGE_NONE = 0,
PL_STAGE_VERTEX = 1 << 0,
PL_STAGE_PIXEL = 1 << 1,
PL_STAGE_COMPUTE = 1 << 2,
PL_STAGE_ALL = PL_STAGE_VERTEX | PL_STAGE_PIXEL | PL_STAGE_COMPUTE
};

Expand Down
26 changes: 13 additions & 13 deletions extensions/pl_graphics_vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ pl_create_compute_shader(plDevice* ptDevice, const plComputeShaderDescription* p
plVulkanComputeShader* ptVulkanShader = &ptVulkanGfx->sbtComputeShadersHot[uResourceIndex];

// if(ptDescription->pcShaderEntryFunc == NULL)
tShader.tDescription.pcShaderEntryFunc = "main";
tShader.tDescription.tShaderModule.pcEntryFunc = "main";

ptVulkanShader->szSpecializationSize = 0;
for(uint32_t i = 0; i < tShader.tDescription.uConstantCount; i++)
Expand All @@ -1589,8 +1589,8 @@ pl_create_compute_shader(plDevice* ptDevice, const plComputeShaderDescription* p

VkShaderModuleCreateInfo tShaderCreateInfo = {
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.codeSize = tShader.tDescription.szShaderByteCodeSize,
.pCode = (const uint32_t*)tShader.tDescription.puShaderByteCode
.codeSize = tShader.tDescription.tShaderModule.szCodeSize,
.pCode = (const uint32_t*)tShader.tDescription.tShaderModule.puCode
};

PL_VULKAN(vkCreateShaderModule(ptVulkanDevice->tLogicalDevice, &tShaderCreateInfo, NULL, &ptVulkanShader->tShaderModule));
Expand Down Expand Up @@ -1621,7 +1621,7 @@ pl_create_compute_shader(plDevice* ptDevice, const plComputeShaderDescription* p
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_COMPUTE_BIT,
.module = ptVulkanShader->tShaderModule,
.pName = tShader.tDescription.pcShaderEntryFunc,
.pName = tShader.tDescription.tShaderModule.pcEntryFunc,
.pSpecializationInfo = tShader.tDescription.uConstantCount > 0 ? &tSpecializationInfo : NULL
};

Expand Down Expand Up @@ -1673,10 +1673,10 @@ pl_create_shader(plDevice* ptDevice, const plShaderDescription* ptDescription)
plVulkanShader* ptVulkanShader = &ptVulkanGfx->sbtShadersHot[uResourceIndex];

// if(ptDescription->pcPixelShaderEntryFunc == NULL)
tShader.tDescription.pcPixelShaderEntryFunc = "main";
tShader.tDescription.tPixelShader.pcEntryFunc = "main";

// if(ptDescription->pcVertexShaderEntryFunc == NULL)
tShader.tDescription.pcVertexShaderEntryFunc = "main";
tShader.tDescription.tVertexShader.pcEntryFunc = "main";

for(uint32_t i = 0; i < tShader.tDescription.uBindGroupLayoutCount; i++)
{
Expand All @@ -1689,19 +1689,19 @@ pl_create_shader(plDevice* ptDevice, const plShaderDescription* ptDescription)

VkShaderModuleCreateInfo tVertexShaderCreateInfo = {
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.codeSize = tShader.tDescription.szVertexShaderByteCodeSize,
.pCode = (const uint32_t*)(tShader.tDescription.puVertexShaderByteCode)
.codeSize = tShader.tDescription.tVertexShader.szCodeSize,
.pCode = (const uint32_t*)(tShader.tDescription.tVertexShader.puCode)
};
PL_VULKAN(vkCreateShaderModule(ptVulkanDevice->tLogicalDevice, &tVertexShaderCreateInfo, NULL, &ptVulkanShader->tVertexShaderModule));


if(tShader.tDescription.puPixelShaderByteCode)
if(tShader.tDescription.tPixelShader.puCode)
{
uStageCount++;
VkShaderModuleCreateInfo tPixelShaderCreateInfo = {
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.codeSize = tShader.tDescription.szPixelShaderByteCodeSize,
.pCode = (const uint32_t*)(tShader.tDescription.puPixelShaderByteCode),
.codeSize = tShader.tDescription.tPixelShader.szCodeSize,
.pCode = (const uint32_t*)(tShader.tDescription.tPixelShader.puCode),
};

PL_VULKAN(vkCreateShaderModule(ptVulkanDevice->tLogicalDevice, &tPixelShaderCreateInfo, NULL, &ptVulkanShader->tPixelShaderModule));
Expand Down Expand Up @@ -1782,7 +1782,7 @@ pl_create_shader(plDevice* ptDevice, const plShaderDescription* ptDescription)
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_VERTEX_BIT,
.module = ptVulkanShader->tVertexShaderModule,
.pName = tShader.tDescription.pcVertexShaderEntryFunc,
.pName = tShader.tDescription.tVertexShader.pcEntryFunc,
.pSpecializationInfo = tShader.tDescription.uConstantCount > 0 ? &tSpecializationInfo : NULL
};

Expand Down Expand Up @@ -1841,7 +1841,7 @@ pl_create_shader(plDevice* ptDevice, const plShaderDescription* ptDescription)
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = ptVulkanShader->tPixelShaderModule,
.pName = tShader.tDescription.pcPixelShaderEntryFunc,
.pName = tShader.tDescription.tPixelShader.pcEntryFunc,
.pSpecializationInfo = &tSpecializationInfo
};

Expand Down
Loading

0 comments on commit e0c6842

Please sign in to comment.