KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rhi_upload_commands.h
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
20#ifndef RHI_UPLOAD_COMMANDS_H
21#define RHI_UPLOAD_COMMANDS_H
22
23#include <rhi/rhi_handle.h>
24#include <rhi/rhi_buffer.h>
25#include <rhi/rhi_texture.h>
26
27#include <cstddef>
28#include <cstdint>
29#include <memory>
30#include <variant>
31#include <vector>
32
33
42{
43 std::shared_ptr<const void> stagingOwner;
44 const void* stagingData = nullptr;
45 size_t stagingSize = 0;
46
47 bool HasStaging() const { return stagingData && stagingSize > 0; }
48};
49
50
56
57
62
63
67inline void RhiUploadCopyStaging( RHI_STAGING& aUpload, const void* aSrc, size_t aBytes )
68{
69 auto held = std::make_shared<std::vector<uint8_t>>(
70 static_cast<const uint8_t*>( aSrc ), static_cast<const uint8_t*>( aSrc ) + aBytes );
71 aUpload.stagingData = held->data();
72 aUpload.stagingSize = aBytes;
73 aUpload.stagingOwner = std::move( held );
74}
75
76
80template <typename T>
81inline void RhiUploadAdoptStaging( RHI_STAGING& aUpload, std::vector<T>&& aVector )
82{
83 auto held = std::make_shared<std::vector<T>>( std::move( aVector ) );
84 aUpload.stagingData = held->data();
85 aUpload.stagingSize = held->size() * sizeof( T );
86 aUpload.stagingOwner = std::move( held );
87}
88
89
99
100
109
110
119
120
128
129
133using RHI_UPLOAD_COMMAND = std::variant<
140>;
141
142
143
144#endif // RHI_UPLOAD_COMMANDS_H
RHI_HANDLE< RHI_TAG_TEXTURE > RHI_TextureHandle
Definition rhi_handle.h:84
RHI_HANDLE< RHI_TAG_BUFFER > RHI_BufferHandle
Definition rhi_handle.h:83
std::variant< RHI_GEOMETRY_UPLOAD, RHI_TEXTURE_UPLOAD, RHI_BUFFER_CREATE, RHI_TEXTURE_CREATE, RHI_BUFFER_DESTROY, RHI_TEXTURE_DESTROY > RHI_UPLOAD_COMMAND
One entry in the render thread upload queue.
void RhiUploadAdoptStaging(RHI_STAGING &aUpload, std::vector< T > &&aVector)
Move the vector into the upload without a copy, for data the producer does not read after queuing.
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 handle
RHI_BufferHandle targetBuffer
Staging data owned by the upload command, so the UI thread can reuse its source at once without racin...
const void * stagingData
bool HasStaging() const
std::shared_ptr< const void > stagingOwner
Texture counterpart of RHI_BUFFER_CREATE.
RHI_TextureHandle handle
Texture counterpart of RHI_BUFFER_DESTROY.
RHI_TextureHandle handle
RHI_TextureHandle targetTexture