@@ -126,8 +126,10 @@ typedef struct _plVulkanShader
126126 VkShaderModule tPixelShaderModule ;
127127 VkShaderModule tVertexShaderModule ;
128128 VkDescriptorSetLayout atDescriptorSetLayouts [4 ];
129- VkSpecializationMapEntry atSpecializationEntries [PL_MAX_SHADER_SPECIALIZATION_CONSTANTS ];
130- size_t szSpecializationSize ;
129+ VkSpecializationMapEntry atVertexSpecializationEntries [PL_MAX_SHADER_SPECIALIZATION_CONSTANTS ];
130+ size_t szVertexSpecializationSize ;
131+ VkSpecializationMapEntry atFragmentSpecializationEntries [PL_MAX_SHADER_SPECIALIZATION_CONSTANTS ];
132+ size_t szFragmentSpecializationSize ;
131133} plVulkanShader ;
132134
133135typedef struct _plVulkanComputeShader
@@ -1586,27 +1588,50 @@ pl_create_shader(plDevice* ptDevice, const plShaderDesc* ptDescription)
15861588 };
15871589
15881590 // setup & count specilization constants
1589- ptShader -> tDesc ._uConstantCount = 0 ;
1590- ptVulkanShader -> szSpecializationSize = 0 ;
1591+ ptShader -> tDesc ._uVertexConstantCount = 0 ;
1592+ ptShader -> tDesc ._uFragmentConstantCount = 0 ;
1593+ ptVulkanShader -> szVertexSpecializationSize = 0 ;
1594+ ptVulkanShader -> szFragmentSpecializationSize = 0 ;
15911595 uint32_t uConstantOffset = 0 ;
15921596 for (uint32_t i = 0 ; i < PL_MAX_SHADER_SPECIALIZATION_CONSTANTS ; i ++ )
15931597 {
1594- const plSpecializationConstant * ptConstant = & ptShader -> tDesc .atConstants [i ];
1598+ const plSpecializationConstant * ptConstant = & ptShader -> tDesc .atVertexConstants [i ];
15951599 if (ptConstant -> tType == PL_DATA_TYPE_UNSPECIFIED )
15961600 break ;
1597- ptVulkanShader -> atSpecializationEntries [i ].constantID = ptConstant -> uID == 0 ? ptShader -> tDesc ._uConstantCount : ptConstant -> uID ;
1598- ptVulkanShader -> atSpecializationEntries [i ].offset = ptConstant -> uOffset == 0 ? uConstantOffset : ptConstant -> uOffset ;
1601+ ptVulkanShader -> atVertexSpecializationEntries [i ].constantID = ptConstant -> uID == 0 ? ptShader -> tDesc ._uVertexConstantCount : ptConstant -> uID ;
1602+ ptVulkanShader -> atVertexSpecializationEntries [i ].offset = ptConstant -> uOffset == 0 ? uConstantOffset : ptConstant -> uOffset ;
15991603 uConstantOffset += (uint32_t )pl_get_data_type_size (ptConstant -> tType );
1600- ptVulkanShader -> atSpecializationEntries [i ].size = pl_get_data_type_size (ptConstant -> tType );
1601- ptVulkanShader -> szSpecializationSize += ptVulkanShader -> atSpecializationEntries [i ].size ;
1602- ptShader -> tDesc ._uConstantCount ++ ;
1604+ ptVulkanShader -> atVertexSpecializationEntries [i ].size = pl_get_data_type_size (ptConstant -> tType );
1605+ ptVulkanShader -> szVertexSpecializationSize += ptVulkanShader -> atVertexSpecializationEntries [i ].size ;
1606+ ptShader -> tDesc ._uVertexConstantCount ++ ;
16031607 }
16041608
1605- const VkSpecializationInfo tSpecializationInfo = {
1606- .mapEntryCount = ptShader -> tDesc ._uConstantCount ,
1607- .pMapEntries = ptVulkanShader -> atSpecializationEntries ,
1608- .dataSize = ptVulkanShader -> szSpecializationSize ,
1609- .pData = ptDescription -> pTempConstantData
1609+ uConstantOffset = 0 ;
1610+ for (uint32_t i = 0 ; i < PL_MAX_SHADER_SPECIALIZATION_CONSTANTS ; i ++ )
1611+ {
1612+ const plSpecializationConstant * ptConstant = & ptShader -> tDesc .atFragmentConstants [i ];
1613+ if (ptConstant -> tType == PL_DATA_TYPE_UNSPECIFIED )
1614+ break ;
1615+ ptVulkanShader -> atFragmentSpecializationEntries [i ].constantID = ptConstant -> uID == 0 ? ptShader -> tDesc ._uFragmentConstantCount : ptConstant -> uID ;
1616+ ptVulkanShader -> atFragmentSpecializationEntries [i ].offset = ptConstant -> uOffset == 0 ? uConstantOffset : ptConstant -> uOffset ;
1617+ uConstantOffset += (uint32_t )pl_get_data_type_size (ptConstant -> tType );
1618+ ptVulkanShader -> atFragmentSpecializationEntries [i ].size = pl_get_data_type_size (ptConstant -> tType );
1619+ ptVulkanShader -> szFragmentSpecializationSize += ptVulkanShader -> atFragmentSpecializationEntries [i ].size ;
1620+ ptShader -> tDesc ._uFragmentConstantCount ++ ;
1621+ }
1622+
1623+ const VkSpecializationInfo tVertexSpecializationInfo = {
1624+ .mapEntryCount = ptShader -> tDesc ._uVertexConstantCount ,
1625+ .pMapEntries = ptVulkanShader -> atVertexSpecializationEntries ,
1626+ .dataSize = ptVulkanShader -> szVertexSpecializationSize ,
1627+ .pData = ptDescription -> pVertexTempConstantData
1628+ };
1629+
1630+ const VkSpecializationInfo tFragmentSpecializationInfo = {
1631+ .mapEntryCount = ptShader -> tDesc ._uFragmentConstantCount ,
1632+ .pMapEntries = ptVulkanShader -> atFragmentSpecializationEntries ,
1633+ .dataSize = ptVulkanShader -> szFragmentSpecializationSize ,
1634+ .pData = ptDescription -> pFragmentTempConstantData
16101635 };
16111636
16121637 // create pipeline layout
@@ -1623,7 +1648,7 @@ pl_create_shader(plDevice* ptDevice, const plShaderDesc* ptDescription)
16231648 .stage = VK_SHADER_STAGE_VERTEX_BIT ,
16241649 .module = ptVulkanShader -> tVertexShaderModule ,
16251650 .pName = ptShader -> tDesc .tVertexShader .pcEntryFunc ,
1626- .pSpecializationInfo = ptShader -> tDesc ._uConstantCount > 0 ? & tSpecializationInfo : NULL
1651+ .pSpecializationInfo = ptShader -> tDesc ._uVertexConstantCount > 0 ? & tVertexSpecializationInfo : NULL
16271652 };
16281653
16291654 // doesn't matter since dynamic
@@ -1668,7 +1693,7 @@ pl_create_shader(plDevice* ptDevice, const plShaderDesc* ptDescription)
16681693 .stage = VK_SHADER_STAGE_FRAGMENT_BIT ,
16691694 .module = ptVulkanShader -> tPixelShaderModule ,
16701695 .pName = ptShader -> tDesc .tFragmentShader .pcEntryFunc ,
1671- .pSpecializationInfo = & tSpecializationInfo
1696+ .pSpecializationInfo = ptShader -> tDesc . _uFragmentConstantCount > 0 ? & tFragmentSpecializationInfo : NULL
16721697 };
16731698
16741699 VkPipelineDepthStencilStateCreateInfo tDepthStencil = {
0 commit comments