mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 14:19:55 -06:00
fix UB
also misc changes to use more unsigned multiplication also fix framebuffer resize
This commit is contained in:
@ -89,7 +89,6 @@ bool ComputeRenderer::Init()
|
|||||||
glGenBuffers(1, &TileMemory);
|
glGenBuffers(1, &TileMemory);
|
||||||
|
|
||||||
glGenTextures(1, &YSpanIndicesTexture);
|
glGenTextures(1, &YSpanIndicesTexture);
|
||||||
glGenTextures(1, &Framebuffer);
|
|
||||||
glGenTextures(1, &LowResFramebuffer);
|
glGenTextures(1, &LowResFramebuffer);
|
||||||
glBindTexture(GL_TEXTURE_2D, LowResFramebuffer);
|
glBindTexture(GL_TEXTURE_2D, LowResFramebuffer);
|
||||||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8UI, 256, 192);
|
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8UI, 256, 192);
|
||||||
@ -230,6 +229,9 @@ void ComputeRenderer::SetRenderSettings(GPU::RenderSettings& settings)
|
|||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, BinResultMemory);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, BinResultMemory);
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, binResultSize, nullptr, GL_DYNAMIC_DRAW);
|
glBufferData(GL_SHADER_STORAGE_BUFFER, binResultSize, nullptr, GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
if (Framebuffer != 0)
|
||||||
|
glDeleteTextures(1, &Framebuffer);
|
||||||
|
glGenTextures(1, &Framebuffer);
|
||||||
glBindTexture(GL_TEXTURE_2D, Framebuffer);
|
glBindTexture(GL_TEXTURE_2D, Framebuffer);
|
||||||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, ScreenWidth, ScreenHeight);
|
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, ScreenWidth, ScreenHeight);
|
||||||
|
|
||||||
@ -1391,7 +1393,7 @@ void ComputeRenderer::RenderFrame()
|
|||||||
for (int i = 0; i < numVariants; i++)
|
for (int i = 0; i < numVariants; i++)
|
||||||
{
|
{
|
||||||
GLuint shader = 0;
|
GLuint shader = 0;
|
||||||
if (variants[i].Texture == -1)
|
if (variants[i].Texture == 0)
|
||||||
{
|
{
|
||||||
shader = shadersNoTexture[variants[i].BlendMode];
|
shader = shadersNoTexture[variants[i].BlendMode];
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ private:
|
|||||||
|
|
||||||
u32 TextureDecodingBuffer[1024*1024];
|
u32 TextureDecodingBuffer[1024*1024];
|
||||||
|
|
||||||
GLuint Framebuffer;
|
GLuint Framebuffer = 0;
|
||||||
GLuint LowResFramebuffer;
|
GLuint LowResFramebuffer;
|
||||||
GLuint PixelBuffer;
|
GLuint PixelBuffer;
|
||||||
|
|
||||||
|
@ -299,11 +299,11 @@ uint Div64_32_32(uint numHi, uint numLo, uint den)
|
|||||||
// there's a 1 in the MSB.
|
// there's a 1 in the MSB.
|
||||||
// We also shift numer by the same amount. This cannot overflow because numHi < den.
|
// We also shift numer by the same amount. This cannot overflow because numHi < den.
|
||||||
// The expression (-shift & 63) is the same as (64 - shift), except it avoids the UB of shifting
|
// The expression (-shift & 63) is the same as (64 - shift), except it avoids the UB of shifting
|
||||||
// by 64. <---- in C. I'm pretty sure shifts are masked in GLSL, but whatever.
|
// by 64. (it's also UB in GLSL!!!!)
|
||||||
uint shift = 31 - findMSB(den);
|
uint shift = 31 - findMSB(den);
|
||||||
den <<= shift;
|
den <<= shift;
|
||||||
numHi <<= shift;
|
numHi <<= shift;
|
||||||
numHi |= (numLo >> (-shift & 63U)) & uint(-int(shift) >> 63);
|
numHi |= (numLo >> (-shift & 31U)) & uint(-int(shift) >> 31);
|
||||||
numLo <<= shift;
|
numLo <<= shift;
|
||||||
|
|
||||||
// Extract the low digits of the numerator and both digits of the denominator.
|
// Extract the low digits of the numerator and both digits of the denominator.
|
||||||
@ -347,12 +347,12 @@ int CalcYFactorY(YSpanSetup span, int i)
|
|||||||
/*
|
/*
|
||||||
maybe it would be better to do use a 32x32=64 multiplication?
|
maybe it would be better to do use a 32x32=64 multiplication?
|
||||||
*/
|
*/
|
||||||
uint numLo = abs(i * span.W0n);
|
uint numLo = uint(abs(i)) * uint(span.W0n);
|
||||||
uint numHi = 0U;
|
uint numHi = 0U;
|
||||||
numHi |= numLo >> (32-YFactorShift);
|
numHi |= numLo >> (32U-YFactorShift);
|
||||||
numLo <<= YFactorShift;
|
numLo <<= YFactorShift;
|
||||||
|
|
||||||
uint den = abs(i * span.W0d + (span.I1 - span.I0 - i) * span.W1d);
|
uint den = uint(abs(i)) * uint(span.W0d) + uint(abs(span.I1 - span.I0 - i)) * span.W1d;
|
||||||
|
|
||||||
if (den == 0)
|
if (den == 0)
|
||||||
{
|
{
|
||||||
@ -370,12 +370,12 @@ int CalcYFactorX(XSpanSetup span, int x)
|
|||||||
|
|
||||||
if (span.X0 != span.X1)
|
if (span.X0 != span.X1)
|
||||||
{
|
{
|
||||||
uint numLo = uint(x) * span.W0;
|
uint numLo = uint(x) * uint(span.W0);
|
||||||
uint numHi = 0U;
|
uint numHi = 0U;
|
||||||
numHi |= numLo >> (32-YFactorShift);
|
numHi |= numLo >> (32U-YFactorShift);
|
||||||
numLo <<= YFactorShift;
|
numLo <<= YFactorShift;
|
||||||
|
|
||||||
uint den = (uint(x) * span.W0) + (uint(span.X1 - span.X0 - x) * span.W1);
|
uint den = uint(x) * uint(span.W0) + uint(span.X1 - span.X0 - x) * uint(span.W1);
|
||||||
|
|
||||||
if (den == 0)
|
if (den == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user