From fa602802da2024668f1807947ed1a9b78cdf45fc Mon Sep 17 00:00:00 2001 From: DH Date: Thu, 17 Oct 2024 03:42:49 +0300 Subject: [PATCH] gpu: fix compilation error bugfixes --- rpcsx/core/include/rx/watchdog.hpp | 2 +- rpcsx/core/src/watchdog.cpp | 45 +++++++++++++++++++++++------- rpcsx/gpu/Cache.cpp | 32 ++++++++------------- rpcsx/gpu/DeviceCtl.cpp | 27 +++++++++++++++++- rpcsx/gpu/DeviceCtl.hpp | 5 +++- rpcsx/gpu/FlipPipeline.cpp | 21 ++++++++++++-- rpcsx/gpu/Pipe.cpp | 2 +- 7 files changed, 97 insertions(+), 37 deletions(-) diff --git a/rpcsx/core/include/rx/watchdog.hpp b/rpcsx/core/include/rx/watchdog.hpp index ba3334153..e76ba2962 100644 --- a/rpcsx/core/include/rx/watchdog.hpp +++ b/rpcsx/core/include/rx/watchdog.hpp @@ -9,5 +9,5 @@ std::filesystem::path getShmGuestPath(std::string_view path); void createGpuDevice(); void shutdown(); void attachProcess(int pid); -int startWatchdog(); +void startWatchdog(); } // namespace rx diff --git a/rpcsx/core/src/watchdog.cpp b/rpcsx/core/src/watchdog.cpp index 1e8c14726..d926e0aeb 100644 --- a/rpcsx/core/src/watchdog.cpp +++ b/rpcsx/core/src/watchdog.cpp @@ -18,6 +18,8 @@ #include #include +static constexpr bool kDebugGpu = false; + static std::atomic g_exitRequested; static std::atomic g_runGpuRequested; static pid_t g_watchdogPid; @@ -37,9 +39,17 @@ static void runGPU() { auto childPid = ::fork(); - if (childPid != 0) { + if (kDebugGpu) { + if (childPid == 0) { + return; + } + g_gpuPid = childPid; - return; + } else { + if (childPid != 0) { + g_gpuPid = childPid; + return; + } } amdgpu::DeviceCtl gpu; @@ -79,7 +89,7 @@ static void handleManagementSignal(siginfo_t *info) { } static void handle_watchdog_signal(int sig, siginfo_t *info, void *) { - if (sig == SIGUSR1) { + if (sig == SIGUSR2) { handleManagementSignal(info); } @@ -89,7 +99,7 @@ static void handle_watchdog_signal(int sig, siginfo_t *info, void *) { } static void sendMessage(MessageId id, std::uint32_t data) { - sigqueue(g_watchdogPid, SIGUSR1, + sigqueue(g_watchdogPid, SIGUSR2, { .sival_ptr = std::bit_cast( ((static_cast(data) << 32) | @@ -102,7 +112,13 @@ std::filesystem::path rx::getShmGuestPath(std::string_view path) { return std::format("{}/guest/{}", getShmPath(), path); } -void rx::createGpuDevice() { sendMessage(MessageId::RunGPU, 0); } +void rx::createGpuDevice() { + if (kDebugGpu) { + runGPU(); + } else { + sendMessage(MessageId::RunGPU, 0); + } +} void rx::shutdown() { kill(g_watchdogPid, SIGQUIT); } void rx::attachProcess(int pid) { sendMessage(MessageId::AttachProcess, pid); } @@ -133,7 +149,7 @@ static void killProcesses(std::vector list) { } } -int rx::startWatchdog() { +void rx::startWatchdog() { auto watchdogPid = ::getpid(); g_watchdogPid = watchdogPid; std::format_to(g_shmPath, "/dev/shm/rpcsx/{}", watchdogPid); @@ -150,8 +166,17 @@ int rx::startWatchdog() { pid_t initProcessPid = fork(); - if (initProcessPid == 0) { - return watchdogPid; + if (kDebugGpu) { + if (initProcessPid == 0) { + initProcessPid = watchdogPid; + } else { + g_watchdogPid = initProcessPid; + return; + } + } else { + if (initProcessPid == 0) { + return; + } } pthread_setname_np(pthread_self(), "rpcsx-watchdog"); @@ -160,7 +185,7 @@ int rx::startWatchdog() { act.sa_sigaction = handle_watchdog_signal; act.sa_flags = SA_SIGINFO; - if (sigaction(SIGUSR1, &act, nullptr)) { + if (sigaction(SIGUSR2, &act, nullptr)) { perror("Error sigaction:"); std::exit(-1); } @@ -182,7 +207,7 @@ int rx::startWatchdog() { sigset_t sigSet; sigemptyset(&sigSet); - sigaddset(&sigSet, SIGUSR1); + sigaddset(&sigSet, SIGUSR2); sigaddset(&sigSet, SIGINT); sigaddset(&sigSet, SIGQUIT); sigaddset(&sigSet, SIGHUP); diff --git a/rpcsx/gpu/Cache.cpp b/rpcsx/gpu/Cache.cpp index c3171533a..3c8178889 100644 --- a/rpcsx/gpu/Cache.cpp +++ b/rpcsx/gpu/Cache.cpp @@ -22,22 +22,7 @@ using namespace amdgpu; using namespace shader; -static void notifyPageChanges(Device *device, int vmId, std::uint32_t firstPage, - std::uint32_t pageCount) { - std::uint64_t command = - (static_cast(pageCount - 1) << 32) | firstPage; - - while (true) { - for (std::size_t i = 0; i < std::size(device->cacheCommands); ++i) { - std::uint64_t expCommand = 0; - if (device->cacheCommands[vmId][i].compare_exchange_strong( - expCommand, command, std::memory_order::acquire, - std::memory_order::relaxed)) { - return; - } - } - } -} +static constexpr bool kDisableCache = false; static bool testHostInvalidations(Device *device, int vmId, std::uint64_t address, std::uint64_t size) { @@ -620,7 +605,9 @@ struct CachedBuffer : Cache::Entry { struct CachedHostVisibleBuffer : CachedBuffer { using CachedBuffer::update; - bool expensive() { return addressRange.size() >= rx::mem::pageSize; } + bool expensive() { + return !kDisableCache && addressRange.size() >= rx::mem::pageSize; + } void flush(void *target, rx::AddressRange range) { if (!hasDelayedFlush) { @@ -686,7 +673,7 @@ struct CachedImage : Cache::Entry { std::uint32_t pitch{}; SurfaceInfo info; - bool expensive() { return true; } + bool expensive() { return !kDisableCache; } [[nodiscard]] VkImageSubresourceRange getSubresource(rx::AddressRange range) const { @@ -2191,7 +2178,8 @@ Cache::Cache(Device *device, int vmId) : mDevice(device), mVmId(vmId) { VkDescriptorPoolCreateInfo info{ .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, - .maxSets = kDescriptorSetCount * 2, + .maxSets = static_cast(std::size(mGraphicsDescriptorSets) * mGraphicsDescriptorSetLayouts.size() + + std::size(mComputeDescriptorSets) + 1), .poolSizeCount = static_cast(std::size(descriptorPoolSizes)), .pPoolSizes = descriptorPoolSizes, }; @@ -2210,7 +2198,8 @@ Cache::Cache(Device *device, int vmId) : mDevice(device), mVmId(vmId) { }; for (auto &graphicsSet : mGraphicsDescriptorSets) { - vkAllocateDescriptorSets(vk::context->device, &info, graphicsSet.data()); + VK_VERIFY(vkAllocateDescriptorSets(vk::context->device, &info, + graphicsSet.data())); } } @@ -2223,7 +2212,8 @@ Cache::Cache(Device *device, int vmId) : mDevice(device), mVmId(vmId) { }; for (auto &computeSet : mComputeDescriptorSets) { - vkAllocateDescriptorSets(vk::context->device, &info, &computeSet); + VK_VERIFY( + vkAllocateDescriptorSets(vk::context->device, &info, &computeSet)); } } } diff --git a/rpcsx/gpu/DeviceCtl.cpp b/rpcsx/gpu/DeviceCtl.cpp index ddc3c0deb..49fb6acc9 100644 --- a/rpcsx/gpu/DeviceCtl.cpp +++ b/rpcsx/gpu/DeviceCtl.cpp @@ -1,6 +1,7 @@ #include "DeviceCtl.hpp" #include "Device.hpp" #include "gnm/pm4.hpp" +#include "orbis/error/ErrorCode.hpp" #include "rx/bits.hpp" #include "rx/die.hpp" #include "shader/dialect.hpp" @@ -60,9 +61,32 @@ void DeviceCtl::submitFlip(int gfxPipe, std::uint32_t pid, int bufferIndex, flipArg >> 32, pid)); } +orbis::ErrorCode DeviceCtl::submitWriteEop(int gfxPipe, std::uint32_t waitMode, + std::uint64_t eopValue) { + std::uint64_t address = 0; + std::uint32_t eventType = 0; + // FIXME: event type currently not used + + std::uint32_t eventCntl = (eventType << 0); + auto addressLo = static_cast(address); + std::uint32_t dataCntl = 0 // + | (2 << 24) // int sel + | (2 << 29) // data sel + | static_cast(address >> 32); + + auto dataLo = static_cast(eopValue); + auto dataHi = static_cast(eopValue >> 32); + + mDevice->submitGfxCommand(gfxPipe, createPm4Packet(gnm::IT_EVENT_WRITE_EOP, + eventCntl, addressLo, + dataCntl, dataLo, dataHi)); + return {}; +} + orbis::ErrorCode DeviceCtl::submitFlipOnEop(int gfxPipe, std::uint32_t pid, int bufferIndex, - std::uint64_t flipArg) { + std::uint64_t flipArg, + std::uint64_t eopValue) { int index; auto &pipe = mDevice->graphicsPipes[gfxPipe]; { @@ -77,6 +101,7 @@ orbis::ErrorCode DeviceCtl::submitFlipOnEop(int gfxPipe, std::uint32_t pid, .pid = pid, .bufferIndex = bufferIndex, .arg = flipArg, + .eopValue = eopValue, }; } diff --git a/rpcsx/gpu/DeviceCtl.hpp b/rpcsx/gpu/DeviceCtl.hpp index 3f6c8425a..fdaeb47f4 100644 --- a/rpcsx/gpu/DeviceCtl.hpp +++ b/rpcsx/gpu/DeviceCtl.hpp @@ -30,8 +30,11 @@ public: void submitSwitchBuffer(int gfxPipe); void submitFlip(int gfxPipe, std::uint32_t pid, int bufferIndex, std::uint64_t flipArg); + orbis::ErrorCode submitWriteEop(int gfxPipe, std::uint32_t waitMode, + std::uint64_t eopValue); orbis::ErrorCode submitFlipOnEop(int gfxPipe, std::uint32_t pid, - int bufferIndex, std::uint64_t flipArg); + int bufferIndex, std::uint64_t flipArg, + std::uint64_t eopValue); void submitMapMemory(int gfxPipe, std::uint32_t pid, std::uint64_t address, std::uint64_t size, int memoryType, int dmemIndex, int prot, std::int64_t offset); diff --git a/rpcsx/gpu/FlipPipeline.cpp b/rpcsx/gpu/FlipPipeline.cpp index e55bdf774..dfff6af24 100644 --- a/rpcsx/gpu/FlipPipeline.cpp +++ b/rpcsx/gpu/FlipPipeline.cpp @@ -139,7 +139,7 @@ FlipPipeline::FlipPipeline() { .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, }; - VkSampleMask sampleMask = -1; + VkSampleMask sampleMask = VK_SAMPLE_COUNT_1_BIT; VkPipelineMultisampleStateCreateInfo multisampleState{ .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT, @@ -149,9 +149,16 @@ FlipPipeline::FlipPipeline() { VkPipelineDepthStencilStateCreateInfo depthStencilState{ .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, }; + + VkPipelineColorBlendAttachmentState blendAttachmentState = { + .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, + }; + VkPipelineColorBlendStateCreateInfo colorBlendState{ .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, - }; + .attachmentCount = 1, + .pAttachments = &blendAttachmentState}; VkDynamicState dynamicStates[] = { VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT, @@ -164,9 +171,18 @@ FlipPipeline::FlipPipeline() { .pDynamicStates = dynamicStates, }; + VkFormat colorFormat = VK_FORMAT_B8G8R8A8_UNORM; + + VkPipelineRenderingCreateInfoKHR info{ + .sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO, + .colorAttachmentCount = 1, + .pColorAttachmentFormats = &colorFormat, + }; + VkGraphicsPipelineCreateInfo pipelineCreateInfos[]{ { .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, + .pNext = &info, .stageCount = std::size(stagesStd), .pStages = stagesStd, .pVertexInputState = &vertexInputState, @@ -181,6 +197,7 @@ FlipPipeline::FlipPipeline() { }, { .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, + .pNext = &info, .stageCount = std::size(stagesAlt), .pStages = stagesAlt, .pVertexInputState = &vertexInputState, diff --git a/rpcsx/gpu/Pipe.cpp b/rpcsx/gpu/Pipe.cpp index 2dda89d9a..44f58b6fa 100644 --- a/rpcsx/gpu/Pipe.cpp +++ b/rpcsx/gpu/Pipe.cpp @@ -1193,7 +1193,7 @@ bool GraphicsPipe::eventWriteEop(Ring &ring) { kGcEventGfxEop); } - if (intSel != 0 && dataSel == 2) { + if (intSel == 2 && dataSel == 2) { std::optional request; int index = -1; {