mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-22 02:41:49 -05:00
commit
fbf0a9c976
6 changed files with 38 additions and 38 deletions
|
@ -38,12 +38,12 @@ public:
|
||||||
Map(address, address_end, null_value);
|
Map(address, address_end, null_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] size_t GetContinousSizeFrom(KeyTBase address) const {
|
[[nodiscard]] size_t GetContinuousSizeFrom(KeyTBase address) const {
|
||||||
const KeyT new_address = static_cast<KeyT>(address);
|
const KeyT new_address = static_cast<KeyT>(address);
|
||||||
if (new_address < 0) {
|
if (new_address < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return ContinousSizeInternal(new_address);
|
return ContinuousSizeInternal(new_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] ValueT GetValueAt(KeyT address) const {
|
[[nodiscard]] ValueT GetValueAt(KeyT address) const {
|
||||||
|
@ -59,7 +59,7 @@ private:
|
||||||
using IteratorType = typename MapType::iterator;
|
using IteratorType = typename MapType::iterator;
|
||||||
using ConstIteratorType = typename MapType::const_iterator;
|
using ConstIteratorType = typename MapType::const_iterator;
|
||||||
|
|
||||||
size_t ContinousSizeInternal(KeyT address) const {
|
size_t ContinuousSizeInternal(KeyT address) const {
|
||||||
const auto it = GetFirstElementBeforeOrOn(address);
|
const auto it = GetFirstElementBeforeOrOn(address);
|
||||||
if (it == container.end() || it->second == null_value) {
|
if (it == container.end() || it->second == null_value) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -21,9 +21,9 @@ TEST_CASE("Range Map: Setup", "[video_core]") {
|
||||||
my_map.Map(4000, 4500, MappedEnum::Valid_2);
|
my_map.Map(4000, 4500, MappedEnum::Valid_2);
|
||||||
my_map.Map(4200, 4400, MappedEnum::Valid_2);
|
my_map.Map(4200, 4400, MappedEnum::Valid_2);
|
||||||
my_map.Map(4200, 4400, MappedEnum::Valid_1);
|
my_map.Map(4200, 4400, MappedEnum::Valid_1);
|
||||||
REQUIRE(my_map.GetContinousSizeFrom(4200) == 200);
|
REQUIRE(my_map.GetContinuousSizeFrom(4200) == 200);
|
||||||
REQUIRE(my_map.GetContinousSizeFrom(3000) == 200);
|
REQUIRE(my_map.GetContinuousSizeFrom(3000) == 200);
|
||||||
REQUIRE(my_map.GetContinousSizeFrom(2900) == 0);
|
REQUIRE(my_map.GetContinuousSizeFrom(2900) == 0);
|
||||||
|
|
||||||
REQUIRE(my_map.GetValueAt(2900) == MappedEnum::Invalid);
|
REQUIRE(my_map.GetValueAt(2900) == MappedEnum::Invalid);
|
||||||
REQUIRE(my_map.GetValueAt(3100) == MappedEnum::Valid_1);
|
REQUIRE(my_map.GetValueAt(3100) == MappedEnum::Valid_1);
|
||||||
|
@ -38,20 +38,20 @@ TEST_CASE("Range Map: Setup", "[video_core]") {
|
||||||
|
|
||||||
my_map.Unmap(0, 6000);
|
my_map.Unmap(0, 6000);
|
||||||
for (u64 address = 0; address < 10000; address += 1000) {
|
for (u64 address = 0; address < 10000; address += 1000) {
|
||||||
REQUIRE(my_map.GetContinousSizeFrom(address) == 0);
|
REQUIRE(my_map.GetContinuousSizeFrom(address) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
my_map.Map(1000, 3000, MappedEnum::Valid_1);
|
my_map.Map(1000, 3000, MappedEnum::Valid_1);
|
||||||
my_map.Map(4000, 5000, MappedEnum::Valid_1);
|
my_map.Map(4000, 5000, MappedEnum::Valid_1);
|
||||||
my_map.Map(2500, 4100, MappedEnum::Valid_1);
|
my_map.Map(2500, 4100, MappedEnum::Valid_1);
|
||||||
REQUIRE(my_map.GetContinousSizeFrom(1000) == 4000);
|
REQUIRE(my_map.GetContinuousSizeFrom(1000) == 4000);
|
||||||
|
|
||||||
my_map.Map(1000, 3000, MappedEnum::Valid_1);
|
my_map.Map(1000, 3000, MappedEnum::Valid_1);
|
||||||
my_map.Map(4000, 5000, MappedEnum::Valid_2);
|
my_map.Map(4000, 5000, MappedEnum::Valid_2);
|
||||||
my_map.Map(2500, 4100, MappedEnum::Valid_3);
|
my_map.Map(2500, 4100, MappedEnum::Valid_3);
|
||||||
REQUIRE(my_map.GetContinousSizeFrom(1000) == 1500);
|
REQUIRE(my_map.GetContinuousSizeFrom(1000) == 1500);
|
||||||
REQUIRE(my_map.GetContinousSizeFrom(2500) == 1600);
|
REQUIRE(my_map.GetContinuousSizeFrom(2500) == 1600);
|
||||||
REQUIRE(my_map.GetContinousSizeFrom(4100) == 900);
|
REQUIRE(my_map.GetContinuousSizeFrom(4100) == 900);
|
||||||
REQUIRE(my_map.GetValueAt(900) == MappedEnum::Invalid);
|
REQUIRE(my_map.GetValueAt(900) == MappedEnum::Invalid);
|
||||||
REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1);
|
REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1);
|
||||||
REQUIRE(my_map.GetValueAt(2500) == MappedEnum::Valid_3);
|
REQUIRE(my_map.GetValueAt(2500) == MappedEnum::Valid_3);
|
||||||
|
@ -59,8 +59,8 @@ TEST_CASE("Range Map: Setup", "[video_core]") {
|
||||||
REQUIRE(my_map.GetValueAt(5000) == MappedEnum::Invalid);
|
REQUIRE(my_map.GetValueAt(5000) == MappedEnum::Invalid);
|
||||||
|
|
||||||
my_map.Map(2000, 6000, MappedEnum::Valid_3);
|
my_map.Map(2000, 6000, MappedEnum::Valid_3);
|
||||||
REQUIRE(my_map.GetContinousSizeFrom(1000) == 1000);
|
REQUIRE(my_map.GetContinuousSizeFrom(1000) == 1000);
|
||||||
REQUIRE(my_map.GetContinousSizeFrom(3000) == 3000);
|
REQUIRE(my_map.GetContinuousSizeFrom(3000) == 3000);
|
||||||
REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1);
|
REQUIRE(my_map.GetValueAt(1000) == MappedEnum::Valid_1);
|
||||||
REQUIRE(my_map.GetValueAt(1999) == MappedEnum::Valid_1);
|
REQUIRE(my_map.GetValueAt(1999) == MappedEnum::Valid_1);
|
||||||
REQUIRE(my_map.GetValueAt(1500) == MappedEnum::Valid_1);
|
REQUIRE(my_map.GetValueAt(1500) == MappedEnum::Valid_1);
|
||||||
|
|
|
@ -1442,7 +1442,7 @@ void BufferCache<P>::UpdateVertexBuffer(u32 index) {
|
||||||
}
|
}
|
||||||
if (!gpu_memory->IsWithinGPUAddressRange(gpu_addr_end)) {
|
if (!gpu_memory->IsWithinGPUAddressRange(gpu_addr_end)) {
|
||||||
address_size =
|
address_size =
|
||||||
static_cast<u32>(gpu_memory->MaxContinousRange(gpu_addr_begin, address_size));
|
static_cast<u32>(gpu_memory->MaxContinuousRange(gpu_addr_begin, address_size));
|
||||||
}
|
}
|
||||||
const u32 size = address_size; // TODO: Analyze stride and number of vertices
|
const u32 size = address_size; // TODO: Analyze stride and number of vertices
|
||||||
vertex_buffers[index] = Binding{
|
vertex_buffers[index] = Binding{
|
||||||
|
|
|
@ -43,7 +43,7 @@ MemoryManager::MemoryManager(Core::System& system_, u64 address_space_bits_, u64
|
||||||
|
|
||||||
big_entries.resize(big_page_table_size / 32, 0);
|
big_entries.resize(big_page_table_size / 32, 0);
|
||||||
big_page_table_cpu.resize(big_page_table_size);
|
big_page_table_cpu.resize(big_page_table_size);
|
||||||
big_page_continous.resize(big_page_table_size / continous_bits, 0);
|
big_page_continuous.resize(big_page_table_size / continuous_bits, 0);
|
||||||
entries.resize(page_table_size / 32, 0);
|
entries.resize(page_table_size / 32, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,17 +85,17 @@ PTEKind MemoryManager::GetPageKind(GPUVAddr gpu_addr) const {
|
||||||
return kind_map.GetValueAt(gpu_addr);
|
return kind_map.GetValueAt(gpu_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool MemoryManager::IsBigPageContinous(size_t big_page_index) const {
|
inline bool MemoryManager::IsBigPageContinuous(size_t big_page_index) const {
|
||||||
const u64 entry_mask = big_page_continous[big_page_index / continous_bits];
|
const u64 entry_mask = big_page_continuous[big_page_index / continuous_bits];
|
||||||
const size_t sub_index = big_page_index % continous_bits;
|
const size_t sub_index = big_page_index % continuous_bits;
|
||||||
return ((entry_mask >> sub_index) & 0x1ULL) != 0;
|
return ((entry_mask >> sub_index) & 0x1ULL) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void MemoryManager::SetBigPageContinous(size_t big_page_index, bool value) {
|
inline void MemoryManager::SetBigPageContinuous(size_t big_page_index, bool value) {
|
||||||
const u64 continous_mask = big_page_continous[big_page_index / continous_bits];
|
const u64 continuous_mask = big_page_continuous[big_page_index / continuous_bits];
|
||||||
const size_t sub_index = big_page_index % continous_bits;
|
const size_t sub_index = big_page_index % continuous_bits;
|
||||||
big_page_continous[big_page_index / continous_bits] =
|
big_page_continuous[big_page_index / continuous_bits] =
|
||||||
(~(1ULL << sub_index) & continous_mask) | (value ? 1ULL << sub_index : 0);
|
(~(1ULL << sub_index) & continuous_mask) | (value ? 1ULL << sub_index : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <MemoryManager::EntryType entry_type>
|
template <MemoryManager::EntryType entry_type>
|
||||||
|
@ -140,7 +140,7 @@ GPUVAddr MemoryManager::BigPageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] VAddr
|
||||||
const auto index = PageEntryIndex<true>(current_gpu_addr);
|
const auto index = PageEntryIndex<true>(current_gpu_addr);
|
||||||
const u32 sub_value = static_cast<u32>(current_cpu_addr >> cpu_page_bits);
|
const u32 sub_value = static_cast<u32>(current_cpu_addr >> cpu_page_bits);
|
||||||
big_page_table_cpu[index] = sub_value;
|
big_page_table_cpu[index] = sub_value;
|
||||||
const bool is_continous = ([&] {
|
const bool is_continuous = ([&] {
|
||||||
uintptr_t base_ptr{
|
uintptr_t base_ptr{
|
||||||
reinterpret_cast<uintptr_t>(memory.GetPointerSilent(current_cpu_addr))};
|
reinterpret_cast<uintptr_t>(memory.GetPointerSilent(current_cpu_addr))};
|
||||||
if (base_ptr == 0) {
|
if (base_ptr == 0) {
|
||||||
|
@ -156,7 +156,7 @@ GPUVAddr MemoryManager::BigPageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] VAddr
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
})();
|
})();
|
||||||
SetBigPageContinous(index, is_continous);
|
SetBigPageContinuous(index, is_continuous);
|
||||||
}
|
}
|
||||||
remaining_size -= big_page_size;
|
remaining_size -= big_page_size;
|
||||||
}
|
}
|
||||||
|
@ -378,7 +378,7 @@ void MemoryManager::ReadBlockImpl(GPUVAddr gpu_src_addr, void* dest_buffer, std:
|
||||||
if constexpr (is_safe) {
|
if constexpr (is_safe) {
|
||||||
rasterizer->FlushRegion(cpu_addr_base, copy_amount, which);
|
rasterizer->FlushRegion(cpu_addr_base, copy_amount, which);
|
||||||
}
|
}
|
||||||
if (!IsBigPageContinous(page_index)) [[unlikely]] {
|
if (!IsBigPageContinuous(page_index)) [[unlikely]] {
|
||||||
memory.ReadBlockUnsafe(cpu_addr_base, dest_buffer, copy_amount);
|
memory.ReadBlockUnsafe(cpu_addr_base, dest_buffer, copy_amount);
|
||||||
} else {
|
} else {
|
||||||
u8* physical = memory.GetPointer(cpu_addr_base);
|
u8* physical = memory.GetPointer(cpu_addr_base);
|
||||||
|
@ -427,7 +427,7 @@ void MemoryManager::WriteBlockImpl(GPUVAddr gpu_dest_addr, const void* src_buffe
|
||||||
if constexpr (is_safe) {
|
if constexpr (is_safe) {
|
||||||
rasterizer->InvalidateRegion(cpu_addr_base, copy_amount, which);
|
rasterizer->InvalidateRegion(cpu_addr_base, copy_amount, which);
|
||||||
}
|
}
|
||||||
if (!IsBigPageContinous(page_index)) [[unlikely]] {
|
if (!IsBigPageContinuous(page_index)) [[unlikely]] {
|
||||||
memory.WriteBlockUnsafe(cpu_addr_base, src_buffer, copy_amount);
|
memory.WriteBlockUnsafe(cpu_addr_base, src_buffer, copy_amount);
|
||||||
} else {
|
} else {
|
||||||
u8* physical = memory.GetPointer(cpu_addr_base);
|
u8* physical = memory.GetPointer(cpu_addr_base);
|
||||||
|
@ -512,7 +512,7 @@ bool MemoryManager::IsMemoryDirty(GPUVAddr gpu_addr, size_t size,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MemoryManager::MaxContinousRange(GPUVAddr gpu_addr, size_t size) const {
|
size_t MemoryManager::MaxContinuousRange(GPUVAddr gpu_addr, size_t size) const {
|
||||||
std::optional<VAddr> old_page_addr{};
|
std::optional<VAddr> old_page_addr{};
|
||||||
size_t range_so_far = 0;
|
size_t range_so_far = 0;
|
||||||
bool result{false};
|
bool result{false};
|
||||||
|
@ -553,7 +553,7 @@ size_t MemoryManager::MaxContinousRange(GPUVAddr gpu_addr, size_t size) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MemoryManager::GetMemoryLayoutSize(GPUVAddr gpu_addr, size_t max_size) const {
|
size_t MemoryManager::GetMemoryLayoutSize(GPUVAddr gpu_addr, size_t max_size) const {
|
||||||
return kind_map.GetContinousSizeFrom(gpu_addr);
|
return kind_map.GetContinuousSizeFrom(gpu_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryManager::InvalidateRegion(GPUVAddr gpu_addr, size_t size,
|
void MemoryManager::InvalidateRegion(GPUVAddr gpu_addr, size_t size,
|
||||||
|
@ -594,7 +594,7 @@ void MemoryManager::CopyBlock(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, std
|
||||||
bool MemoryManager::IsGranularRange(GPUVAddr gpu_addr, std::size_t size) const {
|
bool MemoryManager::IsGranularRange(GPUVAddr gpu_addr, std::size_t size) const {
|
||||||
if (GetEntry<true>(gpu_addr) == EntryType::Mapped) [[likely]] {
|
if (GetEntry<true>(gpu_addr) == EntryType::Mapped) [[likely]] {
|
||||||
size_t page_index = gpu_addr >> big_page_bits;
|
size_t page_index = gpu_addr >> big_page_bits;
|
||||||
if (IsBigPageContinous(page_index)) [[likely]] {
|
if (IsBigPageContinuous(page_index)) [[likely]] {
|
||||||
const std::size_t page{(page_index & big_page_mask) + size};
|
const std::size_t page{(page_index & big_page_mask) + size};
|
||||||
return page <= big_page_size;
|
return page <= big_page_size;
|
||||||
}
|
}
|
||||||
|
@ -608,7 +608,7 @@ bool MemoryManager::IsGranularRange(GPUVAddr gpu_addr, std::size_t size) const {
|
||||||
return page <= Core::Memory::YUZU_PAGESIZE;
|
return page <= Core::Memory::YUZU_PAGESIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MemoryManager::IsContinousRange(GPUVAddr gpu_addr, std::size_t size) const {
|
bool MemoryManager::IsContinuousRange(GPUVAddr gpu_addr, std::size_t size) const {
|
||||||
std::optional<VAddr> old_page_addr{};
|
std::optional<VAddr> old_page_addr{};
|
||||||
bool result{true};
|
bool result{true};
|
||||||
auto fail = [&]([[maybe_unused]] std::size_t page_index, [[maybe_unused]] std::size_t offset,
|
auto fail = [&]([[maybe_unused]] std::size_t page_index, [[maybe_unused]] std::size_t offset,
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Checks if a gpu region is mapped by a single range of cpu addresses.
|
* Checks if a gpu region is mapped by a single range of cpu addresses.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool IsContinousRange(GPUVAddr gpu_addr, std::size_t size) const;
|
[[nodiscard]] bool IsContinuousRange(GPUVAddr gpu_addr, std::size_t size) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a gpu region is mapped entirely.
|
* Checks if a gpu region is mapped entirely.
|
||||||
|
@ -123,7 +123,7 @@ public:
|
||||||
bool IsMemoryDirty(GPUVAddr gpu_addr, size_t size,
|
bool IsMemoryDirty(GPUVAddr gpu_addr, size_t size,
|
||||||
VideoCommon::CacheType which = VideoCommon::CacheType::All) const;
|
VideoCommon::CacheType which = VideoCommon::CacheType::All) const;
|
||||||
|
|
||||||
size_t MaxContinousRange(GPUVAddr gpu_addr, size_t size) const;
|
size_t MaxContinuousRange(GPUVAddr gpu_addr, size_t size) const;
|
||||||
|
|
||||||
bool IsWithinGPUAddressRange(GPUVAddr gpu_addr) const {
|
bool IsWithinGPUAddressRange(GPUVAddr gpu_addr) const {
|
||||||
return gpu_addr < address_space_size;
|
return gpu_addr < address_space_size;
|
||||||
|
@ -158,8 +158,8 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsBigPageContinous(size_t big_page_index) const;
|
inline bool IsBigPageContinuous(size_t big_page_index) const;
|
||||||
inline void SetBigPageContinous(size_t big_page_index, bool value);
|
inline void SetBigPageContinuous(size_t big_page_index, bool value);
|
||||||
|
|
||||||
template <bool is_gpu_address>
|
template <bool is_gpu_address>
|
||||||
void GetSubmappedRangeImpl(
|
void GetSubmappedRangeImpl(
|
||||||
|
@ -213,10 +213,10 @@ private:
|
||||||
Common::RangeMap<GPUVAddr, PTEKind> kind_map;
|
Common::RangeMap<GPUVAddr, PTEKind> kind_map;
|
||||||
Common::VirtualBuffer<u32> big_page_table_cpu;
|
Common::VirtualBuffer<u32> big_page_table_cpu;
|
||||||
|
|
||||||
std::vector<u64> big_page_continous;
|
std::vector<u64> big_page_continuous;
|
||||||
std::vector<std::pair<VAddr, std::size_t>> page_stash{};
|
std::vector<std::pair<VAddr, std::size_t>> page_stash{};
|
||||||
|
|
||||||
static constexpr size_t continous_bits = 64;
|
static constexpr size_t continuous_bits = 64;
|
||||||
|
|
||||||
const size_t unique_identifier;
|
const size_t unique_identifier;
|
||||||
std::unique_ptr<VideoCommon::InvalidationAccumulator> accumulator;
|
std::unique_ptr<VideoCommon::InvalidationAccumulator> accumulator;
|
||||||
|
|
|
@ -1269,7 +1269,7 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA
|
||||||
const ImageId new_image_id = slot_images.insert(runtime, new_info, gpu_addr, cpu_addr);
|
const ImageId new_image_id = slot_images.insert(runtime, new_info, gpu_addr, cpu_addr);
|
||||||
Image& new_image = slot_images[new_image_id];
|
Image& new_image = slot_images[new_image_id];
|
||||||
|
|
||||||
if (!gpu_memory->IsContinousRange(new_image.gpu_addr, new_image.guest_size_bytes)) {
|
if (!gpu_memory->IsContinuousRange(new_image.gpu_addr, new_image.guest_size_bytes)) {
|
||||||
new_image.flags |= ImageFlagBits::Sparse;
|
new_image.flags |= ImageFlagBits::Sparse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue