diff --git a/materialsystem/vulkan/libraries/raster.cpp b/materialsystem/vulkan/libraries/raster.cpp index 3812bba..b23976a 100644 --- a/materialsystem/vulkan/libraries/raster.cpp +++ b/materialsystem/vulkan/libraries/raster.cpp @@ -1,57 +1,43 @@ #include "../vulkan_state.h" #include "../raster_libraries.h" #include "tier1/utlbuffer.h" +#include "tier1/utlvector.h" #include "tier2/ifilesystem.h" #include "vulkan/vulkan_core.h" -BEGIN_BUILD_PIPELINE_LIBRARY(Functions) - CUtlBuffer vertexShaderData; - VkShaderModuleCreateInfo stVertexModule = {}; - VkPipelineShaderStageCreateInfo stVertexStage = {}; - if (szVertexShader) - { +BEGIN_BUILD_PIPELINE_LIBRARY(VertexDescription) + library.flags = VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT; + + VkPipelineVertexInputStateCreateInfo vertexInput = {}; + vertexInput.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertexInput.vertexBindingDescriptionCount = layouts.GetSize(); + vertexInput.pVertexBindingDescriptions = layouts.GetData(); + vertexInput.vertexAttributeDescriptionCount = attributes.GetSize(); + vertexInput.pVertexAttributeDescriptions = attributes.GetData(); - IFileHandle *pFile = filesystem->Open(szVertexShader, FILEMODE_READ); - vertexShaderData = filesystem->Read(pFile); - pFile->Close(); - - stVertexModule.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - stVertexModule.codeSize = vertexShaderData.GetSize(); - stVertexModule.pCode = (uint32_t*)vertexShaderData.GetMemory(); - - stVertexStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - stVertexStage.pName = szVertexShaderMain; - stVertexStage.pNext = &stVertexModule; - } - - CUtlBuffer pixelShaderData; - VkShaderModuleCreateInfo stPixelModule = {}; - VkPipelineShaderStageCreateInfo stPixelStage = {}; - if (szPixelShader) - { - - IFileHandle *pFile = filesystem->Open(szPixelShader, FILEMODE_READ); - pixelShaderData = filesystem->Read(pFile); - pFile->Close(); - - stPixelModule.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - stPixelModule.codeSize = pixelShaderData.GetSize(); - stPixelModule.pCode = (uint32_t*)pixelShaderData.GetMemory(); - - stPixelStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - stPixelStage.pName = szPixelShaderMain; - stPixelStage.pNext = &stPixelModule; - } + pipeline.pVertexInputState = &vertexInput; END_BUILD_PIPELINE_LIBRARY() -void CVkFunctionsPipelineLibrary::SetVertex( const char *szFile, const char *szMain ) + +void CVkVertexDescriptionPipelineLibrary::AddLayout( int iIndex, int iStride ) { - szVertexShader = szFile; - szVertexShaderMain = szMain; + VkVertexInputBindingDescription layout = {}; + layout.binding = iIndex; + layout.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; + layout.stride = iStride; + layouts.AppendTail(layout); } -void CVkFunctionsPipelineLibrary::SetPixel( const char *szFile, const char *szMain ) +void CVkVertexDescriptionPipelineLibrary::AddAttribute( int iBufferIndex, int iLocation, EVertexFormat eFormat, int iOffset ) { - szPixelShader = szFile; - szPixelShaderMain = szMain; + VkVertexInputAttributeDescription attribute = {}; + attribute.binding = iBufferIndex; + attribute.location = iLocation; + attribute.format = VulkanGetVertexFormat(eFormat); + attribute.offset = iOffset; + attributes.AppendTail(attribute); } +void CVkVertexDescriptionPipelineLibrary::SetTopology( ETopologyMode eTopology ) +{ + +} diff --git a/materialsystem/vulkan/raster_libraries.h b/materialsystem/vulkan/raster_libraries.h index c16b698..410eff4 100644 --- a/materialsystem/vulkan/raster_libraries.h +++ b/materialsystem/vulkan/raster_libraries.h @@ -1,36 +1,21 @@ +#include "materialsystem/imaterialsystem.h" +#include "tier1/utlvector.h" #include "vulkan_state.h" -BEGIN_DEFINE_PIPELINE_LIBRARY(Functions) -private: - const char *szVertexShader; - const char *szVertexShaderMain; - const char *szPixelShader; - const char *szPixelShaderMain; -public: - void SetVertex( const char *szFile, const char *szMain ); - void SetPixel( const char *szFile, const char *szMain ); +BEGIN_DEFINE_PIPELINE_LIBRARY(VertexDescription) + void AddLayout( int iIndex, int iStride ); + void AddAttribute( int iBufferIndex, int iLocation, EVertexFormat eFormat, int iOffset ); + void SetTopology( ETopologyMode eTopology ); + + CUtlVector attributes; + CUtlVector layouts; END_DEFINE_PIPELINE_LIBRARY() -BEGIN_DEFINE_PIPELINE_LIBRARY(VertexInput) +BEGIN_DEFINE_PIPELINE_LIBRARY(VertexTransform) END_DEFINE_PIPELINE_LIBRARY() -BEGIN_DEFINE_PIPELINE_LIBRARY(InputAssembly) +BEGIN_DEFINE_PIPELINE_LIBRARY(PixelShade) END_DEFINE_PIPELINE_LIBRARY() -BEGIN_DEFINE_PIPELINE_LIBRARY(Tesselation) -END_DEFINE_PIPELINE_LIBRARY() - -BEGIN_DEFINE_PIPELINE_LIBRARY(ViewportState) -END_DEFINE_PIPELINE_LIBRARY() - -BEGIN_DEFINE_PIPELINE_LIBRARY(RasterizationState) -END_DEFINE_PIPELINE_LIBRARY() - -BEGIN_DEFINE_PIPELINE_LIBRARY(MultisampleState) -END_DEFINE_PIPELINE_LIBRARY() - -BEGIN_DEFINE_PIPELINE_LIBRARY(DepthStencilState) -END_DEFINE_PIPELINE_LIBRARY() - -BEGIN_DEFINE_PIPELINE_LIBRARY(ColorBlend) +BEGIN_DEFINE_PIPELINE_LIBRARY(PixelOutput) END_DEFINE_PIPELINE_LIBRARY() diff --git a/materialsystem/vulkan/rendercontext.cpp b/materialsystem/vulkan/rendercontext.cpp index 001e674..16fd159 100644 --- a/materialsystem/vulkan/rendercontext.cpp +++ b/materialsystem/vulkan/rendercontext.cpp @@ -429,10 +429,15 @@ void CVkRenderContext::Init() stDeviceQueueCreateInfo.queueCount = 1; stDeviceQueueCreateInfo.pQueuePriorities = &fPriority; stDeviceQueueCreateInfo.queueFamilyIndex = g_iDrawFamily; + + VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT gplFeatures = {}; + gplFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GRAPHICS_PIPELINE_LIBRARY_FEATURES_EXT; + gplFeatures.graphicsPipelineLibrary = VK_TRUE; VkPhysicalDeviceVulkan13Features vk13Features = {}; vk13Features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES; vk13Features.synchronization2 = VK_TRUE; + vk13Features.pNext = &gplFeatures; stDeviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; stDeviceCreateInfo.queueCreateInfoCount = 1; @@ -475,9 +480,10 @@ void CVkRenderContext::Init() pCommand->g = 0; pCommand->AddSwapchainDependency( (IRenderingObject**)g_vkSwapchainImages.GetData(), DEPENDENCY_MODE_COLOR_CLEAR_DESTINATION ); - CVkFunctionsPipelineLibrary functions = {}; - functions.SetVertex("funnygame/shaders/flat.spv", "vsMain"); - functions.SetPixel("funnygame/shaders/flat.spv", "psMain"); + CVkVertexDescriptionPipelineLibrary functions = {}; + functions.AddAttribute(0, 0, VERTEX_FORMAT_XYZ32_SFLOAT, 0); + functions.AddLayout(0, 12); + functions.SetTopology(TOPOLOGY_MODE_TRIANGLE_LIST); functions.Build(); CVkEmptyCommand *pPresentCommand = (CVkEmptyCommand*)g_pCommandBufferManager->CreateCommand("Empty"); diff --git a/materialsystem/vulkan/utils.cpp b/materialsystem/vulkan/utils.cpp index 5fe89f8..8aa2ec8 100644 --- a/materialsystem/vulkan/utils.cpp +++ b/materialsystem/vulkan/utils.cpp @@ -48,3 +48,15 @@ VkImageLayout VulkanGetImageLayout( EDependencyMode eMode ) return VK_IMAGE_LAYOUT_UNDEFINED; } } +VkFormat VulkanGetVertexFormat( EVertexFormat eFormat ) +{ + switch (eFormat) + { + case VERTEX_FORMAT_X32_SFLOAT: return VK_FORMAT_R32_SFLOAT; + case VERTEX_FORMAT_XY32_SFLOAT: return VK_FORMAT_R32G32_SFLOAT; + case VERTEX_FORMAT_XYZ32_SFLOAT: return VK_FORMAT_R32G32B32_SFLOAT; + case VERTEX_FORMAT_XYZW32_SFLOAT: return VK_FORMAT_R32G32B32A32_SFLOAT; + default: + return VK_FORMAT_UNDEFINED; + } +} diff --git a/materialsystem/vulkan/vulkan_state.h b/materialsystem/vulkan/vulkan_state.h index dfd96cf..a5cab19 100644 --- a/materialsystem/vulkan/vulkan_state.h +++ b/materialsystem/vulkan/vulkan_state.h @@ -232,7 +232,11 @@ public: \ void CVk##name##PipelineLibrary::Build() \ { \ VkGraphicsPipelineCreateInfo pipeline = {}; \ + VkGraphicsPipelineLibraryCreateInfoEXT library = {}; \ pipeline.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; \ + library.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT; \ + pipeline.pNext = &library; \ + pipeline.flags = VK_PIPELINE_CREATE_LIBRARY_BIT_KHR; \ #define END_BUILD_PIPELINE_LIBRARY() \ vkCreateGraphicsPipelines(g_vkDevice, NULL, 1, &pipeline, NULL, &m_hPipeline); \ @@ -263,11 +267,10 @@ struct VkFrameObject_t }; }; - IRenderingObject *VulkanGetObject( VkFrameObject_t stObject, int iIndex ); VkAccessFlags2 VulkanGetAccessFlags( EDependencyMode eMode ); VkPipelineStageFlags2 VulkanGetStageFlags( EDependencyMode eMode ); VkImageLayout VulkanGetImageLayout( EDependencyMode eMode ); - +VkFormat VulkanGetVertexFormat( EVertexFormat eFormat ); #endif diff --git a/public/materialsystem/imaterialsystem.h b/public/materialsystem/imaterialsystem.h index d3123d6..4058602 100644 --- a/public/materialsystem/imaterialsystem.h +++ b/public/materialsystem/imaterialsystem.h @@ -19,6 +19,14 @@ enum EImageFormat IMAGE_FORMAT_WINDOW, }; +enum EVertexFormat +{ + VERTEX_FORMAT_X32_SFLOAT, + VERTEX_FORMAT_XY32_SFLOAT, + VERTEX_FORMAT_XYZ32_SFLOAT, + VERTEX_FORMAT_XYZW32_SFLOAT, +}; + enum EImageType { IMAGE_TYPE_1D, @@ -69,6 +77,7 @@ enum ETopologyMode TOPOLOGY_MODE_TRIANGLE_STRIP, }; + abstract_class IRenderingObject { public: