use VKPipelineData instead VKPipelineCreater

This commit is contained in:
hyzboy 2020-09-18 20:44:11 +08:00
parent b42ad2d667
commit b3b8de4adb
9 changed files with 30 additions and 573 deletions

2
CMCore

@ -1 +1 @@
Subproject commit 6f1249263e97c2c88fb69d0c277e24d887fd32cb
Subproject commit 2aadf9005ca099d8c72f745c547d610022a79d0b

@ -1 +1 @@
Subproject commit 384727bf3ed298d9aaaa2454afa910568039f1ff
Subproject commit b816297b8811a1a078819f02b740c05576ae5daf

View File

@ -86,13 +86,14 @@ private:
bool InitPipeline()
{
AutoDelete<vulkan::PipelineCreater>
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);

View File

@ -2,6 +2,7 @@
#define HGL_GRAPH_VULKAN_PIPELINE_INCLUDE
#include<hgl/graph/vulkan/VK.h>
#include<hgl/graph/vulkan/VKPipelineData.h>
#include<hgl/io/DataOutputStream.h>
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<VkPipelineColorBlendAttachmentState> 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;i<colorBlendAttachments.GetCount();i++)
if(cba->blendEnable)
{
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

View File

@ -1,28 +0,0 @@
#ifndef HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE
#define HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE
#include<hgl/TypeFunc.h>
/**
*
*/
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

View File

@ -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})

View File

@ -1,150 +0,0 @@
#include<hgl/graph/vulkan/VKPipeline.h>
#include<hgl/type/String.h>
#include<hgl/io/MemoryOutputStream.h>
#include<hgl/io/DataOutputStream.h>
#include<hgl/io/MemoryInputStream.h>
#include<hgl/io/DataInputStream.h>
#include<hgl/filesystem/FileSystem.h>
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;i<pipelineInfo.pColorBlendState->attachmentCount;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(size<sizeof(type))return(false); \
memcpy(&ptr,data,sizeof(type)); \
data+=sizeof(type); \
size-=sizeof(type);
bool PipelineCreater::LoadFromMemory(uchar *data,uint size)
{
uint16 ver=*(uint16 *)data;
if(ver!=1)
return(false);
data+=sizeof(uint16);
size-=sizeof(uint16);
CHECK_SIZE_AND_COPY(pipelineInfo,VkGraphicsPipelineCreateInfo);
CHECK_SIZE_AND_COPY(inputAssembly,VkPipelineInputAssemblyStateCreateInfo);
CHECK_SIZE_AND_COPY(tessellation,VkPipelineTessellationStateCreateInfo);
CHECK_SIZE_AND_COPY(rasterizer,VkPipelineRasterizationStateCreateInfo);
CHECK_SIZE_AND_COPY(multisample,VkPipelineMultisampleStateCreateInfo);
const uint8 count=*(uint8 *)data;
++data;
if(count>0)
{
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(size<colorBlending.attachmentCount*sizeof(VkPipelineColorBlendAttachmentState))
return(false);
VkPipelineColorBlendAttachmentState *cba=(VkPipelineColorBlendAttachmentState *)data;
colorBlendAttachments.SetCount(colorBlending.attachmentCount);
memcpy(colorBlendAttachments.GetData(),data,colorBlending.attachmentCount*sizeof(VkPipelineColorBlendAttachmentState));
colorBlending.pAttachments=colorBlendAttachments.GetData();
for(uint i=0;i<colorBlending.attachmentCount;i++)
{
if(cba->blendEnable)
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;
}

View File

@ -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(topology<Prim::BEGIN_RANGE||topology>Prim::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