Skip to content

Commit 88cfc0e

Browse files
committed
API追加
1 parent 4926567 commit 88cfc0e

File tree

5 files changed

+114
-6
lines changed

5 files changed

+114
-6
lines changed

include/orge.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,23 @@ API_EXPORT uint8_t orgeUpdateBufferDescriptor(
111111
uint32_t offset
112112
);
113113

114+
/// バッファディスクリプタを更新する関数 (コンピュートパイプライン)
115+
///
116+
/// - pipelineId: パイプラインID
117+
/// - id: バッファID
118+
/// - set: ディスクリプタセット番号
119+
/// - index: 何個目のディスクリプタセットか
120+
/// - binding: バインディング番号
121+
/// - offset: 配列上のオフセット (ディスクリプタが配列でないなら0)
122+
API_EXPORT uint8_t orgeUpdateComputeBufferDescriptor(
123+
const char *pipelineId,
124+
const char *id,
125+
uint32_t set,
126+
uint32_t index,
127+
uint32_t binding,
128+
uint32_t offset
129+
);
130+
114131
/// orgeにイメージを追加する関数
115132
///
116133
/// - file: アセットファイル名
@@ -138,6 +155,23 @@ API_EXPORT uint8_t orgeUpdateImageDescriptor(
138155
uint32_t offset
139156
);
140157

158+
/// イメージディスクリプタを更新する関数 (コンピュートパイプライン)
159+
///
160+
/// - pipelineId: パイプラインID
161+
/// - id: イメージID (アセットファイル名)
162+
/// - set: ディスクリプタセット番号
163+
/// - index: 何個目のディスクリプタセットか
164+
/// - binding: バインディング番号
165+
/// - offset: 配列上のオフセット (ディスクリプタが配列でないなら0)
166+
API_EXPORT uint8_t orgeUpdateComputeImageDescriptor(
167+
const char *pipelineId,
168+
const char *id,
169+
uint32_t set,
170+
uint32_t index,
171+
uint32_t binding,
172+
uint32_t offset
173+
);
174+
141175
/// orgeにサンプラを追加する関数
142176
///
143177
/// - id: サンプラID
@@ -174,6 +208,23 @@ API_EXPORT uint8_t orgeUpdateSamplerDescriptor(
174208
uint32_t offset
175209
);
176210

211+
/// サンプラディスクリプタを更新する関数 (コンピュート)
212+
///
213+
/// - pipelineId: パイプラインID
214+
/// - id: サンプラID
215+
/// - set: ディスクリプタセット番号
216+
/// - index: 何個目のディスクリプタセットか
217+
/// - binding: バインディング番号
218+
/// - offset: 配列上のオフセット (ディスクリプタが配列でないなら0)
219+
API_EXPORT uint8_t orgeUpdateComputeSamplerDescriptor(
220+
const char *pipelineId,
221+
const char *id,
222+
uint32_t set,
223+
uint32_t index,
224+
uint32_t binding,
225+
uint32_t offset
226+
);
227+
177228
/// アタッチメントディスクリプタを更新する関数
178229
///
179230
/// - renderPassId: レンダーパスID
@@ -330,6 +381,21 @@ API_EXPORT uint8_t orgeDraw(uint32_t instanceCount, uint32_t instanceOffset);
330381
/// WARN: パイプラインがバインドされていること。
331382
API_EXPORT uint8_t orgeDrawDirectly(uint32_t vertexCount, uint32_t instanceCount, uint32_t instanceOffset);
332383

384+
// ================================================================================================================== //
385+
// Compute //
386+
// ================================================================================================================== //
387+
388+
/// コンピュートパイプラインをバインドする関数
389+
///
390+
/// WARN: 描画が開始されていること。
391+
/// WARN: レンダーパスがバインドされていないこと。
392+
uint8_t orgeBindComputePipeline(const char *pipelineId, uint32_t const *indices);
393+
394+
/// コンピュートパイプラインを実行する関数
395+
///
396+
/// WARN: パイプラインがバインドされていること。
397+
uint8_t orgeDispatch(uint32_t x, uint32_t y, uint32_t z);
398+
333399
// ================================================================================================================== //
334400
// Input //
335401
// ================================================================================================================== //

