增加PipelineCreateInfo保存至配置文件代码(测试中)

This commit is contained in:
hyzboy 2019-05-05 17:43:31 +08:00
parent b87af86b4c
commit 29252ca0b1
9 changed files with 333 additions and 27 deletions

1
3rdpty/dl_jsoncpp.sh Normal file
View File

@ -0,0 +1 @@
git clone https://github.com/open-source-parsers/jsoncpp.git

1
3rdpty/dl_toml11.sh Normal file
View File

@ -0,0 +1 @@
git clone https://github.com/ToruNiina/toml11.git

View File

@ -20,9 +20,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
include_directories(${Vulkan_INCLUDE_DIRS})
SET(SPIRV_CROSS_PATH 3rdpty/SPIRV-Cross)
include_directories(${SPIRV_CROSS_PATH})
add_subdirectory(${SPIRV_CROSS_PATH})
SET(SPIRV_CROSS_PATH 3rdpty/SPIRV-Cross)
include_directories(${SPIRV_CROSS_PATH})
add_subdirectory(${SPIRV_CROSS_PATH})
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)
@ -41,6 +44,7 @@ add_definitions(-DGLFW_INCLUDE_VULKAN)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdpty/MathGeoLib/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdpty/NvTriStrip)
# include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdpty/toml11)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
SET(ROOT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/inc)

View File

@ -5,4 +5,3 @@ endmacro()
CreateProject(0.triangle main)
CreateProject(1.cube cube)

View File

@ -4,6 +4,8 @@
using namespace hgl;
using namespace hgl::graph;
void SaveToTOML(const OSString &filename,const VkGraphicsPipelineCreateInfo *info);
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
@ -101,11 +103,11 @@ private:
pipeline_creater->CloseCullFace();
pipeline_creater->Set(PRIM_TRIANGLES);
SaveToTOML(OS_TEXT("pipeline.toml"),pipeline_creater->GetInfo());
pipeline=pipeline_creater->Create();
delete pipeline_creater;
pipeline_creater=nullptr;
return pipeline;
}

View File

@ -109,6 +109,7 @@ public:
void SetBlendConstans(float *blend_constans) {hgl_typecpy(colorBlending.blendConstants,blend_constans,4);}
const VkGraphicsPipelineCreateInfo *GetInfo()const{return &pipelineInfo;}
Pipeline *Create();
};//class PipelineCreater
VK_NAMESPACE_END

View File

