1b932f109ad6b92419e12f66f3e9087f2b49934cbKarl Schultz/////////////////////////////////////////////////////////////////////////////// 2e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour// 3b932f109ad6b92419e12f66f3e9087f2b49934cbKarl Schultz// Copyright (c) 2015-2016 The Khronos Group Inc. 4b932f109ad6b92419e12f66f3e9087f2b49934cbKarl Schultz// Copyright (c) 2015-2016 Valve Corporation 5b932f109ad6b92419e12f66f3e9087f2b49934cbKarl Schultz// Copyright (c) 2015-2016 LunarG, Inc. 6b932f109ad6b92419e12f66f3e9087f2b49934cbKarl Schultz// Copyright (c) 2015-2016 Google, Inc. 7e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour// 843b53e83705f02245da6ae61e31273866a35b833Jon Ashburn// Licensed under the Apache License, Version 2.0 (the "License"); 943b53e83705f02245da6ae61e31273866a35b833Jon Ashburn// you may not use this file except in compliance with the License. 1043b53e83705f02245da6ae61e31273866a35b833Jon Ashburn// You may obtain a copy of the License at 11e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour// 1243b53e83705f02245da6ae61e31273866a35b833Jon Ashburn// http://www.apache.org/licenses/LICENSE-2.0 13b932f109ad6b92419e12f66f3e9087f2b49934cbKarl Schultz// 1443b53e83705f02245da6ae61e31273866a35b833Jon Ashburn// Unless required by applicable law or agreed to in writing, software 1543b53e83705f02245da6ae61e31273866a35b833Jon Ashburn// distributed under the License is distributed on an "AS IS" BASIS, 1643b53e83705f02245da6ae61e31273866a35b833Jon Ashburn// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1743b53e83705f02245da6ae61e31273866a35b833Jon Ashburn// See the License for the specific language governing permissions and 1843b53e83705f02245da6ae61e31273866a35b833Jon Ashburn// limitations under the License. 19b932f109ad6b92419e12f66f3e9087f2b49934cbKarl Schultz/////////////////////////////////////////////////////////////////////////////// 20e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 21e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour#include "vkjson.h" 22e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 23e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour#include <stdlib.h> 24e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour#include <string.h> 25e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 26e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour#include <iostream> 27e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 28e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour#define EXPECT(X) if (!(X)) \ 29e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour ReportFailure(__FILE__, __LINE__, #X); 30e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 31e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour#define ASSERT(X) if (!(X)) { \ 32e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour ReportFailure(__FILE__, __LINE__, #X); \ 33e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour return 2; \ 34e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour} 35e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 36e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labourint g_failures; 37e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 38e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labourvoid ReportFailure(const char* file, int line, const char* assertion) { 39e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour std::cout << file << ":" << line << ": \"" << assertion << "\" failed." 40e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour << std::endl; 41e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour ++g_failures; 42e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour} 43e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 44e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labourint main(int argc, char* argv[]) { 45e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour std::string errors; 46e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour bool result = false; 47e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 486f328aec9b6c8667e12fee73847d9954814991ddJesse Hall VkJsonInstance instance; 496f328aec9b6c8667e12fee73847d9954814991ddJesse Hall instance.devices.resize(1); 506f328aec9b6c8667e12fee73847d9954814991ddJesse Hall VkJsonDevice& device = instance.devices[0]; 516f328aec9b6c8667e12fee73847d9954814991ddJesse Hall 52e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour const char name[] = "Test device"; 53594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall memcpy(device.properties.deviceName, name, sizeof(name)); 54594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall device.properties.limits.maxImageDimension1D = 3; 55594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall device.properties.limits.maxSamplerLodBias = 3.5f; 56594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall device.properties.limits.bufferImageGranularity = 0x1ffffffffull; 57594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall device.properties.limits.maxViewportDimensions[0] = 1; 58594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall device.properties.limits.maxViewportDimensions[1] = 2; 59e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour VkFormatProperties format_props = { 60e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT, 61e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT, 62e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT}; 63594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall device.formats.insert(std::make_pair(VK_FORMAT_R8_UNORM, format_props)); 64594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall device.formats.insert(std::make_pair(VK_FORMAT_R8G8_UNORM, format_props)); 656f328aec9b6c8667e12fee73847d9954814991ddJesse Hall 666f328aec9b6c8667e12fee73847d9954814991ddJesse Hall std::string json = VkJsonInstanceToJson(instance); 67e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour std::cout << json << std::endl; 68e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 696f328aec9b6c8667e12fee73847d9954814991ddJesse Hall VkJsonInstance instance2; 706f328aec9b6c8667e12fee73847d9954814991ddJesse Hall result = VkJsonInstanceFromJson(json, &instance2, &errors); 71e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour EXPECT(result); 72e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour if (!result) 73e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour std::cout << "Error: " << errors << std::endl; 746f328aec9b6c8667e12fee73847d9954814991ddJesse Hall const VkJsonDevice& device2 = instance2.devices.at(0); 75e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 76594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall EXPECT(!memcmp(&device.properties, &device2.properties, 77594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall sizeof(device.properties))); 78594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall for (auto& kv : device.formats) { 79594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall auto it = device2.formats.find(kv.first); 80594091db7f508f6073975efddb5fab8d0fb273e7Jesse Hall EXPECT(it != device2.formats.end()); 81e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour EXPECT(!memcmp(&kv.second, &it->second, sizeof(kv.second))); 82e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour } 83e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 84e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour VkImageFormatProperties props = {0}; 85e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour json = VkJsonImageFormatPropertiesToJson(props); 86e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour VkImageFormatProperties props2 = {0}; 87e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour result = VkJsonImageFormatPropertiesFromJson(json, &props2, &errors); 88e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour EXPECT(result); 89e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour if (!result) 90e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour std::cout << "Error: " << errors << std::endl; 91e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 92e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour EXPECT(!memcmp(&props, &props2, sizeof(props))); 93e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour 94e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour if (g_failures) { 95e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour std::cout << g_failures << " failures." << std::endl; 96e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour return 1; 97e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour } else { 98e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour std::cout << "Success." << std::endl; 99e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour return 0; 100e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour } 101e3795c1c4e1fd43419a156d9f7858327768ccb76Antoine Labour} 102