Shader_IR: Store Bound buffer on Shader Usage

This commit is contained in:
Fernando Sahmkow 2020-01-03 18:15:24 -04:00 committed by FernandoS27
parent c921e496eb
commit 1e4b6bef6f
5 changed files with 41 additions and 5 deletions

View file

@ -214,6 +214,7 @@ std::unique_ptr<ConstBufferLocker> MakeLocker(Core::System& system, ShaderType s
} }
void FillLocker(ConstBufferLocker& locker, const ShaderDiskCacheUsage& usage) { void FillLocker(ConstBufferLocker& locker, const ShaderDiskCacheUsage& usage) {
locker.SetBoundBuffer(usage.bound_buffer);
for (const auto& key : usage.keys) { for (const auto& key : usage.keys) {
const auto [buffer, offset] = key.first; const auto [buffer, offset] = key.first;
locker.InsertKey(buffer, offset, key.second); locker.InsertKey(buffer, offset, key.second);
@ -418,7 +419,8 @@ bool CachedShader::EnsureValidLockerVariant() {
ShaderDiskCacheUsage CachedShader::GetUsage(const ProgramVariant& variant, ShaderDiskCacheUsage CachedShader::GetUsage(const ProgramVariant& variant,
const ConstBufferLocker& locker) const { const ConstBufferLocker& locker) const {
return ShaderDiskCacheUsage{unique_identifier, variant, locker.GetKeys(), return ShaderDiskCacheUsage{unique_identifier, variant,
locker.GetBoundBuffer(), locker.GetKeys(),
locker.GetBoundSamplers(), locker.GetBindlessSamplers()}; locker.GetBoundSamplers(), locker.GetBindlessSamplers()};
} }

View file

@ -53,7 +53,7 @@ struct BindlessSamplerKey {
Tegra::Engines::SamplerDescriptor sampler{}; Tegra::Engines::SamplerDescriptor sampler{};
}; };
constexpr u32 NativeVersion = 11; constexpr u32 NativeVersion = 12;
// Making sure sizes doesn't change by accident // Making sure sizes doesn't change by accident
static_assert(sizeof(ProgramVariant) == 20); static_assert(sizeof(ProgramVariant) == 20);
@ -186,7 +186,8 @@ ShaderDiskCacheOpenGL::LoadTransferable() {
u32 num_bound_samplers{}; u32 num_bound_samplers{};
u32 num_bindless_samplers{}; u32 num_bindless_samplers{};
if (file.ReadArray(&usage.unique_identifier, 1) != 1 || if (file.ReadArray(&usage.unique_identifier, 1) != 1 ||
file.ReadArray(&usage.variant, 1) != 1 || file.ReadArray(&num_keys, 1) != 1 || file.ReadArray(&usage.variant, 1) != 1 ||
file.ReadArray(&usage.bound_buffer, 1) != 1 || file.ReadArray(&num_keys, 1) != 1 ||
file.ReadArray(&num_bound_samplers, 1) != 1 || file.ReadArray(&num_bound_samplers, 1) != 1 ||
file.ReadArray(&num_bindless_samplers, 1) != 1) { file.ReadArray(&num_bindless_samplers, 1) != 1) {
LOG_ERROR(Render_OpenGL, error_loading); LOG_ERROR(Render_OpenGL, error_loading);
@ -281,7 +282,9 @@ ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) {
u32 num_bindless_samplers{}; u32 num_bindless_samplers{};
ShaderDiskCacheUsage usage; ShaderDiskCacheUsage usage;
if (!LoadObjectFromPrecompiled(usage.unique_identifier) || if (!LoadObjectFromPrecompiled(usage.unique_identifier) ||
!LoadObjectFromPrecompiled(usage.variant) || !LoadObjectFromPrecompiled(num_keys) || !LoadObjectFromPrecompiled(usage.variant) ||
!LoadObjectFromPrecompiled(usage.bound_buffer) ||
!LoadObjectFromPrecompiled(num_keys) ||
!LoadObjectFromPrecompiled(num_bound_samplers) || !LoadObjectFromPrecompiled(num_bound_samplers) ||
!LoadObjectFromPrecompiled(num_bindless_samplers)) { !LoadObjectFromPrecompiled(num_bindless_samplers)) {
return {}; return {};
@ -393,6 +396,7 @@ void ShaderDiskCacheOpenGL::SaveUsage(const ShaderDiskCacheUsage& usage) {
if (file.WriteObject(TransferableEntryKind::Usage) != 1 || if (file.WriteObject(TransferableEntryKind::Usage) != 1 ||
file.WriteObject(usage.unique_identifier) != 1 || file.WriteObject(usage.variant) != 1 || file.WriteObject(usage.unique_identifier) != 1 || file.WriteObject(usage.variant) != 1 ||
file.WriteObject(usage.bound_buffer) != 1 ||
file.WriteObject(static_cast<u32>(usage.keys.size())) != 1 || file.WriteObject(static_cast<u32>(usage.keys.size())) != 1 ||
file.WriteObject(static_cast<u32>(usage.bound_samplers.size())) != 1 || file.WriteObject(static_cast<u32>(usage.bound_samplers.size())) != 1 ||
file.WriteObject(static_cast<u32>(usage.bindless_samplers.size())) != 1) { file.WriteObject(static_cast<u32>(usage.bindless_samplers.size())) != 1) {
@ -447,7 +451,7 @@ void ShaderDiskCacheOpenGL::SaveDump(const ShaderDiskCacheUsage& usage, GLuint p
}; };
if (!SaveObjectToPrecompiled(usage.unique_identifier) || if (!SaveObjectToPrecompiled(usage.unique_identifier) ||
!SaveObjectToPrecompiled(usage.variant) || !SaveObjectToPrecompiled(usage.variant) || !SaveObjectToPrecompiled(usage.bound_buffer) ||
!SaveObjectToPrecompiled(static_cast<u32>(usage.keys.size())) || !SaveObjectToPrecompiled(static_cast<u32>(usage.keys.size())) ||
!SaveObjectToPrecompiled(static_cast<u32>(usage.bound_samplers.size())) || !SaveObjectToPrecompiled(static_cast<u32>(usage.bound_samplers.size())) ||
!SaveObjectToPrecompiled(static_cast<u32>(usage.bindless_samplers.size()))) { !SaveObjectToPrecompiled(static_cast<u32>(usage.bindless_samplers.size()))) {

View file

@ -79,6 +79,7 @@ static_assert(std::is_trivially_copyable_v<ProgramVariant>);
struct ShaderDiskCacheUsage { struct ShaderDiskCacheUsage {
u64 unique_identifier{}; u64 unique_identifier{};
ProgramVariant variant; ProgramVariant variant;
u32 bound_buffer{};
VideoCommon::Shader::KeyMap keys; VideoCommon::Shader::KeyMap keys;
VideoCommon::Shader::BoundSamplerMap bound_samplers; VideoCommon::Shader::BoundSamplerMap bound_samplers;
VideoCommon::Shader::BindlessSamplerMap bindless_samplers; VideoCommon::Shader::BindlessSamplerMap bindless_samplers;

View file

@ -66,6 +66,18 @@ std::optional<Tegra::Engines::SamplerDescriptor> ConstBufferLocker::ObtainBindle
return value; return value;
} }
std::optional<u32> ConstBufferLocker::ObtainBoundBuffer() {
if (bound_buffer_saved) {
return bound_buffer;
}
if (!engine) {
return std::nullopt;
}
bound_buffer_saved = true;
bound_buffer = engine->GetBoundBuffer();
return bound_buffer;
}
void ConstBufferLocker::InsertKey(u32 buffer, u32 offset, u32 value) { void ConstBufferLocker::InsertKey(u32 buffer, u32 offset, u32 value) {
keys.insert_or_assign({buffer, offset}, value); keys.insert_or_assign({buffer, offset}, value);
} }
@ -78,6 +90,11 @@ void ConstBufferLocker::InsertBindlessSampler(u32 buffer, u32 offset, SamplerDes
bindless_samplers.insert_or_assign({buffer, offset}, sampler); bindless_samplers.insert_or_assign({buffer, offset}, sampler);
} }
void ConstBufferLocker::SetBoundBuffer(u32 buffer) {
bound_buffer_saved = true;
bound_buffer = buffer;
}
bool ConstBufferLocker::IsConsistent() const { bool ConstBufferLocker::IsConsistent() const {
if (!engine) { if (!engine) {
return false; return false;

View file

@ -41,6 +41,8 @@ public:
std::optional<Tegra::Engines::SamplerDescriptor> ObtainBindlessSampler(u32 buffer, u32 offset); std::optional<Tegra::Engines::SamplerDescriptor> ObtainBindlessSampler(u32 buffer, u32 offset);
std::optional<u32> ObtainBoundBuffer();
/// Inserts a key. /// Inserts a key.
void InsertKey(u32 buffer, u32 offset, u32 value); void InsertKey(u32 buffer, u32 offset, u32 value);
@ -50,6 +52,10 @@ public:
/// Inserts a bindless sampler key. /// Inserts a bindless sampler key.
void InsertBindlessSampler(u32 buffer, u32 offset, Tegra::Engines::SamplerDescriptor sampler); void InsertBindlessSampler(u32 buffer, u32 offset, Tegra::Engines::SamplerDescriptor sampler);
/// Set the bound buffer for this locker.
void SetBoundBuffer(u32 buffer);
/// Checks keys and samplers against engine's current const buffers. Returns true if they are /// Checks keys and samplers against engine's current const buffers. Returns true if they are
/// the same value, false otherwise; /// the same value, false otherwise;
bool IsConsistent() const; bool IsConsistent() const;
@ -72,6 +78,10 @@ public:
return bindless_samplers; return bindless_samplers;
} }
u32 GetBoundBuffer() const {
return bound_buffer;
}
VideoCore::GuestDriverProfile* AccessGuestDriverProfile() { VideoCore::GuestDriverProfile* AccessGuestDriverProfile() {
if (engine) { if (engine) {
return &(engine->AccessGuestDriverProfile()); return &(engine->AccessGuestDriverProfile());
@ -85,6 +95,8 @@ private:
KeyMap keys; KeyMap keys;
BoundSamplerMap bound_samplers; BoundSamplerMap bound_samplers;
BindlessSamplerMap bindless_samplers; BindlessSamplerMap bindless_samplers;
bool bound_buffer_saved{};
u32 bound_buffer{};
}; };
} // namespace VideoCommon::Shader } // namespace VideoCommon::Shader