完成PipielineCreateInfo的JSON保存版本
*** 现发现使用这种方式保存,对于枚举项在文件中使用数字表示不方便阅讯,考虑自设计一种格式,对枚举项可注册使用字符串保存。 ***
This commit is contained in:
parent
ac0939faa4
commit
0ce2f43e2e
@ -57,6 +57,7 @@ SET(ULRE ULRE.Base
|
|||||||
ULRE.Platform
|
ULRE.Platform
|
||||||
MathGeoLib
|
MathGeoLib
|
||||||
spirv-cross-core
|
spirv-cross-core
|
||||||
|
jsoncpp_lib
|
||||||
${RENDER_LIBRARY}
|
${RENDER_LIBRARY}
|
||||||
${Vulkan_LIBRARIES})
|
${Vulkan_LIBRARIES})
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
|
|
||||||
//void SaveToTOML(const OSString &filename,const VkGraphicsPipelineCreateInfo *info);
|
void SaveToJSON(const OSString &filename,const VkGraphicsPipelineCreateInfo *info);
|
||||||
|
|
||||||
constexpr uint32_t SCREEN_WIDTH=128;
|
constexpr uint32_t SCREEN_WIDTH=128;
|
||||||
constexpr uint32_t SCREEN_HEIGHT=128;
|
constexpr uint32_t SCREEN_HEIGHT=128;
|
||||||
@ -109,7 +109,7 @@ private:
|
|||||||
pipeline_creater->CloseCullFace();
|
pipeline_creater->CloseCullFace();
|
||||||
pipeline_creater->Set(PRIM_TRIANGLES);
|
pipeline_creater->Set(PRIM_TRIANGLES);
|
||||||
|
|
||||||
// SaveToTOML(OS_TEXT("pipeline.toml"),pipeline_creater->GetInfo());
|
SaveToJSON(OS_TEXT("pipeline.json"),pipeline_creater->GetInfo());
|
||||||
|
|
||||||
pipeline=pipeline_creater->Create();
|
pipeline=pipeline_creater->Create();
|
||||||
|
|
||||||
|
@ -1,126 +1,141 @@
|
|||||||
#include<json/json.h>
|
#include<json/json.h>
|
||||||
#include<vulkan/vulkan.h>
|
#include<vulkan/vulkan.h>
|
||||||
#include<hgl/type/BaseString.h>
|
#include<hgl/type/BaseString.h>
|
||||||
#include<sstream>
|
|
||||||
#include<hgl/filesystem/FileSystem.h>
|
#include<hgl/filesystem/FileSystem.h>
|
||||||
|
#include<hgl/util/JsonTool.h>
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
|
|
||||||
#define TOML_BEGIN(struct_name) toml::table ToTOML(const struct_name *state) \
|
namespace
|
||||||
|
{
|
||||||
|
#define JSON_BEGIN(struct_name) Json::Value ToJSON(const struct_name *state) \
|
||||||
{ \
|
{ \
|
||||||
toml::table root=toml::table
|
Json::Value root;
|
||||||
|
|
||||||
#define TOML_END ;return root; \
|
#define JSON_END return root; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TOML_BOOL(name) {#name,bool(state->##name)}
|
#define JSON_STRUCT(name) root[#name]=ToJSON(&(state->name));
|
||||||
#define TOML_INTEGER(name) {#name,std::int64_t(state->##name)}
|
#define JSON_OBJECT(name) root[#name]=ToJSON(state->name);
|
||||||
#define TOML_FLOAT(name) {#name,double(state->##name)}
|
#define JSON_BOOL(name) root[#name]=bool(state->name);
|
||||||
#define TOML_STRING(name) {#name,toml::string(state->##name)}
|
#define JSON_INT32(name) root[#name]=Json::Int(state->name);
|
||||||
|
#define JSON_UINT32(name) root[#name]=Json::UInt(state->name);
|
||||||
|
#define JSON_INT64(name) root[#name]=Json::Int64(state->name);
|
||||||
|
#define JSON_UINT64(name) root[#name]=Json::UInt64(state->name);
|
||||||
|
#define JSON_FLOAT(name) root[#name]=state->name;
|
||||||
|
#define JSON_STRING(name) root[#name]=state->name;
|
||||||
|
|
||||||
TOML_BEGIN(VkStencilOpState)
|
template<typename T>
|
||||||
{
|
Json::Value ToJSON_Array(const T *values,const uint count)
|
||||||
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],
|
Json::Value items;
|
||||||
state->blendConstants[1],
|
|
||||||
state->blendConstants[2],
|
for(uint i=0;i<count;i++)
|
||||||
state->blendConstants[3]
|
{
|
||||||
|
items[i]=*values;
|
||||||
|
++values;
|
||||||
}
|
}
|
||||||
}};
|
|
||||||
|
|
||||||
toml::array pAttachments;
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
for(uint i=0;i<state->attachmentCount;i++)
|
#define JSON_ARRAY(name,count) root[#name]=ToJSON_Array(state->name,count);
|
||||||
pAttachments.push_back(ToTOML(&(state->pAttachments[i])));
|
|
||||||
|
|
||||||
root.insert({"pAttachments",pAttachments});
|
template<typename T>
|
||||||
|
Json::Value ToJSON_StructArray(const T *object,const uint count)
|
||||||
|
{
|
||||||
|
Json::Value items;
|
||||||
|
|
||||||
TOML_END
|
for(uint i=0;i<count;i++)
|
||||||
|
{
|
||||||
|
items[i]=ToJSON(object);
|
||||||
|
++object;
|
||||||
|
}
|
||||||
|
|
||||||
TOML_BEGIN(VkPipelineRasterizationStateCreateInfo)
|
return items;
|
||||||
{
|
}
|
||||||
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)
|
#define JSON_STRUCT_ARRAY(name,count) root[#name]=ToJSON_StructArray(state->name,count)
|
||||||
{
|
|
||||||
TOML_INTEGER(rasterizationSamples),
|
|
||||||
TOML_BOOL(sampleShadingEnable),
|
|
||||||
TOML_FLOAT(minSampleShading),
|
|
||||||
TOML_BOOL(alphaToCoverageEnable),
|
|
||||||
TOML_BOOL(alphaToOneEnable)
|
|
||||||
}
|
|
||||||
TOML_END
|
|
||||||
|
|
||||||
TOML_BEGIN(VkPipelineInputAssemblyStateCreateInfo)
|
JSON_BEGIN(VkStencilOpState)
|
||||||
|
JSON_UINT32(failOp)
|
||||||
|
JSON_UINT32(passOp)
|
||||||
|
JSON_UINT32(depthFailOp)
|
||||||
|
JSON_UINT32(compareOp)
|
||||||
|
JSON_UINT32(compareMask)
|
||||||
|
JSON_UINT32(writeMask)
|
||||||
|
JSON_UINT32(reference)
|
||||||
|
JSON_END
|
||||||
|
|
||||||
|
JSON_BEGIN(VkPipelineDepthStencilStateCreateInfo)
|
||||||
|
JSON_BOOL (depthTestEnable)
|
||||||
|
JSON_BOOL (depthWriteEnable)
|
||||||
|
JSON_UINT32 (depthCompareOp)
|
||||||
|
JSON_BOOL (depthBoundsTestEnable)
|
||||||
|
JSON_BOOL (stencilTestEnable)
|
||||||
|
JSON_STRUCT (front)
|
||||||
|
JSON_STRUCT (back)
|
||||||
|
JSON_FLOAT (minDepthBounds)
|
||||||
|
JSON_FLOAT (maxDepthBounds)
|
||||||
|
JSON_END
|
||||||
|
|
||||||
|
JSON_BEGIN(VkPipelineColorBlendAttachmentState)
|
||||||
|
JSON_BOOL(blendEnable)
|
||||||
|
JSON_UINT32(srcColorBlendFactor)
|
||||||
|
JSON_UINT32(dstColorBlendFactor)
|
||||||
|
JSON_UINT32(colorBlendOp)
|
||||||
|
JSON_UINT32(srcAlphaBlendFactor)
|
||||||
|
JSON_UINT32(dstAlphaBlendFactor)
|
||||||
|
JSON_UINT32(alphaBlendOp)
|
||||||
|
JSON_UINT32(colorWriteMask)
|
||||||
|
JSON_END
|
||||||
|
|
||||||
|
JSON_BEGIN(VkPipelineColorBlendStateCreateInfo)
|
||||||
|
JSON_BOOL(logicOpEnable)
|
||||||
|
JSON_UINT32(logicOp)
|
||||||
|
JSON_ARRAY(blendConstants,4);
|
||||||
|
JSON_STRUCT_ARRAY(pAttachments,state->attachmentCount);
|
||||||
|
JSON_END
|
||||||
|
|
||||||
|
JSON_BEGIN(VkPipelineRasterizationStateCreateInfo)
|
||||||
|
JSON_BOOL(depthClampEnable)
|
||||||
|
JSON_BOOL(rasterizerDiscardEnable)
|
||||||
|
JSON_UINT32(polygonMode)
|
||||||
|
JSON_UINT32(cullMode)
|
||||||
|
JSON_UINT32(frontFace)
|
||||||
|
JSON_BOOL(depthBiasEnable)
|
||||||
|
JSON_FLOAT(depthBiasConstantFactor)
|
||||||
|
JSON_FLOAT(depthBiasClamp)
|
||||||
|
JSON_FLOAT(depthBiasSlopeFactor)
|
||||||
|
JSON_FLOAT(lineWidth)
|
||||||
|
JSON_END
|
||||||
|
|
||||||
|
JSON_BEGIN(VkPipelineMultisampleStateCreateInfo)
|
||||||
|
JSON_UINT32(rasterizationSamples)
|
||||||
|
JSON_BOOL(sampleShadingEnable)
|
||||||
|
JSON_FLOAT(minSampleShading)
|
||||||
|
JSON_BOOL(alphaToCoverageEnable)
|
||||||
|
JSON_BOOL(alphaToOneEnable)
|
||||||
|
JSON_END
|
||||||
|
|
||||||
|
JSON_BEGIN(VkPipelineInputAssemblyStateCreateInfo)
|
||||||
|
JSON_UINT32(topology)
|
||||||
|
JSON_BOOL(primitiveRestartEnable)
|
||||||
|
JSON_END
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
void SaveToJSON(const OSString &filename,const VkGraphicsPipelineCreateInfo *state)
|
||||||
{
|
{
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
|
|
||||||
const auto root=toml::table
|
root["ver"]=100;
|
||||||
{
|
root["vulkan"]=100;
|
||||||
{"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;
|
JSON_OBJECT(pDepthStencilState)
|
||||||
|
JSON_OBJECT(pColorBlendState)
|
||||||
|
JSON_OBJECT(pRasterizationState)
|
||||||
|
JSON_OBJECT(pMultisampleState)
|
||||||
|
JSON_OBJECT(pInputAssemblyState)
|
||||||
|
|
||||||
ss<<root;
|
SaveJson(root,filename);
|
||||||
|
|
||||||
const std::string str=ss.str();
|
|
||||||
|
|
||||||
filesystem::SaveMemoryToFile(filename,str.c_str(),str.length());
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user