mirror of
https://github.com/yuzu-emu/sirit.git
synced 2024-12-23 00:35:38 +00:00
Fix build errors on gcc
This commit is contained in:
parent
0b9ee36247
commit
634428758b
30
src/stream.h
30
src/stream.h
|
@ -15,6 +15,10 @@
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef __cpp_lib_bit_cast
|
||||||
|
#include <cstring>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <spirv/unified1/spirv.hpp>
|
#include <spirv/unified1/spirv.hpp>
|
||||||
|
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
|
@ -24,8 +28,8 @@ namespace Sirit {
|
||||||
class Declarations;
|
class Declarations;
|
||||||
|
|
||||||
struct OpId {
|
struct OpId {
|
||||||
spv::Op opcode;
|
spv::Op opcode{};
|
||||||
Id result_type;
|
Id result_type{};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EndOp {};
|
struct EndOp {};
|
||||||
|
@ -38,7 +42,7 @@ inline void InsertStringView(std::vector<u32>& words, size_t& insert_index,
|
||||||
std::string_view string) {
|
std::string_view string) {
|
||||||
const size_t size = string.size();
|
const size_t size = string.size();
|
||||||
const auto read = [string, size](size_t offset) {
|
const auto read = [string, size](size_t offset) {
|
||||||
return offset < size ? static_cast<u8>(string[offset]) : u8(0);
|
return offset < size ? static_cast<u32>(string[offset]) : 0u;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < size; i += sizeof(u32)) {
|
for (size_t i = 0; i < size; i += sizeof(u32)) {
|
||||||
|
@ -106,11 +110,25 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream& operator<<(float value) {
|
Stream& operator<<(float value) {
|
||||||
|
#ifdef __cpp_lib_bit_cast
|
||||||
return *this << std::bit_cast<u32>(value);
|
return *this << std::bit_cast<u32>(value);
|
||||||
|
#else
|
||||||
|
static_assert(sizeof(float) == sizeof(u32));
|
||||||
|
u32 int_value;
|
||||||
|
std::memcpy(&int_value, &value, sizeof(int_value));
|
||||||
|
return *this << int_value;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream& operator<<(double value) {
|
Stream& operator<<(double value) {
|
||||||
|
#ifdef __cpp_lib_bit_cast
|
||||||
return *this << std::bit_cast<u64>(value);
|
return *this << std::bit_cast<u64>(value);
|
||||||
|
#else
|
||||||
|
static_assert(sizeof(double) == sizeof(u64));
|
||||||
|
u64 int_value;
|
||||||
|
std::memcpy(&int_value, &value, sizeof(int_value));
|
||||||
|
return *this << int_value;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream& operator<<(bool value) {
|
Stream& operator<<(bool value) {
|
||||||
|
@ -131,6 +149,10 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Stream& operator<<(const char* string) {
|
||||||
|
return *this << std::string_view{string};
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
requires std::is_enum_v<T> Stream& operator<<(T value) {
|
requires std::is_enum_v<T> Stream& operator<<(T value) {
|
||||||
static_assert(sizeof(T) == sizeof(u32));
|
static_assert(sizeof(T) == sizeof(u32));
|
||||||
|
@ -188,7 +210,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Id operator<<(EndOp) {
|
Id operator<<(EndOp) {
|
||||||
const auto begin = stream.words.begin();
|
const auto begin = stream.words.data();
|
||||||
std::vector<u32> declarations(begin + stream.op_index, begin + stream.insert_index);
|
std::vector<u32> declarations(begin + stream.op_index, begin + stream.insert_index);
|
||||||
|
|
||||||
// Normalize result id for lookups
|
// Normalize result id for lookups
|
||||||
|
|
Loading…
Reference in a new issue