some fixes

This commit is contained in:
2025-12-16 00:27:23 +02:00
parent dd1a51b752
commit ccaf7f7b65
6 changed files with 76 additions and 75 deletions

View File

@@ -1,57 +1,43 @@
#include "../vulkan_state.h" #include "../vulkan_state.h"
#include "../raster_libraries.h" #include "../raster_libraries.h"
#include "tier1/utlbuffer.h" #include "tier1/utlbuffer.h"
#include "tier1/utlvector.h"
#include "tier2/ifilesystem.h" #include "tier2/ifilesystem.h"
#include "vulkan/vulkan_core.h" #include "vulkan/vulkan_core.h"
BEGIN_BUILD_PIPELINE_LIBRARY(Functions) BEGIN_BUILD_PIPELINE_LIBRARY(VertexDescription)
CUtlBuffer<unsigned char> vertexShaderData; library.flags = VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT;
VkShaderModuleCreateInfo stVertexModule = {};
VkPipelineShaderStageCreateInfo stVertexStage = {};
if (szVertexShader)
{
IFileHandle *pFile = filesystem->Open(szVertexShader, FILEMODE_READ); VkPipelineVertexInputStateCreateInfo vertexInput = {};
vertexShaderData = filesystem->Read(pFile); vertexInput.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
pFile->Close(); vertexInput.vertexBindingDescriptionCount = layouts.GetSize();
vertexInput.pVertexBindingDescriptions = layouts.GetData();
vertexInput.vertexAttributeDescriptionCount = attributes.GetSize();
vertexInput.pVertexAttributeDescriptions = attributes.GetData();
stVertexModule.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; pipeline.pVertexInputState = &vertexInput;
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<unsigned char> 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;
}
END_BUILD_PIPELINE_LIBRARY() END_BUILD_PIPELINE_LIBRARY()
void CVkFunctionsPipelineLibrary::SetVertex( const char *szFile, const char *szMain )
void CVkVertexDescriptionPipelineLibrary::AddLayout( int iIndex, int iStride )
{ {
szVertexShader = szFile; VkVertexInputBindingDescription layout = {};
szVertexShaderMain = szMain; 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; VkVertexInputAttributeDescription attribute = {};
szPixelShaderMain = szMain; attribute.binding = iBufferIndex;
attribute.location = iLocation;
attribute.format = VulkanGetVertexFormat(eFormat);
attribute.offset = iOffset;
attributes.AppendTail(attribute);
} }
void CVkVertexDescriptionPipelineLibrary::SetTopology( ETopologyMode eTopology )
{
}

View File

@@ -1,36 +1,21 @@
#include "materialsystem/imaterialsystem.h"
#include "tier1/utlvector.h"
#include "vulkan_state.h" #include "vulkan_state.h"
BEGIN_DEFINE_PIPELINE_LIBRARY(Functions) BEGIN_DEFINE_PIPELINE_LIBRARY(VertexDescription)
private: void AddLayout( int iIndex, int iStride );
const char *szVertexShader; void AddAttribute( int iBufferIndex, int iLocation, EVertexFormat eFormat, int iOffset );
const char *szVertexShaderMain; void SetTopology( ETopologyMode eTopology );
const char *szPixelShader;
const char *szPixelShaderMain; CUtlVector<VkVertexInputAttributeDescription> attributes;
public: CUtlVector<VkVertexInputBindingDescription> layouts;
void SetVertex( const char *szFile, const char *szMain );
void SetPixel( const char *szFile, const char *szMain );
END_DEFINE_PIPELINE_LIBRARY() END_DEFINE_PIPELINE_LIBRARY()
BEGIN_DEFINE_PIPELINE_LIBRARY(VertexInput) BEGIN_DEFINE_PIPELINE_LIBRARY(VertexTransform)
END_DEFINE_PIPELINE_LIBRARY() END_DEFINE_PIPELINE_LIBRARY()
BEGIN_DEFINE_PIPELINE_LIBRARY(InputAssembly) BEGIN_DEFINE_PIPELINE_LIBRARY(PixelShade)
END_DEFINE_PIPELINE_LIBRARY() END_DEFINE_PIPELINE_LIBRARY()
BEGIN_DEFINE_PIPELINE_LIBRARY(Tesselation) BEGIN_DEFINE_PIPELINE_LIBRARY(PixelOutput)
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)
END_DEFINE_PIPELINE_LIBRARY() END_DEFINE_PIPELINE_LIBRARY()

View File

