mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-16 04:28:57 +02:00
[common] replace Common::BitCast with libc++ provided one (#2774)
Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2774 Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: crueter <crueter@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
6ff043c4fb
commit
992bae4e2a
25 changed files with 152 additions and 151 deletions
|
|
@ -8,9 +8,9 @@
|
|||
#include <cmath>
|
||||
#include <span>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <bit>
|
||||
#include <numeric>
|
||||
#include "common/assert.h"
|
||||
#include "common/bit_cast.h"
|
||||
#include "video_core/engines/sw_blitter/converter.h"
|
||||
#include "video_core/surface.h"
|
||||
#include "video_core/textures/decoders.h"
|
||||
|
|
@ -696,21 +696,21 @@ private:
|
|||
return shifted_value >> shift_amount;
|
||||
};
|
||||
const auto force_to_fp16 = [](f32 base_value) {
|
||||
u32 tmp = Common::BitCast<u32>(base_value);
|
||||
u32 tmp = std::bit_cast<u32>(base_value);
|
||||
constexpr size_t fp32_mantissa_bits = 23;
|
||||
constexpr size_t fp16_mantissa_bits = 10;
|
||||
constexpr size_t mantissa_mask =
|
||||
~((1ULL << (fp32_mantissa_bits - fp16_mantissa_bits)) - 1ULL);
|
||||
tmp = tmp & static_cast<u32>(mantissa_mask);
|
||||
// TODO: force the exponent within the range of half float. Not needed in UNORM / SNORM
|
||||
return Common::BitCast<f32>(tmp);
|
||||
return std::bit_cast<f32>(tmp);
|
||||
};
|
||||
const auto from_fp_n = [&sign_extend](u32 base_value, size_t bits, size_t mantissa) {
|
||||
constexpr size_t fp32_mantissa_bits = 23;
|
||||
size_t shift_towards = fp32_mantissa_bits - mantissa;
|
||||
const u32 new_value =
|
||||
static_cast<u32>(sign_extend(base_value, bits) << shift_towards) & (~(1U << 31));
|
||||
return Common::BitCast<f32>(new_value);
|
||||
return std::bit_cast<f32>(new_value);
|
||||
};
|
||||
const auto calculate_snorm = [&]() {
|
||||
return static_cast<f32>(
|
||||
|
|
@ -740,11 +740,11 @@ private:
|
|||
out_component = force_to_fp16(out_component);
|
||||
} else if constexpr (component_types[which_component] == ComponentType::FLOAT) {
|
||||
if constexpr (component_sizes[which_component] == 32) {
|
||||
out_component = Common::BitCast<f32>(value);
|
||||
out_component = std::bit_cast<f32>(value);
|
||||
} else if constexpr (component_sizes[which_component] == 16) {
|
||||
static constexpr u32 sign_mask = 0x8000;
|
||||
static constexpr u32 mantissa_mask = 0x8000;
|
||||
out_component = Common::BitCast<f32>(((value & sign_mask) << 16) |
|
||||
out_component = std::bit_cast<f32>(((value & sign_mask) << 16) |
|
||||
(((value & 0x7c00) + 0x1C000) << 13) |
|
||||
((value & mantissa_mask) << 13));
|
||||
} else {
|
||||
|
|
@ -774,7 +774,7 @@ private:
|
|||
};
|
||||
const auto to_fp_n = [](f32 base_value, size_t bits, size_t mantissa) {
|
||||
constexpr size_t fp32_mantissa_bits = 23;
|
||||
u32 tmp_value = Common::BitCast<u32>((std::max)(base_value, 0.0f));
|
||||
u32 tmp_value = std::bit_cast<u32>((std::max)(base_value, 0.0f));
|
||||
size_t shift_towards = fp32_mantissa_bits - mantissa;
|
||||
return tmp_value >> shift_towards;
|
||||
};
|
||||
|
|
@ -802,13 +802,13 @@ private:
|
|||
insert_to_word(tmp_word);
|
||||
} else if constexpr (component_types[which_component] == ComponentType::FLOAT) {
|
||||
if constexpr (component_sizes[which_component] == 32) {
|
||||
u32 tmp_word = Common::BitCast<u32>(in_component);
|
||||
u32 tmp_word = std::bit_cast<u32>(in_component);
|
||||
insert_to_word(tmp_word);
|
||||
} else if constexpr (component_sizes[which_component] == 16) {
|
||||
static constexpr u32 sign_mask = 0x8000;
|
||||
static constexpr u32 mantissa_mask = 0x03ff;
|
||||
static constexpr u32 exponent_mask = 0x7c00;
|
||||
const u32 tmp_word = Common::BitCast<u32>(in_component);
|
||||
const u32 tmp_word = std::bit_cast<u32>(in_component);
|
||||
const u32 half = ((tmp_word >> 16) & sign_mask) |
|
||||
((((tmp_word & 0x7f800000) - 0x38000000) >> 13) & exponent_mask) |
|
||||
((tmp_word >> 13) & mantissa_mask);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cmath>
|
||||
#include <bit>
|
||||
#include "video_core/fsr.h"
|
||||
|
||||
namespace FSR {
|
||||
|
|
@ -95,7 +99,7 @@ u32 AU1_AH1_AF1(f32 f) {
|
|||
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
|
||||
0x18, 0x18,
|
||||
};
|
||||
const u32 u = Common::BitCast<u32>(f);
|
||||
const u32 u = std::bit_cast<u32>(f);
|
||||
const u32 i = u >> 23;
|
||||
return base[i] + ((u & 0x7fffff) >> shift[i]);
|
||||
}
|
||||
|
|
@ -107,20 +111,20 @@ u32 AU1_AH2_AF2(f32 a[2]) {
|
|||
void FsrEasuCon(u32 con0[4], u32 con1[4], u32 con2[4], u32 con3[4], f32 inputViewportInPixelsX,
|
||||
f32 inputViewportInPixelsY, f32 inputSizeInPixelsX, f32 inputSizeInPixelsY,
|
||||
f32 outputSizeInPixelsX, f32 outputSizeInPixelsY) {
|
||||
con0[0] = Common::BitCast<u32>(inputViewportInPixelsX / outputSizeInPixelsX);
|
||||
con0[1] = Common::BitCast<u32>(inputViewportInPixelsY / outputSizeInPixelsY);
|
||||
con0[2] = Common::BitCast<u32>(0.5f * inputViewportInPixelsX / outputSizeInPixelsX - 0.5f);
|
||||
con0[3] = Common::BitCast<u32>(0.5f * inputViewportInPixelsY / outputSizeInPixelsY - 0.5f);
|
||||
con1[0] = Common::BitCast<u32>(1.0f / inputSizeInPixelsX);
|
||||
con1[1] = Common::BitCast<u32>(1.0f / inputSizeInPixelsY);
|
||||
con1[2] = Common::BitCast<u32>(1.0f / inputSizeInPixelsX);
|
||||
con1[3] = Common::BitCast<u32>(-1.0f / inputSizeInPixelsY);
|
||||
con2[0] = Common::BitCast<u32>(-1.0f / inputSizeInPixelsX);
|
||||
con2[1] = Common::BitCast<u32>(2.0f / inputSizeInPixelsY);
|
||||
con2[2] = Common::BitCast<u32>(1.0f / inputSizeInPixelsX);
|
||||
con2[3] = Common::BitCast<u32>(2.0f / inputSizeInPixelsY);
|
||||
con3[0] = Common::BitCast<u32>(0.0f / inputSizeInPixelsX);
|
||||
con3[1] = Common::BitCast<u32>(4.0f / inputSizeInPixelsY);
|
||||
con0[0] = std::bit_cast<u32>(inputViewportInPixelsX / outputSizeInPixelsX);
|
||||
con0[1] = std::bit_cast<u32>(inputViewportInPixelsY / outputSizeInPixelsY);
|
||||
con0[2] = std::bit_cast<u32>(0.5f * inputViewportInPixelsX / outputSizeInPixelsX - 0.5f);
|
||||
con0[3] = std::bit_cast<u32>(0.5f * inputViewportInPixelsY / outputSizeInPixelsY - 0.5f);
|
||||
con1[0] = std::bit_cast<u32>(1.0f / inputSizeInPixelsX);
|
||||
con1[1] = std::bit_cast<u32>(1.0f / inputSizeInPixelsY);
|
||||
con1[2] = std::bit_cast<u32>(1.0f / inputSizeInPixelsX);
|
||||
con1[3] = std::bit_cast<u32>(-1.0f / inputSizeInPixelsY);
|
||||
con2[0] = std::bit_cast<u32>(-1.0f / inputSizeInPixelsX);
|
||||
con2[1] = std::bit_cast<u32>(2.0f / inputSizeInPixelsY);
|
||||
con2[2] = std::bit_cast<u32>(1.0f / inputSizeInPixelsX);
|
||||
con2[3] = std::bit_cast<u32>(2.0f / inputSizeInPixelsY);
|
||||
con3[0] = std::bit_cast<u32>(0.0f / inputSizeInPixelsX);
|
||||
con3[1] = std::bit_cast<u32>(4.0f / inputSizeInPixelsY);
|
||||
con3[2] = con3[3] = 0;
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
|
@ -131,16 +135,16 @@ void FsrEasuConOffset(u32 con0[4], u32 con1[4], u32 con2[4], u32 con3[4],
|
|||
f32 outputSizeInPixelsY, f32 inputOffsetInPixelsX, f32 inputOffsetInPixelsY) {
|
||||
FsrEasuCon(con0, con1, con2, con3, inputViewportInPixelsX, inputViewportInPixelsY,
|
||||
inputSizeInPixelsX, inputSizeInPixelsY, outputSizeInPixelsX, outputSizeInPixelsY);
|
||||
con0[2] = Common::BitCast<u32>(0.5f * inputViewportInPixelsX / outputSizeInPixelsX - 0.5f +
|
||||
con0[2] = std::bit_cast<u32>(0.5f * inputViewportInPixelsX / outputSizeInPixelsX - 0.5f +
|
||||
inputOffsetInPixelsX);
|
||||
con0[3] = Common::BitCast<u32>(0.5f * inputViewportInPixelsY / outputSizeInPixelsY - 0.5f +
|
||||
con0[3] = std::bit_cast<u32>(0.5f * inputViewportInPixelsY / outputSizeInPixelsY - 0.5f +
|
||||
inputOffsetInPixelsY);
|
||||
}
|
||||
|
||||
void FsrRcasCon(u32* con, f32 sharpness) {
|
||||
sharpness = std::exp2f(-sharpness);
|
||||
f32 hSharp[2]{sharpness, sharpness};
|
||||
con[0] = Common::BitCast<u32>(sharpness);
|
||||
con[0] = std::bit_cast<u32>(sharpness);
|
||||
con[1] = AU1_AH2_AF2(hSharp);
|
||||
con[2] = 0;
|
||||
con[3] = 0;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bit_cast.h"
|
||||
#include <numeric>
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace FSR {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <bit>
|
||||
#include <numeric>
|
||||
#include "common/cityhash.h"
|
||||
#include "common/settings.h" // for enum class Settings::ShaderBackend
|
||||
#include "video_core/renderer_opengl/gl_compute_pipeline.h"
|
||||
|
|
@ -229,8 +233,8 @@ void ComputePipeline::Configure() {
|
|||
}
|
||||
}
|
||||
if (info.uses_rescaling_uniform) {
|
||||
const f32 float_texture_scaling_mask{Common::BitCast<f32>(texture_scaling_mask)};
|
||||
const f32 float_image_scaling_mask{Common::BitCast<f32>(image_scaling_mask)};
|
||||
const f32 float_texture_scaling_mask{std::bit_cast<f32>(texture_scaling_mask)};
|
||||
const f32 float_image_scaling_mask{std::bit_cast<f32>(image_scaling_mask)};
|
||||
if (assembly_program.handle != 0) {
|
||||
glProgramLocalParameter4fARB(GL_COMPUTE_PROGRAM_NV, 0, float_texture_scaling_mask,
|
||||
float_image_scaling_mask, 0.0f, 0.0f);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
#include <array>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <bit>
|
||||
#include <numeric>
|
||||
#include "common/settings.h" // for enum class Settings::ShaderBackend
|
||||
#include "common/thread_worker.h"
|
||||
#include "shader_recompiler/shader_info.h"
|
||||
|
|
@ -511,8 +512,8 @@ bool GraphicsPipeline::ConfigureImpl(bool is_indexed) {
|
|||
}
|
||||
}
|
||||
if (info.uses_rescaling_uniform) {
|
||||
const f32 float_texture_scaling_mask{Common::BitCast<f32>(texture_scaling_mask)};
|
||||
const f32 float_image_scaling_mask{Common::BitCast<f32>(image_scaling_mask)};
|
||||
const f32 float_texture_scaling_mask{std::bit_cast<f32>(texture_scaling_mask)};
|
||||
const f32 float_image_scaling_mask{std::bit_cast<f32>(image_scaling_mask)};
|
||||
const bool is_rescaling{texture_cache.IsRescaling()};
|
||||
const f32 config_down_factor{Settings::values.resolution_info.down_factor};
|
||||
const f32 down_factor{is_rescaling ? config_down_factor : 1.0f};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "common/bit_cast.h"
|
||||
#include <bit>
|
||||
#include <numeric>
|
||||
#include <ranges>
|
||||
#include "common/cityhash.h"
|
||||
#include "common/common_types.h"
|
||||
#include <ranges>
|
||||
#include "video_core/engines/draw_manager.h"
|
||||
#include "video_core/renderer_vulkan/fixed_pipeline_state.h"
|
||||
#include "video_core/renderer_vulkan/vk_state_tracker.h"
|
||||
|
|
@ -98,8 +98,8 @@ void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d, DynamicFe
|
|||
for (size_t i = 0; i < regs.rt.size(); ++i) {
|
||||
color_formats[i] = static_cast<u8>(regs.rt[i].format);
|
||||
}
|
||||
alpha_test_ref = Common::BitCast<u32>(regs.alpha_test_ref);
|
||||
point_size = Common::BitCast<u32>(regs.point_size);
|
||||
alpha_test_ref = std::bit_cast<u32>(regs.alpha_test_ref);
|
||||
point_size = std::bit_cast<u32>(regs.point_size);
|
||||
|
||||
if (maxwell3d.dirty.flags[Dirty::VertexInput]) {
|
||||
if (features.has_dynamic_vertex_input) {
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
#include <memory>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "common/bit_cast.h"
|
||||
#include <bit>
|
||||
#include <numeric>
|
||||
#include "common/cityhash.h"
|
||||
#include "common/fs/fs.h"
|
||||
#include "common/fs/path_util.h"
|
||||
|
|
@ -160,7 +160,7 @@ Shader::RuntimeInfo MakeRuntimeInfo(std::span<const Shader::IR::Program> program
|
|||
const Shader::Stage stage{program.stage};
|
||||
const bool has_geometry{key.unique_hashes[4] != 0 && !programs[4].is_geometry_passthrough};
|
||||
const bool gl_ndc{key.state.ndc_minus_one_to_one != 0};
|
||||
const float point_size{Common::BitCast<float>(key.state.point_size)};
|
||||
const float point_size{std::bit_cast<float>(key.state.point_size)};
|
||||
switch (stage) {
|
||||
case Shader::Stage::VertexB:
|
||||
if (!has_geometry) {
|
||||
|
|
@ -228,7 +228,7 @@ Shader::RuntimeInfo MakeRuntimeInfo(std::span<const Shader::IR::Program> program
|
|||
case Shader::Stage::Fragment:
|
||||
info.alpha_test_func = MaxwellToCompareFunction(
|
||||
key.state.UnpackComparisonOp(key.state.alpha_test_func.Value()));
|
||||
info.alpha_test_reference = Common::BitCast<float>(key.state.alpha_test_ref);
|
||||
info.alpha_test_reference = std::bit_cast<float>(key.state.alpha_test_ref);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
#include "common/bit_cast.h"
|
||||
#include <bit>
|
||||
#include <numeric>
|
||||
#include "common/bit_util.h"
|
||||
#include "common/settings.h"
|
||||
|
||||
|
|
@ -2216,7 +2216,7 @@ Sampler::Sampler(TextureCacheRuntime& runtime, const Tegra::Texture::TSCEntry& t
|
|||
.sType = VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT,
|
||||
.pNext = nullptr,
|
||||
// TODO: Make use of std::bit_cast once libc++ supports it.
|
||||
.customBorderColor = Common::BitCast<VkClearColorValue>(color),
|
||||
.customBorderColor = std::bit_cast<VkClearColorValue>(color),
|
||||
.format = VK_FORMAT_UNDEFINED,
|
||||
};
|
||||
const void* pnext = nullptr;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -6,7 +9,7 @@
|
|||
#include <algorithm>
|
||||
#include <span>
|
||||
|
||||
#include "common/bit_cast.h"
|
||||
#include <numeric>
|
||||
#include "video_core/texture_cache/types.h"
|
||||
|
||||
namespace VideoCommon {
|
||||
|
|
@ -41,8 +44,8 @@ struct hash<VideoCommon::RenderTargets> {
|
|||
for (const ImageViewId color_buffer_id : rt.color_buffer_ids) {
|
||||
value ^= std::hash<ImageViewId>{}(color_buffer_id);
|
||||
}
|
||||
value ^= Common::BitCast<u64>(rt.draw_buffers);
|
||||
value ^= Common::BitCast<u64>(rt.size);
|
||||
value ^= std::bit_cast<u64>(rt.draw_buffers);
|
||||
value ^= std::bit_cast<u64>(rt.size);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue