Commit 02cbe8ec by Nicolas Capens Committed by Nicolas Capens

Fix conversion to RGB9E5 format

log() was used instead of log2(). Also replace pow(2.0f, x) with the equivalent exp2(x), and remove overloaded functions from Math.hpp which are guaranteed by C++11. Bug: b/138944025 Change-Id: I9e87ee9b2afd8791a40dd3e73191e1ed0740acf5 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34668 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com>
parent 20fb1d68
......@@ -16,6 +16,7 @@
#include "Pipeline/ShaderCore.hpp"
#include "Reactor/Reactor.hpp"
#include "System/Half.hpp"
#include "System/Memory.hpp"
#include "Vulkan/VkDebug.hpp"
#include "Vulkan/VkImage.hpp"
......
......@@ -198,18 +198,18 @@ namespace sw
{
if(state.colorWriteActive(index))
{
cBuffer[index] += *Pointer<Int>(data + OFFSET(DrawData,colorPitchB[index])) << (1 + sw::log2(clusterCount)); // FIXME: Precompute
cBuffer[index] += *Pointer<Int>(data + OFFSET(DrawData,colorPitchB[index])) << (1 + log2i(clusterCount)); // FIXME: Precompute
}
}
if(state.depthTestActive)
{
zBuffer += *Pointer<Int>(data + OFFSET(DrawData,depthPitchB)) << (1 + sw::log2(clusterCount)); // FIXME: Precompute
zBuffer += *Pointer<Int>(data + OFFSET(DrawData,depthPitchB)) << (1 + log2i(clusterCount)); // FIXME: Precompute
}
if(state.stencilActive)
{
sBuffer += *Pointer<Int>(data + OFFSET(DrawData,stencilPitchB)) << (1 + sw::log2(clusterCount)); // FIXME: Precompute
sBuffer += *Pointer<Int>(data + OFFSET(DrawData,stencilPitchB)) << (1 + log2i(clusterCount)); // FIXME: Precompute
}
y += 2 * clusterCount;
......
......@@ -77,19 +77,13 @@ namespace sw
const float blue_c = std::max<float>(0, std::min(g_sharedexp_max, rgb[2]));
const float max_c = std::max<float>(std::max<float>(red_c, green_c), blue_c);
const float exp_p =
std::max<float>(-g_sharedexp_bias - 1, floor(log(max_c))) + 1 + g_sharedexp_bias;
const int max_s = static_cast<int>(
floor((max_c / (pow(2.0f, exp_p - g_sharedexp_bias - g_sharedexp_mantissabits))) + 0.5f));
const int exp_s =
static_cast<int>((max_s < pow(2.0f, g_sharedexp_mantissabits)) ? exp_p : exp_p + 1);
R = static_cast<unsigned int>(
floor((red_c / (pow(2.0f, exp_s - g_sharedexp_bias - g_sharedexp_mantissabits))) + 0.5f));
G = static_cast<unsigned int>(
floor((green_c / (pow(2.0f, exp_s - g_sharedexp_bias - g_sharedexp_mantissabits))) + 0.5f));
B = static_cast<unsigned int>(
floor((blue_c / (pow(2.0f, exp_s - g_sharedexp_bias - g_sharedexp_mantissabits))) + 0.5f));
const float exp_p = std::max<float>(-g_sharedexp_bias - 1, floor(log2(max_c))) + 1 + g_sharedexp_bias;
const int max_s = static_cast<int>(floor((max_c / exp2(exp_p - g_sharedexp_bias - g_sharedexp_mantissabits)) + 0.5f));
const int exp_s = static_cast<int>((max_s < exp2(g_sharedexp_mantissabits)) ? exp_p : exp_p + 1);
R = static_cast<unsigned int>(floor((red_c / exp2(exp_s - g_sharedexp_bias - g_sharedexp_mantissabits)) + 0.5f));
G = static_cast<unsigned int>(floor((green_c / exp2(exp_s - g_sharedexp_bias - g_sharedexp_mantissabits)) + 0.5f));
B = static_cast<unsigned int>(floor((blue_c / exp2(exp_s - g_sharedexp_bias - g_sharedexp_mantissabits)) + 0.5f));
E = exp_s;
}
......
......@@ -16,7 +16,6 @@
#define sw_Math_hpp
#include "Types.hpp"
#include "Half.hpp"
#include "Vulkan/VkDebug.hpp"
......@@ -138,17 +137,7 @@ namespace sw
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
inline float exp2(float x)
{
return exp2f(x);
}
inline int exp2(int x)
{
return 1 << x;
}
inline unsigned long log2(int x)
inline unsigned long log2i(int x)
{
#if defined(_MSC_VER)
unsigned long y;
......@@ -159,18 +148,6 @@ namespace sw
#endif
}
inline int ilog2(float x)
{
unsigned int y = *(unsigned int*)&x;
return ((y & 0x7F800000) >> 23) - 127;
}
inline float log2(float x)
{
return logf(x) * 1.44269504f; // 1.0 / log[e](2)
}
inline bool isPow2(int x)
{
return (x & -x) == x;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment