Merge pull request #3282 from FernandoS27/indexed-samplers
Partially implement Indexed samplers in general and specific code in GLSL
This commit is contained in:
commit
b5bbe7e752
24 changed files with 610 additions and 58 deletions
|
@ -55,16 +55,20 @@ namespace {
|
|||
|
||||
template <typename Engine, typename Entry>
|
||||
Tegra::Texture::FullTextureInfo GetTextureInfo(const Engine& engine, const Entry& entry,
|
||||
Tegra::Engines::ShaderType shader_type) {
|
||||
Tegra::Engines::ShaderType shader_type,
|
||||
std::size_t index = 0) {
|
||||
if (entry.IsBindless()) {
|
||||
const Tegra::Texture::TextureHandle tex_handle =
|
||||
engine.AccessConstBuffer32(shader_type, entry.GetBuffer(), entry.GetOffset());
|
||||
return engine.GetTextureInfo(tex_handle);
|
||||
}
|
||||
const auto& gpu_profile = engine.AccessGuestDriverProfile();
|
||||
const u32 offset =
|
||||
entry.GetOffset() + static_cast<u32>(index * gpu_profile.GetTextureHandlerSize());
|
||||
if constexpr (std::is_same_v<Engine, Tegra::Engines::Maxwell3D>) {
|
||||
return engine.GetStageTexture(shader_type, entry.GetOffset());
|
||||
return engine.GetStageTexture(shader_type, offset);
|
||||
} else {
|
||||
return engine.GetTexture(entry.GetOffset());
|
||||
return engine.GetTexture(offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -942,8 +946,15 @@ void RasterizerOpenGL::SetupDrawTextures(std::size_t stage_index, const Shader&
|
|||
u32 binding = device.GetBaseBindings(stage_index).sampler;
|
||||
for (const auto& entry : shader->GetShaderEntries().samplers) {
|
||||
const auto shader_type = static_cast<Tegra::Engines::ShaderType>(stage_index);
|
||||
const auto texture = GetTextureInfo(maxwell3d, entry, shader_type);
|
||||
SetupTexture(binding++, texture, entry);
|
||||
if (!entry.IsIndexed()) {
|
||||
const auto texture = GetTextureInfo(maxwell3d, entry, shader_type);
|
||||
SetupTexture(binding++, texture, entry);
|
||||
} else {
|
||||
for (std::size_t i = 0; i < entry.Size(); ++i) {
|
||||
const auto texture = GetTextureInfo(maxwell3d, entry, shader_type, i);
|
||||
SetupTexture(binding++, texture, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -952,8 +963,17 @@ void RasterizerOpenGL::SetupComputeTextures(const Shader& kernel) {
|
|||
const auto& compute = system.GPU().KeplerCompute();
|
||||
u32 binding = 0;
|
||||
for (const auto& entry : kernel->GetShaderEntries().samplers) {
|
||||
const auto texture = GetTextureInfo(compute, entry, Tegra::Engines::ShaderType::Compute);
|
||||
SetupTexture(binding++, texture, entry);
|
||||
if (!entry.IsIndexed()) {
|
||||
const auto texture =
|
||||
GetTextureInfo(compute, entry, Tegra::Engines::ShaderType::Compute);
|
||||
SetupTexture(binding++, texture, entry);
|
||||
} else {
|
||||
for (std::size_t i = 0; i < entry.Size(); ++i) {
|
||||
const auto texture =
|
||||
GetTextureInfo(compute, entry, Tegra::Engines::ShaderType::Compute, i);
|
||||
SetupTexture(binding++, texture, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -214,6 +214,7 @@ std::unique_ptr<ConstBufferLocker> MakeLocker(Core::System& system, ShaderType s
|
|||
}
|
||||
|
||||
void FillLocker(ConstBufferLocker& locker, const ShaderDiskCacheUsage& usage) {
|
||||
locker.SetBoundBuffer(usage.bound_buffer);
|
||||
for (const auto& key : usage.keys) {
|
||||
const auto [buffer, offset] = key.first;
|
||||
locker.InsertKey(buffer, offset, key.second);
|
||||
|
@ -418,7 +419,8 @@ bool CachedShader::EnsureValidLockerVariant() {
|
|||
|
||||
ShaderDiskCacheUsage CachedShader::GetUsage(const ProgramVariant& variant,
|
||||
const ConstBufferLocker& locker) const {
|
||||
return ShaderDiskCacheUsage{unique_identifier, variant, locker.GetKeys(),
|
||||
return ShaderDiskCacheUsage{unique_identifier, variant,
|
||||
locker.GetBoundBuffer(), locker.GetKeys(),
|
||||
locker.GetBoundSamplers(), locker.GetBindlessSamplers()};
|
||||
}
|
||||
|
||||
|
|
|
@ -391,6 +391,7 @@ public:
|
|||
DeclareVertex();
|
||||
DeclareGeometry();
|
||||
DeclareRegisters();
|
||||
DeclareCustomVariables();
|
||||
DeclarePredicates();
|
||||
DeclareLocalMemory();
|
||||
DeclareInternalFlags();
|
||||
|
@ -503,6 +504,16 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void DeclareCustomVariables() {
|
||||
const u32 num_custom_variables = ir.GetNumCustomVariables();
|
||||
for (u32 i = 0; i < num_custom_variables; ++i) {
|
||||
code.AddLine("float {} = 0.0f;", GetCustomVariable(i));
|
||||
}
|
||||
if (num_custom_variables > 0) {
|
||||
code.AddNewLine();
|
||||
}
|
||||
}
|
||||
|
||||
void DeclarePredicates() {
|
||||
const auto& predicates = ir.GetPredicates();
|
||||
for (const auto pred : predicates) {
|
||||
|
@ -655,7 +666,8 @@ private:
|
|||
u32 binding = device.GetBaseBindings(stage).sampler;
|
||||
for (const auto& sampler : ir.GetSamplers()) {
|
||||
const std::string name = GetSampler(sampler);
|
||||
const std::string description = fmt::format("layout (binding = {}) uniform", binding++);
|
||||
const std::string description = fmt::format("layout (binding = {}) uniform", binding);
|
||||
binding += sampler.IsIndexed() ? sampler.Size() : 1;
|
||||
|
||||
std::string sampler_type = [&]() {
|
||||
if (sampler.IsBuffer()) {
|
||||
|
@ -682,7 +694,11 @@ private:
|
|||
sampler_type += "Shadow";
|
||||
}
|
||||
|
||||
code.AddLine("{} {} {};", description, sampler_type, name);
|
||||
if (!sampler.IsIndexed()) {
|
||||
code.AddLine("{} {} {};", description, sampler_type, name);
|
||||
} else {
|
||||
code.AddLine("{} {} {}[{}];", description, sampler_type, name, sampler.Size());
|
||||
}
|
||||
}
|
||||
if (!ir.GetSamplers().empty()) {
|
||||
code.AddNewLine();
|
||||
|
@ -775,6 +791,11 @@ private:
|
|||
return {GetRegister(index), Type::Float};
|
||||
}
|
||||
|
||||
if (const auto cv = std::get_if<CustomVarNode>(&*node)) {
|
||||
const u32 index = cv->GetIndex();
|
||||
return {GetCustomVariable(index), Type::Float};
|
||||
}
|
||||
|
||||
if (const auto immediate = std::get_if<ImmediateNode>(&*node)) {
|
||||
const u32 value = immediate->GetValue();
|
||||
if (value < 10) {
|
||||
|
@ -1098,7 +1119,11 @@ private:
|
|||
} else if (!meta->ptp.empty()) {
|
||||
expr += "Offsets";
|
||||
}
|
||||
expr += '(' + GetSampler(meta->sampler) + ", ";
|
||||
if (!meta->sampler.IsIndexed()) {
|
||||
expr += '(' + GetSampler(meta->sampler) + ", ";
|
||||
} else {
|
||||
expr += '(' + GetSampler(meta->sampler) + '[' + Visit(meta->index).AsUint() + "], ";
|
||||
}
|
||||
expr += coord_constructors.at(count + (has_array ? 1 : 0) +
|
||||
(has_shadow && !separate_dc ? 1 : 0) - 1);
|
||||
expr += '(';
|
||||
|
@ -1310,6 +1335,8 @@ private:
|
|||
const std::string final_offset = fmt::format("({} - {}) >> 2", real, base);
|
||||
target = {fmt::format("{}[{}]", GetGlobalMemory(gmem->GetDescriptor()), final_offset),
|
||||
Type::Uint};
|
||||
} else if (const auto cv = std::get_if<CustomVarNode>(&*dest)) {
|
||||
target = {GetCustomVariable(cv->GetIndex()), Type::Float};
|
||||
} else {
|
||||
UNREACHABLE_MSG("Assign called without a proper target");
|
||||
}
|
||||
|
@ -2237,6 +2264,10 @@ private:
|
|||
return GetDeclarationWithSuffix(index, "gpr");
|
||||
}
|
||||
|
||||
std::string GetCustomVariable(u32 index) const {
|
||||
return GetDeclarationWithSuffix(index, "custom_var");
|
||||
}
|
||||
|
||||
std::string GetPredicate(Tegra::Shader::Pred pred) const {
|
||||
return GetDeclarationWithSuffix(static_cast<u32>(pred), "pred");
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ struct BindlessSamplerKey {
|
|||
Tegra::Engines::SamplerDescriptor sampler{};
|
||||
};
|
||||
|
||||
constexpr u32 NativeVersion = 11;
|
||||
constexpr u32 NativeVersion = 12;
|
||||
|
||||
// Making sure sizes doesn't change by accident
|
||||
static_assert(sizeof(ProgramVariant) == 20);
|
||||
|
@ -186,7 +186,8 @@ ShaderDiskCacheOpenGL::LoadTransferable() {
|
|||
u32 num_bound_samplers{};
|
||||
u32 num_bindless_samplers{};
|
||||
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_bindless_samplers, 1) != 1) {
|
||||
LOG_ERROR(Render_OpenGL, error_loading);
|
||||
|
@ -281,7 +282,9 @@ ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) {
|
|||
u32 num_bindless_samplers{};
|
||||
ShaderDiskCacheUsage usage;
|
||||
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_bindless_samplers)) {
|
||||
return {};
|
||||
|
@ -393,6 +396,7 @@ void ShaderDiskCacheOpenGL::SaveUsage(const ShaderDiskCacheUsage& usage) {
|
|||
|
||||
if (file.WriteObject(TransferableEntryKind::Usage) != 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.bound_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) ||
|
||||
!SaveObjectToPrecompiled(usage.variant) ||
|
||||
!SaveObjectToPrecompiled(usage.variant) || !SaveObjectToPrecompiled(usage.bound_buffer) ||
|
||||
!SaveObjectToPrecompiled(static_cast<u32>(usage.keys.size())) ||
|
||||
!SaveObjectToPrecompiled(static_cast<u32>(usage.bound_samplers.size())) ||
|
||||
!SaveObjectToPrecompiled(static_cast<u32>(usage.bindless_samplers.size()))) {
|
||||
|
|
|
@ -79,6 +79,7 @@ static_assert(std::is_trivially_copyable_v<ProgramVariant>);
|
|||
struct ShaderDiskCacheUsage {
|
||||
u64 unique_identifier{};
|
||||
ProgramVariant variant;
|
||||
u32 bound_buffer{};
|
||||
VideoCommon::Shader::KeyMap keys;
|
||||
VideoCommon::Shader::BoundSamplerMap bound_samplers;
|
||||
VideoCommon::Shader::BindlessSamplerMap bindless_samplers;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue