From b3b8de4adb20fec075cd31f0f22c4f46555eced7 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 18 Sep 2020 20:44:11 +0800 Subject: [PATCH] use VKPipelineData instead VKPipelineCreater --- CMCore | 2 +- CMSceneGraph | 2 +- example/Vulkan/Atomsphere.cpp | 15 +- inc/hgl/graph/vulkan/VKPipeline.h | 173 +------------ inc/hgl/graph/vulkan/VKPrimivate.h | 28 --- src/RenderDevice/Vulkan/CMakeLists.txt | 5 +- .../Vulkan/POD/VKPipelineCreateInfo.POD.cpp | 150 ------------ src/RenderDevice/Vulkan/VKPipeline.cpp | 228 ++---------------- .../Vulkan/{POD => }/VKTextureLoader.cpp | 0 9 files changed, 30 insertions(+), 573 deletions(-) delete mode 100644 inc/hgl/graph/vulkan/VKPrimivate.h delete mode 100644 src/RenderDevice/Vulkan/POD/VKPipelineCreateInfo.POD.cpp rename src/RenderDevice/Vulkan/{POD => }/VKTextureLoader.cpp (100%) diff --git a/CMCore b/CMCore index 6f124926..2aadf900 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 6f1249263e97c2c88fb69d0c277e24d887fd32cb +Subproject commit 2aadf9005ca099d8c72f745c547d610022a79d0b diff --git a/CMSceneGraph b/CMSceneGraph index 384727bf..b816297b 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit 384727bf3ed298d9aaaa2454afa910568039f1ff +Subproject commit b816297b8811a1a078819f02b740c05576ae5daf diff --git a/example/Vulkan/Atomsphere.cpp b/example/Vulkan/Atomsphere.cpp index f857e9e0..bf61f672 100644 --- a/example/Vulkan/Atomsphere.cpp +++ b/example/Vulkan/Atomsphere.cpp @@ -86,13 +86,14 @@ private: bool InitPipeline() { - AutoDelete - pipeline_creater=new vulkan::PipelineCreater(device,material); - pipeline_creater->SetDepthTest(true); - pipeline_creater->SetDepthWrite(true); - pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); - pipeline_creater->Set(Prim::Triangles); - pipeline_solid=pipeline_creater->Create(sc_render_target); + vulkan::VKPipelineData pd; + + pd.SetDepthTest(true); + pd.SetDepthWrite(true); + pd.SetCullMode(VK_CULL_MODE_NONE); + pd.Set(Prim::Triangles); + + pipeline_solid=CreatePipeline(device,&pd,material,sc_render_target); if(!pipeline_solid) return(false); diff --git a/inc/hgl/graph/vulkan/VKPipeline.h b/inc/hgl/graph/vulkan/VKPipeline.h index 0f8182b7..15c9ae11 100644 --- a/inc/hgl/graph/vulkan/VKPipeline.h +++ b/inc/hgl/graph/vulkan/VKPipeline.h @@ -2,6 +2,7 @@ #define HGL_GRAPH_VULKAN_PIPELINE_INCLUDE #include +#include #include VK_NAMESPACE_BEGIN class Pipeline @@ -23,176 +24,6 @@ public: const bool IsAlphaBlend()const{return alpha_blend;} };//class GraphicsPipeline -constexpr size_t MAX_SAMPLE_MASK_COUNT=(VK_SAMPLE_COUNT_64_BIT+31)/32; - -#ifndef VK_DYNAMIC_STATE_BEGIN_RANGE -constexpr size_t VK_DYNAMIC_STATE_BEGIN_RANGE=VK_DYNAMIC_STATE_VIEWPORT; -#endif//VK_DYNAMIC_STATE_BEGIN_RANGE - -#ifndef VK_DYNAMIC_STATE_END_RANGE -constexpr size_t VK_DYNAMIC_STATE_END_RANGE=VK_DYNAMIC_STATE_STENCIL_REFERENCE; -#endif//VK_DYNAMIC_STATE_END_RANGE - -#ifndef VK_DYNAMIC_STATE_RANGE_SIZE -constexpr size_t VK_DYNAMIC_STATE_RANGE_SIZE=VK_DYNAMIC_STATE_END_RANGE-VK_DYNAMIC_STATE_BEGIN_RANGE+1; -#endif//VK_DYNAMIC_STATE_RANGE_SIZE - -class PipelineCreater -{ - VkDevice device; - VkPipelineCache cache; - VkGraphicsPipelineCreateInfo pipelineInfo; - - VkPipelineVertexInputStateCreateInfo vis_create_info; - - void InitVertexInputState(const Material *); - - VkPipelineInputAssemblyStateCreateInfo inputAssembly; - VkPipelineTessellationStateCreateInfo tessellation; - - VkViewport viewport; - VkRect2D scissor; - VkPipelineViewportStateCreateInfo viewportState; - - void InitViewportState(const VkExtent2D &); - - VkPipelineRasterizationStateCreateInfo rasterizer; - - VkPipelineMultisampleStateCreateInfo multisample; - VkSampleMask sample_mask[MAX_SAMPLE_MASK_COUNT]; - - VkPipelineDepthStencilStateCreateInfo depthStencilState; - - VkPipelineColorBlendStateCreateInfo colorBlending; - List colorBlendAttachments; - - VkDynamicState dynamicStateEnables[VK_DYNAMIC_STATE_RANGE_SIZE]; - VkPipelineDynamicStateCreateInfo dynamicState; - - void InitDynamicState(); - - float alpha_test=0; - bool alpha_blend=false; - -public: - - PipelineCreater(Device *dev,const Material *,const uint32_t color_attachment_count=1); - PipelineCreater(Device *dev,const Material *,uchar *data,uint size); - ~PipelineCreater()=default; - - bool Set(const Prim prim,bool=false); - - void SetViewport( float x,float y,float w,float h){viewport.x=x;viewport.y=y;viewport.width=w;viewport.height=h;} - void SetDepthRange( float min_depth,float max_depth){viewport.minDepth=min_depth;viewport.maxDepth=max_depth;} - void SetScissor( float l,float t,float w,float h){scissor.offset.x=l;scissor.offset.y=t;scissor.extent.width=w;scissor.extent.height=h;} - - void SetAlphaTest( const float at) {alpha_test=at;} - - void SetDepthTest( bool dt) {depthStencilState.depthTestEnable=dt;} - void SetDepthWrite( bool dw) {depthStencilState.depthWriteEnable=dw;} - void SetDepthCompareOp( VkCompareOp op) {depthStencilState.depthCompareOp=op;} - void SetDepthBoundsTest(bool dbt) {depthStencilState.depthBoundsTestEnable=dbt;} - void SetDepthBounds( float min_depth, - float max_depth) {depthStencilState.depthBoundsTestEnable=VK_TRUE; - depthStencilState.minDepthBounds=min_depth; - depthStencilState.maxDepthBounds=max_depth;} - void SetStencilTest( bool st) {depthStencilState.stencilTestEnable=st;} - - void SetDepthClamp( bool dc) {rasterizer.depthClampEnable=dc;} - void SetDiscard( bool discard) {rasterizer.rasterizerDiscardEnable=discard;} - void SetPolygonMode( VkPolygonMode pm) {rasterizer.polygonMode =pm;} - void SetCullMode( VkCullModeFlagBits cm) {rasterizer.cullMode =cm;} - void CloseCullFace() {rasterizer.cullMode =VK_CULL_MODE_NONE;} - void SetFrontFace( VkFrontFace ff) {rasterizer.frontFace =ff;} - void SetDepthBias( float ConstantFactor, - float Clamp, - float SlopeFactor) - { - rasterizer.depthBiasEnable =VK_TRUE; - rasterizer.depthBiasConstantFactor =ConstantFactor; - rasterizer.depthBiasClamp =Clamp; - rasterizer.depthBiasSlopeFactor =SlopeFactor; - } - void DisableDepthBias() {rasterizer.depthBiasEnable=VK_FALSE;} - void SetLineWidth( float line_width) {rasterizer.lineWidth =line_width;} - - void SetSamleCount( VkSampleCountFlagBits sc) - { - multisample.sampleShadingEnable=(sc==VK_SAMPLE_COUNT_1_BIT?VK_FALSE:VK_TRUE); - multisample.rasterizationSamples=sc; - } - - bool SetColorWriteMask(uint index,bool r,bool g,bool b,bool a) - { - VkPipelineColorBlendAttachmentState *cba=colorBlendAttachments.GetPointer(index); - - if(!cba)return(false); - - cba->colorWriteMask=0; - - if(r)cba->colorWriteMask|=VK_COLOR_COMPONENT_R_BIT; - if(r)cba->colorWriteMask|=VK_COLOR_COMPONENT_G_BIT; - if(g)cba->colorWriteMask|=VK_COLOR_COMPONENT_B_BIT; - if(a)cba->colorWriteMask|=VK_COLOR_COMPONENT_A_BIT; - - return(true); - } - - void AddColorBlendAttachment(const VkPipelineColorBlendAttachmentState *cba) - { - if(!cba)return; - - colorBlendAttachments.Add(*cba); - colorBlending.attachmentCount=colorBlendAttachments.GetCount(); - - if(cba->blendEnable) - alpha_blend=true; - } - - bool SetBlend(uint index,bool blend) - { - VkPipelineColorBlendAttachmentState *cba=colorBlendAttachments.GetPointer(index); - - if(!cba)return(false); - - cba->blendEnable=blend; - - if(blend) - alpha_blend=true; - else - { - cba=colorBlendAttachments.GetData(); - - for(int i=0;iblendEnable) - { - alpha_blend=true; - return(true); - } - - alpha_blend=false; - } - - return(true); - } - - void SetLogicOp(VkLogicOp logic_op) {colorBlending.logicOpEnable=VK_TRUE;colorBlending.logicOp=logic_op;} - void DisableLogicOp() {colorBlending.logicOpEnable=VK_FALSE;} - - void SetBlendConstans(float r,float g,float b,float a) - { - colorBlending.blendConstants[0] = r; - colorBlending.blendConstants[1] = g; - colorBlending.blendConstants[2] = b; - colorBlending.blendConstants[3] = a; - } - - void SetBlendConstans(float *blend_constans) {hgl_typecpy(colorBlending.blendConstants,blend_constans,4);} - - bool SaveToStream(io::DataOutputStream *dos); - bool LoadFromMemory(uchar *,uint); - - Pipeline *Create(const RenderTarget *); -};//class PipelineCreater +Pipeline *CreatePipeline(Device *dev,VKPipelineData *,const Material *material,const RenderTarget *); VK_NAMESPACE_END #endif//HGL_GRAPH_VULKAN_PIPELINE_INCLUDE diff --git a/inc/hgl/graph/vulkan/VKPrimivate.h b/inc/hgl/graph/vulkan/VKPrimivate.h deleted file mode 100644 index 36056f33..00000000 --- a/inc/hgl/graph/vulkan/VKPrimivate.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE -#define HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE - -#include - -/** - * 图元类型枚举 - */ -enum class Prim -{ - Points=0, ///<点 - Lines, ///<线 - LineStrip, ///<连续线 - Triangles, ///<三角形 - TriangleStrip, ///<三角形条 - Fan, ///<扇形 - LinesAdj, ///<代表一个有四个顶点的Primitive,其中第二个点与第三个点会形成线段,而第一个点与第四个点则用来提供2,3邻近点的信息. - LineStripAdj, ///<与LINES_ADJACENCY类似,第一个点跟最后一个点提供信息,剩下的点则跟Line Strip一样形成线段. - TrianglesAdj, ///<代表一个有六个顶点的Primitive,其中第1,3,5个顶点代表一个Triangle,而地2,4,6个点提供邻近信息.(由1起算) - TriangleStripAdj, ///<4+2N个Vertices代表N个Primitive,其中1,3,5,7,9...代表原本的Triangle strip形成Triangle,而2,4,6,8,10...代表邻近提供信息的点.(由1起算) - Patchs, - - Rectangles=0x100, ///<矩形(并非原生支持。以画点形式在每个点的Position中传递Left,Top,Width,Height。在Geometry Shader中转换为2个三角形。用于2D游戏或UI) - - ENUM_CLASS_RANGE(Points,Patchs) -};// - -#endif//HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE diff --git a/src/RenderDevice/Vulkan/CMakeLists.txt b/src/RenderDevice/Vulkan/CMakeLists.txt index cba578d3..aaf9444c 100644 --- a/src/RenderDevice/Vulkan/CMakeLists.txt +++ b/src/RenderDevice/Vulkan/CMakeLists.txt @@ -57,7 +57,7 @@ SET(VK_TEXTURE_SOURCE ${RD_INCLUDE_PATH}/VKImageView.h VKSampler.cpp VKImageView.cpp VKTexture.cpp - POD/VKTextureLoader.cpp) + VKTextureLoader.cpp) SET(VK_MATERIAL_SOURCE ${RD_INCLUDE_PATH}/VKMaterial.h ${RD_INCLUDE_PATH}/VKMaterialInstance.h @@ -83,8 +83,7 @@ SET(VK_RENDER_PASS_SOURCE ${RD_INCLUDE_PATH}/VKFramebuffer.h VKRenderPass.cpp VKRenderTarget.cpp VKSwapchain.cpp - VKCommandBuffer.cpp - POD/VKPipelineCreateInfo.POD.cpp) + VKCommandBuffer.cpp) SOURCE_GROUP("Render Pass" FILES ${VK_RENDER_PASS_SOURCE}) diff --git a/src/RenderDevice/Vulkan/POD/VKPipelineCreateInfo.POD.cpp b/src/RenderDevice/Vulkan/POD/VKPipelineCreateInfo.POD.cpp deleted file mode 100644 index a623d473..00000000 --- a/src/RenderDevice/Vulkan/POD/VKPipelineCreateInfo.POD.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -using namespace hgl; - -VK_NAMESPACE_BEGIN - -#define WRITE_AND_CHECK_SIZE(ptr,type) if(dos->Write(ptr,sizeof(type))!=sizeof(type))return(false); - -bool PipelineCreater::SaveToStream(io::DataOutputStream *dos) -{ - if(!dos)return(false); - - if(!dos->WriteUint16(1))return(false); //file ver - - WRITE_AND_CHECK_SIZE(&pipelineInfo,VkGraphicsPipelineCreateInfo); - WRITE_AND_CHECK_SIZE(pipelineInfo.pInputAssemblyState, VkPipelineInputAssemblyStateCreateInfo ); - WRITE_AND_CHECK_SIZE(pipelineInfo.pTessellationState, VkPipelineTessellationStateCreateInfo ); - WRITE_AND_CHECK_SIZE(pipelineInfo.pRasterizationState, VkPipelineRasterizationStateCreateInfo ); - - WRITE_AND_CHECK_SIZE(pipelineInfo.pMultisampleState, VkPipelineMultisampleStateCreateInfo ); - if(pipelineInfo.pMultisampleState->pSampleMask) - { - const uint count=(pipelineInfo.pMultisampleState->rasterizationSamples+31)/32; - if(!dos->WriteUint8(count))return(false); - if(dos->WriteUint32(pipelineInfo.pMultisampleState->pSampleMask,count)!=count)return(false); - } - else - { - if(!dos->WriteUint8(0))return(false); - } - - WRITE_AND_CHECK_SIZE(pipelineInfo.pDepthStencilState, VkPipelineDepthStencilStateCreateInfo); - - WRITE_AND_CHECK_SIZE(pipelineInfo.pColorBlendState, VkPipelineColorBlendStateCreateInfo); - for(uint32_t i=0;iattachmentCount;i++) - WRITE_AND_CHECK_SIZE(pipelineInfo.pColorBlendState->pAttachments+i,VkPipelineColorBlendAttachmentState); - - if(!dos->WriteFloat(alpha_test))return(false); - - return(true); -} - -#define CHECK_SIZE_AND_COPY(ptr,type) if(size0) - { - memcpy(sample_mask,data,count); - multisample.pSampleMask=sample_mask; - data+=count; - size=count; - } - else - { - multisample.pSampleMask=nullptr; - } - - CHECK_SIZE_AND_COPY(depthStencilState,VkPipelineDepthStencilStateCreateInfo); - CHECK_SIZE_AND_COPY(colorBlending,VkPipelineColorBlendStateCreateInfo); - - if(colorBlending.attachmentCount>0) - { - if(sizeblendEnable) - alpha_blend=true; - - ++cba; - } - } - else - { - colorBlending.pAttachments=nullptr; - alpha_blend=false; - } - - CHECK_SIZE_AND_COPY(alpha_test,float); - - return(true); -} -VK_NAMESPACE_END - -bool SaveToFile(const OSString &filename,VK_NAMESPACE::PipelineCreater *pc) -{ - if(filename.IsEmpty()||!pc) - return(false); - - io::MemoryOutputStream mos; - io::DataOutputStream *dos=new io::LEDataOutputStream(&mos); - - pc->SaveToStream(dos); - - delete dos; - - filesystem::SaveMemoryToFile(filename,mos.GetData(),mos.Tell()); - - return(true); -} - -bool LoadFromFile(const OSString &filename,VK_NAMESPACE::PipelineCreater *pc) -{ - if(filename.IsEmpty()||!pc) - return(false); - - char *data; - uint size=filesystem::LoadFileToMemory(filename,(void **)&data); - - bool result=pc->LoadFromMemory((uchar *)data,size); - - delete[] data; - return result; -} diff --git a/src/RenderDevice/Vulkan/VKPipeline.cpp b/src/RenderDevice/Vulkan/VKPipeline.cpp index ee62313a..7564b33b 100644 --- a/src/RenderDevice/Vulkan/VKPipeline.cpp +++ b/src/RenderDevice/Vulkan/VKPipeline.cpp @@ -11,226 +11,30 @@ Pipeline::~Pipeline() vkDestroyPipeline(device,pipeline,nullptr); } -void PipelineCreater::InitVertexInputState(const Material *material) -{ - pipelineInfo.stageCount = material->GetStageCount(); - pipelineInfo.pStages = material->GetStages(); - - { - vis_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vis_create_info.pNext = nullptr; - vis_create_info.flags = 0; - - material->Write(vis_create_info); - - pipelineInfo.pVertexInputState=&vis_create_info; - } -} - -void PipelineCreater::InitViewportState(const VkExtent2D &extent) -{ - viewport.x = 0.0f; - viewport.y = 0.0f; - viewport.width = extent.width; - viewport.height = extent.height; - viewport.minDepth = 0.0f; - viewport.maxDepth = 1.0f; - - scissor.offset = {0, 0}; - scissor.extent = extent; - - viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; - viewportState.pNext = nullptr; - viewportState.flags = 0; - viewportState.viewportCount = 1; - viewportState.pViewports = &viewport; - viewportState.scissorCount = 1; - viewportState.pScissors = &scissor; - - pipelineInfo.pViewportState = &viewportState; -} - -void PipelineCreater::InitDynamicState() -{ - memset(dynamicStateEnables, 0, sizeof dynamicStateEnables); - - dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamicState.pNext = nullptr; - dynamicState.flags = 0; - dynamicState.pDynamicStates = dynamicStateEnables; - dynamicState.dynamicStateCount = 0; - dynamicStateEnables[dynamicState.dynamicStateCount++] = VK_DYNAMIC_STATE_VIEWPORT; - dynamicStateEnables[dynamicState.dynamicStateCount++] = VK_DYNAMIC_STATE_SCISSOR; - dynamicStateEnables[dynamicState.dynamicStateCount++] = VK_DYNAMIC_STATE_LINE_WIDTH; - - //如果窗口大小不变,可以不设置这两个。能不能提升效能未知 - - pipelineInfo.pDynamicState=&dynamicState; -} - -//为什么一定要把ext放在这里,因为如果不放在这里,总是会让人遗忘它的重要性 - -PipelineCreater::PipelineCreater(Device *dev,const Material *material,const uint32_t color_attachment_count) -{ - device=dev->GetDevice(); - cache=dev->GetPipelineCache(); - - //未来这里需要增加是否有vs/fs的检测 - - hgl_zero(pipelineInfo); - pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - InitVertexInputState(material); - - tessellation.sType=VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; - tessellation.pNext=nullptr; - tessellation.flags=0; - tessellation.patchControlPoints=0; - - pipelineInfo.pTessellationState=&tessellation; - - rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - rasterizer.pNext = nullptr; - rasterizer.flags = 0; - rasterizer.depthClampEnable = VK_FALSE; - rasterizer.rasterizerDiscardEnable = VK_FALSE; - rasterizer.polygonMode = VK_POLYGON_MODE_FILL; - rasterizer.cullMode = VK_CULL_MODE_BACK_BIT; - rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; //逆时针,和opengl一样 - rasterizer.depthBiasEnable = VK_FALSE; - rasterizer.depthBiasConstantFactor = 0; - rasterizer.depthBiasClamp = 0; - rasterizer.depthBiasSlopeFactor = 0; - rasterizer.lineWidth = 1.0f; - - pipelineInfo.pRasterizationState = &rasterizer; - - multisample.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - multisample.pNext = nullptr; - multisample.flags = 0; - multisample.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; - multisample.sampleShadingEnable = VK_FALSE; - multisample.minSampleShading = 0.0; - multisample.pSampleMask = nullptr; - multisample.alphaToCoverageEnable = VK_FALSE; - multisample.alphaToOneEnable = VK_FALSE; - - pipelineInfo.pMultisampleState = &multisample; - - depthStencilState.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; - depthStencilState.pNext = nullptr; - depthStencilState.flags = 0; - depthStencilState.depthTestEnable = VK_TRUE; - depthStencilState.depthWriteEnable = VK_TRUE; - depthStencilState.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; - depthStencilState.depthBoundsTestEnable = VK_FALSE; - depthStencilState.minDepthBounds = 0; - depthStencilState.maxDepthBounds = 0; - depthStencilState.stencilTestEnable = VK_FALSE; - depthStencilState.back.failOp = VK_STENCIL_OP_KEEP; - depthStencilState.back.passOp = VK_STENCIL_OP_KEEP; - depthStencilState.back.compareOp = VK_COMPARE_OP_ALWAYS; - depthStencilState.back.compareMask = 0; - depthStencilState.back.reference = 0; - depthStencilState.back.depthFailOp = VK_STENCIL_OP_KEEP; - depthStencilState.back.writeMask = 0; - depthStencilState.front = depthStencilState.back; - depthStencilState.front.compareOp=VK_COMPARE_OP_NEVER; - - pipelineInfo.pDepthStencilState=&depthStencilState; - - VkPipelineColorBlendAttachmentState cba; - cba.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - cba.blendEnable = VK_FALSE; - cba.alphaBlendOp = VK_BLEND_OP_ADD; - cba.colorBlendOp = VK_BLEND_OP_ADD; - cba.srcColorBlendFactor = VK_BLEND_FACTOR_ZERO; - cba.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO; - cba.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - cba.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - - colorBlendAttachments.Add(cba,color_attachment_count); //这个需要和subpass中的color attachment数量相等,所以添加多份 - - alpha_blend=false; - - colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; - colorBlending.pNext = nullptr; - colorBlending.flags = 0; - colorBlending.logicOpEnable = VK_FALSE; - colorBlending.logicOp = VK_LOGIC_OP_CLEAR; - colorBlending.attachmentCount = colorBlendAttachments.GetCount(); - colorBlending.pAttachments = colorBlendAttachments.GetData(); - colorBlending.blendConstants[0] = 0.0f; - colorBlending.blendConstants[1] = 0.0f; - colorBlending.blendConstants[2] = 0.0f; - colorBlending.blendConstants[3] = 0.0f; - - pipelineInfo.pColorBlendState = &colorBlending; - - InitDynamicState(); - - pipelineInfo.layout = material->GetPipelineLayout(); - - { - pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; - pipelineInfo.basePipelineIndex = -1; - } -} - -PipelineCreater::PipelineCreater(Device *dev,const Material *material,uchar *data,uint size) -{ - LoadFromMemory(data,size); - - device=dev->GetDevice(); - cache=dev->GetPipelineCache(); - - InitVertexInputState(material); - - pipelineInfo.pInputAssemblyState=&inputAssembly; - pipelineInfo.pTessellationState =&tessellation; - pipelineInfo.pRasterizationState=&rasterizer; - pipelineInfo.pMultisampleState =&multisample; - pipelineInfo.pDepthStencilState =&depthStencilState; - pipelineInfo.pColorBlendState =&colorBlending; - - InitDynamicState(); - - pipelineInfo.layout = material->GetPipelineLayout(); - - { - pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; - pipelineInfo.basePipelineIndex = -1; - } -} - -bool PipelineCreater::Set(const Prim topology,bool restart) -{ - if(topologyPrim::END_RANGE) - if(topology!=Prim::Rectangles)return(false); - - inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; - inputAssembly.pNext = nullptr; - inputAssembly.flags = 0; - inputAssembly.topology = VkPrimitiveTopology(topology==Prim::Rectangles?Prim::Points:topology); - inputAssembly.primitiveRestartEnable = restart; - - pipelineInfo.pInputAssemblyState = &inputAssembly; - return(true); -} - -Pipeline *PipelineCreater::Create(const RenderTarget *rt) +Pipeline *CreatePipeline(Device *dev,VKPipelineData *data,const Material *material,const RenderTarget *rt) { VkPipeline graphicsPipeline; + + data->InitVertexInputState(material->GetStageCount(),material->GetStages()); - InitViewportState(rt->GetExtent()); + material->Write(data->vis_create_info); + + data->InitViewportState(rt->GetExtent()); + + data->pipelineInfo.layout = material->GetPipelineLayout(); { - pipelineInfo.renderPass = rt->GetRenderPass(); - pipelineInfo.subpass = 0; //subpass由于还不知道有什么用,所以暂时写0,待知道功用后,需改进 + data->pipelineInfo.renderPass = rt->GetRenderPass(); + data->pipelineInfo.subpass = 0; //subpass由于还不知道有什么用,所以暂时写0,待知道功用后,需改进 } - if (vkCreateGraphicsPipelines(device, cache, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) + if (vkCreateGraphicsPipelines( dev->GetDevice(), + dev->GetPipelineCache(), + 1,&data->pipelineInfo, + nullptr, + &graphicsPipeline) != VK_SUCCESS) return(nullptr); - return(new Pipeline(device,graphicsPipeline,alpha_test>0,alpha_blend)); + return(new Pipeline(dev->GetDevice(),graphicsPipeline,data->alpha_test>0,data->alpha_blend)); } VK_NAMESPACE_END diff --git a/src/RenderDevice/Vulkan/POD/VKTextureLoader.cpp b/src/RenderDevice/Vulkan/VKTextureLoader.cpp similarity index 100% rename from src/RenderDevice/Vulkan/POD/VKTextureLoader.cpp rename to src/RenderDevice/Vulkan/VKTextureLoader.cpp