From 5dc644edb40bad03a2a18baf59c8b6d5f4a28c8b Mon Sep 17 00:00:00 2001 From: nmzik Date: Thu, 17 Sep 2026 19:50:21 +0400 Subject: [PATCH] clean up graphics helpers --- .../pipeline/shaderResourceBarrier.cpp | 12 ++--- .../renderer/pipeline/shaderResourceBarrier.h | 6 +-- .../host_gpu/renderer/renderCompute.cpp | 2 +- src/graphics/host_gpu/renderer/renderDraw.cpp | 4 +- src/graphics/host_gpu/vulkanCommon.h | 2 - .../presentation/window/swapchain.cpp | 3 -- .../presentation/window/vulkanWindow.cpp | 1 - src/graphics/presentation/window/window.cpp | 22 +++------- .../shader/recompiler/ShaderRecompiler.cpp | 13 +++--- .../backend/spirv/spirvEmitterInternal.h | 2 - .../backend/spirv/spirvEmitterModule.cpp | 9 +--- .../recompiler/frontend/decode/ImageOps.cpp | 27 +++--------- .../frontend/decode/ShaderDecoder.cpp | 8 +--- .../frontend/decode/VectorAluOps.cpp | 8 +--- .../shader/recompiler/ir/passes/SrtWalker.cpp | 10 ++--- src/graphics/shader/rectListShader.cpp | 44 +++++++------------ src/graphics/shader/shader.cpp | 4 -- src/graphics/shader/shader.h | 1 - 18 files changed, 57 insertions(+), 121 deletions(-) diff --git a/src/graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.cpp b/src/graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.cpp index f3a86a21c..4370aed19 100644 --- a/src/graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.cpp +++ b/src/graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.cpp @@ -46,8 +46,8 @@ vk::PipelineStageFlags ShaderPipelineStages(vk::ShaderStageFlags stages) { return result; } -VulkanMemoryBarrier MakeShaderWriteDependency() { - VulkanMemoryBarrier barrier {}; +vk::MemoryBarrier MakeShaderWriteDependency() { + vk::MemoryBarrier barrier {}; barrier.srcAccessMask = vk::AccessFlagBits::eShaderWrite; barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite | vk::AccessFlagBits::eVertexAttributeRead | @@ -58,15 +58,15 @@ VulkanMemoryBarrier MakeShaderWriteDependency() { return barrier; } -VulkanMemoryBarrier MakeShaderAccessDependency() { - VulkanMemoryBarrier barrier {}; +vk::MemoryBarrier MakeShaderAccessDependency() { + vk::MemoryBarrier barrier {}; barrier.srcAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite; barrier.dstAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite; return barrier; } -VulkanMemoryBarrier MakeShaderWriteHazardDependency() { - VulkanMemoryBarrier barrier {}; +vk::MemoryBarrier MakeShaderWriteHazardDependency() { + vk::MemoryBarrier barrier {}; barrier.srcAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite; barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite; return barrier; diff --git a/src/graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.h b/src/graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.h index 47d6e5117..23eb75907 100644 --- a/src/graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.h +++ b/src/graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.h @@ -10,9 +10,9 @@ struct ShaderStageRuntime; vk::ShaderStageFlagBits NativeShaderStage(ShaderType stage); vk::PipelineStageFlags ShaderPipelineStages(vk::ShaderStageFlags stages); -VulkanMemoryBarrier MakeShaderAccessDependency(); -VulkanMemoryBarrier MakeShaderWriteHazardDependency(); -VulkanMemoryBarrier MakeShaderWriteDependency(); +vk::MemoryBarrier MakeShaderAccessDependency(); +vk::MemoryBarrier MakeShaderWriteHazardDependency(); +vk::MemoryBarrier MakeShaderWriteDependency(); vk::BufferMemoryBarrier MakeGdsDependency(vk::Buffer buffer); bool HasShaderBufferWrites(const ShaderStageRuntime& runtime); void ShaderAccessBarrier(vk::CommandBuffer vk_buffer, vk::PipelineStageFlags source_stages); diff --git a/src/graphics/host_gpu/renderer/renderCompute.cpp b/src/graphics/host_gpu/renderer/renderCompute.cpp index fdd358caa..1ef9ee345 100644 --- a/src/graphics/host_gpu/renderer/renderCompute.cpp +++ b/src/graphics/host_gpu/renderer/renderCompute.cpp @@ -225,7 +225,7 @@ void RenderExecutor::DispatchDirect(uint64_t submit_id, CommandBuffer& buffer, return; } - if (!ShaderAddressValid(sh_ctx.GetCs().cs_regs.data_addr)) { + if (sh_ctx.GetCs().cs_regs.data_addr == 0) { return; } diff --git a/src/graphics/host_gpu/renderer/renderDraw.cpp b/src/graphics/host_gpu/renderer/renderDraw.cpp index 983afc3e8..e3ce74d81 100644 --- a/src/graphics/host_gpu/renderer/renderDraw.cpp +++ b/src/graphics/host_gpu/renderer/renderDraw.cpp @@ -421,7 +421,7 @@ static void SetGraphicsDynamicParams(const CommandBuffer& buffer, vk::CommandBuf static bool DrawHasValidVertexShader(const HW::Shader& sh_ctx) { const auto& vs = sh_ctx.GetVs(); - return ShaderAddressValid(vs.es_regs.data_addr); + return vs.es_regs.data_addr != 0; } static bool PixelShaderHasDepthOrCoverageSideEffects(const HW::ShaderRegisters& sh_regs) { @@ -608,7 +608,7 @@ static bool DrawHasActivePixelShader(const CommandBuffer& buffer) { const auto& ctx = buffer.GetRegisters(); const auto& sh_regs = ctx.GetShaderRegisters(); const bool has_color_output = (ctx.GetRenderTargetMask() & sh_regs.m_cbShaderMask) != 0; - return ShaderAddressValid(buffer.GetShaders().GetPs().ps_regs.data_addr) && + return buffer.GetShaders().GetPs().ps_regs.data_addr != 0 && (has_color_output || PixelShaderHasDepthOrCoverageSideEffects(sh_regs)); } diff --git a/src/graphics/host_gpu/vulkanCommon.h b/src/graphics/host_gpu/vulkanCommon.h index bcf978832..f735d8ab2 100644 --- a/src/graphics/host_gpu/vulkanCommon.h +++ b/src/graphics/host_gpu/vulkanCommon.h @@ -24,8 +24,6 @@ namespace Libs::Graphics { -using VulkanMemoryBarrier = vk::MemoryBarrier; - vk::Format VulkanFormat(Prospero::BufferFormat guest_format); void RequireVulkanSuccess(vk::Result result, const char* operation); vk::ShaderModule CompileSPV(std::span code, vk::Device device); diff --git a/src/graphics/presentation/window/swapchain.cpp b/src/graphics/presentation/window/swapchain.cpp index 166d77216..cf7ae99f7 100644 --- a/src/graphics/presentation/window/swapchain.cpp +++ b/src/graphics/presentation/window/swapchain.cpp @@ -22,9 +22,6 @@ // IWYU pragma: no_include -#define KYTY_ENABLE_DEBUG_PRINTF -#define KYTY_DBG_INPUT - namespace Libs::Graphics { struct Presenter::Frame { diff --git a/src/graphics/presentation/window/vulkanWindow.cpp b/src/graphics/presentation/window/vulkanWindow.cpp index b5adbc83b..2f2c8a87b 100644 --- a/src/graphics/presentation/window/vulkanWindow.cpp +++ b/src/graphics/presentation/window/vulkanWindow.cpp @@ -49,7 +49,6 @@ // IWYU pragma: no_include #define KYTY_ENABLE_DEBUG_PRINTF -#define KYTY_DBG_INPUT namespace Libs::Graphics { diff --git a/src/graphics/presentation/window/window.cpp b/src/graphics/presentation/window/window.cpp index 6aae9b25b..593dc71e6 100644 --- a/src/graphics/presentation/window/window.cpp +++ b/src/graphics/presentation/window/window.cpp @@ -52,7 +52,6 @@ // IWYU pragma: no_include -#define KYTY_ENABLE_DEBUG_PRINTF #define KYTY_DBG_INPUT namespace Libs::Graphics { @@ -180,12 +179,6 @@ struct EventDisplay { DisplayOrientation orientation; }; -constexpr uint32_t KYTY_SDL_BUTTON_LMASK = SDL_BUTTON_LMASK; // NOLINT(hicpp-signed-bitwise) -constexpr uint32_t KYTY_SDL_BUTTON_MMASK = SDL_BUTTON_MMASK; // NOLINT(hicpp-signed-bitwise) -constexpr uint32_t KYTY_SDL_BUTTON_RMASK = SDL_BUTTON_RMASK; // NOLINT(hicpp-signed-bitwise) -constexpr uint32_t KYTY_SDL_BUTTON_X1MASK = SDL_BUTTON_X1MASK; // NOLINT(hicpp-signed-bitwise) -constexpr uint32_t KYTY_SDL_BUTTON_X2MASK = SDL_BUTTON_X2MASK; // NOLINT(hicpp-signed-bitwise) - namespace { std::unique_ptr g_window; @@ -193,7 +186,6 @@ std::unique_ptr g_window; } // namespace constexpr const char* KYTY_SDL_WINDOW_CAPTION = "Game"; -constexpr int KYTY_SDL_WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED; /*NOLINT(hicpp-signed-bitwise)*/ static void SetPause(WindowLoopState& game, bool flag) { LOGF("Pause: %s\n", flag ? "true" : "false"); @@ -614,11 +606,11 @@ void WindowContext::ProcessEvent(double time_s) { mb.down = false; mb.up = false; - mb.left = ((event->motion.state & KYTY_SDL_BUTTON_LMASK) != 0u); - mb.middle = ((event->motion.state & KYTY_SDL_BUTTON_MMASK) != 0u); - mb.right = ((event->motion.state & KYTY_SDL_BUTTON_RMASK) != 0u); - mb.x1 = ((event->motion.state & KYTY_SDL_BUTTON_X1MASK) != 0u); - mb.x2 = ((event->motion.state & KYTY_SDL_BUTTON_X2MASK) != 0u); + mb.left = ((event->motion.state & SDL_BUTTON_LMASK) != 0u); + mb.middle = ((event->motion.state & SDL_BUTTON_MMASK) != 0u); + mb.right = ((event->motion.state & SDL_BUTTON_RMASK) != 0u); + mb.x1 = ((event->motion.state & SDL_BUTTON_X1MASK) != 0u); + mb.x2 = ((event->motion.state & SDL_BUTTON_X2MASK) != 0u); mb.touch = (event->motion.which == SDL_TOUCH_MOUSEID); mb.pressed = false; mb.released = false; @@ -868,8 +860,8 @@ static void WindowCreate(WindowContext& context) { window_flags |= static_cast(SDL_WINDOW_BORDERLESS); } #endif - context.window = SDL_CreateWindow(KYTY_SDL_WINDOW_CAPTION, KYTY_SDL_WINDOWPOS_CENTERED, - KYTY_SDL_WINDOWPOS_CENTERED, width, height, window_flags); + context.window = SDL_CreateWindow(KYTY_SDL_WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, width, height, window_flags); if (context.window == nullptr) { EXIT("%s\n", SDL_GetError()); diff --git a/src/graphics/shader/recompiler/ShaderRecompiler.cpp b/src/graphics/shader/recompiler/ShaderRecompiler.cpp index dee56e426..f676c7378 100644 --- a/src/graphics/shader/recompiler/ShaderRecompiler.cpp +++ b/src/graphics/shader/recompiler/ShaderRecompiler.cpp @@ -105,8 +105,6 @@ void ClearEmbeddedFetchVectorLanes(EmbeddedFetchVectorLanes* lanes, uint32_t reg lanes->erase(first, last); } -using EmbeddedFetchData = Frontend::EmbeddedFetchPlan; - bool IsDecodedSgpr(const Decoder::Operand& op) { return op.kind == Decoder::OperandKind::Sgpr || op.kind == Decoder::OperandKind::VccLo || op.kind == Decoder::OperandKind::VccHi; @@ -210,13 +208,12 @@ int BufferTableAttribFromOffset(uint32_t raw_offset, int dword) { return static_cast((raw_offset + static_cast(dword) * 4u) / 16u); } -EmbeddedFetchData DetectEmbeddedVertexFetch(const Decoder::Program& decoded, - const ShaderVertexInputInfo* input_info, - uint32_t user_data_base, uint32_t user_data_count, - uint32_t wave_size) { +Frontend::EmbeddedFetchPlan DetectEmbeddedVertexFetch( + const Decoder::Program& decoded, const ShaderVertexInputInfo* input_info, + uint32_t user_data_base, uint32_t user_data_count, uint32_t wave_size) { const uint32_t vertex_index_reg = input_info->logical_stage == ShaderType::Local ? 2u : 5u; const uint32_t instance_index_reg = input_info->logical_stage == ShaderType::Local ? 5u : 8u; - EmbeddedFetchData data; + Frontend::EmbeddedFetchPlan data; data.loads.reserve(input_info->resources_num); int32_t vertex_offset_candidate = -1; int32_t instance_offset_candidate = -1; @@ -560,7 +557,7 @@ TranslateResult TranslateProgram(std::span code, const CompileOp static_cast(cfg.natural_loops.size()), phase_ms()); } - EmbeddedFetchData embedded_fetch; + Frontend::EmbeddedFetchPlan embedded_fetch; if ((options.stage == ShaderType::Vertex || options.stage == ShaderType::Local) && options.input_info.vertex != nullptr && options.input_info.vertex->fetch_embedded) { embedded_fetch = DetectEmbeddedVertexFetch( diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h index b6b6d9b3b..8af6afcf1 100644 --- a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h +++ b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h @@ -308,8 +308,6 @@ uint32_t ConstantI32(EmitterState& state, int32_t value); uint32_t ConstantF32(EmitterState& state, uint32_t bits); -uint32_t FloatBits(float value); - uint32_t ConstantF32Value(EmitterState& state, float value); uint32_t ConstantBool(EmitterState& state, bool value); diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp index cdfab42ae..7f8fb1c90 100644 --- a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp +++ b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp @@ -1,6 +1,7 @@ #include "graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h" #include +#include namespace Libs::Graphics::ShaderRecompiler::Spirv::Emitter { @@ -256,14 +257,8 @@ uint32_t ConstantF32(EmitterState& state, uint32_t bits) { return state.builder.Constant(spv::OpConstant, TypeF32(state), bits); } -uint32_t FloatBits(float value) { - uint32_t bits = 0; - std::memcpy(&bits, &value, sizeof(bits)); - return bits; -} - uint32_t ConstantF32Value(EmitterState& state, float value) { - return ConstantF32(state, FloatBits(value)); + return ConstantF32(state, std::bit_cast(value)); } uint32_t ConstantBool(EmitterState& state, bool value) { diff --git a/src/graphics/shader/recompiler/frontend/decode/ImageOps.cpp b/src/graphics/shader/recompiler/frontend/decode/ImageOps.cpp index 932df888a..831c677d1 100644 --- a/src/graphics/shader/recompiler/frontend/decode/ImageOps.cpp +++ b/src/graphics/shader/recompiler/frontend/decode/ImageOps.cpp @@ -3,6 +3,7 @@ #include "graphics/shader/recompiler/frontend/decode/OpcodeTable.h" #include +#include namespace Libs::Graphics::ShaderRecompiler::Decoder { namespace { @@ -203,18 +204,6 @@ constexpr auto MIMG_SAMPLE_OPS = Detail::MakeOpcodeTable<0x100>(MIMG_SAMPLE_OPCO constexpr auto MIMG_GATHER_OPS = Detail::MakeOpcodeTable<0x100>(MIMG_GATHER_OPCODE_LIST); constexpr auto MIMG_ATOMIC_OPS = Detail::MakeOpcodeTable<0x100>(MIMG_ATOMIC_OPCODE_LIST); -const MimgSampleInfo* LookupSample(uint32_t opcode) { - return Detail::FindOpcode(MIMG_SAMPLE_OPS, opcode); -} - -const MimgGatherInfo* LookupGather(uint32_t opcode) { - return Detail::FindOpcode(MIMG_GATHER_OPS, opcode); -} - -const Detail::OpcodeMap* LookupAtomic(uint32_t opcode) { - return Detail::FindOpcode(MIMG_ATOMIC_OPS, opcode); -} - Opcode DecodeMimgOpcode(uint32_t opcode, const MimgSampleInfo* sample, const MimgGatherInfo* gather, const Detail::OpcodeMap* atomic) { if (sample != nullptr) { @@ -280,10 +269,6 @@ uint32_t CountDmaskComponents(uint32_t dmask) { return count != 0 ? count : 1u; } -bool IsSingleDmaskBit(uint32_t dmask) { - return dmask != 0u && (dmask & (dmask - 1u)) == 0u; -} - } // namespace ImageAddressComponent ImageAddressComponentLayout(uint32_t flags, uint32_t component) { @@ -332,9 +317,9 @@ void DecodeMimg(uint32_t pc, std::span code, uint32_t word_index const bool r128 = ((word0 >> 15u) & 0x1u) != 0u; const bool a16 = ((word1 >> 30u) & 0x1u) != 0u; const bool d16 = ((word1 >> 31u) & 0x1u) != 0u; - const auto* sample = LookupSample(opcode); - const auto* gather = LookupGather(opcode); - const auto* atomic = LookupAtomic(opcode); + const auto* sample = Detail::FindOpcode(MIMG_SAMPLE_OPS, opcode); + const auto* gather = Detail::FindOpcode(MIMG_GATHER_OPS, opcode); + const auto* atomic = Detail::FindOpcode(MIMG_ATOMIC_OPS, opcode); inst.pc = pc; inst.word_count = word_count; @@ -364,7 +349,7 @@ void DecodeMimg(uint32_t pc, std::span code, uint32_t word_index if (inst.opcode == Opcode::UNSUPPORTED) { SetUnsupported(inst, Family::MIMG, opcode, "MIMG opcode is not implemented"); } - if (gather != nullptr && !IsSingleDmaskBit(inst.dmask)) { + if (gather != nullptr && !std::has_single_bit(inst.dmask)) { SetUnsupported(inst, Family::MIMG, opcode, "MIMG image gather requires exactly one dmask bit"); } @@ -382,7 +367,7 @@ void DecodeMimg(uint32_t pc, std::span code, uint32_t word_index } const char* MimgSampleOpcodeName(uint32_t opcode) { - const auto* sample = LookupSample(opcode); + const auto* sample = Detail::FindOpcode(MIMG_SAMPLE_OPS, opcode); return sample != nullptr ? sample->name : nullptr; } diff --git a/src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp b/src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp index 028c715cc..4879f45ab 100644 --- a/src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp +++ b/src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp @@ -14,10 +14,6 @@ namespace Libs::Graphics::ShaderRecompiler::Decoder { namespace { -uint32_t FloatBits(float value) { - return std::bit_cast(value); -} - bool HasLiteral(const Instruction& inst) { return inst.src0.kind == OperandKind::LiteralConstant || inst.src1.kind == OperandKind::LiteralConstant || @@ -242,7 +238,7 @@ void DecodeScalarSource(uint32_t code, uint32_t pc, Operand& operand) { if (code >= 240u && code <= 247u) { constexpr float values[] = {0.5f, -0.5f, 1.0f, -1.0f, 2.0f, -2.0f, 4.0f, -4.0f}; operand.kind = OperandKind::FloatInlineConstant; - operand.value = FloatBits(values[code - 240u]); + operand.value = std::bit_cast(values[code - 240u]); return; } if (code >= 256u && code <= 511u) { @@ -260,7 +256,7 @@ void DecodeScalarSource(uint32_t code, uint32_t pc, Operand& operand) { case 239u: operand.kind = OperandKind::PopsExitingWaveId; return; case 248u: operand.kind = OperandKind::FloatInlineConstant; - operand.value = FloatBits(0.15915494309189535f); + operand.value = std::bit_cast(0.15915494309189535f); return; case 251u: operand.kind = OperandKind::VccZ; return; case 252u: operand.kind = OperandKind::ExecZ; return; diff --git a/src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp b/src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp index 004040cc8..cbeb0fe8b 100644 --- a/src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp +++ b/src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp @@ -83,10 +83,6 @@ constexpr Vop2OpcodeInfo VOP2_OPCODE_LIST[] = { constexpr auto VOP2_OPS = Detail::MakeOpcodeTable<0x40>(VOP2_OPCODE_LIST); -constexpr Opcode LookupVop2Opcode(uint32_t encoding) { - return Detail::LookupOpcode(VOP2_OPS, encoding); -} - constexpr OpcodeMap VOP1_OPCODE_LIST[] = { {0x00u, Opcode::V_NOP}, {0x01u, Opcode::V_MOV_B32}, @@ -375,7 +371,7 @@ Opcode LookupVop3Opcode(uint32_t opcode) { if (IsUnsupportedVop3EncodedVop2Alias(opcode - 0x100u)) { return Opcode::UNSUPPORTED; } - return LookupVop2Opcode(opcode - 0x100u); + return Detail::LookupOpcode(VOP2_OPS, opcode - 0x100u); } if (opcode >= 0x180u && opcode <= 0x1ffu) { return Detail::LookupOpcode(VOP3_ENCODED_VOP1_OPS, opcode - 0x180u); @@ -1470,7 +1466,7 @@ void DecodeVop2(uint32_t pc, std::span code, uint32_t word_index inst.pc = pc; inst.family = Family::VOP2; inst.opcode_id = opcode; - inst.opcode = LookupVop2Opcode(opcode); + inst.opcode = Detail::LookupOpcode(VOP2_OPS, opcode); SetRawWords(inst, code, word_index, 1); if (inst.opcode == Opcode::UNSUPPORTED) { diff --git a/src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp b/src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp index e099d2c6d..f799257a6 100644 --- a/src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp +++ b/src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp @@ -479,8 +479,6 @@ private: return std::bit_cast(static_cast(bits)); } - static uint64_t Float32Bits(float value) { return std::bit_cast(value); } - bool EvaluateWide(Value value, uint64_t& result) { value = value.Resolve(); if (value.IsImmediate()) { @@ -490,7 +488,7 @@ private: case Type::U16: result = value.U16(); return true; case Type::U32: result = value.U32(); return true; case Type::U64: result = value.U64(); return true; - case Type::F32: result = Float32Bits(value.F32Value()); return true; + case Type::F32: result = std::bit_cast(value.F32Value()); return true; default: return false; } } @@ -733,7 +731,7 @@ private: return false; case ValueOpcode::ConvertF32U32: if (Arg(inst, 0, a)) { - result = Float32Bits(static_cast(static_cast(a))); + result = std::bit_cast(static_cast(static_cast(a))); return true; } return false; @@ -750,13 +748,13 @@ private: return false; case ValueOpcode::FPMul32: if (binary()) { - result = Float32Bits(Float32(a) * Float32(b)); + result = std::bit_cast(Float32(a) * Float32(b)); return true; } return false; case ValueOpcode::FPTrunc32: if (Arg(inst, 0, a)) { - result = Float32Bits(std::trunc(Float32(a))); + result = std::bit_cast(std::trunc(Float32(a))); return true; } return false; diff --git a/src/graphics/shader/rectListShader.cpp b/src/graphics/shader/rectListShader.cpp index c809e83d7..cf7f54959 100644 --- a/src/graphics/shader/rectListShader.cpp +++ b/src/graphics/shader/rectListShader.cpp @@ -60,12 +60,12 @@ public: : parameters(parameters_) { builder.AddMemoryModel(spv::AddressingModelLogical, spv::MemoryModelGLSL450); - void_type = Type(spv::OpTypeVoid); - uint_type = Type(spv::OpTypeInt, 32u, 0u); - int_type = Type(spv::OpTypeInt, 32u, 1u); - float_type = Type(spv::OpTypeFloat, 32u); - vec4_float_type = Type(spv::OpTypeVector, float_type, 4u); - function_type = Type(spv::OpTypeFunction, void_type); + void_type = builder.Type(spv::OpTypeVoid); + uint_type = builder.Type(spv::OpTypeInt, 32u, 0u); + int_type = builder.Type(spv::OpTypeInt, 32u, 1u); + float_type = builder.Type(spv::OpTypeFloat, 32u); + vec4_float_type = builder.Type(spv::OpTypeVector, float_type, 4u); + function_type = builder.Type(spv::OpTypeFunction, void_type); per_vertex_type = builder.DecoratedType( spv::OpTypeStruct, @@ -76,12 +76,12 @@ public: ptr_input_vec4_float = Pointer(spv::StorageClassInput, vec4_float_type); ptr_output_vec4_float = Pointer(spv::StorageClassOutput, vec4_float_type); if (model == spv::ExecutionModelTessellationControl) { - bool_type = Type(spv::OpTypeBool); - vec2_bool_type = Type(spv::OpTypeVector, bool_type, 2u); - vec2_float_type = Type(spv::OpTypeVector, float_type, 2u); + bool_type = builder.Type(spv::OpTypeBool); + vec2_bool_type = builder.Type(spv::OpTypeVector, bool_type, 2u); + vec2_float_type = builder.Type(spv::OpTypeVector, float_type, 2u); ptr_output_float = Pointer(spv::StorageClassOutput, float_type); } else { - vec3_float_type = Type(spv::OpTypeVector, float_type, 3u); + vec3_float_type = builder.Type(spv::OpTypeVector, float_type, 3u); ptr_input_float = Pointer(spv::StorageClassInput, float_type); } } @@ -161,8 +161,8 @@ public: Store(Access(ptr_output_vec4_float, outputs[i], invocation), value); } - Emit(spv::OpReturn); - Emit(spv::OpFunctionEnd); + builder.AddFunction(spv::OpReturn); + builder.AddFunction(spv::OpFunctionEnd); return builder.Build(); } @@ -184,27 +184,22 @@ public: Load(vec4_float_type, Access(ptr_input_vec4_float, inputs[i], index))); } - Emit(spv::OpReturn); - Emit(spv::OpFunctionEnd); + builder.AddFunction(spv::OpReturn); + builder.AddFunction(spv::OpFunctionEnd); return builder.Build(); } private: - template - uint32_t Type(spv::Op opcode, Args... operands) { - return builder.Type(opcode, operands...); - } - uint32_t Constant(uint32_t type, uint32_t value) { return builder.Constant(spv::OpConstant, type, value); } uint32_t Pointer(spv::StorageClass storage, uint32_t type) { - return Type(spv::OpTypePointer, storage, type); + return builder.Type(spv::OpTypePointer, storage, type); } uint32_t Array(uint32_t type, uint32_t size) { - return Type(spv::OpTypeArray, type, Uint(size)); + return builder.Type(spv::OpTypeArray, type, Uint(size)); } template @@ -221,11 +216,6 @@ private: return id; } - template - void Emit(spv::Op opcode, Args... operands) { - builder.AddFunction(opcode, operands...); - } - template uint32_t Access(uint32_t pointer_type, uint32_t base, Args... indices) { return Result(spv::OpAccessChain, pointer_type, base, indices...); @@ -233,7 +223,7 @@ private: uint32_t Load(uint32_t type, uint32_t pointer) { return Result(spv::OpLoad, type, pointer); } - void Store(uint32_t pointer, uint32_t value) { Emit(spv::OpStore, pointer, value); } + void Store(uint32_t pointer, uint32_t value) { builder.AddFunction(spv::OpStore, pointer, value); } uint32_t Int(uint32_t value) { return Constant(int_type, value); } diff --git a/src/graphics/shader/shader.cpp b/src/graphics/shader/shader.cpp index ca8645b47..220e6fbee 100644 --- a/src/graphics/shader/shader.cpp +++ b/src/graphics/shader/shader.cpp @@ -1005,8 +1005,4 @@ void ShaderDbgDumpInputInfo(const ShaderComputeInputInfo& info) { info.group_id[1] ? "true" : "false", info.group_id[2] ? "true" : "false"); } -bool ShaderAddressValid(uint64_t addr) { - return reinterpret_cast(addr) != nullptr; -} - } // namespace Libs::Graphics diff --git a/src/graphics/shader/shader.h b/src/graphics/shader/shader.h index 7ec2e2b95..f45dcc8d7 100644 --- a/src/graphics/shader/shader.h +++ b/src/graphics/shader/shader.h @@ -303,7 +303,6 @@ void ShaderMapUserData(uint64_t addr, const ShaderMappedData& data); void ShaderDbgDumpInputInfo(const ShaderVertexInputInfo& info); void ShaderDbgDumpInputInfo(const ShaderPixelInputInfo& info); void ShaderDbgDumpInputInfo(const ShaderComputeInputInfo& info); -bool ShaderAddressValid(uint64_t addr); } // namespace Libs::Graphics