summaryrefslogtreecommitdiffstats
path: root/tools/gfx/vulkan/vk-resource-views.cpp
blob: 10d96ed542351c9e97ea9b5621eba3e0d729a9fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// vk-resource-views.cpp
#include "vk-resource-views.h"

namespace gfx
{

using namespace Slang;

namespace vk
{

TextureResourceViewImpl::~TextureResourceViewImpl()
{
    m_device->m_api.vkDestroyImageView(m_device->m_api.m_device, m_view, nullptr);
}

Result TextureResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
{
    outHandle->api = InteropHandleAPI::Vulkan;
    outHandle->handleValue = (uint64_t)(m_view);
    return SLANG_OK;
}

TexelBufferResourceViewImpl::TexelBufferResourceViewImpl(DeviceImpl* device)
    : ResourceViewImpl(ViewType::TexelBuffer, device)
{}

TexelBufferResourceViewImpl::~TexelBufferResourceViewImpl()
{
    m_device->m_api.vkDestroyBufferView(m_device->m_api.m_device, m_view, nullptr);
}

Result TexelBufferResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
{
    outHandle->api = InteropHandleAPI::Vulkan;
    outHandle->handleValue = (uint64_t)(m_view);
    return SLANG_OK;
}

PlainBufferResourceViewImpl::PlainBufferResourceViewImpl(DeviceImpl* device)
    : ResourceViewImpl(ViewType::PlainBuffer, device)
{}

Result PlainBufferResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
{
    return m_buffer->getNativeResourceHandle(outHandle);
}

DeviceAddress AccelerationStructureImpl::getDeviceAddress()
{
    return m_buffer->getDeviceAddress() + m_offset;
}

Result AccelerationStructureImpl::getNativeHandle(InteropHandle* outHandle)
{
    outHandle->api = InteropHandleAPI::Vulkan;
    outHandle->handleValue = (uint64_t)(m_vkHandle);
    return SLANG_OK;
}

AccelerationStructureImpl::~AccelerationStructureImpl()
{
    if (m_device)
    {
        m_device->m_api.vkDestroyAccelerationStructureKHR(
            m_device->m_api.m_device, m_vkHandle, nullptr);
    }
}

} // namespace vk
} // namespace gfx