KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rhi_device_proxy.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21#include <rhi/render_thread.h>
23
24#include <memory>
25#include <vector>
26
27using namespace KIGFX;
28
29
31{
32 RHI_BufferHandle handle = m_renderThread.ReserveBufferHandle();
33
34 if( !handle )
35 return {};
36
38 cmd.handle = handle;
39 cmd.desc = aDesc;
40 m_renderThread.SubmitUpload( cmd );
41
42 return handle;
43}
44
45
47{
48 RHI_TextureHandle handle = m_renderThread.ReserveTextureHandle();
49
50 if( !handle )
51 return {};
52
54 cmd.handle = handle;
55 cmd.desc = aDesc;
56 m_renderThread.SubmitUpload( cmd );
57
58 return handle;
59}
60
61
62void RHI_DEVICE_PROXY::UpdateBuffer( RHI_BufferHandle aHandle, const void* aData, size_t aSize )
63{
64 if( !aHandle || !aData || aSize == 0 )
65 return;
66
68 RhiUploadCopyStaging( upload, aData, aSize );
69 upload.targetBuffer = aHandle;
70 m_renderThread.SubmitUpload( std::move( upload ) );
71}
72
73
74void RHI_DEVICE_PROXY::UploadTexture( RHI_TextureHandle aHandle, const void* aData, size_t aSize )
75{
76 if( !aHandle || !aData || aSize == 0 )
77 return;
78
79 RHI_TEXTURE_UPLOAD upload;
80 RhiUploadCopyStaging( upload, aData, aSize );
81 upload.targetTexture = aHandle;
82 m_renderThread.SubmitUpload( std::move( upload ) );
83}
84
85
87{
88 if( aHandle )
89 m_renderThread.SubmitUpload( RHI_BUFFER_DESTROY{ aHandle } );
90}
91
92
94{
95 if( aHandle )
96 m_renderThread.SubmitUpload( RHI_TEXTURE_DESTROY{ aHandle } );
97}
98
99
101{
102 return m_renderThread.GetBackendType();
103}
104
105
107{
108 return m_renderThread.GetMaxTextureSize();
109}
110
111
113{
114 return m_renderThread.IsRunning();
115}
void UploadTexture(RHI_TextureHandle aHandle, const void *aData, size_t aSize)
RHI_BufferHandle CreateBuffer(const RHI_BUFFER_DESC &aDesc)
RENDER_THREAD & m_renderThread
void DestroyTexture(RHI_TextureHandle aHandle)
void UpdateBuffer(RHI_BufferHandle aHandle, const void *aData, size_t aSize)
The data is copied, so the caller may reuse it immediately.
RHI_TextureHandle CreateTexture(const RHI_TEXTURE_DESC &aDesc)
RHI_BACKEND GetBackend() const
uint32_t MaxTextureSize() const
void DestroyBuffer(RHI_BufferHandle aHandle)
Queued behind the handle's create and uploads.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
RHI_HANDLE< RHI_TAG_TEXTURE > RHI_TextureHandle
Definition rhi_handle.h:84
RHI_HANDLE< RHI_TAG_BUFFER > RHI_BufferHandle
Definition rhi_handle.h:83
RHI_BACKEND
Identifies which graphics backend a device implements.
Definition rhi_types.h:28
void RhiUploadCopyStaging(RHI_STAGING &aUpload, const void *aSrc, size_t aBytes)
Copy the source into the upload, for data the producer keeps using after queuing.
Create the GPU buffer for a handle the UI thread already reserved, so only the render thread writes t...
RHI_BufferHandle handle
Destroy a buffer the UI thread created, queued so it runs after the handle's create and uploads.
RHI_BufferHandle targetBuffer
Texture counterpart of RHI_BUFFER_CREATE.
RHI_TextureHandle handle
Texture counterpart of RHI_BUFFER_DESTROY.
RHI_TextureHandle targetTexture