2018-04-07 11:12:38 +02:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/hle/kernel/process.h"
|
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
|
|
|
|
|
|
|
namespace GLShader {
|
|
|
|
|
|
|
|
namespace Impl {
|
2018-07-21 00:01:49 +02:00
|
|
|
static void SetShaderUniformBlockBinding(GLuint shader, const char* name,
|
|
|
|
Maxwell3D::Regs::ShaderStage binding,
|
|
|
|
size_t expected_size) {
|
2018-08-04 08:57:08 +02:00
|
|
|
const GLuint ub_index = glGetUniformBlockIndex(shader, name);
|
|
|
|
if (ub_index == GL_INVALID_INDEX) {
|
|
|
|
return;
|
2018-04-07 11:12:38 +02:00
|
|
|
}
|
2018-08-04 08:57:08 +02:00
|
|
|
|
|
|
|
GLint ub_size = 0;
|
|
|
|
glGetActiveUniformBlockiv(shader, ub_index, GL_UNIFORM_BLOCK_DATA_SIZE, &ub_size);
|
|
|
|
ASSERT_MSG(static_cast<size_t>(ub_size) == expected_size,
|
|
|
|
"Uniform block size did not match! Got {}, expected {}", ub_size, expected_size);
|
|
|
|
glUniformBlockBinding(shader, ub_index, static_cast<GLuint>(binding));
|
2018-04-07 11:12:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetShaderUniformBlockBindings(GLuint shader) {
|
2018-04-08 05:45:09 +02:00
|
|
|
SetShaderUniformBlockBinding(shader, "vs_config", Maxwell3D::Regs::ShaderStage::Vertex,
|
|
|
|
sizeof(MaxwellUniformData));
|
|
|
|
SetShaderUniformBlockBinding(shader, "gs_config", Maxwell3D::Regs::ShaderStage::Geometry,
|
|
|
|
sizeof(MaxwellUniformData));
|
|
|
|
SetShaderUniformBlockBinding(shader, "fs_config", Maxwell3D::Regs::ShaderStage::Fragment,
|
|
|
|
sizeof(MaxwellUniformData));
|
2018-04-07 11:12:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Impl
|
|
|
|
|
2018-04-18 22:42:40 +02:00
|
|
|
void MaxwellUniformData::SetFromRegs(const Maxwell3D::State::ShaderStageInfo& shader_stage) {
|
2018-08-12 02:21:31 +02:00
|
|
|
const auto& gpu = Core::System::GetInstance().GPU().Maxwell3D();
|
|
|
|
const auto& regs = gpu.regs;
|
|
|
|
const auto& state = gpu.state;
|
2018-04-18 22:42:40 +02:00
|
|
|
|
|
|
|
// TODO(bunnei): Support more than one viewport
|
2018-06-20 18:39:10 +02:00
|
|
|
viewport_flip[0] = regs.viewport_transform[0].scale_x < 0.0 ? -1.0f : 1.0f;
|
|
|
|
viewport_flip[1] = regs.viewport_transform[0].scale_y < 0.0 ? -1.0f : 1.0f;
|
2018-08-12 02:21:31 +02:00
|
|
|
|
|
|
|
// We only assign the instance to the first component of the vector, the rest is just padding.
|
|
|
|
instance_id[0] = state.current_instance;
|
2018-04-18 22:42:40 +02:00
|
|
|
}
|
2018-04-07 11:12:38 +02:00
|
|
|
|
|
|
|
} // namespace GLShader
|