Guarantee 2048 bones

This commit is contained in:
CodingJellyfish 2024-05-30 02:06:51 +08:00
parent 7320f2e70d
commit 84dff4423e
7 changed files with 38 additions and 22 deletions

View File

@ -1,4 +1,4 @@
#ifdef TBO_DISABLED
#ifdef SKINNING_TBO_DISABLED
uniform sampler2D skinning_tex;
#else
uniform samplerBuffer skinning_tex;
@ -58,7 +58,7 @@ void main()
vec4 skinned_tangent = vec4(0.0);
int skinning_offset = i_misc_data.x;
#ifdef TBO_DISABLED
#ifdef SKINNING_TBO_DISABLED
mat4 joint_matrix =
i_weight[0] * mat4(
texelFetch(skinning_tex, ivec2(0, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES)), 0),

View File

@ -1,6 +1,6 @@
uniform int layer;
#ifdef GL_ES
#ifdef SKINNING_TBO_DISABLED
uniform sampler2D skinning_tex;
#else
uniform samplerBuffer skinning_tex;
@ -25,7 +25,7 @@ void main()
vec4 skinned_position = vec4(0.0);
int skinning_offset = i_misc_data.x;
#ifdef GL_ES
#ifdef SKINNING_TBO_DISABLED
mat4 joint_matrix =
i_weight[0] * mat4(
texelFetch(skinning_tex, ivec2(0, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES)), 0),

View File

@ -542,8 +542,9 @@
<!-- Maximum bones from all animated meshes in each frame to be uploaded for
hardware skinning, For gles 3.0 the specification guarantees at least 2048, for
TBO in desktop at least 65536 (max buffer size) / 64, SSBO at least 2^24 / 64,
so 1024 will work everywhere. -->
<skinning max-bones="1024"/>
and for cases TBO doesn't support equal or more than 2048, use texture instead,
so 2048 will work everywhere. -->
<skinning max-bones="2048"/>
<!-- For users with libsquish:
Use a slow but high quality colour compressor.

View File

@ -22,6 +22,7 @@
#include "config/stk_config.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/graphics_restrictions.hpp"
#include "graphics/sp/sp_base.hpp"
#include "guiengine/message_queue.hpp"
#include "io/file_manager.hpp"
#include "utils/file_utils.hpp"
@ -179,8 +180,8 @@ ShaderFilesManager::SharedShader ShaderFilesManager::loadShader
code << "//" << full_path << "\n";
if (!CVS->isARBUniformBufferObjectUsable())
code << "#define UBO_DISABLED\n";
if (!CVS->isARBTextureBufferObjectUsable())
code << "#define TBO_DISABLED\n";
if (!SP::skinningUseTBO())
code << "#define SKINNING_TBO_DISABLED\n";
if (CVS->needsVertexIdWorkaround())
code << "#define Needs_Vertex_Id_Workaround\n";
if (CVS->isDeferredEnabled())

View File

