mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-29 16:51:20 +00:00
format src and tests with clang-format
This commit is contained in:
1 parent
68be13345a
commit
d8a4c83cc7
52 files changed
+4187
-6010
No files matched your search
@@ -49,8 +49,7 @@ public:
|
||||
|
||||
template <typename Function>
|
||||
void ForEachItemBelow(Tick tick, Function&& function) {
|
||||
constexpr bool ReturnsBool =
|
||||
std::is_same_v<std::invoke_result_t<Function, Object>, bool>;
|
||||
constexpr bool ReturnsBool = std::is_same_v<std::invoke_result_t<Function, Object>, bool>;
|
||||
for (auto* item = m_first; item != nullptr;) {
|
||||
if (item->tick > tick) {
|
||||
return;
|
||||
|
||||
@@ -33,8 +33,7 @@ static bool OnOwnStack() {
|
||||
}
|
||||
void* base = nullptr;
|
||||
size_t size = 0;
|
||||
const bool ok =
|
||||
pthread_attr_getstack(&attr, &base, &size) == 0 && base != nullptr && size != 0;
|
||||
const bool ok = pthread_attr_getstack(&attr, &base, &size) == 0 && base != nullptr && size != 0;
|
||||
pthread_attr_destroy(&attr);
|
||||
if (!ok) {
|
||||
return false;
|
||||
|
||||
@@ -172,8 +172,7 @@ sys_file_t* SysFileCreate(const std::filesystem::path& file_name) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
sys_file_t* SysFileOpenR(const std::filesystem::path& file_name,
|
||||
sys_file_cache_type_t cache_type) {
|
||||
sys_file_t* SysFileOpenR(const std::filesystem::path& file_name, sys_file_cache_type_t cache_type) {
|
||||
auto* ret = new sys_file_t;
|
||||
|
||||
ret->type = SYS_FILE_FILE;
|
||||
@@ -218,8 +217,7 @@ sys_file_t* SysFileCreate() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
sys_file_t* SysFileOpenW(const std::filesystem::path& file_name,
|
||||
sys_file_cache_type_t cache_type) {
|
||||
sys_file_t* SysFileOpenW(const std::filesystem::path& file_name, sys_file_cache_type_t cache_type) {
|
||||
auto* ret = new sys_file_t;
|
||||
|
||||
auto real_name = get_internal_name(file_name);
|
||||
|
||||
@@ -136,8 +136,8 @@ static void* map_anonymous(uintptr_t addr, size_t size, int protect, int flags)
|
||||
break;
|
||||
}
|
||||
const auto hint = (top - step) & ~(LOW_ARENA_GRAIN - 1);
|
||||
void* ptr = mmap(reinterpret_cast<void*>(hint), size, protect,
|
||||
flags | MAP_FIXED_NOREPLACE, -1, 0); // NOLINT
|
||||
void* ptr = mmap(reinterpret_cast<void*>(hint), size, protect, flags | MAP_FIXED_NOREPLACE,
|
||||
-1, 0); // NOLINT
|
||||
if (ptr != MAP_FAILED) {
|
||||
return ptr;
|
||||
}
|
||||
@@ -194,8 +194,8 @@ uint64_t SysVirtualAllocAligned(uint64_t address, uint64_t size, VirtualMemory::
|
||||
if (ptr != MAP_FAILED && ((ret_addr & (alignment - 1)) != 0)) {
|
||||
munmap(ptr, size);
|
||||
|
||||
ptr = map_anonymous(addr, size + alignment, protect,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_NORESERVE);
|
||||
ptr =
|
||||
map_anonymous(addr, size + alignment, protect, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE);
|
||||
ret_addr = reinterpret_cast<uintptr_t>(ptr);
|
||||
if (ptr != MAP_FAILED) {
|
||||
#if defined(__APPLE__)
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cerrno>
|
||||
#include <chrono> // IWYU pragma: keep
|
||||
#include <condition_variable> // IWYU pragma: keep
|
||||
#include <cerrno>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ class UniqueFunction {
|
||||
public:
|
||||
explicit Callable(Function function): m_function(std::move(function)) {}
|
||||
|
||||
Result Invoke(Args&&... args) override {
|
||||
return m_function(std::forward<Args>(args)...);
|
||||
}
|
||||
Result Invoke(Args&&... args) override { return m_function(std::forward<Args>(args)...); }
|
||||
|
||||
private:
|
||||
Function m_function;
|
||||
|
||||
@@ -962,9 +962,8 @@ void CommandProcessor::DrawIndexOffset(uint32_t index_offset, uint32_t index_cou
|
||||
auto* index_addr = reinterpret_cast<const void*>(
|
||||
m_index_base_addr + static_cast<uint64_t>(index_offset) * index_size);
|
||||
|
||||
m_renderer.GetRenderExecutor().DrawIndex(m_submit_id, CurrentBuffer(),
|
||||
m_index_type_and_size, index_count, index_addr,
|
||||
flags, 1, m_num_instances);
|
||||
m_renderer.GetRenderExecutor().DrawIndex(m_submit_id, CurrentBuffer(), m_index_type_and_size,
|
||||
index_count, index_addr, flags, 1, m_num_instances);
|
||||
}
|
||||
|
||||
void CommandProcessor::DrawIndirect(uint32_t data_offset, uint32_t draw_initiator, bool indexed) {
|
||||
@@ -1190,8 +1189,8 @@ void CommandProcessor::DispatchDirect(uint32_t thread_group_x, uint32_t thread_g
|
||||
}
|
||||
}
|
||||
|
||||
m_renderer.GetRenderExecutor().DispatchDirect(
|
||||
m_submit_id, CurrentBuffer(), thread_group_x, thread_group_y, thread_group_z, mode);
|
||||
m_renderer.GetRenderExecutor().DispatchDirect(m_submit_id, CurrentBuffer(), thread_group_x,
|
||||
thread_group_y, thread_group_z, mode);
|
||||
}
|
||||
|
||||
constexpr uint32_t DispatchInitiatorUseThreadDimensions = 1u << 5u;
|
||||
@@ -1237,9 +1236,9 @@ void CommandProcessor::DrawIndexAuto(uint32_t index_count, uint32_t flags,
|
||||
uint32_t first_vertex, uint32_t first_instance) {
|
||||
CheckBuffer();
|
||||
|
||||
m_renderer.GetRenderExecutor().DrawAuto(
|
||||
m_submit_id, CurrentBuffer(), index_count, flags, render_target_slice_offset,
|
||||
instance_count, first_vertex, first_instance);
|
||||
m_renderer.GetRenderExecutor().DrawAuto(m_submit_id, CurrentBuffer(), index_count, flags,
|
||||
render_target_slice_offset, instance_count,
|
||||
first_vertex, first_instance);
|
||||
}
|
||||
|
||||
void CommandProcessor::WaitFlipDone(uint32_t video_out_handle, uint32_t display_buffer_index) {
|
||||
@@ -1317,8 +1316,8 @@ void CommandProcessor::WriteAtEndOfPipe(uint32_t cache_policy, uint32_t event_wr
|
||||
if (eop_event_type == 0x2f && cache_action == 0x00 && event_index == 0x06) {
|
||||
auto* dst = static_cast<uint32_t*>(dst_gpu_addr);
|
||||
SynchronizeGpu();
|
||||
Sync::ReadGds(m_renderer.GetBufferCache().GetGdsBuffer(), dst,
|
||||
value & 0xffffu, value >> 16u);
|
||||
Sync::ReadGds(m_renderer.GetBufferCache().GetGdsBuffer(), dst, value & 0xffffu,
|
||||
value >> 16u);
|
||||
Sync::WriteAtEndOfPipeGds32(m_submit_id, CurrentBuffer(), dst, value & 0xffffu,
|
||||
value >> 16u);
|
||||
return;
|
||||
@@ -1486,8 +1485,7 @@ void CommandProcessor::EmitGlobalBarrier() {
|
||||
barrier.srcStageMask = vk::PipelineStageFlagBits2::eAllCommands;
|
||||
barrier.srcAccessMask = vk::AccessFlagBits2::eMemoryWrite;
|
||||
barrier.dstStageMask = vk::PipelineStageFlagBits2::eAllCommands;
|
||||
barrier.dstAccessMask =
|
||||
vk::AccessFlagBits2::eMemoryRead | vk::AccessFlagBits2::eMemoryWrite;
|
||||
barrier.dstAccessMask = vk::AccessFlagBits2::eMemoryRead | vk::AccessFlagBits2::eMemoryWrite;
|
||||
|
||||
vk::DependencyInfo dependency {};
|
||||
dependency.memoryBarrierCount = 1;
|
||||
|
||||
+6
-8
@@ -135,8 +135,8 @@ void Buffer::Write(uint64_t offset, const void* source, uint64_t size) {
|
||||
void Buffer::Flush(uint64_t offset, uint64_t size) {
|
||||
EXIT_IF(m_mapped.empty() || offset > m_size || size > m_size - offset);
|
||||
if (!m_is_coherent && size != 0) {
|
||||
const auto result = vmaFlushAllocation(m_graphics->allocator, m_buffer->memory.allocation,
|
||||
offset, size);
|
||||
const auto result =
|
||||
vmaFlushAllocation(m_graphics->allocator, m_buffer->memory.allocation, offset, size);
|
||||
EXIT_NOT_IMPLEMENTED(static_cast<vk::Result>(result) != vk::Result::eSuccess);
|
||||
}
|
||||
}
|
||||
@@ -144,8 +144,8 @@ void Buffer::Flush(uint64_t offset, uint64_t size) {
|
||||
vk::BufferMemoryBarrier Buffer::Barrier(uint64_t offset, uint64_t size, vk::AccessFlags source,
|
||||
vk::AccessFlags destination) const {
|
||||
if (Handle() == nullptr || size == 0 || offset > m_size || size > m_size - offset) {
|
||||
EXIT("Buffer: invalid DMA barrier, handle=%p offset=0x%016" PRIx64
|
||||
" size=0x%016" PRIx64 " capacity=0x%016" PRIx64 "\n",
|
||||
EXIT("Buffer: invalid DMA barrier, handle=%p offset=0x%016" PRIx64 " size=0x%016" PRIx64
|
||||
" capacity=0x%016" PRIx64 "\n",
|
||||
static_cast<const void*>(Handle()), offset, size, m_size);
|
||||
}
|
||||
vk::BufferMemoryBarrier barrier {};
|
||||
@@ -175,8 +175,7 @@ void Buffer::CopyFrom(CommandBuffer& command, const Buffer& source, uint64_t sou
|
||||
command.EndRendering();
|
||||
const vk::BufferMemoryBarrier before[] = {
|
||||
source.Barrier(source_offset, size, source_before, vk::AccessFlagBits::eTransferRead),
|
||||
Barrier(destination_offset, size, destination_before,
|
||||
vk::AccessFlagBits::eTransferWrite),
|
||||
Barrier(destination_offset, size, destination_before, vk::AccessFlagBits::eTransferWrite),
|
||||
};
|
||||
const auto host_access = vk::AccessFlagBits::eHostRead | vk::AccessFlagBits::eHostWrite;
|
||||
auto before_stage = vk::PipelineStageFlags {vk::PipelineStageFlagBits::eAllCommands};
|
||||
@@ -214,8 +213,7 @@ void Buffer::Fill(uint64_t offset, uint64_t size, uint32_t value) {
|
||||
vk::PipelineStageFlagBits::eTransfer, vk::DependencyFlagBits::eByRegion,
|
||||
0, nullptr, 1, &before, 0, nullptr);
|
||||
native.fillBuffer(Handle(), offset, size, value);
|
||||
const auto after =
|
||||
Barrier(offset, size, vk::AccessFlagBits::eTransferWrite,
|
||||
const auto after = Barrier(offset, size, vk::AccessFlagBits::eTransferWrite,
|
||||
vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite);
|
||||
native.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer,
|
||||
vk::PipelineStageFlagBits::eAllCommands,
|
||||
|
||||
+7
-8
@@ -54,16 +54,15 @@ public:
|
||||
[[nodiscard]] bool IsInBounds(uint64_t address, uint64_t size) const noexcept;
|
||||
void Write(uint64_t offset, const void* source, uint64_t size);
|
||||
void Flush(uint64_t offset, uint64_t size);
|
||||
void CopyFrom(
|
||||
CommandBuffer& command, const Buffer& source, uint64_t source_offset,
|
||||
void CopyFrom(CommandBuffer& command, const Buffer& source, uint64_t source_offset,
|
||||
uint64_t destination_offset, uint64_t size,
|
||||
vk::AccessFlags source_before = vk::AccessFlagBits::eMemoryWrite,
|
||||
vk::AccessFlags destination_before =
|
||||
vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite,
|
||||
vk::AccessFlags source_after =
|
||||
vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite,
|
||||
vk::AccessFlags destination_after =
|
||||
vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite);
|
||||
vk::AccessFlags destination_before = vk::AccessFlagBits::eMemoryRead |
|
||||
vk::AccessFlagBits::eMemoryWrite,
|
||||
vk::AccessFlags source_after = vk::AccessFlagBits::eMemoryRead |
|
||||
vk::AccessFlagBits::eMemoryWrite,
|
||||
vk::AccessFlags destination_after = vk::AccessFlagBits::eMemoryRead |
|
||||
vk::AccessFlagBits::eMemoryWrite);
|
||||
void Fill(uint64_t offset, uint64_t size, uint32_t value);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#define EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_COLORRENDERTARGET_H_
|
||||
|
||||
#include "graphics/guest_gpu/gpu_defs.h"
|
||||
#include "graphics/host_gpu/renderer/renderTarget.h"
|
||||
#include "graphics/host_gpu/renderer/cache/textureCache.h"
|
||||
#include "graphics/host_gpu/renderer/renderTarget.h"
|
||||
#include "graphics/host_gpu/vulkanCommon.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -331,8 +331,7 @@ void CommandScheduler::WaitPriorityOperations(uint64_t tick) {
|
||||
EXIT_IF(g_deferred_callback_scheduler == this);
|
||||
std::unique_lock lock(m_operation_mutex);
|
||||
m_operation_available.wait(lock, [this, tick] {
|
||||
const bool active_before_or_at =
|
||||
m_priority_active && m_priority_active_tick <= tick;
|
||||
const bool active_before_or_at = m_priority_active && m_priority_active_tick <= tick;
|
||||
const bool queued_before_or_at =
|
||||
!m_priority_operations.empty() && m_priority_operations.front().tick <= tick;
|
||||
return !active_before_or_at && !queued_before_or_at;
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include "graphics/host_gpu/renderer/colorRenderTarget.h"
|
||||
#include "graphics/host_gpu/renderer/debug.h"
|
||||
#include "graphics/host_gpu/renderer/depthRenderTarget.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/descriptorCache.h"
|
||||
#include "graphics/host_gpu/renderer/image/imageView.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/descriptorCache.h"
|
||||
#include "graphics/host_gpu/renderer/render.h"
|
||||
#include "graphics/host_gpu/renderer/renderContext.h"
|
||||
#include "graphics/host_gpu/vma.h"
|
||||
@@ -270,8 +270,8 @@ void CommandBuffer::BeginRendering(const RenderState& state) const {
|
||||
colors[i].sType = vk::StructureType::eRenderingAttachmentInfo;
|
||||
colors[i].imageView = attachment.image_view;
|
||||
colors[i].imageLayout = attachment.image_layout;
|
||||
colors[i].loadOp = attachment.is_clear ? vk::AttachmentLoadOp::eClear
|
||||
: vk::AttachmentLoadOp::eLoad;
|
||||
colors[i].loadOp =
|
||||
attachment.is_clear ? vk::AttachmentLoadOp::eClear : vk::AttachmentLoadOp::eLoad;
|
||||
colors[i].storeOp = vk::AttachmentStoreOp::eStore;
|
||||
colors[i].clearValue.color.uint32 = attachment.clear_value;
|
||||
}
|
||||
@@ -281,8 +281,8 @@ void CommandBuffer::BeginRendering(const RenderState& state) const {
|
||||
depth.sType = vk::StructureType::eRenderingAttachmentInfo;
|
||||
depth.imageView = depth_stencil.image_view;
|
||||
depth.imageLayout = depth_stencil.image_layout;
|
||||
depth.loadOp = depth_stencil.depth_clear ? vk::AttachmentLoadOp::eClear
|
||||
: vk::AttachmentLoadOp::eLoad;
|
||||
depth.loadOp =
|
||||
depth_stencil.depth_clear ? vk::AttachmentLoadOp::eClear : vk::AttachmentLoadOp::eLoad;
|
||||
depth.storeOp = vk::AttachmentStoreOp::eStore;
|
||||
depth.clearValue.depthStencil.depth = std::bit_cast<float>(depth_stencil.clear_value[0]);
|
||||
|
||||
@@ -290,8 +290,8 @@ void CommandBuffer::BeginRendering(const RenderState& state) const {
|
||||
stencil.sType = vk::StructureType::eRenderingAttachmentInfo;
|
||||
stencil.imageView = depth_stencil.image_view;
|
||||
stencil.imageLayout = depth_stencil.image_layout;
|
||||
stencil.loadOp = depth_stencil.stencil_clear ? vk::AttachmentLoadOp::eClear
|
||||
: vk::AttachmentLoadOp::eLoad;
|
||||
stencil.loadOp =
|
||||
depth_stencil.stencil_clear ? vk::AttachmentLoadOp::eClear : vk::AttachmentLoadOp::eLoad;
|
||||
stencil.storeOp = vk::AttachmentStoreOp::eStore;
|
||||
stencil.clearValue.depthStencil.stencil = depth_stencil.clear_value[1];
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#define EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_DEPTHRENDERTARGET_H_
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "graphics/host_gpu/renderer/cache/textureCache.h"
|
||||
#include "graphics/host_gpu/renderer/image/imageView.h"
|
||||
#include "graphics/host_gpu/renderer/renderTarget.h"
|
||||
#include "graphics/host_gpu/renderer/cache/textureCache.h"
|
||||
#include "graphics/host_gpu/vulkanCommon.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -182,8 +182,8 @@ void BlitHelper::ReinterpretColorAsMsDepth(Image& source, Image& destination) {
|
||||
auto command = command_buffer.Handle();
|
||||
source.Transit(vk::ImageLayout::eShaderReadOnlyOptimal, vk::AccessFlagBits2::eShaderRead, {},
|
||||
command);
|
||||
destination.Transit(ColorToMsDepthLayout,
|
||||
vk::AccessFlagBits2::eDepthStencilAttachmentWrite, {}, command);
|
||||
destination.Transit(ColorToMsDepthLayout, vk::AccessFlagBits2::eDepthStencilAttachmentWrite, {},
|
||||
command);
|
||||
|
||||
vk::RenderingAttachmentInfo depth_attachment {};
|
||||
depth_attachment.sType = vk::StructureType::eRenderingAttachmentInfo;
|
||||
|
||||
@@ -21,8 +21,7 @@ struct GuestRange {
|
||||
|
||||
[[nodiscard]] constexpr bool Empty() const noexcept { return address == 0 || size == 0; }
|
||||
[[nodiscard]] constexpr bool Valid() const noexcept {
|
||||
return !Empty() && address < TRACKER_ADDRESS_SIZE &&
|
||||
size <= TRACKER_ADDRESS_SIZE - address;
|
||||
return !Empty() && address < TRACKER_ADDRESS_SIZE && size <= TRACKER_ADDRESS_SIZE - address;
|
||||
}
|
||||
[[nodiscard]] constexpr uint64_t End() const noexcept { return address + size; }
|
||||
auto operator<=>(const GuestRange&) const = default;
|
||||
@@ -352,8 +351,7 @@ inline bool ImageInfo::IsDepth() const noexcept {
|
||||
}
|
||||
const auto transfer_bytes = DepthAspectTransferBytes(info.pixel_format);
|
||||
return transfer_bytes == info.bytes_per_block ||
|
||||
(info.bytes_per_block == sizeof(uint16_t) &&
|
||||
transfer_bytes == sizeof(uint32_t));
|
||||
(info.bytes_per_block == sizeof(uint16_t) && transfer_bytes == sizeof(uint32_t));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline VideoOutCompression
|
||||
@@ -472,16 +470,11 @@ IsSupportedDisplayRenderTargetTileMode(uint32_t tile_mode) noexcept {
|
||||
const auto unorm8 = [](uint32_t value) { return static_cast<float>(value & 0xffu) / 255.0f; };
|
||||
const auto srgb8 = [](uint32_t value) {
|
||||
const auto encoded = static_cast<float>(value & 0xffu) / 255.0f;
|
||||
return encoded <= 0.04045f ? encoded / 12.92f
|
||||
: std::pow((encoded + 0.055f) / 1.055f, 2.4f);
|
||||
return encoded <= 0.04045f ? encoded / 12.92f : std::pow((encoded + 0.055f) / 1.055f, 2.4f);
|
||||
};
|
||||
switch (format) {
|
||||
case vk::Format::eR32Uint:
|
||||
next.uint32[0] = packed;
|
||||
break;
|
||||
case vk::Format::eR32Sint:
|
||||
next.int32[0] = static_cast<int32_t>(packed);
|
||||
break;
|
||||
case vk::Format::eR32Uint: next.uint32[0] = packed; break;
|
||||
case vk::Format::eR32Sint: next.int32[0] = static_cast<int32_t>(packed); break;
|
||||
case vk::Format::eR8G8B8A8Srgb:
|
||||
next.float32[0] = srgb8(packed);
|
||||
next.float32[1] = srgb8(packed >> 8u);
|
||||
|
||||
@@ -70,15 +70,14 @@ namespace {
|
||||
}
|
||||
case vk::ImageType::e3D:
|
||||
switch (info.type) {
|
||||
case vk::ImageViewType::e3D:
|
||||
return info.base_layer == 0 && info.layer_count == 1;
|
||||
case vk::ImageViewType::e3D: return info.base_layer == 0 && info.layer_count == 1;
|
||||
case vk::ImageViewType::e2D:
|
||||
return static_cast<bool>(
|
||||
image.flags & vk::ImageCreateFlagBits::e2DArrayCompatible) &&
|
||||
return static_cast<bool>(image.flags &
|
||||
vk::ImageCreateFlagBits::e2DArrayCompatible) &&
|
||||
info.level_count == 1 && info.layer_count == 1;
|
||||
case vk::ImageViewType::e2DArray:
|
||||
return static_cast<bool>(
|
||||
image.flags & vk::ImageCreateFlagBits::e2DArrayCompatible) &&
|
||||
return static_cast<bool>(image.flags &
|
||||
vk::ImageCreateFlagBits::e2DArrayCompatible) &&
|
||||
info.level_count == 1;
|
||||
default: return false;
|
||||
}
|
||||
@@ -327,8 +326,7 @@ bool FormatsCompatible(vk::Format base, vk::Format view) noexcept {
|
||||
vk::ImageView Image::FindView(const ImageViewInfo& view_info) {
|
||||
const auto& image = backing;
|
||||
auto normalized = view_info;
|
||||
const bool is_storage =
|
||||
static_cast<bool>(normalized.usage & vk::ImageUsageFlagBits::eStorage);
|
||||
const bool is_storage = static_cast<bool>(normalized.usage & vk::ImageUsageFlagBits::eStorage);
|
||||
normalized.aspect = FullAspectMask(image.format);
|
||||
if (normalized.aspect & vk::ImageAspectFlagBits::eDepth &&
|
||||
IsDepthViewFormat(normalized.format)) {
|
||||
@@ -340,12 +338,11 @@ vk::ImageView Image::FindView(const ImageViewInfo& view_info) {
|
||||
normalized.format = image.format;
|
||||
normalized.aspect = vk::ImageAspectFlagBits::eStencil;
|
||||
}
|
||||
normalized.usage =
|
||||
is_storage ? vk::ImageUsageFlagBits::eStorage : vk::ImageUsageFlags {};
|
||||
normalized.usage = is_storage ? vk::ImageUsageFlagBits::eStorage : vk::ImageUsageFlags {};
|
||||
const bool format_compatible = normalized.format != vk::Format::eUndefined &&
|
||||
IsCompatibleViewFormat(image.format, normalized.format);
|
||||
const bool slice_view = image.image_type == vk::ImageType::e3D &&
|
||||
(normalized.type == vk::ImageViewType::e2D ||
|
||||
const bool slice_view =
|
||||
image.image_type == vk::ImageType::e3D && (normalized.type == vk::ImageViewType::e2D ||
|
||||
normalized.type == vk::ImageViewType::e2DArray);
|
||||
const bool levels_valid = normalized.level_count != 0 &&
|
||||
normalized.base_level < image.mip_levels &&
|
||||
@@ -353,15 +350,14 @@ vk::ImageView Image::FindView(const ImageViewInfo& view_info) {
|
||||
const auto view_layers = slice_view && levels_valid
|
||||
? std::max(image.extent.depth >> normalized.base_level, 1u)
|
||||
: image.layers;
|
||||
const bool ranges_valid = levels_valid &&
|
||||
normalized.layer_count != 0 && normalized.base_layer < view_layers &&
|
||||
const bool ranges_valid = levels_valid && normalized.layer_count != 0 &&
|
||||
normalized.base_layer < view_layers &&
|
||||
normalized.layer_count <= view_layers - normalized.base_layer;
|
||||
const bool mapping_valid =
|
||||
IsComponentSwizzle(normalized.mapping.r) && IsComponentSwizzle(normalized.mapping.g) &&
|
||||
IsComponentSwizzle(normalized.mapping.b) && IsComponentSwizzle(normalized.mapping.a);
|
||||
if (image.image == nullptr || !format_compatible || !ranges_valid || !mapping_valid ||
|
||||
!IsValidViewType(image, normalized) ||
|
||||
!IsValidAspect(image, normalized.aspect)) {
|
||||
!IsValidViewType(image, normalized) || !IsValidAspect(image, normalized.aspect)) {
|
||||
EXIT("invalid image view: image_format=%d view_format=%d type=%d aspect=0x%x "
|
||||
"mip=%u+%u layer=%u+%u usage=0x%x image_levels=%u image_layers=%u\n",
|
||||
static_cast<int>(image.format), static_cast<int>(normalized.format),
|
||||
|
||||
@@ -397,10 +397,10 @@ TextureUploadLayout TextureCalcUploadLayout(uint32_t fmt, uint64_t width, uint64
|
||||
return layout;
|
||||
}
|
||||
|
||||
std::vector<vk::BufferImageCopy>
|
||||
TextureBuildImageCopies(const TextureUploadLayout& layout, uint32_t width, uint32_t height,
|
||||
uint32_t depth, uint64_t levels, bool array_texture,
|
||||
bool volume_texture) {
|
||||
std::vector<vk::BufferImageCopy> TextureBuildImageCopies(const TextureUploadLayout& layout,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t depth, uint64_t levels,
|
||||
bool array_texture, bool volume_texture) {
|
||||
uint32_t mip_width = width;
|
||||
uint32_t mip_height = height;
|
||||
uint32_t mip_pitch = volume_texture && static_cast<Prospero::TileMode>(layout.tile) !=
|
||||
@@ -418,10 +418,9 @@ TextureBuildImageCopies(const TextureUploadLayout& layout, uint32_t width, uint3
|
||||
for (uint32_t z = 0; z < mip_depth; z++) {
|
||||
const auto slice_offset = z * layout.slice_stride;
|
||||
vk::BufferImageCopy region {};
|
||||
region.bufferOffset =
|
||||
layout.level_sizes[i].offset + slice_offset;
|
||||
region.imageSubresource = {vk::ImageAspectFlagBits::eColor, i,
|
||||
array_texture ? z : 0, 1};
|
||||
region.bufferOffset = layout.level_sizes[i].offset + slice_offset;
|
||||
region.imageSubresource = {vk::ImageAspectFlagBits::eColor, i, array_texture ? z : 0,
|
||||
1};
|
||||
region.imageOffset.z = volume_texture ? static_cast<int>(z) : 0;
|
||||
region.imageExtent = {mip_width, mip_height, 1};
|
||||
const bool linear =
|
||||
@@ -434,8 +433,7 @@ TextureBuildImageCopies(const TextureUploadLayout& layout, uint32_t width, uint3
|
||||
return ((value + block - 1u) / block) * block;
|
||||
};
|
||||
const auto pitch = align(mip_pitch, layout.texel_block);
|
||||
region.bufferRowLength =
|
||||
pitch > align(mip_width, layout.texel_block) ? pitch : 0;
|
||||
region.bufferRowLength = pitch > align(mip_width, layout.texel_block) ? pitch : 0;
|
||||
}
|
||||
regions.push_back(region);
|
||||
}
|
||||
@@ -480,8 +478,7 @@ static bool SetGpuTileSize(uint64_t offset, uint64_t length, uint64_t capacity,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TextureBuildGpuTileInfos(uint64_t size,
|
||||
const std::vector<vk::BufferImageCopy>& regions,
|
||||
bool TextureBuildGpuTileInfos(uint64_t size, const std::vector<vk::BufferImageCopy>& regions,
|
||||
const TextureUploadLayout& layout, uint32_t fmt, uint32_t depth,
|
||||
uint64_t levels, std::vector<GpuTileInfo>& out_infos) {
|
||||
if (size == 0 || levels == 0 || levels > 16 || depth == 0 ||
|
||||
@@ -522,9 +519,8 @@ bool TextureBuildGpuTileInfos(uint64_t size,
|
||||
for (uint32_t z = 0; z < mip_depth; z += block.block_depth) {
|
||||
const uint32_t copy_depth = std::min(block.block_depth, mip_depth - z);
|
||||
const auto& region = regions[region_base + z];
|
||||
const auto pitch = region.bufferRowLength != 0
|
||||
? region.bufferRowLength
|
||||
: region.imageExtent.width;
|
||||
const auto pitch =
|
||||
region.bufferRowLength != 0 ? region.bufferRowLength : region.imageExtent.width;
|
||||
const auto logical_height = region.bufferImageHeight != 0
|
||||
? region.bufferImageHeight
|
||||
: region.imageExtent.height;
|
||||
@@ -544,16 +540,13 @@ bool TextureBuildGpuTileInfos(uint64_t size,
|
||||
return false;
|
||||
}
|
||||
info.linear_slice_stride = linear_stride;
|
||||
info.width = std::max(
|
||||
(region.imageExtent.width + element.wide - 1u) / element.wide, 1u);
|
||||
info.height = std::max(
|
||||
(logical_height + element.tall - 1u) / element.tall, 1u);
|
||||
info.width =
|
||||
std::max((region.imageExtent.width + element.wide - 1u) / element.wide, 1u);
|
||||
info.height = std::max((logical_height + element.tall - 1u) / element.tall, 1u);
|
||||
info.depth = copy_depth;
|
||||
info.surface_z = block.block_depth == 1
|
||||
? static_cast<uint32_t>(region.imageOffset.z)
|
||||
: 0;
|
||||
info.pitch =
|
||||
std::max((pitch + element.wide - 1u) / element.wide, 1u);
|
||||
info.surface_z =
|
||||
block.block_depth == 1 ? static_cast<uint32_t>(region.imageOffset.z) : 0;
|
||||
info.pitch = std::max((pitch + element.wide - 1u) / element.wide, 1u);
|
||||
info.tail_x = tail ? volume.tail_x[level] : 0;
|
||||
info.tail_y = tail ? volume.tail_y[level] : 0;
|
||||
info.tail = tail;
|
||||
@@ -581,9 +574,8 @@ bool TextureBuildGpuTileInfos(uint64_t size,
|
||||
const auto level_depth = GetTextureLevelDepth(depth, level, layout.volume_texture);
|
||||
for (uint32_t z = 0; z < level_depth; z++) {
|
||||
const auto& region = regions[region_index++];
|
||||
const auto pitch = region.bufferRowLength != 0
|
||||
? region.bufferRowLength
|
||||
: region.imageExtent.width;
|
||||
const auto pitch =
|
||||
region.bufferRowLength != 0 ? region.bufferRowLength : region.imageExtent.width;
|
||||
const auto logical_height = region.bufferImageHeight != 0
|
||||
? region.bufferImageHeight
|
||||
: region.imageExtent.height;
|
||||
@@ -597,16 +589,14 @@ bool TextureBuildGpuTileInfos(uint64_t size,
|
||||
info.tiled_size)) {
|
||||
return false;
|
||||
}
|
||||
info.width = std::max(
|
||||
(region.imageExtent.width + element.wide - 1u) / element.wide, 1u);
|
||||
info.height = std::max(
|
||||
(logical_height + element.tall - 1u) / element.tall, 1u);
|
||||
info.width =
|
||||
std::max((region.imageExtent.width + element.wide - 1u) / element.wide, 1u);
|
||||
info.height = std::max((logical_height + element.tall - 1u) / element.tall, 1u);
|
||||
info.surface_z = base_family == TileBlockFamily::RenderTarget64KB ||
|
||||
base_family == TileBlockFamily::Depth64KB
|
||||
? region.imageSubresource.baseArrayLayer
|
||||
: 0;
|
||||
info.pitch =
|
||||
std::max((pitch + element.wide - 1u) / element.wide, 1u);
|
||||
info.pitch = std::max((pitch + element.wide - 1u) / element.wide, 1u);
|
||||
info.tail = tail;
|
||||
info.tail_x = tail ? level_size.x : 0;
|
||||
info.tail_y = tail ? level_size.y : 0;
|
||||
|
||||
@@ -40,12 +40,11 @@ TextureUploadLayout TextureCalcUploadLayout(uint32_t fmt, uint64_t width, uint64
|
||||
uint64_t tile, uint64_t upload_size,
|
||||
bool allow_depth_tile, bool volume_texture,
|
||||
const char* owner);
|
||||
std::vector<vk::BufferImageCopy>
|
||||
TextureBuildImageCopies(const TextureUploadLayout& layout, uint32_t width, uint32_t height,
|
||||
uint32_t depth, uint64_t levels, bool array_texture,
|
||||
bool volume_texture);
|
||||
bool TextureBuildGpuTileInfos(uint64_t size,
|
||||
const std::vector<vk::BufferImageCopy>& regions,
|
||||
std::vector<vk::BufferImageCopy> TextureBuildImageCopies(const TextureUploadLayout& layout,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t depth, uint64_t levels,
|
||||
bool array_texture, bool volume_texture);
|
||||
bool TextureBuildGpuTileInfos(uint64_t size, const std::vector<vk::BufferImageCopy>& regions,
|
||||
const TextureUploadLayout& layout, uint32_t fmt, uint32_t depth,
|
||||
uint64_t levels, std::vector<GpuTileInfo>& infos);
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
#include "gpu_tiler_shaders/gpu_tiler_standard64_spv.h"
|
||||
#include "gpu_tiler_shaders/gpu_tiler_swap_bgra16_spv.h"
|
||||
#include "graphics/host_gpu/graphicContext.h"
|
||||
#include "graphics/host_gpu/renderer/cache/streamBuffer.h"
|
||||
#include "graphics/host_gpu/renderer/commandScheduler.h"
|
||||
#include "graphics/host_gpu/renderer/image/image.h"
|
||||
#include "graphics/host_gpu/renderer/cache/streamBuffer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
@@ -116,8 +116,8 @@ PipelineCache::GraphicsPipeline& PipelineCache::CreateGraphicsPipeline(
|
||||
if (attachment_samples == 0) {
|
||||
attachment_samples = depth.samples;
|
||||
} else if (attachment_samples != depth.samples) {
|
||||
EXIT("mixed color/depth sample counts are unsupported: %u and %u\n",
|
||||
attachment_samples, depth.samples);
|
||||
EXIT("mixed color/depth sample counts are unsupported: %u and %u\n", attachment_samples,
|
||||
depth.samples);
|
||||
}
|
||||
}
|
||||
EXIT_IF(attachment_samples == 0 ||
|
||||
@@ -203,9 +203,8 @@ PipelineCache::GraphicsPipeline& PipelineCache::CreateGraphicsPipeline(
|
||||
LogPipelineTrace("CreatePipelineInternal begin", vs_id.hash0, vs_id.crc32, ps_id.hash0,
|
||||
ps_id.crc32);
|
||||
CreatePipelineInternal(m_graphics, m_descriptor_cache, *cached, rendering, vs_input_info,
|
||||
vs_spirv, ps_input_info,
|
||||
ps_spirv, static_params, vs_id.hash0, vs_id.crc32, ps_id.hash0,
|
||||
ps_id.crc32, ps_active);
|
||||
vs_spirv, ps_input_info, ps_spirv, static_params, vs_id.hash0,
|
||||
vs_id.crc32, ps_id.hash0, ps_id.crc32, ps_active);
|
||||
LogPipelineTrace("CreatePipelineInternal done", vs_id.hash0, vs_id.crc32, ps_id.hash0,
|
||||
ps_id.crc32);
|
||||
|
||||
|
||||
@@ -118,11 +118,12 @@ public:
|
||||
ShaderId cs_shader_id;
|
||||
};
|
||||
|
||||
GraphicsPipeline& CreateGraphicsPipeline(
|
||||
RenderColorInfo* colors, uint32_t color_count, RenderDepthInfo& depth,
|
||||
GraphicsPipeline&
|
||||
CreateGraphicsPipeline(RenderColorInfo* colors, uint32_t color_count, RenderDepthInfo& depth,
|
||||
ShaderVertexInputInfo& vs_input_info, RenderCommandBuffer& command,
|
||||
ShaderPixelInputInfo* ps_input_info, vk::PrimitiveTopology topology, bool ps_active,
|
||||
std::span<const uint32_t> vs_spirv, std::span<const uint32_t> ps_spirv);
|
||||
ShaderPixelInputInfo* ps_input_info, vk::PrimitiveTopology topology,
|
||||
bool ps_active, std::span<const uint32_t> vs_spirv,
|
||||
std::span<const uint32_t> ps_spirv);
|
||||
ComputePipeline& CreateComputePipeline(ShaderComputeInputInfo& input_info,
|
||||
const HW::ComputeShaderInfo& cs_regs,
|
||||
std::span<const uint32_t> cs_spirv);
|
||||
@@ -211,16 +212,13 @@ private:
|
||||
|
||||
void LogPipelineTrace(const char* phase, uint32_t vs_hash0, uint32_t vs_crc32, uint32_t ps_hash0,
|
||||
uint32_t ps_crc32);
|
||||
void CreatePipelineInternal(GraphicContext& graphics, DescriptorCache& descriptor_cache,
|
||||
PipelineCache::GraphicsPipeline& pipeline,
|
||||
const PipelineRenderingState& rendering,
|
||||
const ShaderVertexInputInfo& vs_input_info,
|
||||
std::span<const uint32_t> vs_shader,
|
||||
const ShaderPixelInputInfo* ps_input_info,
|
||||
std::span<const uint32_t> ps_shader,
|
||||
const PipelineStaticParameters& static_params, uint32_t vs_hash0,
|
||||
uint32_t vs_crc32, uint32_t ps_hash0, uint32_t ps_crc32,
|
||||
bool ps_active);
|
||||
void CreatePipelineInternal(
|
||||
GraphicContext& graphics, DescriptorCache& descriptor_cache,
|
||||
PipelineCache::GraphicsPipeline& pipeline, const PipelineRenderingState& rendering,
|
||||
const ShaderVertexInputInfo& vs_input_info, std::span<const uint32_t> vs_shader,
|
||||
const ShaderPixelInputInfo* ps_input_info, std::span<const uint32_t> ps_shader,
|
||||
const PipelineStaticParameters& static_params, uint32_t vs_hash0, uint32_t vs_crc32,
|
||||
uint32_t ps_hash0, uint32_t ps_crc32, bool ps_active);
|
||||
void CreatePipelineInternal(GraphicContext& graphics, DescriptorCache& descriptor_cache,
|
||||
PipelineCache::ComputePipeline& pipeline,
|
||||
const ShaderComputeInputInfo& input_info,
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
#include "graphics/host_gpu/renderer/debug.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/descriptorCache.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/pipelineCache.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/shaderSubgroup.h"
|
||||
#include "graphics/host_gpu/renderer/render.h"
|
||||
#include "graphics/host_gpu/renderer/renderContext.h"
|
||||
#include "graphics/host_gpu/renderer/renderTarget.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/shaderSubgroup.h"
|
||||
#include "graphics/host_gpu/vulkanCommon.h"
|
||||
#include "graphics/shader/recompiler/ir/ShaderIR.h"
|
||||
#include "graphics/shader/shader.h"
|
||||
@@ -386,8 +386,7 @@ static vk::BlendOp GetBlendOp(uint32_t op) {
|
||||
}
|
||||
|
||||
static void CreateLayout(DescriptorCache& descriptor_cache,
|
||||
std::span<vk::DescriptorSetLayout> set_layouts,
|
||||
uint32_t& set_layouts_num,
|
||||
std::span<vk::DescriptorSetLayout> set_layouts, uint32_t& set_layouts_num,
|
||||
std::span<vk::PushConstantRange> push_constant_info,
|
||||
uint32_t& push_constant_info_num,
|
||||
const ShaderRecompiler::IR::Program& program,
|
||||
@@ -412,8 +411,7 @@ static void CreateLayout(DescriptorCache& descriptor_cache,
|
||||
}
|
||||
}
|
||||
|
||||
static void ConfigureSubgroupSize(const GraphicContext& graphics,
|
||||
vk::ShaderStageFlagBits vk_stage,
|
||||
static void ConfigureSubgroupSize(const GraphicContext& graphics, vk::ShaderStageFlagBits vk_stage,
|
||||
const ShaderRecompiler::IR::Program& program,
|
||||
vk::PipelineShaderStageRequiredSubgroupSizeCreateInfo& required,
|
||||
vk::PipelineShaderStageCreateInfo& stage) {
|
||||
@@ -456,16 +454,13 @@ static void ConfigureSubgroupSize(const GraphicContext&
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
|
||||
void CreatePipelineInternal(GraphicContext& graphics, DescriptorCache& descriptor_cache,
|
||||
PipelineCache::GraphicsPipeline& pipeline,
|
||||
const PipelineRenderingState& rendering,
|
||||
const ShaderVertexInputInfo& vs_input_info,
|
||||
std::span<const uint32_t> vs_shader,
|
||||
const ShaderPixelInputInfo* ps_input_info,
|
||||
std::span<const uint32_t> ps_shader,
|
||||
const PipelineStaticParameters& static_params, uint32_t vs_hash0,
|
||||
uint32_t vs_crc32, uint32_t ps_hash0, uint32_t ps_crc32,
|
||||
bool ps_active) {
|
||||
void CreatePipelineInternal(
|
||||
GraphicContext& graphics, DescriptorCache& descriptor_cache,
|
||||
PipelineCache::GraphicsPipeline& pipeline, const PipelineRenderingState& rendering,
|
||||
const ShaderVertexInputInfo& vs_input_info, std::span<const uint32_t> vs_shader,
|
||||
const ShaderPixelInputInfo* ps_input_info, std::span<const uint32_t> ps_shader,
|
||||
const PipelineStaticParameters& static_params, uint32_t vs_hash0, uint32_t vs_crc32,
|
||||
uint32_t ps_hash0, uint32_t ps_crc32, bool ps_active) {
|
||||
EXIT_IF(ps_active && ps_input_info == nullptr);
|
||||
|
||||
vk::ShaderModule vert_shader_module = nullptr;
|
||||
@@ -511,8 +506,7 @@ void CreatePipelineInternal(GraphicContext& graphics, DescriptorCache& descripto
|
||||
vert_shader_stage_info.pName = "main";
|
||||
vert_shader_stage_info.pSpecializationInfo = nullptr;
|
||||
EXIT_IF(!vs_input_info.stage);
|
||||
ConfigureSubgroupSize(graphics, vk::ShaderStageFlagBits::eVertex,
|
||||
*vs_input_info.stage.program,
|
||||
ConfigureSubgroupSize(graphics, vk::ShaderStageFlagBits::eVertex, *vs_input_info.stage.program,
|
||||
vert_subgroup_size, vert_shader_stage_info);
|
||||
|
||||
vk::PipelineShaderStageCreateInfo frag_shader_stage_info {};
|
||||
@@ -527,8 +521,8 @@ void CreatePipelineInternal(GraphicContext& graphics, DescriptorCache& descripto
|
||||
if (ps_active) {
|
||||
EXIT_IF(!ps_input_info->stage);
|
||||
ConfigureSubgroupSize(graphics, vk::ShaderStageFlagBits::eFragment,
|
||||
*ps_input_info->stage.program,
|
||||
frag_subgroup_size, frag_shader_stage_info);
|
||||
*ps_input_info->stage.program, frag_subgroup_size,
|
||||
frag_shader_stage_info);
|
||||
}
|
||||
|
||||
vk::PipelineShaderStageCreateInfo shader_stages[] = {vert_shader_stage_info,
|
||||
@@ -838,15 +832,13 @@ void CreatePipelineInternal(GraphicContext& graphics, DescriptorCache& descripto
|
||||
|
||||
EXIT_IF(!vs_input_info.stage);
|
||||
CreateLayout(descriptor_cache, set_layouts, set_layouts_num, push_constant_info,
|
||||
push_constant_info_num,
|
||||
*vs_input_info.stage.program, vk::ShaderStageFlagBits::eVertex,
|
||||
DescriptorCache::Stage::Vertex);
|
||||
push_constant_info_num, *vs_input_info.stage.program,
|
||||
vk::ShaderStageFlagBits::eVertex, DescriptorCache::Stage::Vertex);
|
||||
if (ps_active) {
|
||||
EXIT_IF(!ps_input_info->stage);
|
||||
CreateLayout(descriptor_cache, set_layouts, set_layouts_num, push_constant_info,
|
||||
push_constant_info_num,
|
||||
*ps_input_info->stage.program, vk::ShaderStageFlagBits::eFragment,
|
||||
DescriptorCache::Stage::Pixel);
|
||||
push_constant_info_num, *ps_input_info->stage.program,
|
||||
vk::ShaderStageFlagBits::eFragment, DescriptorCache::Stage::Pixel);
|
||||
}
|
||||
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info {};
|
||||
@@ -1012,8 +1004,7 @@ void CreatePipelineInternal(GraphicContext& graphics, DescriptorCache& descripto
|
||||
comp_shader_stage_info.pName = "main";
|
||||
comp_shader_stage_info.pSpecializationInfo = nullptr;
|
||||
EXIT_IF(!input_info.stage);
|
||||
ConfigureSubgroupSize(graphics, vk::ShaderStageFlagBits::eCompute,
|
||||
*input_info.stage.program,
|
||||
ConfigureSubgroupSize(graphics, vk::ShaderStageFlagBits::eCompute, *input_info.stage.program,
|
||||
comp_subgroup_size, comp_shader_stage_info);
|
||||
|
||||
vk::DescriptorSetLayout set_layouts[1] = {};
|
||||
@@ -1024,9 +1015,8 @@ void CreatePipelineInternal(GraphicContext& graphics, DescriptorCache& descripto
|
||||
|
||||
EXIT_IF(!input_info.stage);
|
||||
CreateLayout(descriptor_cache, set_layouts, set_layouts_num, push_constant_info,
|
||||
push_constant_info_num,
|
||||
*input_info.stage.program, vk::ShaderStageFlagBits::eCompute,
|
||||
DescriptorCache::Stage::Compute);
|
||||
push_constant_info_num, *input_info.stage.program,
|
||||
vk::ShaderStageFlagBits::eCompute, DescriptorCache::Stage::Compute);
|
||||
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info {};
|
||||
pipeline_layout_info.sType = vk::StructureType::ePipelineLayoutCreateInfo;
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
#include "graphics/guest_gpu/graphicsRun.h"
|
||||
#include "graphics/guest_gpu/hardwareContext.h"
|
||||
#include "graphics/host_gpu/graphicContext.h"
|
||||
#include "graphics/host_gpu/renderer/image/imageInfo.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/descriptorCache.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/descriptors.h"
|
||||
#include "graphics/host_gpu/renderer/image/imageInfo.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/pipelineCache.h"
|
||||
#include "graphics/host_gpu/renderer/render.h"
|
||||
#include "graphics/host_gpu/renderer/renderContext.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/shaderSubgroup.h"
|
||||
#include "graphics/host_gpu/renderer/render.h"
|
||||
#include "graphics/host_gpu/renderer/renderContext.h"
|
||||
#include "graphics/host_gpu/vulkanCommon.h"
|
||||
#include "graphics/shader/recompiler/ir/ResourceMaterialization.h"
|
||||
#include "graphics/shader/recompiler/ir/ShaderIR.h"
|
||||
|
||||
@@ -14,8 +14,7 @@ namespace Libs::Graphics {
|
||||
RenderContext::RenderContext(GraphicContext& graphics)
|
||||
: m_graphics(graphics), m_render_executor(*this), m_command_scheduler(*this, graphics),
|
||||
m_descriptor_cache(graphics), m_pipeline_cache(graphics, m_descriptor_cache),
|
||||
m_sampler_cache(graphics),
|
||||
m_gpu_resources(graphics, m_command_scheduler) {
|
||||
m_sampler_cache(graphics), m_gpu_resources(graphics, m_command_scheduler) {
|
||||
EXIT_NOT_IMPLEMENTED(!Common::Thread::IsMainThread());
|
||||
}
|
||||
|
||||
@@ -99,8 +98,7 @@ void RenderContext::TriggerEopEvent(uint32_t context_id) {
|
||||
registration.eq, static_cast<uintptr_t>(registration.id),
|
||||
LibKernel::EventQueue::KERNEL_EVFILT_GRAPHICS,
|
||||
reinterpret_cast<void*>(static_cast<uintptr_t>(context_id)));
|
||||
if (result == LibKernel::KERNEL_ERROR_EBADF ||
|
||||
result == LibKernel::KERNEL_ERROR_ENOENT) {
|
||||
if (result == LibKernel::KERNEL_ERROR_EBADF || result == LibKernel::KERNEL_ERROR_ENOENT) {
|
||||
DeleteEopEq(registration.eq, registration.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
#include "common/common.h"
|
||||
#include "common/threads.h"
|
||||
#include "graphics/host_gpu/renderer/cache/bufferCache.h"
|
||||
#include "graphics/host_gpu/renderer/commandScheduler.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/descriptorCache.h"
|
||||
#include "graphics/host_gpu/renderer/cache/gpuResourceManager.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/pipelineCache.h"
|
||||
#include "graphics/host_gpu/renderer/cache/samplerCache.h"
|
||||
#include "graphics/host_gpu/renderer/cache/textureCache.h"
|
||||
#include "graphics/host_gpu/renderer/commandScheduler.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/descriptorCache.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/pipelineCache.h"
|
||||
#include "kernel/eventQueue.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -252,8 +252,8 @@ uint64_t PrepareVideoOutFlip(CommandBuffer& buffer, int handle, int index, int f
|
||||
for (;;) {
|
||||
uint64_t request_id = 0;
|
||||
auto& video_out = buffer.GetContext().GetVideoOut();
|
||||
const auto result = video_out.SubmitFlipFromGpu(
|
||||
buffer, handle, index, flip_mode, flip_arg, request_id);
|
||||
const auto result =
|
||||
video_out.SubmitFlipFromGpu(buffer, handle, index, flip_mode, flip_arg, request_id);
|
||||
if (result == OK) {
|
||||
EXIT_IF(request_id == 0);
|
||||
return request_id;
|
||||
|
||||
@@ -122,8 +122,8 @@ uint64_t GraphicContext::GetDeviceMemoryUsage() const {
|
||||
physical_device_properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu;
|
||||
uint64_t usage = 0;
|
||||
for (uint32_t heap = 0; heap < physical_device_memory_properties.memoryHeapCount; heap++) {
|
||||
const bool device_local = static_cast<bool>(
|
||||
physical_device_memory_properties.memoryHeaps[heap].flags &
|
||||
const bool device_local =
|
||||
static_cast<bool>(physical_device_memory_properties.memoryHeaps[heap].flags &
|
||||
vk::MemoryHeapFlagBits::eDeviceLocal);
|
||||
if (!discrete || device_local) {
|
||||
usage += budgets[heap].usage;
|
||||
@@ -160,8 +160,7 @@ uint64_t GraphicContext::GetTotalMemoryBudget() const {
|
||||
}
|
||||
constexpr uint64_t system_reserve = 8ull * 1024 * 1024 * 1024;
|
||||
const auto available = budget > usage ? budget - usage : uint64_t {0};
|
||||
return std::max(local,
|
||||
available > system_reserve ? available - system_reserve : uint64_t {0});
|
||||
return std::max(local, available > system_reserve ? available - system_reserve : uint64_t {0});
|
||||
}
|
||||
|
||||
void GraphicContext::CreateBuffer(uint64_t size, VulkanBuffer& buffer) {
|
||||
|
||||
@@ -359,9 +359,9 @@ static void TriggerVideoOutEvents(VideoOutConfig& video_out, VideoOutEventKind k
|
||||
if (!registration || registration->generation != video_out.generation) {
|
||||
continue;
|
||||
}
|
||||
const auto result = EventQueue::KernelTriggerEvent(
|
||||
registration->handle, VideoOutEventId(kind), EventQueue::KERNEL_EVFILT_VIDEO_OUT,
|
||||
trigger_data);
|
||||
const auto result =
|
||||
EventQueue::KernelTriggerEvent(registration->handle, VideoOutEventId(kind),
|
||||
EventQueue::KERNEL_EVFILT_VIDEO_OUT, trigger_data);
|
||||
EXIT_NOT_IMPLEMENTED(result != OK && result != LibKernel::KERNEL_ERROR_EBADF &&
|
||||
result != LibKernel::KERNEL_ERROR_ENOENT);
|
||||
}
|
||||
@@ -372,9 +372,8 @@ static void DeleteVideoOutEvents(const VideoOutEventQueues& queues, VideoOutEven
|
||||
if (!registration) {
|
||||
continue;
|
||||
}
|
||||
const auto result =
|
||||
EventQueue::KernelDeleteEvent(registration->handle, VideoOutEventId(kind),
|
||||
EventQueue::KERNEL_EVFILT_VIDEO_OUT);
|
||||
const auto result = EventQueue::KernelDeleteEvent(
|
||||
registration->handle, VideoOutEventId(kind), EventQueue::KERNEL_EVFILT_VIDEO_OUT);
|
||||
EXIT_NOT_IMPLEMENTED(result != OK && result != LibKernel::KERNEL_ERROR_EBADF &&
|
||||
result != LibKernel::KERNEL_ERROR_ENOENT);
|
||||
}
|
||||
@@ -425,17 +424,15 @@ static int RegisterVideoOutEvent(int handle, EventQueue::KernelEqueue eq, VideoO
|
||||
bool add_queue = false;
|
||||
{
|
||||
Common::LockGuard event_lock(event_state->mutex);
|
||||
const auto existing = std::find_if(queues.begin(), queues.end(), [&](const auto& candidate) {
|
||||
const auto existing =
|
||||
std::find_if(queues.begin(), queues.end(), [&](const auto& candidate) {
|
||||
return candidate->handle == eq && candidate->generation == generation;
|
||||
});
|
||||
if (existing != queues.end()) {
|
||||
registration = *existing;
|
||||
} else {
|
||||
registration = std::make_shared<VideoOutEventRegistration>(
|
||||
VideoOutEventRegistration {.handle = eq,
|
||||
.state = event_state,
|
||||
.generation = generation,
|
||||
.kind = kind});
|
||||
registration = std::make_shared<VideoOutEventRegistration>(VideoOutEventRegistration {
|
||||
.handle = eq, .state = event_state, .generation = generation, .kind = kind});
|
||||
queues.push_back(registration);
|
||||
add_queue = true;
|
||||
}
|
||||
@@ -814,8 +811,8 @@ void VideoOutDriver::Impl::PresentThread(std::stop_token token) {
|
||||
m_presenter.Present(*frame, true);
|
||||
}
|
||||
const auto frame_end = Common::Timer::QueryPerformanceCounter();
|
||||
total_wait += static_cast<int64_t>(period) -
|
||||
static_cast<int64_t>(frame_end - frame_begin);
|
||||
total_wait +=
|
||||
static_cast<int64_t>(period) - static_cast<int64_t>(frame_end - frame_begin);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -841,8 +838,7 @@ void VideoOutDriver::Impl::PresentThread(std::stop_token token) {
|
||||
VblankEnd();
|
||||
|
||||
const auto frame_end = Common::Timer::QueryPerformanceCounter();
|
||||
total_wait += static_cast<int64_t>(period) -
|
||||
static_cast<int64_t>(frame_end - frame_begin);
|
||||
total_wait += static_cast<int64_t>(period) - static_cast<int64_t>(frame_end - frame_begin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1000,8 +996,8 @@ void FlipQueue::Prepare(uint64_t request_id, Graphics::CommandBuffer& buffer) {
|
||||
}
|
||||
Graphics::Presenter::Frame* frame = nullptr;
|
||||
if (special) {
|
||||
frame = &m_presenter.PrepareBlankFrame(width, height,
|
||||
index == VIDEO_OUT_BUFFER_INDEX_BLACK, &buffer);
|
||||
frame = &m_presenter.PrepareBlankFrame(width, height, index == VIDEO_OUT_BUFFER_INDEX_BLACK,
|
||||
&buffer);
|
||||
} else {
|
||||
frame = &m_presenter.PrepareFrame(buffer, source_info);
|
||||
}
|
||||
|
||||
@@ -206,21 +206,18 @@ private:
|
||||
vk::Format m_format = vk::Format::eUndefined;
|
||||
};
|
||||
|
||||
void Presenter::Frame::Configure(GraphicContext& graphics, vk::Extent2D extent,
|
||||
vk::Format format) {
|
||||
void Presenter::Frame::Configure(GraphicContext& graphics, vk::Extent2D extent, vk::Format format) {
|
||||
if (extent.width == 0 || extent.height == 0 || format == vk::Format::eUndefined) {
|
||||
EXIT("unsupported prepared frame, extent=%ux%u format=%d\n", extent.width, extent.height,
|
||||
static_cast<int>(format));
|
||||
}
|
||||
const auto features = graphics.GetFormatProperties(format).optimalTilingFeatures;
|
||||
const auto required = vk::FormatFeatureFlagBits::eBlitSrc |
|
||||
vk::FormatFeatureFlagBits::eSampledImageFilterLinear |
|
||||
vk::FormatFeatureFlagBits::eTransferSrc |
|
||||
vk::FormatFeatureFlagBits::eTransferDst;
|
||||
const auto required =
|
||||
vk::FormatFeatureFlagBits::eBlitSrc | vk::FormatFeatureFlagBits::eSampledImageFilterLinear |
|
||||
vk::FormatFeatureFlagBits::eTransferSrc | vk::FormatFeatureFlagBits::eTransferDst;
|
||||
if ((features & required) != required) {
|
||||
EXIT("prepared presentation format lacks optimal blit support: format=%d features=0x%x\n",
|
||||
static_cast<int>(format),
|
||||
static_cast<vk::FormatFeatureFlags::MaskType>(features));
|
||||
static_cast<int>(format), static_cast<vk::FormatFeatureFlags::MaskType>(features));
|
||||
}
|
||||
|
||||
auto& dst = image;
|
||||
@@ -267,8 +264,7 @@ void Presenter::Frame::Transit(vk::CommandBuffer command, vk::ImageLayout layout
|
||||
? vk::PipelineStageFlagBits2::eTransfer
|
||||
: vk::PipelineStageFlagBits2::eAllCommands;
|
||||
constexpr auto writes = vk::AccessFlagBits2::eTransferWrite |
|
||||
vk::AccessFlagBits2::eShaderWrite |
|
||||
vk::AccessFlagBits2::eMemoryWrite;
|
||||
vk::AccessFlagBits2::eShaderWrite | vk::AccessFlagBits2::eMemoryWrite;
|
||||
if (image.state.layout == layout && image.state.access_mask == access &&
|
||||
!static_cast<bool>(image.state.access_mask & writes)) {
|
||||
return;
|
||||
@@ -299,35 +295,27 @@ void Presenter::Frame::Transit(vk::CommandBuffer command, vk::ImageLayout layout
|
||||
void Presenter::Frame::CopyFrom(CommandBuffer& command_buffer, Image& source) {
|
||||
command_buffer.EndRendering();
|
||||
auto command = command_buffer.Handle();
|
||||
source.Transit(vk::ImageLayout::eTransferSrcOptimal,
|
||||
vk::AccessFlagBits2::eTransferRead, {}, command);
|
||||
Transit(command, vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::AccessFlagBits2::eTransferWrite);
|
||||
source.Transit(vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead, {},
|
||||
command);
|
||||
Transit(command, vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite);
|
||||
vk::ImageCopy copy {};
|
||||
copy.srcSubresource = {vk::ImageAspectFlagBits::eColor, 0, 0,
|
||||
source.backing.layers};
|
||||
copy.srcSubresource = {vk::ImageAspectFlagBits::eColor, 0, 0, source.backing.layers};
|
||||
copy.dstSubresource = {vk::ImageAspectFlagBits::eColor, 0, 0, image.layers};
|
||||
copy.extent = {std::min(source.backing.extent.width, image.extent.width),
|
||||
std::min(source.backing.extent.height, image.extent.height), 1};
|
||||
EXIT_IF(copy.srcSubresource.layerCount != copy.dstSubresource.layerCount);
|
||||
command.copyImage(source.backing.image, vk::ImageLayout::eTransferSrcOptimal,
|
||||
image.image, vk::ImageLayout::eTransferDstOptimal, copy);
|
||||
Transit(command, vk::ImageLayout::eTransferSrcOptimal,
|
||||
vk::AccessFlagBits2::eTransferRead);
|
||||
command.copyImage(source.backing.image, vk::ImageLayout::eTransferSrcOptimal, image.image,
|
||||
vk::ImageLayout::eTransferDstOptimal, copy);
|
||||
Transit(command, vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead);
|
||||
}
|
||||
|
||||
void Presenter::Frame::Clear(CommandBuffer& command_buffer,
|
||||
const vk::ClearColorValue& color) {
|
||||
void Presenter::Frame::Clear(CommandBuffer& command_buffer, const vk::ClearColorValue& color) {
|
||||
command_buffer.EndRendering();
|
||||
auto command = command_buffer.Handle();
|
||||
Transit(command, vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::AccessFlagBits2::eTransferWrite);
|
||||
const vk::ImageSubresourceRange range {
|
||||
vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1};
|
||||
command.clearColorImage(image.image, vk::ImageLayout::eTransferDstOptimal, &color, 1,
|
||||
&range);
|
||||
Transit(command, vk::ImageLayout::eTransferSrcOptimal,
|
||||
vk::AccessFlagBits2::eTransferRead);
|
||||
Transit(command, vk::ImageLayout::eTransferDstOptimal, vk::AccessFlagBits2::eTransferWrite);
|
||||
const vk::ImageSubresourceRange range {vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1};
|
||||
command.clearColorImage(image.image, vk::ImageLayout::eTransferDstOptimal, &color, 1, &range);
|
||||
Transit(command, vk::ImageLayout::eTransferSrcOptimal, vk::AccessFlagBits2::eTransferRead);
|
||||
}
|
||||
|
||||
class Swapchain final {
|
||||
@@ -441,16 +429,12 @@ void Swapchain::Create() {
|
||||
? vk::CompositeAlphaFlagBitsKHR::eOpaque
|
||||
: vk::CompositeAlphaFlagBitsKHR::eInherit;
|
||||
|
||||
vk::SurfaceFormatKHR format {vk::Format::eR8G8B8A8Unorm,
|
||||
vk::ColorSpaceKHR::eSrgbNonlinear};
|
||||
if (surface.formats.size() != 1 ||
|
||||
surface.formats.front().format != vk::Format::eUndefined) {
|
||||
vk::SurfaceFormatKHR format {vk::Format::eR8G8B8A8Unorm, vk::ColorSpaceKHR::eSrgbNonlinear};
|
||||
if (surface.formats.size() != 1 || surface.formats.front().format != vk::Format::eUndefined) {
|
||||
const auto it = std::find_if(surface.formats.begin(), surface.formats.end(),
|
||||
[](const vk::SurfaceFormatKHR& candidate) {
|
||||
return candidate.format ==
|
||||
vk::Format::eB8G8R8A8Unorm ||
|
||||
candidate.format ==
|
||||
vk::Format::eR8G8B8A8Unorm;
|
||||
return candidate.format == vk::Format::eB8G8R8A8Unorm ||
|
||||
candidate.format == vk::Format::eR8G8B8A8Unorm;
|
||||
});
|
||||
if (it == surface.formats.end()) {
|
||||
EXIT("no supported UNORM swapchain format\n");
|
||||
@@ -458,8 +442,7 @@ void Swapchain::Create() {
|
||||
format = *it;
|
||||
}
|
||||
m_format = format.format;
|
||||
const auto swapchain_features =
|
||||
graphics.GetFormatProperties(m_format).optimalTilingFeatures;
|
||||
const auto swapchain_features = graphics.GetFormatProperties(m_format).optimalTilingFeatures;
|
||||
if (!static_cast<bool>(swapchain_features & vk::FormatFeatureFlagBits::eBlitDst)) {
|
||||
EXIT("swapchain format cannot be a blit destination: format=%d\n",
|
||||
static_cast<int>(m_format));
|
||||
@@ -503,8 +486,7 @@ void Swapchain::Create() {
|
||||
view.subresourceRange.baseMipLevel = 0;
|
||||
view.subresourceRange.layerCount = 1;
|
||||
view.subresourceRange.levelCount = 1;
|
||||
RequireVulkanSuccess(
|
||||
graphics.device.createImageView(&view, nullptr, &m_image_views[i]),
|
||||
RequireVulkanSuccess(graphics.device.createImageView(&view, nullptr, &m_image_views[i]),
|
||||
"vkCreateImageView");
|
||||
EXIT_IF(m_image_views[i] == nullptr);
|
||||
}
|
||||
@@ -683,10 +665,9 @@ void Swapchain::RecordPresentCommands(CommandBuffer& command, VulkanImage& sourc
|
||||
to_present.subresourceRange.levelCount = 1;
|
||||
to_present.subresourceRange.baseArrayLayer = 0;
|
||||
to_present.subresourceRange.layerCount = 1;
|
||||
vk_command.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::DependencyFlagBits::eByRegion, 0,
|
||||
nullptr, 0, nullptr, 1, &to_present);
|
||||
vk_command.pipelineBarrier(
|
||||
vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::DependencyFlagBits::eByRegion, 0, nullptr, 0, nullptr, 1, &to_present);
|
||||
command.End();
|
||||
}
|
||||
|
||||
@@ -752,8 +733,7 @@ Presenter::Frame& Presenter::PrepareFrame(CommandBuffer& buffer, const ImageInfo
|
||||
default: break;
|
||||
}
|
||||
frame->Configure(m_impl->window.graphic_ctx,
|
||||
{image.backing.extent.width, image.backing.extent.height},
|
||||
frame_format);
|
||||
{image.backing.extent.width, image.backing.extent.height}, frame_format);
|
||||
frame->CopyFrom(buffer, image);
|
||||
return *frame;
|
||||
}
|
||||
@@ -772,8 +752,7 @@ Presenter::Frame& Presenter::PrepareBlankFrame(uint32_t width, uint32_t height,
|
||||
frame->Clear(*producer, clear);
|
||||
} else {
|
||||
if (frame->present_commands == nullptr) {
|
||||
frame->present_commands =
|
||||
std::make_unique<CommandBuffer>(m_impl->present_scheduler);
|
||||
frame->present_commands = std::make_unique<CommandBuffer>(m_impl->present_scheduler);
|
||||
}
|
||||
auto& command = *frame->present_commands;
|
||||
command.WaitForFenceAndReset();
|
||||
@@ -830,8 +809,7 @@ void Presenter::Present(Frame& frame, bool reuse) {
|
||||
continue;
|
||||
}
|
||||
if (frame.present_commands == nullptr) {
|
||||
frame.present_commands =
|
||||
std::make_unique<CommandBuffer>(m_impl->present_scheduler);
|
||||
frame.present_commands = std::make_unique<CommandBuffer>(m_impl->present_scheduler);
|
||||
}
|
||||
{
|
||||
Common::LockGuard render_lock(m_impl->renderer.GetMutex());
|
||||
|
||||
@@ -32,11 +32,11 @@
|
||||
#include "graphics/host_gpu/vma.h"
|
||||
#include "graphics/host_gpu/vulkanCommon.h"
|
||||
#include "graphics/presentation/presenter.h"
|
||||
#include "kernel/memory.h"
|
||||
#include "graphics/presentation/renderDoc.h"
|
||||
#include "graphics/presentation/videoOut.h"
|
||||
#include "graphics/presentation/window.h"
|
||||
#include "graphics/presentation/window/windowInternal.h"
|
||||
#include "kernel/memory.h"
|
||||
#include "libs/controller.h"
|
||||
#include "loader/systemContent.h"
|
||||
|
||||
@@ -909,10 +909,9 @@ void WindowContext::CreateVulkan() {
|
||||
}
|
||||
surface = native_surface;
|
||||
|
||||
std::vector<const char*> device_extensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
||||
VK_EXT_DEPTH_CLIP_CONTROL_EXTENSION_NAME,
|
||||
VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME,
|
||||
"VK_KHR_maintenance1"};
|
||||
std::vector<const char*> device_extensions = {
|
||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_EXT_DEPTH_CLIP_CONTROL_EXTENSION_NAME,
|
||||
VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, "VK_KHR_maintenance1"};
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// MoltenVK lacks VK_EXT_depth_clip_enable and VK_EXT_color_write_enable; the renderer
|
||||
@@ -932,8 +931,8 @@ void WindowContext::CreateVulkan() {
|
||||
|
||||
uint32_t queue_family = static_cast<uint32_t>(-1);
|
||||
|
||||
VulkanFindPhysicalDevice(graphic_ctx.instance, surface, device_extensions,
|
||||
surface_capabilities, graphic_ctx.physical_device, queue_family);
|
||||
VulkanFindPhysicalDevice(graphic_ctx.instance, surface, device_extensions, surface_capabilities,
|
||||
graphic_ctx.physical_device, queue_family);
|
||||
|
||||
if (graphic_ctx.physical_device == nullptr) {
|
||||
EXIT("Could not find suitable device");
|
||||
@@ -949,9 +948,8 @@ void WindowContext::CreateVulkan() {
|
||||
auto available_extensions = EnumerateVulkan<vk::ExtensionProperties>(
|
||||
"vkEnumerateDeviceExtensionProperties",
|
||||
[&](uint32_t* count, vk::ExtensionProperties* values) {
|
||||
return graphic_ctx.physical_device.enumerateDeviceExtensionProperties(nullptr,
|
||||
count,
|
||||
values);
|
||||
return graphic_ctx.physical_device.enumerateDeviceExtensionProperties(
|
||||
nullptr, count, values);
|
||||
});
|
||||
|
||||
if (HasExtension(available_extensions, VK_EXT_MEMORY_BUDGET_EXTENSION_NAME)) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "graphics/presentation/window.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_events.h"
|
||||
@@ -40,6 +38,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -251,9 +250,7 @@ static void GameEventKeyboard(WindowLoopState& game, const EventKeyboard& key) {
|
||||
if (key.down) {
|
||||
switch (key.key_code) {
|
||||
case SDLK_ESCAPE: game.need_exit = true; break;
|
||||
case SDLK_SPACE:
|
||||
SetPause(game, !game.paused.load(std::memory_order_acquire));
|
||||
break;
|
||||
case SDLK_SPACE: SetPause(game, !game.paused.load(std::memory_order_acquire)); break;
|
||||
case SDLK_F1:
|
||||
if (!key.repeat) {
|
||||
RenderDocRequestCapture();
|
||||
@@ -390,7 +387,9 @@ void WindowContext::Resize(uint32_t new_width, uint32_t new_height) {
|
||||
void WindowContext::ProcessWindowEvent(const SDL_WindowEvent& event) {
|
||||
const auto& window_event = event;
|
||||
switch (window_event.event) {
|
||||
case SDL_WINDOWEVENT_SHOWN: LOGF("Window %" PRIu32 " shown\n", window_event.windowID); break;
|
||||
case SDL_WINDOWEVENT_SHOWN:
|
||||
LOGF("Window %" PRIu32 " shown\n", window_event.windowID);
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_HIDDEN:
|
||||
LOGF("Window %" PRIu32 " hidden\n", window_event.windowID);
|
||||
@@ -401,13 +400,13 @@ void WindowContext::ProcessWindowEvent(const SDL_WindowEvent& event) {
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_MOVED:
|
||||
LOGF("Window %" PRIu32 " moved to %" PRId32 ",%" PRId32 "\n",
|
||||
window_event.windowID, window_event.data1, window_event.data2);
|
||||
LOGF("Window %" PRIu32 " moved to %" PRId32 ",%" PRId32 "\n", window_event.windowID,
|
||||
window_event.data1, window_event.data2);
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
LOGF("Window %" PRIu32 " resized to %" PRId32 "x%" PRId32 "\n",
|
||||
window_event.windowID, window_event.data1, window_event.data2);
|
||||
LOGF("Window %" PRIu32 " resized to %" PRId32 "x%" PRId32 "\n", window_event.windowID,
|
||||
window_event.data1, window_event.data2);
|
||||
|
||||
LOGF("m: %d\n", static_cast<int>(SDL_ThreadID()));
|
||||
Resize(window_event.data1, window_event.data2);
|
||||
@@ -807,8 +806,7 @@ static void WindowCreate(WindowContext& context) {
|
||||
window_flags |= static_cast<uint32_t>(SDL_WINDOW_BORDERLESS);
|
||||
}
|
||||
#endif
|
||||
context.window =
|
||||
SDL_CreateWindow(KYTY_SDL_WINDOW_CAPTION, KYTY_SDL_WINDOWPOS_CENTERED,
|
||||
context.window = SDL_CreateWindow(KYTY_SDL_WINDOW_CAPTION, KYTY_SDL_WINDOWPOS_CENTERED,
|
||||
KYTY_SDL_WINDOWPOS_CENTERED, width, height, window_flags);
|
||||
|
||||
context.window_hidden = true;
|
||||
@@ -950,11 +948,11 @@ void WindowContext::UpdateTitle() {
|
||||
fps_frames = 0;
|
||||
}
|
||||
|
||||
auto fps = fmt::format("{}{}{}{}{}{}[{}] [{}], frame: {}, fps: {:f}", (has_title ? title : ""),
|
||||
auto fps =
|
||||
fmt::format("{}{}{}{}{}{}[{}] [{}], frame: {}, fps: {:f}", (has_title ? title : ""),
|
||||
(has_title ? ", " : ""), (has_title_id ? title_id : ""),
|
||||
(has_title_id ? ", " : ""), (has_app_ver ? app_ver : ""),
|
||||
(has_app_ver ? " " : ""), device_name, processor_name,
|
||||
frame_num, current_fps);
|
||||
(has_app_ver ? " " : ""), device_name, processor_name, frame_num, current_fps);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// AppKit traps on title changes off the main thread; fire-and-forget keeps present pacing.
|
||||
|
||||
@@ -38,8 +38,7 @@ struct WindowContext {
|
||||
~WindowContext();
|
||||
KYTY_CLASS_NO_COPY(WindowContext);
|
||||
|
||||
[[nodiscard]] static vk::PhysicalDeviceVulkan13Features
|
||||
RequiredVulkan13Features() noexcept;
|
||||
[[nodiscard]] static vk::PhysicalDeviceVulkan13Features RequiredVulkan13Features() noexcept;
|
||||
void CreateVulkan();
|
||||
void RecreateSurface();
|
||||
void RefreshSurfaceCapabilities();
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include "graphics/guest_gpu/graphicsRun.h"
|
||||
#include "graphics/guest_gpu/hardwareContext.h"
|
||||
#include "graphics/host_gpu/renderer/renderContext.h"
|
||||
#include "graphics/shader/recompiler/decompiler/ShaderDecoder.h"
|
||||
#include "graphics/shader/recompiler/ShaderRecompiler.h"
|
||||
#include "graphics/shader/recompiler/decompiler/ShaderDecoder.h"
|
||||
#include "graphics/shader/shaderVertexMetadata.h"
|
||||
#include "libs/errno.h"
|
||||
#include "spirv-tools/libspirv.h"
|
||||
@@ -828,8 +828,7 @@ static void ShaderGetStaticInputInfoPS(
|
||||
vs_info.stage.program != nullptr && !vs_info.stage.program->bindings.descriptors.empty()
|
||||
? 1
|
||||
: 0;
|
||||
ps_info.push_constant_offset =
|
||||
vs_info.stage.program != nullptr
|
||||
ps_info.push_constant_offset = vs_info.stage.program != nullptr
|
||||
? vs_info.stage.program->bindings.push_constant_offset +
|
||||
vs_info.stage.program->bindings.push_constant_size
|
||||
: 0;
|
||||
@@ -1294,8 +1293,7 @@ static void DumpShaderRecompilerSpirv(const char* type, uint64_t shader_hash,
|
||||
|
||||
static std::atomic_int id = 0;
|
||||
|
||||
const auto base_name =
|
||||
Config::GetShaderLogFolder() /
|
||||
const auto base_name = Config::GetShaderLogFolder() /
|
||||
fmt::format("{:04d}_new_shader_{}_{:016x}", id++, type, shader_hash);
|
||||
Common::File::CreateDirectories(base_name.parent_path());
|
||||
|
||||
@@ -1345,8 +1343,7 @@ static void DumpShaderRecompilerOriginal(const char* type, uint64_t shader_hash,
|
||||
|
||||
static std::atomic_int id = 0;
|
||||
|
||||
const auto base_name =
|
||||
Config::GetShaderLogFolder() / "original" /
|
||||
const auto base_name = Config::GetShaderLogFolder() / "original" /
|
||||
fmt::format("{:04d}_new_shader_{}_{:016x}", id++, type, shader_hash);
|
||||
Common::File::CreateDirectories(base_name.parent_path());
|
||||
|
||||
|
||||
@@ -459,8 +459,7 @@ int KYTY_SYSV_ABI KernelAddUserEvent(KernelEqueue eq, int id) {
|
||||
int KYTY_SYSV_ABI KernelAddUserEventEdge(KernelEqueue eq, int id) {
|
||||
PRINT_NAME();
|
||||
|
||||
LOGF("\t user event edge add: eq = 0x%016" PRIx64 ", id = %d\n", static_cast<uint64_t>(eq),
|
||||
id);
|
||||
LOGF("\t user event edge add: eq = 0x%016" PRIx64 ", id = %d\n", static_cast<uint64_t>(eq), id);
|
||||
|
||||
KernelEqueueEvent event {};
|
||||
event.event.ident = static_cast<uintptr_t>(id);
|
||||
@@ -507,8 +506,7 @@ int KYTY_SYSV_ABI KernelTriggerUserEventForAll(int id, void* udata) {
|
||||
int KYTY_SYSV_ABI KernelDeleteUserEvent(KernelEqueue eq, int id) {
|
||||
PRINT_NAME();
|
||||
|
||||
LOGF("\t user event delete: eq = 0x%016" PRIx64 ", id = %d\n", static_cast<uint64_t>(eq),
|
||||
id);
|
||||
LOGF("\t user event delete: eq = 0x%016" PRIx64 ", id = %d\n", static_cast<uint64_t>(eq), id);
|
||||
|
||||
return KernelDeleteEvent(eq, static_cast<uintptr_t>(id), KERNEL_EVFILT_USER);
|
||||
}
|
||||
@@ -577,8 +575,7 @@ int KYTY_SYSV_ABI KernelAddAmprSystemEvent(KernelEqueue eq, int id, void* udata)
|
||||
int KYTY_SYSV_ABI KernelDeleteAmprEvent(KernelEqueue eq, int id) {
|
||||
PRINT_NAME();
|
||||
|
||||
LOGF("\t AMPR event delete: eq = 0x%016" PRIx64 ", id = %d\n", static_cast<uint64_t>(eq),
|
||||
id);
|
||||
LOGF("\t AMPR event delete: eq = 0x%016" PRIx64 ", id = %d\n", static_cast<uint64_t>(eq), id);
|
||||
|
||||
if (eq != KERNEL_EQUEUE_INVALID) {
|
||||
(void)KernelDeleteEvent(eq, static_cast<uintptr_t>(id), KERNEL_EVFILT_USER);
|
||||
@@ -590,8 +587,8 @@ int KYTY_SYSV_ABI KernelDeleteAmprEvent(KernelEqueue eq, int id) {
|
||||
int KYTY_SYSV_ABI KernelDeleteAmprSystemEvent(KernelEqueue eq, int id) {
|
||||
PRINT_NAME();
|
||||
|
||||
LOGF("\t AMPR system event delete: eq = 0x%016" PRIx64 ", id = %d\n",
|
||||
static_cast<uint64_t>(eq), id);
|
||||
LOGF("\t AMPR system event delete: eq = 0x%016" PRIx64 ", id = %d\n", static_cast<uint64_t>(eq),
|
||||
id);
|
||||
|
||||
return KernelDeleteAmprEvent(eq, id);
|
||||
}
|
||||
|
||||
@@ -206,8 +206,8 @@ bool ConfigurationItem::operator<(const QTreeWidgetItem& other) const {
|
||||
GetStatusText(other_item->m_info->game_status);
|
||||
case GameVersionColumn:
|
||||
case FirmwareVersionColumn: {
|
||||
const auto& version = column == GameVersionColumn ? m_info->gameVersion
|
||||
: m_info->firmwareVer;
|
||||
const auto& version =
|
||||
column == GameVersionColumn ? m_info->gameVersion : m_info->firmwareVer;
|
||||
const auto& other_version = column == GameVersionColumn
|
||||
? other_item->m_info->gameVersion
|
||||
: other_item->m_info->firmwareVer;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "configurationListWidget.h"
|
||||
|
||||
#include "patchesDialog.h"
|
||||
#include "common.h"
|
||||
#include "compatibilityDatabase.h"
|
||||
#include "configuration.h"
|
||||
@@ -8,6 +7,7 @@
|
||||
#include "configurationItem.h"
|
||||
#include "gameListTreeWidget.h"
|
||||
#include "mainDialog.h"
|
||||
#include "patchesDialog.h"
|
||||
#include "trophyViewerDialog.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
@@ -272,10 +272,18 @@ static bool FindTerminal(QString* program, QStringList* prefix) {
|
||||
};
|
||||
|
||||
static const TerminalSpec candidates[] = {
|
||||
{"x-terminal-emulator", "-e"}, {"gnome-terminal", "--"}, {"konsole", "-e"},
|
||||
{"xfce4-terminal", "-x"}, {"mate-terminal", "--"}, {"tilix", "-e"},
|
||||
{"alacritty", "-e"}, {"kitty", nullptr}, {"foot", nullptr},
|
||||
{"wezterm", "-e"}, {"urxvt", "-e"}, {"xterm", "-e"},
|
||||
{"x-terminal-emulator", "-e"},
|
||||
{"gnome-terminal", "--"},
|
||||
{"konsole", "-e"},
|
||||
{"xfce4-terminal", "-x"},
|
||||
{"mate-terminal", "--"},
|
||||
{"tilix", "-e"},
|
||||
{"alacritty", "-e"},
|
||||
{"kitty", nullptr},
|
||||
{"foot", nullptr},
|
||||
{"wezterm", "-e"},
|
||||
{"urxvt", "-e"},
|
||||
{"xterm", "-e"},
|
||||
};
|
||||
|
||||
const auto try_candidate = [program, prefix](const QString& executable, const char* separator) {
|
||||
@@ -379,9 +387,9 @@ void MainDialog::RunInterpreter(QProcess* process, const Configuration& info) {
|
||||
#if !defined(_WIN32)
|
||||
// Report immediate launch failures.
|
||||
if (!process->waitForStarted(5000)) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Failed to start:\n%1\n\n%2")
|
||||
.arg(process->program(), process->errorString()));
|
||||
QMessageBox::critical(
|
||||
this, tr("Error"),
|
||||
tr("Failed to start:\n%1\n\n%2").arg(process->program(), process->errorString()));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -59,10 +59,8 @@ void PatchesDialog::Load() {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto patches = QJsonDocument::fromJson(file.readAll())
|
||||
.object()
|
||||
.value(QStringLiteral("patches"))
|
||||
.toArray();
|
||||
const auto patches =
|
||||
QJsonDocument::fromJson(file.readAll()).object().value(QStringLiteral("patches")).toArray();
|
||||
for (const auto& value: patches) {
|
||||
const auto patch = value.toObject();
|
||||
auto* item = new QListWidgetItem(patch.value(QStringLiteral("name")).toString(), m_patches);
|
||||
|
||||
@@ -439,7 +439,8 @@ int KYTY_SYSV_ABI SaveDataMount3(const SaveDataMount3* mount, SaveDataMountResul
|
||||
|
||||
Common::LockGuard lock(g_mount_mutex);
|
||||
const std::string dir_name = mount->dir_name->data;
|
||||
const std::string mount_dir = std::string(SAVE_DATA_DIR) + "/" + get_title_id() + "/" + dir_name;
|
||||
const std::string mount_dir =
|
||||
std::string(SAVE_DATA_DIR) + "/" + get_title_id() + "/" + dir_name;
|
||||
const bool create = ((mount->mount_mode & 4u) != 0);
|
||||
const bool create2 = ((mount->mount_mode & 32u) != 0);
|
||||
const bool open = (!create && !create2 && ((mount->mount_mode & 3u) != 0));
|
||||
@@ -595,7 +596,8 @@ int KYTY_SYSV_ABI SaveDataTransferringMount(const SaveDataTransferringMount* mou
|
||||
|
||||
Common::LockGuard lock(g_mount_mutex);
|
||||
const std::string dir_name = mount->dir_name->data;
|
||||
const std::string mount_dir = std::string(SAVE_DATA_DIR) + "/" + get_title_id() + "/" + dir_name;
|
||||
const std::string mount_dir =
|
||||
std::string(SAVE_DATA_DIR) + "/" + get_title_id() + "/" + dir_name;
|
||||
const int slot = g_mount_slots.FindAvailable(dir_name);
|
||||
if (slot == SaveDataMountSlots::BUSY) {
|
||||
return SAVE_DATA_ERROR_BUSY;
|
||||
|
||||
@@ -312,7 +312,9 @@ static bool DecodeShaNiInsn(const uint8_t* rip, ShaNiInsn& insn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ShaNiModrmIsRegister(uint8_t modrm) { return (modrm & 0xc0u) == 0xc0u; }
|
||||
static bool ShaNiModrmIsRegister(uint8_t modrm) {
|
||||
return (modrm & 0xc0u) == 0xc0u;
|
||||
}
|
||||
|
||||
static uint8_t ShaNiRegIndex(uint8_t modrm, uint8_t rex, bool reg_field) {
|
||||
if (reg_field) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "kernel/eventQueue.h"
|
||||
|
||||
#include "libs/errno.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -17,31 +16,27 @@ namespace EventQueue = Libs::LibKernel::EventQueue;
|
||||
using Libs::LibKernel::KERNEL_ERROR_EBADF;
|
||||
using Libs::LibKernel::KERNEL_ERROR_ENOENT;
|
||||
|
||||
void Check(bool value, const char *text) {
|
||||
void Check(bool value, const char* text) {
|
||||
if (!value) {
|
||||
std::fprintf(stderr, "EventQueueLifetimeTests: failed: %s\n", text);
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
void CheckConcurrentResult(int result, const char *text) {
|
||||
Check(result == OK || result == KERNEL_ERROR_EBADF ||
|
||||
result == KERNEL_ERROR_ENOENT,
|
||||
text);
|
||||
void CheckConcurrentResult(int result, const char* text) {
|
||||
Check(result == OK || result == KERNEL_ERROR_EBADF || result == KERNEL_ERROR_ENOENT, text);
|
||||
}
|
||||
|
||||
void CountDeletedEvent(EventQueue::KernelEqueue,
|
||||
EventQueue::KernelEqueueEvent *event) {
|
||||
auto *count = static_cast<std::atomic_uint32_t *>(event->filter.data);
|
||||
void CountDeletedEvent(EventQueue::KernelEqueue, EventQueue::KernelEqueueEvent* event) {
|
||||
auto* count = static_cast<std::atomic_uint32_t*>(event->filter.data);
|
||||
count->fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
struct DuplicateEventOwner {
|
||||
std::atomic_uint32_t delete_count{0};
|
||||
std::atomic_uint32_t delete_count {0};
|
||||
};
|
||||
|
||||
void QueueDuplicateEvent(EventQueue::KernelEqueueEvent *event,
|
||||
void *trigger_data) {
|
||||
void QueueDuplicateEvent(EventQueue::KernelEqueueEvent* event, void* trigger_data) {
|
||||
auto next = event->event;
|
||||
next.data = reinterpret_cast<intptr_t>(trigger_data);
|
||||
if (event->triggered) {
|
||||
@@ -52,18 +47,17 @@ void QueueDuplicateEvent(EventQueue::KernelEqueueEvent *event,
|
||||
}
|
||||
}
|
||||
|
||||
void ResetDuplicateEvent(EventQueue::KernelEqueueEvent *event) {
|
||||
void ResetDuplicateEvent(EventQueue::KernelEqueueEvent* event) {
|
||||
event->triggered = false;
|
||||
event->event.data = 0;
|
||||
}
|
||||
|
||||
void DeleteDuplicateEvent(EventQueue::KernelEqueue,
|
||||
EventQueue::KernelEqueueEvent *event) {
|
||||
auto *owner = static_cast<DuplicateEventOwner *>(event->filter.data);
|
||||
void DeleteDuplicateEvent(EventQueue::KernelEqueue, EventQueue::KernelEqueueEvent* event) {
|
||||
auto* owner = static_cast<DuplicateEventOwner*>(event->filter.data);
|
||||
owner->delete_count.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void PoisonDuplicateEvent(EventQueue::KernelEqueueEvent *, void *) {
|
||||
void PoisonDuplicateEvent(EventQueue::KernelEqueueEvent*, void*) {
|
||||
Check(false, "duplicate add replaced trigger callback");
|
||||
}
|
||||
|
||||
@@ -74,40 +68,36 @@ void TestDuplicateAddPreservesEventState() {
|
||||
|
||||
auto original_owner = std::make_shared<DuplicateEventOwner>();
|
||||
std::weak_ptr<DuplicateEventOwner> weak_original = original_owner;
|
||||
EventQueue::KernelEqueueEvent original{};
|
||||
EventQueue::KernelEqueueEvent original {};
|
||||
original.event.ident = 17;
|
||||
original.event.filter = EventQueue::KERNEL_EVFILT_VIDEO_OUT;
|
||||
original.event.udata = reinterpret_cast<void *>(0x1111);
|
||||
original.event.udata = reinterpret_cast<void*>(0x1111);
|
||||
original.filter.data = original_owner.get();
|
||||
original.filter.owner = original_owner;
|
||||
original.filter.trigger_func = QueueDuplicateEvent;
|
||||
original.filter.reset_func = ResetDuplicateEvent;
|
||||
original.filter.delete_event_func = DeleteDuplicateEvent;
|
||||
Check(EventQueue::KernelAddEvent(queue, original) == OK,
|
||||
"add original duplicate event");
|
||||
Check(EventQueue::KernelTriggerEvent(queue, 17,
|
||||
EventQueue::KERNEL_EVFILT_VIDEO_OUT,
|
||||
reinterpret_cast<void *>(0x1234)) == OK,
|
||||
Check(EventQueue::KernelAddEvent(queue, original) == OK, "add original duplicate event");
|
||||
Check(EventQueue::KernelTriggerEvent(queue, 17, EventQueue::KERNEL_EVFILT_VIDEO_OUT,
|
||||
reinterpret_cast<void*>(0x1234)) == OK,
|
||||
"queue first trigger");
|
||||
Check(EventQueue::KernelTriggerEvent(queue, 17,
|
||||
EventQueue::KERNEL_EVFILT_VIDEO_OUT,
|
||||
reinterpret_cast<void *>(0x5678)) == OK,
|
||||
Check(EventQueue::KernelTriggerEvent(queue, 17, EventQueue::KERNEL_EVFILT_VIDEO_OUT,
|
||||
reinterpret_cast<void*>(0x5678)) == OK,
|
||||
"queue pending trigger");
|
||||
|
||||
auto replacement_owner = std::make_shared<DuplicateEventOwner>();
|
||||
std::weak_ptr<DuplicateEventOwner> weak_replacement = replacement_owner;
|
||||
EventQueue::KernelEqueueEvent duplicate{};
|
||||
EventQueue::KernelEqueueEvent duplicate {};
|
||||
duplicate.triggered = false;
|
||||
duplicate.deadline_ns = 1;
|
||||
duplicate.event.ident = 17;
|
||||
duplicate.event.filter = EventQueue::KERNEL_EVFILT_VIDEO_OUT;
|
||||
duplicate.event.data = 0x7fffffff;
|
||||
duplicate.event.udata = reinterpret_cast<void *>(0x2222);
|
||||
duplicate.event.udata = reinterpret_cast<void*>(0x2222);
|
||||
duplicate.filter.data = replacement_owner.get();
|
||||
duplicate.filter.owner = replacement_owner;
|
||||
duplicate.filter.trigger_func = PoisonDuplicateEvent;
|
||||
Check(EventQueue::KernelAddEvent(queue, duplicate) == OK,
|
||||
"update duplicate event");
|
||||
Check(EventQueue::KernelAddEvent(queue, duplicate) == OK, "update duplicate event");
|
||||
|
||||
duplicate.filter.owner.reset();
|
||||
replacement_owner.reset();
|
||||
@@ -116,7 +106,7 @@ void TestDuplicateAddPreservesEventState() {
|
||||
original_owner.reset();
|
||||
Check(!weak_original.expired(), "original event owner remains retained");
|
||||
|
||||
EventQueue::KernelEvent events[2]{};
|
||||
EventQueue::KernelEvent events[2] {};
|
||||
int out = 0;
|
||||
Libs::LibKernel::KernelUseconds timeout = 0;
|
||||
Check(EventQueue::KernelWaitEqueue(queue, events, 2, &out, &timeout) == OK,
|
||||
@@ -124,32 +114,26 @@ void TestDuplicateAddPreservesEventState() {
|
||||
Check(out == 2, "duplicate add preserves pending event count");
|
||||
Check(events[0].data == 0x1234 && events[1].data == 0x5678,
|
||||
"duplicate add preserves current and pending event data");
|
||||
Check(events[0].udata == reinterpret_cast<void *>(0x2222),
|
||||
Check(events[0].udata == reinterpret_cast<void*>(0x2222),
|
||||
"duplicate add updates current user data");
|
||||
Check(events[1].udata == reinterpret_cast<void *>(0x2222),
|
||||
Check(events[1].udata == reinterpret_cast<void*>(0x2222),
|
||||
"duplicate add updates pending user data");
|
||||
|
||||
EventQueue::KernelEvent timer_event{};
|
||||
Check(EventQueue::KernelWaitEqueue(queue, &timer_event, 1, &out, &timeout) ==
|
||||
OK &&
|
||||
out == 1,
|
||||
EventQueue::KernelEvent timer_event {};
|
||||
Check(EventQueue::KernelWaitEqueue(queue, &timer_event, 1, &out, &timeout) == OK && out == 1,
|
||||
"duplicate add updates deadline metadata");
|
||||
Check(timer_event.data == 0 &&
|
||||
timer_event.udata == reinterpret_cast<void *>(0x2222),
|
||||
Check(timer_event.data == 0 && timer_event.udata == reinterpret_cast<void*>(0x2222),
|
||||
"deadline trigger retains updated duplicate metadata");
|
||||
|
||||
auto retained_owner = weak_original.lock();
|
||||
Check(retained_owner != nullptr, "original owner alive before delete");
|
||||
Check(EventQueue::KernelDeleteEvent(queue, 17,
|
||||
EventQueue::KERNEL_EVFILT_VIDEO_OUT) ==
|
||||
OK,
|
||||
Check(EventQueue::KernelDeleteEvent(queue, 17, EventQueue::KERNEL_EVFILT_VIDEO_OUT) == OK,
|
||||
"delete duplicate event");
|
||||
Check(retained_owner->delete_count.load(std::memory_order_relaxed) == 1,
|
||||
"duplicate add preserves delete callback");
|
||||
retained_owner.reset();
|
||||
Check(weak_original.expired(), "original owner released on delete");
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == OK,
|
||||
"delete duplicate add queue");
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == OK, "delete duplicate add queue");
|
||||
}
|
||||
|
||||
struct SimulatedVideoOutEventState;
|
||||
@@ -161,25 +145,21 @@ struct SimulatedVideoOutRegistration {
|
||||
};
|
||||
|
||||
struct SimulatedVideoOutEventState {
|
||||
SimulatedVideoOutEventState(std::atomic_uint32_t &stage,
|
||||
std::atomic_uint32_t &destroy_count)
|
||||
SimulatedVideoOutEventState(std::atomic_uint32_t& stage, std::atomic_uint32_t& destroy_count)
|
||||
: stage(stage), destroy_count(destroy_count) {}
|
||||
|
||||
~SimulatedVideoOutEventState() {
|
||||
destroy_count.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
~SimulatedVideoOutEventState() { destroy_count.fetch_add(1, std::memory_order_relaxed); }
|
||||
|
||||
std::mutex mutex;
|
||||
std::vector<std::shared_ptr<SimulatedVideoOutRegistration>> queues;
|
||||
std::atomic_uint32_t &stage;
|
||||
std::atomic_uint32_t &destroy_count;
|
||||
std::atomic_uint32_t& stage;
|
||||
std::atomic_uint32_t& destroy_count;
|
||||
uint64_t marker = 0xfedcba9876543210ull;
|
||||
};
|
||||
|
||||
void DetachSimulatedVideoOutEvent(EventQueue::KernelEqueue queue,
|
||||
EventQueue::KernelEqueueEvent *event) {
|
||||
auto *registration =
|
||||
static_cast<SimulatedVideoOutRegistration *>(event->filter.data);
|
||||
EventQueue::KernelEqueueEvent* event) {
|
||||
auto* registration = static_cast<SimulatedVideoOutRegistration*>(event->filter.data);
|
||||
Check(registration != nullptr && registration->handle == queue,
|
||||
"simulated registration identity");
|
||||
auto state = registration->state;
|
||||
@@ -191,18 +171,15 @@ void DetachSimulatedVideoOutEvent(EventQueue::KernelEqueue queue,
|
||||
|
||||
{
|
||||
std::lock_guard lock(state->mutex);
|
||||
const auto entry =
|
||||
std::find_if(state->queues.begin(), state->queues.end(),
|
||||
[registration](const auto &candidate) {
|
||||
return candidate.get() == registration;
|
||||
});
|
||||
const auto entry = std::find_if(
|
||||
state->queues.begin(), state->queues.end(),
|
||||
[registration](const auto& candidate) { return candidate.get() == registration; });
|
||||
if (entry != state->queues.end()) {
|
||||
state->queues.erase(entry);
|
||||
}
|
||||
}
|
||||
event->filter.owner.reset();
|
||||
Check(state->marker == 0xfedcba9876543210ull &&
|
||||
registration->marker == 0x123456789abcdef0ull,
|
||||
Check(state->marker == 0xfedcba9876543210ull && registration->marker == 0x123456789abcdef0ull,
|
||||
"callback state survives simulated port destruction");
|
||||
}
|
||||
|
||||
@@ -211,31 +188,27 @@ void TestCallbackStateOutlivesPort() {
|
||||
Check(EventQueue::KernelCreateEqueue(&queue, "shared-port-state") == OK,
|
||||
"create shared port state queue");
|
||||
|
||||
std::atomic_uint32_t stage{0};
|
||||
std::atomic_uint32_t destroy_count{0};
|
||||
auto port_state =
|
||||
std::make_shared<SimulatedVideoOutEventState>(stage, destroy_count);
|
||||
std::atomic_uint32_t stage {0};
|
||||
std::atomic_uint32_t destroy_count {0};
|
||||
auto port_state = std::make_shared<SimulatedVideoOutEventState>(stage, destroy_count);
|
||||
std::weak_ptr<SimulatedVideoOutEventState> weak_state = port_state;
|
||||
auto registration = std::make_shared<SimulatedVideoOutRegistration>();
|
||||
std::weak_ptr<SimulatedVideoOutRegistration> weak_registration =
|
||||
registration;
|
||||
std::weak_ptr<SimulatedVideoOutRegistration> weak_registration = registration;
|
||||
registration->handle = queue;
|
||||
registration->state = port_state;
|
||||
port_state->queues.push_back(registration);
|
||||
|
||||
EventQueue::KernelEqueueEvent event{};
|
||||
EventQueue::KernelEqueueEvent event {};
|
||||
event.event.ident = 8;
|
||||
event.event.filter = EventQueue::KERNEL_EVFILT_VIDEO_OUT;
|
||||
event.filter.data = registration.get();
|
||||
event.filter.owner = registration;
|
||||
event.filter.delete_event_func = DetachSimulatedVideoOutEvent;
|
||||
Check(EventQueue::KernelAddEvent(queue, event) == OK,
|
||||
"add shared port state event");
|
||||
Check(EventQueue::KernelAddEvent(queue, event) == OK, "add shared port state event");
|
||||
event.filter.owner.reset();
|
||||
|
||||
std::jthread close([&] {
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == OK,
|
||||
"delete shared port state queue");
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == OK, "delete shared port state queue");
|
||||
});
|
||||
while (stage.load(std::memory_order_acquire) != 1) {
|
||||
std::this_thread::yield();
|
||||
@@ -249,10 +222,8 @@ void TestCallbackStateOutlivesPort() {
|
||||
registration.reset();
|
||||
detached.clear();
|
||||
port_state.reset();
|
||||
Check(!weak_state.expired(),
|
||||
"callback state outlives simulated port object");
|
||||
Check(!weak_registration.expired(),
|
||||
"registration outlives simulated port object");
|
||||
Check(!weak_state.expired(), "callback state outlives simulated port object");
|
||||
Check(!weak_registration.expired(), "registration outlives simulated port object");
|
||||
|
||||
stage.store(2, std::memory_order_release);
|
||||
close.join();
|
||||
@@ -263,35 +234,29 @@ void TestCallbackStateOutlivesPort() {
|
||||
}
|
||||
|
||||
struct OwnedCallbackPayload {
|
||||
OwnedCallbackPayload(std::atomic_uint32_t &stage,
|
||||
std::atomic_uint32_t &delete_count,
|
||||
std::atomic_uint32_t &destroy_count)
|
||||
OwnedCallbackPayload(std::atomic_uint32_t& stage, std::atomic_uint32_t& delete_count,
|
||||
std::atomic_uint32_t& destroy_count)
|
||||
: stage(stage), delete_count(delete_count), destroy_count(destroy_count) {}
|
||||
|
||||
std::atomic_uint32_t &stage;
|
||||
std::atomic_uint32_t &delete_count;
|
||||
std::atomic_uint32_t &destroy_count;
|
||||
std::atomic_uint32_t& stage;
|
||||
std::atomic_uint32_t& delete_count;
|
||||
std::atomic_uint32_t& destroy_count;
|
||||
uint64_t marker = 0xc0dec0dec0dec0deull;
|
||||
|
||||
~OwnedCallbackPayload() {
|
||||
destroy_count.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
~OwnedCallbackPayload() { destroy_count.fetch_add(1, std::memory_order_relaxed); }
|
||||
};
|
||||
|
||||
void DeleteOwnedEvent(EventQueue::KernelEqueue queue,
|
||||
EventQueue::KernelEqueueEvent *event) {
|
||||
auto *payload = static_cast<OwnedCallbackPayload *>(event->filter.data);
|
||||
void DeleteOwnedEvent(EventQueue::KernelEqueue queue, EventQueue::KernelEqueueEvent* event) {
|
||||
auto* payload = static_cast<OwnedCallbackPayload*>(event->filter.data);
|
||||
Check(payload != nullptr, "owned callback payload");
|
||||
Check(!EventQueue::KernelPinEqueue(queue),
|
||||
"owned callback runs after registry removal");
|
||||
Check(!EventQueue::KernelPinEqueue(queue), "owned callback runs after registry removal");
|
||||
payload->delete_count.fetch_add(1, std::memory_order_relaxed);
|
||||
event->filter.owner.reset();
|
||||
payload->stage.store(1, std::memory_order_release);
|
||||
while (payload->stage.load(std::memory_order_acquire) != 2) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
Check(payload->marker == 0xc0dec0dec0dec0deull,
|
||||
"owned callback payload remains valid");
|
||||
Check(payload->marker == 0xc0dec0dec0dec0deull, "owned callback payload remains valid");
|
||||
}
|
||||
|
||||
void TestCallbackOwnsPayload() {
|
||||
@@ -299,29 +264,24 @@ void TestCallbackOwnsPayload() {
|
||||
Check(EventQueue::KernelCreateEqueue(&queue, "owned-callback") == OK,
|
||||
"create owned callback queue");
|
||||
|
||||
std::atomic_uint32_t stage{0};
|
||||
std::atomic_uint32_t delete_count{0};
|
||||
std::atomic_uint32_t destroy_count{0};
|
||||
auto registration =
|
||||
std::make_shared<OwnedCallbackPayload>(stage, delete_count, destroy_count);
|
||||
std::atomic_uint32_t stage {0};
|
||||
std::atomic_uint32_t delete_count {0};
|
||||
std::atomic_uint32_t destroy_count {0};
|
||||
auto registration = std::make_shared<OwnedCallbackPayload>(stage, delete_count, destroy_count);
|
||||
std::weak_ptr<OwnedCallbackPayload> weak_registration = registration;
|
||||
std::vector<std::shared_ptr<OwnedCallbackPayload>> port_registrations{
|
||||
registration};
|
||||
std::vector<std::shared_ptr<OwnedCallbackPayload>> port_registrations {registration};
|
||||
{
|
||||
EventQueue::KernelEqueueEvent event{};
|
||||
EventQueue::KernelEqueueEvent event {};
|
||||
event.event.ident = 2;
|
||||
event.event.filter = EventQueue::KERNEL_EVFILT_VIDEO_OUT;
|
||||
event.filter.data = registration.get();
|
||||
event.filter.owner = registration;
|
||||
event.filter.delete_event_func = DeleteOwnedEvent;
|
||||
Check(EventQueue::KernelAddEvent(queue, event) == OK,
|
||||
"add owned callback event");
|
||||
Check(EventQueue::KernelAddEvent(queue, event) == OK, "add owned callback event");
|
||||
}
|
||||
|
||||
std::jthread close([&] {
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == OK,
|
||||
"delete owned callback queue");
|
||||
});
|
||||
std::jthread close(
|
||||
[&] { Check(EventQueue::KernelDeleteEqueue(queue) == OK, "delete owned callback queue"); });
|
||||
while (stage.load(std::memory_order_acquire) != 1) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
@@ -330,26 +290,22 @@ void TestCallbackOwnsPayload() {
|
||||
"owned callback queue removed while callback blocked");
|
||||
port_registrations.clear();
|
||||
registration.reset();
|
||||
Check(!weak_registration.expired(),
|
||||
"delete callback retains detached payload");
|
||||
Check(!weak_registration.expired(), "delete callback retains detached payload");
|
||||
|
||||
stage.store(2, std::memory_order_release);
|
||||
close.join();
|
||||
Check(delete_count.load(std::memory_order_relaxed) == 1,
|
||||
"owned callback runs exactly once");
|
||||
Check(weak_registration.expired(),
|
||||
"owned callback payload released with event");
|
||||
Check(delete_count.load(std::memory_order_relaxed) == 1, "owned callback runs exactly once");
|
||||
Check(weak_registration.expired(), "owned callback payload released with event");
|
||||
Check(destroy_count.load(std::memory_order_relaxed) == 1,
|
||||
"owned callback payload destroyed exactly once");
|
||||
}
|
||||
|
||||
void TestPinnedClose() {
|
||||
EventQueue::KernelEqueue queue = EventQueue::KERNEL_EQUEUE_INVALID;
|
||||
Check(EventQueue::KernelCreateEqueue(&queue, "pinned-close") == OK,
|
||||
"create pinned queue");
|
||||
Check(EventQueue::KernelCreateEqueue(&queue, "pinned-close") == OK, "create pinned queue");
|
||||
|
||||
std::atomic_uint32_t delete_count{0};
|
||||
EventQueue::KernelEqueueEvent event{};
|
||||
std::atomic_uint32_t delete_count {0};
|
||||
EventQueue::KernelEqueueEvent event {};
|
||||
event.event.ident = 1;
|
||||
event.event.filter = EventQueue::KERNEL_EVFILT_VIDEO_OUT;
|
||||
event.filter.data = &delete_count;
|
||||
@@ -359,12 +315,10 @@ void TestPinnedClose() {
|
||||
auto owner = EventQueue::KernelPinEqueue(queue);
|
||||
Check(owner != nullptr, "pin live queue");
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == OK, "delete pinned queue");
|
||||
Check(delete_count.load(std::memory_order_relaxed) == 1,
|
||||
"close invokes callback once");
|
||||
Check(delete_count.load(std::memory_order_relaxed) == 1, "close invokes callback once");
|
||||
Check(!EventQueue::KernelPinEqueue(queue), "deleted queue leaves registry");
|
||||
Check(EventQueue::KernelTriggerEvent(queue, 1,
|
||||
EventQueue::KERNEL_EVFILT_VIDEO_OUT,
|
||||
nullptr) == KERNEL_ERROR_EBADF,
|
||||
Check(EventQueue::KernelTriggerEvent(queue, 1, EventQueue::KERNEL_EVFILT_VIDEO_OUT, nullptr) ==
|
||||
KERNEL_ERROR_EBADF,
|
||||
"stale trigger rejected");
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == KERNEL_ERROR_EBADF,
|
||||
"second queue delete rejected");
|
||||
@@ -376,8 +330,7 @@ void TestPinnedClose() {
|
||||
|
||||
void TestStaleHandleNeverAliasesNewQueue() {
|
||||
EventQueue::KernelEqueue stale = EventQueue::KERNEL_EQUEUE_INVALID;
|
||||
Check(EventQueue::KernelCreateEqueue(&stale, "stale-handle") == OK,
|
||||
"create stale queue");
|
||||
Check(EventQueue::KernelCreateEqueue(&stale, "stale-handle") == OK, "create stale queue");
|
||||
Check(EventQueue::KernelDeleteEqueue(stale) == OK, "delete stale queue");
|
||||
|
||||
EventQueue::KernelEqueue replacement = EventQueue::KERNEL_EQUEUE_INVALID;
|
||||
@@ -389,13 +342,11 @@ void TestStaleHandleNeverAliasesNewQueue() {
|
||||
"stale handle cannot mutate replacement");
|
||||
Check(EventQueue::KernelAddUserEvent(replacement, 11) == OK,
|
||||
"replacement handle remains valid");
|
||||
Check(EventQueue::KernelTriggerUserEvent(stale, 11, nullptr) ==
|
||||
KERNEL_ERROR_EBADF,
|
||||
Check(EventQueue::KernelTriggerUserEvent(stale, 11, nullptr) == KERNEL_ERROR_EBADF,
|
||||
"stale handle cannot trigger replacement");
|
||||
Check(EventQueue::KernelTriggerUserEvent(replacement, 11, nullptr) == OK,
|
||||
"replacement event triggers");
|
||||
Check(EventQueue::KernelDeleteEqueue(replacement) == OK,
|
||||
"delete replacement queue");
|
||||
Check(EventQueue::KernelDeleteEqueue(replacement) == OK, "delete replacement queue");
|
||||
}
|
||||
|
||||
void TestConcurrentCloseCallback() {
|
||||
@@ -404,31 +355,28 @@ void TestConcurrentCloseCallback() {
|
||||
Check(EventQueue::KernelCreateEqueue(&queue, "callback-race") == OK,
|
||||
"create callback race queue");
|
||||
|
||||
std::atomic_uint32_t delete_count{0};
|
||||
EventQueue::KernelEqueueEvent callback_event{};
|
||||
std::atomic_uint32_t delete_count {0};
|
||||
EventQueue::KernelEqueueEvent callback_event {};
|
||||
callback_event.event.ident = 9;
|
||||
callback_event.event.filter = EventQueue::KERNEL_EVFILT_GRAPHICS;
|
||||
callback_event.filter.data = &delete_count;
|
||||
callback_event.filter.delete_event_func = CountDeletedEvent;
|
||||
Check(EventQueue::KernelAddEvent(queue, callback_event) == OK,
|
||||
"add callback race event");
|
||||
Check(EventQueue::KernelAddEvent(queue, callback_event) == OK, "add callback race event");
|
||||
|
||||
std::atomic_bool start{false};
|
||||
std::atomic_bool start {false};
|
||||
std::jthread trigger([&] {
|
||||
while (!start.load(std::memory_order_acquire)) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
for (uint32_t i = 0; i < 256; i++) {
|
||||
CheckConcurrentResult(
|
||||
EventQueue::KernelTriggerEvent(
|
||||
CheckConcurrentResult(EventQueue::KernelTriggerEvent(
|
||||
queue, 9, EventQueue::KERNEL_EVFILT_GRAPHICS, nullptr),
|
||||
"callback race trigger result");
|
||||
}
|
||||
});
|
||||
|
||||
start.store(true, std::memory_order_release);
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == OK,
|
||||
"callback race queue delete");
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == OK, "callback race queue delete");
|
||||
trigger.join();
|
||||
Check(delete_count.load(std::memory_order_relaxed) == 1,
|
||||
"concurrent close invokes callback exactly once");
|
||||
@@ -440,13 +388,12 @@ void TestConcurrentDelete() {
|
||||
EventQueue::KernelEqueue queue = EventQueue::KERNEL_EQUEUE_INVALID;
|
||||
Check(EventQueue::KernelCreateEqueue(&queue, "concurrent-delete") == OK,
|
||||
"create concurrent queue");
|
||||
EventQueue::KernelEqueueEvent event{};
|
||||
EventQueue::KernelEqueueEvent event {};
|
||||
event.event.ident = 7;
|
||||
event.event.filter = EventQueue::KERNEL_EVFILT_USER;
|
||||
Check(EventQueue::KernelAddEvent(queue, event) == OK,
|
||||
"add concurrent event");
|
||||
Check(EventQueue::KernelAddEvent(queue, event) == OK, "add concurrent event");
|
||||
|
||||
std::atomic_bool start{false};
|
||||
std::atomic_bool start {false};
|
||||
std::jthread mutate([&] {
|
||||
while (!start.load(std::memory_order_acquire)) {
|
||||
std::this_thread::yield();
|
||||
@@ -454,12 +401,11 @@ void TestConcurrentDelete() {
|
||||
for (uint32_t i = 0; i < 64; i++) {
|
||||
CheckConcurrentResult(EventQueue::KernelAddEvent(queue, event),
|
||||
"concurrent add result");
|
||||
CheckConcurrentResult(
|
||||
EventQueue::KernelTriggerEvent(
|
||||
CheckConcurrentResult(EventQueue::KernelTriggerEvent(
|
||||
queue, 7, EventQueue::KERNEL_EVFILT_USER, nullptr),
|
||||
"concurrent trigger result");
|
||||
CheckConcurrentResult(EventQueue::KernelDeleteEvent(
|
||||
queue, 7, EventQueue::KERNEL_EVFILT_USER),
|
||||
CheckConcurrentResult(
|
||||
EventQueue::KernelDeleteEvent(queue, 7, EventQueue::KERNEL_EVFILT_USER),
|
||||
"concurrent event delete result");
|
||||
}
|
||||
});
|
||||
@@ -468,20 +414,17 @@ void TestConcurrentDelete() {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
for (uint32_t i = 0; i < 128; i++) {
|
||||
CheckConcurrentResult(
|
||||
EventQueue::KernelTriggerEvent(
|
||||
CheckConcurrentResult(EventQueue::KernelTriggerEvent(
|
||||
queue, 7, EventQueue::KERNEL_EVFILT_USER, nullptr),
|
||||
"parallel trigger result");
|
||||
}
|
||||
});
|
||||
|
||||
start.store(true, std::memory_order_release);
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == OK,
|
||||
"concurrent queue delete");
|
||||
Check(EventQueue::KernelDeleteEqueue(queue) == OK, "concurrent queue delete");
|
||||
mutate.join();
|
||||
trigger.join();
|
||||
Check(!EventQueue::KernelPinEqueue(queue),
|
||||
"concurrent queue removed from registry");
|
||||
Check(!EventQueue::KernelPinEqueue(queue), "concurrent queue removed from registry");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,23 +24,26 @@ void TestMultiOwnerAndExactErase() {
|
||||
owners.push_back(11);
|
||||
owners.push_back(22);
|
||||
|
||||
Check(table.Find(17) != nullptr && table.Find(17)->size() == 2, "both page owners are retained");
|
||||
Check(table.Find(17) != nullptr && table.Find(17)->size() == 2,
|
||||
"both page owners are retained");
|
||||
Check(Libs::Graphics::EraseExact(owners, 11U), "registered owner is erased");
|
||||
Check(owners.size() == 1 && owners.front() == 22, "erasing one owner preserves its neighbor");
|
||||
Check(!Libs::Graphics::EraseExact(owners, 33U), "missing owner is reported without mutation");
|
||||
}
|
||||
|
||||
void TestCrossBucketRange() {
|
||||
Table::PageRange range{};
|
||||
constexpr uint64_t bucket_boundary = uint64_t{Table::kBucketEntries} << Table::kPageBits;
|
||||
Table::PageRange range {};
|
||||
constexpr uint64_t bucket_boundary = uint64_t {Table::kBucketEntries} << Table::kPageBits;
|
||||
Check(Table::TryGetPageRange(bucket_boundary - 1, 2, range), "cross-bucket range is valid");
|
||||
Check(range.first == Table::kBucketEntries - 1 && range.last_exclusive == Table::kBucketEntries + 1,
|
||||
Check(range.first == Table::kBucketEntries - 1 &&
|
||||
range.last_exclusive == Table::kBucketEntries + 1,
|
||||
"cross-bucket range covers both pages");
|
||||
|
||||
Table table;
|
||||
table[range.first].push_back(1);
|
||||
table[range.last_exclusive - 1].push_back(2);
|
||||
Check(table.AllocatedBucketCount() == 2, "pages across the L1 boundary use distinct sparse buckets");
|
||||
Check(table.AllocatedBucketCount() == 2,
|
||||
"pages across the L1 boundary use distinct sparse buckets");
|
||||
}
|
||||
|
||||
void TestQueriesDoNotAllocate() {
|
||||
@@ -55,27 +58,34 @@ void TestQueriesDoNotAllocate() {
|
||||
}
|
||||
|
||||
void TestAddressSpaceBoundaries() {
|
||||
Table::PageRange range{};
|
||||
Check(Table::TryGetPageRange(Table::kAddressSpaceSize - 1, 1, range), "last guest byte is valid");
|
||||
Table::PageRange range {};
|
||||
Check(Table::TryGetPageRange(Table::kAddressSpaceSize - 1, 1, range),
|
||||
"last guest byte is valid");
|
||||
Check(range.first == Table::kPageCount - 1 && range.last_exclusive == Table::kPageCount,
|
||||
"last guest byte maps to the final page");
|
||||
Check(!Table::TryGetPageRange(0, 0, range), "empty ranges are rejected");
|
||||
Check(!Table::TryGetPageRange(Table::kAddressSpaceSize, 1, range), "first out-of-range byte is rejected");
|
||||
Check(!Table::TryGetPageRange(Table::kAddressSpaceSize - 1, 2, range), "crossing the address-space end is rejected");
|
||||
Check(!Table::TryGetPageRange(Table::kAddressSpaceSize, 1, range),
|
||||
"first out-of-range byte is rejected");
|
||||
Check(!Table::TryGetPageRange(Table::kAddressSpaceSize - 1, 2, range),
|
||||
"crossing the address-space end is rejected");
|
||||
Check(!Table::TryGetPageRange(UINT64_MAX - 1, 4, range), "wrapping input is rejected");
|
||||
|
||||
Table table;
|
||||
table.GetOrCreate(Table::kPageCount - 1).push_back(99);
|
||||
Check(table.Find(Table::kPageCount - 1) != nullptr && table.Find(Table::kPageCount - 1)->front() == 99,
|
||||
Check(table.Find(Table::kPageCount - 1) != nullptr &&
|
||||
table.Find(Table::kPageCount - 1)->front() == 99,
|
||||
"final page supports allocating and nonallocating access");
|
||||
}
|
||||
|
||||
void TestMultiRangeRegistrationDeduplicatesPages() {
|
||||
OwnerIndex index;
|
||||
// Depth and stencil-like planes overlap tracking pages and share one 1 MiB bucket.
|
||||
Check(index.Register(7, {{0x101000, 0x2800}, {0x102000, 0x3000}}), "multi-range owner registers");
|
||||
Check(index.CoarseMembershipCount(1) == 1, "one owner is inserted once in a shared 1 MiB bucket");
|
||||
Check(index.TrackingMembershipCount(0x102) == 1, "overlapping planes insert one 4 KiB membership");
|
||||
Check(index.Register(7, {{0x101000, 0x2800}, {0x102000, 0x3000}}),
|
||||
"multi-range owner registers");
|
||||
Check(index.CoarseMembershipCount(1) == 1,
|
||||
"one owner is inserted once in a shared 1 MiB bucket");
|
||||
Check(index.TrackingMembershipCount(0x102) == 1,
|
||||
"overlapping planes insert one 4 KiB membership");
|
||||
Check(!index.Register(7, {{0x101000, 0x1000}}), "duplicate owner registration hard-fails");
|
||||
|
||||
const auto owners = index.Query(0x100000, 0x10000);
|
||||
@@ -84,8 +94,9 @@ void TestMultiRangeRegistrationDeduplicatesPages() {
|
||||
|
||||
void TestSharedPageUnregisterLifecycle() {
|
||||
OwnerIndex index;
|
||||
const std::vector<OwnerIndex::ByteRange> ranges{{0x202000, 0x2000}};
|
||||
Check(index.Register(11, ranges) && index.Register(22, ranges), "two owners register on identical pages");
|
||||
const std::vector<OwnerIndex::ByteRange> ranges {{0x202000, 0x2000}};
|
||||
Check(index.Register(11, ranges) && index.Register(22, ranges),
|
||||
"two owners register on identical pages");
|
||||
Check(index.CoarseMembershipCount(2) == 2 && index.TrackingMembershipCount(0x202) == 2,
|
||||
"coarse and tracking pages retain both owners");
|
||||
|
||||
@@ -97,7 +108,8 @@ void TestSharedPageUnregisterLifecycle() {
|
||||
Check(!index.Unregister(11, releases), "missing membership hard-fails without mutation");
|
||||
|
||||
Check(index.Unregister(22, releases), "final owner unregisters");
|
||||
Check(releases.size() == 1 && releases.front().address == 0x202000 && releases.front().size == 0x2000,
|
||||
Check(releases.size() == 1 && releases.front().address == 0x202000 &&
|
||||
releases.front().size == 0x2000,
|
||||
"adjacent final-owner tracking pages return one contiguous release");
|
||||
}
|
||||
|
||||
@@ -105,14 +117,19 @@ void TestStrictByteFilteringAndPredicate() {
|
||||
OwnerIndex index;
|
||||
Check(index.Register(31, {{0x300100, 0x100}}), "first byte-disjoint owner registers");
|
||||
Check(index.Register(32, {{0x300800, 0x100}}), "second byte-disjoint owner registers");
|
||||
Check(index.TrackingMembershipCount(0x300) == 2, "byte-disjoint owners share one tracking page");
|
||||
Check(index.TrackingMembershipCount(0x300) == 2,
|
||||
"byte-disjoint owners share one tracking page");
|
||||
Check(index.Query(0x300400, 0x40).empty(), "page hit without byte overlap is filtered out");
|
||||
const auto page_candidates = index.QueryCandidates(0x300400, 0x40);
|
||||
Check(page_candidates.size() == 2, "fault candidate query retains byte-disjoint owners on the touched page");
|
||||
Check(page_candidates.size() == 2,
|
||||
"fault candidate query retains byte-disjoint owners on the touched page");
|
||||
const auto first = index.Query(0x300180, 0x10);
|
||||
Check(first.size() == 1 && first.front() == 31, "strict byte overlap selects only the matching owner");
|
||||
const auto predicate_filtered = index.Query(0x300000, 0x1000, [](uint32_t owner) { return owner == 32; });
|
||||
Check(predicate_filtered.size() == 1 && predicate_filtered.front() == 32, "supplied predicate filters query owners");
|
||||
Check(first.size() == 1 && first.front() == 31,
|
||||
"strict byte overlap selects only the matching owner");
|
||||
const auto predicate_filtered =
|
||||
index.Query(0x300000, 0x1000, [](uint32_t owner) { return owner == 32; });
|
||||
Check(predicate_filtered.size() == 1 && predicate_filtered.front() == 32,
|
||||
"supplied predicate filters query owners");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
+236
-322
File diff suppressed because it is too large.
Load diff
+121
-169
@@ -1,5 +1,5 @@
|
||||
#include "graphics/host_gpu/pageManager.h"
|
||||
#include "common/virtualMemory.h"
|
||||
#include "graphics/host_gpu/pageManager.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
@@ -32,7 +32,7 @@ namespace {
|
||||
using Libs::Graphics::PageFaultAccess;
|
||||
using Libs::Graphics::PageManager;
|
||||
|
||||
void Check(bool value, const char *text) {
|
||||
void Check(bool value, const char* text) {
|
||||
if (!value) {
|
||||
std::fprintf(stderr, "PageManagerTests: failed: %s\n", text);
|
||||
std::abort();
|
||||
@@ -49,25 +49,22 @@ constexpr uint32_t MEM_RELEASE = 0;
|
||||
|
||||
int ToHostProt(uint32_t protection) {
|
||||
switch (protection) {
|
||||
case PAGE_NOACCESS:
|
||||
return PROT_NONE;
|
||||
case PAGE_READONLY:
|
||||
return PROT_READ;
|
||||
default:
|
||||
return PROT_READ | PROT_WRITE;
|
||||
case PAGE_NOACCESS: return PROT_NONE;
|
||||
case PAGE_READONLY: return PROT_READ;
|
||||
default: return PROT_READ | PROT_WRITE;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Protection(const void *address) {
|
||||
uint32_t Protection(const void* address) {
|
||||
const auto addr = reinterpret_cast<uintptr_t>(address);
|
||||
std::FILE *maps = std::fopen("/proc/self/maps", "r");
|
||||
std::FILE* maps = std::fopen("/proc/self/maps", "r");
|
||||
Check(maps != nullptr, "open /proc/self/maps failed");
|
||||
char line[512];
|
||||
uint32_t result = 0; // 0 => not mapped at all
|
||||
while (std::fgets(line, sizeof(line), maps) != nullptr) {
|
||||
unsigned long start = 0;
|
||||
unsigned long end = 0;
|
||||
char perms[8]{};
|
||||
char perms[8] {};
|
||||
if (std::sscanf(line, "%lx-%lx %7s", &start, &end, perms) != 3) {
|
||||
continue;
|
||||
}
|
||||
@@ -82,16 +79,18 @@ uint32_t Protection(const void *address) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IsWritable(const void *address) { return Protection(address) == PAGE_READWRITE; }
|
||||
bool IsWritable(const void* address) {
|
||||
return Protection(address) == PAGE_READWRITE;
|
||||
}
|
||||
|
||||
// munmap needs the length that VirtualFree's callers pass as 0, so sizes are remembered here.
|
||||
std::map<void *, size_t> &AllocationSizes() {
|
||||
static std::map<void *, size_t> sizes;
|
||||
std::map<void*, size_t>& AllocationSizes() {
|
||||
static std::map<void*, size_t> sizes;
|
||||
return sizes;
|
||||
}
|
||||
|
||||
int VirtualFree(void *address, size_t /*size*/, DWORD /*type*/) {
|
||||
auto &sizes = AllocationSizes();
|
||||
int VirtualFree(void* address, size_t /*size*/, DWORD /*type*/) {
|
||||
auto& sizes = AllocationSizes();
|
||||
auto it = sizes.find(address);
|
||||
if (it == sizes.end()) {
|
||||
return 0;
|
||||
@@ -101,7 +100,7 @@ int VirtualFree(void *address, size_t /*size*/, DWORD /*type*/) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
int VirtualProtect(void *address, size_t size, uint32_t protection, DWORD *old_protection) {
|
||||
int VirtualProtect(void* address, size_t size, uint32_t protection, DWORD* old_protection) {
|
||||
if (old_protection != nullptr) {
|
||||
*old_protection = Protection(address);
|
||||
}
|
||||
@@ -110,23 +109,22 @@ int VirtualProtect(void *address, size_t size, uint32_t protection, DWORD *old_p
|
||||
#endif
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
bool IsWritable(const void *address) {
|
||||
MEMORY_BASIC_INFORMATION info{};
|
||||
bool IsWritable(const void* address) {
|
||||
MEMORY_BASIC_INFORMATION info {};
|
||||
Check(VirtualQuery(address, &info, sizeof(info)) != 0, "VirtualQuery failed");
|
||||
return info.Protect == PAGE_READWRITE;
|
||||
}
|
||||
|
||||
uint32_t Protection(const void *address) {
|
||||
MEMORY_BASIC_INFORMATION info{};
|
||||
uint32_t Protection(const void* address) {
|
||||
MEMORY_BASIC_INFORMATION info {};
|
||||
Check(VirtualQuery(address, &info, sizeof(info)) != 0, "VirtualQuery failed");
|
||||
return info.Protect;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::atomic_uint64_t g_protection_calls{0};
|
||||
std::atomic_uint64_t g_protection_calls {0};
|
||||
|
||||
bool ProtectAddressSpace(uint64_t vaddr, uint64_t size,
|
||||
Common::VirtualMemory::Mode mode) {
|
||||
bool ProtectAddressSpace(uint64_t vaddr, uint64_t size, Common::VirtualMemory::Mode mode) {
|
||||
uint32_t protection = PAGE_NOACCESS;
|
||||
if (mode == Common::VirtualMemory::Mode::Read) {
|
||||
protection = PAGE_READONLY;
|
||||
@@ -135,30 +133,29 @@ bool ProtectAddressSpace(uint64_t vaddr, uint64_t size,
|
||||
}
|
||||
DWORD old_protection = 0;
|
||||
g_protection_calls.fetch_add(1, std::memory_order_relaxed);
|
||||
return VirtualProtect(reinterpret_cast<void *>(vaddr), size, protection,
|
||||
&old_protection) != 0;
|
||||
return VirtualProtect(reinterpret_cast<void*>(vaddr), size, protection, &old_protection) != 0;
|
||||
}
|
||||
|
||||
#if 1
|
||||
|
||||
struct FaultContext {
|
||||
PageManager *manager = nullptr;
|
||||
PageManager* manager = nullptr;
|
||||
bool result = true;
|
||||
bool reenter = false;
|
||||
uint64_t reenter_address = 0;
|
||||
bool block = false;
|
||||
std::atomic_uint32_t calls{0};
|
||||
std::atomic_bool entered{false};
|
||||
std::atomic_bool release{false};
|
||||
std::atomic_uint32_t calls {0};
|
||||
std::atomic_bool entered {false};
|
||||
std::atomic_bool release {false};
|
||||
};
|
||||
|
||||
std::atomic<PageManager *> g_native_fault_manager{nullptr};
|
||||
std::atomic_bool g_delay_native_fault{false};
|
||||
std::atomic_bool g_native_fault_entered{false};
|
||||
std::atomic_bool g_release_native_fault{false};
|
||||
std::atomic<PageManager*> g_native_fault_manager {nullptr};
|
||||
std::atomic_bool g_delay_native_fault {false};
|
||||
std::atomic_bool g_native_fault_entered {false};
|
||||
std::atomic_bool g_release_native_fault {false};
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
LONG CALLBACK NativeFaultHandler(EXCEPTION_POINTERS *exception) {
|
||||
LONG CALLBACK NativeFaultHandler(EXCEPTION_POINTERS* exception) {
|
||||
if (exception == nullptr || exception->ExceptionRecord == nullptr ||
|
||||
exception->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION) {
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
@@ -168,7 +165,7 @@ LONG CALLBACK NativeFaultHandler(EXCEPTION_POINTERS *exception) {
|
||||
: operation == 1 ? PageFaultAccess::Write
|
||||
: operation == 8 ? PageFaultAccess::Execute
|
||||
: PageFaultAccess::Unknown;
|
||||
auto *manager = g_native_fault_manager.load(std::memory_order_acquire);
|
||||
auto* manager = g_native_fault_manager.load(std::memory_order_acquire);
|
||||
if (manager == nullptr) {
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
@@ -178,20 +175,19 @@ LONG CALLBACK NativeFaultHandler(EXCEPTION_POINTERS *exception) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
}
|
||||
return manager->HandleFault(
|
||||
access, exception->ExceptionRecord->ExceptionInformation[1])
|
||||
return manager->HandleFault(access, exception->ExceptionRecord->ExceptionInformation[1])
|
||||
? EXCEPTION_CONTINUE_EXECUTION
|
||||
: EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
#else
|
||||
// SIGSEGV stands in for the vectored exception handler.
|
||||
void NativeFaultHandler(int signal_number, siginfo_t *info, void *native_context) {
|
||||
auto *context = static_cast<ucontext_t *>(native_context);
|
||||
void NativeFaultHandler(int signal_number, siginfo_t* info, void* native_context) {
|
||||
auto* context = static_cast<ucontext_t*>(native_context);
|
||||
const auto error_code = static_cast<uint64_t>(context->uc_mcontext.gregs[REG_ERR]);
|
||||
const auto access = (error_code & 0x10u) != 0 ? PageFaultAccess::Execute
|
||||
: (error_code & 0x02u) != 0 ? PageFaultAccess::Write
|
||||
: PageFaultAccess::Read;
|
||||
auto *manager = g_native_fault_manager.load(std::memory_order_acquire);
|
||||
auto* manager = g_native_fault_manager.load(std::memory_order_acquire);
|
||||
if (manager != nullptr) {
|
||||
if (g_delay_native_fault.load(std::memory_order_acquire)) {
|
||||
g_native_fault_entered.store(true, std::memory_order_release);
|
||||
@@ -211,8 +207,8 @@ void NativeFaultHandler(int signal_number, siginfo_t *info, void *native_context
|
||||
|
||||
struct sigaction g_saved_segv_action {};
|
||||
|
||||
void *AddVectoredExceptionHandler(unsigned long /*first*/,
|
||||
void (*handler)(int, siginfo_t *, void *)) {
|
||||
void* AddVectoredExceptionHandler(unsigned long /*first*/,
|
||||
void (*handler)(int, siginfo_t*, void*)) {
|
||||
struct sigaction action {};
|
||||
action.sa_sigaction = handler;
|
||||
sigemptyset(&action.sa_mask);
|
||||
@@ -220,25 +216,24 @@ void *AddVectoredExceptionHandler(unsigned long /*first*/,
|
||||
if (::sigaction(SIGSEGV, &action, &g_saved_segv_action) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return reinterpret_cast<void *>(handler);
|
||||
return reinterpret_cast<void*>(handler);
|
||||
}
|
||||
|
||||
int RemoveVectoredExceptionHandler(void * /*token*/) {
|
||||
int RemoveVectoredExceptionHandler(void* /*token*/) {
|
||||
return ::sigaction(SIGSEGV, &g_saved_segv_action, nullptr) == 0 ? 1 : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool InvalidateFault(void *context, Libs::Graphics::PageFaultAccess, uint64_t vaddr, uint64_t size,
|
||||
bool InvalidateFault(void* context, Libs::Graphics::PageFaultAccess, uint64_t vaddr, uint64_t size,
|
||||
Libs::Graphics::PageFaultPhase phase) noexcept {
|
||||
auto *fault = static_cast<FaultContext *>(context);
|
||||
auto* fault = static_cast<FaultContext*>(context);
|
||||
Check(fault != nullptr && fault->manager != nullptr, "invalid fault context");
|
||||
if (phase != Libs::Graphics::PageFaultPhase::Invalidate) {
|
||||
return true;
|
||||
}
|
||||
fault->calls.fetch_add(1, std::memory_order_relaxed);
|
||||
if (fault->reenter) {
|
||||
const auto address =
|
||||
fault->reenter_address != 0 ? fault->reenter_address : vaddr;
|
||||
const auto address = fault->reenter_address != 0 ? fault->reenter_address : vaddr;
|
||||
(void)fault->manager->HandleFault(PageFaultAccess::Write, address);
|
||||
}
|
||||
if (fault->block) {
|
||||
@@ -251,20 +246,18 @@ bool InvalidateFault(void *context, Libs::Graphics::PageFaultAccess, uint64_t va
|
||||
return fault->result;
|
||||
}
|
||||
|
||||
uint8_t *Allocate(uint64_t size, uint32_t protection = PAGE_READWRITE) {
|
||||
uint8_t* Allocate(uint64_t size, uint32_t protection = PAGE_READWRITE) {
|
||||
constexpr uintptr_t test_address = 0x0000000200010000ull;
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
auto *memory = static_cast<uint8_t *>(
|
||||
VirtualAlloc(reinterpret_cast<void *>(test_address), size,
|
||||
auto* memory = static_cast<uint8_t*>(VirtualAlloc(reinterpret_cast<void*>(test_address), size,
|
||||
MEM_RESERVE | MEM_COMMIT, protection));
|
||||
Check(memory == reinterpret_cast<void *>(test_address),
|
||||
"fixed low VirtualAlloc failed");
|
||||
Check(memory == reinterpret_cast<void*>(test_address), "fixed low VirtualAlloc failed");
|
||||
#else
|
||||
// Do not overwrite a leaked mapping from an earlier case.
|
||||
void *raw = ::mmap(reinterpret_cast<void *>(test_address), size, ToHostProt(protection),
|
||||
void* raw = ::mmap(reinterpret_cast<void*>(test_address), size, ToHostProt(protection),
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, -1, 0);
|
||||
Check(raw == reinterpret_cast<void *>(test_address), "fixed low mmap failed");
|
||||
auto *memory = static_cast<uint8_t *>(raw);
|
||||
Check(raw == reinterpret_cast<void*>(test_address), "fixed low mmap failed");
|
||||
auto* memory = static_cast<uint8_t*>(raw);
|
||||
AllocationSizes()[raw] = static_cast<size_t>(size);
|
||||
#endif
|
||||
return memory;
|
||||
@@ -276,27 +269,21 @@ void TestWatchFaultAndUnwatch() {
|
||||
PageManager manager(InvalidateFault, &context);
|
||||
context.manager = &manager;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
auto *memory = Allocate(page_size * 2);
|
||||
auto* memory = Allocate(page_size * 2);
|
||||
|
||||
manager.OnGpuMap(reinterpret_cast<uint64_t>(memory), page_size * 2);
|
||||
manager.UpdatePageWatchers(true, reinterpret_cast<uint64_t>(memory),
|
||||
page_size);
|
||||
Check(manager.IsTracked(reinterpret_cast<uint64_t>(memory)) &&
|
||||
!IsWritable(memory),
|
||||
manager.UpdatePageWatchers(true, reinterpret_cast<uint64_t>(memory), page_size);
|
||||
Check(manager.IsTracked(reinterpret_cast<uint64_t>(memory)) && !IsWritable(memory),
|
||||
"watch did not protect the page");
|
||||
Check(g_protection_calls.load(std::memory_order_relaxed) != 0,
|
||||
"watch protection bypassed the address-space owner callback");
|
||||
Check(manager.HandleFault(PageFaultAccess::Write,
|
||||
reinterpret_cast<uint64_t>(memory + 32)),
|
||||
Check(manager.HandleFault(PageFaultAccess::Write, reinterpret_cast<uint64_t>(memory + 32)),
|
||||
"tracked write fault was not handled");
|
||||
Check(!manager.IsTracked(reinterpret_cast<uint64_t>(memory)) &&
|
||||
IsWritable(memory),
|
||||
Check(!manager.IsTracked(reinterpret_cast<uint64_t>(memory)) && IsWritable(memory),
|
||||
"fault invalidation did not remove the watcher");
|
||||
Check(manager.HandleFault(PageFaultAccess::Write,
|
||||
reinterpret_cast<uint64_t>(memory)),
|
||||
Check(manager.HandleFault(PageFaultAccess::Write, reinterpret_cast<uint64_t>(memory)),
|
||||
"single delayed write fault was not coalesced");
|
||||
Check(manager.HandleFault(PageFaultAccess::Write,
|
||||
reinterpret_cast<uint64_t>(memory)),
|
||||
Check(manager.HandleFault(PageFaultAccess::Write, reinterpret_cast<uint64_t>(memory)),
|
||||
"second delayed write fault was not coalesced");
|
||||
manager.OnGpuUnmap(reinterpret_cast<uint64_t>(memory), page_size * 2);
|
||||
Check(VirtualFree(memory, 0, MEM_RELEASE) != 0, "VirtualFree failed");
|
||||
@@ -307,7 +294,7 @@ void TestSharedWatcherFault() {
|
||||
PageManager manager(InvalidateFault, &context);
|
||||
context.manager = &manager;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
auto *memory = Allocate(page_size);
|
||||
auto* memory = Allocate(page_size);
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
|
||||
manager.OnGpuMap(address, page_size);
|
||||
@@ -326,16 +313,13 @@ void TestReadWriteWatcherFault() {
|
||||
PageManager manager(InvalidateFault, &context);
|
||||
context.manager = &manager;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
auto *memory = Allocate(page_size);
|
||||
auto* memory = Allocate(page_size);
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
|
||||
manager.OnGpuMap(address, page_size);
|
||||
manager.UpdatePageWatchers(true, address, page_size,
|
||||
Libs::Graphics::PageWatchMode::Write);
|
||||
manager.UpdatePageWatchers(true, address, page_size,
|
||||
Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
manager.UpdatePageWatchers(false, address, page_size,
|
||||
Libs::Graphics::PageWatchMode::Write);
|
||||
manager.UpdatePageWatchers(true, address, page_size, Libs::Graphics::PageWatchMode::Write);
|
||||
manager.UpdatePageWatchers(true, address, page_size, Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
manager.UpdatePageWatchers(false, address, page_size, Libs::Graphics::PageWatchMode::Write);
|
||||
Check(Protection(memory) == PAGE_NOACCESS,
|
||||
"read/write watcher did not install no-access protection");
|
||||
Check(manager.HandleFault(PageFaultAccess::Read, address + 8),
|
||||
@@ -351,7 +335,7 @@ void TestPermittedMappedLateFaultsResume() {
|
||||
PageManager manager(InvalidateFault, &context);
|
||||
context.manager = &manager;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
auto *memory = Allocate(page_size);
|
||||
auto* memory = Allocate(page_size);
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
|
||||
manager.OnGpuMap(address, page_size);
|
||||
@@ -372,15 +356,13 @@ void TestPartialMappingUnmapPreservesTokens() {
|
||||
PageManager manager(InvalidateFault, &context);
|
||||
context.manager = &manager;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
auto *memory = Allocate(page_size);
|
||||
auto* memory = Allocate(page_size);
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
|
||||
manager.OnGpuMap(address, page_size);
|
||||
manager.OnGpuMap(address + 8, 16);
|
||||
manager.UpdatePageWatchers(true, address, page_size,
|
||||
Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
manager.UpdatePageWatchers(false, address, page_size,
|
||||
Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
manager.UpdatePageWatchers(true, address, page_size, Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
manager.UpdatePageWatchers(false, address, page_size, Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
manager.OnGpuUnmap(address + 8, 16);
|
||||
Check(manager.HandleFault(PageFaultAccess::Read, address),
|
||||
"partial mapping unmap erased delayed read ownership");
|
||||
@@ -395,45 +377,40 @@ void TestNativeDelayedReadAfterModeDowngrade() {
|
||||
PageManager manager(InvalidateFault, &context);
|
||||
context.manager = &manager;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
auto *memory = Allocate(page_size);
|
||||
auto* memory = Allocate(page_size);
|
||||
memory[0] = 0x6d;
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
|
||||
manager.OnGpuMap(address, page_size);
|
||||
manager.UpdatePageWatchers(true, address, page_size);
|
||||
manager.UpdatePageWatchers(true, address, page_size,
|
||||
Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
manager.UpdatePageWatchers(true, address, page_size, Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
manager.UpdatePageWatchers(false, address, page_size);
|
||||
Check(Protection(memory) == PAGE_NOACCESS,
|
||||
"read/write ownership did not install no-access protection");
|
||||
|
||||
void *handler = AddVectoredExceptionHandler(1, NativeFaultHandler);
|
||||
void* handler = AddVectoredExceptionHandler(1, NativeFaultHandler);
|
||||
Check(handler != nullptr, "AddVectoredExceptionHandler failed");
|
||||
Check(g_native_fault_manager.exchange(&manager, std::memory_order_acq_rel) ==
|
||||
nullptr,
|
||||
Check(g_native_fault_manager.exchange(&manager, std::memory_order_acq_rel) == nullptr,
|
||||
"native fault manager already installed");
|
||||
g_native_fault_entered.store(false, std::memory_order_release);
|
||||
g_release_native_fault.store(false, std::memory_order_release);
|
||||
g_delay_native_fault.store(true, std::memory_order_release);
|
||||
|
||||
uint8_t value = 0;
|
||||
std::thread reader(
|
||||
[&] { value = *static_cast<volatile uint8_t *>(memory); });
|
||||
std::thread reader([&] { value = *static_cast<volatile uint8_t*>(memory); });
|
||||
while (!g_native_fault_entered.load(std::memory_order_acquire)) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
manager.UpdatePageWatchers(true, address, page_size);
|
||||
manager.UpdatePageWatchers(false, address, page_size,
|
||||
Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
manager.UpdatePageWatchers(false, address, page_size, Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
Check(Protection(memory) == PAGE_READONLY,
|
||||
"mode downgrade did not restore readable protection");
|
||||
manager.UpdatePageWatchers(true, address, page_size);
|
||||
|
||||
context.block = true;
|
||||
bool write_handled = false;
|
||||
std::thread writer([&] {
|
||||
write_handled = manager.HandleFault(PageFaultAccess::Write, address);
|
||||
});
|
||||
std::thread writer(
|
||||
[&] { write_handled = manager.HandleFault(PageFaultAccess::Write, address); });
|
||||
while (!context.entered.load(std::memory_order_acquire)) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
@@ -443,13 +420,10 @@ void TestNativeDelayedReadAfterModeDowngrade() {
|
||||
writer.join();
|
||||
|
||||
g_delay_native_fault.store(false, std::memory_order_release);
|
||||
Check(g_native_fault_manager.exchange(nullptr, std::memory_order_acq_rel) ==
|
||||
&manager,
|
||||
Check(g_native_fault_manager.exchange(nullptr, std::memory_order_acq_rel) == &manager,
|
||||
"native fault manager publication changed");
|
||||
Check(RemoveVectoredExceptionHandler(handler) != 0,
|
||||
"RemoveVectoredExceptionHandler failed");
|
||||
Check(value == 0x6d && write_handled &&
|
||||
context.calls.load(std::memory_order_relaxed) == 1,
|
||||
Check(RemoveVectoredExceptionHandler(handler) != 0, "RemoveVectoredExceptionHandler failed");
|
||||
Check(value == 0x6d && write_handled && context.calls.load(std::memory_order_relaxed) == 1,
|
||||
"delayed read was not coalesced across write ownership/resolution");
|
||||
|
||||
manager.OnGpuUnmap(address, page_size);
|
||||
@@ -461,7 +435,7 @@ void TestDelayedFaultAfterExplicitUnwatch() {
|
||||
PageManager manager(InvalidateFault, &context);
|
||||
context.manager = &manager;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
auto *memory = Allocate(page_size);
|
||||
auto* memory = Allocate(page_size);
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
manager.OnGpuMap(address, page_size);
|
||||
manager.UpdatePageWatchers(true, address, page_size);
|
||||
@@ -484,22 +458,19 @@ void TestNativeAccessViolation() {
|
||||
PageManager manager(InvalidateFault, &context);
|
||||
context.manager = &manager;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
auto *memory = Allocate(page_size);
|
||||
auto* memory = Allocate(page_size);
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
manager.OnGpuMap(address, page_size);
|
||||
manager.UpdatePageWatchers(true, address, page_size);
|
||||
|
||||
void *handler = AddVectoredExceptionHandler(1, NativeFaultHandler);
|
||||
void* handler = AddVectoredExceptionHandler(1, NativeFaultHandler);
|
||||
Check(handler != nullptr, "AddVectoredExceptionHandler failed");
|
||||
Check(g_native_fault_manager.exchange(&manager, std::memory_order_acq_rel) ==
|
||||
nullptr,
|
||||
Check(g_native_fault_manager.exchange(&manager, std::memory_order_acq_rel) == nullptr,
|
||||
"native fault manager already installed");
|
||||
*static_cast<volatile uint8_t *>(memory) = 0x5a;
|
||||
Check(g_native_fault_manager.exchange(nullptr, std::memory_order_acq_rel) ==
|
||||
&manager,
|
||||
*static_cast<volatile uint8_t*>(memory) = 0x5a;
|
||||
Check(g_native_fault_manager.exchange(nullptr, std::memory_order_acq_rel) == &manager,
|
||||
"native fault manager publication changed");
|
||||
Check(RemoveVectoredExceptionHandler(handler) != 0,
|
||||
"RemoveVectoredExceptionHandler failed");
|
||||
Check(RemoveVectoredExceptionHandler(handler) != 0, "RemoveVectoredExceptionHandler failed");
|
||||
|
||||
Check(memory[0] == 0x5a && !manager.IsTracked(address) &&
|
||||
context.calls.load(std::memory_order_relaxed) == 1,
|
||||
@@ -514,21 +485,20 @@ void TestCrossRegionRange() {
|
||||
context.manager = &manager;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
constexpr uint64_t region_size = 4ull * 1024ull * 1024ull;
|
||||
auto *memory = Allocate(region_size * 2);
|
||||
auto* memory = Allocate(region_size * 2);
|
||||
const auto base = reinterpret_cast<uint64_t>(memory);
|
||||
const auto boundary = (base + region_size - 1) & ~(region_size - 1);
|
||||
Check(boundary >= base + page_size &&
|
||||
boundary + page_size <= base + region_size * 2,
|
||||
Check(boundary >= base + page_size && boundary + page_size <= base + region_size * 2,
|
||||
"test allocation does not contain a region boundary");
|
||||
|
||||
manager.OnGpuMap(base, region_size * 2);
|
||||
manager.UpdatePageWatchers(true, boundary - page_size, page_size * 2);
|
||||
Check(!IsWritable(reinterpret_cast<void *>(boundary - page_size)) &&
|
||||
!IsWritable(reinterpret_cast<void *>(boundary)),
|
||||
Check(!IsWritable(reinterpret_cast<void*>(boundary - page_size)) &&
|
||||
!IsWritable(reinterpret_cast<void*>(boundary)),
|
||||
"cross-region watch did not protect both pages");
|
||||
manager.UpdatePageWatchers(false, boundary - page_size, page_size * 2);
|
||||
Check(IsWritable(reinterpret_cast<void *>(boundary - page_size)) &&
|
||||
IsWritable(reinterpret_cast<void *>(boundary)),
|
||||
Check(IsWritable(reinterpret_cast<void*>(boundary - page_size)) &&
|
||||
IsWritable(reinterpret_cast<void*>(boundary)),
|
||||
"cross-region unwatch did not restore both pages");
|
||||
manager.OnGpuUnmap(base, region_size * 2);
|
||||
Check(VirtualFree(memory, 0, MEM_RELEASE) != 0, "VirtualFree failed");
|
||||
@@ -541,7 +511,7 @@ void TestBatchedWatcherRanges() {
|
||||
const auto page_size = manager.GetPageSize();
|
||||
constexpr uint64_t region_size = 4ull * 1024ull * 1024ull;
|
||||
constexpr uint64_t allocation_size = region_size * 3;
|
||||
auto *memory = Allocate(allocation_size);
|
||||
auto* memory = Allocate(allocation_size);
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
|
||||
manager.OnGpuMap(address, allocation_size);
|
||||
@@ -554,8 +524,7 @@ void TestBatchedWatcherRanges() {
|
||||
"fragmented watch did not coalesce to read-only");
|
||||
}
|
||||
manager.UpdatePageWatchers(false, address, page_size * 5);
|
||||
Check(IsWritable(memory) &&
|
||||
Protection(memory + page_size) == PAGE_READONLY &&
|
||||
Check(IsWritable(memory) && Protection(memory + page_size) == PAGE_READONLY &&
|
||||
IsWritable(memory + page_size * 2) &&
|
||||
Protection(memory + page_size * 3) == PAGE_READONLY &&
|
||||
IsWritable(memory + page_size * 4),
|
||||
@@ -564,14 +533,12 @@ void TestBatchedWatcherRanges() {
|
||||
manager.UpdatePageWatchers(false, address + page_size * 3, page_size);
|
||||
|
||||
manager.UpdatePageWatchers(true, address, allocation_size);
|
||||
Check(!IsWritable(memory) &&
|
||||
!IsWritable(memory + region_size) &&
|
||||
Check(!IsWritable(memory) && !IsWritable(memory + region_size) &&
|
||||
!IsWritable(memory + region_size * 2) &&
|
||||
!IsWritable(memory + allocation_size - page_size),
|
||||
"large cross-region watch did not protect the full range");
|
||||
manager.UpdatePageWatchers(false, address, allocation_size);
|
||||
Check(IsWritable(memory) &&
|
||||
IsWritable(memory + region_size) &&
|
||||
Check(IsWritable(memory) && IsWritable(memory + region_size) &&
|
||||
IsWritable(memory + region_size * 2) &&
|
||||
IsWritable(memory + allocation_size - page_size),
|
||||
"large cross-region unwatch did not restore the full range");
|
||||
@@ -579,23 +546,20 @@ void TestBatchedWatcherRanges() {
|
||||
manager.UpdatePageWatchers(true, address, page_size * 5);
|
||||
manager.UpdatePageWatchers(true, address + page_size, page_size * 3,
|
||||
Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
Check(Protection(memory) == PAGE_READONLY &&
|
||||
Protection(memory + page_size) == PAGE_NOACCESS &&
|
||||
Check(Protection(memory) == PAGE_READONLY && Protection(memory + page_size) == PAGE_NOACCESS &&
|
||||
Protection(memory + page_size * 2) == PAGE_NOACCESS &&
|
||||
Protection(memory + page_size * 3) == PAGE_NOACCESS &&
|
||||
Protection(memory + page_size * 4) == PAGE_READONLY,
|
||||
"mixed watcher modes installed incorrect protections");
|
||||
manager.UpdatePageWatchers(false, address, page_size * 5);
|
||||
Check(IsWritable(memory) &&
|
||||
Protection(memory + page_size) == PAGE_NOACCESS &&
|
||||
Check(IsWritable(memory) && Protection(memory + page_size) == PAGE_NOACCESS &&
|
||||
Protection(memory + page_size * 2) == PAGE_NOACCESS &&
|
||||
Protection(memory + page_size * 3) == PAGE_NOACCESS &&
|
||||
IsWritable(memory + page_size * 4),
|
||||
"write unwatch incorrectly released read/write watchers");
|
||||
manager.UpdatePageWatchers(false, address + page_size, page_size * 3,
|
||||
Libs::Graphics::PageWatchMode::ReadWrite);
|
||||
Check(IsWritable(memory + page_size) &&
|
||||
IsWritable(memory + page_size * 2) &&
|
||||
Check(IsWritable(memory + page_size) && IsWritable(memory + page_size * 2) &&
|
||||
IsWritable(memory + page_size * 3),
|
||||
"read/write unwatch did not restore writable protection");
|
||||
|
||||
@@ -603,7 +567,7 @@ void TestBatchedWatcherRanges() {
|
||||
Check(VirtualFree(memory, 0, MEM_RELEASE) != 0, "VirtualFree failed");
|
||||
}
|
||||
|
||||
[[noreturn]] void RunDeathCase(const char *name) {
|
||||
[[noreturn]] void RunDeathCase(const char* name) {
|
||||
FaultContext context;
|
||||
auto manager = std::make_unique<PageManager>(InvalidateFault, &context);
|
||||
context.manager = manager.get();
|
||||
@@ -614,7 +578,7 @@ void TestBatchedWatcherRanges() {
|
||||
manager->UpdatePageWatchers(false, 0x1000, page_size);
|
||||
} else {
|
||||
const bool two_pages = std::strcmp(name, "cross-reentrant") == 0;
|
||||
auto *memory = Allocate(two_pages ? page_size * 2 : page_size);
|
||||
auto* memory = Allocate(two_pages ? page_size * 2 : page_size);
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
manager->OnGpuMap(address, two_pages ? page_size * 2 : page_size);
|
||||
manager->UpdatePageWatchers(true, address, page_size);
|
||||
@@ -637,8 +601,7 @@ void TestBatchedWatcherRanges() {
|
||||
(void)manager->HandleFault(PageFaultAccess::Write, address);
|
||||
} else if (std::strcmp(name, "concurrent-non-write") == 0) {
|
||||
context.block = true;
|
||||
std::thread first(
|
||||
[&] { (void)manager->HandleFault(PageFaultAccess::Write, address); });
|
||||
std::thread first([&] { (void)manager->HandleFault(PageFaultAccess::Write, address); });
|
||||
while (!context.entered.load(std::memory_order_acquire)) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
@@ -651,25 +614,21 @@ void TestBatchedWatcherRanges() {
|
||||
std::_Exit(0x7f);
|
||||
}
|
||||
|
||||
void CheckDeathCase(const char *name) {
|
||||
void CheckDeathCase(const char* name) {
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
char path[MAX_PATH]{};
|
||||
Check(GetModuleFileNameA(nullptr, path, MAX_PATH) != 0,
|
||||
"GetModuleFileName failed");
|
||||
char path[MAX_PATH] {};
|
||||
Check(GetModuleFileNameA(nullptr, path, MAX_PATH) != 0, "GetModuleFileName failed");
|
||||
std::string command = std::string("\"") + path + "\" --death " + name;
|
||||
std::vector<char> mutable_command(command.begin(), command.end());
|
||||
mutable_command.push_back('\0');
|
||||
STARTUPINFOA startup{sizeof(startup)};
|
||||
PROCESS_INFORMATION process{};
|
||||
Check(CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, FALSE,
|
||||
CREATE_NO_WINDOW, nullptr, nullptr, &startup,
|
||||
&process) != 0,
|
||||
STARTUPINFOA startup {sizeof(startup)};
|
||||
PROCESS_INFORMATION process {};
|
||||
Check(CreateProcessA(nullptr, mutable_command.data(), nullptr, nullptr, FALSE, CREATE_NO_WINDOW,
|
||||
nullptr, nullptr, &startup, &process) != 0,
|
||||
"CreateProcess failed");
|
||||
Check(WaitForSingleObject(process.hProcess, 10000) == WAIT_OBJECT_0,
|
||||
"death test timed out");
|
||||
Check(WaitForSingleObject(process.hProcess, 10000) == WAIT_OBJECT_0, "death test timed out");
|
||||
DWORD exit_code = 0;
|
||||
Check(
|
||||
GetExitCodeProcess(process.hProcess, &exit_code) != 0 &&
|
||||
Check(GetExitCodeProcess(process.hProcess, &exit_code) != 0 &&
|
||||
(exit_code == 322 || exit_code == EXCEPTION_NONCONTINUABLE_EXCEPTION),
|
||||
"death case did not use the PageManager fatal exit");
|
||||
CloseHandle(process.hThread);
|
||||
@@ -686,16 +645,14 @@ void CheckDeathCase(const char *name) {
|
||||
// Exit status carries only the low 8 bits.
|
||||
const bool fatal_exit = WIFEXITED(status) && WEXITSTATUS(status) == (322 & 0xff);
|
||||
const bool fatal_signal = WIFSIGNALED(status);
|
||||
Check(fatal_exit || fatal_signal,
|
||||
"death case did not use the PageManager fatal exit");
|
||||
Check(fatal_exit || fatal_signal, "death case did not use the PageManager fatal exit");
|
||||
#endif
|
||||
}
|
||||
|
||||
void TestFatalPaths() {
|
||||
for (const char *name :
|
||||
{"invalid-range", "unknown-untrack", "destructor-watch", "non-write",
|
||||
"callback-false", "reentrant", "cross-reentrant",
|
||||
"concurrent-non-write"}) {
|
||||
for (const char* name:
|
||||
{"invalid-range", "unknown-untrack", "destructor-watch", "non-write", "callback-false",
|
||||
"reentrant", "cross-reentrant", "concurrent-non-write"}) {
|
||||
CheckDeathCase(name);
|
||||
}
|
||||
}
|
||||
@@ -706,26 +663,22 @@ void TestConcurrentFault() {
|
||||
context.manager = &manager;
|
||||
context.block = true;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
auto *memory = Allocate(page_size);
|
||||
auto* memory = Allocate(page_size);
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
manager.OnGpuMap(address, page_size);
|
||||
manager.UpdatePageWatchers(true, address, page_size);
|
||||
bool first_result = false;
|
||||
bool second_result = false;
|
||||
std::thread first([&] {
|
||||
first_result = manager.HandleFault(PageFaultAccess::Write, address);
|
||||
});
|
||||
std::thread first([&] { first_result = manager.HandleFault(PageFaultAccess::Write, address); });
|
||||
while (!context.entered.load(std::memory_order_acquire)) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
std::thread second([&] {
|
||||
second_result = manager.HandleFault(PageFaultAccess::Write, address);
|
||||
});
|
||||
std::thread second(
|
||||
[&] { second_result = manager.HandleFault(PageFaultAccess::Write, address); });
|
||||
context.release.store(true, std::memory_order_release);
|
||||
first.join();
|
||||
second.join();
|
||||
Check(first_result && second_result &&
|
||||
context.calls.load(std::memory_order_relaxed) == 1,
|
||||
Check(first_result && second_result && context.calls.load(std::memory_order_relaxed) == 1,
|
||||
"concurrent faults dispatched invalidation more than once");
|
||||
manager.OnGpuUnmap(address, page_size);
|
||||
Check(VirtualFree(memory, 0, MEM_RELEASE) != 0, "VirtualFree failed");
|
||||
@@ -737,13 +690,12 @@ void TestExternalDirtyTransferDuringResolution() {
|
||||
context.manager = &manager;
|
||||
context.block = true;
|
||||
const auto page_size = manager.GetPageSize();
|
||||
auto *memory = Allocate(page_size);
|
||||
auto* memory = Allocate(page_size);
|
||||
const auto address = reinterpret_cast<uint64_t>(memory);
|
||||
manager.OnGpuMap(address, page_size);
|
||||
manager.UpdatePageWatchers(true, address, page_size);
|
||||
bool handled = false;
|
||||
std::thread fault(
|
||||
[&] { handled = manager.HandleFault(PageFaultAccess::Write, address); });
|
||||
std::thread fault([&] { handled = manager.HandleFault(PageFaultAccess::Write, address); });
|
||||
while (!context.entered.load(std::memory_order_acquire)) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
@@ -768,7 +720,7 @@ bool ProtectGuestHostMemory(uint64_t vaddr, uint64_t size, Common::VirtualMemory
|
||||
|
||||
} // namespace Libs::LibKernel::Memory
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char** argv) {
|
||||
#if 1
|
||||
if (argc == 3 && std::strcmp(argv[1], "--death") == 0) {
|
||||
RunDeathCase(argv[2]);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "graphics/host_gpu/renderer/cache/resourceMutex.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
+310
-482
File diff suppressed because it is too large.
Load diff
@@ -482,8 +482,8 @@ void TestReadLaneVectorOverwriteInvalidatesSpill() {
|
||||
overwrite.dst = Vgpr(11);
|
||||
overwrite.src[0] = Imm(0);
|
||||
overwrite.src_count = 1;
|
||||
program.blocks[0].instructions = {WriteLane(0, 11, 4, 0), overwrite,
|
||||
ReadLane(8, 0, 11, 0), BufferUse(12, 0)};
|
||||
program.blocks[0].instructions = {WriteLane(0, 11, 4, 0), overwrite, ReadLane(8, 0, 11, 0),
|
||||
BufferUse(12, 0)};
|
||||
|
||||
std::string error;
|
||||
Check(BuildScalarProvenance(program, &error), error.c_str());
|
||||
@@ -550,8 +550,8 @@ void TestReadLaneWideAndRelativeWritesInvalidateSpill() {
|
||||
overwrite.dst = Vgpr(11);
|
||||
overwrite.src[0] = Imm(0);
|
||||
overwrite.src_count = 1;
|
||||
program.blocks[0].instructions = {WriteLane(0, 12, 4, 0), overwrite,
|
||||
ReadLane(8, 0, 12, 0), BufferUse(12, 0)};
|
||||
program.blocks[0].instructions = {WriteLane(0, 12, 4, 0), overwrite, ReadLane(8, 0, 12, 0),
|
||||
BufferUse(12, 0)};
|
||||
|
||||
std::string error;
|
||||
Check(BuildScalarProvenance(program, &error), error.c_str());
|
||||
@@ -589,8 +589,8 @@ void TestReadLaneModuloAndDynamicLane() {
|
||||
write.src[1] = Sgpr(7);
|
||||
dynamic.blocks[0].instructions = {write, ReadLane(4, 0, 11, 0), BufferUse(8, 0)};
|
||||
Check(BuildScalarProvenance(dynamic, &error), error.c_str());
|
||||
Check(!DescriptorSourceResolved(
|
||||
dynamic, dynamic.blocks[0].instructions.back().memory.resource_source),
|
||||
Check(!DescriptorSourceResolved(dynamic,
|
||||
dynamic.blocks[0].instructions.back().memory.resource_source),
|
||||
"dynamic writelane selector retained unsafe lane provenance");
|
||||
}
|
||||
|
||||
@@ -599,8 +599,7 @@ void TestReadLaneEliminationSnapshotsWriteValue() {
|
||||
program.wave_size = 64;
|
||||
program.user_data_count = 8;
|
||||
program.blocks.resize(1);
|
||||
program.blocks[0].instructions = {
|
||||
MoveImmediate(0, 4, 0x12345678u), WriteLane(4, 11, 4, 4),
|
||||
program.blocks[0].instructions = {MoveImmediate(0, 4, 0x12345678u), WriteLane(4, 11, 4, 4),
|
||||
MoveImmediate(8, 4, 0xdeadbeefu), ReadLane(12, 0, 11, 4)};
|
||||
|
||||
std::string error;
|
||||
@@ -680,8 +679,7 @@ void TestReadLaneEliminationHonorsVectorInvalidation() {
|
||||
overwrite.dst = Vgpr(11);
|
||||
overwrite.src[0] = Imm(0);
|
||||
overwrite.src_count = 1;
|
||||
program.blocks[0].instructions = {WriteLane(0, 11, 4, 4), overwrite,
|
||||
ReadLane(8, 0, 11, 4)};
|
||||
program.blocks[0].instructions = {WriteLane(0, 11, 4, 4), overwrite, ReadLane(8, 0, 11, 4)};
|
||||
|
||||
std::string error;
|
||||
Check(BuildScalarProvenance(program, &error), error.c_str());
|
||||
@@ -840,8 +838,7 @@ void TestDynamicReadIsNotFlattened() {
|
||||
DescriptorValue descriptor;
|
||||
const auto source = program.blocks[0].instructions[1].memory.resource_source;
|
||||
const SrtRuntime runtime {user_data, 0, ReadHostMemory, nullptr};
|
||||
Check(EvaluateDescriptorSource(program, source, 4, runtime, descriptor, &error),
|
||||
error.c_str());
|
||||
Check(EvaluateDescriptorSource(program, source, 4, runtime, descriptor, &error), error.c_str());
|
||||
Check(descriptor.dwords[0] == table[1], "dynamic ReadConst evaluated the wrong dword");
|
||||
}
|
||||
|
||||
@@ -1151,39 +1148,36 @@ void TestBitFieldMaskDescriptor() {
|
||||
mask.src_count = 2;
|
||||
auto high = MoveImmediate(8, 30, 0x05500000u);
|
||||
high.op = Opcode::MoveU64;
|
||||
program.blocks[0].instructions = {MoveImmediate(0, 28, 0x92u), mask, high,
|
||||
BufferUse(12, 28)};
|
||||
program.blocks[0].instructions = {MoveImmediate(0, 28, 0x92u), mask, high, BufferUse(12, 28)};
|
||||
|
||||
std::string error;
|
||||
Check(BuildScalarProvenance(program, &error) && BuildSrtPlan(program, &error), error.c_str());
|
||||
DescriptorValue descriptor;
|
||||
const SrtRuntime runtime {{}, 0, nullptr, nullptr};
|
||||
Check(EvaluateDescriptorSource(program,
|
||||
program.blocks[0].instructions.back().memory.resource_source,
|
||||
16, runtime, descriptor, &error),
|
||||
program.blocks[0].instructions.back().memory.resource_source, 16,
|
||||
runtime, descriptor, &error),
|
||||
error.c_str());
|
||||
Check(descriptor.dwords[0] == 0x92u && descriptor.dwords[1] == 0x00fff000u &&
|
||||
descriptor.dwords[2] == 0x05500000u && descriptor.dwords[3] == 0,
|
||||
"production sampler bit-field mask evaluated incorrectly");
|
||||
|
||||
mask.src[0] = Imm(0);
|
||||
program.blocks[0].instructions = {MoveImmediate(0, 28, 0x92u), mask, high,
|
||||
BufferUse(12, 28)};
|
||||
program.blocks[0].instructions = {MoveImmediate(0, 28, 0x92u), mask, high, BufferUse(12, 28)};
|
||||
Check(BuildScalarProvenance(program, &error) && BuildSrtPlan(program, &error), error.c_str());
|
||||
Check(EvaluateDescriptorSource(program,
|
||||
program.blocks[0].instructions.back().memory.resource_source,
|
||||
12, runtime, descriptor, &error),
|
||||
program.blocks[0].instructions.back().memory.resource_source, 12,
|
||||
runtime, descriptor, &error),
|
||||
error.c_str());
|
||||
Check(descriptor.dwords[1] == 0, "zero-width bit-field mask was not zero");
|
||||
|
||||
mask.src[0] = Imm(31);
|
||||
mask.src[1] = Imm(31);
|
||||
program.blocks[0].instructions = {MoveImmediate(0, 28, 0x92u), mask, high,
|
||||
BufferUse(12, 28)};
|
||||
program.blocks[0].instructions = {MoveImmediate(0, 28, 0x92u), mask, high, BufferUse(12, 28)};
|
||||
Check(BuildScalarProvenance(program, &error) && BuildSrtPlan(program, &error), error.c_str());
|
||||
Check(EvaluateDescriptorSource(program,
|
||||
program.blocks[0].instructions.back().memory.resource_source,
|
||||
12, runtime, descriptor, &error),
|
||||
program.blocks[0].instructions.back().memory.resource_source, 12,
|
||||
runtime, descriptor, &error),
|
||||
error.c_str());
|
||||
Check(descriptor.dwords[1] == 0x80000000u,
|
||||
"maximum bit-field mask count/offset evaluated incorrectly");
|
||||
|
||||
+3064
-4443
File diff suppressed because it is too large.
Load diff
@@ -1,7 +1,6 @@
|
||||
#include "graphics/shader/shader.h"
|
||||
|
||||
#include "graphics/shader/recompiler/ir/ResourceMaterialization.h"
|
||||
#include "graphics/shader/recompiler/ir/ShaderIR.h"
|
||||
#include "graphics/shader/shader.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -61,8 +60,7 @@ void TestMappedSrtUsesDirectReaderByDefault() {
|
||||
Check(ShaderMaterializeStageRuntime(cached_program, {}, 0, stage, &error), error.c_str());
|
||||
Check(stage.program == cached_program && stage.resources != nullptr,
|
||||
"cache rematerialization did not publish the mapped stage");
|
||||
Check(stage.resources->flattened_srt.size() == 1 &&
|
||||
stage.resources->flattened_srt[0] == dword,
|
||||
Check(stage.resources->flattened_srt.size() == 1 && stage.resources->flattened_srt[0] == dword,
|
||||
"cache rematerialization did not use the direct reader by default");
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ void TestValidAndInvalidMetadata() {
|
||||
CheckRejected(excessive_semantics.mapped, "excessive vertex semantic count was accepted");
|
||||
|
||||
Fixture excessive_register;
|
||||
excessive_register.offsets[
|
||||
static_cast<size_t>(AgcDirectResourceType::PtrVertexBufferTable)] = 63;
|
||||
excessive_register.offsets[static_cast<size_t>(AgcDirectResourceType::PtrVertexBufferTable)] =
|
||||
63;
|
||||
CheckRejected(excessive_register.mapped, "out-of-domain vertex table SGPR was accepted");
|
||||
|
||||
Fixture missing_semantics;
|
||||
|
||||
@@ -107,8 +107,7 @@ void InitSubsystems() {
|
||||
slist->Add(log, {core, config});
|
||||
Check("InitSubsystems", slist->InitAll(false), "failed to initialize logging subsystem");
|
||||
|
||||
const auto param_json =
|
||||
std::filesystem::temp_directory_path() /
|
||||
const auto param_json = std::filesystem::temp_directory_path() /
|
||||
("kyty_virtual_memory_" +
|
||||
std::to_string(reinterpret_cast<uintptr_t>(&initialized)) + ".json");
|
||||
constexpr char json[] = R"({"kernel":{"flexibleMemorySize":3221225472}})";
|
||||
@@ -247,8 +246,8 @@ void TestGuestAddressSpaceOwnsReservationsBeforeBacking() {
|
||||
Check(test, Libs::LibKernel::Memory::TestPlaceholderRangeIsFree(base, SceKernelPageSize),
|
||||
"semantic reservation replaced the owner's placeholder");
|
||||
Check(test,
|
||||
Libs::LibKernel::Memory::ProtectGuestHostMemory(
|
||||
base, SceKernelPageSize, Common::VirtualMemory::Mode::NoAccess),
|
||||
Libs::LibKernel::Memory::ProtectGuestHostMemory(base, SceKernelPageSize,
|
||||
Common::VirtualMemory::Mode::NoAccess),
|
||||
"owner rejected a sparse placeholder protection no-op");
|
||||
CheckOk(test, Libs::LibKernel::Memory::KernelMunmap(base, SceKernelPageSize), "KernelMunmap");
|
||||
Check(test, Libs::LibKernel::Memory::TestPlaceholderRangeIsFree(base, SceKernelPageSize),
|
||||
@@ -402,8 +401,7 @@ void TestFlexibleDmemCompatAndAlignmentFlags() {
|
||||
Check(test, stack_start == nullptr && stack_end == nullptr,
|
||||
"DMEM_COMPAT flexible mapping was reported as a stack");
|
||||
|
||||
CheckOk(test, Libs::LibKernel::Memory::KernelMunmap(base, SceKernelPageSize),
|
||||
"KernelMunmap");
|
||||
CheckOk(test, Libs::LibKernel::Memory::KernelMunmap(base, SceKernelPageSize), "KernelMunmap");
|
||||
Check(test, AvailableFlexibleMemory(test) == baseline,
|
||||
"DMEM_COMPAT cleanup did not restore flexible capacity");
|
||||
|
||||
@@ -443,8 +441,8 @@ void TestFlexibleNoCoalescePreservesBoundaries() {
|
||||
const auto baseline = AvailableFlexibleMemory(test);
|
||||
void* reserve = nullptr;
|
||||
CheckOk(test,
|
||||
Libs::LibKernel::Memory::KernelReserveVirtualRange(
|
||||
&reserve, SceKernelPageSize * 2, 0, SceKernelPageSize),
|
||||
Libs::LibKernel::Memory::KernelReserveVirtualRange(&reserve, SceKernelPageSize * 2, 0,
|
||||
SceKernelPageSize),
|
||||
"KernelReserveVirtualRange");
|
||||
const auto base = reinterpret_cast<uint64_t>(reserve);
|
||||
|
||||
@@ -601,12 +599,11 @@ void TestRuntimeMemoryOwnerLifecycle() {
|
||||
Common::VirtualMemory::Mode::ReadWrite, "runtime_adjacent_second", true);
|
||||
Check(test, adjacent_second == adjacent_first + SceKernelPageSize,
|
||||
"second adjacent runtime allocation failed");
|
||||
Check(test,
|
||||
Libs::LibKernel::Memory::FreeGuestMemory(adjacent_first, SceKernelPageSize * 2),
|
||||
Check(test, Libs::LibKernel::Memory::FreeGuestMemory(adjacent_first, SceKernelPageSize * 2),
|
||||
"combined adjacent runtime free failed");
|
||||
Check(test,
|
||||
Libs::LibKernel::Memory::TestPlaceholderRangeIsFree(adjacent_first,
|
||||
SceKernelPageSize * 2),
|
||||
Check(
|
||||
test,
|
||||
Libs::LibKernel::Memory::TestPlaceholderRangeIsFree(adjacent_first, SceKernelPageSize * 2),
|
||||
"combined adjacent runtime free did not restore one owner placeholder");
|
||||
|
||||
std::printf("[host] %-48s ok\n", test);
|
||||
@@ -877,12 +874,12 @@ void TestDirectPartialProtectUnmapPreservesNeighbors() {
|
||||
SceKernelPageSize, SceKernelProtCpuRead),
|
||||
"KernelMprotect(middle)");
|
||||
Check(test,
|
||||
Libs::LibKernel::Memory::ProtectGuestHostMemory(
|
||||
base, size, Common::VirtualMemory::Mode::Read),
|
||||
Libs::LibKernel::Memory::ProtectGuestHostMemory(base, size,
|
||||
Common::VirtualMemory::Mode::Read),
|
||||
"owner could not protect fragmented backing views");
|
||||
Check(test,
|
||||
Libs::LibKernel::Memory::ProtectGuestHostMemory(
|
||||
base, size, Common::VirtualMemory::Mode::ReadWrite),
|
||||
Libs::LibKernel::Memory::ProtectGuestHostMemory(base, size,
|
||||
Common::VirtualMemory::Mode::ReadWrite),
|
||||
"owner could not restore fragmented backing views");
|
||||
CheckOk(test,
|
||||
Libs::LibKernel::Memory::KernelMunmap(base + SceKernelPageSize, SceKernelPageSize),
|
||||
@@ -1091,12 +1088,12 @@ void TestMunmapAcrossAdjacentFlexibleMappings() {
|
||||
Libs::LibKernel::Memory::ClampRangeSize(base + SceKernelPageSize - 0x100, 0x200) == 0x200,
|
||||
"ClampRangeSize did not cross adjacent committed mappings");
|
||||
Check(test,
|
||||
Libs::LibKernel::Memory::ProtectGuestHostMemory(
|
||||
base, SceKernelPageSize * 2, Common::VirtualMemory::Mode::Read),
|
||||
Libs::LibKernel::Memory::ProtectGuestHostMemory(base, SceKernelPageSize * 2,
|
||||
Common::VirtualMemory::Mode::Read),
|
||||
"owner could not protect adjacent backing mappings");
|
||||
Check(test,
|
||||
Libs::LibKernel::Memory::ProtectGuestHostMemory(
|
||||
base, SceKernelPageSize * 2, Common::VirtualMemory::Mode::ReadWrite),
|
||||
Libs::LibKernel::Memory::ProtectGuestHostMemory(base, SceKernelPageSize * 2,
|
||||
Common::VirtualMemory::Mode::ReadWrite),
|
||||
"owner could not restore adjacent backing mappings");
|
||||
|
||||
CheckOk(test, Libs::LibKernel::Memory::KernelMunmap(base, SceKernelPageSize * 2),
|
||||
|
||||
+41
-51
@@ -4,22 +4,22 @@
|
||||
#include "common/threads.h"
|
||||
#include "graphics/guest_gpu/hardwareContext.h"
|
||||
#include "graphics/guest_gpu/pm4.h"
|
||||
#include "graphics/host_gpu/renderer/image/textureCommon.h"
|
||||
#include "graphics/host_gpu/renderer/image/imageView.h"
|
||||
#include "graphics/host_gpu/renderer/image/textureCommon.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/shaderSubgroup.h"
|
||||
#include "graphics/shader/recompiler/ExecMask.h"
|
||||
#include "graphics/shader/recompiler/ir/ResourceTracking.h"
|
||||
#include "graphics/shader/recompiler/ir/ScalarProvenance.h"
|
||||
#include "graphics/shader/recompiler/ShaderRecompiler.h"
|
||||
#include "graphics/shader/recompiler/cfg/ShaderCFG.h"
|
||||
#include "graphics/shader/recompiler/decompiler/ShaderDecoder.h"
|
||||
#include "graphics/shader/recompiler/emitter/SpirvEmitter.h"
|
||||
#include "graphics/shader/recompiler/emitter/spirvEmitterInternal.h"
|
||||
#include "graphics/shader/recompiler/ir/ResourceTracking.h"
|
||||
#include "graphics/shader/recompiler/ir/ScalarProvenance.h"
|
||||
#include "graphics/shader/recompiler/ir/ShaderIR.h"
|
||||
#include "graphics/shader/recompiler/ir/ShaderInfoCollection.h"
|
||||
#include "graphics/shader/recompiler/ShaderRecompiler.h"
|
||||
#include "graphics/shader/recompiler/emitter/SpirvEmitter.h"
|
||||
#include "graphics/shader/recompiler/ir/SrtPatcher.h"
|
||||
#include "graphics/shader/recompiler/ir/SrtWalker.h"
|
||||
#include "graphics/shader/recompiler/emitter/spirvEmitterInternal.h"
|
||||
#include "graphics/shader/shader.h"
|
||||
#include "libs/agc.h"
|
||||
#include "spirv-tools/libspirv.hpp"
|
||||
@@ -411,8 +411,8 @@ constexpr uint32_t EncodeSopp(uint32_t opcode, uint32_t simm = 0) {
|
||||
}
|
||||
|
||||
void TestNativeShaderResourceDependencies() {
|
||||
const auto stages = ShaderPipelineStages(
|
||||
vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment |
|
||||
const auto stages =
|
||||
ShaderPipelineStages(vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment |
|
||||
vk::ShaderStageFlagBits::eCompute);
|
||||
Check(stages == (vk::PipelineStageFlagBits::eVertexShader |
|
||||
vk::PipelineStageFlagBits::eFragmentShader |
|
||||
@@ -463,8 +463,7 @@ void TestNormalizedImageContracts() {
|
||||
ImageInfo container {};
|
||||
container.data = {0x10000, 0x15000};
|
||||
container.pixel_format = vk::Format::eR8G8B8A8Unorm;
|
||||
container.guest_format =
|
||||
Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm);
|
||||
container.guest_format = Prospero::GpuEnumValue(Prospero::BufferFormat::k8_8_8_8UNorm);
|
||||
container.type = Prospero::ImageType::kColor2D;
|
||||
container.extent = {64, 64, 1};
|
||||
container.resources = {3, 4};
|
||||
@@ -488,8 +487,7 @@ void TestNormalizedImageContracts() {
|
||||
"normalized image block extent changed");
|
||||
Check(subresource.IsCompatible(container), "normalized compatible image was rejected");
|
||||
Check(subresource.MipOf(container) == 1, "normalized mip lookup missed a subresource");
|
||||
Check(subresource.SliceOf(container, 1) == 2,
|
||||
"normalized slice lookup missed a subresource");
|
||||
Check(subresource.SliceOf(container, 1) == 2, "normalized slice lookup missed a subresource");
|
||||
|
||||
auto incompatible = subresource;
|
||||
incompatible.samples = 2;
|
||||
@@ -497,17 +495,14 @@ void TestNormalizedImageContracts() {
|
||||
"sample-count mismatch was accepted as a compatible image");
|
||||
|
||||
auto compressed = container;
|
||||
compressed.guest_format =
|
||||
Prospero::GpuEnumValue(Prospero::BufferFormat::kBc3UNorm);
|
||||
compressed.guest_format = Prospero::GpuEnumValue(Prospero::BufferFormat::kBc3UNorm);
|
||||
compressed.pitch = 128;
|
||||
compressed.extent.height = 64;
|
||||
Check(compressed.BlockExtent() == vk::Extent2D {32, 16},
|
||||
"block-compressed extent was not expressed in blocks");
|
||||
|
||||
Check(ImageViewOps::FormatsCompatible(vk::Format::eR8G8B8A8Unorm,
|
||||
vk::Format::eR8G8B8A8Uint) &&
|
||||
!ImageViewOps::FormatsCompatible(vk::Format::eD32Sfloat,
|
||||
vk::Format::eR32Sfloat) &&
|
||||
Check(ImageViewOps::FormatsCompatible(vk::Format::eR8G8B8A8Unorm, vk::Format::eR8G8B8A8Uint) &&
|
||||
!ImageViewOps::FormatsCompatible(vk::Format::eD32Sfloat, vk::Format::eR32Sfloat) &&
|
||||
ImageViewOps::FormatsCompatible(vk::Format::eBc3UnormBlock,
|
||||
vk::Format::eR32G32B32A32Uint),
|
||||
"Vulkan image-view compatibility classes diverged from production");
|
||||
@@ -524,20 +519,19 @@ void TestNativeSubgroupPolicy() {
|
||||
safe.wave_size = 32;
|
||||
safe.lane_mask_mode = ShaderLaneMaskMode::NativeWave;
|
||||
Check(ConfigureShaderSubgroup(ShaderSubgroupCapabilities {context},
|
||||
vk::ShaderStageFlagBits::eVertex, safe).mode ==
|
||||
ShaderSubgroupMode::Natural,
|
||||
vk::ShaderStageFlagBits::eVertex, safe)
|
||||
.mode == ShaderSubgroupMode::Natural,
|
||||
"native wave32 policy changed");
|
||||
safe.wave_size = 64;
|
||||
Check(SelectGraphicsLaneMaskMode(safe.wave_size) ==
|
||||
ShaderLaneMaskMode::PerInvocation &&
|
||||
Check(SelectGraphicsLaneMaskMode(safe.wave_size) == ShaderLaneMaskMode::PerInvocation &&
|
||||
ConfigureShaderSubgroup(ShaderSubgroupCapabilities {context},
|
||||
vk::ShaderStageFlagBits::eVertex, safe).mode ==
|
||||
ShaderSubgroupMode::Unsupported,
|
||||
vk::ShaderStageFlagBits::eVertex, safe)
|
||||
.mode == ShaderSubgroupMode::Unsupported,
|
||||
"wave64 graphics mismatch accepted native-wave mask lowering");
|
||||
safe.lane_mask_mode = ShaderLaneMaskMode::PerInvocation;
|
||||
Check(ConfigureShaderSubgroup(ShaderSubgroupCapabilities {context},
|
||||
vk::ShaderStageFlagBits::eVertex, safe).mode ==
|
||||
ShaderSubgroupMode::PerInvocationGraphics,
|
||||
vk::ShaderStageFlagBits::eVertex, safe)
|
||||
.mode == ShaderSubgroupMode::PerInvocationGraphics,
|
||||
"wave64 graphics mismatch did not select per-invocation masks");
|
||||
|
||||
ShaderRecompiler::IR::Program cross_lane = safe;
|
||||
@@ -545,14 +539,14 @@ void TestNativeSubgroupPolicy() {
|
||||
ShaderRecompiler::IR::Opcode::ReadLaneU32;
|
||||
Check(ShaderRecompiler::Spirv::ProgramRequiresExactSubgroupSize(cross_lane) &&
|
||||
ConfigureShaderSubgroup(ShaderSubgroupCapabilities {context},
|
||||
vk::ShaderStageFlagBits::eVertex, cross_lane).mode ==
|
||||
ShaderSubgroupMode::PerInvocationGraphics,
|
||||
vk::ShaderStageFlagBits::eVertex, cross_lane)
|
||||
.mode == ShaderSubgroupMode::PerInvocationGraphics,
|
||||
"graphics mismatch did not select per-invocation masks");
|
||||
auto cross_lane_compute = cross_lane;
|
||||
cross_lane_compute.lane_mask_mode = ShaderLaneMaskMode::NativeWave;
|
||||
Check(ConfigureShaderSubgroup(ShaderSubgroupCapabilities {context},
|
||||
vk::ShaderStageFlagBits::eCompute, cross_lane_compute).mode ==
|
||||
ShaderSubgroupMode::Unsupported,
|
||||
vk::ShaderStageFlagBits::eCompute, cross_lane_compute)
|
||||
.mode == ShaderSubgroupMode::Unsupported,
|
||||
"cross-lane compute mismatch bypassed the exact subgroup requirement");
|
||||
|
||||
ShaderRecompiler::IR::Program zero_exec = safe;
|
||||
@@ -568,8 +562,8 @@ void TestNativeSubgroupPolicy() {
|
||||
zero_bfm.scalar_sources[0] = 2;
|
||||
Check(!ShaderRecompiler::Spirv::ProgramRequiresExactSubgroupSize(zero_exec) &&
|
||||
ConfigureShaderSubgroup(ShaderSubgroupCapabilities {context},
|
||||
vk::ShaderStageFlagBits::eCompute, zero_exec).mode ==
|
||||
ShaderSubgroupMode::FlattenedMasks,
|
||||
vk::ShaderStageFlagBits::eCompute, zero_exec)
|
||||
.mode == ShaderSubgroupMode::FlattenedMasks,
|
||||
"compile-time uniform-zero EXEC write did not stay on the mask-free path");
|
||||
|
||||
ShaderRecompiler::IR::Program selective_exec = safe;
|
||||
@@ -600,8 +594,8 @@ void TestNativeSubgroupPolicy() {
|
||||
ds_partial.blocks.emplace_back().instructions.emplace_back().op =
|
||||
ShaderRecompiler::IR::Opcode::DsAppend;
|
||||
Check(ConfigureShaderSubgroup(ShaderSubgroupCapabilities {context},
|
||||
vk::ShaderStageFlagBits::eCompute, ds_partial).mode ==
|
||||
ShaderSubgroupMode::Unsupported,
|
||||
vk::ShaderStageFlagBits::eCompute, ds_partial)
|
||||
.mode == ShaderSubgroupMode::Unsupported,
|
||||
"partial wave64 DS append bypassed the exact subgroup requirement");
|
||||
context.max_subgroup_size = 64;
|
||||
const auto controlled =
|
||||
@@ -614,17 +608,18 @@ void TestNativeSubgroupPolicy() {
|
||||
cross_lane.wave_size = 32;
|
||||
cross_lane.lane_mask_mode = ShaderLaneMaskMode::PerInvocation;
|
||||
Check(ConfigureShaderSubgroup(ShaderSubgroupCapabilities {context},
|
||||
vk::ShaderStageFlagBits::eFragment, cross_lane).mode ==
|
||||
ShaderSubgroupMode::Unsupported,
|
||||
vk::ShaderStageFlagBits::eFragment, cross_lane)
|
||||
.mode == ShaderSubgroupMode::Unsupported,
|
||||
"inverse graphics mismatch was accepted as one guest wave");
|
||||
cross_lane_compute.wave_size = 32;
|
||||
Check(ConfigureShaderSubgroup(ShaderSubgroupCapabilities {context},
|
||||
vk::ShaderStageFlagBits::eCompute, cross_lane_compute).mode ==
|
||||
ShaderSubgroupMode::Unsupported,
|
||||
vk::ShaderStageFlagBits::eCompute, cross_lane_compute)
|
||||
.mode == ShaderSubgroupMode::Unsupported,
|
||||
"inverse cross-lane compute mismatch was accepted");
|
||||
}
|
||||
|
||||
std::array<uint32_t, 64> ImageTestUserData(Prospero::ImageType type = Prospero::ImageType::kColor2D) {
|
||||
std::array<uint32_t, 64>
|
||||
ImageTestUserData(Prospero::ImageType type = Prospero::ImageType::kColor2D) {
|
||||
std::array<uint32_t, 64> data {};
|
||||
for (uint32_t start = 0; start + 3u < data.size(); start += 4u) {
|
||||
data[start] = 0x1000u + start * 0x100u;
|
||||
@@ -3525,10 +3520,8 @@ void TestNewShaderRecompilerImageViewDimensions() {
|
||||
"SPIR-V binary does not contain sampled 2D-array image type");
|
||||
Check(SpirvContainsTypeImage(result.spirv, SpirvDim3D, 0, 1),
|
||||
"SPIR-V binary does not contain sampled 3D image type");
|
||||
Check(SpirvContainsCapability(result.spirv, 43),
|
||||
"SPIR-V binary does not request Sampled1D");
|
||||
Check(SpirvContainsCapability(result.spirv, 44),
|
||||
"SPIR-V binary does not request Image1D");
|
||||
Check(SpirvContainsCapability(result.spirv, 43), "SPIR-V binary does not request Sampled1D");
|
||||
Check(SpirvContainsCapability(result.spirv, 44), "SPIR-V binary does not request Image1D");
|
||||
Check(SpirvContainsOpcode(result.spirv, 95),
|
||||
"SPIR-V binary does not contain array image fetch");
|
||||
CheckSpirvBinaryValidates(result.spirv);
|
||||
@@ -4116,8 +4109,7 @@ void TestNewShaderRecompilerVintrpLowering() {
|
||||
options.pixel_input_info = &flat_ps_info;
|
||||
|
||||
ShaderRecompiler::CompileResult flat_result;
|
||||
Check(ShaderRecompiler::TryRecompile(flat_shader, options, flat_result, &error),
|
||||
error.c_str());
|
||||
Check(ShaderRecompiler::TryRecompile(flat_shader, options, flat_result, &error), error.c_str());
|
||||
Check(SpirvHasDecorationValueWithDecoration(flat_result.spirv, 30u, 0u, 14u),
|
||||
"flat VINTRP input did not emit a Flat decoration");
|
||||
Check(!SpirvHasDecorationValueWithDecoration(flat_result.spirv, 30u, 0u, 13u),
|
||||
@@ -6027,8 +6019,8 @@ void TestRenderTargetReverseFloat16ExportMapping() {
|
||||
format.export_mapping.ApplyMask(0xfu) == 0xfu,
|
||||
"reverse RGBA16F render-target export or write-mask mapping is "
|
||||
"incorrect");
|
||||
const auto legacy_alt = TextureGetRenderTargetFormat(
|
||||
Prospero::GpuEnumValue(Prospero::ChannelLayout::k8_8_8_8),
|
||||
const auto legacy_alt =
|
||||
TextureGetRenderTargetFormat(Prospero::GpuEnumValue(Prospero::ChannelLayout::k8_8_8_8),
|
||||
Prospero::GpuEnumValue(Prospero::ChannelType::kUNorm),
|
||||
Prospero::GpuEnumValue(Prospero::ChannelOrder::kAlt));
|
||||
Check(legacy_alt.format == vk::Format::eB8G8R8A8Unorm && legacy_alt.export_mapping.IsIdentity(),
|
||||
@@ -6060,8 +6052,7 @@ void TestRenderTargetReverseFloat16ExportMapping() {
|
||||
CheckSpirvBinaryValidates(reversed_result.spirv);
|
||||
|
||||
HW::PixelShaderInfo regs {};
|
||||
Check(ShaderGetIdPS(regs, identity_info, false) !=
|
||||
ShaderGetIdPS(regs, reversed_info, false),
|
||||
Check(ShaderGetIdPS(regs, identity_info, false) != ShaderGetIdPS(regs, reversed_info, false),
|
||||
"pixel shader cache identity omitted the render-target export mapping");
|
||||
|
||||
regs.ps_regs.data_addr = reinterpret_cast<uint64_t>(shader);
|
||||
@@ -7006,8 +6997,7 @@ void TestNewShaderRecompilerFlatAddressProvenanceBoundaries() {
|
||||
options.flat_memory_base = 0;
|
||||
ShaderRecompiler::CompileResult result;
|
||||
std::string error;
|
||||
const bool compiled =
|
||||
ShaderRecompiler::TryRecompile(segmented_shader, options, result, &error);
|
||||
const bool compiled = ShaderRecompiler::TryRecompile(segmented_shader, options, result, &error);
|
||||
Check(compiled, error.c_str());
|
||||
Check(result.program.info.addresses.size() == 2,
|
||||
"segmented address resources were not tracked independently");
|
||||
|
||||
Reference in new issue
Block a user