|
|
|
@ -220,6 +220,8 @@ static void unmap_object(uint64_t obj)
|
|
|
|
|
#define CHAR_CELSIUS "\xe2\x84\x83"
|
|
|
|
|
#define CHAR_FAHRENHEIT "\xe2\x84\x89"
|
|
|
|
|
|
|
|
|
|
static void shutdown_swapchain_font(struct swapchain_data*);
|
|
|
|
|
|
|
|
|
|
static VkLayerInstanceCreateInfo *get_instance_chain_info(const VkInstanceCreateInfo *pCreateInfo,
|
|
|
|
|
VkLayerFunction func)
|
|
|
|
|
{
|
|
|
|
@ -835,13 +837,14 @@ static void upload_image_data(struct device_data *device_data,
|
|
|
|
|
1, use_barrier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static VkDescriptorSet create_image_with_desc(struct swapchain_data *data,
|
|
|
|
|
uint32_t width,
|
|
|
|
|
uint32_t height,
|
|
|
|
|
VkFormat format,
|
|
|
|
|
VkImage& image,
|
|
|
|
|
VkDeviceMemory& image_mem,
|
|
|
|
|
VkImageView& image_view)
|
|
|
|
|
static void create_image(struct swapchain_data *data,
|
|
|
|
|
VkDescriptorSet descriptor_set,
|
|
|
|
|
uint32_t width,
|
|
|
|
|
uint32_t height,
|
|
|
|
|
VkFormat format,
|
|
|
|
|
VkImage& image,
|
|
|
|
|
VkDeviceMemory& image_mem,
|
|
|
|
|
VkImageView& image_view)
|
|
|
|
|
{
|
|
|
|
|
struct device_data *device_data = data->device;
|
|
|
|
|
|
|
|
|
@ -888,9 +891,22 @@ static VkDescriptorSet create_image_with_desc(struct swapchain_data *data,
|
|
|
|
|
VK_CHECK(device_data->vtable.CreateImageView(device_data->device, &view_info,
|
|
|
|
|
NULL, &image_view));
|
|
|
|
|
|
|
|
|
|
VkDescriptorSet descriptor_set;
|
|
|
|
|
update_image_descriptor(data, image_view, descriptor_set);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkDescriptorSetAllocateInfo alloc_info = {};
|
|
|
|
|
static VkDescriptorSet create_image_with_desc(struct swapchain_data *data,
|
|
|
|
|
uint32_t width,
|
|
|
|
|
uint32_t height,
|
|
|
|
|
VkFormat format,
|
|
|
|
|
VkImage& image,
|
|
|
|
|
VkDeviceMemory& image_mem,
|
|
|
|
|
VkImageView& image_view)
|
|
|
|
|
{
|
|
|
|
|
struct device_data *device_data = data->device;
|
|
|
|
|
|
|
|
|
|
VkDescriptorSet descriptor_set {};
|
|
|
|
|
|
|
|
|
|
VkDescriptorSetAllocateInfo alloc_info {};
|
|
|
|
|
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
|
|
|
|
alloc_info.descriptorPool = data->descriptor_pool;
|
|
|
|
|
alloc_info.descriptorSetCount = 1;
|
|
|
|
@ -899,14 +915,54 @@ static VkDescriptorSet create_image_with_desc(struct swapchain_data *data,
|
|
|
|
|
&alloc_info,
|
|
|
|
|
&descriptor_set));
|
|
|
|
|
|
|
|
|
|
update_image_descriptor(data, image_view, descriptor_set);
|
|
|
|
|
create_image(data, descriptor_set, width, height, format, image, image_mem, image_view);
|
|
|
|
|
return descriptor_set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void check_fonts(struct swapchain_data* data)
|
|
|
|
|
{
|
|
|
|
|
struct device_data *device_data = data->device;
|
|
|
|
|
struct instance_data *instance_data = device_data->instance;
|
|
|
|
|
auto& params = instance_data->params;
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
|
|
|
|
if (params.font_params_hash != data->sw_stats.font_params_hash)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "MANGOHUD: recreating font image\n";
|
|
|
|
|
VkDescriptorSet desc_set = (VkDescriptorSet)io.Fonts->TexID;
|
|
|
|
|
create_fonts(instance_data->params, data->sw_stats.font1, data->sw_stats.font_text);
|
|
|
|
|
unsigned char* pixels;
|
|
|
|
|
int width, height;
|
|
|
|
|
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);
|
|
|
|
|
|
|
|
|
|
// wait for rendering to complete, if any
|
|
|
|
|
device_data->vtable.DeviceWaitIdle(device_data->device);
|
|
|
|
|
shutdown_swapchain_font(data);
|
|
|
|
|
|
|
|
|
|
if (desc_set)
|
|
|
|
|
create_image(data, desc_set, width, height, VK_FORMAT_R8_UNORM, data->font_image, data->font_mem, data->font_image_view);
|
|
|
|
|
else
|
|
|
|
|
desc_set = create_image_with_desc(data, width, height, VK_FORMAT_R8_UNORM, data->font_image, data->font_mem, data->font_image_view);
|
|
|
|
|
|
|
|
|
|
io.Fonts->TexID = (ImTextureID) desc_set;
|
|
|
|
|
|
|
|
|
|
data->font_uploaded = false;
|
|
|
|
|
data->sw_stats.font_params_hash = params.font_params_hash;
|
|
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
std::cerr << "MANGOHUD: Default font tex size: " << width << "x" << height << "px (" << (width*height*1) << " bytes)" << "\n";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ensure_swapchain_fonts(struct swapchain_data *data,
|
|
|
|
|
VkCommandBuffer command_buffer)
|
|
|
|
|
{
|
|
|
|
|
struct device_data *device_data = data->device;
|
|
|
|
|
|
|
|
|
|
check_fonts(data);
|
|
|
|
|
|
|
|
|
|
if (data->font_uploaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
@ -1411,18 +1467,7 @@ static void setup_swapchain_data_pipeline(struct swapchain_data *data)
|
|
|
|
|
device_data->vtable.DestroyShaderModule(device_data->device, vert_module, NULL);
|
|
|
|
|
device_data->vtable.DestroyShaderModule(device_data->device, frag_module, NULL);
|
|
|
|
|
|
|
|
|
|
create_fonts(device_data->instance->params, data->sw_stats.font1, data->sw_stats.font_text);
|
|
|
|
|
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
unsigned char* pixels;
|
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
|
|
// upload default font to VkImage
|
|
|
|
|
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);
|
|
|
|
|
io.Fonts->TexID = (ImTextureID)create_image_with_desc(data, width, height, VK_FORMAT_R8_UNORM, data->font_image, data->font_mem, data->font_image_view);
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
std::cerr << "MANGOHUD: Default font tex size: " << width << "x" << height << "px (" << (width*height*1) << " bytes)" << "\n";
|
|
|
|
|
#endif
|
|
|
|
|
check_fonts(data);
|
|
|
|
|
|
|
|
|
|
// if (data->descriptor_set)
|
|
|
|
|
// update_image_descriptor(data, data->font_image_view[0], data->descriptor_set);
|
|
|
|
@ -1593,6 +1638,18 @@ static void setup_swapchain_data(struct swapchain_data *data,
|
|
|
|
|
NULL, &data->command_pool));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void shutdown_swapchain_font(struct swapchain_data *data)
|
|
|
|
|
{
|
|
|
|
|
struct device_data *device_data = data->device;
|
|
|
|
|
|
|
|
|
|
device_data->vtable.DestroyImageView(device_data->device, data->font_image_view, NULL);
|
|
|
|
|
device_data->vtable.DestroyImage(device_data->device, data->font_image, NULL);
|
|
|
|
|
device_data->vtable.FreeMemory(device_data->device, data->font_mem, NULL);
|
|
|
|
|
|
|
|
|
|
device_data->vtable.DestroyBuffer(device_data->device, data->upload_font_buffer, NULL);
|
|
|
|
|
device_data->vtable.FreeMemory(device_data->device, data->upload_font_buffer_mem, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void shutdown_swapchain_data(struct swapchain_data *data)
|
|
|
|
|
{
|
|
|
|
|
struct device_data *device_data = data->device;
|
|
|
|
@ -1626,12 +1683,7 @@ static void shutdown_swapchain_data(struct swapchain_data *data)
|
|
|
|
|
data->descriptor_layout, NULL);
|
|
|
|
|
|
|
|
|
|
device_data->vtable.DestroySampler(device_data->device, data->font_sampler, NULL);
|
|
|
|
|
device_data->vtable.DestroyImageView(device_data->device, data->font_image_view, NULL);
|
|
|
|
|
device_data->vtable.DestroyImage(device_data->device, data->font_image, NULL);
|
|
|
|
|
device_data->vtable.FreeMemory(device_data->device, data->font_mem, NULL);
|
|
|
|
|
|
|
|
|
|
device_data->vtable.DestroyBuffer(device_data->device, data->upload_font_buffer, NULL);
|
|
|
|
|
device_data->vtable.FreeMemory(device_data->device, data->upload_font_buffer_mem, NULL);
|
|
|
|
|
shutdown_swapchain_font(data);
|
|
|
|
|
|
|
|
|
|
ImGui::DestroyContext(data->imgui_context);
|
|
|
|
|
}
|
|
|
|
|