src/graphics/compute/pipeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ DEFINE_UPDATE_DESC_METHOD(updateBufferDescriptor) {
4848
core::device().updateDescriptorSets(1, &ds, 0, nullptr);
4949
}
5050

51-
DEFINE_UPDATE_DESC_METHOD(updateUserImageDescriptor) {
51+
DEFINE_UPDATE_DESC_METHOD(updateImageDescriptor) {
5252
const auto &descSets = error::at(_descSetss, set, "descriptor sets");
5353
const auto &descSet = error::at(descSets, index, "descriptor sets allocated");
5454
const auto &image = resource::getUserImage(id);

src/graphics/compute/pipeline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ComputePipeline {
5151
) const
5252

5353
DECLARE_UPDATE_DESC_METHOD(updateBufferDescriptor);
54-
DECLARE_UPDATE_DESC_METHOD(updateUserImageDescriptor);
54+
DECLARE_UPDATE_DESC_METHOD(updateImageDescriptor);
5555
DECLARE_UPDATE_DESC_METHOD(updateSamplerDescriptor);
5656

5757
#undef DECLARE_UPDATE_DESC_METHOD

src/graphics/renderer/context.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,14 @@ class RenderContext {
134134
if (_renderPass) {
135135
throw std::format("render pass '{}' not ended.", _renderPass->id());
136136
}
137-
const auto &computePipeline = compute::getComputePipeline(pipelineId);
138-
computePipeline.bind(_commandBuffer);
139-
computePipeline.bindDescriptorSets(_commandBuffer, indices);
140-
_computePipeline = &computePipeline;
137+
if (!_computePipeline || _computePipeline->id() != pipelineId) {
138+
const auto &computePipeline = compute::getComputePipeline(pipelineId);
139+
computePipeline.bind(_commandBuffer);
140+
if (indices) {
141+
computePipeline.bindDescriptorSets(_commandBuffer, indices);
142+
}
143+
_computePipeline = &computePipeline;
144+
}
141145
}
142146

143147
void dispatch(uint32_t x, uint32_t y, uint32_t z) const {

src/orge-compute.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <orge.h>
2+
3+
#include "graphics/compute/pipeline.hpp"
4+
#include "graphics/renderer/renderer.hpp"
5+
#include "orge-private.hpp"
6+
7+
#define DEFINE_UPDATE_DESC_FUNC(n) \
8+
uint8_t orgeUpdateCompute##n##Descriptor( \
9+
const char *pipelineId, \
10+
const char *id, \
11+
uint32_t set, \
12+
uint32_t index, \
13+
uint32_t binding, \
14+
uint32_t offset \
15+
) { \
16+
TRY( \
17+
graphics::compute::getComputePipeline(pipelineId) \
18+
.update##n##Descriptor(id, set, index, binding, offset) \
19+
); \
20+
}
21+
22+
DEFINE_UPDATE_DESC_FUNC(Buffer)
23+
DEFINE_UPDATE_DESC_FUNC(Image)
24+
DEFINE_UPDATE_DESC_FUNC(Sampler)
25+
26+
#define TRY_OR(n) \
27+
bool result = false; \
28+
CHECK(n); \
29+
if (!result) graphics::renderer::renderer().reset(); \
30+
return static_cast<uint8_t>(result);
31+
32+
uint8_t orgeBindComputePipeline(const char *pipelineId, uint32_t const *indices) {
33+
TRY_OR(graphics::renderer::renderer().getContext().bindComputePipeline(pipelineId, indices));
34+
}
35+
36+
uint8_t orgeDispatch(uint32_t x, uint32_t y, uint32_t z) {
37+
TRY_OR(graphics::renderer::renderer().getContext().dispatch(x, y, z));
38+
}

0 commit comments

Comments
 (0)