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;

View file

@ -1949,21 +1949,6 @@ class Sequence : public std::enable_shared_from_this<Sequence>
namespace kp {
struct DeviceProperties
{
//Name of the device
const std::string deviceName;
//Maximum number of workgroups that can be dispatched per shader
const std::array<uint32_t,3> maxWorkGroupCount;
//Maximum number of shader invocations per local workgroup
//i.e. the product of maxWorkGroupSize must not exceed this value
const uint32_t maxWorkGroupInvocations;
//Maximum number of shader invocations per local workgroup
const std::array<uint32_t,3> maxWorkGroupSize;
//Whether timestamping is supported by this device or not
const bool timestampsSupported;
};
/**
Base orchestrator which creates and manages device and child components
*/
@ -2109,7 +2094,7 @@ class Manager
/**
* Return a struct containing information about the device.
**/
DeviceProperties getDeviceProperties() const;
vk::PhysicalDeviceProperties getDeviceProperties() const;
private:
// -------------- OPTIONALLY OWNED RESOURCES

View file

@ -447,17 +447,10 @@ Manager::sequence(uint32_t queueIndex, uint32_t totalTimestamps)
return sq;
}
DeviceProperties Manager::getDeviceProperties() const
vk::PhysicalDeviceProperties
Manager::getDeviceProperties() const
{
const vk::PhysicalDeviceProperties properties = this->mPhysicalDevice->getProperties();
const DeviceProperties output{
std::string(properties.deviceName.data()),
properties.limits.maxComputeWorkGroupCount,
properties.limits.maxComputeWorkGroupInvocations,
properties.limits.maxComputeWorkGroupSize,
properties.limits.timestampComputeAndGraphics,
};
return output;
return this->mPhysicalDevice->getProperties();
}
}

View file

@ -11,23 +11,6 @@
namespace kp {
struct DeviceProperties
{
//Name of the device
const std::string deviceName;
//Maximum number of workgroups that can be dispatched per shader
const std::array<uint32_t,3> maxWorkGroupCount;
//Maximum number of shader invocations per local workgroup
//i.e. the product of maxWorkGroupSize must not exceed this value
const uint32_t maxWorkGroupInvocations;
//Maximum number of shader invocations per local workgroup
const std::array<uint32_t,3> maxWorkGroupSize;
//Whether timestamping is supported by this device or not
const bool timestampsSupported;
};
/**
Base orchestrator which creates and manages device and child components
*/
@ -173,7 +156,7 @@ class Manager
/**
* Return a struct containing information about the device.
**/
DeviceProperties getDeviceProperties() const;
vk::PhysicalDeviceProperties getDeviceProperties() const;
private:
// -------------- OPTIONALLY OWNED RESOURCES
@ -207,5 +190,4 @@ class Manager
const std::vector<std::string>& desiredExtensions = {});
};
} // End namespace kp

View file

@ -67,6 +67,5 @@ TEST(TestManager, TestDeviceProperties)
{
kp::Manager mgr;
const auto properties = mgr.getDeviceProperties();
EXPECT_GT(properties.deviceName.size(), 0);
}