1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +01:00
OpenDX/src/dxvk/dxvk_image.h

234 lines
5.2 KiB
C
Raw Normal View History

2017-10-10 23:32:13 +02:00
#pragma once
2017-12-09 02:44:59 +01:00
#include "dxvk_format.h"
2017-10-10 23:32:13 +02:00
#include "dxvk_memory.h"
#include "dxvk_resource.h"
namespace dxvk {
/**
* \brief Image create info
*
* The properties of an image that are
* passed to \ref DxvkDevice::createImage
*/
2017-10-10 23:32:13 +02:00
struct DxvkImageCreateInfo {
/// Image dimension
2017-10-10 23:32:13 +02:00
VkImageType type;
/// Pixel format
2017-10-10 23:32:13 +02:00
VkFormat format;
2017-12-05 14:41:58 +01:00
/// Flags
VkImageCreateFlags flags;
/// Sample count for MSAA
2017-10-10 23:32:13 +02:00
VkSampleCountFlagBits sampleCount;
/// Image size, in texels
2017-10-10 23:32:13 +02:00
VkExtent3D extent;
/// Number of image array layers
2017-10-10 23:32:13 +02:00
uint32_t numLayers;
/// Number of mip levels
2017-10-10 23:32:13 +02:00
uint32_t mipLevels;
/// Image usage flags
2017-10-10 23:32:13 +02:00
VkImageUsageFlags usage;
/// Pipeline stages that can access
/// the contents of the image
VkPipelineStageFlags stages;
/// Allowed access pattern
VkAccessFlags access;
/// Image tiling mode
2017-10-10 23:32:13 +02:00
VkImageTiling tiling;
/// Common image layout
VkImageLayout layout;
2017-10-10 23:32:13 +02:00
};
/**
* \brief Image create info
*
* The properties of an image view that are
* passed to \ref DxvkDevice::createImageView
*/
2017-10-10 23:32:13 +02:00
struct DxvkImageViewCreateInfo {
/// Image view dimension
VkImageViewType type = VK_IMAGE_VIEW_TYPE_2D;
/// Pixel format
VkFormat format = VK_FORMAT_UNDEFINED;
/// Subresources to use in the view
VkImageAspectFlags aspect = 0;
uint32_t minLevel = 0;
uint32_t numLevels = 0;
uint32_t minLayer = 0;
uint32_t numLayers = 0;
/// Component mapping. Defaults to identity.
VkComponentMapping swizzle = {
VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY,
};
2017-10-10 23:32:13 +02:00
};
/**
* \brief DXVK image
2017-11-27 12:01:35 +01:00
*
* An image resource consisting of various subresources.
* Can be accessed by the host if allocated on a suitable
* memory type and if created with the linear tiling option.
2017-10-10 23:32:13 +02:00
*/
class DxvkImage : public DxvkResource {
public:
2017-11-27 12:01:35 +01:00
DxvkImage(
const Rc<vk::DeviceFn>& vkd,
const DxvkImageCreateInfo& createInfo,
DxvkMemoryAllocator& memAlloc,
VkMemoryPropertyFlags memFlags);
2017-10-10 23:32:13 +02:00
/**
* \brief Creates image object from existing image
*
* This can be used to create an image object for
* an implementation-managed image. Make sure to
* provide the correct image properties, since
* otherwise some image operations may fail.
*/
DxvkImage(
const Rc<vk::DeviceFn>& vkd,
const DxvkImageCreateInfo& info,
VkImage image);
/**
* \brief Destroys image
*
* If this is an implementation-managed image,
* this will not destroy the Vulkan image.
*/
~DxvkImage();
/**
* \brief Image handle
*
* Internal use only.
* \returns Image handle
*/
VkImage handle() const {
return m_image;
}
/**
* \brief Image properties
*
* The image create info structure.
* \returns Image properties
*/
const DxvkImageCreateInfo& info() const {
return m_info;
}
VkExtent3D mipLevelExtent(uint32_t level) const {
VkExtent3D size = m_info.extent;
size.width = std::max(1u, size.width >> level);
size.height = std::max(1u, size.height >> level);
size.depth = std::max(1u, size.depth >> level);
return size;
}
2017-10-10 23:32:13 +02:00
private:
Rc<vk::DeviceFn> m_vkd;
DxvkImageCreateInfo m_info;
DxvkMemory m_memory;
2017-11-27 12:01:35 +01:00
VkImage m_image = VK_NULL_HANDLE;
2017-10-10 23:32:13 +02:00
};
/**
* \brief DXVK image view
*/
class DxvkImageView : public DxvkResource {
public:
DxvkImageView(
const Rc<vk::DeviceFn>& vkd,
const Rc<DxvkImage>& image,
const DxvkImageViewCreateInfo& info);
~DxvkImageView();
/**
* \brief Image view handle
*
* Internal use only.
* \returns Image view handle
*/
VkImageView handle() const {
return m_view;
}
/**
* \brief Image view properties
* \returns Image view properties
*/
const DxvkImageViewCreateInfo& info() const {
return m_info;
}
/**
* \brief Image properties
* \returns Image properties
2017-10-10 23:32:13 +02:00
*/
const DxvkImageCreateInfo& imageInfo() const {
return m_image->info();
2017-10-10 23:32:13 +02:00
}
/**
* \brief Image
* \returns Image
*/
Rc<DxvkImage> image() const {
return m_image;
}
/**
* \brief Subresource range
* \returns Subresource range
*/
VkImageSubresourceRange subresources() const {
VkImageSubresourceRange result;
result.aspectMask = m_info.aspect;
result.baseMipLevel = m_info.minLevel;
result.levelCount = m_info.numLevels;
result.baseArrayLayer = m_info.minLayer;
result.layerCount = m_info.numLayers;
return result;
}
2017-10-10 23:32:13 +02:00
private:
Rc<vk::DeviceFn> m_vkd;
Rc<DxvkImage> m_image;
DxvkImageViewCreateInfo m_info;
VkImageView m_view;
};
}