Skip to content

Minor refactor for vulkan renderer#176

Draft
xiaowei-guan wants to merge 3 commits into
flutter-tizen:masterfrom
xiaowei-guan:vulkan_refactor
Draft

Minor refactor for vulkan renderer#176
xiaowei-guan wants to merge 3 commits into
flutter-tizen:masterfrom
xiaowei-guan:vulkan_refactor

Conversation

@xiaowei-guan

@xiaowei-guan xiaowei-guan commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Main changes:

  1. Move FindMemoryType method to vulkan renderer.
  2. Make GetDevice method to const.
  3. Cast to VkDeviceSize before multiplication.

@xiaowei-guan xiaowei-guan marked this pull request as draft June 9, 2026 06:14

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors Vulkan memory type retrieval by moving FindMemoryType from individual texture classes to TizenRendererVulkan, adds a null check for pixel_buffer->buffer, and introduces error handling for vkMapMemory. Review feedback suggests refactoring CopyBufferToImage to propagate mapping failures and checking for null command buffers to prevent crashes. Additionally, it is recommended to ensure subclasses of ExternalTextureSurfaceVulkanBuffer can still access FindMemoryType, and to use pointers instead of references for output parameters in FindMemoryType to align with the Google C++ Style Guide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +185 to +190
VkResult result =
vkMapMemory(GetDevice(), staging_buffer_memory_, 0, size, 0, &data);
if (result != VK_SUCCESS) {
FT_LOG(Error) << "Failed to map staging buffer memory";
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are two correctness and stability issues in this error handling path:

  1. Lack of Error Propagation: CopyBufferToImage returns void. If vkMapMemory fails, it returns early, but the caller PopulateVulkanTexture is unaware of the failure and will proceed to return true with an uninitialized or outdated texture. Consider refactoring CopyBufferToImage to return a bool and checking its return value in PopulateVulkanTexture to handle the failure gracefully.
  2. Unchecked Command Buffer: Although not shown in this specific diff hunk, vulkan_renderer_->BeginSingleTimeCommands() (called on line 193) can return VK_NULL_HANDLE on failure. If it does, calling vkCmdCopyBufferToImage and EndSingleTimeCommands with a null command buffer will result in undefined behavior or a crash. Please add a check to ensure command_buffer is not VK_NULL_HANDLE before proceeding.

bool FindMemoryType(uint32_t memory_type_bits_requirement,
VkMemoryPropertyFlags required_properties,
uint32_t& index_out);
VkDevice GetDevice() const;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Since ExternalTextureSurfaceVulkanBuffer is an abstract base class with pure virtual methods like AllocateAndBindMemory (which subclasses must implement), those subclasses will likely need to call FindMemoryType to allocate Vulkan memory.

However, FindMemoryType has been removed from this class, and vulkan_renderer_ is private. This means subclasses cannot access vulkan_renderer_->FindMemoryType directly.

To resolve this without duplicating the vulkan_renderer_ pointer in subclasses (which would violate the 'Avoid duplicating state' principle), consider making vulkan_renderer_ protected, providing a protected getter, or keeping a protected FindMemoryType helper that forwards the call to vulkan_renderer_.

References
  1. Avoid duplicating state: Keep only one source of truth. (link)

Comment on lines +54 to +56
bool FindMemoryType(uint32_t type_filter,
VkMemoryPropertyFlags properties,
uint32_t& index_out);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the Google C++ Style Guide, output parameters should be passed as pointers rather than references (e.g., uint32_t* index_out instead of uint32_t& index_out). This makes it clear at the call site that the argument may be modified.

Suggested change
bool FindMemoryType(uint32_t type_filter,
VkMemoryPropertyFlags properties,
uint32_t& index_out);
bool FindMemoryType(uint32_t type_filter,
VkMemoryPropertyFlags properties,
uint32_t* index_out);
References
  1. Google C++ Style Guide: Prefer using return values instead of output parameters. If you must use output parameters, they should be pointers, not references. (link)

Comment on lines +1025 to +1040
bool TizenRendererVulkan::FindMemoryType(uint32_t type_filter,
VkMemoryPropertyFlags properties,
uint32_t& index_out) {
VkPhysicalDeviceMemoryProperties memory_properties;
vkGetPhysicalDeviceMemoryProperties(physical_device_, &memory_properties);

for (uint32_t i = 0; i < memory_properties.memoryTypeCount; i++) {
if ((type_filter & (1 << i)) &&
(memory_properties.memoryTypes[i].propertyFlags & properties) ==
properties) {
index_out = i;
return true;
}
}
return false;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the implementation of FindMemoryType to accept a pointer for the output parameter index_out instead of a reference, adhering to the Google C++ Style Guide.

bool TizenRendererVulkan::FindMemoryType(uint32_t type_filter,
                                         VkMemoryPropertyFlags properties,
                                         uint32_t* index_out) {
  VkPhysicalDeviceMemoryProperties memory_properties;
  vkGetPhysicalDeviceMemoryProperties(physical_device_, &memory_properties);

  for (uint32_t i = 0; i < memory_properties.memoryTypeCount; i++) {
    if ((type_filter & (1 << i)) &&
        (memory_properties.memoryTypes[i].propertyFlags & properties) ==
            properties) {
      if (index_out) {
        *index_out = i;
      }
      return true;
    }
  }
  return false;
}
References
  1. Google C++ Style Guide: Prefer using return values instead of output parameters. If you must use output parameters, they should be pointers, not references. (link)

Comment on lines +230 to +231
if (!vulkan_renderer_->FindMemoryType(memory_requirements.memoryTypeBits,
properties, memory_type_index)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the call to FindMemoryType to pass the address of memory_type_index as a pointer, matching the updated signature.

Suggested change
if (!vulkan_renderer_->FindMemoryType(memory_requirements.memoryTypeBits,
properties, memory_type_index)) {
if (!vulkan_renderer_->FindMemoryType(memory_requirements.memoryTypeBits,
properties, &memory_type_index)) {
References
  1. Google C++ Style Guide: Prefer using return values instead of output parameters. If you must use output parameters, they should be pointers, not references. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant