1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-31 23:52:20 +01:00

[dxvk] Add function to invalidate images

This commit is contained in:
Philip Rebohle 2024-09-26 03:21:46 +02:00 committed by Philip Rebohle
parent 347925c8b7
commit 50878f2846
4 changed files with 69 additions and 5 deletions

View File

@ -1815,7 +1815,6 @@ namespace dxvk {
void DxvkContext::invalidateBuffer( void DxvkContext::invalidateBuffer(
const Rc<DxvkBuffer>& buffer, const Rc<DxvkBuffer>& buffer,
Rc<DxvkResourceAllocation>&& slice) { Rc<DxvkResourceAllocation>&& slice) {
// Allocate new backing resource
Rc<DxvkResourceAllocation> prevAllocation = buffer->assignSlice(std::move(slice)); Rc<DxvkResourceAllocation> prevAllocation = buffer->assignSlice(std::move(slice));
m_cmd->trackResource<DxvkAccess::None>(std::move(prevAllocation)); m_cmd->trackResource<DxvkAccess::None>(std::move(prevAllocation));
@ -1851,6 +1850,31 @@ namespace dxvk {
} }
void DxvkContext::invalidateImage(
const Rc<DxvkImage>& image,
Rc<DxvkResourceAllocation>&& slice) {
Rc<DxvkResourceAllocation> prevAllocation = image->assignResource(std::move(slice));
m_cmd->trackResource<DxvkAccess::None>(std::move(prevAllocation));
VkImageUsageFlags usage = image->info().usage;
if (usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT))
m_descriptorState.dirtyViews(image->getShaderStages());
if (usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
// Interrupt the current render pass if the image is bound for rendering
for (uint32_t i = 0; i < m_state.om.framebufferInfo.numAttachments(); i++) {
if (m_state.om.framebufferInfo.getAttachment(i).view->image() == image) {
this->spillRenderPass(false);
m_flags.set(DxvkContextFlag::GpDirtyFramebuffer);
break;
}
}
}
}
void DxvkContext::resolveImage( void DxvkContext::resolveImage(
const Rc<DxvkImage>& dstImage, const Rc<DxvkImage>& dstImage,
const Rc<DxvkImage>& srcImage, const Rc<DxvkImage>& srcImage,

View File

@ -965,6 +965,19 @@ namespace dxvk {
const Rc<DxvkBuffer>& buffer, const Rc<DxvkBuffer>& buffer,
Rc<DxvkResourceAllocation>&& slice); Rc<DxvkResourceAllocation>&& slice);
/**
* \brief Invalidates image content
*
* Replaces the backing storage of an image.
* \warning If the image is used by another context,
* invalidating it will result in undefined behaviour.
* \param [in] buffer The buffer to invalidate
* \param [in] slice New buffer slice
*/
void invalidateImage(
const Rc<DxvkImage>& image,
Rc<DxvkResourceAllocation>&& slice);
/** /**
* \brief Updates push constants * \brief Updates push constants
* *

View File

@ -9,7 +9,11 @@ namespace dxvk {
const DxvkImageCreateInfo& createInfo, const DxvkImageCreateInfo& createInfo,
DxvkMemoryAllocator& memAlloc, DxvkMemoryAllocator& memAlloc,
VkMemoryPropertyFlags memFlags) VkMemoryPropertyFlags memFlags)
: m_vkd(device->vkd()), m_allocator(&memAlloc), m_properties(memFlags), m_info(createInfo) { : m_vkd (device->vkd()),
m_allocator (&memAlloc),
m_properties (memFlags),
m_shaderStages (util::shaderStages(createInfo.stages)),
m_info (createInfo) {
copyFormatList(createInfo.viewFormatCount, createInfo.viewFormats); copyFormatList(createInfo.viewFormatCount, createInfo.viewFormats);
// Determine whether the image is shareable before creating the resource // Determine whether the image is shareable before creating the resource
@ -22,12 +26,16 @@ namespace dxvk {
DxvkImage::DxvkImage( DxvkImage::DxvkImage(
DxvkDevice* device, DxvkDevice* device,
const DxvkImageCreateInfo& info, const DxvkImageCreateInfo& createInfo,
VkImage imageHandle, VkImage imageHandle,
DxvkMemoryAllocator& memAlloc, DxvkMemoryAllocator& memAlloc,
VkMemoryPropertyFlags memFlags) VkMemoryPropertyFlags memFlags)
: m_vkd(device->vkd()), m_allocator(&memAlloc), m_properties(memFlags), m_info(info) { : m_vkd (device->vkd()),
copyFormatList(info.viewFormatCount, info.viewFormats); m_allocator (&memAlloc),
m_properties (memFlags),
m_shaderStages (util::shaderStages(createInfo.stages)),
m_info (createInfo) {
copyFormatList(createInfo.viewFormatCount, createInfo.viewFormats);
// Create backing storage for existing image resource // Create backing storage for existing image resource
VkImageCreateInfo imageInfo = getImageCreateInfo(); VkImageCreateInfo imageInfo = getImageCreateInfo();

View File

@ -373,6 +373,16 @@ namespace dxvk {
return m_properties; return m_properties;
} }
/**
* \brief Queries shader stages that can access this image
*
* Derived from the pipeline stage mask passed in during creation.
* \returns Shader stages that may access this image
*/
VkShaderStageFlags getShaderStages() const {
return m_shaderStages;
}
/** /**
* \brief Map pointer * \brief Map pointer
* *
@ -543,6 +553,14 @@ namespace dxvk {
return old; return old;
} }
/**
* \brief Retrieves current backing storage
* \returns Backing storage for this image
*/
Rc<DxvkResourceAllocation> getAllocation() const {
return m_storage;
}
/** /**
* \brief Creates or retrieves an image view * \brief Creates or retrieves an image view
* *
@ -557,6 +575,7 @@ namespace dxvk {
Rc<vk::DeviceFn> m_vkd; Rc<vk::DeviceFn> m_vkd;
DxvkMemoryAllocator* m_allocator = nullptr; DxvkMemoryAllocator* m_allocator = nullptr;
VkMemoryPropertyFlags m_properties = 0u; VkMemoryPropertyFlags m_properties = 0u;
VkShaderStageFlags m_shaderStages = 0u;
DxvkImageCreateInfo m_info = { }; DxvkImageCreateInfo m_info = { };