@ -123,6 +123,8 @@ unsigned g_skinning_offset = 0;
// ----------------------------------------------------------------------------
std::vector<SPMeshNode*> g_skinning_mesh;
// ----------------------------------------------------------------------------
int g_skinning_tbo_limit = 0;
// ----------------------------------------------------------------------------
int sp_cur_shadow_cascade = 0;
// ----------------------------------------------------------------------------
void initSTKRenderer(ShaderBasedRenderer* sbr)
@ -251,9 +253,7 @@ void resizeSkinning(unsigned number)
const irr::core::matrix4 m;
g_skinning_size = number;
if (!CVS->isARBTextureBufferObjectUsable())
if (!skinningUseTBO())
{
glBindTexture(GL_TEXTURE_2D, g_skinning_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 4, number, 0, GL_RGBA,
@ -302,7 +302,7 @@ void initSkinning()
int max_size = 0;
if (!CVS->isARBTextureBufferObjectUsable())
if (!skinningUseTBO())
{
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
@ -319,12 +319,12 @@ void initSkinning()
else
{
#ifndef USE_GLES2
glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &max_size);
if (stk_config->m_max_skinning_bones << 6 > (unsigned)max_size)
glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &g_skinning_tbo_limit);
if (stk_config->m_max_skinning_bones << 6 > (unsigned)g_skinning_tbo_limit)
{
Log::warn("SharedGPUObjects", "Too many bones for skinning, max: %d",
max_size >> 6);
stk_config->m_max_skinning_bones = max_size >> 6;
g_skinning_tbo_limit >> 6);
stk_config->m_max_skinning_bones = g_skinning_tbo_limit >> 6;
}
Log::info("SharedGPUObjects", "Hardware Skinning enabled, method: TBO, "
"max bones: %u", stk_config->m_max_skinning_bones);
@ -337,7 +337,7 @@ void initSkinning()
const irr::core::matrix4 m;
glGenTextures(1, &g_skinning_tex);
#ifndef USE_GLES2
if (CVS->isARBTextureBufferObjectUsable())
if (skinningUseTBO())
{
glGenBuffers(1, &g_skinning_buf);
}
@ -442,6 +442,11 @@ void init()
return;
}
if (CVS->isARBTextureBufferObjectUsable())
{
glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE_ARB, &g_skinning_tbo_limit);
}
initSkinning();
for (unsigned i = 0; i < MAX_PLAYER_COUNT; i++)
{
@ -605,7 +610,7 @@ void destroy()
SPTextureManager::destroy();
#ifndef USE_GLES2
if (CVS->isARBTextureBufferObjectUsable() &&
if (skinningUseTBO() &&
CVS->isARBBufferStorageUsable())
{
glBindBuffer(GL_TEXTURE_BUFFER, g_skinning_buf);
@ -647,6 +652,13 @@ SPShader* getNormalVisualizer()
return g_normal_visualizer;
} // getNormalVisualizer
// ----------------------------------------------------------------------------
bool skinningUseTBO()
{
return CVS->isARBTextureBufferObjectUsable()
&& g_skinning_tbo_limit >= 64 * stk_config->m_max_skinning_bones;
}
// ----------------------------------------------------------------------------
inline core::vector3df getCorner(const core::aabbox3df& bbox, unsigned n)
@ -1127,7 +1139,7 @@ void uploadSkinningMatrices()
unsigned buffer_offset = 0;
#ifndef USE_GLES2
if (CVS->isARBTextureBufferObjectUsable() &&
if (skinningUseTBO() &&
!CVS->isARBBufferStorageUsable())
{
glBindBuffer(GL_TEXTURE_BUFFER, g_skinning_buf);
@ -1146,7 +1158,7 @@ void uploadSkinningMatrices()
buffer_offset += g_skinning_mesh[i]->getTotalJoints();
}
if (!CVS->isARBTextureBufferObjectUsable())
if (!skinningUseTBO())
{
glBindTexture(GL_TEXTURE_2D, g_skinning_tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 1, 4, buffer_offset, GL_RGBA,
@ -1155,7 +1167,7 @@ void uploadSkinningMatrices()
}
#ifndef USE_GLES2
if (CVS->isARBTextureBufferObjectUsable() &&
if (skinningUseTBO() &&
!CVS->isARBBufferStorageUsable())
{
glUnmapBuffer(GL_TEXTURE_BUFFER);

View File

@ -110,6 +110,8 @@ SPShader* getNormalVisualizer();
// ----------------------------------------------------------------------------
SPShader* getGlowShader();
// ----------------------------------------------------------------------------
bool skinningUseTBO();
// ----------------------------------------------------------------------------
void prepareDrawCalls();
// ----------------------------------------------------------------------------
void draw(RenderPass, DrawCallType dct = DCT_NORMAL);

View File

@ -44,7 +44,7 @@ SPShader::SPShader(const std::string& name,
m_use_tangents(use_tangents), m_srgb(srgb)
{
#ifndef SERVER_ONLY
if (CVS->isARBTextureBufferObjectUsable())
if (skinningUseTBO())
{
#ifndef USE_GLES2
m_prefilled_names["skinning_tex"] = std::make_pair<unsigned,