Skip to content

Commit 782fbdf

Browse files
authored
Update QueryPool interface (#1028)
* Update slang-rhi * Replace QueryPool::is_result_ready with QueryPool::get_result_state
1 parent 68f7bbf commit 782fbdf

6 files changed

Lines changed: 60 additions & 12 deletions

File tree

src/sgl/device/query.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,24 @@ void QueryPool::reset(uint32_t index, uint32_t count)
3232
SLANG_RHI_CALL(m_rhi_query_pool->reset(index, count), m_device);
3333
}
3434

35-
void QueryPool::get_results(uint32_t index, uint32_t count, std::span<uint64_t> result)
35+
QueryResultState QueryPool::get_result_state(uint32_t index, uint32_t count)
3636
{
3737
SGL_CHECK(uint64_t(index) + count <= m_desc.count, "'index' / 'count' out of range");
38-
SGL_CHECK(result.size() >= count, "'result' buffer too small");
39-
SLANG_RHI_CALL(m_rhi_query_pool->getResult(index, count, result.data()), m_device);
38+
rhi::QueryResultState rhi_state;
39+
SLANG_RHI_CALL(m_rhi_query_pool->getResultState(index, count, &rhi_state), m_device);
40+
return static_cast<QueryResultState>(rhi_state);
4041
}
4142

42-
bool QueryPool::is_result_ready(uint32_t index, uint32_t count)
43+
QueryResultState QueryPool::get_result_state(uint32_t index)
44+
{
45+
return get_result_state(index, 1);
46+
}
47+
48+
void QueryPool::get_results(uint32_t index, uint32_t count, std::span<uint64_t> result)
4349
{
4450
SGL_CHECK(uint64_t(index) + count <= m_desc.count, "'index' / 'count' out of range");
45-
bool ready;
46-
SLANG_RHI_CALL(m_rhi_query_pool->isResultReady(index, count, &ready), m_device);
47-
return ready;
51+
SGL_CHECK(result.size() >= count, "'result' buffer too small");
52+
SLANG_RHI_CALL(m_rhi_query_pool->getResult(index, count, result.data()), m_device);
4853
}
4954

5055
std::vector<uint64_t> QueryPool::get_results(uint32_t index, uint32_t count)

src/sgl/device/query.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class SGL_API QueryPool : public DeviceChild {
3535
void reset();
3636
void reset(uint32_t index, uint32_t count);
3737

38-
bool is_result_ready(uint32_t index, uint32_t count);
38+
QueryResultState get_result_state(uint32_t index, uint32_t count);
39+
QueryResultState get_result_state(uint32_t index);
3940

4041
void get_results(uint32_t index, uint32_t count, std::span<uint64_t> result);
4142
std::vector<uint64_t> get_results(uint32_t index, uint32_t count);

src/sgl/device/types.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,22 @@ SGL_ENUM_INFO(
797797
);
798798
SGL_ENUM_REGISTER(QueryType);
799799

800+
enum class QueryResultState : uint32_t {
801+
reset = static_cast<uint32_t>(rhi::QueryResultState::Reset),
802+
pending = static_cast<uint32_t>(rhi::QueryResultState::Pending),
803+
resolved = static_cast<uint32_t>(rhi::QueryResultState::Resolved),
804+
};
805+
806+
SGL_ENUM_INFO(
807+
QueryResultState,
808+
{
809+
{QueryResultState::reset, "reset"},
810+
{QueryResultState::pending, "pending"},
811+
{QueryResultState::resolved, "resolved"},
812+
}
813+
);
814+
SGL_ENUM_REGISTER(QueryResultState);
815+
800816
enum class CpuTimestampDomain : uint32_t {
801817
unknown = static_cast<uint32_t>(rhi::CpuTimestampDomain::Unknown),
802818
query_performance_counter = static_cast<uint32_t>(rhi::CpuTimestampDomain::QueryPerformanceCounter),

src/slangpy_ext/device/query.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,19 @@ SGL_PY_EXPORT(device_query)
3838
"count"_a,
3939
D(QueryPool, reset, 2)
4040
)
41-
.def("is_result_ready", &QueryPool::is_result_ready, "index"_a, "count"_a, D(QueryPool, is_result_ready))
41+
.def(
42+
"get_result_state",
43+
nb::overload_cast<uint32_t, uint32_t>(&QueryPool::get_result_state),
44+
"index"_a,
45+
"count"_a,
46+
D(QueryPool, get_result_state)
47+
)
48+
.def(
49+
"get_result_state",
50+
nb::overload_cast<uint32_t>(&QueryPool::get_result_state),
51+
"index"_a,
52+
D(QueryPool, get_result_state, 2)
53+
)
4254
.def("get_result", &QueryPool::get_result, "index"_a, D(QueryPool, get_result))
4355
.def(
4456
"get_results",

src/slangpy_ext/py_doc.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6501,6 +6501,10 @@ static const char *__doc_sgl_QueryPool_desc = R"doc()doc";
65016501

65026502
static const char *__doc_sgl_QueryPool_get_result = R"doc()doc";
65036503

6504+
static const char *__doc_sgl_QueryPool_get_result_state = R"doc()doc";
6505+
6506+
static const char *__doc_sgl_QueryPool_get_result_state_2 = R"doc()doc";
6507+
65046508
static const char *__doc_sgl_QueryPool_get_results = R"doc()doc";
65056509

65066510
static const char *__doc_sgl_QueryPool_get_results_2 = R"doc()doc";
@@ -6511,8 +6515,6 @@ static const char *__doc_sgl_QueryPool_get_timestamp_results = R"doc()doc";
65116515

65126516
static const char *__doc_sgl_QueryPool_get_timestamp_results_2 = R"doc()doc";
65136517

6514-
static const char *__doc_sgl_QueryPool_is_result_ready = R"doc()doc";
6515-
65166518
static const char *__doc_sgl_QueryPool_m_desc = R"doc()doc";
65176519

65186520
static const char *__doc_sgl_QueryPool_m_rhi_query_pool = R"doc()doc";
@@ -6527,6 +6529,16 @@ static const char *__doc_sgl_QueryPool_rhi_query_pool = R"doc()doc";
65276529

65286530
static const char *__doc_sgl_QueryPool_to_string = R"doc()doc";
65296531

6532+
static const char *__doc_sgl_QueryResultState = R"doc()doc";
6533+
6534+
static const char *__doc_sgl_QueryResultState_info = R"doc()doc";
6535+
6536+
static const char *__doc_sgl_QueryResultState_pending = R"doc()doc";
6537+
6538+
static const char *__doc_sgl_QueryResultState_reset = R"doc()doc";
6539+
6540+
static const char *__doc_sgl_QueryResultState_resolved = R"doc()doc";
6541+
65306542
static const char *__doc_sgl_QueryType = R"doc()doc";
65316543

65326544
static const char *__doc_sgl_QueryType_acceleration_structure_compacted_size = R"doc()doc";
@@ -10059,6 +10071,8 @@ static const char *__doc_sgl_find_enum_info_adl_78 = R"doc()doc";
1005910071

1006010072
static const char *__doc_sgl_find_enum_info_adl_79 = R"doc()doc";
1006110073

10074+
static const char *__doc_sgl_find_enum_info_adl_80 = R"doc()doc";
10075+
1006210076
static const char *__doc_sgl_flags_to_string_list = R"doc(Convert an flags enum value to a list of strings.)doc";
1006310077

1006410078
static const char *__doc_sgl_flip_bit = R"doc()doc";

0 commit comments

Comments
 (0)