Optimize fixed-function Vulkan shaders for Adreno 512 and recover Android surfaces

This commit is contained in:
shen
2026-09-30 21:48:07 -07:00
parent 1e4762ccf4
commit 922954dd97
17 changed files with 238 additions and 32 deletions
+9 -7
View File
@@ -84,7 +84,9 @@ void VulkanWindow::create_descriptors_and_buffers() {
bone_bindings[0].descriptorCount = 1;
bone_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
bone_bindings[1].binding = 1;
bone_bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
// Draw state is constant across a draw. Uniform memory lets mobile GPUs broadcast
// these values instead of fetching them as general storage data for each fragment.
bone_bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
bone_bindings[1].descriptorCount = 1;
bone_bindings[1].stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
VkDescriptorSetLayoutCreateInfo bone_layout_info{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO};
@@ -95,7 +97,7 @@ void VulkanWindow::create_descriptors_and_buffers() {
VkDescriptorPoolSize pool_sizes[3] = {
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 16384},
{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 4 * kMaxFramesInFlight},
{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 4 * kMaxFramesInFlight}};
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 4 * kMaxFramesInFlight}};
VkDescriptorPoolCreateInfo pool_info{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
pool_info.maxSets = 8192;
@@ -111,7 +113,7 @@ void VulkanWindow::create_descriptors_and_buffers() {
VkPhysicalDeviceProperties properties{};
vkGetPhysicalDeviceProperties(physical_, &properties);
const auto alignment = std::max<VkDeviceSize>(
1, properties.limits.minStorageBufferOffsetAlignment);
1, properties.limits.minUniformBufferOffsetAlignment);
state_stride_ = ((sizeof(FixedFunctionState) + alignment - 1) / alignment) * alignment;
staging_alignment_ = std::max<VkDeviceSize>(16, properties.limits.optimalBufferCopyOffsetAlignment);
@@ -124,7 +126,7 @@ void VulkanWindow::create_descriptors_and_buffers() {
slot.state_capacity = 256;
void* state_raw = nullptr;
create_host_buffer(slot.state_capacity * state_stride_, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
create_host_buffer(slot.state_capacity * state_stride_, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
slot.state_buffer, slot.state_memory, &state_raw);
slot.state_mapped = static_cast<std::uint8_t*>(state_raw);
@@ -144,7 +146,7 @@ void VulkanWindow::create_descriptors_and_buffers() {
writes[binding].dstBinding = static_cast<std::uint32_t>(binding);
writes[binding].descriptorCount = 1;
writes[binding].descriptorType = binding == 0
? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER : VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
writes[binding].pBufferInfo = &buffer_infos[binding];
}
vkUpdateDescriptorSets(device_, 2, writes, 0, nullptr);
@@ -224,7 +226,7 @@ void VulkanWindow::ensure_state_capacity(std::size_t required) {
VkBuffer buffer = VK_NULL_HANDLE;
VkDeviceMemory memory = VK_NULL_HANDLE;
void* mapped = nullptr;
create_host_buffer(next * state_stride_, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
create_host_buffer(next * state_stride_, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
buffer, memory, &mapped);
vkUnmapMemory(device_, f_->state_memory);
vkDestroyBuffer(device_, f_->state_buffer, nullptr);
@@ -238,7 +240,7 @@ void VulkanWindow::ensure_state_capacity(std::size_t required) {
write.dstSet = f_->bone_descriptor_set;
write.dstBinding = 1;
write.descriptorCount = 1;
write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
write.pBufferInfo = &info;
vkUpdateDescriptorSets(device_, 1, &write, 0, nullptr);
}