<commit_before>// Most of this is just standard vulkano setup
// Check the code following the UNIQUE CODE comments

#[macro_use]
extern crate vulkano;
extern crate winit;
extern crate vulkano_win;
extern crate vulkano_text;

use vulkano_text::{DrawText, DrawTextTrait, UpdateTextCache};

use vulkano_win::VkSurfaceBuild;
use vulkano::command_buffer;
use vulkano::command_buffer::PrimaryCommandBufferBuilder;
use vulkano::command_buffer::Submission;
use vulkano::device::Device;
use vulkano::framebuffer::Framebuffer;
use vulkano::instance::Instance;
use vulkano::swapchain::SurfaceTransform;
use vulkano::swapchain::Swapchain;

use std::sync::Arc;
use std::time::Duration;

mod render_pass {
    use vulkano::format::Format;

    single_pass_renderpass!{
        attachments: {
            color: {
                load: Clear,
                store: Store,
                format: Format,
            }
        },
        pass: {
            color: [color],
            depth_stencil: {}
        }
    }
}

fn main() {
    let instance = {
        let extensions = vulkano_win::required_extensions();
        Instance::new(None, &extensions, None).expect("failed to create Vulkan instance")
    };
    let physical = vulkano::instance::PhysicalDevice::enumerate(&instance).next().expect("no device available");
    let window = winit::WindowBuilder::new().build_vk_surface(&instance).unwrap();
    let queue = physical.queue_families().find(|q| {
        q.supports_graphics() && window.surface().is_supported(q).unwrap_or(false)
    }).expect("couldn't find a graphical queue family");

    let (device, mut queues) = {
        let device_ext = vulkano::device::DeviceExtensions {
            khr_swapchain: true,
            .. vulkano::device::DeviceExtensions::none()
        };

        Device::new(&physical, physical.supported_features(), &device_ext,
                    [(queue, 0.5)].iter().cloned()).expect("failed to create device")
    };

    let queue = queues.next().unwrap();
    let (swapchain, images) = {
        let caps = window.surface().get_capabilities(&physical)
                         .expect("failed to get surface capabilities");
        let dimensions = caps.current_extent.unwrap_or([1280, 1024]);
        let present = caps.present_modes.iter().next().unwrap();
        let alpha = caps.supported_composite_alpha.iter().next().unwrap();
        let format = caps.supported_formats[0].0;
        Swapchain::new(&device, &window.surface(), caps.min_image_count, format, dimensions, 1,
           &caps.supported_usage_flags, &queue, SurfaceTransform::Identity, alpha,
           present, true, None).expect("failed to create swapchain")
    };

    let render_pass = render_pass::CustomRenderPass::new(&device, &render_pass::Formats {
        color: (images[0].format(), 1)
    }).unwrap();

    let framebuffers = images.iter().map(|image| {
        let dimensions = [image.dimensions()[0], image.dimensions()[1], 1];
        Framebuffer::new(&render_pass, dimensions, render_pass::AList {
            color: image
        }).unwrap()
    }).collect::<Vec<_>>();

    let mut submissions: Vec<Arc<Submission>> = Vec::new();

    // UNIQUE CODE: create DrawText
    let mut draw_text = DrawText::new(&device, &queue, &images);

    let mut x = -200.0;

    loop {
        let (width, height) = window.window().get_inner_size_points().unwrap();
<commit_msg>Add window resize to demo<commit_after>// Most of this is just standard vulkano setup
// Check the code following the UNIQUE CODE comments

#[macro_use]
extern crate vulkano;
extern crate winit;
extern crate vulkano_win;
extern crate vulkano_text;

use vulkano_text::{DrawText, DrawTextTrait, UpdateTextCache};

use vulkano_win::VkSurfaceBuild;
use vulkano::command_buffer;
use vulkano::command_buffer::PrimaryCommandBufferBuilder;
use vulkano::command_buffer::Submission;
use vulkano::device::Device;
use vulkano::framebuffer::Framebuffer;
use vulkano::instance::Instance;
use vulkano::swapchain::SurfaceTransform;
use vulkano::swapchain::Swapchain;

use std::sync::Arc;
use std::time::Duration;

mod render_pass {
    use vulkano::format::Format;

    single_pass_renderpass!{
        attachments: {
            color: {
                load: Clear,
                store: Store,
                format: Format,
            }
        },
        pass: {
            color: [color],
            depth_stencil: {}
        }
    }
}

fn main() {
    let instance = {
        let extensions = vulkano_win::required_extensions();
        Instance::new(None, &extensions, None).expect("failed to create Vulkan instance")
    };
    let physical = vulkano::instance::PhysicalDevice::enumerate(&instance).next().expect("no device available");
    let window = winit::WindowBuilder::new().build_vk_surface(&instance).unwrap();
    let queue = physical.queue_families().find(|q| {
        q.supports_graphics() && window.surface().is_supported(q).unwrap_or(false)
    }).expect("couldn't find a graphical queue family");

    let (device, mut queues) = {
        let device_ext = vulkano::device::DeviceExtensions {
            khr_swapchain: true,
            .. vulkano::device::DeviceExtensions::none()
        };

        Device::new(&physical, physical.supported_features(), &device_ext,
                    [(queue, 0.5)].iter().cloned()).expect("failed to create device")
    };

    let queue = queues.next().unwrap();
    let (mut swapchain, mut images) = {
        let caps = window.surface().get_capabilities(&physical)
                         .expect("failed to get surface capabilities");
        let dimensions = caps.current_extent.unwrap_or([1280, 1024]);
        let present = caps.present_modes.iter().next().unwrap();
        let alpha = caps.supported_composite_alpha.iter().next().unwrap();
        let format = caps.supported_formats[0].0;
        Swapchain::new(&device, &window.surface(), caps.min_image_count, format, dimensions, 1,
           &caps.supported_usage_flags, &queue, SurfaceTransform::Identity, alpha,
           present, true, None).expect("failed to create swapchain")
    };

    let render_pass = render_pass::CustomRenderPass::new(&device, &render_pass::Formats {
        color: (images[0].format(), 1)
    }).unwrap();

    let mut framebuffers = images.iter().map(|image| {
        let dimensions = [image.dimensions()[0], image.dimensions()[1], 1];
        Framebuffer::new(&render_pass, dimensions, render_pass::AList {
            color: image
        }).unwrap()
    }).collect::<Vec<_>>();

    let mut submissions: Vec<Arc<Submission>> = Vec::new();

    // UNIQUE CODE: create DrawText
    let mut draw_text = DrawText::new(&device, &queue, &images);

    let mut x = -200.0;

    let (mut width, mut height) = window.window().get_inner_size_points().unwrap();

    loop {
        // TODO: https://github.com/tomaka/vulkano/issues/366 I guess we are waiting on the vulkano rewrite for this to not explode
        // TODO: Comment out all the draw_text code and resizing fails as described in the issue.
        let (new_width, new_height) = window.window().get_inner_size_points().unwrap();
        if width != new_width || height != new_height {
            width = new_width;
            height = new_height;

            let swapchain_results = swapchain.recreate_with_dimension([width, height]).unwrap();
            swapchain = swapchain_results.0;
            images = swapchain_results.1;

            framebuffers = images.iter().map(|image| {
                let dimensions = [image.dimensions()[0], image.dimensions()[1], 1];
                Framebuffer::new(&render_pass, dimensions, render_pass::AList {
                    color: image
                }).unwrap()
            }).collect::<Vec<_>>();

            // UNIQUE CODE: recreate DrawText due to new window size
            draw_text = DrawText::new(&device, &queue, &images);
        }

{'fraction_non_alphanumeric': 0.13608717688798783, 'fraction_numerical': 0.006588950836289914, 'mean_word_length': 3.0580976863753215, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5959464', 'n_tokens_mistral': 2337, 'n_tokens_neox': 2250, 'n_words': 516}