yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

Shader_IR: Address Feedback

This commit is contained in:
Fernando Sahmkow 2020-01-08 11:46:36 -04:00 committed by FernandoS27
parent b97608ca64
commit 64496f2456
5 changed files with 37 additions and 35 deletions

View File

@ -3,7 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm> #include <algorithm>
#include <climits> #include <limits>
#include "video_core/guest_driver.h" #include "video_core/guest_driver.h"
@ -17,10 +17,9 @@ void GuestDriverProfile::DeduceTextureHandlerSize(std::vector<u32>&& bound_offse
if (size < 2) { if (size < 2) {
return; return;
} }
std::sort(bound_offsets.begin(), bound_offsets.end(), std::sort(bound_offsets.begin(), bound_offsets.end(), std::less{});
[](const u32& a, const u32& b) { return a < b; }); u32 min_val = std::numeric_limits<u32>::max();
u32 min_val = UINT_MAX; for (std::size_t i = 1; i < size; ++i) {
for (std::size_t i = 1; i < size; i++) {
if (bound_offsets[i] == bound_offsets[i - 1]) { if (bound_offsets[i] == bound_offsets[i - 1]) {
continue; continue;
} }

View File

@ -12,10 +12,13 @@ namespace VideoCore {
/** /**
* The GuestDriverProfile class is used to learn about the GPU drivers behavior and collect * The GuestDriverProfile class is used to learn about the GPU drivers behavior and collect
* information necessary for impossible to avoid HLE methods like shader tracks. * information necessary for impossible to avoid HLE methods like shader tracks as they are
* Entscheidungsproblems.
*/ */
class GuestDriverProfile { class GuestDriverProfile {
public: public:
void DeduceTextureHandlerSize(std::vector<u32>&& bound_offsets);
u32 GetTextureHandlerSize() const { u32 GetTextureHandlerSize() const {
return texture_handler_size; return texture_handler_size;
} }
@ -24,16 +27,14 @@ public:
return texture_handler_size_deduced; return texture_handler_size_deduced;
} }
void DeduceTextureHandlerSize(std::vector<u32>&& bound_offsets);
private: private:
// Minimum size of texture handler any driver can use. // Minimum size of texture handler any driver can use.
static constexpr u32 min_texture_handler_size = 4; static constexpr u32 min_texture_handler_size = 4;
// This goes with Vulkan and OpenGL standards but Nvidia GPUs can easily // This goes with Vulkan and OpenGL standards but Nvidia GPUs can easily
// use 4 bytes instead. Thus, certain drivers may squish the size. // use 4 bytes instead. Thus, certain drivers may squish the size.
static constexpr u32 default_texture_handler_size = 8; static constexpr u32 default_texture_handler_size = 8;
u32 texture_handler_size{default_texture_handler_size}; u32 texture_handler_size = default_texture_handler_size;
bool texture_handler_size_deduced{}; bool texture_handler_size_deduced = false;
}; };
} // namespace VideoCore } // namespace VideoCore

View File

@ -80,10 +80,12 @@ public:
virtual void LoadDiskResources(const std::atomic_bool& stop_loading = false, virtual void LoadDiskResources(const std::atomic_bool& stop_loading = false,
const DiskResourceLoadCallback& callback = {}) {} const DiskResourceLoadCallback& callback = {}) {}
/// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
GuestDriverProfile& AccessGuestDriverProfile() { GuestDriverProfile& AccessGuestDriverProfile() {
return guest_driver_profile; return guest_driver_profile;
} }
/// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
const GuestDriverProfile& AccessGuestDriverProfile() const { const GuestDriverProfile& AccessGuestDriverProfile() const {
return guest_driver_profile; return guest_driver_profile;
} }

View File

@ -83,7 +83,7 @@ public:
VideoCore::GuestDriverProfile* AccessGuestDriverProfile() const { VideoCore::GuestDriverProfile* AccessGuestDriverProfile() const {
if (engine) { if (engine) {
return &(engine->AccessGuestDriverProfile()); return &engine->AccessGuestDriverProfile();
} }
return nullptr; return nullptr;
} }

View File

@ -33,6 +33,29 @@ constexpr bool IsSchedInstruction(u32 offset, u32 main_offset) {
return (absolute_offset % SchedPeriod) == 0; return (absolute_offset % SchedPeriod) == 0;
} }
void DeduceTextureHandlerSize(VideoCore::GuestDriverProfile* gpu_driver,
std::list<Sampler>& used_samplers) {
if (gpu_driver == nullptr) {
LOG_CRITICAL(HW_GPU, "GPU Driver profile has not been created yet");
return;
}
if (gpu_driver->TextureHandlerSizeKnown() || used_samplers.size() <= 1) {
return;
}
u32 count{};
std::vector<u32> bound_offsets;
for (const auto& sampler : used_samplers) {
if (sampler.IsBindless()) {
continue;
}
++count;
bound_offsets.emplace_back(sampler.GetOffset());
}
if (count > 1) {
gpu_driver->DeduceTextureHandlerSize(std::move(bound_offsets));
}
}
} // Anonymous namespace } // Anonymous namespace
class ASTDecoder { class ASTDecoder {
@ -315,32 +338,9 @@ u32 ShaderIR::DecodeInstr(NodeBlock& bb, u32 pc) {
return pc + 1; return pc + 1;
} }
void DeduceTextureHandlerSize(VideoCore::GuestDriverProfile* gpu_driver,
std::list<Sampler>& used_samplers) {
if (gpu_driver == nullptr) {
LOG_CRITICAL(HW_GPU, "GPU Driver profile has not been created yet");
return;
}
if (gpu_driver->TextureHandlerSizeKnown() || used_samplers.size() <= 1) {
return;
}
u32 count{};
std::vector<u32> bound_offsets;
for (const auto& sampler : used_samplers) {
if (sampler.IsBindless()) {
continue;
}
count++;
bound_offsets.emplace_back(sampler.GetOffset());
}
if (count > 1) {
gpu_driver->DeduceTextureHandlerSize(std::move(bound_offsets));
}
}
void ShaderIR::PostDecode() { void ShaderIR::PostDecode() {
// Deduce texture handler size if needed // Deduce texture handler size if needed
auto* gpu_driver = locker.AccessGuestDriverProfile(); auto gpu_driver = locker.AccessGuestDriverProfile();
DeduceTextureHandlerSize(gpu_driver, used_samplers); DeduceTextureHandlerSize(gpu_driver, used_samplers);
} }