gpu: fix compilation error

bugfixes
This commit is contained in:
DH 2024-10-17 03:42:49 +03:00
parent ae6bb38073
commit fa602802da
7 changed files with 97 additions and 37 deletions

View file

@ -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

View file

@ -18,6 +18,8 @@
#include <unistd.h>
#include <utility>
static constexpr bool kDebugGpu = false;
static std::atomic<bool> g_exitRequested;
static std::atomic<bool> 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<void *>(
((static_cast<std::uintptr_t>(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<int> 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);

View file

@ -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<std::uint64_t>(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<uint32_t>(std::size(mGraphicsDescriptorSets) * mGraphicsDescriptorSetLayouts.size() +
std::size(mComputeDescriptorSets) + 1),
.poolSizeCount = static_cast<uint32_t>(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));
}
}
}

View file

@ -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<std::uint32_t>(address);
std::uint32_t dataCntl = 0 //
| (2 << 24) // int sel
| (2 << 29) // data sel
| static_cast<std::uint16_t>(address >> 32);
auto dataLo = static_cast<std::uint32_t>(eopValue);
auto dataHi = static_cast<std::uint32_t>(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,
};
}

View file

@ -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);

View file

@ -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,

View file

@ -1193,7 +1193,7 @@ bool GraphicsPipe::eventWriteEop(Ring &ring) {
kGcEventGfxEop);
}
if (intSel != 0 && dataSel == 2) {
if (intSel == 2 && dataSel == 2) {
std::optional<EopFlipRequest> request;
int index = -1;
{