mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-08-03 11:23:49 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8a4c83cc7 | ||
|
|
68be13345a | ||
|
|
167da0abe0 | ||
|
|
48c31d61ee | ||
|
|
212282d693 | ||
|
|
6bca35d1f5 |
@@ -329,6 +329,7 @@ add_kyty_full_emulator_test(shader_cfg_tests ../tests/shaderCfgTests.cpp)
|
||||
add_executable(scalar_provenance_tests EXCLUDE_FROM_ALL
|
||||
../tests/ScalarProvenanceTests.cpp
|
||||
graphics/host_gpu/hostMemory.cpp
|
||||
graphics/shader/recompiler/ir/ReadLaneElimination.cpp
|
||||
graphics/shader/recompiler/ir/ScalarProvenance.cpp
|
||||
graphics/shader/recompiler/ir/SrtWalker.cpp
|
||||
)
|
||||
@@ -441,6 +442,7 @@ if(NOT KYTY_CLANG_CL)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test(NAME scalar_provenance COMMAND $<TARGET_FILE:scalar_provenance_tests>)
|
||||
add_test(NAME image_page_table COMMAND $<TARGET_FILE:image_page_table_tests>)
|
||||
add_test(NAME memory_tracker COMMAND $<TARGET_FILE:memory_tracker_tests>)
|
||||
add_test(NAME page_manager COMMAND $<TARGET_FILE:page_manager_tests>)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -374,6 +374,8 @@ enum class BufferFormat : uint32_t {
|
||||
k32_32_32_32UInt = 75,
|
||||
k32_32_32_32SInt = 76,
|
||||
k32_32_32_32Float = 77,
|
||||
k8Srgb = 128,
|
||||
k8_8Srgb = 129,
|
||||
k8_8_8_8Srgb = 130,
|
||||
k9_9_9_5Float = 132,
|
||||
k5_6_5UNorm = 133,
|
||||
|
||||
@@ -57,6 +57,8 @@ constexpr FormatInfo kFormatInfo[] = {
|
||||
{GpuEnumValue(BufferFormat::k32_32_32_32UInt), 16, 0, 16, true, true},
|
||||
{GpuEnumValue(BufferFormat::k32_32_32_32SInt), 16, 0, 16, false, false},
|
||||
{GpuEnumValue(BufferFormat::k32_32_32_32Float), 16, 0, 16, true, false},
|
||||
{GpuEnumValue(BufferFormat::k8Srgb), 1, 0, 0, true, false},
|
||||
{GpuEnumValue(BufferFormat::k8_8Srgb), 2, 0, 0, true, false},
|
||||
{GpuEnumValue(BufferFormat::k8_8_8_8Srgb), 4, 0, 4, true, false},
|
||||
{GpuEnumValue(BufferFormat::k9_9_9_5Float), 4, 0, 0, true, false},
|
||||
{GpuEnumValue(BufferFormat::k5_6_5UNorm), 2, 0, 2, true, false},
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include "graphics/guest_gpu/hardwareContext.h"
|
||||
#include "graphics/guest_gpu/tile.h"
|
||||
#include "graphics/host_gpu/graphicContext.h"
|
||||
#include "graphics/host_gpu/renderer/image/textureCommon.h"
|
||||
#include "graphics/host_gpu/renderer/debug.h"
|
||||
#include "graphics/host_gpu/renderer/image/textureCommon.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/descriptorCache.h"
|
||||
#include "graphics/host_gpu/renderer/render.h"
|
||||
#include "graphics/host_gpu/renderer/renderContext.h"
|
||||
@@ -79,10 +79,8 @@ void RenderExecutor::ResolveRenderColorTarget(uint64_t submit_id, RenderCommandB
|
||||
const auto view = ResolveTargetViewInfo(
|
||||
rt.view.base_array_slice_index, rt.view.last_array_slice_index, render_target_slice_offset);
|
||||
switch (view.type) {
|
||||
case TargetViewType::Image2D: break;
|
||||
case TargetViewType::Image2DArray:
|
||||
EXIT("layered render-target views are unsupported: base=%u count=%u\n", view.base_layer,
|
||||
view.layer_count);
|
||||
case TargetViewType::Image2D:
|
||||
case TargetViewType::Image2DArray: break;
|
||||
case TargetViewType::Unsupported:
|
||||
EXIT("invalid render-target view: base=%u last=%u draw_offset=%u\n",
|
||||
rt.view.base_array_slice_index, rt.view.last_array_slice_index,
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
@@ -548,14 +548,6 @@ static void ZCheck(const HW::DepthRenderTarget& z) {
|
||||
EXIT_NOT_IMPLEMENTED(z.htile_surface.prefetch_height != 0x00000000);
|
||||
EXIT_NOT_IMPLEMENTED(z.htile_surface.dst_outside_zero_to_one != 0x00000000);
|
||||
|
||||
if (z.depth_view.slice_start != 0x00000000 || z.depth_view.slice_max != 0x00000000) {
|
||||
static std::atomic<uint32_t> log_count {0};
|
||||
if (log_count.fetch_add(1, std::memory_order_relaxed) < 16) {
|
||||
LOGF("DepthTarget: temporary: ignoring PS5 array slice view start=0x%08" PRIx32
|
||||
", max=0x%08" PRIx32 "\n",
|
||||
z.depth_view.slice_start, z.depth_view.slice_max);
|
||||
}
|
||||
}
|
||||
if (z.depth_view.current_mip_level != 0x00000000) {
|
||||
static std::atomic<uint32_t> log_count {0};
|
||||
if (log_count.fetch_add(1, std::memory_order_relaxed) < 16) {
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
#include "graphics/guest_gpu/hardwareContext.h"
|
||||
#include "graphics/guest_gpu/tile.h"
|
||||
#include "graphics/host_gpu/graphicContext.h"
|
||||
#include "graphics/host_gpu/renderer/image/textureCommon.h"
|
||||
#include "graphics/host_gpu/renderer/debug.h"
|
||||
#include "graphics/host_gpu/renderer/pipeline/descriptorCache.h"
|
||||
#include "graphics/host_gpu/renderer/image/imageView.h"
|
||||
#include "graphics/host_gpu/renderer/image/textureCommon.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/vulkanCommon.h"
|
||||
@@ -150,10 +150,8 @@ void RenderExecutor::ResolveRenderDepthTarget(uint64_t submit_id, RenderCommandB
|
||||
has_stencil, has_htile, z.stencil_info.htile_stencil_disabled);
|
||||
const auto view = ResolveTargetViewInfo(z.depth_view.slice_start, z.depth_view.slice_max);
|
||||
switch (view.type) {
|
||||
case TargetViewType::Image2D: break;
|
||||
case TargetViewType::Image2DArray:
|
||||
DepthFatal("layered depth views are unsupported: base=%u count=%u", view.base_layer,
|
||||
view.layer_count);
|
||||
case TargetViewType::Image2D:
|
||||
case TargetViewType::Image2DArray: break;
|
||||
case TargetViewType::Unsupported:
|
||||
DepthFatal("invalid depth view: base=%u last=%u", z.depth_view.slice_start,
|
||||
z.depth_view.slice_max);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -88,7 +88,9 @@ SelectSampledDepthView(vk::Format image_format, vk::Format view_format, uint32_t
|
||||
IsSupportedSampledDepthResource(const ShaderRecompiler::IR::ImageResource& resource) noexcept {
|
||||
return resource.kind == ShaderRecompiler::IR::ResourceKind::Image &&
|
||||
(resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2D ||
|
||||
resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2DArray) &&
|
||||
resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2DArray ||
|
||||
resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2DMsaa ||
|
||||
resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2DMsaaArray) &&
|
||||
resource.mip_mode == ShaderRecompiler::IR::ImageMipMode::None && resource.read &&
|
||||
!resource.written && !resource.atomic;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -26,11 +26,15 @@ bool IsSampledImage(BindingKind kind) {
|
||||
case BindingKind::Sampled1DArray:
|
||||
case BindingKind::Sampled2D:
|
||||
case BindingKind::Sampled2DArray:
|
||||
case BindingKind::Sampled2DMsaa:
|
||||
case BindingKind::Sampled2DMsaaArray:
|
||||
case BindingKind::Sampled3D:
|
||||
case BindingKind::SampledUint1D:
|
||||
case BindingKind::SampledUint1DArray:
|
||||
case BindingKind::SampledUint2D:
|
||||
case BindingKind::SampledUint2DArray:
|
||||
case BindingKind::SampledUint2DMsaa:
|
||||
case BindingKind::SampledUint2DMsaaArray:
|
||||
case BindingKind::SampledUint3D: return true;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,11 @@ static Prospero::ImageType TextureBaseType(Prospero::ImageType type) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsMultisampledTexture(Prospero::ImageType type) {
|
||||
return type == Prospero::ImageType::kColor2DMsaa ||
|
||||
type == Prospero::ImageType::kColor2DMsaaArray;
|
||||
}
|
||||
|
||||
static BufferView NativeStorageBuffer(RenderContext& context, CommandBuffer& command_buffer,
|
||||
const ShaderBufferResource& descriptor,
|
||||
const ShaderRecompiler::IR::BufferResource& resource,
|
||||
@@ -159,6 +164,8 @@ static bool IsSupportedSampledColorResource(const ShaderRecompiler::IR::ImageRes
|
||||
case ShaderRecompiler::Decoder::ImageDimension::Dim1DArray:
|
||||
case ShaderRecompiler::Decoder::ImageDimension::Dim2D:
|
||||
case ShaderRecompiler::Decoder::ImageDimension::Dim2DArray:
|
||||
case ShaderRecompiler::Decoder::ImageDimension::Dim2DMsaa:
|
||||
case ShaderRecompiler::Decoder::ImageDimension::Dim2DMsaaArray:
|
||||
supported_dimension = true;
|
||||
break;
|
||||
default: break;
|
||||
@@ -195,6 +202,22 @@ TargetTextureViewInfo ResolveTargetTextureView(const ShaderRecompiler::IR::Image
|
||||
? TargetTextureViewInfo {vk::ImageViewType::e2DArray, base_layer,
|
||||
image_layers - base_layer}
|
||||
: TargetTextureViewInfo {};
|
||||
case Prospero::ImageType::kColor2DMsaa:
|
||||
return resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2DMsaa &&
|
||||
base_layer == 0 && image_layers == 1
|
||||
? TargetTextureViewInfo {vk::ImageViewType::e2D, 0, 1}
|
||||
: TargetTextureViewInfo {};
|
||||
case Prospero::ImageType::kColor2DMsaaArray:
|
||||
if (resource.dimension == ShaderRecompiler::Decoder::ImageDimension::Dim2DMsaa &&
|
||||
base_layer == 0 && image_layers == 1) {
|
||||
return {vk::ImageViewType::e2D, 0, 1};
|
||||
}
|
||||
return resource.dimension ==
|
||||
ShaderRecompiler::Decoder::ImageDimension::Dim2DMsaaArray &&
|
||||
base_layer < image_layers
|
||||
? TargetTextureViewInfo {vk::ImageViewType::e2DArray, base_layer,
|
||||
image_layers - base_layer}
|
||||
: TargetTextureViewInfo {};
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
@@ -211,34 +234,57 @@ bool IsSupportedSampledVideoOutView(const ShaderRecompiler::IR::ImageResource& r
|
||||
bool IsSupportedDepthTargetDescriptor(const ShaderTextureResource& descriptor, const Image& image) {
|
||||
const auto width = static_cast<uint32_t>(descriptor.Width5()) + 1u;
|
||||
const auto height = static_cast<uint32_t>(descriptor.Height5()) + 1u;
|
||||
const auto pitch = TileGetTexturePitch(descriptor.Format(), width, 1, descriptor.TileMode());
|
||||
const auto type = static_cast<Prospero::ImageType>(descriptor.Type());
|
||||
const bool supported_single_layer =
|
||||
const bool multisampled = IsMultisampledTexture(type);
|
||||
const auto samples = multisampled ? 1u << descriptor.LastLevel() : 1u;
|
||||
const auto pitch =
|
||||
multisampled ? TileGetDepthPitch(width, image.info.bytes_per_block, descriptor.LastLevel())
|
||||
: TileGetTexturePitch(descriptor.Format(), width, 1, descriptor.TileMode());
|
||||
const bool supported_2d = type == Prospero::ImageType::kColor2D &&
|
||||
image.info.resources.layers == 1 && descriptor.Depth() == 0 &&
|
||||
descriptor.BaseArray5() == 0 &&
|
||||
(type == Prospero::ImageType::kColor2D || type == Prospero::ImageType::kColor2DArray);
|
||||
descriptor.BaseArray5() == 0;
|
||||
const bool supported_array = type == Prospero::ImageType::kColor2DArray &&
|
||||
descriptor.BaseArray5() <= descriptor.Depth() &&
|
||||
descriptor.Depth() < image.info.resources.layers;
|
||||
const bool supported_cube =
|
||||
type == Prospero::ImageType::kCube && width == height && image.info.resources.layers >= 6 &&
|
||||
image.info.resources.layers % 6u == 0 &&
|
||||
static_cast<uint32_t>(descriptor.Depth()) + 1u == image.info.resources.layers &&
|
||||
descriptor.BaseArray5() == 0;
|
||||
const bool supported_msaa_2d = type == Prospero::ImageType::kColor2DMsaa &&
|
||||
image.info.resources.layers == 1 && descriptor.Depth() == 0 &&
|
||||
descriptor.BaseArray5() == 0;
|
||||
const bool supported_msaa_array = type == Prospero::ImageType::kColor2DMsaaArray &&
|
||||
descriptor.BaseArray5() <= descriptor.Depth() &&
|
||||
descriptor.Depth() < image.info.resources.layers;
|
||||
const bool levels_ok =
|
||||
multisampled
|
||||
? descriptor.BaseLevel() == 0 && descriptor.LastLevel() >= 1 &&
|
||||
descriptor.LastLevel() <= 3 && descriptor.MaxMip() == descriptor.LastLevel() &&
|
||||
image.info.resources.levels == 1 && image.info.samples == samples
|
||||
: descriptor.BaseLevel() == 0 && descriptor.LastLevel() == 0 &&
|
||||
descriptor.MaxMip() == 0 && image.info.samples == 1;
|
||||
return image.info.IsDepth() && width == image.info.extent.width &&
|
||||
height == image.info.extent.height && (supported_single_layer || supported_cube) &&
|
||||
descriptor.BaseLevel() == 0 && descriptor.LastLevel() == 0 && descriptor.MaxMip() == 0 &&
|
||||
descriptor.MinLod() == 0 && descriptor.BaseArray5() == 0 &&
|
||||
height == image.info.extent.height &&
|
||||
(supported_2d || supported_array || supported_cube || supported_msaa_2d ||
|
||||
supported_msaa_array) &&
|
||||
levels_ok && descriptor.MinLod() == 0 &&
|
||||
descriptor.TileMode() == Prospero::GpuEnumValue(Prospero::TileMode::kDepth) &&
|
||||
descriptor.BCSwizzle() == 0 && !descriptor.MsaaDepth() && pitch >= width &&
|
||||
pitch == image.info.pitch;
|
||||
descriptor.BCSwizzle() == 0 && descriptor.MsaaDepth() == multisampled &&
|
||||
pitch >= width && pitch == image.info.pitch;
|
||||
}
|
||||
|
||||
bool IsSupportedDepthTextureEncoding(const ShaderTextureResource& descriptor, const Image& image) {
|
||||
constexpr uint32_t field1_reserved_mask = 0x200fff00u;
|
||||
constexpr uint32_t field2_reserved_mask = 0xf0003000u;
|
||||
constexpr uint32_t field3_common = 0x01800000u;
|
||||
constexpr uint32_t field5_expected = 0x00700000u;
|
||||
const uint32_t field3_expected =
|
||||
(descriptor.Type() << 28u) | field3_common | descriptor.DstSelXYZW();
|
||||
const uint32_t field3_expected = descriptor.DstSelXYZW() |
|
||||
(static_cast<uint32_t>(descriptor.BaseLevel()) << 12u) |
|
||||
(static_cast<uint32_t>(descriptor.LastLevel()) << 16u) |
|
||||
(static_cast<uint32_t>(descriptor.TileMode()) << 20u) |
|
||||
(static_cast<uint32_t>(descriptor.Type()) << 28u);
|
||||
const uint32_t field4_expected = descriptor.Depth() | (descriptor.BaseArray5() << 16u);
|
||||
const uint32_t field5_expected =
|
||||
0x00700000u | (static_cast<uint32_t>(descriptor.MaxMip()) << 4u);
|
||||
const bool common = (descriptor.fields[1] & field1_reserved_mask) == 0 &&
|
||||
(descriptor.fields[2] & field2_reserved_mask) == 0 &&
|
||||
descriptor.fields[3] == field3_expected &&
|
||||
@@ -251,8 +297,9 @@ bool IsSupportedDepthTextureEncoding(const ShaderTextureResource& descriptor, co
|
||||
return true;
|
||||
}
|
||||
constexpr uint32_t htile_control = 0x00280000u;
|
||||
const uint32_t expected_control = htile_control | (descriptor.MsaaDepth() ? (1u << 10u) : 0u);
|
||||
const auto metadata_addr = descriptor.MetaAddr() << 8u;
|
||||
return (descriptor.fields[6] & 0x00ffffffu) == htile_control && metadata_addr != 0 &&
|
||||
return (descriptor.fields[6] & 0x00ffffffu) == expected_control && metadata_addr != 0 &&
|
||||
descriptor.TileMode() == Prospero::GpuEnumValue(Prospero::TileMode::kDepth) &&
|
||||
image.info.tile_mode == Prospero::GpuEnumValue(Prospero::TileMode::kDepth) &&
|
||||
image.info.metadata.kind == ImageMetadataKind::Htile &&
|
||||
@@ -518,6 +565,7 @@ static ImageViewInfo TextureViewInfo(const ShaderRecompiler::IR::ImageResource&
|
||||
view.layer_count = 1;
|
||||
break;
|
||||
case ShaderRecompiler::Decoder::ImageDimension::Dim2DArray:
|
||||
case ShaderRecompiler::Decoder::ImageDimension::Dim2DMsaaArray:
|
||||
view.type = vk::ImageViewType::e2DArray;
|
||||
view.base_layer = descriptor.BaseArray5();
|
||||
if (view.base_layer >= image_layers) {
|
||||
@@ -526,6 +574,7 @@ static ImageViewInfo TextureViewInfo(const ShaderRecompiler::IR::ImageResource&
|
||||
view.layer_count = image_layers - view.base_layer;
|
||||
break;
|
||||
case ShaderRecompiler::Decoder::ImageDimension::Dim2D:
|
||||
case ShaderRecompiler::Decoder::ImageDimension::Dim2DMsaa:
|
||||
view.type = vk::ImageViewType::e2D;
|
||||
view.base_layer = descriptor.BaseArray5();
|
||||
if (view.base_layer >= image_layers) {
|
||||
@@ -562,16 +611,17 @@ RenderExecutor::ResolveTexture(const ShaderRecompiler::IR::ImageResource& reso
|
||||
const auto base_level = descriptor.BaseLevel();
|
||||
const auto last_level = descriptor.LastLevel();
|
||||
const auto type = TextureType(descriptor);
|
||||
const bool multisampled =
|
||||
type == Prospero::ImageType::kColor2DMsaa || type == Prospero::ImageType::kColor2DMsaaArray;
|
||||
const bool multisampled = IsMultisampledTexture(type);
|
||||
const auto levels = multisampled ? 1u : static_cast<uint32_t>(descriptor.MaxMip()) + 1u;
|
||||
const auto tile = descriptor.TileMode();
|
||||
const bool msaa_tile = tile == Prospero::GpuEnumValue(Prospero::TileMode::kRenderTarget);
|
||||
const bool msaa_tile =
|
||||
tile == Prospero::GpuEnumValue(descriptor.MsaaDepth() ? Prospero::TileMode::kDepth
|
||||
: Prospero::TileMode::kRenderTarget);
|
||||
const bool msaa_array = type == Prospero::ImageType::kColor2DMsaaArray;
|
||||
if ((!multisampled && (base_level > last_level || last_level >= levels)) ||
|
||||
(multisampled &&
|
||||
(base_level != 0 || last_level == 0 || last_level > 3 ||
|
||||
descriptor.MaxMip() != last_level || !msaa_tile || descriptor.MsaaDepth() ||
|
||||
descriptor.MaxMip() != last_level || !msaa_tile ||
|
||||
(!msaa_array && (descriptor.Depth() != 0 || descriptor.BaseArray5() != 0))))) {
|
||||
EXIT("unsupported texture mip view: base=%u last=%u levels=%u\n", base_level, last_level,
|
||||
levels);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -55,6 +55,10 @@ constexpr FormatMapping kFormatMappings[] = {
|
||||
{Prospero::BufferFormat::k32_32_32_32UInt, vk::Format::eR32G32B32A32Uint},
|
||||
{Prospero::BufferFormat::k32_32_32_32SInt, vk::Format::eR32G32B32A32Sint},
|
||||
{Prospero::BufferFormat::k32_32_32_32Float, vk::Format::eR32G32B32A32Sfloat},
|
||||
// Narrow-channel sRGB formats are optional in Vulkan. Keep a same-width fallback until
|
||||
// sampler-aware sRGB emulation is available.
|
||||
{Prospero::BufferFormat::k8Srgb, vk::Format::eR8Unorm},
|
||||
{Prospero::BufferFormat::k8_8Srgb, vk::Format::eR8G8Unorm},
|
||||
{Prospero::BufferFormat::k8_8_8_8Srgb, vk::Format::eR8G8B8A8Srgb},
|
||||
{Prospero::BufferFormat::k9_9_9_5Float, vk::Format::eE5B9G9R9UfloatPack32},
|
||||
{Prospero::BufferFormat::k5_6_5UNorm, vk::Format::eB5G6R5UnormPack16},
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.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/ir/BindingLayout.h"
|
||||
#include "graphics/shader/recompiler/ir/ReadLaneElimination.h"
|
||||
#include "graphics/shader/recompiler/ir/ResourceMaterialization.h"
|
||||
#include "graphics/shader/recompiler/ir/ResourceTracking.h"
|
||||
#include "graphics/shader/recompiler/ir/ScalarProvenance.h"
|
||||
#include "graphics/shader/recompiler/cfg/ShaderCFG.h"
|
||||
#include "graphics/shader/recompiler/decompiler/ShaderDecoder.h"
|
||||
#include "graphics/shader/recompiler/ir/ShaderIR.h"
|
||||
#include "graphics/shader/recompiler/ir/ShaderInfoCollection.h"
|
||||
#include "graphics/shader/recompiler/emitter/SpirvEmitter.h"
|
||||
#include "graphics/shader/recompiler/ir/SrtPatcher.h"
|
||||
#include "graphics/shader/recompiler/ir/SrtWalker.h"
|
||||
|
||||
@@ -838,6 +839,11 @@ bool TryRecompile(std::span<const uint32_t> code, const CompileOptions& options,
|
||||
if (!IR::AllocateBindings(ir, layout_options, error)) {
|
||||
return false;
|
||||
}
|
||||
const auto read_lane_stats = IR::EliminateReadLane(ir);
|
||||
if (read_lane_stats.rewritten_reads != 0) {
|
||||
LOGF("%s read-lane elimination: reads=%" PRIu32 " shadow_writes=%" PRIu32 "\n",
|
||||
GetDumpLabel(options), read_lane_stats.rewritten_reads, read_lane_stats.shadow_writes);
|
||||
}
|
||||
std::string ir_dump;
|
||||
if (options.dump_ir) {
|
||||
ir_dump = MakeIrDump(cfg, ir);
|
||||
|
||||
@@ -35,9 +35,9 @@ constexpr ImageDimension DecodeImageDimension(uint32_t dim) {
|
||||
case 2u: return ImageDimension::Dim3D;
|
||||
case 3u: return ImageDimension::Dim2DArray;
|
||||
case 4u: return ImageDimension::Dim1DArray;
|
||||
case 5u:
|
||||
case 7u: return ImageDimension::Dim2DArray;
|
||||
case 6u: return ImageDimension::Dim2D;
|
||||
case 5u: return ImageDimension::Dim2DArray;
|
||||
case 6u: return ImageDimension::Dim2DMsaa;
|
||||
case 7u: return ImageDimension::Dim2DMsaaArray;
|
||||
default: return ImageDimension::Unknown;
|
||||
}
|
||||
}
|
||||
@@ -46,8 +46,10 @@ constexpr uint32_t ImageCoordComponents(ImageDimension dimension) {
|
||||
switch (dimension) {
|
||||
case ImageDimension::Dim1D: return 1u;
|
||||
case ImageDimension::Dim1DArray: return 2u;
|
||||
case ImageDimension::Dim2DMsaa:
|
||||
case ImageDimension::Dim3D:
|
||||
case ImageDimension::Dim2DArray: return 3u;
|
||||
case ImageDimension::Dim2DMsaaArray: return 4u;
|
||||
default: return 2u;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +194,8 @@ const char* ImageDimensionToString(ImageDimension dimension) {
|
||||
case ImageDimension::Dim2D: return "2d";
|
||||
case ImageDimension::Dim3D: return "3d";
|
||||
case ImageDimension::Dim2DArray: return "2d_array";
|
||||
case ImageDimension::Dim2DMsaa: return "2d_msaa";
|
||||
case ImageDimension::Dim2DMsaaArray: return "2d_msaa_array";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,6 +575,8 @@ enum class ImageDimension : uint32_t {
|
||||
Dim2D,
|
||||
Dim3D,
|
||||
Dim2DArray,
|
||||
Dim2DMsaa,
|
||||
Dim2DMsaaArray,
|
||||
};
|
||||
|
||||
constexpr uint32_t MaxInstructionRawWords = 5u;
|
||||
|
||||
@@ -30,10 +30,16 @@ bool ImageBinding(const IR::ImageResource& image, IR::DescriptorBindingKind& kin
|
||||
kind = integer ? Kind::SampledUint1DArray : Kind::Sampled1DArray;
|
||||
return true;
|
||||
case Dim::Dim2D: kind = integer ? Kind::SampledUint2D : Kind::Sampled2D; return true;
|
||||
case Dim::Dim2DMsaa:
|
||||
kind = integer ? Kind::SampledUint2DMsaa : Kind::Sampled2DMsaa;
|
||||
return true;
|
||||
case Dim::Dim3D: kind = integer ? Kind::SampledUint3D : Kind::Sampled3D; return true;
|
||||
case Dim::Dim2DArray:
|
||||
kind = integer ? Kind::SampledUint2DArray : Kind::Sampled2DArray;
|
||||
return true;
|
||||
case Dim::Dim2DMsaaArray:
|
||||
kind = integer ? Kind::SampledUint2DMsaaArray : Kind::Sampled2DMsaaArray;
|
||||
return true;
|
||||
case Dim::Unknown: return false;
|
||||
}
|
||||
}
|
||||
@@ -51,6 +57,8 @@ bool ImageBinding(const IR::ImageResource& image, IR::DescriptorBindingKind& kin
|
||||
case Dim::Dim2DArray:
|
||||
kind = uint_image ? Kind::StorageUint2DArray : Kind::Storage2DArray;
|
||||
return true;
|
||||
case Dim::Dim2DMsaa:
|
||||
case Dim::Dim2DMsaaArray: return false;
|
||||
case Dim::Unknown: return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -276,8 +276,7 @@ void CopyProgramInputsAndOutputs(EmitterState& state, const IR::Program& program
|
||||
if (HasOutput(state.outputs, output.kind, output.index)) {
|
||||
continue;
|
||||
}
|
||||
state.outputs.push_back(
|
||||
{output.kind, output.index, output.location, 0, output.debug_name});
|
||||
state.outputs.push_back({output.kind, output.index, output.location, 0, output.debug_name});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -576,6 +575,8 @@ ImageViewKind ImageViewKindFromDimension(Decoder::ImageDimension dimension) {
|
||||
case Decoder::ImageDimension::Dim1DArray: return ImageViewKind::Dim1DArray;
|
||||
case Decoder::ImageDimension::Dim2DArray: return ImageViewKind::Dim2DArray;
|
||||
case Decoder::ImageDimension::Dim3D: return ImageViewKind::Dim3D;
|
||||
case Decoder::ImageDimension::Dim2DMsaa: return ImageViewKind::Dim2DMsaa;
|
||||
case Decoder::ImageDimension::Dim2DMsaaArray: return ImageViewKind::Dim2DMsaaArray;
|
||||
default: return ImageViewKind::Dim2D;
|
||||
}
|
||||
}
|
||||
@@ -601,7 +602,9 @@ uint32_t ImageViewCoordinateComponents(ImageViewKind view) {
|
||||
case ImageViewKind::Dim1DArray:
|
||||
case ImageViewKind::Dim2D: return 2u;
|
||||
case ImageViewKind::Dim2DArray:
|
||||
case ImageViewKind::Dim2DMsaaArray:
|
||||
case ImageViewKind::Dim3D: return 3u;
|
||||
case ImageViewKind::Dim2DMsaa: return 2u;
|
||||
default: return 0u;
|
||||
}
|
||||
}
|
||||
@@ -611,7 +614,9 @@ uint32_t ImageViewSpatialComponents(ImageViewKind view) {
|
||||
case ImageViewKind::Dim1D:
|
||||
case ImageViewKind::Dim1DArray: return 1u;
|
||||
case ImageViewKind::Dim2D:
|
||||
case ImageViewKind::Dim2DArray: return 2u;
|
||||
case ImageViewKind::Dim2DArray:
|
||||
case ImageViewKind::Dim2DMsaa:
|
||||
case ImageViewKind::Dim2DMsaaArray: return 2u;
|
||||
case ImageViewKind::Dim3D: return 3u;
|
||||
default: return 0u;
|
||||
}
|
||||
@@ -663,8 +668,7 @@ uint32_t LoadSampledImageDescriptor(EmitterState& state, const IR::MemoryInfo& m
|
||||
|
||||
uint32_t LoadSamplerDescriptor(EmitterState& state, uint32_t sampler, uint32_t use_pc) {
|
||||
(void)use_pc;
|
||||
const auto binding =
|
||||
ResourceForDescriptor(state, IR::DescriptorBindingKind::Samplers, sampler);
|
||||
const auto binding = ResourceForDescriptor(state, IR::DescriptorBindingKind::Samplers, sampler);
|
||||
const auto pointer = DescriptorElementPointer(
|
||||
state, state.ptr_uniform_sampler, state.sampler_variable, binding.array_index,
|
||||
IR::DescriptorBindingKind::Samplers, sampler, "sampler descriptor array was not emitted");
|
||||
|
||||
@@ -36,8 +36,8 @@ uint32_t EmitExportVec4F32(EmitterState& state, const IR::Instruction& inst) {
|
||||
}
|
||||
}
|
||||
const auto vec = state.builder.AllocateId();
|
||||
state.builder.AddFunction({OpCompositeConstruct, state.vec4_float_type, vec,
|
||||
components[0], components[1], components[2], components[3]});
|
||||
state.builder.AddFunction({OpCompositeConstruct, state.vec4_float_type, vec, components[0],
|
||||
components[1], components[2], components[3]});
|
||||
return vec;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,59 @@ uint32_t EmitExportVec4F32(EmitterState& state, const IR::Instruction& inst) {
|
||||
return vec;
|
||||
}
|
||||
|
||||
uint32_t ApplyMrtExportMapping(EmitterState& state, const IR::Instruction& inst, uint32_t value) {
|
||||
uint32_t EmitExportComponentU32(EmitterState& state, const IR::Instruction& inst,
|
||||
uint32_t component) {
|
||||
const bool enabled = ((inst.export_info.en >> component) & 1u) != 0;
|
||||
if (!enabled || component >= inst.src_count || component >= 4u) {
|
||||
return ConstantU32(state, component == 3u ? 1u : 0u);
|
||||
}
|
||||
return EmitValueLoad(state, inst.src[component]);
|
||||
}
|
||||
|
||||
uint32_t EmitExportVec4U32(EmitterState& state, const IR::Instruction& inst) {
|
||||
uint32_t components[4] = {
|
||||
ConstantU32(state, 0u),
|
||||
ConstantU32(state, 0u),
|
||||
ConstantU32(state, 0u),
|
||||
ConstantU32(state, 1u),
|
||||
};
|
||||
|
||||
if (inst.export_info.compr) {
|
||||
for (uint32_t pair_index = 0; pair_index < 2u && pair_index < inst.src_count;
|
||||
pair_index++) {
|
||||
const auto raw = EmitValueLoad(state, inst.src[pair_index]);
|
||||
for (uint32_t lane = 0; lane < 2u; lane++) {
|
||||
const auto component = pair_index * 2u + lane;
|
||||
if (((inst.export_info.en >> component) & 1u) == 0) {
|
||||
continue;
|
||||
}
|
||||
components[component] = state.builder.AllocateId();
|
||||
state.builder.AddFunction(
|
||||
{OpBitFieldUExtract, state.uint_type, components[component], raw,
|
||||
ConstantU32(state, lane * 16u), ConstantU32(state, 16u)});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (uint32_t component = 0; component < 4u; component++) {
|
||||
components[component] = EmitExportComponentU32(state, inst, component);
|
||||
}
|
||||
}
|
||||
|
||||
const auto vec = state.builder.AllocateId();
|
||||
state.builder.AddFunction({OpCompositeConstruct, state.vec4_uint_type, vec, components[0],
|
||||
components[1], components[2], components[3]});
|
||||
return vec;
|
||||
}
|
||||
|
||||
static bool MrtUsesUintOutput(const EmitterState& state, const IR::Instruction& inst) {
|
||||
return inst.export_info.kind == IR::ExportTargetKind::Mrt &&
|
||||
state.pixel_input_info != nullptr &&
|
||||
inst.export_info.index < std::size(state.pixel_input_info->target_output_mode) &&
|
||||
state.pixel_input_info->target_output_mode[inst.export_info.index] == 7u;
|
||||
}
|
||||
|
||||
uint32_t ApplyMrtExportMapping(EmitterState& state, const IR::Instruction& inst, uint32_t value,
|
||||
uint32_t vector_type) {
|
||||
if (inst.export_info.kind != IR::ExportTargetKind::Mrt || state.pixel_input_info == nullptr ||
|
||||
inst.export_info.index >= state.pixel_input_info->target_export_mapping.size()) {
|
||||
return value;
|
||||
@@ -62,8 +114,8 @@ uint32_t ApplyMrtExportMapping(EmitterState& state, const IR::Instruction& inst,
|
||||
}
|
||||
|
||||
const auto mapped = state.builder.AllocateId();
|
||||
state.builder.AddFunction({OpVectorShuffle, state.vec4_float_type, mapped, value, value,
|
||||
mapping.Map(0), mapping.Map(1), mapping.Map(2), mapping.Map(3)});
|
||||
state.builder.AddFunction({OpVectorShuffle, vector_type, mapped, value, value, mapping.Map(0),
|
||||
mapping.Map(1), mapping.Map(2), mapping.Map(3)});
|
||||
return mapped;
|
||||
}
|
||||
|
||||
@@ -114,11 +166,15 @@ void EmitExport(EmitterState& state, const IR::Instruction& inst) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto value = ApplyMrtExportMapping(state, inst, EmitExportVec4F32(state, inst));
|
||||
const auto uint_output = MrtUsesUintOutput(state, inst);
|
||||
const auto vector_type = uint_output ? state.vec4_uint_type : state.vec4_float_type;
|
||||
const auto value = ApplyMrtExportMapping(
|
||||
state, inst, uint_output ? EmitExportVec4U32(state, inst) : EmitExportVec4F32(state, inst),
|
||||
vector_type);
|
||||
if (inst.export_info.kind == IR::ExportTargetKind::Position) {
|
||||
const auto pointer = state.builder.AllocateId();
|
||||
state.builder.AddFunction({OpAccessChain, state.ptr_output_vec4_float, pointer, variable,
|
||||
ConstantU32(state, 0)});
|
||||
state.builder.AddFunction(
|
||||
{OpAccessChain, state.ptr_output_vec4_float, pointer, variable, ConstantU32(state, 0)});
|
||||
state.builder.AddFunction({OpStore, pointer, value});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -150,8 +150,8 @@ void EmitWqmB64(EmitterState& state, const IR::Instruction& inst) {
|
||||
EmitPerInvocationMask(state, inst.dst, active);
|
||||
} else {
|
||||
const auto result = state.builder.AllocateId();
|
||||
state.builder.AddFunction({OpSelect, state.uint_type, result, active,
|
||||
ConstantU32(state, 1), ConstantU32(state, 0)});
|
||||
state.builder.AddFunction({OpSelect, state.uint_type, result, active, ConstantU32(state, 1),
|
||||
ConstantU32(state, 0)});
|
||||
EmitStoreU32(state, inst.dst, result);
|
||||
EmitStoreU32(state, OffsetRegisterOperand(inst.dst, 1), ConstantU32(state, 0));
|
||||
}
|
||||
@@ -205,8 +205,7 @@ void EmitSaveexecB32(EmitterState& state, const IR::Instruction& inst) {
|
||||
|
||||
const auto cond = state.builder.AllocateId();
|
||||
const auto scc = state.builder.AllocateId();
|
||||
state.builder.AddFunction(
|
||||
{OpINotEqual, state.bool_type, cond, new_low, ConstantU32(state, 0)});
|
||||
state.builder.AddFunction({OpINotEqual, state.bool_type, cond, new_low, ConstantU32(state, 0)});
|
||||
state.builder.AddFunction(
|
||||
{OpSelect, state.uint_type, scc, cond, ConstantU32(state, 1), ConstantU32(state, 0)});
|
||||
EmitStoreU32(state, SccOperand(), scc);
|
||||
@@ -279,8 +278,9 @@ void EmitReadFirstLaneU32(EmitterState& state, const IR::Instruction& inst) {
|
||||
|
||||
uint32_t EmitLaneIndex(EmitterState& state, const IR::Operand& operand) {
|
||||
const auto lane = state.builder.AllocateId();
|
||||
const auto mask = state.wave_size == 32u ? 31u : 63u;
|
||||
state.builder.AddFunction({OpBitwiseAnd, state.uint_type, lane, EmitValueLoad(state, operand),
|
||||
ConstantU32(state, 63)});
|
||||
ConstantU32(state, mask)});
|
||||
return lane;
|
||||
}
|
||||
|
||||
@@ -336,10 +336,8 @@ void EmitPermlaneB32(EmitterState& state, const IR::Instruction& inst, bool x16)
|
||||
state.builder.AddFunction(
|
||||
{OpBitwiseXor, state.uint_type, row_value, row, ConstantU32(state, 16)});
|
||||
}
|
||||
state.builder.AddFunction(
|
||||
{OpBitwiseAnd, state.uint_type, lane, subid, ConstantU32(state, 15)});
|
||||
state.builder.AddFunction(
|
||||
{OpBitwiseAnd, state.uint_type, lane8, lane, ConstantU32(state, 7)});
|
||||
state.builder.AddFunction({OpBitwiseAnd, state.uint_type, lane, subid, ConstantU32(state, 15)});
|
||||
state.builder.AddFunction({OpBitwiseAnd, state.uint_type, lane8, lane, ConstantU32(state, 7)});
|
||||
state.builder.AddFunction(
|
||||
{OpShiftLeftLogical, state.uint_type, shift, lane8, ConstantU32(state, 2)});
|
||||
state.builder.AddFunction(
|
||||
|
||||
@@ -133,10 +133,18 @@ void EmitImageLoad(EmitterState& state, const IR::Instruction& inst) {
|
||||
const bool integer = inst.memory.kind == IR::ResourceKind::ImageUint;
|
||||
|
||||
const auto color = state.builder.AllocateId();
|
||||
state.builder.AddFunction({OpImageFetch, integer ? state.vec4_uint_type : state.vec4_float_type,
|
||||
color, image, EmitImageLoadCoordU32(state, inst, view),
|
||||
ImageOperandsLodMask,
|
||||
EmitImageMipLodU32(state, inst, inst.src[0], view)});
|
||||
const auto coord = EmitImageLoadCoordU32(state, inst, view);
|
||||
if (ImageSpirvMultisampled(view) != 0) {
|
||||
const auto sample = EmitImageAddressValueLoad(state, inst, inst.src[0],
|
||||
ImageViewCoordinateComponents(view));
|
||||
state.builder.AddFunction({OpImageFetch,
|
||||
integer ? state.vec4_uint_type : state.vec4_float_type, color,
|
||||
image, coord, ImageOperandsSampleMask, sample});
|
||||
} else {
|
||||
state.builder.AddFunction(
|
||||
{OpImageFetch, integer ? state.vec4_uint_type : state.vec4_float_type, color, image,
|
||||
coord, ImageOperandsLodMask, EmitImageMipLodU32(state, inst, inst.src[0], view)});
|
||||
}
|
||||
|
||||
const auto dmask = inst.memory.dmask != 0 ? inst.memory.dmask : 1u;
|
||||
uint32_t dst_index = 0;
|
||||
@@ -158,8 +166,8 @@ void EmitImageLoad(EmitterState& state, const IR::Instruction& inst) {
|
||||
void EmitImageStore(EmitterState& state, const IR::Instruction& inst) {
|
||||
const auto uint_image = inst.memory.kind == IR::ResourceKind::StorageImageUint;
|
||||
const auto view = StorageImageViewKind(state, inst.memory, uint_image, inst.pc);
|
||||
const auto binding = ResourceForDescriptor(state, StorageBindingKind(uint_image, view),
|
||||
inst.memory.resource);
|
||||
const auto binding =
|
||||
ResourceForDescriptor(state, StorageBindingKind(uint_image, view), inst.memory.resource);
|
||||
const auto image = LoadStorageImageDescriptorAtIndex(state, inst.memory.resource,
|
||||
binding.array_index, uint_image, view);
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ enum : uint32_t {
|
||||
ImageOperandsGradMask = 0x00000004u,
|
||||
ImageOperandsOffsetMask = 0x00000010u,
|
||||
ImageOperandsConstOffsetsMask = 0x00000020u,
|
||||
ImageOperandsSampleMask = 0x00000040u,
|
||||
};
|
||||
|
||||
enum : uint32_t {
|
||||
@@ -150,7 +151,6 @@ enum : uint32_t {
|
||||
OpImageGather = 96,
|
||||
OpImageDrefGather = 97,
|
||||
OpImageWrite = 99,
|
||||
OpImage = 100,
|
||||
OpImageQuerySizeLod = 103,
|
||||
OpImageQueryLod = 105,
|
||||
OpImageQueryLevels = 106,
|
||||
@@ -382,7 +382,7 @@ struct EmitterState {
|
||||
uint32_t ptr_workgroup_array = 0;
|
||||
uint32_t ptr_workgroup_uint = 0;
|
||||
uint32_t lds_variable = 0;
|
||||
std::array<SampledImageDescriptors, 10> sampled_images;
|
||||
std::array<SampledImageDescriptors, 14> sampled_images;
|
||||
std::array<StorageImageDescriptors, 10> storage_images;
|
||||
uint32_t sampler_type = 0;
|
||||
uint32_t sampler_array_type = 0;
|
||||
@@ -453,17 +453,20 @@ enum class ImageViewKind {
|
||||
Dim2D,
|
||||
Dim2DArray,
|
||||
Dim3D,
|
||||
Dim2DMsaa,
|
||||
Dim2DMsaaArray,
|
||||
Count,
|
||||
};
|
||||
|
||||
constexpr uint32_t ImageViewKindCount = static_cast<uint32_t>(ImageViewKind::Count);
|
||||
constexpr uint32_t SampledImageViewKindCount = static_cast<uint32_t>(ImageViewKind::Count);
|
||||
constexpr uint32_t StorageImageViewKindCount = static_cast<uint32_t>(ImageViewKind::Dim2DMsaa);
|
||||
|
||||
constexpr uint32_t SampledImageIndex(bool integer, ImageViewKind view) {
|
||||
return static_cast<uint32_t>(view) + (integer ? ImageViewKindCount : 0u);
|
||||
return static_cast<uint32_t>(view) + (integer ? SampledImageViewKindCount : 0u);
|
||||
}
|
||||
|
||||
constexpr uint32_t StorageImageIndex(bool integer, ImageViewKind view) {
|
||||
return static_cast<uint32_t>(view) + (integer ? ImageViewKindCount : 0u);
|
||||
return static_cast<uint32_t>(view) + (integer ? StorageImageViewKindCount : 0u);
|
||||
}
|
||||
|
||||
constexpr IR::DescriptorBindingKind SampledBindingKind(bool integer, ImageViewKind view) {
|
||||
@@ -474,6 +477,9 @@ constexpr IR::DescriptorBindingKind SampledBindingKind(bool integer, ImageViewKi
|
||||
case ImageViewKind::Dim2D: return IR::DescriptorBindingKind::SampledUint2D;
|
||||
case ImageViewKind::Dim2DArray: return IR::DescriptorBindingKind::SampledUint2DArray;
|
||||
case ImageViewKind::Dim3D: return IR::DescriptorBindingKind::SampledUint3D;
|
||||
case ImageViewKind::Dim2DMsaa: return IR::DescriptorBindingKind::SampledUint2DMsaa;
|
||||
case ImageViewKind::Dim2DMsaaArray:
|
||||
return IR::DescriptorBindingKind::SampledUint2DMsaaArray;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -483,6 +489,8 @@ constexpr IR::DescriptorBindingKind SampledBindingKind(bool integer, ImageViewKi
|
||||
case ImageViewKind::Dim2D: return IR::DescriptorBindingKind::Sampled2D;
|
||||
case ImageViewKind::Dim2DArray: return IR::DescriptorBindingKind::Sampled2DArray;
|
||||
case ImageViewKind::Dim3D: return IR::DescriptorBindingKind::Sampled3D;
|
||||
case ImageViewKind::Dim2DMsaa: return IR::DescriptorBindingKind::Sampled2DMsaa;
|
||||
case ImageViewKind::Dim2DMsaaArray: return IR::DescriptorBindingKind::Sampled2DMsaaArray;
|
||||
default: break;
|
||||
}
|
||||
return IR::DescriptorBindingKind::Count;
|
||||
@@ -516,6 +524,8 @@ constexpr uint32_t ImageSpirvDimension(ImageViewKind view) {
|
||||
case ImageViewKind::Dim1DArray: return Dim1D;
|
||||
case ImageViewKind::Dim2D:
|
||||
case ImageViewKind::Dim2DArray:
|
||||
case ImageViewKind::Dim2DMsaa:
|
||||
case ImageViewKind::Dim2DMsaaArray:
|
||||
case ImageViewKind::Count: return Dim2D;
|
||||
case ImageViewKind::Dim3D: return Dim3D;
|
||||
}
|
||||
@@ -523,7 +533,14 @@ constexpr uint32_t ImageSpirvDimension(ImageViewKind view) {
|
||||
}
|
||||
|
||||
constexpr uint32_t ImageSpirvArrayed(ImageViewKind view) {
|
||||
return view == ImageViewKind::Dim1DArray || view == ImageViewKind::Dim2DArray ? 1u : 0u;
|
||||
return view == ImageViewKind::Dim1DArray || view == ImageViewKind::Dim2DArray ||
|
||||
view == ImageViewKind::Dim2DMsaaArray
|
||||
? 1u
|
||||
: 0u;
|
||||
}
|
||||
|
||||
constexpr uint32_t ImageSpirvMultisampled(ImageViewKind view) {
|
||||
return view == ImageViewKind::Dim2DMsaa || view == ImageViewKind::Dim2DMsaaArray ? 1u : 0u;
|
||||
}
|
||||
|
||||
struct AddCarryResult {
|
||||
|
||||
@@ -174,6 +174,12 @@ uint32_t VertexParameterInputPointerType(const EmitterState& state, VertexInputS
|
||||
}
|
||||
}
|
||||
|
||||
static bool MrtUsesUintOutput(const EmitterState& state, uint32_t index) {
|
||||
return state.stage == ShaderType::Pixel && state.pixel_input_info != nullptr &&
|
||||
index < std::size(state.pixel_input_info->target_output_mode) &&
|
||||
state.pixel_input_info->target_output_mode[index] == 7u;
|
||||
}
|
||||
|
||||
void AllocateInputVariables(EmitterState& state) {
|
||||
for (auto& binding: state.inputs) {
|
||||
binding.variable_id = state.builder.AllocateId();
|
||||
@@ -323,23 +329,39 @@ void AddDescriptorAnnotationsAndNames(EmitterState& state) {
|
||||
Decorate(state.address_memory_variable, "address_memory",
|
||||
IR::DescriptorBindingKind::AddressMemory);
|
||||
}
|
||||
constexpr const char* SampledNames[] = {
|
||||
"sampled_1d", "sampled_1d_array", "sampled_2d", "sampled_2d_array",
|
||||
"sampled_3d", "sampled_uint_1d", "sampled_uint_1d_array",
|
||||
"sampled_uint_2d", "sampled_uint_2d_array", "sampled_uint_3d"};
|
||||
constexpr const char* SampledNames[] = {"sampled_1d",
|
||||
"sampled_1d_array",
|
||||
"sampled_2d",
|
||||
"sampled_2d_array",
|
||||
"sampled_3d",
|
||||
"sampled_2d_msaa",
|
||||
"sampled_2d_msaa_array",
|
||||
"sampled_uint_1d",
|
||||
"sampled_uint_1d_array",
|
||||
"sampled_uint_2d",
|
||||
"sampled_uint_2d_array",
|
||||
"sampled_uint_3d",
|
||||
"sampled_uint_2d_msaa",
|
||||
"sampled_uint_2d_msaa_array"};
|
||||
for (uint32_t i = 0; i < state.sampled_images.size(); i++) {
|
||||
const auto view = static_cast<ImageViewKind>(i % ImageViewKindCount);
|
||||
const auto view = static_cast<ImageViewKind>(i % SampledImageViewKindCount);
|
||||
Decorate(state.sampled_images[i].variable, SampledNames[i],
|
||||
SampledBindingKind(i >= ImageViewKindCount, view));
|
||||
SampledBindingKind(i >= SampledImageViewKindCount, view));
|
||||
}
|
||||
constexpr const char* StorageNames[] = {
|
||||
"storage_1d", "storage_1d_array", "storage_2d", "storage_2d_array",
|
||||
"storage_3d", "storage_uint_1d", "storage_uint_1d_array",
|
||||
"storage_uint_2d", "storage_uint_2d_array", "storage_uint_3d"};
|
||||
constexpr const char* StorageNames[] = {"storage_1d",
|
||||
"storage_1d_array",
|
||||
"storage_2d",
|
||||
"storage_2d_array",
|
||||
"storage_3d",
|
||||
"storage_uint_1d",
|
||||
"storage_uint_1d_array",
|
||||
"storage_uint_2d",
|
||||
"storage_uint_2d_array",
|
||||
"storage_uint_3d"};
|
||||
for (uint32_t i = 0; i < state.storage_images.size(); i++) {
|
||||
const auto view = static_cast<ImageViewKind>(i % ImageViewKindCount);
|
||||
const auto view = static_cast<ImageViewKind>(i % StorageImageViewKindCount);
|
||||
Decorate(state.storage_images[i].variable, StorageNames[i],
|
||||
StorageBindingKind(i >= ImageViewKindCount, view));
|
||||
StorageBindingKind(i >= StorageImageViewKindCount, view));
|
||||
}
|
||||
if (state.sampler_variable != 0) {
|
||||
Decorate(state.sampler_variable, "samplers", IR::DescriptorBindingKind::Samplers);
|
||||
@@ -409,6 +431,7 @@ void EmitHeaderAndTypes(EmitterState& state) {
|
||||
state.ptr_output_sample_mask_array = state.builder.AllocateId();
|
||||
state.ptr_output_float = state.builder.AllocateId();
|
||||
state.ptr_output_vec4_float = state.builder.AllocateId();
|
||||
const auto ptr_output_vec4_uint = state.builder.AllocateId();
|
||||
state.per_vertex_type = state.builder.AllocateId();
|
||||
state.ptr_output_per_vertex = state.builder.AllocateId();
|
||||
state.storage_runtime_array_type = state.builder.AllocateId();
|
||||
@@ -462,7 +485,7 @@ void EmitHeaderAndTypes(EmitterState& state) {
|
||||
state.builder.AddCapability({CapabilityImageGatherExtended});
|
||||
}
|
||||
if (std::any_of(state.storage_images.begin(),
|
||||
state.storage_images.begin() + ImageViewKindCount,
|
||||
state.storage_images.begin() + StorageImageViewKindCount,
|
||||
[](const auto& image) { return image.variable != 0; })) {
|
||||
state.builder.AddCapability({CapabilityStorageImageReadWithoutFormat});
|
||||
state.builder.AddCapability({CapabilityStorageImageWriteWithoutFormat});
|
||||
@@ -605,6 +628,8 @@ void EmitHeaderAndTypes(EmitterState& state) {
|
||||
{OpTypePointer, state.ptr_output_int, StorageClassOutput, state.int_type});
|
||||
state.builder.AddType(
|
||||
{OpTypePointer, state.ptr_output_vec4_float, StorageClassOutput, state.vec4_float_type});
|
||||
state.builder.AddType(
|
||||
{OpTypePointer, ptr_output_vec4_uint, StorageClassOutput, state.vec4_uint_type});
|
||||
if (state.per_vertex_variable != 0) {
|
||||
state.builder.AddType({OpTypeStruct, state.per_vertex_type, state.vec4_float_type});
|
||||
state.builder.AddType({OpTypePointer, state.ptr_output_per_vertex, StorageClassOutput,
|
||||
@@ -615,8 +640,12 @@ void EmitHeaderAndTypes(EmitterState& state) {
|
||||
for (const auto& binding: state.outputs) {
|
||||
if (binding.kind == IR::StageOutputKind::Parameter ||
|
||||
binding.kind == IR::StageOutputKind::Mrt) {
|
||||
const auto pointer_type =
|
||||
binding.kind == IR::StageOutputKind::Mrt && MrtUsesUintOutput(state, binding.index)
|
||||
? ptr_output_vec4_uint
|
||||
: state.ptr_output_vec4_float;
|
||||
state.builder.AddType(
|
||||
{OpVariable, state.ptr_output_vec4_float, binding.variable_id, StorageClassOutput});
|
||||
{OpVariable, pointer_type, binding.variable_id, StorageClassOutput});
|
||||
}
|
||||
}
|
||||
if (state.depth_variable != 0) {
|
||||
@@ -700,11 +729,11 @@ void EmitHeaderAndTypes(EmitterState& state) {
|
||||
}
|
||||
for (uint32_t i = 0; i < state.sampled_images.size(); i++) {
|
||||
auto& image = state.sampled_images[i];
|
||||
const auto view = static_cast<ImageViewKind>(i % ImageViewKindCount);
|
||||
const bool integer = i >= ImageViewKindCount;
|
||||
const auto view = static_cast<ImageViewKind>(i % SampledImageViewKindCount);
|
||||
const bool integer = i >= SampledImageViewKindCount;
|
||||
const auto component = integer ? state.uint_type : state.float_type;
|
||||
state.builder.AddType({OpTypeImage, image.image_type, component,
|
||||
ImageSpirvDimension(view), 0, ImageSpirvArrayed(view), 0, 1,
|
||||
state.builder.AddType({OpTypeImage, image.image_type, component, ImageSpirvDimension(view),
|
||||
0, ImageSpirvArrayed(view), ImageSpirvMultisampled(view), 1,
|
||||
ImageFormatUnknown});
|
||||
state.builder.AddType({OpTypeSampledImage, image.sampled_image_type, image.image_type});
|
||||
state.builder.AddType(
|
||||
@@ -733,13 +762,12 @@ void EmitHeaderAndTypes(EmitterState& state) {
|
||||
}
|
||||
for (uint32_t i = 0; i < state.storage_images.size(); i++) {
|
||||
auto& image = state.storage_images[i];
|
||||
const auto view = static_cast<ImageViewKind>(i % ImageViewKindCount);
|
||||
const bool integer = i >= ImageViewKindCount;
|
||||
const auto view = static_cast<ImageViewKind>(i % StorageImageViewKindCount);
|
||||
const bool integer = i >= StorageImageViewKindCount;
|
||||
const auto component = integer ? state.uint_type : state.float_type;
|
||||
const auto format = integer ? ImageFormatR32ui : ImageFormatUnknown;
|
||||
state.builder.AddType({OpTypeImage, image.image_type, component,
|
||||
ImageSpirvDimension(view), 0, ImageSpirvArrayed(view), 0, 2,
|
||||
format});
|
||||
state.builder.AddType({OpTypeImage, image.image_type, component, ImageSpirvDimension(view),
|
||||
0, ImageSpirvArrayed(view), 0, 2, format});
|
||||
state.builder.AddType(
|
||||
{OpTypePointer, image.pointer_type, StorageClassUniformConstant, image.image_type});
|
||||
if (image.variable != 0) {
|
||||
@@ -786,15 +814,15 @@ void AllocateDescriptorVariables(EmitterState& state) {
|
||||
state.flattened_srt_variable = state.builder.AllocateId();
|
||||
}
|
||||
for (uint32_t i = 0; i < state.sampled_images.size(); i++) {
|
||||
const auto view = static_cast<ImageViewKind>(i % ImageViewKindCount);
|
||||
if (DescriptorBinding(state, SampledBindingKind(i >= ImageViewKindCount, view)) !=
|
||||
const auto view = static_cast<ImageViewKind>(i % SampledImageViewKindCount);
|
||||
if (DescriptorBinding(state, SampledBindingKind(i >= SampledImageViewKindCount, view)) !=
|
||||
nullptr) {
|
||||
state.sampled_images[i].variable = state.builder.AllocateId();
|
||||
}
|
||||
}
|
||||
for (uint32_t i = 0; i < state.storage_images.size(); i++) {
|
||||
const auto view = static_cast<ImageViewKind>(i % ImageViewKindCount);
|
||||
if (DescriptorBinding(state, StorageBindingKind(i >= ImageViewKindCount, view)) !=
|
||||
const auto view = static_cast<ImageViewKind>(i % StorageImageViewKindCount);
|
||||
if (DescriptorBinding(state, StorageBindingKind(i >= StorageImageViewKindCount, view)) !=
|
||||
nullptr) {
|
||||
state.storage_images[i].variable = state.builder.AllocateId();
|
||||
}
|
||||
|
||||
@@ -13,16 +13,30 @@ namespace {
|
||||
constexpr uint32_t MaxPushConstantBytes = 128;
|
||||
|
||||
constexpr std::array ImageBindingKinds = {
|
||||
DescriptorBindingKind::Sampled1D, DescriptorBindingKind::Sampled1DArray,
|
||||
DescriptorBindingKind::Sampled2D, DescriptorBindingKind::Sampled2DArray,
|
||||
DescriptorBindingKind::Sampled3D, DescriptorBindingKind::SampledUint1D,
|
||||
DescriptorBindingKind::SampledUint1DArray, DescriptorBindingKind::SampledUint2D,
|
||||
DescriptorBindingKind::SampledUint2DArray, DescriptorBindingKind::SampledUint3D,
|
||||
DescriptorBindingKind::Storage1D, DescriptorBindingKind::Storage1DArray,
|
||||
DescriptorBindingKind::Storage2D, DescriptorBindingKind::Storage2DArray,
|
||||
DescriptorBindingKind::Storage3D, DescriptorBindingKind::StorageUint1D,
|
||||
DescriptorBindingKind::StorageUint1DArray, DescriptorBindingKind::StorageUint2D,
|
||||
DescriptorBindingKind::StorageUint2DArray, DescriptorBindingKind::StorageUint3D,
|
||||
DescriptorBindingKind::Sampled1D,
|
||||
DescriptorBindingKind::Sampled1DArray,
|
||||
DescriptorBindingKind::Sampled2D,
|
||||
DescriptorBindingKind::Sampled2DArray,
|
||||
DescriptorBindingKind::Sampled2DMsaa,
|
||||
DescriptorBindingKind::Sampled2DMsaaArray,
|
||||
DescriptorBindingKind::Sampled3D,
|
||||
DescriptorBindingKind::SampledUint1D,
|
||||
DescriptorBindingKind::SampledUint1DArray,
|
||||
DescriptorBindingKind::SampledUint2D,
|
||||
DescriptorBindingKind::SampledUint2DArray,
|
||||
DescriptorBindingKind::SampledUint2DMsaa,
|
||||
DescriptorBindingKind::SampledUint2DMsaaArray,
|
||||
DescriptorBindingKind::SampledUint3D,
|
||||
DescriptorBindingKind::Storage1D,
|
||||
DescriptorBindingKind::Storage1DArray,
|
||||
DescriptorBindingKind::Storage2D,
|
||||
DescriptorBindingKind::Storage2DArray,
|
||||
DescriptorBindingKind::Storage3D,
|
||||
DescriptorBindingKind::StorageUint1D,
|
||||
DescriptorBindingKind::StorageUint1DArray,
|
||||
DescriptorBindingKind::StorageUint2D,
|
||||
DescriptorBindingKind::StorageUint2DArray,
|
||||
DescriptorBindingKind::StorageUint3D,
|
||||
};
|
||||
|
||||
bool ImageBinding(const ImageResource& image, DescriptorBindingKind& result) {
|
||||
@@ -36,6 +50,8 @@ bool ImageBinding(const ImageResource& image, DescriptorBindingKind& result) {
|
||||
case Dimension::Dim1DArray: result = Kind::Sampled1DArray; return true;
|
||||
case Dimension::Dim2D: result = Kind::Sampled2D; return true;
|
||||
case Dimension::Dim2DArray: result = Kind::Sampled2DArray; return true;
|
||||
case Dimension::Dim2DMsaa: result = Kind::Sampled2DMsaa; return true;
|
||||
case Dimension::Dim2DMsaaArray: result = Kind::Sampled2DMsaaArray; return true;
|
||||
case Dimension::Dim3D: result = Kind::Sampled3D; return true;
|
||||
default: return false;
|
||||
}
|
||||
@@ -45,6 +61,8 @@ bool ImageBinding(const ImageResource& image, DescriptorBindingKind& result) {
|
||||
case Dimension::Dim1DArray: result = Kind::SampledUint1DArray; return true;
|
||||
case Dimension::Dim2D: result = Kind::SampledUint2D; return true;
|
||||
case Dimension::Dim2DArray: result = Kind::SampledUint2DArray; return true;
|
||||
case Dimension::Dim2DMsaa: result = Kind::SampledUint2DMsaa; return true;
|
||||
case Dimension::Dim2DMsaaArray: result = Kind::SampledUint2DMsaaArray; return true;
|
||||
case Dimension::Dim3D: result = Kind::SampledUint3D; return true;
|
||||
default: return false;
|
||||
}
|
||||
@@ -165,8 +183,7 @@ bool CollectUserData(const Program& program, std::vector<uint32_t>& result) {
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 0; i < inst.src_count; i++) {
|
||||
if (!CollectValue(program.provenance, inst.scalar_sources[i], visited,
|
||||
registers)) {
|
||||
if (!CollectValue(program.provenance, inst.scalar_sources[i], visited, registers)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
#include "graphics/shader/recompiler/ir/ReadLaneElimination.h"
|
||||
|
||||
#include "graphics/shader/recompiler/ir/SrtWalker.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
namespace Libs::Graphics::ShaderRecompiler::IR {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint32_t FirstTemporaryScalarRegister = 128;
|
||||
|
||||
struct LaneKey {
|
||||
uint32_t reg = 0;
|
||||
uint32_t lane = 0;
|
||||
|
||||
auto operator<=>(const LaneKey&) const = default;
|
||||
};
|
||||
|
||||
using LaneSet = std::set<LaneKey>;
|
||||
|
||||
bool PairDwordOpcode(Opcode op) {
|
||||
switch (op) {
|
||||
case Opcode::MoveU64:
|
||||
case Opcode::WqmB64:
|
||||
case Opcode::SaveexecB64:
|
||||
case Opcode::BitwiseAndU64:
|
||||
case Opcode::BitwiseAndNotU64:
|
||||
case Opcode::BitwiseOrU64:
|
||||
case Opcode::BitwiseOrNotU64:
|
||||
case Opcode::BitwiseXorU64:
|
||||
case Opcode::BitwiseNandU64:
|
||||
case Opcode::BitwiseNorU64:
|
||||
case Opcode::BitwiseXnorU64:
|
||||
case Opcode::BitwiseNotU64:
|
||||
case Opcode::BitFieldMaskU64:
|
||||
case Opcode::BitFieldExtractU64:
|
||||
case Opcode::BitReplicateB64B32:
|
||||
case Opcode::ShiftLeftLogicalU64:
|
||||
case Opcode::ShiftRightLogicalU64:
|
||||
case Opcode::SelectU64: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ResolveLane(const Program& program, const Instruction& inst, uint32_t source_index,
|
||||
uint32_t& lane) {
|
||||
if (source_index >= inst.src_count || (program.wave_size != 32 && program.wave_size != 64)) {
|
||||
return false;
|
||||
}
|
||||
const auto& selector = inst.src[source_index];
|
||||
if (selector.kind == OperandKind::ImmediateU32) {
|
||||
lane = selector.imm % program.wave_size;
|
||||
return true;
|
||||
}
|
||||
uint32_t folded = 0;
|
||||
if (!FoldScalarConstant(program.provenance, inst.scalar_sources[source_index], folded)) {
|
||||
return false;
|
||||
}
|
||||
lane = folded % program.wave_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UniformWriteSource(const Instruction& inst) {
|
||||
if (inst.src_count == 0) {
|
||||
return false;
|
||||
}
|
||||
const auto& source = inst.src[0];
|
||||
if (source.kind == OperandKind::ImmediateU32 || source.kind == OperandKind::PcRelativeU32) {
|
||||
return true;
|
||||
}
|
||||
return source.kind == OperandKind::Register &&
|
||||
(source.reg.file == RegisterFile::Scalar || source.reg.file == RegisterFile::Scc ||
|
||||
source.reg.file == RegisterFile::M0);
|
||||
}
|
||||
|
||||
bool WriteLaneKey(const Program& program, const Instruction& inst, LaneKey& key) {
|
||||
if (inst.op != Opcode::WriteLaneU32 || inst.dst.kind != OperandKind::Register ||
|
||||
inst.dst.reg.file != RegisterFile::Vector || !UniformWriteSource(inst)) {
|
||||
return false;
|
||||
}
|
||||
uint32_t lane = 0;
|
||||
if (!ResolveLane(program, inst, 1, lane)) {
|
||||
return false;
|
||||
}
|
||||
key = {inst.dst.reg.index, lane};
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReadLaneKey(const Program& program, const Instruction& inst, LaneKey& key) {
|
||||
if (inst.op != Opcode::ReadLaneU32 || inst.src_count < 2 ||
|
||||
inst.src[0].kind != OperandKind::Register || inst.src[0].reg.file != RegisterFile::Vector) {
|
||||
return false;
|
||||
}
|
||||
uint32_t lane = 0;
|
||||
if (!ResolveLane(program, inst, 1, lane)) {
|
||||
return false;
|
||||
}
|
||||
key = {inst.src[0].reg.index, lane};
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvalidateRegister(LaneSet& valid, uint32_t reg) {
|
||||
const auto first = valid.lower_bound({reg, 0});
|
||||
const auto last = valid.lower_bound({reg + 1u, 0});
|
||||
valid.erase(first, last);
|
||||
}
|
||||
|
||||
void ApplyInstruction(const Program& program, const Instruction& inst, LaneSet& valid) {
|
||||
if (inst.op == Opcode::WriteLaneU32 && inst.dst.kind == OperandKind::Register &&
|
||||
inst.dst.reg.file == RegisterFile::Vector) {
|
||||
LaneKey key;
|
||||
if (WriteLaneKey(program, inst, key)) {
|
||||
valid.insert(key);
|
||||
return;
|
||||
}
|
||||
uint32_t lane = 0;
|
||||
if (ResolveLane(program, inst, 1, lane)) {
|
||||
valid.erase({inst.dst.reg.index, lane});
|
||||
} else {
|
||||
InvalidateRegister(valid, inst.dst.reg.index);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (inst.op == Opcode::MoveRelDestU32 && inst.dst.kind == OperandKind::Register &&
|
||||
inst.dst.reg.file == RegisterFile::Vector) {
|
||||
valid.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (inst.dst.kind == OperandKind::Register && inst.dst.reg.file == RegisterFile::Vector) {
|
||||
uint32_t dwords = std::max(inst.memory.data_dwords, 1u);
|
||||
if (PairDwordOpcode(inst.op) || inst.op == Opcode::UMadU64U32) {
|
||||
dwords = std::max(dwords, 2u);
|
||||
}
|
||||
for (uint32_t i = 0; i < dwords && inst.dst.reg.index <= UINT32_MAX - i; i++) {
|
||||
InvalidateRegister(valid, inst.dst.reg.index + i);
|
||||
}
|
||||
}
|
||||
if (inst.dst2.kind == OperandKind::Register && inst.dst2.reg.file == RegisterFile::Vector) {
|
||||
InvalidateRegister(valid, inst.dst2.reg.index);
|
||||
}
|
||||
}
|
||||
|
||||
LaneSet TransferBlock(const Program& program, const BasicBlock& block, LaneSet state) {
|
||||
for (const auto& inst: block.instructions) {
|
||||
ApplyInstruction(program, inst, state);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
LaneSet Intersect(const LaneSet& left, const LaneSet& right) {
|
||||
LaneSet result;
|
||||
std::set_intersection(left.begin(), left.end(), right.begin(), right.end(),
|
||||
std::inserter(result, result.end()));
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t NextTemporaryScalarRegister(const Program& program) {
|
||||
uint32_t next = FirstTemporaryScalarRegister;
|
||||
const auto consider = [&next](const Operand& operand) {
|
||||
if (operand.kind == OperandKind::Register && operand.reg.file == RegisterFile::Scalar &&
|
||||
operand.reg.index >= next && operand.reg.index != UINT32_MAX) {
|
||||
next = operand.reg.index + 1u;
|
||||
}
|
||||
};
|
||||
for (const auto& block: program.blocks) {
|
||||
for (const auto& inst: block.instructions) {
|
||||
consider(inst.dst);
|
||||
consider(inst.dst2);
|
||||
for (uint32_t i = 0; i < inst.src_count; i++) {
|
||||
consider(inst.src[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
Operand ScalarRegisterOperand(uint32_t reg) {
|
||||
Operand operand;
|
||||
operand.kind = OperandKind::Register;
|
||||
operand.reg.file = RegisterFile::Scalar;
|
||||
operand.reg.index = reg;
|
||||
return operand;
|
||||
}
|
||||
|
||||
Instruction ShadowWrite(const Instruction& write, uint32_t temporary) {
|
||||
Instruction shadow;
|
||||
shadow.pc = write.pc;
|
||||
shadow.op = Opcode::MoveU32;
|
||||
shadow.dst = ScalarRegisterOperand(temporary);
|
||||
shadow.src[0] = write.src[0];
|
||||
shadow.src_count = 1;
|
||||
return shadow;
|
||||
}
|
||||
|
||||
Instruction ShadowRead(const Instruction& read, uint32_t temporary) {
|
||||
Instruction rewritten;
|
||||
rewritten.pc = read.pc;
|
||||
rewritten.op = Opcode::MoveU32;
|
||||
rewritten.dst = read.dst;
|
||||
rewritten.src[0] = ScalarRegisterOperand(temporary);
|
||||
rewritten.src_count = 1;
|
||||
return rewritten;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ReadLaneEliminationStats EliminateReadLane(Program& program) {
|
||||
ReadLaneEliminationStats stats;
|
||||
if (program.blocks.empty() || (program.wave_size != 32 && program.wave_size != 64)) {
|
||||
return stats;
|
||||
}
|
||||
|
||||
LaneSet universe;
|
||||
for (const auto& block: program.blocks) {
|
||||
for (const auto& inst: block.instructions) {
|
||||
LaneKey key;
|
||||
if (WriteLaneKey(program, inst, key)) {
|
||||
universe.insert(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (universe.empty()) {
|
||||
return stats;
|
||||
}
|
||||
|
||||
const size_t block_count = program.blocks.size();
|
||||
std::vector<LaneSet> entry(block_count, universe);
|
||||
std::vector<LaneSet> exit(block_count, universe);
|
||||
entry[0].clear();
|
||||
for (size_t block = 0; block < block_count; block++) {
|
||||
exit[block] = TransferBlock(program, program.blocks[block], entry[block]);
|
||||
}
|
||||
|
||||
bool changed = true;
|
||||
while (changed) {
|
||||
changed = false;
|
||||
for (size_t block_index = 0; block_index < block_count; block_index++) {
|
||||
LaneSet next_entry;
|
||||
const auto& block = program.blocks[block_index];
|
||||
if (block_index != 0 && !block.predecessors.empty()) {
|
||||
next_entry = universe;
|
||||
for (const auto predecessor: block.predecessors) {
|
||||
if (predecessor >= block_count) {
|
||||
next_entry.clear();
|
||||
break;
|
||||
}
|
||||
next_entry = Intersect(next_entry, exit[predecessor]);
|
||||
}
|
||||
}
|
||||
auto next_exit = TransferBlock(program, block, next_entry);
|
||||
if (next_entry != entry[block_index] || next_exit != exit[block_index]) {
|
||||
entry[block_index] = std::move(next_entry);
|
||||
exit[block_index] = std::move(next_exit);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaneSet forwarded;
|
||||
for (size_t block_index = 0; block_index < block_count; block_index++) {
|
||||
auto state = entry[block_index];
|
||||
for (const auto& inst: program.blocks[block_index].instructions) {
|
||||
LaneKey key;
|
||||
if (ReadLaneKey(program, inst, key) && state.contains(key)) {
|
||||
forwarded.insert(key);
|
||||
}
|
||||
ApplyInstruction(program, inst, state);
|
||||
}
|
||||
}
|
||||
if (forwarded.empty()) {
|
||||
return stats;
|
||||
}
|
||||
|
||||
std::map<LaneKey, uint32_t> temporaries;
|
||||
auto next_temporary = NextTemporaryScalarRegister(program);
|
||||
for (const auto& key: forwarded) {
|
||||
if (next_temporary == UINT32_MAX) {
|
||||
return {};
|
||||
}
|
||||
temporaries.emplace(key, next_temporary++);
|
||||
}
|
||||
|
||||
for (size_t block_index = 0; block_index < block_count; block_index++) {
|
||||
const auto original = std::move(program.blocks[block_index].instructions);
|
||||
auto& rewritten = program.blocks[block_index].instructions;
|
||||
rewritten.clear();
|
||||
rewritten.reserve(original.size() + temporaries.size());
|
||||
auto state = entry[block_index];
|
||||
for (const auto& inst: original) {
|
||||
LaneKey read_key;
|
||||
if (ReadLaneKey(program, inst, read_key) && state.contains(read_key)) {
|
||||
const auto temporary = temporaries.find(read_key);
|
||||
if (temporary != temporaries.end()) {
|
||||
rewritten.push_back(ShadowRead(inst, temporary->second));
|
||||
stats.rewritten_reads++;
|
||||
ApplyInstruction(program, inst, state);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
rewritten.push_back(inst);
|
||||
LaneKey write_key;
|
||||
if (WriteLaneKey(program, inst, write_key)) {
|
||||
const auto temporary = temporaries.find(write_key);
|
||||
if (temporary != temporaries.end()) {
|
||||
rewritten.push_back(ShadowWrite(inst, temporary->second));
|
||||
stats.shadow_writes++;
|
||||
}
|
||||
}
|
||||
ApplyInstruction(program, inst, state);
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
} // namespace Libs::Graphics::ShaderRecompiler::IR
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_SHADER_RECOMPILER_READLANEELIMINATION_H_
|
||||
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_SHADER_RECOMPILER_READLANEELIMINATION_H_
|
||||
|
||||
#include "graphics/shader/recompiler/ir/ShaderIR.h"
|
||||
|
||||
namespace Libs::Graphics::ShaderRecompiler::IR {
|
||||
|
||||
struct ReadLaneEliminationStats {
|
||||
uint32_t rewritten_reads = 0;
|
||||
uint32_t shadow_writes = 0;
|
||||
};
|
||||
|
||||
// Replaces fixed-lane ReadLane operations that are reached by a matching WriteLane on every
|
||||
// control-flow path. A synthetic scalar register snapshots the value at WriteLane execution time,
|
||||
// so the rewrite remains valid when the source SGPR is subsequently overwritten.
|
||||
[[nodiscard]] ReadLaneEliminationStats EliminateReadLane(Program& program);
|
||||
|
||||
} // namespace Libs::Graphics::ShaderRecompiler::IR
|
||||
|
||||
#endif /* EMULATOR_INCLUDE_EMULATOR_GRAPHICS_SHADER_RECOMPILER_READLANEELIMINATION_H_ */
|
||||
@@ -15,7 +15,8 @@ constexpr uint64_t AddressMask = 0x0000ffffffffffffull;
|
||||
Decoder::ImageDimension DescriptorDimension(const DescriptorValue& descriptor,
|
||||
Decoder::ImageDimension requested) {
|
||||
const bool is_array = requested == Decoder::ImageDimension::Dim1DArray ||
|
||||
requested == Decoder::ImageDimension::Dim2DArray;
|
||||
requested == Decoder::ImageDimension::Dim2DArray ||
|
||||
requested == Decoder::ImageDimension::Dim2DMsaaArray;
|
||||
switch (static_cast<Prospero::ImageType>((descriptor.dwords[3] >> 28u) & 0xfu)) {
|
||||
case Prospero::ImageType::kColor1D: return Decoder::ImageDimension::Dim1D;
|
||||
case Prospero::ImageType::kColor1DArray:
|
||||
@@ -26,13 +27,17 @@ Decoder::ImageDimension DescriptorDimension(const DescriptorValue& descriptor,
|
||||
case Prospero::ImageType::kColor3D: return Decoder::ImageDimension::Dim3D;
|
||||
case Prospero::ImageType::kCube: return Decoder::ImageDimension::Dim2DArray;
|
||||
case Prospero::ImageType::kColor2DArray:
|
||||
case Prospero::ImageType::kColor2DMsaaArray:
|
||||
if (is_array) {
|
||||
return Decoder::ImageDimension::Dim2DArray;
|
||||
}
|
||||
return Decoder::ImageDimension::Dim2D;
|
||||
case Prospero::ImageType::kColor2D:
|
||||
case Prospero::ImageType::kColor2DMsaa: return Decoder::ImageDimension::Dim2D;
|
||||
case Prospero::ImageType::kColor2DMsaaArray:
|
||||
if (is_array) {
|
||||
return Decoder::ImageDimension::Dim2DMsaaArray;
|
||||
}
|
||||
return Decoder::ImageDimension::Dim2DMsaa;
|
||||
case Prospero::ImageType::kColor2D: return Decoder::ImageDimension::Dim2D;
|
||||
case Prospero::ImageType::kColor2DMsaa: return Decoder::ImageDimension::Dim2DMsaa;
|
||||
default: return Decoder::ImageDimension::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -679,11 +679,15 @@ enum class DescriptorBindingKind {
|
||||
Sampled1DArray,
|
||||
Sampled2D,
|
||||
Sampled2DArray,
|
||||
Sampled2DMsaa,
|
||||
Sampled2DMsaaArray,
|
||||
Sampled3D,
|
||||
SampledUint1D,
|
||||
SampledUint1DArray,
|
||||
SampledUint2D,
|
||||
SampledUint2DArray,
|
||||
SampledUint2DMsaa,
|
||||
SampledUint2DMsaaArray,
|
||||
SampledUint3D,
|
||||
Storage1D,
|
||||
Storage1DArray,
|
||||
|
||||
@@ -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;
|
||||
|
||||
+250
-34
@@ -1,10 +1,12 @@
|
||||
#include "common/abi.h"
|
||||
#include "libs/errno.h"
|
||||
#include "libs/libs.h"
|
||||
#include "libs/videoDec2Decoder.h"
|
||||
#include "loader/symbolDatabase.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -14,6 +16,7 @@ LIB_VERSION("Videodec2", 1, "Videodec2", 1, 1);
|
||||
|
||||
namespace VideoDec2 {
|
||||
|
||||
constexpr int32_t VIDEODEC2_ERROR_API_FAIL = -2128805632; // 0x811d0100
|
||||
constexpr int32_t VIDEODEC2_ERROR_STRUCT_SIZE = -2128805631; // 0x811d0101
|
||||
constexpr int32_t VIDEODEC2_ERROR_ARGUMENT_POINTER = -2128805630; // 0x811d0102
|
||||
constexpr int32_t VIDEODEC2_ERROR_DECODER_INSTANCE = -2128805629; // 0x811d0103
|
||||
@@ -21,13 +24,20 @@ constexpr int32_t VIDEODEC2_ERROR_MEMORY_SIZE = -2128805628; // 0x811d0
|
||||
constexpr int32_t VIDEODEC2_ERROR_MEMORY_POINTER = -2128805627; // 0x811d0105
|
||||
constexpr int32_t VIDEODEC2_ERROR_FRAME_BUFFER_SIZE = -2128805626; // 0x811d0106
|
||||
constexpr int32_t VIDEODEC2_ERROR_FRAME_BUFFER_POINTER = -2128805625; // 0x811d0107
|
||||
constexpr int32_t VIDEODEC2_ERROR_ACCESS_UNIT_SIZE = -2128805619; // 0x811d010d
|
||||
constexpr int32_t VIDEODEC2_ERROR_ACCESS_UNIT_POINTER = -2128805618; // 0x811d010e
|
||||
constexpr int32_t VIDEODEC2_ERROR_OUTPUT_INFO = -2128805617; // 0x811d010f
|
||||
constexpr int32_t VIDEODEC2_ERROR_COMPUTE_QUEUE = -2128805616; // 0x811d0110
|
||||
constexpr int32_t VIDEODEC2_ERROR_CONFIG_INFO = -2128805376; // 0x811d0200
|
||||
constexpr int32_t VIDEODEC2_ERROR_COMPUTE_PIPE_ID = -2128805375; // 0x811d0201
|
||||
constexpr int32_t VIDEODEC2_ERROR_COMPUTE_QUEUE_ID = -2128805374; // 0x811d0202
|
||||
constexpr int32_t VIDEODEC2_ERROR_RESOURCE_TYPE = -2128805373; // 0x811d0203
|
||||
constexpr int32_t VIDEODEC2_ERROR_CODEC_TYPE = -2128805372; // 0x811d0204
|
||||
constexpr int32_t VIDEODEC2_ERROR_INPUT_QUEUE_DEPTH = -2128805370; // 0x811d0206
|
||||
constexpr int32_t VIDEODEC2_ERROR_DPB_FRAME_COUNT = -2128805367; // 0x811d0209
|
||||
constexpr int32_t VIDEODEC2_ERROR_FRAME_WIDTH_HEIGHT = -2128805366; // 0x811d020a
|
||||
constexpr int32_t VIDEODEC2_ERROR_ACCESS_UNIT = -2128805119; // 0x811d0301
|
||||
constexpr int32_t VIDEODEC2_ERROR_OVERSIZE_DECODE = -2128805118; // 0x811d0302
|
||||
|
||||
constexpr uint32_t VIDEODEC2_RESOURCE_TYPE_COMPUTE = 1;
|
||||
constexpr size_t VIDEODEC2_MIN_MEMORY_SIZE = 16ull * 1024ull * 1024ull;
|
||||
@@ -101,6 +111,70 @@ struct Videodec2FrameBuffer {
|
||||
bool is_accepted;
|
||||
};
|
||||
|
||||
struct Videodec2AvcPictureInfo {
|
||||
size_t this_size;
|
||||
bool is_valid;
|
||||
|
||||
uint64_t pts_data;
|
||||
uint64_t dts_data;
|
||||
uint64_t attached_data;
|
||||
|
||||
uint8_t idr_picture_flag;
|
||||
uint8_t profile_idc;
|
||||
uint8_t level_idc;
|
||||
uint32_t pic_width_in_mbs_minus1;
|
||||
uint32_t pic_height_in_map_units_minus1;
|
||||
uint8_t frame_mbs_only_flag;
|
||||
|
||||
uint8_t frame_cropping_flag;
|
||||
uint32_t frame_crop_left_offset;
|
||||
uint32_t frame_crop_right_offset;
|
||||
uint32_t frame_crop_top_offset;
|
||||
uint32_t frame_crop_bottom_offset;
|
||||
|
||||
uint8_t aspect_ratio_info_present_flag;
|
||||
uint8_t aspect_ratio_idc;
|
||||
uint16_t sar_width;
|
||||
uint16_t sar_height;
|
||||
|
||||
uint8_t video_signal_type_present_flag;
|
||||
uint8_t video_format;
|
||||
uint8_t video_full_range_flag;
|
||||
uint8_t colour_description_present_flag;
|
||||
uint8_t colour_primaries;
|
||||
uint8_t transfer_characteristics;
|
||||
uint8_t matrix_coefficients;
|
||||
|
||||
uint8_t timing_info_present_flag;
|
||||
uint32_t num_units_in_tick;
|
||||
uint32_t time_scale;
|
||||
uint8_t fixed_frame_rate_flag;
|
||||
|
||||
uint8_t bitstream_restriction_flag;
|
||||
uint8_t max_dec_frame_buffering;
|
||||
|
||||
uint8_t pic_struct_present_flag;
|
||||
uint8_t pic_struct;
|
||||
uint8_t field_pic_flag;
|
||||
uint8_t bottom_field_flag;
|
||||
|
||||
uint8_t sequence_parameter_set_present_flag;
|
||||
uint8_t picture_parameter_set_present_flag;
|
||||
uint8_t au_delimiter_present_flag;
|
||||
uint8_t end_of_sequence_present_flag;
|
||||
uint8_t end_of_stream_present_flag;
|
||||
uint8_t filler_data_present_flag;
|
||||
uint8_t picture_timing_sei_present_flag;
|
||||
uint8_t buffering_period_sei_present_flag;
|
||||
|
||||
uint8_t constraint_set0_flag;
|
||||
uint8_t constraint_set1_flag;
|
||||
uint8_t constraint_set2_flag;
|
||||
uint8_t constraint_set3_flag;
|
||||
uint8_t constraint_set4_flag;
|
||||
uint8_t constraint_set5_flag;
|
||||
};
|
||||
|
||||
struct Videodec2ComputeMemoryInfo {
|
||||
size_t this_size;
|
||||
size_t cpu_gpu_memory_size;
|
||||
@@ -116,10 +190,7 @@ struct Videodec2ComputeConfigInfo {
|
||||
uint16_t reserved1;
|
||||
};
|
||||
|
||||
struct DecoderState {
|
||||
uint64_t magic;
|
||||
uint32_t codec_type;
|
||||
};
|
||||
using DecoderState = Decoder::Instance;
|
||||
|
||||
static_assert(sizeof(Videodec2ComputeMemoryInfo) == 24);
|
||||
static_assert(sizeof(Videodec2ComputeConfigInfo) == 16);
|
||||
@@ -128,8 +199,7 @@ static_assert(sizeof(Videodec2DecoderMemoryInfo) == 72);
|
||||
static_assert(sizeof(Videodec2InputData) == 48);
|
||||
static_assert(sizeof(Videodec2OutputInfo) == 56);
|
||||
static_assert(sizeof(Videodec2FrameBuffer) == 32);
|
||||
|
||||
constexpr uint64_t DECODER_MAGIC = 0x4b59545956444543ull; // KYTYVDEC
|
||||
static_assert(sizeof(Videodec2AvcPictureInfo) == 120);
|
||||
|
||||
static std::mutex g_decoder_mutex;
|
||||
static std::unordered_set<void*> g_decoders;
|
||||
@@ -156,15 +226,54 @@ static void FillNoPictureOutput(const Videodec2FrameBuffer* frame_buffer,
|
||||
output_info->frame_height = 0;
|
||||
output_info->frame_buffer = frame_buffer != nullptr ? frame_buffer->frame_buffer : nullptr;
|
||||
output_info->frame_buffer_size = frame_buffer != nullptr ? frame_buffer->frame_buffer_size : 0;
|
||||
if (output_info->this_size == sizeof(Videodec2OutputInfo)) {
|
||||
output_info->frame_format = VIDEODEC2_FRAME_FORMAT_DEFAULT;
|
||||
output_info->frame_pitch_in_bytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t ValidateDecoderConfig(const Videodec2DecoderConfigInfo* config) {
|
||||
static int32_t MapDecoderResult(Decoder::Result result) {
|
||||
switch (result) {
|
||||
case Decoder::Result::Ok: return OK;
|
||||
case Decoder::Result::ApiFail: return VIDEODEC2_ERROR_API_FAIL;
|
||||
case Decoder::Result::AccessUnit: return VIDEODEC2_ERROR_ACCESS_UNIT;
|
||||
case Decoder::Result::FrameBufferSize: return VIDEODEC2_ERROR_FRAME_BUFFER_SIZE;
|
||||
case Decoder::Result::OversizeDecode: return VIDEODEC2_ERROR_OVERSIZE_DECODE;
|
||||
}
|
||||
return VIDEODEC2_ERROR_API_FAIL;
|
||||
}
|
||||
|
||||
static void ApplyDecodedOutput(const Decoder::Output& decoded, Videodec2FrameBuffer* frame_buffer,
|
||||
Videodec2OutputInfo* output_info) {
|
||||
frame_buffer->is_accepted = decoded.buffer_accepted;
|
||||
if (!decoded.valid) {
|
||||
return;
|
||||
}
|
||||
output_info->is_valid = true;
|
||||
output_info->is_error_frame = decoded.error_frame;
|
||||
output_info->picture_count = 1;
|
||||
output_info->codec_type = decoded.codec_type;
|
||||
output_info->frame_width = decoded.width;
|
||||
output_info->frame_pitch = decoded.pitch;
|
||||
output_info->frame_height = decoded.height;
|
||||
output_info->frame_buffer = decoded.buffer;
|
||||
output_info->frame_buffer_size = decoded.buffer_size;
|
||||
if (output_info->this_size == sizeof(Videodec2OutputInfo)) {
|
||||
output_info->frame_format = VIDEODEC2_FRAME_FORMAT_DEFAULT;
|
||||
output_info->frame_pitch_in_bytes = decoded.pitch;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t ValidateDecoderConfig(const Videodec2DecoderConfigInfo* config,
|
||||
bool require_compute_queue) {
|
||||
if (config->resource_type != VIDEODEC2_RESOURCE_TYPE_COMPUTE) {
|
||||
return VIDEODEC2_ERROR_RESOURCE_TYPE;
|
||||
}
|
||||
|
||||
if (!Decoder::IsCodecSupported(config->codec_type)) {
|
||||
return VIDEODEC2_ERROR_CODEC_TYPE;
|
||||
}
|
||||
|
||||
if (config->reserved0 != 0 || config->reserved1 != 0) {
|
||||
return VIDEODEC2_ERROR_CONFIG_INFO;
|
||||
}
|
||||
@@ -182,8 +291,8 @@ static int32_t ValidateDecoderConfig(const Videodec2DecoderConfigInfo* config) {
|
||||
return VIDEODEC2_ERROR_FRAME_WIDTH_HEIGHT;
|
||||
}
|
||||
|
||||
if (config->compute_queue == nullptr) {
|
||||
return VIDEODEC2_ERROR_CONFIG_INFO;
|
||||
if (require_compute_queue && config->compute_queue == nullptr) {
|
||||
return VIDEODEC2_ERROR_COMPUTE_QUEUE;
|
||||
}
|
||||
|
||||
return OK;
|
||||
@@ -243,7 +352,6 @@ static int32_t KYTY_SYSV_ABI AllocateComputeQueue(
|
||||
}
|
||||
|
||||
*compute_queue = compute_memory_info->cpu_gpu_memory;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -266,7 +374,7 @@ static int32_t KYTY_SYSV_ABI QueryDecoderMemoryInfo(const Videodec2DecoderConfig
|
||||
return VIDEODEC2_ERROR_STRUCT_SIZE;
|
||||
}
|
||||
|
||||
const auto validation_result = ValidateDecoderConfig(config);
|
||||
const auto validation_result = ValidateDecoderConfig(config, false);
|
||||
if (validation_result != OK) {
|
||||
return validation_result;
|
||||
}
|
||||
@@ -298,7 +406,7 @@ static int32_t KYTY_SYSV_ABI CreateDecoder(const Videodec2DecoderConfigInfo* con
|
||||
return VIDEODEC2_ERROR_STRUCT_SIZE;
|
||||
}
|
||||
|
||||
const auto validation_result = ValidateDecoderConfig(config);
|
||||
const auto validation_result = ValidateDecoderConfig(config, true);
|
||||
if (validation_result != OK) {
|
||||
return validation_result;
|
||||
}
|
||||
@@ -315,9 +423,11 @@ static int32_t KYTY_SYSV_ABI CreateDecoder(const Videodec2DecoderConfigInfo* con
|
||||
return VIDEODEC2_ERROR_MEMORY_POINTER;
|
||||
}
|
||||
|
||||
auto* state = new DecoderState {};
|
||||
state->magic = DECODER_MAGIC;
|
||||
state->codec_type = config->codec_type;
|
||||
auto* state =
|
||||
Decoder::Create({config->codec_type, config->max_frame_width, config->max_frame_height});
|
||||
if (state == nullptr) {
|
||||
return VIDEODEC2_ERROR_API_FAIL;
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock lock(g_decoder_mutex);
|
||||
@@ -325,7 +435,6 @@ static int32_t KYTY_SYSV_ABI CreateDecoder(const Videodec2DecoderConfigInfo* con
|
||||
}
|
||||
|
||||
*decoder = state;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -343,7 +452,7 @@ static int32_t KYTY_SYSV_ABI DeleteDecoder(Videodec2Decoder decoder) {
|
||||
g_decoders.erase(it);
|
||||
}
|
||||
|
||||
delete state;
|
||||
Decoder::Destroy(state);
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -353,8 +462,8 @@ static int32_t KYTY_SYSV_ABI Decode(Videodec2Decoder decoder, const Videodec2Inp
|
||||
Videodec2OutputInfo* output_info) {
|
||||
PRINT_NAME();
|
||||
|
||||
const auto* state = GetDecoder(decoder);
|
||||
if (state == nullptr || state->magic != DECODER_MAGIC) {
|
||||
auto* state = GetDecoder(decoder);
|
||||
if (state == nullptr) {
|
||||
return VIDEODEC2_ERROR_DECODER_INSTANCE;
|
||||
}
|
||||
|
||||
@@ -368,8 +477,12 @@ static int32_t KYTY_SYSV_ABI Decode(Videodec2Decoder decoder, const Videodec2Inp
|
||||
return VIDEODEC2_ERROR_STRUCT_SIZE;
|
||||
}
|
||||
|
||||
if (input_data->au_size != 0 && input_data->au_data == nullptr) {
|
||||
return VIDEODEC2_ERROR_ARGUMENT_POINTER;
|
||||
if (input_data->au_size == 0) {
|
||||
return VIDEODEC2_ERROR_ACCESS_UNIT_SIZE;
|
||||
}
|
||||
|
||||
if (input_data->au_data == nullptr) {
|
||||
return VIDEODEC2_ERROR_ACCESS_UNIT_POINTER;
|
||||
}
|
||||
|
||||
if (frame_buffer->frame_buffer_size == 0) {
|
||||
@@ -381,17 +494,24 @@ static int32_t KYTY_SYSV_ABI Decode(Videodec2Decoder decoder, const Videodec2Inp
|
||||
}
|
||||
|
||||
frame_buffer->is_accepted = false;
|
||||
FillNoPictureOutput(frame_buffer, output_info, state->codec_type);
|
||||
FillNoPictureOutput(frame_buffer, output_info, Decoder::GetCodecType(state));
|
||||
|
||||
return OK;
|
||||
Decoder::Output decoded {};
|
||||
const auto result =
|
||||
Decoder::Decode(state,
|
||||
{input_data->au_data, input_data->au_size, input_data->pts_data,
|
||||
input_data->dts_data, input_data->attached_data},
|
||||
{frame_buffer->frame_buffer, frame_buffer->frame_buffer_size}, &decoded);
|
||||
ApplyDecodedOutput(decoded, frame_buffer, output_info);
|
||||
return MapDecoderResult(result);
|
||||
}
|
||||
|
||||
static int32_t KYTY_SYSV_ABI Flush(Videodec2Decoder decoder, Videodec2FrameBuffer* frame_buffer,
|
||||
Videodec2OutputInfo* output_info) {
|
||||
PRINT_NAME();
|
||||
|
||||
const auto* state = GetDecoder(decoder);
|
||||
if (state == nullptr || state->magic != DECODER_MAGIC) {
|
||||
auto* state = GetDecoder(decoder);
|
||||
if (state == nullptr) {
|
||||
return VIDEODEC2_ERROR_DECODER_INSTANCE;
|
||||
}
|
||||
|
||||
@@ -404,26 +524,40 @@ static int32_t KYTY_SYSV_ABI Flush(Videodec2Decoder decoder, Videodec2FrameBuffe
|
||||
return VIDEODEC2_ERROR_STRUCT_SIZE;
|
||||
}
|
||||
|
||||
frame_buffer->is_accepted = false;
|
||||
FillNoPictureOutput(frame_buffer, output_info, state->codec_type);
|
||||
if (frame_buffer->frame_buffer_size == 0) {
|
||||
return VIDEODEC2_ERROR_FRAME_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
return OK;
|
||||
if (frame_buffer->frame_buffer == nullptr) {
|
||||
return VIDEODEC2_ERROR_FRAME_BUFFER_POINTER;
|
||||
}
|
||||
|
||||
frame_buffer->is_accepted = false;
|
||||
FillNoPictureOutput(frame_buffer, output_info, Decoder::GetCodecType(state));
|
||||
|
||||
Decoder::Output decoded {};
|
||||
const auto result = Decoder::Flush(
|
||||
state, {frame_buffer->frame_buffer, frame_buffer->frame_buffer_size}, &decoded);
|
||||
ApplyDecodedOutput(decoded, frame_buffer, output_info);
|
||||
return MapDecoderResult(result);
|
||||
}
|
||||
|
||||
static int32_t KYTY_SYSV_ABI Reset(Videodec2Decoder decoder) {
|
||||
PRINT_NAME();
|
||||
|
||||
const auto* state = GetDecoder(decoder);
|
||||
return state != nullptr && state->magic == DECODER_MAGIC ? OK
|
||||
: VIDEODEC2_ERROR_DECODER_INSTANCE;
|
||||
auto* state = GetDecoder(decoder);
|
||||
if (state == nullptr) {
|
||||
return VIDEODEC2_ERROR_DECODER_INSTANCE;
|
||||
}
|
||||
Decoder::Reset(state);
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int32_t KYTY_SYSV_ABI GetPictureInfo(const Videodec2OutputInfo* output_info,
|
||||
void* /*first_picture_info*/,
|
||||
void* /*second_picture_info*/) {
|
||||
void* first_picture_info, void* second_picture_info) {
|
||||
PRINT_NAME();
|
||||
|
||||
if (output_info == nullptr) {
|
||||
if (output_info == nullptr || first_picture_info == nullptr) {
|
||||
return VIDEODEC2_ERROR_ARGUMENT_POINTER;
|
||||
}
|
||||
|
||||
@@ -431,6 +565,88 @@ static int32_t KYTY_SYSV_ABI GetPictureInfo(const Videodec2OutputInfo* output_in
|
||||
return VIDEODEC2_ERROR_STRUCT_SIZE;
|
||||
}
|
||||
|
||||
if (!output_info->is_valid || output_info->picture_count == 0 ||
|
||||
output_info->frame_buffer == nullptr) {
|
||||
return VIDEODEC2_ERROR_OUTPUT_INFO;
|
||||
}
|
||||
|
||||
Decoder::PictureInfo decoded {};
|
||||
if (!Decoder::GetPictureInfo(output_info->frame_buffer, &decoded) ||
|
||||
decoded.codec_type != output_info->codec_type) {
|
||||
return VIDEODEC2_ERROR_OUTPUT_INFO;
|
||||
}
|
||||
|
||||
auto fill_common = [&decoded](void* destination, bool valid) -> int32_t {
|
||||
auto* bytes = static_cast<uint8_t*>(destination);
|
||||
const auto size = *static_cast<const size_t*>(destination);
|
||||
if (size < 40 || size > 256) {
|
||||
return VIDEODEC2_ERROR_STRUCT_SIZE;
|
||||
}
|
||||
std::memset(bytes + sizeof(size_t), 0, size - sizeof(size_t));
|
||||
bytes[8] = valid ? 1 : 0;
|
||||
if (valid) {
|
||||
std::memcpy(bytes + 16, &decoded.pts, sizeof(decoded.pts));
|
||||
std::memcpy(bytes + 24, &decoded.dts, sizeof(decoded.dts));
|
||||
std::memcpy(bytes + 32, &decoded.attached_data, sizeof(decoded.attached_data));
|
||||
}
|
||||
return OK;
|
||||
};
|
||||
|
||||
if (output_info->codec_type == 1) {
|
||||
const auto requested_size = *static_cast<const size_t*>(first_picture_info);
|
||||
if (requested_size != sizeof(Videodec2AvcPictureInfo) &&
|
||||
(requested_size | 16u) != sizeof(Videodec2AvcPictureInfo)) {
|
||||
return VIDEODEC2_ERROR_STRUCT_SIZE;
|
||||
}
|
||||
|
||||
Videodec2AvcPictureInfo picture {};
|
||||
picture.this_size = requested_size;
|
||||
picture.is_valid = true;
|
||||
picture.pts_data = decoded.pts;
|
||||
picture.dts_data = decoded.dts;
|
||||
picture.attached_data = decoded.attached_data;
|
||||
picture.idr_picture_flag = decoded.key_frame ? 1 : 0;
|
||||
picture.profile_idc = static_cast<uint8_t>(decoded.profile);
|
||||
picture.level_idc = static_cast<uint8_t>(decoded.level);
|
||||
picture.pic_width_in_mbs_minus1 = (decoded.width + 15u) / 16u - 1u;
|
||||
picture.pic_height_in_map_units_minus1 = (decoded.height + 15u) / 16u - 1u;
|
||||
picture.frame_mbs_only_flag = 1;
|
||||
picture.frame_cropping_flag = decoded.crop_left != 0 || decoded.crop_right != 0 ||
|
||||
decoded.crop_top != 0 || decoded.crop_bottom != 0
|
||||
? 1
|
||||
: 0;
|
||||
picture.frame_crop_left_offset = decoded.crop_left;
|
||||
picture.frame_crop_right_offset = decoded.crop_right;
|
||||
picture.frame_crop_top_offset = decoded.crop_top;
|
||||
picture.frame_crop_bottom_offset = decoded.crop_bottom;
|
||||
picture.aspect_ratio_info_present_flag =
|
||||
decoded.sar_width != 0 && decoded.sar_height != 0 ? 1 : 0;
|
||||
picture.aspect_ratio_idc = picture.aspect_ratio_info_present_flag ? 255 : 0;
|
||||
picture.sar_width = decoded.sar_width;
|
||||
picture.sar_height = decoded.sar_height;
|
||||
picture.video_signal_type_present_flag = 1;
|
||||
picture.video_format = 5;
|
||||
picture.video_full_range_flag = decoded.color_range == 2 ? 1 : 0;
|
||||
picture.colour_description_present_flag =
|
||||
decoded.color_primaries != 0 || decoded.color_trc != 0 || decoded.color_space != 0 ? 1
|
||||
: 0;
|
||||
picture.colour_primaries = decoded.color_primaries;
|
||||
picture.transfer_characteristics = decoded.color_trc;
|
||||
picture.matrix_coefficients = decoded.color_space;
|
||||
std::memcpy(first_picture_info, &picture, requested_size);
|
||||
} else {
|
||||
const auto result = fill_common(first_picture_info, true);
|
||||
if (result != OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (second_picture_info != nullptr) {
|
||||
const auto result = fill_common(second_picture_info, false);
|
||||
if (result != OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,412 @@
|
||||
#include "libs/videoDec2Decoder.h"
|
||||
|
||||
#include "common/logging/log.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavutil/buffer.h>
|
||||
#include <libavutil/error.h>
|
||||
#include <libavutil/frame.h>
|
||||
#include <libavutil/pixfmt.h>
|
||||
#include <libswscale/swscale.h>
|
||||
}
|
||||
|
||||
namespace Libs::VideoDec2::Decoder {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint32_t CODEC_TYPE_AVC = 1;
|
||||
constexpr uint32_t CODEC_TYPE_HEVC = 974921;
|
||||
constexpr uint32_t CODEC_TYPE_VP9 = 2382845;
|
||||
|
||||
struct PacketMetadata {
|
||||
uint64_t pts = TIMESTAMP_INVALID;
|
||||
uint64_t dts = TIMESTAMP_INVALID;
|
||||
uint64_t attached_data = 0;
|
||||
};
|
||||
|
||||
struct StoredPicture {
|
||||
const Instance* owner = nullptr;
|
||||
PictureInfo info;
|
||||
};
|
||||
|
||||
std::mutex g_picture_mutex;
|
||||
std::unordered_map<void*, StoredPicture> g_picture_infos;
|
||||
|
||||
AVCodecID GetAvCodecId(uint32_t codec_type) {
|
||||
switch (codec_type) {
|
||||
case CODEC_TYPE_AVC: return AV_CODEC_ID_H264;
|
||||
case CODEC_TYPE_HEVC: return AV_CODEC_ID_HEVC;
|
||||
case CODEC_TYPE_VP9: return AV_CODEC_ID_VP9;
|
||||
default: return AV_CODEC_ID_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
const char* AvErrorString(int error) {
|
||||
thread_local char text[AV_ERROR_MAX_STRING_SIZE] {};
|
||||
if (av_strerror(error, text, sizeof(text)) != 0) {
|
||||
std::strcpy(text, "unknown FFmpeg error");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
uint32_t AlignUp(uint32_t value, uint32_t alignment) {
|
||||
return (value + alignment - 1u) & ~(alignment - 1u);
|
||||
}
|
||||
|
||||
int64_t ToAvTimestamp(uint64_t timestamp) {
|
||||
return timestamp == TIMESTAMP_INVALID ||
|
||||
timestamp > static_cast<uint64_t>(std::numeric_limits<int64_t>::max())
|
||||
? AV_NOPTS_VALUE
|
||||
: static_cast<int64_t>(timestamp);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class Instance {
|
||||
public:
|
||||
explicit Instance(const Config& config): m_config(config) {}
|
||||
|
||||
~Instance() {
|
||||
ClearPictureMetadata();
|
||||
if (m_sws != nullptr) {
|
||||
sws_freeContext(m_sws);
|
||||
}
|
||||
if (m_codec != nullptr) {
|
||||
avcodec_free_context(&m_codec);
|
||||
}
|
||||
}
|
||||
|
||||
Instance(const Instance&) = delete;
|
||||
Instance& operator=(const Instance&) = delete;
|
||||
|
||||
[[nodiscard]] bool Initialize() {
|
||||
const AVCodec* decoder = avcodec_find_decoder(GetAvCodecId(m_config.codec_type));
|
||||
if (decoder == nullptr) {
|
||||
LOGF("Videodec2: FFmpeg decoder is unavailable for codec type %u\n",
|
||||
m_config.codec_type);
|
||||
return false;
|
||||
}
|
||||
m_codec = avcodec_alloc_context3(decoder);
|
||||
if (m_codec == nullptr) {
|
||||
LOGF("Videodec2: avcodec_alloc_context3 failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// This carries PTS/DTS/attachedData through codecs that reorder B frames.
|
||||
m_codec->flags |= AV_CODEC_FLAG_COPY_OPAQUE;
|
||||
const int result = avcodec_open2(m_codec, decoder, nullptr);
|
||||
if (result < 0) {
|
||||
LOGF("Videodec2: avcodec_open2 failed: %s (%d)\n", AvErrorString(result), result);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] uint32_t CodecType() const { return m_config.codec_type; }
|
||||
|
||||
[[nodiscard]] Result DecodeInput(const Input& input, const FrameBuffer& frame_buffer,
|
||||
Output* output) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
*output = {};
|
||||
m_draining = false;
|
||||
|
||||
AVPacket* packet = av_packet_alloc();
|
||||
AVFrame* frame = av_frame_alloc();
|
||||
if (packet == nullptr || frame == nullptr ||
|
||||
input.size > static_cast<size_t>(std::numeric_limits<int>::max())) {
|
||||
av_packet_free(&packet);
|
||||
av_frame_free(&frame);
|
||||
return Result::ApiFail;
|
||||
}
|
||||
|
||||
int result = av_new_packet(packet, static_cast<int>(input.size));
|
||||
if (result < 0) {
|
||||
LOGF("Videodec2: av_new_packet failed: %s (%d)\n", AvErrorString(result), result);
|
||||
av_packet_free(&packet);
|
||||
av_frame_free(&frame);
|
||||
return Result::ApiFail;
|
||||
}
|
||||
std::memcpy(packet->data, input.data, input.size);
|
||||
packet->pts = ToAvTimestamp(input.pts);
|
||||
packet->dts = ToAvTimestamp(input.dts);
|
||||
|
||||
packet->opaque_ref = av_buffer_alloc(sizeof(PacketMetadata));
|
||||
if (packet->opaque_ref == nullptr) {
|
||||
av_packet_free(&packet);
|
||||
av_frame_free(&frame);
|
||||
return Result::ApiFail;
|
||||
}
|
||||
const PacketMetadata metadata {input.pts, input.dts, input.attached_data};
|
||||
std::memcpy(packet->opaque_ref->data, &metadata, sizeof(metadata));
|
||||
|
||||
bool have_pending_frame = false;
|
||||
result = avcodec_send_packet(m_codec, packet);
|
||||
if (result == AVERROR(EAGAIN)) {
|
||||
result = avcodec_receive_frame(m_codec, frame);
|
||||
if (result < 0) {
|
||||
LOGF("Videodec2: decoder rejected an AU while no output was available: %s (%d)\n",
|
||||
AvErrorString(result), result);
|
||||
av_packet_free(&packet);
|
||||
av_frame_free(&frame);
|
||||
return Result::AccessUnit;
|
||||
}
|
||||
have_pending_frame = true;
|
||||
result = avcodec_send_packet(m_codec, packet);
|
||||
}
|
||||
if (result < 0) {
|
||||
LOGF("Videodec2: avcodec_send_packet failed: %s (%d)\n", AvErrorString(result), result);
|
||||
av_packet_free(&packet);
|
||||
av_frame_free(&frame);
|
||||
return Result::AccessUnit;
|
||||
}
|
||||
|
||||
Result decode_result = Result::Ok;
|
||||
if (!have_pending_frame) {
|
||||
result = avcodec_receive_frame(m_codec, frame);
|
||||
if (result != AVERROR(EAGAIN) && result != AVERROR_EOF) {
|
||||
if (result < 0) {
|
||||
LOGF("Videodec2: avcodec_receive_frame failed: %s (%d)\n",
|
||||
AvErrorString(result), result);
|
||||
decode_result = Result::AccessUnit;
|
||||
} else {
|
||||
decode_result = CopyFrame(frame, frame_buffer, output);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
decode_result = CopyFrame(frame, frame_buffer, output);
|
||||
}
|
||||
|
||||
av_packet_free(&packet);
|
||||
av_frame_free(&frame);
|
||||
return decode_result;
|
||||
}
|
||||
|
||||
[[nodiscard]] Result FlushOutput(const FrameBuffer& frame_buffer, Output* output) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
*output = {};
|
||||
|
||||
AVFrame* frame = av_frame_alloc();
|
||||
if (frame == nullptr) {
|
||||
return Result::ApiFail;
|
||||
}
|
||||
|
||||
if (!m_draining) {
|
||||
const int send_result = avcodec_send_packet(m_codec, nullptr);
|
||||
if (send_result == 0 || send_result == AVERROR_EOF) {
|
||||
m_draining = true;
|
||||
} else if (send_result != AVERROR(EAGAIN)) {
|
||||
LOGF("Videodec2: flushing decoder failed: %s (%d)\n", AvErrorString(send_result),
|
||||
send_result);
|
||||
av_frame_free(&frame);
|
||||
return Result::ApiFail;
|
||||
}
|
||||
}
|
||||
|
||||
const int receive_result = avcodec_receive_frame(m_codec, frame);
|
||||
if (receive_result == AVERROR(EAGAIN) || receive_result == AVERROR_EOF) {
|
||||
av_frame_free(&frame);
|
||||
return Result::Ok;
|
||||
}
|
||||
if (receive_result < 0) {
|
||||
LOGF("Videodec2: receiving a flushed frame failed: %s (%d)\n",
|
||||
AvErrorString(receive_result), receive_result);
|
||||
av_frame_free(&frame);
|
||||
return Result::ApiFail;
|
||||
}
|
||||
|
||||
const auto result = CopyFrame(frame, frame_buffer, output);
|
||||
av_frame_free(&frame);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ResetDecoder() {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
avcodec_flush_buffers(m_codec);
|
||||
m_draining = false;
|
||||
ClearPictureMetadata();
|
||||
}
|
||||
|
||||
private:
|
||||
[[nodiscard]] PictureInfo MakePictureInfo(const AVFrame* frame) const {
|
||||
PictureInfo result {};
|
||||
if (frame->opaque_ref != nullptr && frame->opaque_ref->size >= sizeof(PacketMetadata)) {
|
||||
PacketMetadata metadata {};
|
||||
std::memcpy(&metadata, frame->opaque_ref->data, sizeof(metadata));
|
||||
result.pts = metadata.pts;
|
||||
result.dts = metadata.dts;
|
||||
result.attached_data = metadata.attached_data;
|
||||
} else {
|
||||
result.pts = frame->pts == AV_NOPTS_VALUE ? TIMESTAMP_INVALID
|
||||
: static_cast<uint64_t>(frame->pts);
|
||||
result.dts = frame->pkt_dts == AV_NOPTS_VALUE ? TIMESTAMP_INVALID
|
||||
: static_cast<uint64_t>(frame->pkt_dts);
|
||||
}
|
||||
result.codec_type = m_config.codec_type;
|
||||
result.width = static_cast<uint32_t>(frame->width);
|
||||
result.height = static_cast<uint32_t>(frame->height);
|
||||
result.crop_left = static_cast<uint32_t>(frame->crop_left);
|
||||
result.crop_right = static_cast<uint32_t>(frame->crop_right);
|
||||
result.crop_top = static_cast<uint32_t>(frame->crop_top);
|
||||
result.crop_bottom = static_cast<uint32_t>(frame->crop_bottom);
|
||||
result.profile = m_codec->profile > 0 ? static_cast<uint32_t>(m_codec->profile) : 0;
|
||||
result.level = m_codec->level > 0 ? static_cast<uint32_t>(m_codec->level) : 0;
|
||||
result.sar_width =
|
||||
frame->sample_aspect_ratio.num > 0
|
||||
? static_cast<uint16_t>(std::min(frame->sample_aspect_ratio.num, 65535))
|
||||
: 0;
|
||||
result.sar_height =
|
||||
frame->sample_aspect_ratio.den > 0
|
||||
? static_cast<uint16_t>(std::min(frame->sample_aspect_ratio.den, 65535))
|
||||
: 0;
|
||||
result.color_range = static_cast<uint8_t>(frame->color_range);
|
||||
result.color_primaries = static_cast<uint8_t>(frame->color_primaries);
|
||||
result.color_trc = static_cast<uint8_t>(frame->color_trc);
|
||||
result.color_space = static_cast<uint8_t>(frame->colorspace);
|
||||
result.key_frame = (frame->flags & AV_FRAME_FLAG_KEY) != 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] Result CopyFrame(const AVFrame* frame, const FrameBuffer& frame_buffer,
|
||||
Output* output) {
|
||||
if (frame->width <= 0 || frame->height <= 0) {
|
||||
return Result::ApiFail;
|
||||
}
|
||||
if ((m_config.max_width > 0 && frame->width > m_config.max_width) ||
|
||||
(m_config.max_height > 0 && frame->height > m_config.max_height)) {
|
||||
return Result::OversizeDecode;
|
||||
}
|
||||
|
||||
const auto width = static_cast<uint32_t>(frame->width);
|
||||
const auto height = static_cast<uint32_t>(frame->height);
|
||||
const auto pitch = AlignUp(width, 256);
|
||||
const auto chroma_rows = (static_cast<uint64_t>(height) + 1u) / 2u;
|
||||
const auto required =
|
||||
static_cast<uint64_t>(pitch) * height + static_cast<uint64_t>(pitch) * chroma_rows;
|
||||
if (required > frame_buffer.size) {
|
||||
return Result::FrameBufferSize;
|
||||
}
|
||||
|
||||
auto* dst = static_cast<uint8_t*>(frame_buffer.data);
|
||||
std::memset(dst, 0, static_cast<size_t>(required));
|
||||
if (frame->format == AV_PIX_FMT_NV12) {
|
||||
for (uint32_t y = 0; y < height; y++) {
|
||||
std::memcpy(dst + static_cast<size_t>(y) * pitch,
|
||||
frame->data[0] + static_cast<ptrdiff_t>(y) * frame->linesize[0], width);
|
||||
}
|
||||
auto* chroma = dst + static_cast<size_t>(pitch) * height;
|
||||
for (uint32_t y = 0; y < chroma_rows; y++) {
|
||||
std::memcpy(chroma + static_cast<size_t>(y) * pitch,
|
||||
frame->data[1] + static_cast<ptrdiff_t>(y) * frame->linesize[1], width);
|
||||
}
|
||||
} else {
|
||||
m_sws = sws_getCachedContext(m_sws, frame->width, frame->height,
|
||||
static_cast<AVPixelFormat>(frame->format), frame->width,
|
||||
frame->height, AV_PIX_FMT_NV12, SWS_FAST_BILINEAR, nullptr,
|
||||
nullptr, nullptr);
|
||||
if (m_sws == nullptr) {
|
||||
return Result::ApiFail;
|
||||
}
|
||||
uint8_t* output_planes[4] = {dst, dst + static_cast<size_t>(pitch) * height, nullptr,
|
||||
nullptr};
|
||||
int output_strides[4] = {static_cast<int>(pitch), static_cast<int>(pitch), 0, 0};
|
||||
if (sws_scale(m_sws, frame->data, frame->linesize, 0, frame->height, output_planes,
|
||||
output_strides) != frame->height) {
|
||||
return Result::ApiFail;
|
||||
}
|
||||
}
|
||||
|
||||
output->valid = true;
|
||||
output->error_frame = (frame->flags & AV_FRAME_FLAG_CORRUPT) != 0;
|
||||
output->buffer_accepted = true;
|
||||
output->codec_type = m_config.codec_type;
|
||||
output->width = width;
|
||||
output->pitch = pitch;
|
||||
output->height = height;
|
||||
output->buffer = frame_buffer.data;
|
||||
output->buffer_size = frame_buffer.size;
|
||||
|
||||
{
|
||||
std::scoped_lock lock(g_picture_mutex);
|
||||
g_picture_infos[frame_buffer.data] = {this, MakePictureInfo(frame)};
|
||||
m_picture_buffers.insert(frame_buffer.data);
|
||||
}
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
void ClearPictureMetadata() {
|
||||
std::scoped_lock lock(g_picture_mutex);
|
||||
for (auto* buffer: m_picture_buffers) {
|
||||
const auto it = g_picture_infos.find(buffer);
|
||||
if (it != g_picture_infos.end() && it->second.owner == this) {
|
||||
g_picture_infos.erase(it);
|
||||
}
|
||||
}
|
||||
m_picture_buffers.clear();
|
||||
}
|
||||
|
||||
Config m_config;
|
||||
AVCodecContext* m_codec = nullptr;
|
||||
SwsContext* m_sws = nullptr;
|
||||
bool m_draining = false;
|
||||
std::mutex m_mutex;
|
||||
std::unordered_set<void*> m_picture_buffers;
|
||||
};
|
||||
|
||||
bool IsCodecSupported(uint32_t codec_type) {
|
||||
return GetAvCodecId(codec_type) != AV_CODEC_ID_NONE;
|
||||
}
|
||||
|
||||
Instance* Create(const Config& config) {
|
||||
if (!IsCodecSupported(config.codec_type)) {
|
||||
return nullptr;
|
||||
}
|
||||
auto* instance = new Instance(config);
|
||||
if (!instance->Initialize()) {
|
||||
delete instance;
|
||||
return nullptr;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Destroy(Instance* instance) {
|
||||
delete instance;
|
||||
}
|
||||
|
||||
uint32_t GetCodecType(const Instance* instance) {
|
||||
return instance->CodecType();
|
||||
}
|
||||
|
||||
Result Decode(Instance* instance, const Input& input, const FrameBuffer& frame_buffer,
|
||||
Output* output) {
|
||||
return instance->DecodeInput(input, frame_buffer, output);
|
||||
}
|
||||
|
||||
Result Flush(Instance* instance, const FrameBuffer& frame_buffer, Output* output) {
|
||||
return instance->FlushOutput(frame_buffer, output);
|
||||
}
|
||||
|
||||
void Reset(Instance* instance) {
|
||||
instance->ResetDecoder();
|
||||
}
|
||||
|
||||
bool GetPictureInfo(void* frame_buffer, PictureInfo* picture_info) {
|
||||
std::scoped_lock lock(g_picture_mutex);
|
||||
const auto it = g_picture_infos.find(frame_buffer);
|
||||
if (it == g_picture_infos.end()) {
|
||||
return false;
|
||||
}
|
||||
*picture_info = it->second.info;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Libs::VideoDec2::Decoder
|
||||
@@ -0,0 +1,86 @@
|
||||
#ifndef EMULATOR_INCLUDE_EMULATOR_LIBS_VIDEODEC2DECODER_H_
|
||||
#define EMULATOR_INCLUDE_EMULATOR_LIBS_VIDEODEC2DECODER_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Libs::VideoDec2::Decoder {
|
||||
|
||||
constexpr uint64_t TIMESTAMP_INVALID = UINT64_MAX;
|
||||
|
||||
enum class Result {
|
||||
Ok,
|
||||
ApiFail,
|
||||
AccessUnit,
|
||||
FrameBufferSize,
|
||||
OversizeDecode,
|
||||
};
|
||||
|
||||
struct Config {
|
||||
uint32_t codec_type = 0;
|
||||
int32_t max_width = -1;
|
||||
int32_t max_height = -1;
|
||||
};
|
||||
|
||||
struct Input {
|
||||
const void* data = nullptr;
|
||||
size_t size = 0;
|
||||
uint64_t pts = TIMESTAMP_INVALID;
|
||||
uint64_t dts = TIMESTAMP_INVALID;
|
||||
uint64_t attached_data = 0;
|
||||
};
|
||||
|
||||
struct FrameBuffer {
|
||||
void* data = nullptr;
|
||||
size_t size = 0;
|
||||
};
|
||||
|
||||
struct Output {
|
||||
bool valid = false;
|
||||
bool error_frame = false;
|
||||
bool buffer_accepted = false;
|
||||
uint32_t codec_type = 0;
|
||||
uint32_t width = 0;
|
||||
uint32_t pitch = 0;
|
||||
uint32_t height = 0;
|
||||
void* buffer = nullptr;
|
||||
size_t buffer_size = 0;
|
||||
};
|
||||
|
||||
struct PictureInfo {
|
||||
uint64_t pts = TIMESTAMP_INVALID;
|
||||
uint64_t dts = TIMESTAMP_INVALID;
|
||||
uint64_t attached_data = 0;
|
||||
uint32_t codec_type = 0;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
uint32_t crop_left = 0;
|
||||
uint32_t crop_right = 0;
|
||||
uint32_t crop_top = 0;
|
||||
uint32_t crop_bottom = 0;
|
||||
uint32_t profile = 0;
|
||||
uint32_t level = 0;
|
||||
uint16_t sar_width = 0;
|
||||
uint16_t sar_height = 0;
|
||||
uint8_t color_range = 0;
|
||||
uint8_t color_primaries = 0;
|
||||
uint8_t color_trc = 0;
|
||||
uint8_t color_space = 0;
|
||||
bool key_frame = false;
|
||||
};
|
||||
|
||||
class Instance;
|
||||
|
||||
[[nodiscard]] bool IsCodecSupported(uint32_t codec_type);
|
||||
[[nodiscard]] Instance* Create(const Config& config);
|
||||
void Destroy(Instance* instance);
|
||||
[[nodiscard]] uint32_t GetCodecType(const Instance* instance);
|
||||
[[nodiscard]] Result Decode(Instance* instance, const Input& input, const FrameBuffer& frame_buffer,
|
||||
Output* output);
|
||||
[[nodiscard]] Result Flush(Instance* instance, const FrameBuffer& frame_buffer, Output* output);
|
||||
void Reset(Instance* instance);
|
||||
[[nodiscard]] bool GetPictureInfo(void* frame_buffer, PictureInfo* picture_info);
|
||||
|
||||
} // namespace Libs::VideoDec2::Decoder
|
||||
|
||||
#endif // EMULATOR_INCLUDE_EMULATOR_LIBS_VIDEODEC2DECODER_H_
|
||||
@@ -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
+136
-20
@@ -1,3 +1,4 @@
|
||||
#include "graphics/shader/recompiler/ir/ReadLaneElimination.h"
|
||||
#include "graphics/shader/recompiler/ir/ScalarProvenance.h"
|
||||
#include "graphics/shader/recompiler/ir/SrtWalker.h"
|
||||
|
||||
@@ -481,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());
|
||||
@@ -549,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());
|
||||
@@ -588,11 +589,125 @@ 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");
|
||||
}
|
||||
|
||||
void TestReadLaneEliminationSnapshotsWriteValue() {
|
||||
Program program;
|
||||
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),
|
||||
MoveImmediate(8, 4, 0xdeadbeefu), ReadLane(12, 0, 11, 4)};
|
||||
|
||||
std::string error;
|
||||
Check(BuildScalarProvenance(program, &error), error.c_str());
|
||||
const auto stats = EliminateReadLane(program);
|
||||
Check(stats.rewritten_reads == 1 && stats.shadow_writes == 1,
|
||||
"fixed readlane was not rewritten through a writelane shadow");
|
||||
const auto& instructions = program.blocks[0].instructions;
|
||||
Check(instructions.size() == 5 && instructions[2].op == Opcode::MoveU32 &&
|
||||
instructions[2].dst.kind == OperandKind::Register &&
|
||||
instructions[2].dst.reg.file == RegisterFile::Scalar &&
|
||||
instructions[2].dst.reg.index >= 128 && instructions[2].src[0] == Sgpr(4),
|
||||
"writelane did not snapshot its source into a temporary scalar");
|
||||
Check(instructions[4].op == Opcode::MoveU32 && instructions[4].dst == Sgpr(0) &&
|
||||
instructions[4].src[0] == instructions[2].dst,
|
||||
"readlane did not consume the writelane snapshot");
|
||||
}
|
||||
|
||||
void TestReadLaneEliminationMergesControlFlowWrites() {
|
||||
Program program;
|
||||
program.wave_size = 64;
|
||||
program.user_data_count = 8;
|
||||
program.blocks.resize(4);
|
||||
program.blocks[0].successors = {1, 2};
|
||||
program.blocks[1].predecessors = {0};
|
||||
program.blocks[1].successors = {3};
|
||||
program.blocks[2].predecessors = {0};
|
||||
program.blocks[2].successors = {3};
|
||||
program.blocks[3].predecessors = {1, 2};
|
||||
program.blocks[1].instructions = {WriteLane(0, 11, 4, 4)};
|
||||
program.blocks[2].instructions = {WriteLane(4, 11, 5, 4)};
|
||||
program.blocks[3].instructions = {ReadLane(8, 0, 11, 4)};
|
||||
|
||||
std::string error;
|
||||
Check(BuildScalarProvenance(program, &error), error.c_str());
|
||||
const auto stats = EliminateReadLane(program);
|
||||
Check(stats.rewritten_reads == 1 && stats.shadow_writes == 2,
|
||||
"readlane merge did not shadow both reaching writelane definitions");
|
||||
const auto branch_a_temp = program.blocks[1].instructions[1].dst;
|
||||
const auto branch_b_temp = program.blocks[2].instructions[1].dst;
|
||||
Check(branch_a_temp == branch_b_temp &&
|
||||
program.blocks[3].instructions[0].op == Opcode::MoveU32 &&
|
||||
program.blocks[3].instructions[0].src[0] == branch_a_temp,
|
||||
"control-flow writelanes did not merge through one shadow register");
|
||||
}
|
||||
|
||||
void TestReadLaneEliminationRequiresWriteOnEveryPath() {
|
||||
Program program;
|
||||
program.wave_size = 64;
|
||||
program.user_data_count = 8;
|
||||
program.blocks.resize(4);
|
||||
program.blocks[0].successors = {1, 2};
|
||||
program.blocks[1].predecessors = {0};
|
||||
program.blocks[1].successors = {3};
|
||||
program.blocks[2].predecessors = {0};
|
||||
program.blocks[2].successors = {3};
|
||||
program.blocks[3].predecessors = {1, 2};
|
||||
program.blocks[1].instructions = {WriteLane(0, 11, 4, 4)};
|
||||
program.blocks[3].instructions = {ReadLane(4, 0, 11, 4)};
|
||||
|
||||
std::string error;
|
||||
Check(BuildScalarProvenance(program, &error), error.c_str());
|
||||
const auto stats = EliminateReadLane(program);
|
||||
Check(stats.rewritten_reads == 0 && stats.shadow_writes == 0 &&
|
||||
program.blocks[3].instructions[0].op == Opcode::ReadLaneU32,
|
||||
"readlane without a definition on every path was unsafely rewritten");
|
||||
}
|
||||
|
||||
void TestReadLaneEliminationHonorsVectorInvalidation() {
|
||||
Program program;
|
||||
program.wave_size = 64;
|
||||
program.user_data_count = 8;
|
||||
program.blocks.resize(1);
|
||||
Instruction overwrite;
|
||||
overwrite.pc = 4;
|
||||
overwrite.op = Opcode::MoveU32;
|
||||
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)};
|
||||
|
||||
std::string error;
|
||||
Check(BuildScalarProvenance(program, &error), error.c_str());
|
||||
const auto stats = EliminateReadLane(program);
|
||||
Check(stats.rewritten_reads == 0 && stats.shadow_writes == 0 &&
|
||||
program.blocks[0].instructions.back().op == Opcode::ReadLaneU32,
|
||||
"readlane was rewritten across an intervening vector overwrite");
|
||||
}
|
||||
|
||||
void TestReadLaneEliminationFoldsScalarLaneSelector() {
|
||||
Program program;
|
||||
program.wave_size = 32;
|
||||
program.user_data_count = 8;
|
||||
program.blocks.resize(1);
|
||||
auto write = WriteLane(4, 11, 4, 0);
|
||||
write.src[1] = Sgpr(7);
|
||||
auto read = ReadLane(8, 0, 11, 0);
|
||||
read.src[1] = Sgpr(7);
|
||||
program.blocks[0].instructions = {MoveImmediate(0, 7, 33), write, read};
|
||||
|
||||
std::string error;
|
||||
Check(BuildScalarProvenance(program, &error), error.c_str());
|
||||
const auto stats = EliminateReadLane(program);
|
||||
Check(stats.rewritten_reads == 1 && stats.shadow_writes == 1 &&
|
||||
program.blocks[0].instructions.back().op == Opcode::MoveU32,
|
||||
"constant scalar lane selector was not folded modulo wave32");
|
||||
}
|
||||
|
||||
void TestUnresolvedSourceIsMarked() {
|
||||
Program program;
|
||||
program.blocks.resize(1);
|
||||
@@ -723,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");
|
||||
}
|
||||
|
||||
@@ -1034,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");
|
||||
@@ -1091,6 +1202,11 @@ int main() {
|
||||
TestReadLaneLoopConvergence();
|
||||
TestReadLaneWideAndRelativeWritesInvalidateSpill();
|
||||
TestReadLaneModuloAndDynamicLane();
|
||||
TestReadLaneEliminationSnapshotsWriteValue();
|
||||
TestReadLaneEliminationMergesControlFlowWrites();
|
||||
TestReadLaneEliminationRequiresWriteOnEveryPath();
|
||||
TestReadLaneEliminationHonorsVectorInvalidation();
|
||||
TestReadLaneEliminationFoldsScalarLaneSelector();
|
||||
TestUnresolvedSourceIsMarked();
|
||||
TestUnsupportedWideWriteInvalidatesBothDwords();
|
||||
TestCyclicPhiIsUnresolved();
|
||||
|
||||
+3125
-4446
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),
|
||||
|
||||
+104
-54
@@ -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"
|
||||
@@ -221,7 +221,7 @@ uint32_t SpirvExtInstCount(const std::vector<uint32_t>& binary, uint32_t ext_ins
|
||||
}
|
||||
|
||||
bool SpirvContainsTypeImage(const std::vector<uint32_t>& binary, uint32_t dim, uint32_t arrayed,
|
||||
uint32_t sampled) {
|
||||
uint32_t sampled, uint32_t multisampled = 0) {
|
||||
for (size_t i = 5; i < binary.size();) {
|
||||
const uint32_t word = binary[i];
|
||||
const uint32_t opcode = word & 0xffffu;
|
||||
@@ -230,7 +230,7 @@ bool SpirvContainsTypeImage(const std::vector<uint32_t>& binary, uint32_t dim, u
|
||||
return false;
|
||||
}
|
||||
if (opcode == 25u && word_count >= 9u && binary[i + 3] == dim && binary[i + 5] == arrayed &&
|
||||
binary[i + 7] == sampled) {
|
||||
binary[i + 6] == multisampled && binary[i + 7] == sampled) {
|
||||
return true;
|
||||
}
|
||||
i += word_count;
|
||||
@@ -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;
|
||||
@@ -2972,7 +2967,6 @@ void TestNewShaderRecompilerMemoryFamilyLowering() {
|
||||
Check(SpirvContainsOpcode(result.spirv, 61), "SPIR-V binary does not contain OpLoad");
|
||||
Check(SpirvContainsOpcode(result.spirv, 62), "SPIR-V binary does not contain OpStore");
|
||||
Check(SpirvContainsOpcode(result.spirv, 95), "SPIR-V binary does not contain OpImageFetch");
|
||||
Check(SpirvContainsOpcode(result.spirv, 100), "SPIR-V binary does not contain OpImage");
|
||||
Check(SpirvContainsOpcode(result.spirv, 103),
|
||||
"SPIR-V binary does not contain OpImageQuerySizeLod");
|
||||
Check(SpirvContainsOpcode(result.spirv, 88),
|
||||
@@ -3526,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);
|
||||
@@ -3766,6 +3758,50 @@ void TestNewShaderRecompilerImageLoadVariants() {
|
||||
CheckSpirvBinaryValidates(result.spirv);
|
||||
}
|
||||
|
||||
void TestNewShaderRecompilerImageLoad2DMsaa() {
|
||||
const uint32_t shader[] = {
|
||||
0xf0000130u, // image_load v3, v[5:7], s[0:7] dmask:x dim:2d_msaa
|
||||
0x00000305u,
|
||||
0xbf810000u,
|
||||
};
|
||||
|
||||
auto user_data = ImageTestUserData(Prospero::ImageType::kColor2DMsaa);
|
||||
user_data[3] |= 2u << 16u;
|
||||
user_data[5] |= 2u << 4u;
|
||||
user_data[6] |= 1u << 10u;
|
||||
|
||||
ShaderRecompiler::CompileOptions options;
|
||||
options.stage = ShaderType::Pixel;
|
||||
options.dump_ir = true;
|
||||
options.user_data = user_data.data();
|
||||
|
||||
ShaderRecompiler::CompileResult result;
|
||||
std::string error;
|
||||
Check(ShaderRecompiler::TryRecompile(shader, options, result, &error), error.c_str());
|
||||
Check(Common::ContainsStr(result.decoded_dump, "image_dim=2d_msaa") &&
|
||||
Common::ContainsStr(result.ir_dump, "image_dim=2d_msaa") &&
|
||||
Common::ContainsStr(result.ir_dump, "image_addr=3 image_mip=0"),
|
||||
"RDNA2 2D-MSAA load did not preserve x, y, and fragment ID");
|
||||
Check(result.program.info.images.size() == 1 &&
|
||||
result.program.info.images[0].dimension ==
|
||||
ShaderRecompiler::Decoder::ImageDimension::Dim2DMsaa,
|
||||
"2D-MSAA descriptor specialization lost the multisample dimension");
|
||||
Check(ShaderRecompiler::IR::FindBinding(
|
||||
result.program.bindings,
|
||||
ShaderRecompiler::IR::DescriptorBindingKind::Sampled2DMsaa) != nullptr,
|
||||
"2D-MSAA image did not receive a multisampled descriptor binding");
|
||||
Check(SpirvContainsTypeImage(result.spirv, 1, 0, 1, 1),
|
||||
"SPIR-V binary does not contain a multisampled 2D image type");
|
||||
CheckSpirvBinaryValidates(result.spirv);
|
||||
const auto source = DisassembleSpirvBinary(result.spirv);
|
||||
Check(SpirvSourceHasInstructionUsing(source, "OpAccessChain", "sampled_2d_msaa"),
|
||||
"2D-MSAA load did not access its multisampled descriptor");
|
||||
Check(SpirvSourceHasInstructionUsing(source, "OpImageFetch", " Sample "),
|
||||
"2D-MSAA load did not emit the fragment ID as a SPIR-V Sample operand");
|
||||
Check(!SpirvSourceHasInstructionUsing(source, "OpImageFetch", " Lod "),
|
||||
"2D-MSAA load incorrectly emitted its fragment ID as a mip level");
|
||||
}
|
||||
|
||||
void TestNewShaderRecompilerImageStoreLowering() {
|
||||
const uint32_t shader[] = {
|
||||
EncodeMimg0(0x08, 0xf),
|
||||
@@ -4073,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),
|
||||
@@ -5950,6 +5985,22 @@ void TestNewShaderRecompilerExpPixelOutputs() {
|
||||
Check(SpirvContainsOpcode(result.spirv, 81),
|
||||
"compressed pixel export SPIR-V lacks OpCompositeExtract");
|
||||
CheckSpirvBinaryValidates(result.spirv);
|
||||
|
||||
ShaderPixelInputInfo uint16_info;
|
||||
uint16_info.target_output_mode[0] = 7;
|
||||
options.pixel_input_info = &uint16_info;
|
||||
ShaderRecompiler::CompileResult uint16_result;
|
||||
Check(ShaderRecompiler::TryRecompile(shader, options, uint16_result, &error), error.c_str());
|
||||
const auto uint16_source = DisassembleSpirvBinary(uint16_result.spirv);
|
||||
Check(Common::ContainsStr(uint16_source, "OpVariable %_ptr_Output_v4uint Output"),
|
||||
"UINT16 MRT export did not use an unsigned integer output");
|
||||
Check(CountSourceOccurrences(uint16_source, "OpBitFieldUExtract") == 4u &&
|
||||
Common::ContainsStr(uint16_source, "%uint_0 %uint_16") &&
|
||||
Common::ContainsStr(uint16_source, "%uint_16 %uint_16"),
|
||||
"compressed UINT16 MRT export did not extract all low/high 16-bit lanes");
|
||||
Check(!SpirvContainsExtInst(uint16_result.spirv, 62),
|
||||
"compressed UINT16 MRT export was incorrectly decoded as FP16");
|
||||
CheckSpirvBinaryValidates(uint16_result.spirv);
|
||||
}
|
||||
|
||||
void TestRenderTargetReverseFloat16ExportMapping() {
|
||||
@@ -5968,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(),
|
||||
@@ -6001,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);
|
||||
@@ -6947,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");
|
||||
@@ -7002,6 +7051,7 @@ int main() {
|
||||
TestNewShaderRecompilerImageGatherVariants();
|
||||
TestNewShaderRecompilerImageLoadA16UintCoords();
|
||||
TestNewShaderRecompilerImageLoadVariants();
|
||||
TestNewShaderRecompilerImageLoad2DMsaa();
|
||||
TestNewShaderRecompilerImageStoreLowering();
|
||||
TestNewShaderRecompilerStorageImage3DDescriptorVariant();
|
||||
TestNewShaderRecompilerStorageImage2DDescriptorOverridesMimg3D();
|
||||
|
||||
Reference in New Issue
Block a user