summaryrefslogtreecommitdiffstats
path: root/tools/gfx/cpu/cpu-buffer.cpp
blob: a1184fd95ebade51c052fb23c9641da4d5b7fd80 (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
// cpu-buffer.cpp
#include "cpu-buffer.h"

namespace gfx
{
using namespace Slang;

namespace cpu
{

BufferResourceImpl::~BufferResourceImpl()
{
    if (m_data)
    {
        free(m_data);
    }
}

Result BufferResourceImpl::init()
{
    m_data = malloc(m_desc.sizeInBytes);
    if (!m_data)
        return SLANG_E_OUT_OF_MEMORY;
    return SLANG_OK;
}

Result BufferResourceImpl::setData(size_t offset, size_t size, void const* data)
{
    memcpy((char*)m_data + offset, data, size);
    return SLANG_OK;
}

SLANG_NO_THROW DeviceAddress SLANG_MCALL BufferResourceImpl::getDeviceAddress()
{
    return (DeviceAddress)m_data;
}

SLANG_NO_THROW Result SLANG_MCALL
BufferResourceImpl::map(MemoryRange* rangeToRead, void** outPointer)
{
    SLANG_UNUSED(rangeToRead);
    if (outPointer)
        *outPointer = m_data;
    return SLANG_OK;
}

SLANG_NO_THROW Result SLANG_MCALL BufferResourceImpl::unmap(MemoryRange* writtenRange)
{
    SLANG_UNUSED(writtenRange);
    return SLANG_OK;
}

} // namespace cpu
} // namespace gfx