Skip to content

Commit

Permalink
Fix Vulkan GGUI on CPU rendering (swiftshaders)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcao3 committed Oct 22, 2021
1 parent 5099565 commit 4805fcd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 2 additions & 2 deletions taichi/backends/vulkan/codegen_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,8 +1408,8 @@ class KernelCodegen {

std::ofstream fout((params_.ti_kernel_name).c_str(),
std::ios::binary | std::ios::out);
fout.write(reinterpret_cast<const char *>(task_res.spirv_code.data()),
task_res.spirv_code.size() * sizeof(uint32_t));
fout.write(reinterpret_cast<const char *>(optimized_spv.data()),
optimized_spv.size() * sizeof(uint32_t));
fout.close();
#endif

Expand Down
18 changes: 12 additions & 6 deletions taichi/backends/vulkan/vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,8 +1144,11 @@ DeviceAllocation VulkanDevice::allocate_memory(const AllocParams &params) {
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
#endif

bool export_sharing = params.export_sharing &&
this->get_cap(DeviceCapability::vk_has_external_memory);

VmaAllocationCreateInfo alloc_info{};
if (params.export_sharing) {
if (export_sharing) {
buffer_info.pNext = &external_mem_buffer_create_info;
}
#ifdef __APPLE__
Expand Down Expand Up @@ -1173,8 +1176,8 @@ DeviceAllocation VulkanDevice::allocate_memory(const AllocParams &params) {
}

alloc.buffer = vkapi::create_buffer(
device_, params.export_sharing ? allocator_export_ : allocator_,
&buffer_info, &alloc_info);
device_, export_sharing ? allocator_export_ : allocator_, &buffer_info,
&alloc_info);
vmaGetAllocationInfo(alloc.buffer->allocator, alloc.buffer->allocation,
&alloc.alloc_info);

Expand Down Expand Up @@ -1482,8 +1485,11 @@ DeviceAllocation VulkanDevice::create_image(const ImageParams &params) {

alloc.format = image_info.format;

bool export_sharing = params.export_sharing &&
this->get_cap(DeviceCapability::vk_has_external_memory);

VkExternalMemoryImageCreateInfo external_mem_image_create_info = {};
if (params.export_sharing) {
if (export_sharing) {
external_mem_image_create_info.sType =
VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO;
external_mem_image_create_info.pNext = NULL;
Expand All @@ -1504,8 +1510,8 @@ DeviceAllocation VulkanDevice::create_image(const ImageParams &params) {
alloc_info.usage = VMA_MEMORY_USAGE_GPU_ONLY;

alloc.image = vkapi::create_image(
device_, params.export_sharing ? allocator_export_ : allocator_,
&image_info, &alloc_info);
device_, export_sharing ? allocator_export_ : allocator_, &image_info,
&alloc_info);
vmaGetAllocationInfo(alloc.image->allocator, alloc.image->allocation,
&alloc.alloc_info);

Expand Down
14 changes: 14 additions & 0 deletions taichi/program/opaque_handles.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include "taichi/lang_util.h"
#include "taichi/backends/device.h"

namespace taichi {
namespace lang {

class OpaqueObjects {
public:

};

}
} // namespace taichi

0 comments on commit 4805fcd

Please sign in to comment.