using glTexStorage2D/glTexSubImage2D instead of glTexImage2D

Minor improvements
This commit is contained in:
DHrpcs3 2016-03-07 16:39:52 +03:00
parent c365004776
commit 8e57cf8da8
7 changed files with 178 additions and 90 deletions

View File

@ -389,8 +389,8 @@ void GLGSRender::end()
int location; int location;
if (m_program->uniforms.has_location("tex" + std::to_string(i), &location)) if (m_program->uniforms.has_location("tex" + std::to_string(i), &location))
{ {
rsx::gl_texture::bind(m_texture_cache, i, textures[i]); __glcheck rsx::gl_texture::bind(m_texture_cache, i, textures[i]);
glProgramUniform1i(m_program->id(), location, i); __glcheck glProgramUniform1i(m_program->id(), location, i);
} }
} }
@ -464,9 +464,9 @@ void GLGSRender::end()
if (!vertex_info.size) // disabled, bind a null sampler if (!vertex_info.size) // disabled, bind a null sampler
{ {
glActiveTexture(GL_TEXTURE0 + index + rsx::limits::textures_count); __glcheck glActiveTexture(GL_TEXTURE0 + index + rsx::limits::textures_count);
glBindTexture(GL_TEXTURE_BUFFER, NULL); __glcheck glBindTexture(GL_TEXTURE_BUFFER, NULL);
glProgramUniform1i(m_program->id(), location, index + rsx::limits::textures_count); __glcheck glProgramUniform1i(m_program->id(), location, index + rsx::limits::textures_count);
continue; continue;
} }
@ -500,14 +500,13 @@ void GLGSRender::end()
dst += element_size; dst += element_size;
} }
buffer->data(data_size, nullptr); buffer.data(data_size, vertex_arrays_data.data());
buffer->sub_data(0, data_size, vertex_arrays_data.data());
//Attach buffer to texture //Attach buffer to texture
texture->copy_from(*buffer, gl_type); texture.copy_from(buffer, gl_type);
//Link texture to uniform //Link texture to uniform
m_program->uniforms.texture(location, index + rsx::limits::textures_count, *texture); m_program->uniforms.texture(location, index + rsx::limits::textures_count, texture);
} }
} }
@ -577,17 +576,19 @@ void GLGSRender::end()
u32 gl_type = to_gl_internal_type(vertex_info.type, vertex_info.size); u32 gl_type = to_gl_internal_type(vertex_info.type, vertex_info.size);
u32 data_size = element_size * vertex_draw_count; u32 data_size = element_size * vertex_draw_count;
auto &buffer = m_gl_attrib_buffers[index].buffer; auto& attrib_pair = m_gl_attrib_buffers[index];
auto &texture = m_gl_attrib_buffers[index].texture;
buffer->data(data_size, nullptr); __glcheck 0;
buffer->sub_data(0, data_size, vertex_array.data());
attrib_pair.buffer.data(data_size, vertex_array.data());
__glcheck 0;
//Attach buffer to texture //Attach buffer to texture
texture->copy_from(*buffer, gl_type); attrib_pair.texture.copy_from(attrib_pair.buffer, gl_type);
//Link texture to uniform //Link texture to uniform
m_program->uniforms.texture(location, index + rsx::limits::textures_count, *texture); m_program->uniforms.texture(location, index + rsx::limits::textures_count, attrib_pair.texture);
} }
else if (register_vertex_info[index].size > 0) else if (register_vertex_info[index].size > 0)
{ {
@ -603,17 +604,15 @@ void GLGSRender::end()
const u32 gl_type = to_gl_internal_type(vertex_info.type, vertex_info.size); const u32 gl_type = to_gl_internal_type(vertex_info.type, vertex_info.size);
const size_t data_size = vertex_data.size(); const size_t data_size = vertex_data.size();
auto &buffer = m_gl_attrib_buffers[index].buffer; auto& attrib_pair = m_gl_attrib_buffers[index];
auto &texture = m_gl_attrib_buffers[index].texture;
buffer->data(data_size, nullptr); attrib_pair.buffer.data(data_size, vertex_data.data());
buffer->sub_data(0, data_size, vertex_data.data());
//Attach buffer to texture //Attach buffer to texture
texture->copy_from(*buffer, gl_type); attrib_pair.texture.copy_from(attrib_pair.buffer, gl_type);
//Link texture to uniform //Link texture to uniform
m_program->uniforms.texture(location, index + rsx::limits::textures_count, *texture); m_program->uniforms.texture(location, index + rsx::limits::textures_count, attrib_pair.texture);
break; break;
} }
default: default:
@ -731,16 +730,10 @@ void GLGSRender::on_init_thread()
m_vao.array_buffer = m_vbo; m_vao.array_buffer = m_vbo;
m_vao.element_array_buffer = m_ebo; m_vao.element_array_buffer = m_ebo;
for (texture_buffer_pair &attrib_buffer : m_gl_attrib_buffers) for (texture_buffer_pair &pair : m_gl_attrib_buffers)
{ {
gl::texture *&tex = attrib_buffer.texture; pair.texture.create(gl::texture::target::texture_buffer);
tex = new gl::texture(gl::texture::target::texture_buffer); pair.buffer.create();
tex->create();
tex->set_target(gl::texture::target::texture_buffer);
gl::buffer *&buf = attrib_buffer.buffer;
buf = new gl::buffer();
buf->create();
} }
} }
@ -783,17 +776,10 @@ void GLGSRender::on_exit()
if (m_fragment_constants_buffer) if (m_fragment_constants_buffer)
m_fragment_constants_buffer.remove(); m_fragment_constants_buffer.remove();
for (texture_buffer_pair &attrib_buffer : m_gl_attrib_buffers) for (texture_buffer_pair &pair : m_gl_attrib_buffers)
{ {
gl::texture *&tex = attrib_buffer.texture; pair.buffer.remove();
tex->remove(); pair.texture.remove();
delete tex;
tex = nullptr;
gl::buffer *&buf = attrib_buffer.buffer;
buf->remove();
delete buf;
buf = nullptr;
} }
} }
@ -1200,7 +1186,7 @@ void GLGSRender::init_buffers(bool skip_reading)
info.format.bpp = 2; info.format.bpp = 2;
info.format.flags = gl::texture_flags::swap_bytes; info.format.flags = gl::texture_flags::swap_bytes;
info.format.type = gl::texture::type::ushort; info.format.type = gl::texture::type::ushort;
info.format.internal_format = gl::texture::internal_format::depth16; info.format.internal_format = gl::texture::sized_internal_format::depth16;
info.format.format = gl::texture::format::depth; info.format.format = gl::texture::format::depth;
break; break;
@ -1208,7 +1194,7 @@ void GLGSRender::init_buffers(bool skip_reading)
info.format.bpp = 4; info.format.bpp = 4;
info.format.flags = gl::texture_flags::swap_bytes; info.format.flags = gl::texture_flags::swap_bytes;
info.format.type = gl::texture::type::uint_24_8; info.format.type = gl::texture::type::uint_24_8;
info.format.internal_format = gl::texture::internal_format::depth24_stencil8; info.format.internal_format = gl::texture::sized_internal_format::depth24_stencil8;
info.format.format = gl::texture::format::depth_stencil; info.format.format = gl::texture::format::depth_stencil;
break; break;
@ -1337,6 +1323,8 @@ bool GLGSRender::on_access_violation(u32 address, bool is_writing)
{ {
if (auto region = m_texture_cache.find_region(address)) if (auto region = m_texture_cache.find_region(address))
{ {
std::lock_guard<gl::protected_region> lock(*region);
if (is_writing) if (is_writing)
{ {
const bool accurate_cache = true; const bool accurate_cache = true;

View File

@ -10,6 +10,12 @@
#pragma comment(lib, "opengl32.lib") #pragma comment(lib, "opengl32.lib")
struct texture_buffer_pair
{
gl::texture texture;
gl::buffer buffer;
};
class GLGSRender : public GSRender class GLGSRender : public GSRender
{ {
private: private:
@ -20,12 +26,7 @@ private:
rsx::surface_info m_surface; rsx::surface_info m_surface;
struct texture_buffer_pair texture_buffer_pair m_gl_attrib_buffers[rsx::limits::vertex_count];
{
gl::texture *texture;
gl::buffer *buffer;
}
m_gl_attrib_buffers[rsx::limits::vertex_count];
gl::texture_cache m_texture_cache; gl::texture_cache m_texture_cache;

View File

@ -170,6 +170,10 @@ OPENGL_PROC(PFNGLBINDBUFFERBASEPROC, BindBufferBase);
OPENGL_PROC(PFNGLTEXBUFFERPROC, TexBuffer); OPENGL_PROC(PFNGLTEXBUFFERPROC, TexBuffer);
OPENGL_PROC(PFNGLTEXTUREBUFFERRANGEEXTPROC, TextureBufferRangeEXT); OPENGL_PROC(PFNGLTEXTUREBUFFERRANGEEXTPROC, TextureBufferRangeEXT);
OPENGL_PROC(PFNGLTEXSTORAGE1DPROC, TexStorage1D);
OPENGL_PROC(PFNGLTEXSTORAGE2DPROC, TexStorage2D);
OPENGL_PROC(PFNGLTEXSTORAGE3DPROC, TexStorage3D);
//ARB_Copy_Image //ARB_Copy_Image
OPENGL_PROC(PFNGLCOPYIMAGESUBDATAPROC, CopyImageSubData); OPENGL_PROC(PFNGLCOPYIMAGESUBDATAPROC, CopyImageSubData);

View File

@ -15,7 +15,7 @@
namespace gl namespace gl
{ {
#ifdef _DEBUG #if 1//def _DEBUG
struct __glcheck_impl_t struct __glcheck_impl_t
{ {
const char* file; const char* file;
@ -777,7 +777,7 @@ namespace gl
depth_stencil = GL_DEPTH_STENCIL depth_stencil = GL_DEPTH_STENCIL
}; };
enum class internal_format enum class internal_format : GLenum
{ {
red = GL_RED, red = GL_RED,
r = GL_R, r = GL_R,
@ -802,6 +802,69 @@ namespace gl
compressed_rgba_s3tc_dxt5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT compressed_rgba_s3tc_dxt5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
}; };
enum class sized_internal_format : GLenum
{
r8 = GL_R8,
r8_snorm = GL_R8_SNORM,
r16f = GL_R16F,
r32f = GL_R32F,
r8ui = GL_R8UI,
r8i = GL_R8I,
r16ui = GL_R16UI,
r16i = GL_R16I,
r32ui = GL_R32UI,
r32i = GL_R32I,
rg8 = GL_RG8,
rg8_snorm = GL_RG8_SNORM,
rg16f = GL_RG16F,
rg32f = GL_RG32F,
rg8ui = GL_RG8UI,
rg8i = GL_RG8I,
rg16ui = GL_RG16UI,
rg16i = GL_RG16I,
rg32ui = GL_RG32UI,
rg32i = GL_RG32I,
rgb8 = GL_RGB8,
srgb8 = GL_SRGB8,
rgb565 = GL_RGB565,
rgb8_snorm = GL_RGB8_SNORM,
r11f_g11f_b10f = GL_R11F_G11F_B10F,
rgb9_e5 = GL_RGB9_E5,
rgb16f = GL_RGB16F,
rgb32f = GL_RGB32F,
rgb8ui = GL_RGB8UI,
rgb8i = GL_RGB8I,
rgb16ui = GL_RGB16UI,
rgb16i = GL_RGB16I,
rgb32ui = GL_RGB32UI,
rgb32i = GL_RGB32I,
rgba8 = GL_RGBA8,
srgb8_alpha8 = GL_SRGB8_ALPHA8,
rgba8_snorm = GL_RGBA8_SNORM,
rgb5_a1 = GL_RGB5_A1,
rgba4 = GL_RGBA4,
rgb10_a2 = GL_RGB10_A2,
rgba16f = GL_RGBA16F,
rgba32f = GL_RGBA32F,
rgba8ui = GL_RGBA8UI,
rgba8i = GL_RGBA8I,
rgb10_a2ui = GL_RGB10_A2UI,
rgba16ui = GL_RGBA16UI,
rgba16i = GL_RGBA16I,
rgba32i = GL_RGBA32I,
rgba32ui = GL_RGBA32UI,
stencil8 = GL_STENCIL_INDEX8,
depth16 = GL_DEPTH_COMPONENT16,
depth24 = GL_DEPTH_COMPONENT24,
depth24_stencil8 = GL_DEPTH24_STENCIL8,
compressed_rgb_s3tc_dxt1 = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
compressed_rgba_s3tc_dxt1 = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
compressed_rgba_s3tc_dxt3 = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
compressed_rgba_s3tc_dxt5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
};
enum class wrap enum class wrap
{ {
repeat = GL_REPEAT, repeat = GL_REPEAT,
@ -877,7 +940,7 @@ namespace gl
case target::texture_rectangle: pname = GL_TEXTURE_BINDING_RECTANGLE; break; case target::texture_rectangle: pname = GL_TEXTURE_BINDING_RECTANGLE; break;
} }
glGetIntegerv(pname, &m_last_binding); __glcheck glGetIntegerv(pname, &m_last_binding);
new_binding.bind(); new_binding.bind();
m_target = (GLenum)new_binding.get_target(); m_target = (GLenum)new_binding.get_target();
@ -885,7 +948,7 @@ namespace gl
~save_binding_state() noexcept ~save_binding_state() noexcept
{ {
glBindTexture(m_target, m_last_binding); __glcheck glBindTexture(m_target, m_last_binding);
} }
}; };

View File

@ -68,7 +68,7 @@ namespace gl
{ {
LOG_WARNING(RSX, "cached_texture at 0x%x: reading compressed texture from host buffer", info->start_address); LOG_WARNING(RSX, "cached_texture at 0x%x: reading compressed texture from host buffer", info->start_address);
glCompressedTexImage2D((GLenum)info->target, 0, __glcheck glCompressedTexImage2D((GLenum)info->target, 0,
(GLenum)info->format.internal_format, (GLenum)info->format.internal_format,
info->width, info->height, info->width, info->height,
0, 0,
@ -84,7 +84,7 @@ namespace gl
.swap_bytes((info->format.flags & gl::texture_flags::swap_bytes) != gl::texture_flags::none) .swap_bytes((info->format.flags & gl::texture_flags::swap_bytes) != gl::texture_flags::none)
.apply(); .apply();
glTexImage2D((GLenum)info->target, 0, (GLenum)info->format.internal_format, info->width, info->height, 0, __glcheck glTexSubImage2D((GLenum)info->target, 0, 0, 0, info->width, info->height,
(GLenum)info->format.format, (GLenum)info->format.type, vm::base_priv(info->start_address)); (GLenum)info->format.format, (GLenum)info->format.type, vm::base_priv(info->start_address));
} }
} }
@ -228,14 +228,24 @@ namespace gl
return cache_access::none; return cache_access::none;
} }
void cached_texture::lock()
{
m_parent_region->lock();
}
void cached_texture::unlock()
{
m_parent_region->unlock();
}
void cached_texture::bind(uint index) const void cached_texture::bind(uint index) const
{ {
if (index != ~0u) if (index != ~0u)
{ {
glActiveTexture(GL_TEXTURE0 + index); __glcheck glActiveTexture(GL_TEXTURE0 + index);
} }
glBindTexture((GLenum)info->target, gl_name); __glcheck glBindTexture((GLenum)info->target, gl_name);
} }
void cached_texture::create() void cached_texture::create()
@ -243,9 +253,12 @@ namespace gl
assert(!created()); assert(!created());
glGenTextures(1, &gl_name); glGenTextures(1, &gl_name);
bind();
glTexImage2D((GLenum)info->target, 0, (GLenum)info->format.internal_format, info->width, info->height, 0, if (!info->compressed_size)
(GLenum)info->format.format, (GLenum)info->format.type, nullptr); {
bind();
__glcheck glTexStorage2D((GLenum)info->target, 1, (GLenum)info->format.internal_format, info->width, info->height);
}
} }
void cached_texture::remove() void cached_texture::remove()
@ -385,7 +398,7 @@ namespace gl
cached_texture& protected_region::add(const texture_info& info) cached_texture& protected_region::add(const texture_info& info)
{ {
LOG_WARNING(RSX, "new texture in cache at 0x%x", info.start_address); LOG_WARNING(RSX, "new texture in cache at 0x%x", info.start_address);
auto &result = m_textures.emplace(info, cached_texture{}); const auto &result = m_textures.emplace(info, cached_texture{});
if (!result.second) if (!result.second)
{ {
@ -424,7 +437,17 @@ namespace gl
m_textures.clear(); m_textures.clear();
} }
cached_texture &texture_cache::entry(texture_info &info, cache_buffers sync) void protected_region::lock()
{
m_mtx.lock();
}
void protected_region::unlock()
{
m_mtx.unlock();
}
cached_texture &texture_cache::entry(const texture_info &info, cache_buffers sync)
{ {
u32 aligned_address = info.start_address & ~(vm::page_size - 1); u32 aligned_address = info.start_address & ~(vm::page_size - 1);
u32 aligned_size = align(info.size(), vm::page_size); u32 aligned_size = align(info.size(), vm::page_size);

View File

@ -46,7 +46,7 @@ namespace gl
{ {
u8 bpp; u8 bpp;
std::array<GLint, 4> remap; std::array<GLint, 4> remap;
texture::internal_format internal_format; texture::sized_internal_format internal_format;
texture::format format; texture::format format;
texture::type type; texture::type type;
texture_flags flags; texture_flags flags;
@ -104,6 +104,9 @@ namespace gl
cache_access requires_protection() const; cache_access requires_protection() const;
void lock();
void unlock();
protected: protected:
void create(); void create();
void remove(); void remove();
@ -121,6 +124,7 @@ namespace gl
std::unordered_map<texture_info, cached_texture, fnv_1a_hasher, bitwise_equals> m_textures; std::unordered_map<texture_info, cached_texture, fnv_1a_hasher, bitwise_equals> m_textures;
u32 m_current_protection = 0; u32 m_current_protection = 0;
std::mutex m_mtx;
public: public:
u32 size() const u32 size() const
@ -142,6 +146,9 @@ namespace gl
cached_texture& add(const texture_info& info); cached_texture& add(const texture_info& info);
void clear(); void clear();
void lock();
void unlock();
}; };
class texture_cache class texture_cache
@ -149,7 +156,7 @@ namespace gl
std::map<u32, protected_region> m_protected_regions; std::map<u32, protected_region> m_protected_regions;
public: public:
cached_texture &entry(texture_info &info, cache_buffers sync = cache_buffers::none); cached_texture &entry(const texture_info &info, cache_buffers sync = cache_buffers::none);
protected_region *find_region(u32 address); protected_region *find_region(u32 address);
std::vector<protected_region*> find_regions(u32 address, u32 size); std::vector<protected_region*> find_regions(u32 address, u32 size);
void update_protection(); void update_protection();

View File

@ -9,7 +9,7 @@
#include "gl_texture_cache.h" #include "gl_texture_cache.h"
const std::array<GLint, 4> default_remap{ GL_ALPHA, GL_RED, GL_GREEN, GL_BLUE }; const std::array<GLint, 4> default_remap{ GL_ALPHA, GL_RED, GL_GREEN, GL_BLUE };
const std::array<GLint, 4> remap_B8{ GL_BLUE, GL_BLUE, GL_BLUE, GL_BLUE }; const std::array<GLint, 4> remap_B8{ GL_RED, GL_RED, GL_RED, GL_RED };
const std::array<GLint, 4> remap_G8B8{ GL_RED, GL_GREEN, GL_RED, GL_GREEN }; const std::array<GLint, 4> remap_G8B8{ GL_RED, GL_GREEN, GL_RED, GL_GREEN };
const std::array<GLint, 4> remap_R6G5B5{ GL_ALPHA, GL_GREEN, GL_RED, GL_BLUE }; const std::array<GLint, 4> remap_R6G5B5{ GL_ALPHA, GL_GREEN, GL_RED, GL_BLUE };
const std::array<GLint, 4> remap_X16{ GL_RED, GL_ONE, GL_RED, GL_ONE }; const std::array<GLint, 4> remap_X16{ GL_RED, GL_ONE, GL_RED, GL_ONE };
@ -22,26 +22,26 @@ const std::array<GLint, 4> remap_Y16_X16_FLOAT{ GL_RED, GL_GREEN, GL_RED, GL_GRE
const std::unordered_map<u32, gl::texture_format> textures_fromats const std::unordered_map<u32, gl::texture_format> textures_fromats
{ {
{ CELL_GCM_TEXTURE_B8,{ 1, remap_B8, gl::texture::internal_format::rgba, gl::texture::format::blue, gl::texture::type::ubyte, gl::texture_flags::none } }, { CELL_GCM_TEXTURE_B8,{ 1, remap_B8, gl::texture::sized_internal_format::r8, gl::texture::format::red, gl::texture::type::ubyte, gl::texture_flags::none } },
{ CELL_GCM_TEXTURE_A1R5G5B5,{ 2, default_remap, gl::texture::internal_format::rgba, gl::texture::format::bgra, gl::texture::type::ushort_5_5_5_1, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } }, { CELL_GCM_TEXTURE_A1R5G5B5,{ 2, default_remap, gl::texture::sized_internal_format::rgb5_a1, gl::texture::format::bgra, gl::texture::type::ushort_5_5_5_1, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } },
{ CELL_GCM_TEXTURE_A4R4G4B4,{ 2, default_remap, gl::texture::internal_format::rgba, gl::texture::format::bgra, gl::texture::type::ushort_4_4_4_4, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } }, { CELL_GCM_TEXTURE_A4R4G4B4,{ 2, default_remap, gl::texture::sized_internal_format::rgba4, gl::texture::format::bgra, gl::texture::type::ushort_4_4_4_4, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } },
{ CELL_GCM_TEXTURE_R5G6B5,{ 2, default_remap, gl::texture::internal_format::rgb, gl::texture::format::bgr, gl::texture::type::ushort_5_6_5, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } }, { CELL_GCM_TEXTURE_R5G6B5,{ 2, default_remap, gl::texture::sized_internal_format::rgb565, gl::texture::format::bgr, gl::texture::type::ushort_5_6_5, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } },
{ CELL_GCM_TEXTURE_A8R8G8B8,{ 4, default_remap, gl::texture::internal_format::rgba, gl::texture::format::bgra, gl::texture::type::uint_8_8_8_8, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } }, { CELL_GCM_TEXTURE_A8R8G8B8,{ 4, default_remap, gl::texture::sized_internal_format::rgba8, gl::texture::format::bgra, gl::texture::type::uint_8_8_8_8, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } },
{ CELL_GCM_TEXTURE_G8B8,{ 2, remap_G8B8, gl::texture::internal_format::rgba, gl::texture::format::rg, gl::texture::type::ubyte, gl::texture_flags::allow_remap } }, { CELL_GCM_TEXTURE_G8B8,{ 2, remap_G8B8, gl::texture::sized_internal_format::rg8, gl::texture::format::rg, gl::texture::type::ubyte, gl::texture_flags::allow_remap } },
{ CELL_GCM_TEXTURE_R6G5B5,{ 2, remap_R6G5B5, gl::texture::internal_format::rgba, gl::texture::format::bgr, gl::texture::type::ushort_5_6_5, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } }, { CELL_GCM_TEXTURE_R6G5B5,{ 2, remap_R6G5B5, gl::texture::sized_internal_format::rgb565, gl::texture::format::bgr, gl::texture::type::ushort_5_6_5, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } },
{ CELL_GCM_TEXTURE_DEPTH24_D8,{ 4, default_remap, gl::texture::internal_format::depth24, gl::texture::format::depth, gl::texture::type::uint_8_8_8_8_rev, gl::texture_flags::allow_remap } }, { CELL_GCM_TEXTURE_DEPTH24_D8,{ 4, default_remap, gl::texture::sized_internal_format::depth24, gl::texture::format::depth, gl::texture::type::uint_8_8_8_8_rev, gl::texture_flags::allow_remap } },
{ CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT,{ 4, default_remap, gl::texture::internal_format::depth24, gl::texture::format::depth, gl::texture::type::f32, gl::texture_flags::allow_remap } }, { CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT,{ 4, default_remap, gl::texture::sized_internal_format::depth24, gl::texture::format::depth, gl::texture::type::f32, gl::texture_flags::allow_remap } },
{ CELL_GCM_TEXTURE_DEPTH16,{ 2, default_remap, gl::texture::internal_format::depth16, gl::texture::format::depth, gl::texture::type::ushort, gl::texture_flags::allow_remap } }, { CELL_GCM_TEXTURE_DEPTH16,{ 2, default_remap, gl::texture::sized_internal_format::depth16, gl::texture::format::depth, gl::texture::type::ushort, gl::texture_flags::allow_remap } },
{ CELL_GCM_TEXTURE_DEPTH16_FLOAT,{ 2, default_remap, gl::texture::internal_format::depth16, gl::texture::format::depth, gl::texture::type::f32, gl::texture_flags::allow_remap } }, { CELL_GCM_TEXTURE_DEPTH16_FLOAT,{ 2, default_remap, gl::texture::sized_internal_format::depth16, gl::texture::format::depth, gl::texture::type::f32, gl::texture_flags::allow_remap } },
{ CELL_GCM_TEXTURE_X16,{ 2, remap_X16, gl::texture::internal_format::rgba, gl::texture::format::red, gl::texture::type::ushort, gl::texture_flags::swap_bytes } }, { CELL_GCM_TEXTURE_X16,{ 2, remap_X16, gl::texture::sized_internal_format::r16ui, gl::texture::format::red, gl::texture::type::ushort, gl::texture_flags::swap_bytes } },
{ CELL_GCM_TEXTURE_Y16_X16,{ 4, remap_Y16_X16, gl::texture::internal_format::rgba, gl::texture::format::rg, gl::texture::type::ushort, gl::texture_flags::allow_remap | gl::texture_flags::swap_bytes } }, { CELL_GCM_TEXTURE_Y16_X16,{ 4, remap_Y16_X16, gl::texture::sized_internal_format::rg16ui, gl::texture::format::rg, gl::texture::type::ushort, gl::texture_flags::allow_remap | gl::texture_flags::swap_bytes } },
{ CELL_GCM_TEXTURE_R5G5B5A1,{ 2, default_remap, gl::texture::internal_format::rgba, gl::texture::format::rgba, gl::texture::type::ushort_5_5_5_1, gl::texture_flags::allow_remap | gl::texture_flags::swap_bytes | gl::texture_flags::allow_swizzle } }, { CELL_GCM_TEXTURE_R5G5B5A1,{ 2, default_remap, gl::texture::sized_internal_format::rgb5_a1, gl::texture::format::rgba, gl::texture::type::ushort_5_5_5_1, gl::texture_flags::allow_remap | gl::texture_flags::swap_bytes | gl::texture_flags::allow_swizzle } },
{ CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT,{ 8, default_remap, gl::texture::internal_format::rgba, gl::texture::format::rgba, gl::texture::type::f16, gl::texture_flags::allow_remap | gl::texture_flags::swap_bytes } }, { CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT,{ 8, default_remap, gl::texture::sized_internal_format::rgba16f, gl::texture::format::rgba, gl::texture::type::f16, gl::texture_flags::allow_remap | gl::texture_flags::swap_bytes } },
{ CELL_GCM_TEXTURE_W32_Z32_Y32_X32_FLOAT,{ 16, default_remap, gl::texture::internal_format::rgba, gl::texture::format::rgba, gl::texture::type::f32, gl::texture_flags::allow_remap | gl::texture_flags::swap_bytes } }, { CELL_GCM_TEXTURE_W32_Z32_Y32_X32_FLOAT,{ 16, default_remap, gl::texture::sized_internal_format::rgba32f, gl::texture::format::rgba, gl::texture::type::f32, gl::texture_flags::allow_remap | gl::texture_flags::swap_bytes } },
{ CELL_GCM_TEXTURE_X32_FLOAT,{ 4, remap_X32_FLOAT, gl::texture::internal_format::rgba, gl::texture::format::red, gl::texture::type::f32, gl::texture_flags::swap_bytes } }, { CELL_GCM_TEXTURE_X32_FLOAT,{ 4, remap_X32_FLOAT, gl::texture::sized_internal_format::r32f, gl::texture::format::red, gl::texture::type::f32, gl::texture_flags::swap_bytes } },
{ CELL_GCM_TEXTURE_D1R5G5B5,{ 2, remap_D1R5G5B5, gl::texture::internal_format::rgba, gl::texture::format::bgra, gl::texture::type::ushort_5_5_5_1, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } }, { CELL_GCM_TEXTURE_D1R5G5B5,{ 2, remap_D1R5G5B5, gl::texture::sized_internal_format::rgb5_a1, gl::texture::format::bgra, gl::texture::type::ushort_5_5_5_1, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } },
{ CELL_GCM_TEXTURE_D8R8G8B8,{ 4, remap_D8R8G8B8, gl::texture::internal_format::rgba, gl::texture::format::bgra, gl::texture::type::uint_8_8_8_8, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } }, { CELL_GCM_TEXTURE_D8R8G8B8,{ 4, remap_D8R8G8B8, gl::texture::sized_internal_format::rgba8, gl::texture::format::bgra, gl::texture::type::uint_8_8_8_8, gl::texture_flags::allow_remap | gl::texture_flags::allow_swizzle } },
{ CELL_GCM_TEXTURE_Y16_X16_FLOAT,{ 4, remap_Y16_X16_FLOAT, gl::texture::internal_format::rgba, gl::texture::format::rg, gl::texture::type::f16, gl::texture_flags::allow_remap | gl::texture_flags::swap_bytes } }, { CELL_GCM_TEXTURE_Y16_X16_FLOAT,{ 4, remap_Y16_X16_FLOAT, gl::texture::sized_internal_format::rg16f, gl::texture::format::rg, gl::texture::type::f16, gl::texture_flags::allow_remap | gl::texture_flags::swap_bytes } },
}; };
namespace gl namespace gl
@ -177,17 +177,17 @@ void rsx::gl_texture::bind(gl::texture_cache& cache, int index, rsx::texture& te
{ {
case CELL_GCM_TEXTURE_COMPRESSED_DXT1: // Compressed 4x4 pixels into 8 bytes case CELL_GCM_TEXTURE_COMPRESSED_DXT1: // Compressed 4x4 pixels into 8 bytes
info.compressed_size = ((info.width + 3) / 4) * ((info.height + 3) / 4) * 8; info.compressed_size = ((info.width + 3) / 4) * ((info.height + 3) / 4) * 8;
info.format.internal_format = gl::texture::internal_format::compressed_rgba_s3tc_dxt1; info.format.internal_format = gl::texture::sized_internal_format::compressed_rgba_s3tc_dxt1;
break; break;
case CELL_GCM_TEXTURE_COMPRESSED_DXT23: // Compressed 4x4 pixels into 16 bytes case CELL_GCM_TEXTURE_COMPRESSED_DXT23: // Compressed 4x4 pixels into 16 bytes
info.compressed_size = ((info.width + 3) / 4) * ((info.height + 3) / 4) * 16; info.compressed_size = ((info.width + 3) / 4) * ((info.height + 3) / 4) * 16;
info.format.internal_format = gl::texture::internal_format::compressed_rgba_s3tc_dxt3; info.format.internal_format = gl::texture::sized_internal_format::compressed_rgba_s3tc_dxt3;
break; break;
case CELL_GCM_TEXTURE_COMPRESSED_DXT45: // Compressed 4x4 pixels into 16 bytes case CELL_GCM_TEXTURE_COMPRESSED_DXT45: // Compressed 4x4 pixels into 16 bytes
info.compressed_size = ((info.width + 3) / 4) * ((info.height + 3) / 4) * 16; info.compressed_size = ((info.width + 3) / 4) * ((info.height + 3) / 4) * 16;
info.format.internal_format = gl::texture::internal_format::compressed_rgba_s3tc_dxt5; info.format.internal_format = gl::texture::sized_internal_format::compressed_rgba_s3tc_dxt5;
break; break;
default: default:
@ -218,10 +218,10 @@ void rsx::gl_texture::bind(gl::texture_cache& cache, int index, rsx::texture& te
remap = info.format.remap.data(); remap = info.format.remap.data();
} }
cache.entry(info, gl::cache_buffers::local).bind(index); __glcheck cache.entry(info, gl::cache_buffers::local).bind(index);
glTexParameteri((GLenum)target, GL_TEXTURE_MAX_LEVEL, tex.mipmap() - 1); __glcheck glTexParameteri((GLenum)target, GL_TEXTURE_MAX_LEVEL, tex.mipmap() - 1);
glTexParameteri((GLenum)target, GL_GENERATE_MIPMAP, tex.mipmap() > 1); __glcheck glTexParameteri((GLenum)target, GL_GENERATE_MIPMAP, tex.mipmap() > 1);
if ((info.format.flags & gl::texture_flags::allow_remap) != gl::texture_flags::none) if ((info.format.flags & gl::texture_flags::allow_remap) != gl::texture_flags::none)
{ {
@ -256,5 +256,7 @@ void rsx::gl_texture::bind(gl::texture_cache& cache, int index, rsx::texture& te
glTexParameteri((GLenum)target, GL_TEXTURE_MIN_FILTER, gl_tex_min_filter[tex.min_filter()]); glTexParameteri((GLenum)target, GL_TEXTURE_MIN_FILTER, gl_tex_min_filter[tex.min_filter()]);
glTexParameteri((GLenum)target, GL_TEXTURE_MAG_FILTER, gl_tex_mag_filter[tex.mag_filter()]); glTexParameteri((GLenum)target, GL_TEXTURE_MAG_FILTER, gl_tex_mag_filter[tex.mag_filter()]);
glTexParameterf((GLenum)target, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_aniso(tex.max_aniso())); glTexParameterf((GLenum)target, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_aniso(tex.max_aniso()));
__glcheck 0;
} }