From 88a9fdf9cbac2a6d74e60aa201f0f6e13667e4ac Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 17 May 2019 19:34:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4json/toml=E7=89=88PipelineCre?= =?UTF-8?q?ateInfo=E5=AD=98=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 3 +- src/CMakeLists.txt | 2 +- .../Vulkan/json/VKPipelineCreateInfo.JSON.cpp | 249 ------------------ .../Vulkan/toml/VKPipelineCreateInfo.TOML.cpp | 131 --------- 4 files changed, 2 insertions(+), 383 deletions(-) delete mode 100644 src/RenderDevice/Vulkan/json/VKPipelineCreateInfo.JSON.cpp delete mode 100644 src/RenderDevice/Vulkan/toml/VKPipelineCreateInfo.TOML.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ededf16..e00a9f33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cfe1a64c..0dd78eb0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ add_subdirectory(Base) -add_subdirectory(Util) +#add_subdirectory(Util) add_subdirectory(RenderDevice) add_subdirectory(Platform) diff --git a/src/RenderDevice/Vulkan/json/VKPipelineCreateInfo.JSON.cpp b/src/RenderDevice/Vulkan/json/VKPipelineCreateInfo.JSON.cpp deleted file mode 100644 index d58d9788..00000000 --- a/src/RenderDevice/Vulkan/json/VKPipelineCreateInfo.JSON.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#include -#include -#include -#include -#include - -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 - Json::Value ToJSON_Array(const T *values,const uint count) - { - Json::Value items; - - for(uint i=0;iname,count); - - template 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;iname,count); - - template - Json::Value ToJSON_StructArray(const T *object,const uint count) - { - Json::Value items; - - for(uint i=0;iname,count) - - template - void FromJSON_StructArray(const Json::Value &root,T *objects,const uint count) - { - for(uint i=0;iname,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); -} diff --git a/src/RenderDevice/Vulkan/toml/VKPipelineCreateInfo.TOML.cpp b/src/RenderDevice/Vulkan/toml/VKPipelineCreateInfo.TOML.cpp deleted file mode 100644 index c8534a2f..00000000 --- a/src/RenderDevice/Vulkan/toml/VKPipelineCreateInfo.TOML.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include -#include -#include -#include -#include - -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;iattachmentCount;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<