<commit_before>﻿/**
 * Copyright (c) 2017 <NAME>
 * Licensed under the MIT License.
 * See LICENSE file for more information.
 */


#pragma once

//#include "saiga/vulkan/buffer/DeviceMemory.h"
#include "saiga/vulkan/Base.h"
#include "saiga/vulkan/svulkan.h"

namespace Saiga
{
namespace Vulkan
{
class SAIGA_GLOBAL Buffer
{
   protected:
    VulkanBase* base;
    vk::BufferUsageFlags bufferUsage = vk::BufferUsageFlagBits();
    vk::MemoryPropertyFlags memoryProperties = vk::MemoryPropertyFlags();
    MemoryLocation m_memoryLocation;

   public:
    ~Buffer() { destroy(); }


    void createBuffer(Saiga::Vulkan::VulkanBase& base, size_t size, vk::BufferUsageFlags bufferUsage,
                      const vk::MemoryPropertyFlags& memoryProperties, vk::SharingMode sharingMode = vk::SharingMode::eExclusive);

    /**
     * Perform a staged upload to the buffer. A StagingBuffer is created and used for this.
     * \see Saiga::Vulkan::StagingBuffer
     * @param base A reference to a VulkanBase
     * @param size Size of the data
     * @param data Pointer to the data.
     */
    void stagedUpload(VulkanBase& base, size_t size, const void* data);

    vk::DescriptorBufferInfo createInfo();

    void flush(VulkanBase& base, vk::DeviceSize size = VK_WHOLE_SIZE, vk::DeviceSize offset = 0);

    void destroy();

    inline vk::DeviceSize size() const { return m_memoryLocation.size; }

    /**
     * Copy this buffer to another with vk::CommandBuffer::copyBuffer
     * @param cmd vk::commandBuffer to use.
     * @param target Target buffer
     * @param srcOffset Offset in bytes at the source.
     * @param dstOffset Offset in bytes at the target.
     * @param size Number of bytes to copy.
     */
    void copyTo(vk::CommandBuffer cmd, Buffer& target, vk::DeviceSize srcOffset = 0, vk::DeviceSize dstOffset = 0,
                vk::DeviceSize size = VK_WHOLE_SIZE);

    /**
     * Copy the buffer to an image with vk::CommandBuffer::copyBufferToImage
     * @param cmd command buffer to use
     * @param dstImage Destination image
     * @param dstImageLayout Destination image layout
     * @param regions Regions to copy
     */
    void copyTo(vk::CommandBuffer cmd, vk::Image dstImage, vk::ImageLayout dstImageLayout,
                vk::ArrayProxy<const vk::BufferImageCopy> regions);

    /**
     * Get a buffer image copy with the correct offset set for this buffer.
     * @param offset Additional offset in bytes from the beginning of the buffer.
     * @return An instance of vk::BufferImageCopy.
     */<commit_msg>Add offset field to buffer<commit_after>﻿/**
 * Copyright (c) 2017 <NAME>
 * Licensed under the MIT License.
 * See LICENSE file for more information.
 */


#pragma once

//#include "saiga/vulkan/buffer/DeviceMemory.h"
#include "saiga/vulkan/Base.h"
#include "saiga/vulkan/svulkan.h"

namespace Saiga
{
namespace Vulkan
{
class SAIGA_GLOBAL Buffer
{
   protected:
    VulkanBase* base;
    vk::BufferUsageFlags bufferUsage = vk::BufferUsageFlagBits();
    vk::MemoryPropertyFlags memoryProperties = vk::MemoryPropertyFlags();
    MemoryLocation m_memoryLocation;

   public:
    ~Buffer() { destroy(); }


    void createBuffer(Saiga::Vulkan::VulkanBase& base, size_t size, vk::BufferUsageFlags bufferUsage,
                      const vk::MemoryPropertyFlags& memoryProperties, vk::SharingMode sharingMode = vk::SharingMode::eExclusive);

    /**
     * Perform a staged upload to the buffer. A StagingBuffer is created and used for this.
     * \see Saiga::Vulkan::StagingBuffer
     * @param base A reference to a VulkanBase
     * @param size Size of the data
     * @param data Pointer to the data.
     */
    void stagedUpload(VulkanBase& base, size_t size, const void* data);

    vk::DescriptorBufferInfo createInfo();

    void flush(VulkanBase& base, vk::DeviceSize size = VK_WHOLE_SIZE, vk::DeviceSize offset = 0);

    void destroy();

    inline vk::DeviceSize offset() const {return m_memoryLocation.offset;}
    inline vk::DeviceSize size() const { return m_memoryLocation.size; }

    /**
     * Copy this buffer to another with vk::CommandBuffer::copyBuffer
     * @param cmd vk::commandBuffer to use.
     * @param target Target buffer
     * @param srcOffset Offset in bytes at the source.
     * @param dstOffset Offset in bytes at the target.
     * @param size Number of bytes to copy.
     */
    void copyTo(vk::CommandBuffer cmd, Buffer& target, vk::DeviceSize srcOffset = 0, vk::DeviceSize dstOffset = 0,
                vk::DeviceSize size = VK_WHOLE_SIZE);

    /**
     * Copy the buffer to an image with vk::CommandBuffer::copyBufferToImage
     * @param cmd command buffer to use
     * @param dstImage Destination image
     * @param dstImageLayout Destination image layout
     * @param regions Regions to copy
     */
    void copyTo(vk::CommandBuffer cmd, vk::Image dstImage, vk::ImageLayout dstImageLayout,
                vk::ArrayProxy<const vk::BufferImageCopy> regions);

    /**
     * Get a buffer image copy with the correct offset set for this buffer.
     * @param offset Additional offset in bytes from the beginning of the buffer.
     * @return An instance of vk::BufferImageCopy.
     */
{'fraction_non_alphanumeric': 0.09718472811415349, 'fraction_numerical': 0.002699575780948708, 'mean_word_length': 3.373524451939292, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '7637946', 'n_tokens_mistral': 1567, 'n_tokens_neox': 1494, 'n_words': 494}