@ -1,21 +1,57 @@
add_library(ULRE.RenderDevice.Vulkan STATIC VKFormat.cpp
VKInstance.cpp
VKPhysicalDevice.cpp
VKImageView.cpp
VKCommandBuffer.cpp
VKDeviceAttribute.cpp
VKDeviceCreater.cpp
VKDevice.cpp
VKDeviceBuffer.cpp
VKBuffer.cpp
VKDescriptorSets.cpp
VKRenderPass.cpp
VKShaderModule.cpp
VKShaderModuleManage.cpp
VKVertexAttributeBinding.cpp
VKPipeline.cpp
VKSemaphore.cpp
VKFramebuffer.cpp
VKFence.cpp
VKMaterial.cpp
VKRenderable.cpp)
SET(RENDER_DEVICE_VULKAN_HEADER ${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VK.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKBuffer.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKBufferData.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKCommandBuffer.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKDescriptorSets.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKDevice.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKDeviceAttribute.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKFence.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKFormat.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKFramebuffer.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKImageView.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKInstance.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKMaterial.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKPhysicalDevice.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKPipeline.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKPrimivate.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKRenderable.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKRenderPass.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKSemaphore.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKShaderModule.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKShaderModuleManage.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKShaderParse.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKSurfaceExtensionName.h
${ROOT_INCLUDE_PATH}/hgl/graph/vulkan/VKVertexAttributeBinding.h)
SET(RENDER_DEVICE_VULKAN_SOURCE VKFormat.cpp
VKInstance.cpp
VKPhysicalDevice.cpp
VKImageView.cpp
VKCommandBuffer.cpp
VKDeviceAttribute.cpp
VKDeviceCreater.cpp
VKDevice.cpp
VKDeviceBuffer.cpp
VKBuffer.cpp
VKDescriptorSets.cpp
VKRenderPass.cpp
VKShaderModule.cpp
VKShaderModuleManage.cpp
VKVertexAttributeBinding.cpp
VKPipeline.cpp
VKSemaphore.cpp
VKFramebuffer.cpp
VKFence.cpp
VKMaterial.cpp
VKRenderable.cpp)
#SET(RENDER_DEVICE_VULKAN_TOML_SOURCE toml/VKPipelineCreateInfo.TOML.cpp)
SET(RENDER_DEVICE_VULKAN_JSON_SOURCE json/VKPipelineCreateInfo.JSON.cpp)
SOURCE_GROUP("Header Files" FILES ${RENDER_DEVICE_VULKAN_HEADER})
SOURCE_GROUP("Source Files" FILES ${RENDER_DEVICE_VULKAN_SOURCE})
SOURCE_GROUP("JSON Source Files" FILES ${RENDER_DEVICE_VULKAN_JSON_SOURCE})
add_library(ULRE.RenderDevice.Vulkan STATIC ${RENDER_DEVICE_VULKAN_HEADER}
${RENDER_DEVICE_VULKAN_SOURCE}
${RENDER_DEVICE_VULKAN_JSON_SOURCE})

View File

@ -0,0 +1,131 @@
#include<toml.hpp>
#include<vulkan/vulkan.h>
#include<hgl/type/BaseString.h>
#include<sstream>
#include<hgl/filesystem/FileSystem.h>
using namespace hgl;
#define TOML_BEGIN(struct_name) toml::table ToTOML(const struct_name *state) \
{ \
toml::table root=toml::table
#define TOML_END ;return root; \
}
#define TOML_BOOL(name) {#name,bool(state->##name)}
#define TOML_INTEGER(name) {#name,std::int64_t(state->##name)}
#define TOML_FLOAT(name) {#name,double(state->##name)}
#define TOML_STRING(name) {#name,toml::string(state->##name)}
TOML_BEGIN(VkStencilOpState)
{
TOML_INTEGER(failOp),
TOML_INTEGER(passOp),
TOML_INTEGER(depthFailOp),
TOML_INTEGER(compareOp),
TOML_INTEGER(compareMask),
TOML_INTEGER(writeMask),
TOML_INTEGER(reference)
}
TOML_END
TOML_BEGIN(VkPipelineDepthStencilStateCreateInfo)
{
TOML_BOOL (depthTestEnable),
TOML_BOOL (depthWriteEnable),
TOML_INTEGER(depthCompareOp),
TOML_BOOL (depthBoundsTestEnable),
TOML_BOOL (stencilTestEnable),
{"front", ToTOML(&state->front)},
{"back", ToTOML(&state->back)}
}
TOML_END
TOML_BEGIN(VkPipelineColorBlendAttachmentState)
{
TOML_BOOL(blendEnable),
TOML_INTEGER(srcColorBlendFactor),
TOML_INTEGER(dstColorBlendFactor),
TOML_INTEGER(colorBlendOp),
TOML_INTEGER(srcAlphaBlendFactor),
TOML_INTEGER(dstAlphaBlendFactor),
TOML_INTEGER(alphaBlendOp),
TOML_INTEGER(colorWriteMask)
}
TOML_END
TOML_BEGIN(VkPipelineColorBlendStateCreateInfo)
{
TOML_BOOL(logicOpEnable),
TOML_INTEGER(logicOp),
{"blendConstants", toml::array
{
state->blendConstants[0],
state->blendConstants[1],
state->blendConstants[2],
state->blendConstants[3]
}
}};
toml::array pAttachments;
for(uint i=0;i<state->attachmentCount;i++)
pAttachments.push_back(ToTOML(&(state->pAttachments[i])));
root.insert({"pAttachments",pAttachments});
TOML_END
TOML_BEGIN(VkPipelineRasterizationStateCreateInfo)
{
TOML_BOOL(depthClampEnable),
TOML_BOOL(rasterizerDiscardEnable),
TOML_INTEGER(polygonMode),
TOML_INTEGER(cullMode),
TOML_INTEGER(frontFace),
TOML_BOOL(depthBiasEnable),
TOML_FLOAT(depthBiasConstantFactor),
TOML_FLOAT(depthBiasClamp),
TOML_FLOAT(depthBiasSlopeFactor),
TOML_FLOAT(lineWidth)
}
TOML_END
TOML_BEGIN(VkPipelineMultisampleStateCreateInfo)
{
TOML_INTEGER(rasterizationSamples),
TOML_BOOL(sampleShadingEnable),
TOML_FLOAT(minSampleShading),
TOML_BOOL(alphaToCoverageEnable),
TOML_BOOL(alphaToOneEnable)
}
TOML_END
TOML_BEGIN(VkPipelineInputAssemblyStateCreateInfo)
{
TOML_INTEGER(topology),
TOML_BOOL(primitiveRestartEnable)
}
TOML_END
void SaveToTOML(const OSString &filename,const VkGraphicsPipelineCreateInfo *info)
{
const auto root=toml::table
{
{"ver",toml::table{{"file",100},{"vulkan",100}}},
{"pDepthStencilState", ToTOML(info->pDepthStencilState)},
{"pColorBlendState", ToTOML(info->pColorBlendState)},
{"pRasterizationState", ToTOML(info->pRasterizationState)},
{"pMultisampleState", ToTOML(info->pMultisampleState)},
{"pInputAssemblyState", ToTOML(info->pInputAssemblyState)}
};
std::stringstream ss;
ss<<root;
const std::string str=ss.str();
filesystem::SaveMemoryToFile(filename,str.c_str(),str.length());
}

View File

@ -0,0 +1,131 @@
#include<toml.hpp>
#include<vulkan/vulkan.h>
#include<hgl/type/BaseString.h>
#include<sstream>
#include<hgl/filesystem/FileSystem.h>
using namespace hgl;
#define TOML_BEGIN(struct_name) toml::table ToTOML(const struct_name *state) \
{ \
toml::table root=toml::table
#define TOML_END ;return root; \
}
#define TOML_BOOL(name) {#name,bool(state->##name)}
#define TOML_INTEGER(name) {#name,std::int64_t(state->##name)}
#define TOML_FLOAT(name) {#name,double(state->##name)}
#define TOML_STRING(name) {#name,toml::string(state->##name)}
TOML_BEGIN(VkStencilOpState)
{
TOML_INTEGER(failOp),
TOML_INTEGER(passOp),
TOML_INTEGER(depthFailOp),
TOML_INTEGER(compareOp),
TOML_INTEGER(compareMask),
TOML_INTEGER(writeMask),
TOML_INTEGER(reference)
}
TOML_END
TOML_BEGIN(VkPipelineDepthStencilStateCreateInfo)
{
TOML_BOOL (depthTestEnable),
TOML_BOOL (depthWriteEnable),
TOML_INTEGER(depthCompareOp),
TOML_BOOL (depthBoundsTestEnable),
TOML_BOOL (stencilTestEnable),
{"front", ToTOML(&state->front)},
{"back", ToTOML(&state->back)}
}
TOML_END
TOML_BEGIN(VkPipelineColorBlendAttachmentState)
{
TOML_BOOL(blendEnable),
TOML_INTEGER(srcColorBlendFactor),
TOML_INTEGER(dstColorBlendFactor),
TOML_INTEGER(colorBlendOp),
TOML_INTEGER(srcAlphaBlendFactor),
TOML_INTEGER(dstAlphaBlendFactor),
TOML_INTEGER(alphaBlendOp),
TOML_INTEGER(colorWriteMask)
}
TOML_END
TOML_BEGIN(VkPipelineColorBlendStateCreateInfo)
{
TOML_BOOL(logicOpEnable),
TOML_INTEGER(logicOp),
{"blendConstants", toml::array
{
state->blendConstants[0],
state->blendConstants[1],
state->blendConstants[2],
state->blendConstants[3]
}
}};
toml::array pAttachments;
for(uint i=0;i<state->attachmentCount;i++)
pAttachments.push_back(ToTOML(&(state->pAttachments[i])));
root.insert({"pAttachments",pAttachments});
TOML_END
TOML_BEGIN(VkPipelineRasterizationStateCreateInfo)
{
TOML_BOOL(depthClampEnable),
TOML_BOOL(rasterizerDiscardEnable),
TOML_INTEGER(polygonMode),
TOML_INTEGER(cullMode),
TOML_INTEGER(frontFace),
TOML_BOOL(depthBiasEnable),
TOML_FLOAT(depthBiasConstantFactor),
TOML_FLOAT(depthBiasClamp),
TOML_FLOAT(depthBiasSlopeFactor),
TOML_FLOAT(lineWidth)
}
TOML_END
TOML_BEGIN(VkPipelineMultisampleStateCreateInfo)
{
TOML_INTEGER(rasterizationSamples),
TOML_BOOL(sampleShadingEnable),
TOML_FLOAT(minSampleShading),
TOML_BOOL(alphaToCoverageEnable),
TOML_BOOL(alphaToOneEnable)
}
TOML_END
TOML_BEGIN(VkPipelineInputAssemblyStateCreateInfo)
{
TOML_INTEGER(topology),
TOML_BOOL(primitiveRestartEnable)
}
TOML_END
void SaveToTOML(const OSString &filename,const VkGraphicsPipelineCreateInfo *info)
{
const auto root=toml::table
{
{"ver",toml::table{{"file",100},{"vulkan",100}}},
{"pDepthStencilState", ToTOML(info->pDepthStencilState)},
{"pColorBlendState", ToTOML(info->pColorBlendState)},
{"pRasterizationState", ToTOML(info->pRasterizationState)},
{"pMultisampleState", ToTOML(info->pMultisampleState)},
{"pInputAssemblyState", ToTOML(info->pInputAssemblyState)}
};
std::stringstream ss;
ss<<root;
const std::string str=ss.str();
filesystem::SaveMemoryToFile(filename,str.c_str(),str.length());
}