PipelineCreateInfo.POD增加安全性检测

This commit is contained in:
hyzboy 2019-05-18 00:08:41 +08:00
parent 88a9fdf9cb
commit a84fd2b970
6 changed files with 33 additions and 28 deletions

View File

@ -20,8 +20,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
include_directories(${Vulkan_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdpty/jsoncpp/include)
add_subdirectory(3rdpty/jsoncpp)
# include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdpty/jsoncpp/include)
# add_subdirectory(3rdpty/jsoncpp)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR)
elseif(UNIX)
@ -56,7 +56,7 @@ SET(ULRE ULRE.Base
ULRE.Platform
MathGeoLib
spirv-cross-core
jsoncpp_lib
# jsoncpp_lib
${RENDER_LIBRARY}
${Vulkan_LIBRARIES})

View File

@ -106,17 +106,17 @@ private:
{
constexpr os_char PIPELINE_FILENAME[]=OS_TEXT("2DSolid.pipeline");
//{
// vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetRenderPass(),device->GetExtent());
// pipeline_creater->SetDepthTest(false);
// pipeline_creater->SetDepthWrite(false);
// pipeline_creater->CloseCullFace();
// pipeline_creater->Set(PRIM_TRIANGLES);
{
vulkan::PipelineCreater *pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetRenderPass(),device->GetExtent());
pipeline_creater->SetDepthTest(false);
pipeline_creater->SetDepthWrite(false);
pipeline_creater->CloseCullFace();
pipeline_creater->Set(PRIM_TRIANGLES);
// SaveToFile(PIPELINE_FILENAME,pipeline_creater);
SaveToFile(PIPELINE_FILENAME,pipeline_creater);
// delete pipeline_creater;
//}
delete pipeline_creater;
}
{
void *data;

View File

@ -1,7 +1,6 @@
#ifndef HGL_IO_MEMORY_INPUT_STREAM_INCLUDE
#define HGL_IO_MEMORY_INPUT_STREAM_INCLUDE
#include<hgl/type/MemBlock.h>
#include<hgl/io/InputStream.h>
namespace hgl
{

View File

@ -1,7 +1,6 @@
#ifndef HGL_IO_MEMORY_OUTPUT_STREAM_INCLUDE
#define HGL_IO_MEMORY_OUTPUT_STREAM_INCLUDE
#include<hgl/type/MemBlock.h>
#include<hgl/io/OutputStream.h>
namespace hgl
{

View File

@ -9,35 +9,37 @@
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);
dos->WriteUint16(1); //file ver
if(!dos->WriteUint16(1))return(false); //file ver
dos->Write(&pipelineInfo,sizeof(VkGraphicsPipelineCreateInfo));
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 );
dos->Write(pipelineInfo.pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
dos->Write(pipelineInfo.pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
dos->Write(pipelineInfo.pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
dos->Write(pipelineInfo.pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
WRITE_AND_CHECK_SIZE(pipelineInfo.pMultisampleState, VkPipelineMultisampleStateCreateInfo );
if(pipelineInfo.pMultisampleState->pSampleMask)
{
const uint count=(pipelineInfo.pMultisampleState->rasterizationSamples+31)/32;
dos->WriteUint8(count);
dos->WriteUint32(pipelineInfo.pMultisampleState->pSampleMask,count);
if(!dos->WriteUint8(count))return(false);
if(dos->WriteUint32(pipelineInfo.pMultisampleState->pSampleMask,count)!=count)return(false);
}
else
{
dos->WriteUint8(0);
if(!dos->WriteUint8(0))return(false);
}
dos->Write(pipelineInfo.pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
WRITE_AND_CHECK_SIZE(pipelineInfo.pDepthStencilState, VkPipelineDepthStencilStateCreateInfo);
dos->Write(pipelineInfo.pColorBlendState,sizeof(VkPipelineColorBlendStateCreateInfo));
WRITE_AND_CHECK_SIZE(pipelineInfo.pColorBlendState, VkPipelineColorBlendStateCreateInfo);
for(uint32_t i=0;i<pipelineInfo.pColorBlendState->attachmentCount;i++)
dos->Write(pipelineInfo.pColorBlendState->pAttachments+i,sizeof(VkPipelineColorBlendAttachmentState));
WRITE_AND_CHECK_SIZE(pipelineInfo.pColorBlendState->pAttachments+i,VkPipelineColorBlendAttachmentState);
return(true);
}

View File

@ -77,7 +77,12 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,RenderPass
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
InitVertexInputState(material);
pipelineInfo.pTessellationState=nullptr;
tessellation.sType=VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
tessellation.pNext=nullptr;
tessellation.flags=0;
tessellation.patchControlPoints=0;
pipelineInfo.pTessellationState=&tessellation;
InitViewportState();