mirror of
https://github.com/yuzu-emu/sirit
synced 2024-11-22 11:53:43 +00:00
Fix build errors on gcc
This commit is contained in:
parent
0b9ee36247
commit
634428758b
1 changed files with 26 additions and 4 deletions
30
src/stream.h
30
src/stream.h
|
@ -15,6 +15,10 @@
|
|||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#ifndef __cpp_lib_bit_cast
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
#include <spirv/unified1/spirv.hpp>
|
||||
|
||||
#include "common_types.h"
|
||||
|
@ -24,8 +28,8 @@ namespace Sirit {
|
|||
class Declarations;
|
||||
|
||||
struct OpId {
|
||||
spv::Op opcode;
|
||||
Id result_type;
|
||||
spv::Op opcode{};
|
||||
Id result_type{};
|
||||
};
|
||||
|
||||
struct EndOp {};
|
||||
|
@ -38,7 +42,7 @@ inline void InsertStringView(std::vector<u32>& words, size_t& insert_index,
|
|||
std::string_view string) {
|
||||
const size_t size = string.size();
|
||||
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)) {
|
||||
|
@ -106,11 +110,25 @@ public:
|
|||
}
|
||||
|
||||
Stream& operator<<(float value) {
|
||||
#ifdef __cpp_lib_bit_cast
|
||||
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) {
|
||||
#ifdef __cpp_lib_bit_cast
|
||||
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) {
|
||||
|
@ -131,6 +149,10 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
Stream& operator<<(const char* string) {
|
||||
return *this << std::string_view{string};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_enum_v<T> Stream& operator<<(T value) {
|
||||
static_assert(sizeof(T) == sizeof(u32));
|
||||
|
@ -188,7 +210,7 @@ public:
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
// Normalize result id for lookups
|
||||
|
|
Loading…
Reference in a new issue