ostream: add some trivial ostream operators
This commit is contained in:
parent
7850699178
commit
2c0f3f4df4
@ -69,6 +69,8 @@ list (APPEND sources
|
||||
instance.hpp
|
||||
image.cpp
|
||||
image.hpp
|
||||
ostream.cpp
|
||||
ostream.hpp
|
||||
physical_device.cpp
|
||||
physical_device.hpp
|
||||
pipeline.cpp
|
||||
|
136
ostream.cpp
Normal file
136
ostream.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright:
|
||||
* 2017, Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#include "./ostream.hpp"
|
||||
|
||||
#include "./instance.hpp"
|
||||
#include "./physical_device.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <cruft/util/iterator.hpp>
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static
|
||||
std::ostream&
|
||||
write_version (std::ostream &os, uint32_t version)
|
||||
{
|
||||
static constexpr uint32_t MAJOR_BITS = 10;
|
||||
static constexpr uint32_t MINOR_BITS = 10;
|
||||
static constexpr uint32_t PATCH_BITS = 12;
|
||||
static_assert (MAJOR_BITS + MINOR_BITS + PATCH_BITS == sizeof (version) * 8);
|
||||
|
||||
uint32_t major, minor, patch;
|
||||
|
||||
patch = version & ((1 << PATCH_BITS) - 1); version >>= PATCH_BITS;
|
||||
minor = version & ((1 << MINOR_BITS) - 1); version >>= MINOR_BITS;
|
||||
major = version & ((1 << MAJOR_BITS) - 1); version >>= MAJOR_BITS;
|
||||
|
||||
return os << +major << '.' << +minor << '.' << +patch;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::ostream&
|
||||
cruft::vk::operator<< (std::ostream &os, const instance &i)
|
||||
{
|
||||
os << "{ extensions: [ ";
|
||||
|
||||
const auto &extensions = i.extensions ();
|
||||
std::copy (std::cbegin (extensions),
|
||||
std::cend (extensions),
|
||||
util::infix_iterator<std::string> (os, ", "));
|
||||
|
||||
return os << " ] }";
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::ostream&
|
||||
operator<< (std::ostream &os, VkPhysicalDeviceType t)
|
||||
{
|
||||
switch (t) {
|
||||
case VK_PHYSICAL_DEVICE_TYPE_OTHER: return os << "other";
|
||||
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: return os << "integrated-gpu";
|
||||
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: return os << "discrete-gpu";
|
||||
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: return os << "virtual-gpu";
|
||||
case VK_PHYSICAL_DEVICE_TYPE_CPU: return os << "cpu";
|
||||
}
|
||||
|
||||
return os << "unknown-" << +static_cast<std::underlying_type_t<decltype(t)>> (t);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::ostream&
|
||||
operator<< (std::ostream &os, const VkPhysicalDeviceLimits &l)
|
||||
{
|
||||
return os
|
||||
<< "{ max_image: [ " << l.maxImageDimension1D
|
||||
<< ", " << l.maxImageDimension2D
|
||||
<< ", " << l.maxImageDimension3D
|
||||
<< " ]"
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::ostream&
|
||||
operator<< (std::ostream &os, const VkPhysicalDeviceProperties &p)
|
||||
{
|
||||
os << "{ api: "; write_version (os, p.apiVersion);
|
||||
os << ", driver: "; write_version (os, p.driverVersion);
|
||||
os << ", vendor: 0x" << std::hex << std::setw (4) << std::setfill ('0') << p.vendorID << std::dec;
|
||||
os << ", device: 0x" << std::hex << std::setw (4) << std::setfill ('0') << p.deviceID << std::dec;
|
||||
os << ", name: '" << p.deviceName << "'";
|
||||
os << ", type: " << p.deviceType;
|
||||
os << ", limits: " << p.limits;
|
||||
os << " }";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::ostream&
|
||||
operator<< (std::ostream &os, const VkPhysicalDeviceFeatures &f)
|
||||
{
|
||||
os << "[ ";
|
||||
if (f.geometryShader) os << "GEOMETRY_SHADER ";
|
||||
return os << "]";
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::ostream&
|
||||
cruft::vk::operator<< (std::ostream &os, const physical_device &d)
|
||||
{
|
||||
os << "physical_device { ";
|
||||
|
||||
os << "extensions: [ ";
|
||||
const auto &extensions = d.extensions ();
|
||||
std::copy (std::cbegin (extensions),
|
||||
std::cend (extensions),
|
||||
util::infix_iterator<std::string> (os, ", "));
|
||||
os << " ], ";
|
||||
|
||||
os << " properties: " << d.properties ()
|
||||
<< ", features: " << d.features ()
|
||||
<< " }";
|
||||
|
||||
return os;
|
||||
}
|
38
ostream.hpp
Normal file
38
ostream.hpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright:
|
||||
* 2017, Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_VK_OSTREAM_HPP
|
||||
#define CRUFT_VK_OSTREAM_HPP
|
||||
|
||||
#include "./fwd.hpp"
|
||||
#include "./vk.hpp"
|
||||
|
||||
#include <cruft/util/preprocessor.hpp>
|
||||
|
||||
#include <ostream>
|
||||
|
||||
std::ostream& operator<< (std::ostream&, VkPhysicalDeviceType);
|
||||
std::ostream& operator<< (std::ostream&, const VkPhysicalDeviceLimits&);
|
||||
std::ostream& operator<< (std::ostream&, const VkPhysicalDeviceProperties&);
|
||||
|
||||
namespace cruft::vk {
|
||||
#define CRUFT_VK_OSTREAM(T) std::ostream& operator<< (std::ostream&, const cruft::vk::T&);
|
||||
VK_TYPE_MAP (CRUFT_VK_OSTREAM)
|
||||
#undef CRUFT_VK_OSTREAM
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user