删除json/toml版PipelineCreateInfo存档

This commit is contained in:
hyzboy 2019-05-17 19:34:31 +08:00
parent 7ee063a49c
commit 88a9fdf9cb
4 changed files with 2 additions and 383 deletions

View File

@ -38,7 +38,6 @@ 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)
@ -52,7 +51,7 @@ add_subdirectory(3rdpty/NvTriStrip)
add_subdirectory(src)
SET(ULRE ULRE.Base
ULRE.Util
# ULRE.Util
ULRE.RenderDevice.Vulkan
ULRE.Platform
MathGeoLib

View File

@ -1,4 +1,4 @@
add_subdirectory(Base)
add_subdirectory(Util)
#add_subdirectory(Util)
add_subdirectory(RenderDevice)
add_subdirectory(Platform)

View File

@ -1,249 +0,0 @@
#include<json/json.h>
#include<vulkan/vulkan.h>
#include<hgl/type/BaseString.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/util/JsonTool.h>
using namespace hgl;
namespace
{
#define TO_JSON_BEGIN(struct_name) Json::Value ToJSON(const struct_name *state) \
{ \
Json::Value root;
#define TO_JSON_END return root; \
}
#define TO_JSON_STRUCT(name) root[#name]=ToJSON(&(state->name));
#define TO_JSON_OBJECT(name) root[#name]=ToJSON(state->name);
#define TO_JSON_BOOL(name) root[#name]=bool(state->name);
#define TO_JSON_INT32(name) root[#name]=Json::Int(state->name);
#define TO_JSON_UINT32(name) root[#name]=Json::UInt(state->name);
#define TO_JSON_INT64(name) root[#name]=Json::Int64(state->name);
#define TO_JSON_UINT64(name) root[#name]=Json::UInt64(state->name);
#define TO_JSON_FLOAT(name) root[#name]=state->name;
#define TO_JSON_STRING(name) root[#name]=state->name;
#define FROM_JSON_BEGIN(struct_name) bool FromJSON(const Json::Value &root,struct_name *state) \
{ \
#define FROM_JSON_END return true; \
}
#define CHECK_MEMBER(name) if(!root.isMember(#name))return(false)
#define FROM_JSON_STRUCT(name) CHECK_MEMBER(name);if(!FromJSON(root[#name],&(state->name)))return(false);
#define FROM_JSON_OBJECT(name) CHECK_MEMBER(name);if(!FromJSON(root[#name],state->name))return(false);
#define FROM_JSON_BOOL(name) CHECK_MEMBER(name);state->name=root[#name].asBool();
#define FROM_JSON_ENUM(type,name) CHECK_MEMBER(name);state->name=type(root[#name].asUInt());
#define FROM_JSON_INT32(name) CHECK_MEMBER(name);state->name=root[#name].asInt();
#define FROM_JSON_UINT32(name) CHECK_MEMBER(name);state->name=root[#name].asUInt();
#define FROM_JSON_INT64(name) CHECK_MEMBER(name);state->name=root[#name].asInt64();
#define FROM_JSON_UINT64(name) CHECK_MEMBER(name);state->name=root[#name].asUInt64();
#define FROM_JSON_FLOAT(name) CHECK_MEMBER(name);state->name=root[#name].asFloat();
#define FROM_JSON_STRING(name) CHECK_MEMBER(name);state->name=root[#name].asCString();
template<typename T>
Json::Value ToJSON_Array(const T *values,const uint count)
{
Json::Value items;
for(uint i=0;i<count;i++)
{
items[i]=*values;
++values;
}
return items;
}
#define TO_JSON_ARRAY(name,count) root[#name]=ToJSON_Array(state->name,count);
template<typename T> void FromJSON_Array(const Json::Value &root,T *object,const uint count);
template<> void FromJSON_Array(const Json::Value &root,float *object,const uint count)
{
for(uint i=0;i<count;i++)
{
*object=root[i].asFloat();
++object;
}
}
#define FROM_JSON_ARRAY(name,count) FromJSON_Array(root[#name],state->name,count);
template<typename T>
Json::Value ToJSON_StructArray(const T *object,const uint count)
{
Json::Value items;
for(uint i=0;i<count;i++)
{
items[i]=ToJSON(object);
++object;
}
return items;
}
#define TO_JSON_STRUCT_ARRAY(name,count) root[#name]=ToJSON_StructArray(state->name,count)
template<typename T>
void FromJSON_StructArray(const Json::Value &root,T *objects,const uint count)
{
for(uint i=0;i<count;i++)
{
FromJSON(root[i],objects);
++objects;
}
}
#define FROM_JSON_STRUCT_ARRAY(name,count) FromJSON_StructArray(root[#name],state->name,count);
TO_JSON_BEGIN(VkStencilOpState)
TO_JSON_UINT32(failOp)
TO_JSON_UINT32(passOp)
TO_JSON_UINT32(depthFailOp)
TO_JSON_UINT32(compareOp)
TO_JSON_UINT32(compareMask)
TO_JSON_UINT32(writeMask)
TO_JSON_UINT32(reference)
TO_JSON_END
FROM_JSON_BEGIN(VkStencilOpState)
FROM_JSON_ENUM(VkStencilOp,failOp)
FROM_JSON_ENUM(VkStencilOp,passOp)
FROM_JSON_ENUM(VkStencilOp,depthFailOp)
FROM_JSON_ENUM(VkCompareOp,compareOp)
FROM_JSON_UINT32(compareMask)
FROM_JSON_UINT32(writeMask)
FROM_JSON_UINT32(reference)
FROM_JSON_END
TO_JSON_BEGIN(VkPipelineDepthStencilStateCreateInfo)
TO_JSON_BOOL (depthTestEnable)
TO_JSON_BOOL (depthWriteEnable)
TO_JSON_UINT32 (depthCompareOp)
TO_JSON_BOOL (depthBoundsTestEnable)
TO_JSON_BOOL (stencilTestEnable)
TO_JSON_STRUCT (front)
TO_JSON_STRUCT (back)
TO_JSON_FLOAT (minDepthBounds)
TO_JSON_FLOAT (maxDepthBounds)
TO_JSON_END
FROM_JSON_BEGIN(VkPipelineDepthStencilStateCreateInfo)
FROM_JSON_BOOL (depthTestEnable)
FROM_JSON_BOOL (depthWriteEnable)
FROM_JSON_ENUM (VkCompareOp,depthCompareOp)
FROM_JSON_BOOL (depthBoundsTestEnable)
FROM_JSON_BOOL (stencilTestEnable)
FROM_JSON_STRUCT(front)
FROM_JSON_STRUCT(back)
FROM_JSON_FLOAT (minDepthBounds)
FROM_JSON_FLOAT (maxDepthBounds)
FROM_JSON_END
TO_JSON_BEGIN(VkPipelineColorBlendAttachmentState)
TO_JSON_BOOL(blendEnable)
TO_JSON_UINT32(srcColorBlendFactor)
TO_JSON_UINT32(dstColorBlendFactor)
TO_JSON_UINT32(colorBlendOp)
TO_JSON_UINT32(srcAlphaBlendFactor)
TO_JSON_UINT32(dstAlphaBlendFactor)
TO_JSON_UINT32(alphaBlendOp)
TO_JSON_UINT32(colorWriteMask)
TO_JSON_END
FROM_JSON_BEGIN(VkPipelineColorBlendAttachmentState)
FROM_JSON_BOOL(blendEnable)
FROM_JSON_ENUM(VkBlendFactor,srcColorBlendFactor)
FROM_JSON_ENUM(VkBlendFactor,dstColorBlendFactor)
FROM_JSON_ENUM(VkBlendOp,colorBlendOp)
FROM_JSON_ENUM(VkBlendFactor,srcAlphaBlendFactor)
FROM_JSON_ENUM(VkBlendFactor,dstAlphaBlendFactor)
FROM_JSON_ENUM(VkBlendOp,alphaBlendOp)
FROM_JSON_UINT32(colorWriteMask)
FROM_JSON_END
TO_JSON_BEGIN(VkPipelineColorBlendStateCreateInfo)
TO_JSON_BOOL(logicOpEnable)
TO_JSON_UINT32(logicOp)
TO_JSON_ARRAY(blendConstants,4);
TO_JSON_UINT32(attachmentCount);
TO_JSON_STRUCT_ARRAY(pAttachments,state->attachmentCount);
TO_JSON_END
FROM_JSON_BEGIN(VkPipelineColorBlendStateCreateInfo)
FROM_JSON_BOOL(logicOpEnable)
FROM_JSON_ENUM(VkLogicOp,logicOp)
FROM_JSON_ARRAY(blendConstants,4);
FROM_JSON_UINT32(attachmentCount);
FROM_JSON_STRUCT_ARRAY(pAttachments,state->attachmentCount);
FROM_JSON_END
TO_JSON_BEGIN(VkPipelineRasterizationStateCreateInfo)
TO_JSON_BOOL(depthClampEnable)
TO_JSON_BOOL(rasterizerDiscardEnable)
TO_JSON_UINT32(polygonMode)
TO_JSON_UINT32(cullMode)
TO_JSON_UINT32(frontFace)
TO_JSON_BOOL(depthBiasEnable)
TO_JSON_FLOAT(depthBiasConstantFactor)
TO_JSON_FLOAT(depthBiasClamp)
TO_JSON_FLOAT(depthBiasSlopeFactor)
TO_JSON_FLOAT(lineWidth)
TO_JSON_END
TO_JSON_BEGIN(VkPipelineMultisampleStateCreateInfo)
TO_JSON_UINT32(rasterizationSamples)
TO_JSON_BOOL(sampleShadingEnable)
TO_JSON_FLOAT(minSampleShading)
TO_JSON_BOOL(alphaToCoverageEnable)
TO_JSON_BOOL(alphaToOneEnable)
TO_JSON_END
TO_JSON_BEGIN(VkPipelineInputAssemblyStateCreateInfo)
TO_JSON_UINT32(topology)
TO_JSON_BOOL(primitiveRestartEnable)
TO_JSON_END
TO_JSON_BEGIN(VkGraphicsPipelineCreateInfo)
TO_JSON_OBJECT(pDepthStencilState)
TO_JSON_OBJECT(pColorBlendState)
TO_JSON_OBJECT(pRasterizationState)
TO_JSON_OBJECT(pMultisampleState)
TO_JSON_OBJECT(pInputAssemblyState)
TO_JSON_END
const Json::String STRING_VER="ver",
STRING_VULKAN="vulkan",
STRING_PIPELINE="pipeline";
}//namespace
void SaveToJSON(const OSString &filename,const VkGraphicsPipelineCreateInfo *state)
{
Json::Value root;
root[STRING_VER]=100;
root[STRING_VULKAN]=100;
root[STRING_PIPELINE]=ToJSON(state);
SaveJson(root,filename);
}
bool LoadFromJSON(const OSString &filename,const VkGraphicsPipelineCreateInfo *state)
{
Json::Value root;
if(!LoadJson(root,filename))
return(false);
if(!root.isMember(STRING_VER)) return(false);
if(!root.isMember(STRING_VULKAN)) return(false);
if(!root.isMember(STRING_PIPELINE)) return(false);
const uint file_ver =root[STRING_VER].asUInt(),
vulkan_ver =root[STRING_VULKAN].asUInt();
FromJSON(root[STRING_PIPELINE],state);
}

View File

@ -1,131 +0,0 @@
#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());
}