gl_rasterizer: Minor style changes

This commit is contained in:
ReinUsesLisp 2019-07-05 23:11:58 -03:00
parent 9cdc576f60
commit 7ecf64257a
4 changed files with 22 additions and 32 deletions

View File

@ -67,6 +67,7 @@ public:
static constexpr std::size_t MaxShaderStage = 5; static constexpr std::size_t MaxShaderStage = 5;
// Maximum number of const buffers per shader stage. // Maximum number of const buffers per shader stage.
static constexpr std::size_t MaxConstBuffers = 18; static constexpr std::size_t MaxConstBuffers = 18;
static constexpr std::size_t MaxConstBufferSize = 0x10000;
enum class QueryMode : u32 { enum class QueryMode : u32 {
Write = 0, Write = 0,

View File

@ -81,6 +81,21 @@ struct DrawParameters {
} }
}; };
static std::size_t GetConstBufferSize(const Tegra::Engines::ConstBufferInfo& buffer,
const GLShader::ConstBufferEntry& entry) {
if (!entry.IsIndirect()) {
return entry.GetSize();
}
if (buffer.size > Maxwell::MaxConstBufferSize) {
LOG_WARNING(Render_OpenGL, "Indirect constbuffer size {} exceeds maximum {}", buffer.size,
Maxwell::MaxConstBufferSize);
return Maxwell::MaxConstBufferSize;
}
return buffer.size;
}
RasterizerOpenGL::RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWindow& emu_window, RasterizerOpenGL::RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWindow& emu_window,
ScreenInfo& info) ScreenInfo& info)
: texture_cache{system, *this, device}, shader_cache{*this, system, emu_window, device}, : texture_cache{system, *this, device}, shader_cache{*this, system, emu_window, device},
@ -634,8 +649,8 @@ void RasterizerOpenGL::DrawArrays() {
Maxwell::MaxShaderStage; Maxwell::MaxShaderStage;
// Add space for at least 18 constant buffers // Add space for at least 18 constant buffers
buffer_size += buffer_size += Maxwell::MaxConstBuffers *
Maxwell::MaxConstBuffers * (MaxConstbufferSize + device.GetUniformBufferAlignment()); (Maxwell::MaxConstBufferSize + device.GetUniformBufferAlignment());
// Prepare the vertex array. // Prepare the vertex array.
buffer_cache.Map(buffer_size); buffer_cache.Map(buffer_size);
@ -762,11 +777,9 @@ void RasterizerOpenGL::SetupDrawConstBuffers(Tegra::Engines::Maxwell3D::Regs::Sh
MICROPROFILE_SCOPE(OpenGL_UBO); MICROPROFILE_SCOPE(OpenGL_UBO);
const auto stage_index = static_cast<std::size_t>(stage); const auto stage_index = static_cast<std::size_t>(stage);
const auto& shader_stage = system.GPU().Maxwell3D().state.shader_stages[stage_index]; const auto& shader_stage = system.GPU().Maxwell3D().state.shader_stages[stage_index];
const auto& entries = shader->GetShaderEntries().const_buffers;
// Upload only the enabled buffers from the 16 constbuffers of each shader stage // Upload only the enabled buffers from the 16 constbuffers of each shader stage
for (u32 bindpoint = 0; bindpoint < entries.size(); ++bindpoint) { for (const auto& entry : shader->GetShaderEntries().const_buffers) {
const auto& entry = entries[bindpoint];
SetupConstBuffer(shader_stage.const_buffers[entry.GetIndex()], entry); SetupConstBuffer(shader_stage.const_buffers[entry.GetIndex()], entry);
} }
} }
@ -779,25 +792,9 @@ void RasterizerOpenGL::SetupConstBuffer(const Tegra::Engines::ConstBufferInfo& b
return; return;
} }
std::size_t size;
if (entry.IsIndirect()) {
// Buffer is accessed indirectly, so upload the entire thing
size = buffer.size;
if (size > MaxConstbufferSize) {
LOG_WARNING(Render_OpenGL, "Indirect constbuffer size {} exceeds maximum {}", size,
MaxConstbufferSize);
size = MaxConstbufferSize;
}
} else {
// Buffer is accessed directly, upload just what we use
size = entry.GetSize();
}
// Align the actual size so it ends up being a multiple of vec4 to meet the OpenGL std140 // Align the actual size so it ends up being a multiple of vec4 to meet the OpenGL std140
// UBO alignment requirements. // UBO alignment requirements.
size = Common::AlignUp(size, sizeof(GLvec4)); const std::size_t size = Common::AlignUp(GetConstBufferSize(buffer, entry), sizeof(GLvec4));
ASSERT_MSG(size <= MaxConstbufferSize, "Constant buffer is too big");
const auto alignment = device.GetUniformBufferAlignment(); const auto alignment = device.GetUniformBufferAlignment();
const auto [cbuf, offset] = buffer_cache.UploadMemory(buffer.address, size, alignment); const auto [cbuf, offset] = buffer_cache.UploadMemory(buffer.address, size, alignment);
@ -811,10 +808,7 @@ void RasterizerOpenGL::SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::Shade
const auto cbufs{gpu.Maxwell3D().state.shader_stages[static_cast<std::size_t>(stage)]}; const auto cbufs{gpu.Maxwell3D().state.shader_stages[static_cast<std::size_t>(stage)]};
const auto alignment{device.GetShaderStorageBufferAlignment()}; const auto alignment{device.GetShaderStorageBufferAlignment()};
const auto& entries = shader->GetShaderEntries().global_memory_entries; for (const auto& entry : shader->GetShaderEntries().global_memory_entries) {
for (std::size_t bindpoint = 0; bindpoint < entries.size(); ++bindpoint) {
const auto& entry{entries[bindpoint]};
const auto addr{cbufs.const_buffers[entry.GetCbufIndex()].address + entry.GetCbufOffset()}; const auto addr{cbufs.const_buffers[entry.GetCbufIndex()].address + entry.GetCbufOffset()};
const auto actual_addr{memory_manager.Read<u64>(addr)}; const auto actual_addr{memory_manager.Read<u64>(addr)};
const auto size{memory_manager.Read<u32>(addr + 8)}; const auto size{memory_manager.Read<u32>(addr + 8)};

View File

@ -73,11 +73,6 @@ public:
void LoadDiskResources(const std::atomic_bool& stop_loading, void LoadDiskResources(const std::atomic_bool& stop_loading,
const VideoCore::DiskResourceLoadCallback& callback) override; const VideoCore::DiskResourceLoadCallback& callback) override;
/// Maximum supported size that a constbuffer can have in bytes.
static constexpr std::size_t MaxConstbufferSize = 0x10000;
static_assert(MaxConstbufferSize % sizeof(GLvec4) == 0,
"The maximum size of a constbuffer must be a multiple of the size of GLvec4");
private: private:
struct FramebufferConfigState { struct FramebufferConfigState {
bool using_color_fb{}; bool using_color_fb{};

View File

@ -46,7 +46,7 @@ using TextureArgument = std::pair<Type, Node>;
using TextureIR = std::variant<TextureAoffi, TextureArgument>; using TextureIR = std::variant<TextureAoffi, TextureArgument>;
constexpr u32 MAX_CONSTBUFFER_ELEMENTS = constexpr u32 MAX_CONSTBUFFER_ELEMENTS =
static_cast<u32>(RasterizerOpenGL::MaxConstbufferSize) / (4 * sizeof(float)); static_cast<u32>(Maxwell::MaxConstBufferSize) / (4 * sizeof(float));
class ShaderWriter { class ShaderWriter {
public: public: