Browse Source

Shader_IR: Address Feedback

nce_cpp
Fernando Sahmkow 6 years ago
committed by FernandoS27
parent
commit
c0c5fa078b
  1. 9
      src/video_core/guest_driver.cpp
  2. 11
      src/video_core/guest_driver.h
  3. 2
      src/video_core/rasterizer_interface.h
  4. 2
      src/video_core/shader/const_buffer_locker.h
  5. 48
      src/video_core/shader/decode.cpp

9
src/video_core/guest_driver.cpp

@ -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(),
[](const u32& a, const u32& b) { return a < b; });
u32 min_val = UINT_MAX;
for (std::size_t i = 1; i < size; i++) {
std::sort(bound_offsets.begin(), bound_offsets.end(), std::less{});
u32 min_val = std::numeric_limits<u32>::max();
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;
} }

11
src/video_core/guest_driver.h

@ -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};
bool texture_handler_size_deduced{};
u32 texture_handler_size = default_texture_handler_size;
bool texture_handler_size_deduced = false;
}; };
} // namespace VideoCore } // namespace VideoCore

2
src/video_core/rasterizer_interface.h

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

2
src/video_core/shader/const_buffer_locker.h

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

48
src/video_core/shader/decode.cpp

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

Loading…
Cancel
Save