@@ -430,9 +430,14 @@ void CVkRenderContext::Init()
stDeviceQueueCreateInfo.pQueuePriorities = &fPriority; stDeviceQueueCreateInfo.pQueuePriorities = &fPriority;
stDeviceQueueCreateInfo.queueFamilyIndex = g_iDrawFamily; stDeviceQueueCreateInfo.queueFamilyIndex = g_iDrawFamily;
VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT gplFeatures = {};
gplFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GRAPHICS_PIPELINE_LIBRARY_FEATURES_EXT;
gplFeatures.graphicsPipelineLibrary = VK_TRUE;
VkPhysicalDeviceVulkan13Features vk13Features = {}; VkPhysicalDeviceVulkan13Features vk13Features = {};
vk13Features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES; vk13Features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
vk13Features.synchronization2 = VK_TRUE; vk13Features.synchronization2 = VK_TRUE;
vk13Features.pNext = &gplFeatures;
stDeviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; stDeviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
stDeviceCreateInfo.queueCreateInfoCount = 1; stDeviceCreateInfo.queueCreateInfoCount = 1;
@@ -475,9 +480,10 @@ void CVkRenderContext::Init()
pCommand->g = 0; pCommand->g = 0;
pCommand->AddSwapchainDependency( (IRenderingObject**)g_vkSwapchainImages.GetData(), DEPENDENCY_MODE_COLOR_CLEAR_DESTINATION ); pCommand->AddSwapchainDependency( (IRenderingObject**)g_vkSwapchainImages.GetData(), DEPENDENCY_MODE_COLOR_CLEAR_DESTINATION );
CVkFunctionsPipelineLibrary functions = {}; CVkVertexDescriptionPipelineLibrary functions = {};
functions.SetVertex("funnygame/shaders/flat.spv", "vsMain"); functions.AddAttribute(0, 0, VERTEX_FORMAT_XYZ32_SFLOAT, 0);
functions.SetPixel("funnygame/shaders/flat.spv", "psMain"); functions.AddLayout(0, 12);
functions.SetTopology(TOPOLOGY_MODE_TRIANGLE_LIST);
functions.Build(); functions.Build();
CVkEmptyCommand *pPresentCommand = (CVkEmptyCommand*)g_pCommandBufferManager->CreateCommand("Empty"); CVkEmptyCommand *pPresentCommand = (CVkEmptyCommand*)g_pCommandBufferManager->CreateCommand("Empty");

View File

@@ -48,3 +48,15 @@ VkImageLayout VulkanGetImageLayout( EDependencyMode eMode )
return VK_IMAGE_LAYOUT_UNDEFINED; 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;
}
}

View File

@@ -232,7 +232,11 @@ public: \
void CVk##name##PipelineLibrary::Build() \ void CVk##name##PipelineLibrary::Build() \
{ \ { \
VkGraphicsPipelineCreateInfo pipeline = {}; \ VkGraphicsPipelineCreateInfo pipeline = {}; \
VkGraphicsPipelineLibraryCreateInfoEXT library = {}; \
pipeline.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; \ 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() \ #define END_BUILD_PIPELINE_LIBRARY() \
vkCreateGraphicsPipelines(g_vkDevice, NULL, 1, &pipeline, NULL, &m_hPipeline); \ vkCreateGraphicsPipelines(g_vkDevice, NULL, 1, &pipeline, NULL, &m_hPipeline); \
@@ -263,11 +267,10 @@ struct VkFrameObject_t
}; };
}; };
IRenderingObject *VulkanGetObject( VkFrameObject_t stObject, int iIndex ); IRenderingObject *VulkanGetObject( VkFrameObject_t stObject, int iIndex );
VkAccessFlags2 VulkanGetAccessFlags( EDependencyMode eMode ); VkAccessFlags2 VulkanGetAccessFlags( EDependencyMode eMode );
VkPipelineStageFlags2 VulkanGetStageFlags( EDependencyMode eMode ); VkPipelineStageFlags2 VulkanGetStageFlags( EDependencyMode eMode );
VkImageLayout VulkanGetImageLayout( EDependencyMode eMode ); VkImageLayout VulkanGetImageLayout( EDependencyMode eMode );
VkFormat VulkanGetVertexFormat( EVertexFormat eFormat );
#endif #endif

View File

@@ -19,6 +19,14 @@ enum EImageFormat
IMAGE_FORMAT_WINDOW, IMAGE_FORMAT_WINDOW,
}; };
enum EVertexFormat
{
VERTEX_FORMAT_X32_SFLOAT,
VERTEX_FORMAT_XY32_SFLOAT,
VERTEX_FORMAT_XYZ32_SFLOAT,
VERTEX_FORMAT_XYZW32_SFLOAT,
};
enum EImageType enum EImageType
{ {
IMAGE_TYPE_1D, IMAGE_TYPE_1D,
@@ -69,6 +77,7 @@ enum ETopologyMode
TOPOLOGY_MODE_TRIANGLE_STRIP, TOPOLOGY_MODE_TRIANGLE_STRIP,
}; };
abstract_class IRenderingObject abstract_class IRenderingObject
{ {
public: public: