From 6eea12f99ba825086838554d7702217d780282be Mon Sep 17 00:00:00 2001 From: xinyunh Date: Thu, 17 Jul 2025 17:21:48 -0700 Subject: [PATCH] Cardboard SDK v1.30.0 --- hellocardboard-android/build.gradle | 2 +- hellocardboard-ios/HelloCardboard-Info.plist | 4 +- .../android/vulkan_distortion_renderer.cc | 235 ++++++++--------- sdk/screen_params/ios/screen_params.mm | 241 +++++------------- sdk/sdk.xcodeproj/project.pbxproj | 6 + .../xr_unity_plugin/vulkan/vulkan_renderer.cc | 108 ++++---- .../vulkan/vulkan_widgets_renderer.cc | 206 +++++++-------- .../unity_plugin_api/update_unity_headers.md | 7 +- 8 files changed, 349 insertions(+), 460 deletions(-) diff --git a/hellocardboard-android/build.gradle b/hellocardboard-android/build.gradle index aefe5a4a..157f9102 100644 --- a/hellocardboard-android/build.gradle +++ b/hellocardboard-android/build.gradle @@ -18,7 +18,7 @@ android { minSdkVersion 26 targetSdkVersion 35 versionCode 1 - versionName "1.29.0" + versionName "1.30.0" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' ndk { abiFilters 'armeabi-v7a', 'arm64-v8a' diff --git a/hellocardboard-ios/HelloCardboard-Info.plist b/hellocardboard-ios/HelloCardboard-Info.plist index 68404581..ddcf49e6 100644 --- a/hellocardboard-ios/HelloCardboard-Info.plist +++ b/hellocardboard-ios/HelloCardboard-Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.29.0 + 1.30.0 CFBundleVersion - 1.29.0 + 1.30.0 LSRequiresIPhoneOS NSCameraUsageDescription diff --git a/sdk/rendering/android/vulkan_distortion_renderer.cc b/sdk/rendering/android/vulkan_distortion_renderer.cc index e9d51435..7219c8cf 100644 --- a/sdk/rendering/android/vulkan_distortion_renderer.cc +++ b/sdk/rendering/android/vulkan_distortion_renderer.cc @@ -27,6 +27,7 @@ #include "util/is_arg_null.h" #include "util/is_initialized.h" #include "util/logging.h" +#include // Vulkan call wrapper #define CALL_VK(func) \ @@ -183,22 +184,22 @@ class VulkanDistortionRenderer : public DistortionRenderer { void CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& buffer_memory) { - VkBufferCreateInfo buffer_info{ - .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, - .size = size, - .usage = usage, - .sharingMode = VK_SHARING_MODE_EXCLUSIVE}; + VkBufferCreateInfo buffer_info{}; + buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info.size = size; + buffer_info.usage = usage; + buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; CALL_VK(vkCreateBuffer(logical_device_, &buffer_info, nullptr, &buffer)); VkMemoryRequirements mem_requirements; vkGetBufferMemoryRequirements(logical_device_, buffer, &mem_requirements); - VkMemoryAllocateInfo alloc_info{ - .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, - .allocationSize = mem_requirements.size, - .memoryTypeIndex = - FindMemoryType(mem_requirements.memoryTypeBits, properties)}; + VkMemoryAllocateInfo alloc_info{}; + alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + alloc_info.allocationSize = mem_requirements.size, + alloc_info.memoryTypeIndex = + FindMemoryType(mem_requirements.memoryTypeBits, properties); CALL_VK(vkAllocateMemory(logical_device_, &alloc_info, nullptr, &buffer_memory)); @@ -222,30 +223,30 @@ class VulkanDistortionRenderer : public DistortionRenderer { }; bindings[0] = sampler_layout_binding; - VkDescriptorSetLayoutCreateInfo layout_info = { - .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, - .bindingCount = 1, - .pBindings = bindings, - }; + VkDescriptorSetLayoutCreateInfo layout_info{}; + layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + layout_info.bindingCount = 1; + layout_info.pBindings = bindings; + CALL_VK(vkCreateDescriptorSetLayout(logical_device_, &layout_info, nullptr, &descriptor_set_layout_)); // Setup push constants. VkPushConstantRange push_constant_range = { - .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, - .offset = 0, - .size = sizeof(PushConstantsObject), + .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, + .offset = 0, + .size = sizeof(PushConstantsObject), }; // Create Pipeline Layout - VkPipelineLayoutCreateInfo pipeline_layout_create_info{ - .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, - .pNext = nullptr, - .setLayoutCount = 1, - .pSetLayouts = &descriptor_set_layout_, - .pushConstantRangeCount = 1, - .pPushConstantRanges = &push_constant_range, - }; + VkPipelineLayoutCreateInfo pipeline_layout_create_info{}; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.pNext = nullptr; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout_; + pipeline_layout_create_info.pushConstantRangeCount = 1; + pipeline_layout_create_info.pPushConstantRanges = &push_constant_range; CALL_VK(vkCreatePipelineLayout(logical_device_, &pipeline_layout_create_info, nullptr, &pipeline_layout_)); @@ -254,23 +255,22 @@ class VulkanDistortionRenderer : public DistortionRenderer { VkPhysicalDeviceProperties properties{}; vkGetPhysicalDeviceProperties(physical_device_, &properties); - VkSamplerCreateInfo sampler = { - .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, - .pNext = nullptr, - .magFilter = VK_FILTER_NEAREST, - .minFilter = VK_FILTER_NEAREST, - .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST, - .addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT, - .addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT, - .addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT, - .mipLodBias = 0.0f, - .maxAnisotropy = properties.limits.maxSamplerAnisotropy, - .compareOp = VK_COMPARE_OP_NEVER, - .minLod = 0.0f, - .maxLod = 0.0f, - .borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE, - .unnormalizedCoordinates = VK_FALSE, - }; + VkSamplerCreateInfo sampler{}; + sampler.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler.pNext = nullptr; + sampler.magFilter = VK_FILTER_NEAREST; + sampler.minFilter = VK_FILTER_NEAREST; + sampler.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; + sampler.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler.mipLodBias = 0.0f; + sampler.maxAnisotropy = properties.limits.maxSamplerAnisotropy; + sampler.compareOp = VK_COMPARE_OP_NEVER; + sampler.minLod = 0.0f; + sampler.maxLod = 0.0f; + sampler.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; + sampler.unnormalizedCoordinates = VK_FALSE; CALL_VK( vkCreateSampler(logical_device_, &sampler, nullptr, &texture_sampler_)); @@ -352,65 +352,63 @@ class VulkanDistortionRenderer : public DistortionRenderer { }; // Specify viewport info - VkPipelineViewportStateCreateInfo viewport_info{ - .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, - .pNext = nullptr, - .viewportCount = 1, - .pViewports = nullptr, - .scissorCount = 1, - .pScissors = nullptr, - }; + VkPipelineViewportStateCreateInfo viewport_info{}; + viewport_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_info.pNext = nullptr; + viewport_info.viewportCount = 1; + viewport_info.pViewports = nullptr; + viewport_info.scissorCount = 1; + viewport_info.pScissors = nullptr; // Specify multisample info VkSampleMask sample_mask = ~0u; - VkPipelineMultisampleStateCreateInfo multisample_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, - .pNext = nullptr, - .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT, - .sampleShadingEnable = VK_FALSE, - .minSampleShading = 0, - .pSampleMask = &sample_mask, - .alphaToCoverageEnable = VK_FALSE, - .alphaToOneEnable = VK_FALSE, - }; + VkPipelineMultisampleStateCreateInfo multisample_info{}; + multisample_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisample_info.pNext = nullptr; + multisample_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + multisample_info.sampleShadingEnable = VK_FALSE; + multisample_info.minSampleShading = 0; + multisample_info.pSampleMask = &sample_mask; + multisample_info.alphaToCoverageEnable = VK_FALSE; + multisample_info.alphaToOneEnable = VK_FALSE; // Specify color blend state - VkPipelineColorBlendAttachmentState attachment_states = { - .blendEnable = VK_FALSE, - .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | - VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, - }; - - VkPipelineColorBlendStateCreateInfo color_blend_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, - .pNext = nullptr, - .flags = 0, - .logicOpEnable = VK_FALSE, - .logicOp = VK_LOGIC_OP_COPY, - .attachmentCount = 1, - .pAttachments = &attachment_states, - }; + VkPipelineColorBlendAttachmentState attachment_states{}; + attachment_states.blendEnable = VK_FALSE, + attachment_states.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + VkPipelineColorBlendStateCreateInfo color_blend_info{}; + color_blend_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blend_info.pNext = nullptr; + color_blend_info.flags = 0; + color_blend_info.logicOpEnable = VK_FALSE; + color_blend_info.logicOp = VK_LOGIC_OP_COPY; + color_blend_info.attachmentCount = 1; + color_blend_info.pAttachments = &attachment_states; // Specify rasterizer info - VkPipelineRasterizationStateCreateInfo raster_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, - .pNext = nullptr, - .depthClampEnable = VK_FALSE, - .rasterizerDiscardEnable = VK_FALSE, - .polygonMode = VK_POLYGON_MODE_FILL, - .cullMode = VK_CULL_MODE_NONE, - .frontFace = VK_FRONT_FACE_CLOCKWISE, - .depthBiasEnable = VK_FALSE, - .lineWidth = 1, - }; + VkPipelineRasterizationStateCreateInfo raster_info{}; + raster_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + raster_info.pNext = nullptr; + raster_info.depthClampEnable = VK_FALSE; + raster_info.rasterizerDiscardEnable = VK_FALSE; + raster_info.polygonMode = VK_POLYGON_MODE_FILL; + raster_info.cullMode = VK_CULL_MODE_NONE; + raster_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + raster_info.depthBiasEnable = VK_FALSE; + raster_info.lineWidth = 1; // Specify input assembler state - VkPipelineInputAssemblyStateCreateInfo input_assembly_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, - .pNext = nullptr, - .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, - .primitiveRestartEnable = VK_FALSE, - }; + VkPipelineInputAssemblyStateCreateInfo input_assembly_info{}; + input_assembly_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_info.pNext = nullptr; + input_assembly_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; + input_assembly_info.primitiveRestartEnable = VK_FALSE; // Specify vertex input state VkVertexInputBindingDescription vertex_input_bindings = { @@ -433,33 +431,35 @@ class VulkanDistortionRenderer : public DistortionRenderer { .offset = sizeof(float) * 2, }}; - VkPipelineVertexInputStateCreateInfo vertex_input_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, - .pNext = nullptr, - .vertexBindingDescriptionCount = 1, - .pVertexBindingDescriptions = &vertex_input_bindings, - .vertexAttributeDescriptionCount = 2, - .pVertexAttributeDescriptions = vertex_input_attributes, - }; + VkPipelineVertexInputStateCreateInfo vertex_input_info{}; + vertex_input_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_info.pNext = nullptr; + vertex_input_info.vertexBindingDescriptionCount = 1; + vertex_input_info.pVertexBindingDescriptions = &vertex_input_bindings; + vertex_input_info.vertexAttributeDescriptionCount = 2; + vertex_input_info.pVertexAttributeDescriptions = vertex_input_attributes; VkDynamicState dynamic_state_enables[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, }; - VkPipelineDynamicStateCreateInfo dynamic_state_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, - .pNext = nullptr, - .dynamicStateCount = 2, - .pDynamicStates = dynamic_state_enables}; - - VkPipelineDepthStencilStateCreateInfo depth_stencil = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, - .depthTestEnable = VK_TRUE, - .depthWriteEnable = VK_TRUE, - .depthCompareOp = VK_COMPARE_OP_LESS, - .depthBoundsTestEnable = VK_FALSE, - .stencilTestEnable = VK_FALSE}; + VkPipelineDynamicStateCreateInfo dynamic_state_info{}; + dynamic_state_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_info.pNext = nullptr; + dynamic_state_info.dynamicStateCount = 2; + dynamic_state_info.pDynamicStates = dynamic_state_enables; + + VkPipelineDepthStencilStateCreateInfo depth_stencil{}; + depth_stencil.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil.depthTestEnable = VK_TRUE; + depth_stencil.depthWriteEnable = VK_TRUE; + depth_stencil.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil.depthBoundsTestEnable = VK_FALSE; + depth_stencil.stencilTestEnable = VK_FALSE; // Create the pipeline VkPipelineShaderStageCreateInfo shader_stages[2] = {vertex_shader_state, @@ -550,13 +550,15 @@ class VulkanDistortionRenderer : public DistortionRenderer { VkCommandBuffer command_buffer, uint32_t image_index, int x, int y, int width, int height) { // Update Push constants. - PushConstantsObject push_constants { + PushConstantsObject push_constants{ .left_u = eye_description->left_u, .right_u = eye_description->right_u, .top_v = eye_description->top_v, .bottom_v = eye_description->bottom_v, }; - vkCmdPushConstants(command_buffer, pipeline_layout_, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(PushConstantsObject), &push_constants); + vkCmdPushConstants(command_buffer, pipeline_layout_, + VK_SHADER_STAGE_VERTEX_BIT, 0, + sizeof(PushConstantsObject), &push_constants); // Update image and view VkImage current_image = reinterpret_cast(eye_description->texture); @@ -618,6 +620,7 @@ class VulkanDistortionRenderer : public DistortionRenderer { .maxDepth = 1.0}; VkRect2D scissor = { + .offset = {.x = 0, .y = 0}, .extent = {.width = static_cast(width / 2), .height = static_cast(height)}, }; diff --git a/sdk/screen_params/ios/screen_params.mm b/sdk/screen_params/ios/screen_params.mm index 54dbc909..29b2dba2 100644 --- a/sdk/screen_params/ios/screen_params.mm +++ b/sdk/screen_params/ios/screen_params.mm @@ -14,207 +14,82 @@ * limitations under the License. */ #import "screen_params.h" - +#import "screen_params/ios/sdk_bundle_finder.h" +#import "util/logging.h" #import #import +#import +#import +#import +#import +#import + namespace cardboard { namespace screen_params { -// iPhone Generations. -NSString *const kGIPDeviceGenerationiPhone2G = @"iPhone"; -NSString *const kGIPDeviceGenerationiPhone3G = @"iPhone 3G"; -NSString *const kGIPDeviceGenerationiPhone3GS = @"iPhone 3Gs"; -NSString *const kGIPDeviceGenerationiPhone4 = @"iPhone 4"; -NSString *const kGIPDeviceGenerationiPhone4S = @"iPhone 4s"; -NSString *const kGIPDeviceGenerationiPhone5 = @"iPhone 5"; -NSString *const kGIPDeviceGenerationiPhone5c = @"iPhone 5c"; -NSString *const kGIPDeviceGenerationiPhone5s = @"iPhone 5s"; -NSString *const kGIPDeviceGenerationiPhone6 = @"iPhone 6"; -NSString *const kGIPDeviceGenerationiPhone6Plus = @"iPhone 6 Plus"; -NSString *const kGIPDeviceGenerationiPhone6s = @"iPhone 6s"; -NSString *const kGIPDeviceGenerationiPhone6sPlus = @"iPhone 6s Plus"; -NSString *const kGIPDeviceGenerationiPhone7 = @"iPhone 7"; -NSString *const kGIPDeviceGenerationiPhone7Plus = @"iPhone 7 Plus"; -NSString *const kGIPDeviceGenerationiPhone8 = @"iPhone 8"; -NSString *const kGIPDeviceGenerationiPhone8Plus = @"iPhone 8 Plus"; -NSString *const kGIPDeviceGenerationiPhoneSE = @"iPhone SE"; -NSString *const kGIPDeviceGenerationiPhoneX = @"iPhone X"; -NSString *const kGIPDeviceGenerationiPhoneXr = @"iPhone Xr"; -NSString *const kGIPDeviceGenerationiPhoneXs = @"iPhone Xs"; -NSString *const kGIPDeviceGenerationiPhoneXsMax = @"iPhone Xs Max"; -NSString *const kGIPDeviceGenerationiPhone11 = @"iPhone 11"; -NSString *const kGIPDeviceGenerationiPhone11Pro = @"iPhone 11 Pro"; -NSString *const kGIPDeviceGenerationiPhone11ProMax = @"iPhone 11 Pro Max"; -NSString *const kGIPDeviceGenerationiPhoneSimulator = @"iPhone Simulator"; -NSString *const kGIPDeviceGenerationiPhone12Mini = @"iPhone 12 Mini"; -NSString *const kGIPDeviceGenerationiPhone12 = @"iPhone 12"; -NSString *const kGIPDeviceGenerationiPhone12Pro = @"iPhone 12 Pro"; -NSString *const kGIPDeviceGenerationiPhone12ProMax = @"iPhone 12 Pro Max"; -NSString *const kGIPDeviceGenerationiPhone13Mini = @"iPhone 13 Mini"; -NSString *const kGIPDeviceGenerationiPhone13 = @"iPhone 13"; -NSString *const kGIPDeviceGenerationiPhone13Pro = @"iPhone 13 Pro"; -NSString *const kGIPDeviceGenerationiPhone13ProMax = @"iPhone 13 Pro Max"; -NSString *const kGIPDeviceGenerationiPhone14 = @"iPhone 14"; -NSString *const kGIPDeviceGenerationiPhone14Plus = @"iPhone 14 Plus"; -NSString *const kGIPDeviceGenerationiPhone14Pro = @"iPhone 14 Pro"; -NSString *const kGIPDeviceGenerationiPhone14ProMax = @"iPhone 14 Pro Max"; -NSString *const kGIPDeviceGenerationiPhone15 = @"iPhone 15"; -NSString *const kGIPDeviceGenerationiPhone15Plus = @"iPhone 15 Plus"; -NSString *const kGIPDeviceGenerationiPhone15Pro = @"iPhone 15 Pro"; -NSString *const kGIPDeviceGenerationiPhone15ProMax = @"iPhone 15 Pro Max"; -NSString *const kGIPDeviceGenerationiPhone16 = @"iPhone 16"; -NSString *const kGIPDeviceGenerationiPhone16Plus = @"iPhone 16 Plus"; -NSString *const kGIPDeviceGenerationiPhone16Pro = @"iPhone 16 Pro"; -NSString *const kGIPDeviceGenerationiPhone16ProMax = @"iPhone 16 Pro Max"; - -// iPod touch Generations. -NSString *const kGIPDeviceGenerationiPodTouch7thGen = @"iPod touch (7th generation)"; - -// DPI for iPod touch, iPhone (default) and iPhone+: http://dpi.lv/ -static CGFloat const kDefaultDpi = 326.0f; -static CGFloat const kIPhonePlusDpi = 401.0f; -static CGFloat const kIPhoneOledDpi = 458.0f; -static CGFloat const kIPhoneXrDpi = 324.0f; -static CGFloat const kIPhoneXsMaxDpi = 456.0f; -static CGFloat const kIPhone12MiniDpi = 476.0f; -static CGFloat const kIPhone12Dpi = 460.0f; +constexpr CGFloat kDefaultDpi = 326.0f; +using IosScreenParamsMap = std::unordered_map>; + +std::array stringSplit(const std::string& s, const char delimiter) { + std::array tokens; + std::string token; + std::istringstream tokenStream(s); + + for (uint32_t i = 0; i < 3 && std::getline(tokenStream, token, delimiter); i++) { + tokens[i] = token; + } + + return tokens; +} + +IosScreenParamsMap loadIosScreenParamsFromFile(std::string_view filePath) { + IosScreenParamsMap screenParams; + + std::ifstream screenParamsFile{filePath.data()}; + if (!screenParamsFile.is_open()) { + CARDBOARD_LOGE("Couldn't open file: %s", filePath.data()); + return screenParams; + } + + std::string line; + std::getline(screenParamsFile, line); // Skip the header + while (std::getline(screenParamsFile, line)) { + const std::array tokens {stringSplit(line, ',')}; + screenParams[tokens.at(0)] = {tokens.at(1), strtod(tokens.at(2).c_str(), nullptr)}; + } + + return screenParams; +} CGFloat getDpi() { // Gets model name. struct utsname systemInfo; uname(&systemInfo); - NSString *modelName = [NSString stringWithCString:systemInfo.machine - encoding:NSUTF8StringEncoding]; - - // Narrows it down to a specific generation, if we recognize it. - // Information taken from http://theiphonewiki.com/wiki/Models - NSDictionary *models = @{ - @"iPhone1,1" : kGIPDeviceGenerationiPhone2G, - @"iPhone1,2" : kGIPDeviceGenerationiPhone3G, - @"iPhone2,1" : kGIPDeviceGenerationiPhone3GS, - @"iPhone3,1" : kGIPDeviceGenerationiPhone4, - @"iPhone3,2" : kGIPDeviceGenerationiPhone4, - @"iPhone3,3" : kGIPDeviceGenerationiPhone4, - @"iPhone4,1" : kGIPDeviceGenerationiPhone4S, - @"iPhone4,2" : kGIPDeviceGenerationiPhone4S, - @"iPhone5,1" : kGIPDeviceGenerationiPhone5, - @"iPhone5,2" : kGIPDeviceGenerationiPhone5, - @"iPhone5,3" : kGIPDeviceGenerationiPhone5c, - @"iPhone5,4" : kGIPDeviceGenerationiPhone5c, - @"iPhone6,1" : kGIPDeviceGenerationiPhone5s, - @"iPhone6,2" : kGIPDeviceGenerationiPhone5s, - @"iPhone7,1" : kGIPDeviceGenerationiPhone6Plus, // 6+ is 7,1 - @"iPhone7,2" : kGIPDeviceGenerationiPhone6, // 6 is 7,2 - @"iPhone8,1" : kGIPDeviceGenerationiPhone6s, - @"iPhone8,2" : kGIPDeviceGenerationiPhone6sPlus, - // There is no iPhone8,3. - @"iPhone8,4" : kGIPDeviceGenerationiPhoneSE, - @"iPhone9,1" : kGIPDeviceGenerationiPhone7, - @"iPhone9,2" : kGIPDeviceGenerationiPhone7Plus, - @"iPhone9,3" : kGIPDeviceGenerationiPhone7, - @"iPhone9,4" : kGIPDeviceGenerationiPhone7Plus, - @"iPhone10,1" : kGIPDeviceGenerationiPhone8, - @"iPhone10,2" : kGIPDeviceGenerationiPhone8Plus, - @"iPhone10,3" : kGIPDeviceGenerationiPhoneX, - @"iPhone10,4" : kGIPDeviceGenerationiPhone8, - @"iPhone10,5" : kGIPDeviceGenerationiPhone8Plus, - @"iPhone10,6" : kGIPDeviceGenerationiPhoneX, - @"iPhone11,2" : kGIPDeviceGenerationiPhoneXs, - @"iPhone11,4" : kGIPDeviceGenerationiPhoneXsMax, - @"iPhone11,6" : kGIPDeviceGenerationiPhoneXsMax, - @"iPhone11,8" : kGIPDeviceGenerationiPhoneXr, - @"iPhone12,1" : kGIPDeviceGenerationiPhone11, - @"iPhone12,3" : kGIPDeviceGenerationiPhone11Pro, - @"iPhone12,5" : kGIPDeviceGenerationiPhone11ProMax, - @"iPhone13,1" : kGIPDeviceGenerationiPhone12Mini, - @"iPhone13,2" : kGIPDeviceGenerationiPhone12, - @"iPhone13,3" : kGIPDeviceGenerationiPhone12Pro, - @"iPhone13,4" : kGIPDeviceGenerationiPhone12ProMax, - @"iPhone14,4" : kGIPDeviceGenerationiPhone13Mini, - @"iPhone14,5" : kGIPDeviceGenerationiPhone13, - @"iPhone14,2" : kGIPDeviceGenerationiPhone13Pro, - @"iPhone14,3" : kGIPDeviceGenerationiPhone13ProMax, - @"iPhone14,7" : kGIPDeviceGenerationiPhone14, - @"iPhone14,8" : kGIPDeviceGenerationiPhone14Plus, - @"iPhone15,2" : kGIPDeviceGenerationiPhone14Pro, - @"iPhone15,3" : kGIPDeviceGenerationiPhone14ProMax, - @"iPhone15,4" : kGIPDeviceGenerationiPhone15, - @"iPhone15,5" : kGIPDeviceGenerationiPhone15Plus, - @"iPhone16,1" : kGIPDeviceGenerationiPhone15Pro, - @"iPhone16,2" : kGIPDeviceGenerationiPhone15ProMax, - @"iPhone17,3" : kGIPDeviceGenerationiPhone16, - @"iPhone17,4" : kGIPDeviceGenerationiPhone16Plus, - @"iPhone17,1" : kGIPDeviceGenerationiPhone16Pro, - @"iPhone17,2" : kGIPDeviceGenerationiPhone16ProMax, - @"iPod9,1" : kGIPDeviceGenerationiPodTouch7thGen, - }; - NSString *model = models[modelName]; - if (!model) { - return kDefaultDpi; - } + NSString *machineName = [NSString stringWithCString:systemInfo.machine + encoding:NSUTF8StringEncoding]; + machineName = [machineName stringByReplacingOccurrencesOfString:@"," withString:@"."]; + const std::string modelName{[machineName UTF8String]}; + + CARDBOARD_LOGI("Model name: %s", modelName.c_str()); + + const SDKBundleFinder *bundleFinder = [[SDKBundleFinder alloc] init]; + const NSBundle *sdkBundle = [bundleFinder getSDKBundle]; + const NSString *screenParamsFilePath = [sdkBundle pathForResource:@"resolutions" ofType:@"csv"]; + const IosScreenParamsMap screenParams{loadIosScreenParamsFromFile([screenParamsFilePath UTF8String])}; - // Gets Dpi for a particular generation. - NSDictionary *dpis = @{ - kGIPDeviceGenerationiPhone2G : @(kDefaultDpi), - kGIPDeviceGenerationiPhone3G : @(kDefaultDpi), - kGIPDeviceGenerationiPhone3GS : @(kDefaultDpi), - kGIPDeviceGenerationiPhone4 : @(kDefaultDpi), - kGIPDeviceGenerationiPhone4S : @(kDefaultDpi), - kGIPDeviceGenerationiPhone5 : @(kDefaultDpi), - kGIPDeviceGenerationiPhone5c : @(kDefaultDpi), - kGIPDeviceGenerationiPhone5s : @(kDefaultDpi), - kGIPDeviceGenerationiPhone6Plus : @(kIPhonePlusDpi), - kGIPDeviceGenerationiPhone6 : @(kDefaultDpi), - kGIPDeviceGenerationiPhone6s : @(kDefaultDpi), - kGIPDeviceGenerationiPhone6sPlus : @(kIPhonePlusDpi), - kGIPDeviceGenerationiPhoneSE : @(kDefaultDpi), - kGIPDeviceGenerationiPhone7 : @(kDefaultDpi), - kGIPDeviceGenerationiPhone7Plus : @(kIPhonePlusDpi), - kGIPDeviceGenerationiPhone8 : @(kDefaultDpi), - kGIPDeviceGenerationiPhone8Plus : @(kIPhonePlusDpi), - kGIPDeviceGenerationiPhoneX : @(kIPhoneOledDpi), - kGIPDeviceGenerationiPhoneXs : @(kIPhoneOledDpi), - kGIPDeviceGenerationiPhoneXsMax : @(kIPhoneXsMaxDpi), - kGIPDeviceGenerationiPhoneXr : @(kIPhoneXrDpi), - kGIPDeviceGenerationiPhone11 : @(kDefaultDpi), - kGIPDeviceGenerationiPhone11Pro : @(kIPhoneOledDpi), - kGIPDeviceGenerationiPhone11ProMax : @(kIPhoneOledDpi), - kGIPDeviceGenerationiPhone12Mini : @(kIPhone12MiniDpi), - kGIPDeviceGenerationiPhone12 : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone12Pro : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone12ProMax : @(kIPhoneOledDpi), - kGIPDeviceGenerationiPhone13Mini : @(kIPhone12MiniDpi), - kGIPDeviceGenerationiPhone13 : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone13Pro : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone13ProMax : @(kIPhoneOledDpi), - kGIPDeviceGenerationiPhone14 : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone14Plus : @(kIPhoneOledDpi), - kGIPDeviceGenerationiPhone14Pro : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone14ProMax : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone15 : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone15Plus : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone15Pro : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone15ProMax : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone16 : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone16Plus : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone16Pro : @(kIPhone12Dpi), - kGIPDeviceGenerationiPhone16ProMax : @(kIPhone12Dpi), - kGIPDeviceGenerationiPodTouch7thGen : @(kDefaultDpi), - }; - - NSNumber *dpi = dpis[model]; - if (!dpi) { + if (screenParams.find(modelName) == screenParams.end()) { + CARDBOARD_LOGE("Couldn't find screen params for model: %s", modelName.c_str()); return kDefaultDpi; } - return dpi.doubleValue; + return screenParams.at(modelName).second; } -void getScreenSizeInMeters(int width_pixels, int height_pixels, float* out_width_meters, - float* out_height_meters) { - float dpi = getDpi(); +void getScreenSizeInMeters(int width_pixels, int height_pixels, float *out_width_meters, + float *out_height_meters) { + const float dpi = getDpi(); *out_width_meters = (width_pixels / dpi) * kMetersPerInch; *out_height_meters = (height_pixels / dpi) * kMetersPerInch; } diff --git a/sdk/sdk.xcodeproj/project.pbxproj b/sdk/sdk.xcodeproj/project.pbxproj index 11b4fc56..418808c4 100644 --- a/sdk/sdk.xcodeproj/project.pbxproj +++ b/sdk/sdk.xcodeproj/project.pbxproj @@ -48,6 +48,7 @@ 7B76813B24A3FA6B00E92050 /* display.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7B76813524A3FA6B00E92050 /* display.cc */; }; 7B76813C24A3FA6B00E92050 /* main.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7B76813624A3FA6B00E92050 /* main.cc */; }; 7B76813D24A3FA6B00E92050 /* math_tools.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7B76813724A3FA6B00E92050 /* math_tools.cc */; }; + C6BAF6162E2696240018EFED /* sdk_bundle_finder.mm in Sources */ = {isa = PBXBuildFile; fileRef = C6BAF6152E2696240018EFED /* sdk_bundle_finder.mm */; }; E01C984226B44A72001BB0E3 /* cardboard_display_api.cc in Sources */ = {isa = PBXBuildFile; fileRef = E01C984026B44A71001BB0E3 /* cardboard_display_api.cc */; }; E0DFCFED26B3474400F285A5 /* cardboard_input_api.cc in Sources */ = {isa = PBXBuildFile; fileRef = E0DFCFEC26B3474400F285A5 /* cardboard_input_api.cc */; }; /* End PBXBuildFile section */ @@ -168,6 +169,8 @@ 7B76815224A3FA8100E92050 /* IUnityXRInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IUnityXRInput.h; sourceTree = ""; }; 7B76815324A3FA8100E92050 /* IUnityGraphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IUnityGraphics.h; sourceTree = ""; }; 7B76815424A3FA8100E92050 /* IUnityGraphicsD3D9.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IUnityGraphicsD3D9.h; sourceTree = ""; }; + C6BAF6142E2696240018EFED /* sdk_bundle_finder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sdk_bundle_finder.h; sourceTree = ""; }; + C6BAF6152E2696240018EFED /* sdk_bundle_finder.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = sdk_bundle_finder.mm; sourceTree = ""; }; E01C984026B44A71001BB0E3 /* cardboard_display_api.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cardboard_display_api.cc; sourceTree = ""; }; E01C984126B44A71001BB0E3 /* cardboard_display_api.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cardboard_display_api.h; sourceTree = ""; }; E0DFCFEB26B3474400F285A5 /* cardboard_input_api.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cardboard_input_api.h; sourceTree = ""; }; @@ -252,6 +255,8 @@ 0FD201F923575F3A00B3C342 /* ios */ = { isa = PBXGroup; children = ( + C6BAF6142E2696240018EFED /* sdk_bundle_finder.h */, + C6BAF6152E2696240018EFED /* sdk_bundle_finder.mm */, 0FD201FA23575F3A00B3C342 /* screen_params.mm */, ); path = ios; @@ -504,6 +509,7 @@ 0FD2024B23575F3B00B3C342 /* device_gyroscope_sensor.mm in Sources */, E0DFCFED26B3474400F285A5 /* cardboard_input_api.cc in Sources */, 0FD2024223575F3B00B3C342 /* matrixutils.cc in Sources */, + C6BAF6162E2696240018EFED /* sdk_bundle_finder.mm in Sources */, 0FD2025F2357613600B3C342 /* cardboard_device.pb.cc in Sources */, 0FD2024723575F3B00B3C342 /* median_filter.cc in Sources */, 0FD2024523575F3B00B3C342 /* head_tracker.cc in Sources */, diff --git a/sdk/unity/xr_unity_plugin/vulkan/vulkan_renderer.cc b/sdk/unity/xr_unity_plugin/vulkan/vulkan_renderer.cc index 7d68318d..28a2736b 100644 --- a/sdk/unity/xr_unity_plugin/vulkan/vulkan_renderer.cc +++ b/sdk/unity/xr_unity_plugin/vulkan/vulkan_renderer.cc @@ -26,6 +26,7 @@ #include "unity/xr_unity_plugin/cardboard_display_api.h" #include "unity/xr_unity_plugin/renderer.h" #include "unity/xr_unity_plugin/vulkan/vulkan_widgets_renderer.h" +#include // clang-format off #include "IUnityRenderingExtensions.h" #include "IUnityGraphicsVulkan.h" @@ -273,6 +274,7 @@ class VulkanRenderer : public Renderer { // Create RenderPass const VkAttachmentDescription attachment_descriptions{ + .flags = 0, .format = VK_FORMAT_R8G8B8A8_SRGB, .samples = VK_SAMPLE_COUNT_1_BIT, .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR, @@ -385,26 +387,26 @@ class VulkanRenderer : public Renderer { void CreateRenderTexture(RenderTexture* render_texture, int screen_width, int screen_height) override { - VkImageCreateInfo imageInfo = { - .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, - .flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, - .imageType = VK_IMAGE_TYPE_2D, - .format = VK_FORMAT_R8G8B8A8_SRGB, - .extent = - { - .width = static_cast(screen_width / 2), - .height = static_cast(screen_height), - .depth = 1, - }, - .mipLevels = 1, - .arrayLayers = 1, - .samples = VK_SAMPLE_COUNT_1_BIT, - .tiling = VK_IMAGE_TILING_OPTIMAL, - .usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | - VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, - .sharingMode = VK_SHARING_MODE_EXCLUSIVE, - .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, - }; + VkImageCreateInfo imageInfo {}; + imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + imageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; + imageInfo.imageType = VK_IMAGE_TYPE_2D; + imageInfo.format = VK_FORMAT_R8G8B8A8_SRGB; + imageInfo.extent = + { + .width = static_cast(screen_width / 2), + .height = static_cast(screen_height), + .depth = 1, + }, + imageInfo.mipLevels = 1; + imageInfo.arrayLayers = 1; + imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; + imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; + imageInfo.usage = + VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; VkImage image; cardboard::rendering::vkCreateImage(logical_device_, &imageInfo, nullptr, @@ -414,12 +416,11 @@ class VulkanRenderer : public Renderer { cardboard::rendering::vkGetImageMemoryRequirements(logical_device_, image, &memRequirements); - VkMemoryAllocateInfo allocInfo{ - .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, - .allocationSize = memRequirements.size, - .memoryTypeIndex = FindMemoryType(memRequirements.memoryTypeBits, - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), - }; + VkMemoryAllocateInfo allocInfo{}; + allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + allocInfo.allocationSize = memRequirements.size; + allocInfo.memoryTypeIndex = FindMemoryType(memRequirements.memoryTypeBits, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); VkDeviceMemory texture_image_memory; cardboard::rendering::vkAllocateMemory(logical_device_, &allocInfo, nullptr, @@ -505,6 +506,7 @@ class VulkanRenderer : public Renderer { VkFramebufferCreateInfo fb_create_info{ .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, .pNext = nullptr, + .flags = 0, .renderPass = render_pass_, .attachmentCount = 1, .pAttachments = attachments, @@ -584,11 +586,15 @@ class VulkanRenderer : public Renderer { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; const VkSubmitInfo submit_info = { .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, + .pNext = nullptr, .waitSemaphoreCount = 0, .pWaitSemaphores = wait_semaphores, .pWaitDstStageMask = wait_stages, .commandBufferCount = 1, - .pCommandBuffers = &command_buffers_[image_index]}; + .pCommandBuffers = &command_buffers_[image_index], + .signalSemaphoreCount = 0, + .pSignalSemaphores = nullptr, + }; UnityVulkanInstance vulkanInstance = vulkan_interface_->Instance(); @@ -702,22 +708,21 @@ class VulkanRenderer : public Renderer { VkImageLayout new_layout) { VkCommandBuffer command_buffer = BeginSingleTimeCommands(); - VkImageMemoryBarrier barrier{ - .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, - .oldLayout = old_layout, - .newLayout = new_layout, - .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, - .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, - .image = image, - .subresourceRange = - { - .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, - .baseMipLevel = 0, - .levelCount = 1, - .baseArrayLayer = 0, - .layerCount = 1, - }, - }; + VkImageMemoryBarrier barrier{}; + barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barrier.oldLayout = old_layout; + barrier.newLayout = new_layout; + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.image = image; + barrier.subresourceRange = + { + .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .baseMipLevel = 0, + .levelCount = 1, + .baseArrayLayer = 0, + .layerCount = 1, + }; VkPipelineStageFlags source_stage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; VkPipelineStageFlags destination_stage = @@ -739,6 +744,7 @@ class VulkanRenderer : public Renderer { VkCommandBuffer BeginSingleTimeCommands() { VkCommandBufferAllocateInfo alloc_info{ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, + .pNext = nullptr, .commandPool = command_pool_, .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY, .commandBufferCount = 1, @@ -748,10 +754,9 @@ class VulkanRenderer : public Renderer { cardboard::rendering::vkAllocateCommandBuffers(logical_device_, &alloc_info, &command_buffer); - VkCommandBufferBeginInfo begin_info{ - .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, - .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, - }; + VkCommandBufferBeginInfo begin_info {}; + begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; cardboard::rendering::vkBeginCommandBuffer(command_buffer, &begin_info); @@ -767,11 +772,10 @@ class VulkanRenderer : public Renderer { void EndSingleTimeCommands(VkCommandBuffer command_buffer) { cardboard::rendering::vkEndCommandBuffer(command_buffer); - VkSubmitInfo submit_info{ - .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, - .commandBufferCount = 1, - .pCommandBuffers = &command_buffer, - }; + VkSubmitInfo submit_info{}; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.commandBufferCount = 1; + submit_info.pCommandBuffers = &command_buffer; UnityVulkanInstance vulkan_instance = vulkan_interface_->Instance(); diff --git a/sdk/unity/xr_unity_plugin/vulkan/vulkan_widgets_renderer.cc b/sdk/unity/xr_unity_plugin/vulkan/vulkan_widgets_renderer.cc index 60510cd0..3a5d2b4f 100644 --- a/sdk/unity/xr_unity_plugin/vulkan/vulkan_widgets_renderer.cc +++ b/sdk/unity/xr_unity_plugin/vulkan/vulkan_widgets_renderer.cc @@ -22,6 +22,7 @@ #include "rendering/android/vulkan/android_vulkan_loader.h" #include "util/logging.h" #include "unity/xr_unity_plugin/renderer.h" +#include #include "unity/xr_unity_plugin/vulkan/shaders/widget_frag.spv.h" #include "unity/xr_unity_plugin/vulkan/shaders/widget_vert.spv.h" @@ -128,10 +129,11 @@ void VulkanWidgetsRenderer::CreateBuffer(VkDeviceSize size, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& buffer_memory) { - VkBufferCreateInfo buffer_info{.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, - .size = size, - .usage = usage, - .sharingMode = VK_SHARING_MODE_EXCLUSIVE}; + VkBufferCreateInfo buffer_info{}; + buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info.size = size; + buffer_info.usage = usage; + buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; CALL_VK(rendering::vkCreateBuffer(logical_device_, &buffer_info, nullptr, &buffer)); @@ -142,6 +144,7 @@ void VulkanWidgetsRenderer::CreateBuffer(VkDeviceSize size, VkMemoryAllocateInfo alloc_info{ .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .pNext = nullptr, .allocationSize = mem_requirements.size, .memoryTypeIndex = FindMemoryType(mem_requirements.memoryTypeBits, properties)}; @@ -165,23 +168,23 @@ void VulkanWidgetsRenderer::CreateSharedVulkanObjects() { }; bindings[0] = sampler_layout_binding; - VkDescriptorSetLayoutCreateInfo layout_info = { - .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, - .bindingCount = 1, - .pBindings = bindings, - }; + VkDescriptorSetLayoutCreateInfo layout_info {}; + layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + layout_info.bindingCount = 1; + layout_info.pBindings = bindings; + CALL_VK(rendering::vkCreateDescriptorSetLayout( logical_device_, &layout_info, nullptr, &descriptor_set_layout_)); // Create Pipeline Layout - VkPipelineLayoutCreateInfo pipeline_layout_create_info{ - .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, - .pNext = nullptr, - .setLayoutCount = 1, - .pSetLayouts = &descriptor_set_layout_, - .pushConstantRangeCount = 0, - .pPushConstantRanges = nullptr, - }; + VkPipelineLayoutCreateInfo pipeline_layout_create_info{}; + pipeline_layout_create_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_create_info.pNext = nullptr; + pipeline_layout_create_info.setLayoutCount = 1; + pipeline_layout_create_info.pSetLayouts = &descriptor_set_layout_; + pipeline_layout_create_info.pushConstantRangeCount = 0; + pipeline_layout_create_info.pPushConstantRanges = nullptr; CALL_VK(rendering::vkCreatePipelineLayout(logical_device_, &pipeline_layout_create_info, nullptr, &pipeline_layout_)); @@ -190,23 +193,22 @@ void VulkanWidgetsRenderer::CreateSharedVulkanObjects() { VkPhysicalDeviceProperties properties{}; rendering::vkGetPhysicalDeviceProperties(physical_device_, &properties); - VkSamplerCreateInfo sampler = { - .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, - .pNext = nullptr, - .magFilter = VK_FILTER_NEAREST, - .minFilter = VK_FILTER_NEAREST, - .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST, - .addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT, - .addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT, - .addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT, - .mipLodBias = 0.0f, - .maxAnisotropy = properties.limits.maxSamplerAnisotropy, - .compareOp = VK_COMPARE_OP_NEVER, - .minLod = 0.0f, - .maxLod = 0.0f, - .borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE, - .unnormalizedCoordinates = VK_FALSE, - }; + VkSamplerCreateInfo sampler {}; + sampler.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sampler.pNext = nullptr; + sampler.magFilter = VK_FILTER_NEAREST; + sampler.minFilter = VK_FILTER_NEAREST; + sampler.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; + sampler.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + sampler.mipLodBias = 0.0f; + sampler.maxAnisotropy = properties.limits.maxSamplerAnisotropy; + sampler.compareOp = VK_COMPARE_OP_NEVER; + sampler.minLod = 0.0f; + sampler.maxLod = 0.0f; + sampler.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; + sampler.unnormalizedCoordinates = VK_FALSE; CALL_VK(rendering::vkCreateSampler(logical_device_, &sampler, nullptr, &texture_sampler_)); @@ -300,27 +302,26 @@ void VulkanWidgetsRenderer::CreateGraphicsPipeline() { }; // Specify viewport info - VkPipelineViewportStateCreateInfo viewport_info{ - .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, - .pNext = nullptr, - .viewportCount = 1, - .pViewports = nullptr, - .scissorCount = 1, - .pScissors = nullptr, - }; + VkPipelineViewportStateCreateInfo viewport_info{}; + viewport_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; + viewport_info.pNext = nullptr; + viewport_info.viewportCount = 1; + viewport_info.pViewports = nullptr; + viewport_info.scissorCount = 1; + viewport_info.pScissors = nullptr; // Specify multisample info VkSampleMask sample_mask = ~0u; - VkPipelineMultisampleStateCreateInfo multisample_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, - .pNext = nullptr, - .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT, - .sampleShadingEnable = VK_FALSE, - .minSampleShading = 0, - .pSampleMask = &sample_mask, - .alphaToCoverageEnable = VK_FALSE, - .alphaToOneEnable = VK_FALSE, - }; + VkPipelineMultisampleStateCreateInfo multisample_info {}; + multisample_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; + multisample_info.pNext = nullptr; + multisample_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + multisample_info.sampleShadingEnable = VK_FALSE; + multisample_info.minSampleShading = 0; + multisample_info.pSampleMask = &sample_mask; + multisample_info.alphaToCoverageEnable = VK_FALSE; + multisample_info.alphaToOneEnable = VK_FALSE; // Specify color blend state VkPipelineColorBlendAttachmentState attachment_states = { @@ -336,36 +337,36 @@ void VulkanWidgetsRenderer::CreateGraphicsPipeline() { VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, }; - VkPipelineColorBlendStateCreateInfo color_blend_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, - .pNext = nullptr, - .flags = 0, - .logicOpEnable = VK_FALSE, - .logicOp = VK_LOGIC_OP_COPY, - .attachmentCount = 1, - .pAttachments = &attachment_states, - }; + VkPipelineColorBlendStateCreateInfo color_blend_info {}; + color_blend_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; + color_blend_info.pNext = nullptr; + color_blend_info.flags = 0; + color_blend_info.logicOpEnable = VK_FALSE; + color_blend_info.logicOp = VK_LOGIC_OP_COPY; + color_blend_info.attachmentCount = 1; + color_blend_info.pAttachments = &attachment_states; // Specify rasterizer info - VkPipelineRasterizationStateCreateInfo raster_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, - .pNext = nullptr, - .depthClampEnable = VK_FALSE, - .rasterizerDiscardEnable = VK_FALSE, - .polygonMode = VK_POLYGON_MODE_FILL, - .cullMode = VK_CULL_MODE_NONE, - .frontFace = VK_FRONT_FACE_CLOCKWISE, - .depthBiasEnable = VK_FALSE, - .lineWidth = 1, - }; + VkPipelineRasterizationStateCreateInfo raster_info {}; + raster_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; + raster_info.pNext = nullptr; + raster_info.depthClampEnable = VK_FALSE; + raster_info.rasterizerDiscardEnable = VK_FALSE; + raster_info.polygonMode = VK_POLYGON_MODE_FILL; + raster_info.cullMode = VK_CULL_MODE_NONE; + raster_info.frontFace = VK_FRONT_FACE_CLOCKWISE; + raster_info.depthBiasEnable = VK_FALSE; + raster_info.lineWidth = 1; // Specify input assembler state - VkPipelineInputAssemblyStateCreateInfo input_assembly_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, - .pNext = nullptr, - .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, - .primitiveRestartEnable = VK_FALSE, - }; + VkPipelineInputAssemblyStateCreateInfo input_assembly_info {}; + input_assembly_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; + input_assembly_info.pNext = nullptr; + input_assembly_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; + input_assembly_info.primitiveRestartEnable = VK_FALSE; // Specify vertex input state VkVertexInputBindingDescription vertex_input_bindings = { @@ -388,33 +389,35 @@ void VulkanWidgetsRenderer::CreateGraphicsPipeline() { .offset = sizeof(float) * 2, }}; - VkPipelineVertexInputStateCreateInfo vertex_input_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, - .pNext = nullptr, - .vertexBindingDescriptionCount = 1, - .pVertexBindingDescriptions = &vertex_input_bindings, - .vertexAttributeDescriptionCount = 2, - .pVertexAttributeDescriptions = vertex_input_attributes, - }; + VkPipelineVertexInputStateCreateInfo vertex_input_info {}; + vertex_input_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_info.pNext = nullptr; + vertex_input_info.vertexBindingDescriptionCount = 1; + vertex_input_info.pVertexBindingDescriptions = &vertex_input_bindings; + vertex_input_info.vertexAttributeDescriptionCount = 2; + vertex_input_info.pVertexAttributeDescriptions = vertex_input_attributes; VkDynamicState dynamic_state_enables[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, }; - VkPipelineDynamicStateCreateInfo dynamic_state_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, - .pNext = nullptr, - .dynamicStateCount = 2, - .pDynamicStates = dynamic_state_enables}; - - VkPipelineDepthStencilStateCreateInfo depth_stencil = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, - .depthTestEnable = VK_TRUE, - .depthWriteEnable = VK_TRUE, - .depthCompareOp = VK_COMPARE_OP_LESS, - .depthBoundsTestEnable = VK_FALSE, - .stencilTestEnable = VK_FALSE}; + VkPipelineDynamicStateCreateInfo dynamic_state_info{}; + dynamic_state_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_info.pNext = nullptr; + dynamic_state_info.dynamicStateCount = 2; + dynamic_state_info.pDynamicStates = dynamic_state_enables; + + VkPipelineDepthStencilStateCreateInfo depth_stencil {}; + depth_stencil.sType = + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; + depth_stencil.depthTestEnable = VK_TRUE; + depth_stencil.depthWriteEnable = VK_TRUE; + depth_stencil.depthCompareOp = VK_COMPARE_OP_LESS; + depth_stencil.depthBoundsTestEnable = VK_FALSE; + depth_stencil.stencilTestEnable = VK_FALSE; // Create the pipeline VkPipelineShaderStageCreateInfo shader_stages[2] = {vertex_shader_state, @@ -605,14 +608,13 @@ void VulkanWidgetsRenderer::RenderWidget( .maxDepth = 1.0}; VkRect2D scissor = { + .offset = {.x = screen_params.viewport_x, + .y = screen_params.viewport_y}, .extent = {.width = static_cast(screen_params.viewport_width), .height = static_cast(screen_params.viewport_height)}, }; - scissor.offset = {.x = screen_params.viewport_x, - .y = screen_params.viewport_y}; - // Bind to the command buffer. rendering::vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphics_pipeline_); diff --git a/third_party/unity_plugin_api/update_unity_headers.md b/third_party/unity_plugin_api/update_unity_headers.md index 399c94f7..a651cc38 100644 --- a/third_party/unity_plugin_api/update_unity_headers.md +++ b/third_party/unity_plugin_api/update_unity_headers.md @@ -8,16 +8,15 @@ The plugin API folder has a mix of headers from different Unity versions. Each i If there is not a version present then the version is `2020.3.25f1`. +## Update Unity XR headers -## Update IUnityXR* headers - -Coordinate with the [XR APIs team](https://g3doc.corp.google.com/company/teams/android-xr/openxr/index.md?cl=head#contact). +Coordinate with the [XR APIs team](go/xrapis#contact). ## Update non-XR headers Follow these steps to update the Unity Plugin API in a gmac: -1. Download last Unity version. +1. Download the latest Unity version. 1. Open a terminal and run: ```sh