summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp28
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h15
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.cpp27
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.h101
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp4
-rw-r--r--src/video_core/renderer_opengl/maxwell_to_gl.h5
6 files changed, 144 insertions, 36 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 56d9c575b..a1c47bae9 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -5,6 +5,7 @@
#include <algorithm>
#include <memory>
#include <string>
+#include <string_view>
#include <tuple>
#include <utility>
#include <glad/glad.h>
@@ -37,11 +38,6 @@ MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255));
MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100));
RasterizerOpenGL::RasterizerOpenGL() {
- has_ARB_buffer_storage = false;
- has_ARB_direct_state_access = false;
- has_ARB_separate_shader_objects = false;
- has_ARB_vertex_attrib_binding = false;
-
// Create sampler objects
for (size_t i = 0; i < texture_samplers.size(); ++i) {
texture_samplers[i].Create();
@@ -59,7 +55,8 @@ RasterizerOpenGL::RasterizerOpenGL() {
GLint ext_num;
glGetIntegerv(GL_NUM_EXTENSIONS, &ext_num);
for (GLint i = 0; i < ext_num; i++) {
- std::string extension{reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i))};
+ const std::string_view extension{
+ reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i))};
if (extension == "GL_ARB_buffer_storage") {
has_ARB_buffer_storage = true;
@@ -110,8 +107,6 @@ RasterizerOpenGL::RasterizerOpenGL() {
glBindBufferBase(GL_UNIFORM_BUFFER, index, buffer.handle);
}
- accelerate_draw = AccelDraw::Disabled;
-
glEnable(GL_BLEND);
LOG_CRITICAL(Render_OpenGL, "Sync fixed function OpenGL state here!");
@@ -601,7 +596,6 @@ void RasterizerOpenGL::SamplerInfo::Create() {
sampler.Create();
mag_filter = min_filter = Tegra::Texture::TextureFilter::Linear;
wrap_u = wrap_v = Tegra::Texture::WrapMode::Wrap;
- border_color_r = border_color_g = border_color_b = border_color_a = 0;
// default is GL_LINEAR_MIPMAP_LINEAR
glSamplerParameteri(sampler.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -630,8 +624,12 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntr
}
if (wrap_u == Tegra::Texture::WrapMode::Border || wrap_v == Tegra::Texture::WrapMode::Border) {
- // TODO(Subv): Implement border color
- ASSERT(false);
+ const GLvec4 new_border_color = {{config.border_color_r, config.border_color_g,
+ config.border_color_b, config.border_color_a}};
+ if (border_color != new_border_color) {
+ border_color = new_border_color;
+ glSamplerParameterfv(s, GL_TEXTURE_BORDER_COLOR, border_color.data());
+ }
}
}
@@ -691,10 +689,12 @@ u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint progr
glBindBuffer(GL_UNIFORM_BUFFER, 0);
// Now configure the bindpoint of the buffer inside the shader
- std::string buffer_name = used_buffer.GetName();
- GLuint index = glGetProgramResourceIndex(program, GL_UNIFORM_BLOCK, buffer_name.c_str());
- if (index != -1)
+ const std::string buffer_name = used_buffer.GetName();
+ const GLuint index =
+ glGetProgramResourceIndex(program, GL_UNIFORM_BLOCK, buffer_name.c_str());
+ if (index != GL_INVALID_INDEX) {
glUniformBlockBinding(program, index, buffer_draw_state.bindpoint);
+ }
}
state.Apply();
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index c406142e4..e150be58f 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -77,10 +77,7 @@ private:
Tegra::Texture::TextureFilter min_filter;
Tegra::Texture::WrapMode wrap_u;
Tegra::Texture::WrapMode wrap_v;
- u32 border_color_r;
- u32 border_color_g;
- u32 border_color_b;
- u32 border_color_a;
+ GLvec4 border_color;
};
/// Configures the color and depth framebuffer states and returns the dirty <Color, Depth>
@@ -138,10 +135,10 @@ private:
/// Syncs the blend state to match the guest state
void SyncBlendState();
- bool has_ARB_buffer_storage;
- bool has_ARB_direct_state_access;
- bool has_ARB_separate_shader_objects;
- bool has_ARB_vertex_attrib_binding;
+ bool has_ARB_buffer_storage = false;
+ bool has_ARB_direct_state_access = false;
+ bool has_ARB_separate_shader_objects = false;
+ bool has_ARB_vertex_attrib_binding = false;
OpenGLState state;
@@ -170,5 +167,5 @@ private:
void SetupShaders(u8* buffer_ptr, GLintptr buffer_offset);
enum class AccelDraw { Disabled, Arrays, Indexed };
- AccelDraw accelerate_draw;
+ AccelDraw accelerate_draw = AccelDraw::Disabled;
};
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
index 28f0bc379..91ce0357b 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
@@ -38,7 +38,8 @@ struct FormatTuple {
params.addr = config.tic.Address();
params.is_tiled = config.tic.IsTiled();
params.block_height = params.is_tiled ? config.tic.BlockHeight() : 0,
- params.pixel_format = PixelFormatFromTextureFormat(config.tic.format);
+ params.pixel_format =
+ PixelFormatFromTextureFormat(config.tic.format, config.tic.r_type.Value());
params.component_type = ComponentTypeFromTexture(config.tic.r_type.Value());
params.type = GetFormatType(params.pixel_format);
params.width = Common::AlignUp(config.tic.Width(), GetCompressionFactor(params.pixel_format));
@@ -106,6 +107,12 @@ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_form
true}, // BC7U
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_4X4
{GL_RG8, GL_RG, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // G8R8
+ {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // BGRA8
+ {GL_RGBA32F, GL_RGBA, GL_FLOAT, ComponentType::Float, false}, // RGBA32F
+ {GL_RG32F, GL_RG, GL_FLOAT, ComponentType::Float, false}, // RG32F
+ {GL_R32F, GL_RED, GL_FLOAT, ComponentType::Float, false}, // R32F
+ {GL_R16F, GL_RED, GL_HALF_FLOAT, ComponentType::Float, false}, // R16F
+ {GL_R16, GL_RED, GL_UNSIGNED_SHORT, ComponentType::UNorm, false}, // R16UNORM
// DepthStencil formats
{GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, ComponentType::UNorm,
@@ -115,6 +122,8 @@ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_form
{GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, ComponentType::Float, false}, // Z32F
{GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, ComponentType::UNorm,
false}, // Z16
+ {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
+ ComponentType::Float, false}, // Z32FS8
}};
static const FormatTuple& GetFormatTuple(PixelFormat pixel_format, ComponentType component_type) {
@@ -197,9 +206,12 @@ static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr),
MortonCopy<true, PixelFormat::DXT1>, MortonCopy<true, PixelFormat::DXT23>,
MortonCopy<true, PixelFormat::DXT45>, MortonCopy<true, PixelFormat::DXN1>,
MortonCopy<true, PixelFormat::BC7U>, MortonCopy<true, PixelFormat::ASTC_2D_4X4>,
- MortonCopy<true, PixelFormat::G8R8>, MortonCopy<true, PixelFormat::Z24S8>,
+ MortonCopy<true, PixelFormat::G8R8>, MortonCopy<true, PixelFormat::BGRA8>,
+ MortonCopy<true, PixelFormat::RGBA32F>, MortonCopy<true, PixelFormat::RG32F>,
+ MortonCopy<true, PixelFormat::R32F>, MortonCopy<true, PixelFormat::R16F>,
+ MortonCopy<true, PixelFormat::R16UNORM>, MortonCopy<true, PixelFormat::Z24S8>,
MortonCopy<true, PixelFormat::S8Z24>, MortonCopy<true, PixelFormat::Z32F>,
- MortonCopy<true, PixelFormat::Z16>,
+ MortonCopy<true, PixelFormat::Z16>, MortonCopy<true, PixelFormat::Z32FS8>,
};
static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr),
@@ -213,7 +225,7 @@ static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr),
MortonCopy<false, PixelFormat::RGBA16F>,
MortonCopy<false, PixelFormat::R11FG11FB10F>,
MortonCopy<false, PixelFormat::RGBA32UI>,
- // TODO(Subv): Swizzling the DXT1/DXT23/DXT45/DXN1/BC7U formats is not yet supported
+ // TODO(Subv): Swizzling DXT1/DXT23/DXT45/DXN1/BC7U/ASTC_2D_4X4 formats is not supported
nullptr,
nullptr,
nullptr,
@@ -221,10 +233,17 @@ static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr),
nullptr,
nullptr,
MortonCopy<false, PixelFormat::G8R8>,
+ MortonCopy<false, PixelFormat::BGRA8>,
+ MortonCopy<false, PixelFormat::RGBA32F>,
+ MortonCopy<false, PixelFormat::RG32F>,
+ MortonCopy<false, PixelFormat::R32F>,
+ MortonCopy<false, PixelFormat::R16F>,
+ MortonCopy<false, PixelFormat::R16UNORM>,
MortonCopy<false, PixelFormat::Z24S8>,
MortonCopy<false, PixelFormat::S8Z24>,
MortonCopy<false, PixelFormat::Z32F>,
MortonCopy<false, PixelFormat::Z16>,
+ MortonCopy<false, PixelFormat::Z32FS8>,
};
// Allocate an uninitialized texture of appropriate size and format for the surface
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
index b084c4db4..fc864c56f 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
@@ -37,14 +37,21 @@ struct SurfaceParams {
BC7U = 12,
ASTC_2D_4X4 = 13,
G8R8 = 14,
+ BGRA8 = 15,
+ RGBA32F = 16,
+ RG32F = 17,
+ R32F = 18,
+ R16F = 19,
+ R16UNORM = 20,
MaxColorFormat,
// DepthStencil formats
- Z24S8 = 15,
- S8Z24 = 16,
- Z32F = 17,
- Z16 = 18,
+ Z24S8 = 21,
+ S8Z24 = 22,
+ Z32F = 23,
+ Z16 = 24,
+ Z32FS8 = 25,
MaxDepthStencilFormat,
@@ -97,10 +104,17 @@ struct SurfaceParams {
4, // BC7U
4, // ASTC_2D_4X4
1, // G8R8
+ 1, // BGRA8
+ 1, // RGBA32F
+ 1, // RG32F
+ 1, // R32F
+ 1, // R16F
+ 1, // R16UNORM
1, // Z24S8
1, // S8Z24
1, // Z32F
1, // Z16
+ 1, // Z32FS8
}};
ASSERT(static_cast<size_t>(format) < compression_factor_table.size());
@@ -127,10 +141,17 @@ struct SurfaceParams {
128, // BC7U
32, // ASTC_2D_4X4
16, // G8R8
+ 32, // BGRA8
+ 128, // RGBA32F
+ 64, // RG32F
+ 32, // R32F
+ 16, // R16F
+ 16, // R16UNORM
32, // Z24S8
32, // S8Z24
32, // Z32F
16, // Z16
+ 64, // Z32FS8
}};
ASSERT(static_cast<size_t>(format) < bpp_table.size());
@@ -151,6 +172,8 @@ struct SurfaceParams {
return PixelFormat::Z32F;
case Tegra::DepthFormat::Z16_UNORM:
return PixelFormat::Z16;
+ case Tegra::DepthFormat::Z32_S8_X24_FLOAT:
+ return PixelFormat::Z32FS8;
default:
LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
UNREACHABLE();
@@ -162,21 +185,30 @@ struct SurfaceParams {
case Tegra::RenderTargetFormat::RGBA8_UNORM:
case Tegra::RenderTargetFormat::RGBA8_SRGB:
return PixelFormat::ABGR8;
+ case Tegra::RenderTargetFormat::BGRA8_UNORM:
+ return PixelFormat::BGRA8;
case Tegra::RenderTargetFormat::RGB10_A2_UNORM:
return PixelFormat::A2B10G10R10;
case Tegra::RenderTargetFormat::RGBA16_FLOAT:
return PixelFormat::RGBA16F;
+ case Tegra::RenderTargetFormat::RGBA32_FLOAT:
+ return PixelFormat::RGBA32F;
+ case Tegra::RenderTargetFormat::RG32_FLOAT:
+ return PixelFormat::RG32F;
case Tegra::RenderTargetFormat::R11G11B10_FLOAT:
return PixelFormat::R11FG11FB10F;
case Tegra::RenderTargetFormat::RGBA32_UINT:
return PixelFormat::RGBA32UI;
+ case Tegra::RenderTargetFormat::R8_UNORM:
+ return PixelFormat::R8;
default:
LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
UNREACHABLE();
}
}
- static PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format) {
+ static PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format,
+ Tegra::Texture::ComponentType component_type) {
// TODO(Subv): Properly implement this
switch (format) {
case Tegra::Texture::TextureFormat::A8R8G8B8:
@@ -196,7 +228,33 @@ struct SurfaceParams {
case Tegra::Texture::TextureFormat::BF10GF11RF11:
return PixelFormat::R11FG11FB10F;
case Tegra::Texture::TextureFormat::R32_G32_B32_A32:
- return PixelFormat::RGBA32UI;
+ switch (component_type) {
+ case Tegra::Texture::ComponentType::FLOAT:
+ return PixelFormat::RGBA32F;
+ case Tegra::Texture::ComponentType::UINT:
+ return PixelFormat::RGBA32UI;
+ }
+ LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
+ static_cast<u32>(component_type));
+ UNREACHABLE();
+ case Tegra::Texture::TextureFormat::R32_G32:
+ return PixelFormat::RG32F;
+ case Tegra::Texture::TextureFormat::R16:
+ switch (component_type) {
+ case Tegra::Texture::ComponentType::FLOAT:
+ return PixelFormat::R16F;
+ case Tegra::Texture::ComponentType::UNORM:
+ return PixelFormat::R16UNORM;
+ }
+ LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
+ static_cast<u32>(component_type));
+ UNREACHABLE();
+ case Tegra::Texture::TextureFormat::R32:
+ return PixelFormat::R32F;
+ case Tegra::Texture::TextureFormat::ZF32:
+ return PixelFormat::Z32F;
+ case Tegra::Texture::TextureFormat::Z24S8:
+ return PixelFormat::Z24S8;
case Tegra::Texture::TextureFormat::DXT1:
return PixelFormat::DXT1;
case Tegra::Texture::TextureFormat::DXT23:
@@ -210,7 +268,8 @@ struct SurfaceParams {
case Tegra::Texture::TextureFormat::ASTC_2D_4X4:
return PixelFormat::ASTC_2D_4X4;
default:
- LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
+ LOG_CRITICAL(HW_GPU, "Unimplemented format={}, component_type={}",
+ static_cast<u32>(format), static_cast<u32>(component_type));
UNREACHABLE();
}
}
@@ -248,7 +307,25 @@ struct SurfaceParams {
return Tegra::Texture::TextureFormat::BC7U;
case PixelFormat::ASTC_2D_4X4:
return Tegra::Texture::TextureFormat::ASTC_2D_4X4;
+ case PixelFormat::BGRA8:
+ // TODO(bunnei): This is fine for unswizzling (since we just need the right component
+ // sizes), but could be a bug if we used this function in different ways.
+ return Tegra::Texture::TextureFormat::A8R8G8B8;
+ case PixelFormat::RGBA32F:
+ return Tegra::Texture::TextureFormat::R32_G32_B32_A32;
+ case PixelFormat::RG32F:
+ return Tegra::Texture::TextureFormat::R32_G32;
+ case PixelFormat::R32F:
+ return Tegra::Texture::TextureFormat::R32;
+ case PixelFormat::R16F:
+ case PixelFormat::R16UNORM:
+ return Tegra::Texture::TextureFormat::R16;
+ case PixelFormat::Z32F:
+ return Tegra::Texture::TextureFormat::ZF32;
+ case PixelFormat::Z24S8:
+ return Tegra::Texture::TextureFormat::Z24S8;
default:
+ LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
UNREACHABLE();
}
}
@@ -263,7 +340,10 @@ struct SurfaceParams {
return Tegra::DepthFormat::Z32_FLOAT;
case PixelFormat::Z16:
return Tegra::DepthFormat::Z16_UNORM;
+ case PixelFormat::Z32FS8:
+ return Tegra::DepthFormat::Z32_S8_X24_FLOAT;
default:
+ LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
UNREACHABLE();
}
}
@@ -273,6 +353,8 @@ struct SurfaceParams {
switch (type) {
case Tegra::Texture::ComponentType::UNORM:
return ComponentType::UNorm;
+ case Tegra::Texture::ComponentType::FLOAT:
+ return ComponentType::Float;
default:
LOG_CRITICAL(HW_GPU, "Unimplemented component type={}", static_cast<u32>(type));
UNREACHABLE();
@@ -284,10 +366,14 @@ struct SurfaceParams {
switch (format) {
case Tegra::RenderTargetFormat::RGBA8_UNORM:
case Tegra::RenderTargetFormat::RGBA8_SRGB:
+ case Tegra::RenderTargetFormat::BGRA8_UNORM:
case Tegra::RenderTargetFormat::RGB10_A2_UNORM:
+ case Tegra::RenderTargetFormat::R8_UNORM:
return ComponentType::UNorm;
case Tegra::RenderTargetFormat::RGBA16_FLOAT:
case Tegra::RenderTargetFormat::R11G11B10_FLOAT:
+ case Tegra::RenderTargetFormat::RGBA32_FLOAT:
+ case Tegra::RenderTargetFormat::RG32_FLOAT:
return ComponentType::Float;
case Tegra::RenderTargetFormat::RGBA32_UINT:
return ComponentType::UInt;
@@ -314,6 +400,7 @@ struct SurfaceParams {
case Tegra::DepthFormat::Z24_S8_UNORM:
return ComponentType::UNorm;
case Tegra::DepthFormat::Z32_FLOAT:
+ case Tegra::DepthFormat::Z32_S8_X24_FLOAT:
return ComponentType::Float;
default:
LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index d4b1a6f33..acf067050 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -756,8 +756,8 @@ private:
}
}
- std::string WriteTexsInstruction(const Instruction& instr, const std::string& coord,
- const std::string& texture) {
+ void WriteTexsInstruction(const Instruction& instr, const std::string& coord,
+ const std::string& texture) {
// Add an extra scope and declare the texture coords inside to prevent
// overwriting them in case they are used as outputs of the texs instruction.
shader.AddLine('{');
diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h
index e19c3b280..16b1bd606 100644
--- a/src/video_core/renderer_opengl/maxwell_to_gl.h
+++ b/src/video_core/renderer_opengl/maxwell_to_gl.h
@@ -56,6 +56,9 @@ inline GLenum VertexType(Maxwell::VertexAttribute attrib) {
return {};
}
+ case Maxwell::VertexAttribute::Type::UnsignedInt:
+ return GL_UNSIGNED_INT;
+
case Maxwell::VertexAttribute::Type::Float:
return GL_FLOAT;
}
@@ -112,6 +115,8 @@ inline GLenum WrapMode(Tegra::Texture::WrapMode wrap_mode) {
return GL_MIRRORED_REPEAT;
case Tegra::Texture::WrapMode::ClampToEdge:
return GL_CLAMP_TO_EDGE;
+ case Tegra::Texture::WrapMode::Border:
+ return GL_CLAMP_TO_BORDER;
case Tegra::Texture::WrapMode::ClampOGL:
// TODO(Subv): GL_CLAMP was removed as of OpenGL 3.1, to implement GL_CLAMP, we can use
// GL_CLAMP_TO_BORDER to get the border color of the texture, and then sample the edge to