raw vk::deviceproperties and python dict

This commit is contained in:
alexander-g 2021-03-12 09:51:31 +01:00
parent f52efcef0f
commit d71d169886
5 changed files with 24 additions and 65 deletions

View file

@ -9,6 +9,8 @@
#include "docstrings.hpp"
namespace py = pybind11;
using namespace pybind11::literals; // for the `_a` literal
//used in Core.hpp
py::object kp_debug, kp_info, kp_warning, kp_error;
@ -218,25 +220,23 @@ PYBIND11_MODULE(kp, m) {
py::arg("workgroup") = kp::Workgroup(),
py::arg("spec_consts") = kp::Constants(),
py::arg("push_consts") = kp::Constants())
.def("get_device_properties", &kp::Manager::getDeviceProperties, "Return a struct containing information about the device");
py::class_<kp::DeviceProperties>(m, "DeviceProperties")
.def_readonly("device_name", &kp::DeviceProperties::deviceName)
.def_readonly("max_work_group_count", &kp::DeviceProperties::maxWorkGroupCount)
.def_readonly("max_work_group_invocations", &kp::DeviceProperties::maxWorkGroupInvocations)
.def_readonly("max_work_group_size", &kp::DeviceProperties::maxWorkGroupSize)
.def_readonly("timestamps_supported", &kp::DeviceProperties::timestampsSupported)
.def("__repr__", [](const kp::DeviceProperties &p) {
return "Device Name: " + p.deviceName + "\n"
+"Maximum Workgroup Count: " + std::to_string(p.maxWorkGroupCount[0]) + ", "
+ std::to_string(p.maxWorkGroupCount[1]) + ", "
+ std::to_string(p.maxWorkGroupCount[2]) + "\n"
+"Maximum Workgroup Invocations: " + std::to_string(p.maxWorkGroupInvocations) + "\n"
+"Maximum Workgroup Size: " + std::to_string(p.maxWorkGroupSize[0]) + ", "
+ std::to_string(p.maxWorkGroupSize[1]) + ", "
+ std::to_string(p.maxWorkGroupSize[2]) + "\n"
+"Timestamps Supported: " + (p.timestampsSupported? "True" : "False") + "\n";
});
.def("get_device_properties", [](kp::Manager& self){
const auto properties = self.getDeviceProperties();
py::dict py_props(
"device_name"_a = std::string(properties.deviceName.data()),
"max_work_group_count"_a = py::make_tuple(properties.limits.maxComputeWorkGroupCount[0],
properties.limits.maxComputeWorkGroupCount[1],
properties.limits.maxComputeWorkGroupCount[2]),
"max_work_group_invocations"_a = properties.limits.maxComputeWorkGroupInvocations,
"max_work_group_size"_a = py::make_tuple(properties.limits.maxComputeWorkGroupSize[0],
properties.limits.maxComputeWorkGroupSize[1],
properties.limits.maxComputeWorkGroupSize[2]),
"timestamps_supported"_a = (bool)properties.limits.timestampComputeAndGraphics
);
return py_props;
}, "Return a dict containing information about the device");
#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;