Don't use unsync map buffer

It causes regression in hd5670 in windows

Although we should update ubo only once per frame
This commit is contained in:
Benau 2017-10-22 01:43:26 +08:00
parent 6a79d204c1
commit a0991c3233
5 changed files with 60 additions and 68 deletions

View File

@ -685,7 +685,6 @@ void DrawCalls::prepareDrawCalls( ShadowMatrices& shadow_matrices,
}*/
PROFILER_PUSH_CPU_MARKER("- Animations/Buffer upload", 0x0, 0x0, 0x0);
shadow_matrices.updateUBO();
#ifdef USE_GLES2
glBindTexture(GL_TEXTURE_2D, SharedGPUObjects::getSkinningTexture());
#else

View File

@ -152,6 +152,39 @@ void ShaderBasedRenderer::prepareForwardRenderer()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
// ----------------------------------------------------------------------------
/** Upload lighting info to the dedicated uniform buffer
*/
void ShaderBasedRenderer::uploadLightingData() const
{
assert(CVS->isARBUniformBufferObjectUsable());
float Lighting[36];
core::vector3df sun_direction = irr_driver->getSunDirection();
video::SColorf sun_color = irr_driver->getSunColor();
Lighting[0] = sun_direction.X;
Lighting[1] = sun_direction.Y;
Lighting[2] = sun_direction.Z;
Lighting[4] = sun_color.getRed();
Lighting[5] = sun_color.getGreen();
Lighting[6] = sun_color.getBlue();
Lighting[7] = 0.54f;
const SHCoefficients* sh_coeff = m_spherical_harmonics->getCoefficients();
if(sh_coeff) {
memcpy(&Lighting[8], sh_coeff->blue_SH_coeff, 9 * sizeof(float));
memcpy(&Lighting[17], sh_coeff->green_SH_coeff, 9 * sizeof(float));
memcpy(&Lighting[26], sh_coeff->red_SH_coeff, 9 * sizeof(float));
}
glBindBuffer(GL_UNIFORM_BUFFER, SharedGPUObjects::getLightingDataUBO());
glBufferSubData(GL_UNIFORM_BUFFER, 0, 36 * sizeof(float), Lighting);
} // uploadLightingData
// ----------------------------------------------------------------------------
void ShaderBasedRenderer::computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode,
unsigned int width, unsigned int height)
@ -778,9 +811,11 @@ void ShaderBasedRenderer::render(float dt)
glEnable(GL_FRAMEBUFFER_SRGB);
#endif
PROFILER_PUSH_CPU_MARKER("Update camera matrices", 0x0, 0xFF, 0x0);
PROFILER_PUSH_CPU_MARKER("UBO upload", 0x0, 0xFF, 0x0);
computeMatrixesAndCameras(camnode, m_rtts->getWidth(), m_rtts->getHeight());
m_shadow_matrices.updateSunOrthoMatrices();
if(CVS->isARBUniformBufferObjectUsable())
uploadLightingData();
PROFILER_POP_CPU_MARKER();
renderScene(camnode, dt, track->hasShadows(), false);
@ -887,6 +922,9 @@ void ShaderBasedRenderer::renderToTexture(GL3RenderTarget *render_target,
irr_driver->getSceneManager()->setActiveCamera(camera);
computeMatrixesAndCameras(camera, m_rtts->getWidth(), m_rtts->getHeight());
if (CVS->isARBUniformBufferObjectUsable())
uploadLightingData();
renderScene(camera, dt, false, true);
render_target->setFrameBuffer(m_post_processing
->render(camera, false, m_rtts));

View File

@ -61,6 +61,8 @@ private:
void prepareForwardRenderer();
void uploadLightingData() const;
void computeMatrixesAndCameras(scene::ICameraSceneNode * const camnode,
unsigned int width, unsigned int height);

View File

@ -26,7 +26,6 @@
#include "graphics/post_processing.hpp"
#include "graphics/rtts.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/spherical_harmonics.hpp"
#include "graphics/texture_shader.hpp"
#include "modes/world.hpp"
#include "physics/triangle_mesh.hpp"
@ -312,55 +311,6 @@ void ShadowMatrices::updateSplitAndLightcoordRangeFromComputeShaders(unsigned in
#endif
} // updateSplitAndLightcoordRangeFromComputeShaders
// ----------------------------------------------------------------------------
void ShadowMatrices::updateUBO()
{
if (!CVS->isARBUniformBufferObjectUsable())
{
return;
}
float lighting[36] = {};
core::vector3df sun_direction = irr_driver->getSunDirection();
video::SColorf sun_color = irr_driver->getSunColor();
lighting[0] = sun_direction.X;
lighting[1] = sun_direction.Y;
lighting[2] = sun_direction.Z;
lighting[4] = sun_color.getRed();
lighting[5] = sun_color.getGreen();
lighting[6] = sun_color.getBlue();
lighting[7] = 0.54f;
const SHCoefficients* sh_coeff = irr_driver->getSHCoefficients();
if (sh_coeff)
{
memcpy(&lighting[8], sh_coeff->blue_SH_coeff, 9 * sizeof(float));
memcpy(&lighting[17], sh_coeff->green_SH_coeff, 9 * sizeof(float));
memcpy(&lighting[26], sh_coeff->red_SH_coeff, 9 * sizeof(float));
}
glBindBuffer(GL_UNIFORM_BUFFER, SharedGPUObjects::getLightingDataUBO());
void* ptr = glMapBufferRange(GL_UNIFORM_BUFFER, 0, 36 * 4,
GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT |
GL_MAP_INVALIDATE_BUFFER_BIT);
memcpy(ptr, lighting, 36 * 4);
glUnmapBuffer(GL_UNIFORM_BUFFER);
if (CVS->isSDSMEnabled())
{
return;
}
glBindBuffer(GL_UNIFORM_BUFFER,
SharedGPUObjects::getViewProjectionMatricesUBO());
ptr = glMapBufferRange(GL_UNIFORM_BUFFER, 0, (16 * 9 + 2) * 4,
GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT |
GL_MAP_INVALIDATE_BUFFER_BIT);
memcpy(ptr, m_ubo_data, (16 * 9 + 2) * 4);
glUnmapBuffer(GL_UNIFORM_BUFFER);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
} // updateUBO
// ----------------------------------------------------------------------------
/** Generate View, Projection, Inverse View, Inverse Projection, ViewProjection
* and InverseProjection matrixes and matrixes and cameras for the four shadow
@ -388,11 +338,12 @@ void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const ca
const float oldfar = camnode->getFarValue();
const float oldnear = camnode->getNearValue();
memcpy(m_ubo_data, irr_driver->getViewMatrix().pointer(), 16 * sizeof(float));
memcpy(&m_ubo_data[16], irr_driver->getProjMatrix().pointer(), 16 * sizeof(float));
memcpy(&m_ubo_data[32], irr_driver->getInvViewMatrix().pointer(), 16 * sizeof(float));
memcpy(&m_ubo_data[48], irr_driver->getInvProjMatrix().pointer(), 16 * sizeof(float));
memcpy(&m_ubo_data[64], irr_driver->getProjViewMatrix().pointer(), 16 * sizeof(float));
float tmp[16 * 9 + 2];
memcpy(tmp, irr_driver->getViewMatrix().pointer(), 16 * sizeof(float));
memcpy(&tmp[16], irr_driver->getProjMatrix().pointer(), 16 * sizeof(float));
memcpy(&tmp[32], irr_driver->getInvViewMatrix().pointer(), 16 * sizeof(float));
memcpy(&tmp[48], irr_driver->getInvProjMatrix().pointer(), 16 * sizeof(float));
memcpy(&tmp[64], irr_driver->getProjViewMatrix().pointer(), 16 * sizeof(float));
m_sun_cam->render();
for (unsigned i = 0; i < 4; i++)
@ -518,23 +469,27 @@ void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const ca
size_t size = m_sun_ortho_matrices.size();
for (unsigned i = 0; i < size; i++)
memcpy(&m_ubo_data[16 * i + 80],
memcpy(&tmp[16 * i + 80],
m_sun_ortho_matrices[i].pointer(),
16 * sizeof(float));
}
m_ubo_data[144] = float(width);
m_ubo_data[145] = float(height);
if(!CVS->isARBUniformBufferObjectUsable())
return;
tmp[144] = float(width);
tmp[145] = float(height);
glBindBuffer(GL_UNIFORM_BUFFER,
SharedGPUObjects::getViewProjectionMatricesUBO());
if (CVS->isSDSMEnabled())
{
glBindBuffer(GL_UNIFORM_BUFFER,
SharedGPUObjects::getViewProjectionMatricesUBO());
glBufferSubData(GL_UNIFORM_BUFFER, 0, (16 * 5) * sizeof(float),
m_ubo_data);
glBufferSubData(GL_UNIFORM_BUFFER, 0, (16 * 5) * sizeof(float), tmp);
glBufferSubData(GL_UNIFORM_BUFFER, (16 * 9) * sizeof(float),
2 * sizeof(float), &m_ubo_data[144]);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
2 * sizeof(float), &tmp[144]);
}
else
glBufferSubData(GL_UNIFORM_BUFFER, 0, (16 * 9 + 2) * sizeof(float),
tmp);
} // computeMatrixesAndCameras
// ----------------------------------------------------------------------------

View File

@ -49,7 +49,6 @@ private:
core::matrix4 m_rsm_matrix;
bool m_rsm_matrix_initialized;
float m_shadows_cam[4][24];
float m_ubo_data[16 * 9 + 2];
bool m_rsm_map_available;
core::vector3df m_rh_extend;
core::matrix4 m_rh_matrix;
@ -105,7 +104,6 @@ public:
return m_shadow_scales;
}
// ------------------------------------------------------------------------
void updateUBO();
}; // class ShadowMatrices