forked from ShuriZma/suyu
1
0
Fork 0

GL Backend: Introduce indexed samplers into the GL backend

This commit is contained in:
Fernando Sahmkow 2020-01-06 11:43:13 -04:00 committed by FernandoS27
parent 037ea431ce
commit 2b02f29a2d
2 changed files with 39 additions and 10 deletions

View File

@ -55,16 +55,20 @@ namespace {
template <typename Engine, typename Entry> template <typename Engine, typename Entry>
Tegra::Texture::FullTextureInfo GetTextureInfo(const Engine& engine, const Entry& 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()) { if (entry.IsBindless()) {
const Tegra::Texture::TextureHandle tex_handle = const Tegra::Texture::TextureHandle tex_handle =
engine.AccessConstBuffer32(shader_type, entry.GetBuffer(), entry.GetOffset()); engine.AccessConstBuffer32(shader_type, entry.GetBuffer(), entry.GetOffset());
return engine.GetTextureInfo(tex_handle); 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>) { if constexpr (std::is_same_v<Engine, Tegra::Engines::Maxwell3D>) {
return engine.GetStageTexture(shader_type, entry.GetOffset()); return engine.GetStageTexture(shader_type, offset);
} else { } 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; u32 binding = device.GetBaseBindings(stage_index).sampler;
for (const auto& entry : shader->GetShaderEntries().samplers) { for (const auto& entry : shader->GetShaderEntries().samplers) {
const auto shader_type = static_cast<Tegra::Engines::ShaderType>(stage_index); const auto shader_type = static_cast<Tegra::Engines::ShaderType>(stage_index);
const auto texture = GetTextureInfo(maxwell3d, entry, shader_type); if (!entry.IsIndexed()) {
SetupTexture(binding++, texture, entry); 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(); const auto& compute = system.GPU().KeplerCompute();
u32 binding = 0; u32 binding = 0;
for (const auto& entry : kernel->GetShaderEntries().samplers) { for (const auto& entry : kernel->GetShaderEntries().samplers) {
const auto texture = GetTextureInfo(compute, entry, Tegra::Engines::ShaderType::Compute); if (!entry.IsIndexed()) {
SetupTexture(binding++, texture, entry); 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);
}
}
} }
} }

View File

@ -655,7 +655,8 @@ private:
u32 binding = device.GetBaseBindings(stage).sampler; u32 binding = device.GetBaseBindings(stage).sampler;
for (const auto& sampler : ir.GetSamplers()) { for (const auto& sampler : ir.GetSamplers()) {
const std::string name = GetSampler(sampler); 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 = [&]() { std::string sampler_type = [&]() {
if (sampler.IsBuffer()) { if (sampler.IsBuffer()) {
@ -682,7 +683,11 @@ private:
sampler_type += "Shadow"; 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()) { if (!ir.GetSamplers().empty()) {
code.AddNewLine(); code.AddNewLine();
@ -1099,7 +1104,11 @@ private:
} else if (!meta->ptp.empty()) { } else if (!meta->ptp.empty()) {
expr += "Offsets"; expr += "Offsets";
} }
expr += '(' + GetSampler(meta->sampler) + ", "; if (!meta->sampler.IsIndexed()) {
expr += '(' + GetSampler(meta->sampler) + ", ";
} else {
expr += '(' + GetSampler(meta->sampler) + "[0], ";
}
expr += coord_constructors.at(count + (has_array ? 1 : 0) + expr += coord_constructors.at(count + (has_array ? 1 : 0) +
(has_shadow && !separate_dc ? 1 : 0) - 1); (has_shadow && !separate_dc ? 1 : 0) - 1);
expr += '('; expr += '(';