clang-format the src/Device directory
Bug: b/144825072
Change-Id: I2e9c18aa5e3d394d18f86ca597aed6d6dc8dfe93
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39654
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Device/BC_Decoder.cpp b/src/Device/BC_Decoder.cpp
index f14d871..f29b839 100644
--- a/src/Device/BC_Decoder.cpp
+++ b/src/Device/BC_Decoder.cpp
@@ -14,206 +14,205 @@
#include "BC_Decoder.hpp"
-namespace
+namespace {
+static constexpr int BlockWidth = 4;
+static constexpr int BlockHeight = 4;
+
+struct BC_color
{
- static constexpr int BlockWidth = 4;
- static constexpr int BlockHeight = 4;
-
- struct BC_color
+ void decode(unsigned char *dst, int x, int y, int dstW, int dstH, int dstPitch, int dstBpp, bool hasAlphaChannel, bool hasSeparateAlpha) const
{
- void decode(unsigned char* dst, int x, int y, int dstW, int dstH, int dstPitch, int dstBpp, bool hasAlphaChannel, bool hasSeparateAlpha) const
+ Color c[4];
+ c[0].extract565(c0);
+ c[1].extract565(c1);
+ if(hasSeparateAlpha || (c0 > c1))
{
- Color c[4];
- c[0].extract565(c0);
- c[1].extract565(c1);
- if(hasSeparateAlpha || (c0 > c1))
+ c[2] = ((c[0] * 2) + c[1]) / 3;
+ c[3] = ((c[1] * 2) + c[0]) / 3;
+ }
+ else
+ {
+ c[2] = (c[0] + c[1]) >> 1;
+ if(hasAlphaChannel)
{
- c[2] = ((c[0] * 2) + c[1]) / 3;
- c[3] = ((c[1] * 2) + c[0]) / 3;
+ c[3].clearAlpha();
}
- else
- {
- c[2] = (c[0] + c[1]) >> 1;
- if(hasAlphaChannel)
- {
- c[3].clearAlpha();
- }
- }
+ }
- for(int j = 0; j < BlockHeight && (y + j) < dstH; j++)
+ for(int j = 0; j < BlockHeight && (y + j) < dstH; j++)
+ {
+ int dstOffset = j * dstPitch;
+ int idxOffset = j * BlockHeight;
+ for(int i = 0; i < BlockWidth && (x + i) < dstW; i++, idxOffset++, dstOffset += dstBpp)
{
- int dstOffset = j * dstPitch;
- int idxOffset = j * BlockHeight;
- for(int i = 0; i < BlockWidth && (x + i) < dstW; i++, idxOffset++, dstOffset += dstBpp)
- {
- *reinterpret_cast<unsigned int*>(dst + dstOffset) = c[getIdx(idxOffset)].pack8888();
- }
+ *reinterpret_cast<unsigned int *>(dst + dstOffset) = c[getIdx(idxOffset)].pack8888();
}
}
+ }
+
+private:
+ struct Color
+ {
+ Color()
+ {
+ c[0] = c[1] = c[2] = 0;
+ c[3] = 0xFF000000;
+ }
+
+ void extract565(const unsigned int c565)
+ {
+ c[0] = ((c565 & 0x0000001F) << 3) | ((c565 & 0x0000001C) >> 2);
+ c[1] = ((c565 & 0x000007E0) >> 3) | ((c565 & 0x00000600) >> 9);
+ c[2] = ((c565 & 0x0000F800) >> 8) | ((c565 & 0x0000E000) >> 13);
+ }
+
+ unsigned int pack8888() const
+ {
+ return ((c[2] & 0xFF) << 16) | ((c[1] & 0xFF) << 8) | (c[0] & 0xFF) | c[3];
+ }
+
+ void clearAlpha()
+ {
+ c[3] = 0;
+ }
+
+ Color operator*(int factor) const
+ {
+ Color res;
+ for(int i = 0; i < 4; ++i)
+ {
+ res.c[i] = c[i] * factor;
+ }
+ return res;
+ }
+
+ Color operator/(int factor) const
+ {
+ Color res;
+ for(int i = 0; i < 4; ++i)
+ {
+ res.c[i] = c[i] / factor;
+ }
+ return res;
+ }
+
+ Color operator>>(int shift) const
+ {
+ Color res;
+ for(int i = 0; i < 4; ++i)
+ {
+ res.c[i] = c[i] >> shift;
+ }
+ return res;
+ }
+
+ Color operator+(Color const &obj) const
+ {
+ Color res;
+ for(int i = 0; i < 4; ++i)
+ {
+ res.c[i] = c[i] + obj.c[i];
+ }
+ return res;
+ }
private:
- struct Color
- {
- Color()
- {
- c[0] = c[1] = c[2] = 0;
- c[3] = 0xFF000000;
- }
-
- void extract565(const unsigned int c565)
- {
- c[0] = ((c565 & 0x0000001F) << 3) | ((c565 & 0x0000001C) >> 2);
- c[1] = ((c565 & 0x000007E0) >> 3) | ((c565 & 0x00000600) >> 9);
- c[2] = ((c565 & 0x0000F800) >> 8) | ((c565 & 0x0000E000) >> 13);
- }
-
- unsigned int pack8888() const
- {
- return ((c[2] & 0xFF) << 16) | ((c[1] & 0xFF) << 8) | (c[0] & 0xFF) | c[3];
- }
-
- void clearAlpha()
- {
- c[3] = 0;
- }
-
- Color operator*(int factor) const
- {
- Color res;
- for(int i = 0; i < 4; ++i)
- {
- res.c[i] = c[i] * factor;
- }
- return res;
- }
-
- Color operator/(int factor) const
- {
- Color res;
- for(int i = 0; i < 4; ++i)
- {
- res.c[i] = c[i] / factor;
- }
- return res;
- }
-
- Color operator>>(int shift) const
- {
- Color res;
- for(int i = 0; i < 4; ++i)
- {
- res.c[i] = c[i] >> shift;
- }
- return res;
- }
-
- Color operator+(Color const& obj) const
- {
- Color res;
- for(int i = 0; i < 4; ++i)
- {
- res.c[i] = c[i] + obj.c[i];
- }
- return res;
- }
-
- private:
- int c[4];
- };
-
- unsigned int getIdx(int i) const
- {
- int offset = i << 1; // 2 bytes per index
- return (idx & (0x3 << offset)) >> offset;
- }
-
- unsigned short c0;
- unsigned short c1;
- unsigned int idx;
+ int c[4];
};
- struct BC_channel
+ unsigned int getIdx(int i) const
{
- void decode(unsigned char* dst, int x, int y, int dstW, int dstH, int dstPitch, int dstBpp, int channel, bool isSigned) const
- {
- int c[8] = { 0 };
+ int offset = i << 1; // 2 bytes per index
+ return (idx & (0x3 << offset)) >> offset;
+ }
- if(isSigned)
- {
- c[0] = static_cast<signed char>(data & 0xFF);
- c[1] = static_cast<signed char>((data & 0xFF00) >> 8);
- }
- else
- {
- c[0] = static_cast<unsigned char>(data & 0xFF);
- c[1] = static_cast<unsigned char>((data & 0xFF00) >> 8);
- }
+ unsigned short c0;
+ unsigned short c1;
+ unsigned int idx;
+};
- if(c[0] > c[1])
- {
- for(int i = 2; i < 8; ++i)
- {
- c[i] = ((8 - i) * c[0] + (i - 1) * c[1]) / 7;
- }
- }
- else
- {
- for(int i = 2; i < 6; ++i)
- {
- c[i] = ((6 - i) * c[0] + (i - 1) * c[1]) / 5;
- }
- c[6] = isSigned ? -128 : 0;
- c[7] = isSigned ? 127 : 255;
- }
-
- for(int j = 0; j < BlockHeight && (y + j) < dstH; j++)
- {
- for(int i = 0; i < BlockWidth && (x + i) < dstW; i++)
- {
- dst[channel + (i * dstBpp) + (j * dstPitch)] = static_cast<unsigned char>(c[getIdx((j * BlockHeight) + i)]);
- }
- }
- }
-
- private:
- unsigned char getIdx(int i) const
- {
- int offset = i * 3 + 16;
- return static_cast<unsigned char>((data & (0x7ull << offset)) >> offset);
- }
-
- unsigned long long data;
- };
-
- struct BC_alpha
+struct BC_channel
+{
+ void decode(unsigned char *dst, int x, int y, int dstW, int dstH, int dstPitch, int dstBpp, int channel, bool isSigned) const
{
- void decode(unsigned char* dst, int x, int y, int dstW, int dstH, int dstPitch, int dstBpp) const
+ int c[8] = { 0 };
+
+ if(isSigned)
{
- dst += 3; // Write only to alpha (channel 3)
- for(int j = 0; j < BlockHeight && (y + j) < dstH; j++, dst += dstPitch)
+ c[0] = static_cast<signed char>(data & 0xFF);
+ c[1] = static_cast<signed char>((data & 0xFF00) >> 8);
+ }
+ else
+ {
+ c[0] = static_cast<unsigned char>(data & 0xFF);
+ c[1] = static_cast<unsigned char>((data & 0xFF00) >> 8);
+ }
+
+ if(c[0] > c[1])
+ {
+ for(int i = 2; i < 8; ++i)
{
- unsigned char* dstRow = dst;
- for(int i = 0; i < BlockWidth && (x + i) < dstW; i++, dstRow += dstBpp)
- {
- *dstRow = getAlpha(j * BlockHeight + i);
- }
+ c[i] = ((8 - i) * c[0] + (i - 1) * c[1]) / 7;
}
}
-
- private:
- unsigned char getAlpha(int i) const
+ else
{
- int offset = i << 2;
- int alpha = (data & (0xFull << offset)) >> offset;
- return static_cast<unsigned char>(alpha | (alpha << 4));
+ for(int i = 2; i < 6; ++i)
+ {
+ c[i] = ((6 - i) * c[0] + (i - 1) * c[1]) / 5;
+ }
+ c[6] = isSigned ? -128 : 0;
+ c[7] = isSigned ? 127 : 255;
}
- unsigned long long data;
- };
-} // end namespace
+ for(int j = 0; j < BlockHeight && (y + j) < dstH; j++)
+ {
+ for(int i = 0; i < BlockWidth && (x + i) < dstW; i++)
+ {
+ dst[channel + (i * dstBpp) + (j * dstPitch)] = static_cast<unsigned char>(c[getIdx((j * BlockHeight) + i)]);
+ }
+ }
+ }
+
+private:
+ unsigned char getIdx(int i) const
+ {
+ int offset = i * 3 + 16;
+ return static_cast<unsigned char>((data & (0x7ull << offset)) >> offset);
+ }
+
+ unsigned long long data;
+};
+
+struct BC_alpha
+{
+ void decode(unsigned char *dst, int x, int y, int dstW, int dstH, int dstPitch, int dstBpp) const
+ {
+ dst += 3; // Write only to alpha (channel 3)
+ for(int j = 0; j < BlockHeight && (y + j) < dstH; j++, dst += dstPitch)
+ {
+ unsigned char *dstRow = dst;
+ for(int i = 0; i < BlockWidth && (x + i) < dstW; i++, dstRow += dstBpp)
+ {
+ *dstRow = getAlpha(j * BlockHeight + i);
+ }
+ }
+ }
+
+private:
+ unsigned char getAlpha(int i) const
+ {
+ int offset = i << 2;
+ int alpha = (data & (0xFull << offset)) >> offset;
+ return static_cast<unsigned char>(alpha | (alpha << 4));
+ }
+
+ unsigned long long data;
+};
+} // end namespace
// Decodes 1 to 4 channel images to 8 bit output
-bool BC_Decoder::Decode(const unsigned char* src, unsigned char* dst, int w, int h, int dstW, int dstH, int dstPitch, int dstBpp, int n, bool isNoAlphaU)
+bool BC_Decoder::Decode(const unsigned char *src, unsigned char *dst, int w, int h, int dstW, int dstH, int dstPitch, int dstBpp, int n, bool isNoAlphaU)
{
static_assert(sizeof(BC_color) == 8, "BC_color must be 8 bytes");
static_assert(sizeof(BC_channel) == 8, "BC_channel must be 8 bytes");
@@ -226,12 +225,12 @@
switch(n)
{
- case 1: // BC1
+ case 1: // BC1
{
- const BC_color* color = reinterpret_cast<const BC_color*>(src);
+ const BC_color *color = reinterpret_cast<const BC_color *>(src);
for(int y = 0; y < h; y += BlockHeight, dst += dy)
{
- unsigned char* dstRow = dst;
+ unsigned char *dstRow = dst;
for(int x = 0; x < w; x += BlockWidth, ++color, dstRow += dx)
{
color->decode(dstRow, x, y, dstW, dstH, dstPitch, dstBpp, isAlpha, false);
@@ -239,13 +238,13 @@
}
}
break;
- case 2: // BC2
+ case 2: // BC2
{
- const BC_alpha* alpha = reinterpret_cast<const BC_alpha*>(src);
- const BC_color* color = reinterpret_cast<const BC_color*>(src + 8);
+ const BC_alpha *alpha = reinterpret_cast<const BC_alpha *>(src);
+ const BC_color *color = reinterpret_cast<const BC_color *>(src + 8);
for(int y = 0; y < h; y += BlockHeight, dst += dy)
{
- unsigned char* dstRow = dst;
+ unsigned char *dstRow = dst;
for(int x = 0; x < w; x += BlockWidth, alpha += 2, color += 2, dstRow += dx)
{
color->decode(dstRow, x, y, dstW, dstH, dstPitch, dstBpp, isAlpha, true);
@@ -254,13 +253,13 @@
}
}
break;
- case 3: // BC3
+ case 3: // BC3
{
- const BC_channel* alpha = reinterpret_cast<const BC_channel*>(src);
- const BC_color* color = reinterpret_cast<const BC_color*>(src + 8);
+ const BC_channel *alpha = reinterpret_cast<const BC_channel *>(src);
+ const BC_color *color = reinterpret_cast<const BC_color *>(src + 8);
for(int y = 0; y < h; y += BlockHeight, dst += dy)
{
- unsigned char* dstRow = dst;
+ unsigned char *dstRow = dst;
for(int x = 0; x < w; x += BlockWidth, alpha += 2, color += 2, dstRow += dx)
{
color->decode(dstRow, x, y, dstW, dstH, dstPitch, dstBpp, isAlpha, true);
@@ -269,12 +268,12 @@
}
}
break;
- case 4: // BC4
+ case 4: // BC4
{
- const BC_channel* red = reinterpret_cast<const BC_channel*>(src);
+ const BC_channel *red = reinterpret_cast<const BC_channel *>(src);
for(int y = 0; y < h; y += BlockHeight, dst += dy)
{
- unsigned char* dstRow = dst;
+ unsigned char *dstRow = dst;
for(int x = 0; x < w; x += BlockWidth, ++red, dstRow += dx)
{
red->decode(dstRow, x, y, dstW, dstH, dstPitch, dstBpp, 0, isSigned);
@@ -282,13 +281,13 @@
}
}
break;
- case 5: // BC5
+ case 5: // BC5
{
- const BC_channel* red = reinterpret_cast<const BC_channel*>(src);
- const BC_channel* green = reinterpret_cast<const BC_channel*>(src + 8);
+ const BC_channel *red = reinterpret_cast<const BC_channel *>(src);
+ const BC_channel *green = reinterpret_cast<const BC_channel *>(src + 8);
for(int y = 0; y < h; y += BlockHeight, dst += dy)
{
- unsigned char* dstRow = dst;
+ unsigned char *dstRow = dst;
for(int x = 0; x < w; x += BlockWidth, red += 2, green += 2, dstRow += dx)
{
red->decode(dstRow, x, y, dstW, dstH, dstPitch, dstBpp, 0, isSigned);
@@ -297,8 +296,8 @@
}
}
break;
- default:
- return false;
+ default:
+ return false;
}
return true;
diff --git a/src/Device/BC_Decoder.hpp b/src/Device/BC_Decoder.hpp
index 28547bb..8ebbb60 100644
--- a/src/Device/BC_Decoder.hpp
+++ b/src/Device/BC_Decoder.hpp
@@ -15,7 +15,6 @@
class BC_Decoder
{
public:
-
/// BCn_Decoder::Decode - Decodes 1 to 4 channel images to 8 bit output
/// @param src Pointer to BCn encoded image
/// @param dst Pointer to decoded output image
@@ -29,5 +28,5 @@
/// @param isNoAlphaU BC1: true if RGB, BC2/BC3: unused, BC4/BC5: true if unsigned
/// @return true if the decoding was performed
- static bool Decode(const unsigned char* src, unsigned char* dst, int w, int h, int dstW, int dstH, int dstPitch, int dstBpp, int n, bool isNoAlphaU);
+ static bool Decode(const unsigned char *src, unsigned char *dst, int w, int h, int dstW, int dstH, int dstPitch, int dstBpp, int n, bool isNoAlphaU);
};
diff --git a/src/Device/Blitter.cpp b/src/Device/Blitter.cpp
index 3103616..2394fb2 100644
--- a/src/Device/Blitter.cpp
+++ b/src/Device/Blitter.cpp
@@ -18,19 +18,19 @@
#include "Reactor/Reactor.hpp"
#include "System/Half.hpp"
#include "System/Memory.hpp"
+#include "Vulkan/VkBuffer.hpp"
#include "Vulkan/VkDebug.hpp"
#include "Vulkan/VkImage.hpp"
-#include "Vulkan/VkBuffer.hpp"
#include <utility>
namespace sw {
-Blitter::Blitter() :
- blitMutex(),
- blitCache(1024),
- cornerUpdateMutex(),
- cornerUpdateCache(64) // We only need one of these per format
+Blitter::Blitter()
+ : blitMutex()
+ , blitCache(1024)
+ , cornerUpdateMutex()
+ , cornerUpdateCache(64) // We only need one of these per format
{
}
@@ -38,7 +38,7 @@
{
}
-void Blitter::clear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea)
+void Blitter::clear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format &viewFormat, const VkImageSubresourceRange &subresourceRange, const VkRect2D *renderArea)
{
VkImageAspectFlagBits aspect = static_cast<VkImageAspectFlagBits>(subresourceRange.aspectMask);
vk::Format dstFormat = viewFormat.getAspectFormat(aspect);
@@ -75,8 +75,7 @@
return;
}
- VkImageSubresourceLayers subresLayers =
- {
+ VkImageSubresourceLayers subresLayers = {
subresourceRange.aspectMask,
subresourceRange.baseMipLevel,
subresourceRange.baseArrayLayer,
@@ -102,21 +101,20 @@
area.extent.height = extent.height;
}
- BlitData data =
- {
- pixel, nullptr, // source, dest
+ BlitData data = {
+ pixel, nullptr, // source, dest
- format.bytes(), // sPitchB
- dest->rowPitchBytes(aspect, subresLayers.mipLevel), // dPitchB
- 0, // sSliceB (unused in clear operations)
- dest->slicePitchBytes(aspect, subresLayers.mipLevel), // dSliceB
+ format.bytes(), // sPitchB
+ dest->rowPitchBytes(aspect, subresLayers.mipLevel), // dPitchB
+ 0, // sSliceB (unused in clear operations)
+ dest->slicePitchBytes(aspect, subresLayers.mipLevel), // dSliceB
- 0.5f, 0.5f, 0.0f, 0.0f, // x0, y0, w, h
+ 0.5f, 0.5f, 0.0f, 0.0f, // x0, y0, w, h
- area.offset.y, static_cast<int>(area.offset.y + area.extent.height), // y0d, y1d
- area.offset.x, static_cast<int>(area.offset.x + area.extent.width), // x0d, x1d
+ area.offset.y, static_cast<int>(area.offset.y + area.extent.height), // y0d, y1d
+ area.offset.x, static_cast<int>(area.offset.x + area.extent.width), // x0d, x1d
- 0, 0, // sWidth, sHeight
+ 0, 0, // sWidth, sHeight
};
if(renderArea && dest->is3DSlice())
@@ -126,7 +124,7 @@
subresLayers.layerCount = 1;
for(uint32_t depth = subresourceRange.baseArrayLayer; depth <= lastLayer; depth++)
{
- data.dest = dest->getTexelPointer({0, 0, static_cast<int32_t>(depth)}, subresLayers);
+ data.dest = dest->getTexelPointer({ 0, 0, static_cast<int32_t>(depth) }, subresLayers);
blitRoutine(&data);
}
}
@@ -145,14 +143,14 @@
}
}
-bool Blitter::fastClear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea)
+bool Blitter::fastClear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format &viewFormat, const VkImageSubresourceRange &subresourceRange, const VkRect2D *renderArea)
{
if(format != VK_FORMAT_R32G32B32A32_SFLOAT)
{
return false;
}
- float *color = (float*)pixel;
+ float *color = (float *)pixel;
float r = color[0];
float g = color[1];
float b = color[2];
@@ -163,42 +161,41 @@
VkImageAspectFlagBits aspect = static_cast<VkImageAspectFlagBits>(subresourceRange.aspectMask);
switch(viewFormat)
{
- case VK_FORMAT_R5G6B5_UNORM_PACK16:
- packed = ((uint16_t)(31 * b + 0.5f) << 0) |
- ((uint16_t)(63 * g + 0.5f) << 5) |
- ((uint16_t)(31 * r + 0.5f) << 11);
- break;
- case VK_FORMAT_B5G6R5_UNORM_PACK16:
- packed = ((uint16_t)(31 * r + 0.5f) << 0) |
- ((uint16_t)(63 * g + 0.5f) << 5) |
- ((uint16_t)(31 * b + 0.5f) << 11);
- break;
- case VK_FORMAT_A8B8G8R8_UINT_PACK32:
- case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
- case VK_FORMAT_R8G8B8A8_UNORM:
- packed = ((uint32_t)(255 * a + 0.5f) << 24) |
- ((uint32_t)(255 * b + 0.5f) << 16) |
- ((uint32_t)(255 * g + 0.5f) << 8) |
- ((uint32_t)(255 * r + 0.5f) << 0);
- break;
- case VK_FORMAT_B8G8R8A8_UNORM:
- packed = ((uint32_t)(255 * a + 0.5f) << 24) |
- ((uint32_t)(255 * r + 0.5f) << 16) |
- ((uint32_t)(255 * g + 0.5f) << 8) |
- ((uint32_t)(255 * b + 0.5f) << 0);
- break;
- case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
- packed = R11G11B10F(color);
- break;
- case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
- packed = RGB9E5(color);
- break;
- default:
- return false;
+ case VK_FORMAT_R5G6B5_UNORM_PACK16:
+ packed = ((uint16_t)(31 * b + 0.5f) << 0) |
+ ((uint16_t)(63 * g + 0.5f) << 5) |
+ ((uint16_t)(31 * r + 0.5f) << 11);
+ break;
+ case VK_FORMAT_B5G6R5_UNORM_PACK16:
+ packed = ((uint16_t)(31 * r + 0.5f) << 0) |
+ ((uint16_t)(63 * g + 0.5f) << 5) |
+ ((uint16_t)(31 * b + 0.5f) << 11);
+ break;
+ case VK_FORMAT_A8B8G8R8_UINT_PACK32:
+ case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
+ case VK_FORMAT_R8G8B8A8_UNORM:
+ packed = ((uint32_t)(255 * a + 0.5f) << 24) |
+ ((uint32_t)(255 * b + 0.5f) << 16) |
+ ((uint32_t)(255 * g + 0.5f) << 8) |
+ ((uint32_t)(255 * r + 0.5f) << 0);
+ break;
+ case VK_FORMAT_B8G8R8A8_UNORM:
+ packed = ((uint32_t)(255 * a + 0.5f) << 24) |
+ ((uint32_t)(255 * r + 0.5f) << 16) |
+ ((uint32_t)(255 * g + 0.5f) << 8) |
+ ((uint32_t)(255 * b + 0.5f) << 0);
+ break;
+ case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
+ packed = R11G11B10F(color);
+ break;
+ case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
+ packed = RGB9E5(color);
+ break;
+ default:
+ return false;
}
- VkImageSubresourceLayers subresLayers =
- {
+ VkImageSubresourceLayers subresLayers = {
subresourceRange.aspectMask,
subresourceRange.baseMipLevel,
subresourceRange.baseArrayLayer,
@@ -226,15 +223,15 @@
}
if(dest->is3DSlice())
{
- extent.depth = 1; // The 3D image is instead interpreted as a 2D image with layers
+ extent.depth = 1; // The 3D image is instead interpreted as a 2D image with layers
}
for(subresLayers.baseArrayLayer = subresourceRange.baseArrayLayer; subresLayers.baseArrayLayer <= lastLayer; subresLayers.baseArrayLayer++)
{
for(uint32_t depth = 0; depth < extent.depth; depth++)
{
- uint8_t *slice = (uint8_t*)dest->getTexelPointer(
- { area.offset.x, area.offset.y, static_cast<int32_t>(depth) }, subresLayers);
+ uint8_t *slice = (uint8_t *)dest->getTexelPointer(
+ { area.offset.x, area.offset.y, static_cast<int32_t>(depth) }, subresLayers);
for(int j = 0; j < dest->getSampleCountFlagBits(); j++)
{
@@ -242,24 +239,24 @@
switch(viewFormat.bytes())
{
- case 2:
- for(uint32_t i = 0; i < area.extent.height; i++)
- {
- ASSERT(d < dest->end());
- sw::clear((uint16_t*)d, static_cast<uint16_t>(packed), area.extent.width);
- d += rowPitchBytes;
- }
- break;
- case 4:
- for(uint32_t i = 0; i < area.extent.height; i++)
- {
- ASSERT(d < dest->end());
- sw::clear((uint32_t*)d, packed, area.extent.width);
- d += rowPitchBytes;
- }
- break;
- default:
- assert(false);
+ case 2:
+ for(uint32_t i = 0; i < area.extent.height; i++)
+ {
+ ASSERT(d < dest->end());
+ sw::clear((uint16_t *)d, static_cast<uint16_t>(packed), area.extent.width);
+ d += rowPitchBytes;
+ }
+ break;
+ case 4:
+ for(uint32_t i = 0; i < area.extent.height; i++)
+ {
+ ASSERT(d < dest->end());
+ sw::clear((uint32_t *)d, packed, area.extent.width);
+ d += rowPitchBytes;
+ }
+ break;
+ default:
+ assert(false);
}
slice += slicePitchBytes;
@@ -277,178 +274,178 @@
switch(state.sourceFormat)
{
- case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
- c.w = Float(Int(*Pointer<Byte>(element)) & Int(0xF));
- c.x = Float((Int(*Pointer<Byte>(element)) >> 4) & Int(0xF));
- c.y = Float(Int(*Pointer<Byte>(element + 1)) & Int(0xF));
- c.z = Float((Int(*Pointer<Byte>(element + 1)) >> 4) & Int(0xF));
- break;
- case VK_FORMAT_R8_SINT:
- case VK_FORMAT_R8_SNORM:
- c.x = Float(Int(*Pointer<SByte>(element)));
- c.w = float(0x7F);
- break;
- case VK_FORMAT_R8_UNORM:
- case VK_FORMAT_R8_UINT:
- case VK_FORMAT_R8_SRGB:
- c.x = Float(Int(*Pointer<Byte>(element)));
- c.w = float(0xFF);
- break;
- case VK_FORMAT_R16_SINT:
- case VK_FORMAT_R16_SNORM:
- c.x = Float(Int(*Pointer<Short>(element)));
- c.w = float(0x7FFF);
- break;
- case VK_FORMAT_R16_UNORM:
- case VK_FORMAT_R16_UINT:
- c.x = Float(Int(*Pointer<UShort>(element)));
- c.w = float(0xFFFF);
- break;
- case VK_FORMAT_R32_SINT:
- c.x = Float(*Pointer<Int>(element));
- c.w = float(0x7FFFFFFF);
- break;
- case VK_FORMAT_R32_UINT:
- c.x = Float(*Pointer<UInt>(element));
- c.w = float(0xFFFFFFFF);
- break;
- case VK_FORMAT_B8G8R8A8_SRGB:
- case VK_FORMAT_B8G8R8A8_UNORM:
- c = Float4(*Pointer<Byte4>(element)).zyxw;
- break;
- case VK_FORMAT_A8B8G8R8_SINT_PACK32:
- case VK_FORMAT_R8G8B8A8_SINT:
- case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
- case VK_FORMAT_R8G8B8A8_SNORM:
- c = Float4(*Pointer<SByte4>(element));
- break;
- case VK_FORMAT_A8B8G8R8_UINT_PACK32:
- case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
- case VK_FORMAT_R8G8B8A8_UNORM:
- case VK_FORMAT_R8G8B8A8_UINT:
- case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
- case VK_FORMAT_R8G8B8A8_SRGB:
- c = Float4(*Pointer<Byte4>(element));
- break;
- case VK_FORMAT_R16G16B16A16_SINT:
- c = Float4(*Pointer<Short4>(element));
- break;
- case VK_FORMAT_R16G16B16A16_UNORM:
- case VK_FORMAT_R16G16B16A16_UINT:
- c = Float4(*Pointer<UShort4>(element));
- break;
- case VK_FORMAT_R32G32B32A32_SINT:
- c = Float4(*Pointer<Int4>(element));
- break;
- case VK_FORMAT_R32G32B32A32_UINT:
- c = Float4(*Pointer<UInt4>(element));
- break;
- case VK_FORMAT_R8G8_SINT:
- case VK_FORMAT_R8G8_SNORM:
- c.x = Float(Int(*Pointer<SByte>(element + 0)));
- c.y = Float(Int(*Pointer<SByte>(element + 1)));
- c.w = float(0x7F);
- break;
- case VK_FORMAT_R8G8_UNORM:
- case VK_FORMAT_R8G8_UINT:
- case VK_FORMAT_R8G8_SRGB:
- c.x = Float(Int(*Pointer<Byte>(element + 0)));
- c.y = Float(Int(*Pointer<Byte>(element + 1)));
- c.w = float(0xFF);
- break;
- case VK_FORMAT_R16G16_SINT:
- case VK_FORMAT_R16G16_SNORM:
- c.x = Float(Int(*Pointer<Short>(element + 0)));
- c.y = Float(Int(*Pointer<Short>(element + 2)));
- c.w = float(0x7FFF);
- break;
- case VK_FORMAT_R16G16_UNORM:
- case VK_FORMAT_R16G16_UINT:
- c.x = Float(Int(*Pointer<UShort>(element + 0)));
- c.y = Float(Int(*Pointer<UShort>(element + 2)));
- c.w = float(0xFFFF);
- break;
- case VK_FORMAT_R32G32_SINT:
- c.x = Float(*Pointer<Int>(element + 0));
- c.y = Float(*Pointer<Int>(element + 4));
- c.w = float(0x7FFFFFFF);
- break;
- case VK_FORMAT_R32G32_UINT:
- c.x = Float(*Pointer<UInt>(element + 0));
- c.y = Float(*Pointer<UInt>(element + 4));
- c.w = float(0xFFFFFFFF);
- break;
- case VK_FORMAT_R32G32B32A32_SFLOAT:
- c = *Pointer<Float4>(element);
- break;
- case VK_FORMAT_R32G32_SFLOAT:
- c.x = *Pointer<Float>(element + 0);
- c.y = *Pointer<Float>(element + 4);
- break;
- case VK_FORMAT_R32_SFLOAT:
- c.x = *Pointer<Float>(element);
- break;
- case VK_FORMAT_R16G16B16A16_SFLOAT:
- c.w = Float(*Pointer<Half>(element + 6));
- case VK_FORMAT_R16G16B16_SFLOAT:
- c.z = Float(*Pointer<Half>(element + 4));
- case VK_FORMAT_R16G16_SFLOAT:
- c.y = Float(*Pointer<Half>(element + 2));
- case VK_FORMAT_R16_SFLOAT:
- c.x = Float(*Pointer<Half>(element));
- break;
- case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
- c = r11g11b10Unpack(*Pointer<UInt>(element));
- break;
- case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
- // This type contains a common 5 bit exponent (E) and a 9 bit the mantissa for R, G and B.
- c.x = Float(*Pointer<UInt>(element) & UInt(0x000001FF)); // R's mantissa (bits 0-8)
- c.y = Float((*Pointer<UInt>(element) & UInt(0x0003FE00)) >> 9); // G's mantissa (bits 9-17)
- c.z = Float((*Pointer<UInt>(element) & UInt(0x07FC0000)) >> 18); // B's mantissa (bits 18-26)
- c *= Float4(
- // 2^E, using the exponent (bits 27-31) and treating it as an unsigned integer value
- Float(UInt(1) << ((*Pointer<UInt>(element) & UInt(0xF8000000)) >> 27)) *
- // Since the 9 bit mantissa values currently stored in RGB were converted straight
- // from int to float (in the [0, 1<<9] range instead of the [0, 1] range), they
- // are (1 << 9) times too high.
- // Also, the exponent has 5 bits and we compute the exponent bias of floating point
- // formats using "2^(k-1) - 1", so, in this case, the exponent bias is 2^(5-1)-1 = 15
- // Exponent bias (15) + number of mantissa bits per component (9) = 24
- Float(1.0f / (1 << 24)));
- c.w = 1.0f;
- break;
- case VK_FORMAT_R5G6B5_UNORM_PACK16:
- c.x = Float(Int((*Pointer<UShort>(element) & UShort(0xF800)) >> UShort(11)));
- c.y = Float(Int((*Pointer<UShort>(element) & UShort(0x07E0)) >> UShort(5)));
- c.z = Float(Int(*Pointer<UShort>(element) & UShort(0x001F)));
- break;
- case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
- c.w = Float(Int((*Pointer<UShort>(element) & UShort(0x8000)) >> UShort(15)));
- c.x = Float(Int((*Pointer<UShort>(element) & UShort(0x7C00)) >> UShort(10)));
- c.y = Float(Int((*Pointer<UShort>(element) & UShort(0x03E0)) >> UShort(5)));
- c.z = Float(Int(*Pointer<UShort>(element) & UShort(0x001F)));
- break;
- case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
- case VK_FORMAT_A2B10G10R10_UINT_PACK32:
- c.x = Float(Int((*Pointer<UInt>(element) & UInt(0x000003FF))));
- c.y = Float(Int((*Pointer<UInt>(element) & UInt(0x000FFC00)) >> 10));
- c.z = Float(Int((*Pointer<UInt>(element) & UInt(0x3FF00000)) >> 20));
- c.w = Float(Int((*Pointer<UInt>(element) & UInt(0xC0000000)) >> 30));
- break;
- case VK_FORMAT_D16_UNORM:
- c.x = Float(Int((*Pointer<UShort>(element))));
- break;
- case VK_FORMAT_X8_D24_UNORM_PACK32:
- c.x = Float(Int((*Pointer<UInt>(element) & UInt(0xFFFFFF00)) >> 8));
- break;
- case VK_FORMAT_D32_SFLOAT:
- c.x = *Pointer<Float>(element);
- break;
- case VK_FORMAT_S8_UINT:
- c.x = Float(Int(*Pointer<Byte>(element)));
- break;
- default:
- UNSUPPORTED("Blitter source format %d", (int)state.sourceFormat);
+ case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
+ c.w = Float(Int(*Pointer<Byte>(element)) & Int(0xF));
+ c.x = Float((Int(*Pointer<Byte>(element)) >> 4) & Int(0xF));
+ c.y = Float(Int(*Pointer<Byte>(element + 1)) & Int(0xF));
+ c.z = Float((Int(*Pointer<Byte>(element + 1)) >> 4) & Int(0xF));
+ break;
+ case VK_FORMAT_R8_SINT:
+ case VK_FORMAT_R8_SNORM:
+ c.x = Float(Int(*Pointer<SByte>(element)));
+ c.w = float(0x7F);
+ break;
+ case VK_FORMAT_R8_UNORM:
+ case VK_FORMAT_R8_UINT:
+ case VK_FORMAT_R8_SRGB:
+ c.x = Float(Int(*Pointer<Byte>(element)));
+ c.w = float(0xFF);
+ break;
+ case VK_FORMAT_R16_SINT:
+ case VK_FORMAT_R16_SNORM:
+ c.x = Float(Int(*Pointer<Short>(element)));
+ c.w = float(0x7FFF);
+ break;
+ case VK_FORMAT_R16_UNORM:
+ case VK_FORMAT_R16_UINT:
+ c.x = Float(Int(*Pointer<UShort>(element)));
+ c.w = float(0xFFFF);
+ break;
+ case VK_FORMAT_R32_SINT:
+ c.x = Float(*Pointer<Int>(element));
+ c.w = float(0x7FFFFFFF);
+ break;
+ case VK_FORMAT_R32_UINT:
+ c.x = Float(*Pointer<UInt>(element));
+ c.w = float(0xFFFFFFFF);
+ break;
+ case VK_FORMAT_B8G8R8A8_SRGB:
+ case VK_FORMAT_B8G8R8A8_UNORM:
+ c = Float4(*Pointer<Byte4>(element)).zyxw;
+ break;
+ case VK_FORMAT_A8B8G8R8_SINT_PACK32:
+ case VK_FORMAT_R8G8B8A8_SINT:
+ case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
+ case VK_FORMAT_R8G8B8A8_SNORM:
+ c = Float4(*Pointer<SByte4>(element));
+ break;
+ case VK_FORMAT_A8B8G8R8_UINT_PACK32:
+ case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
+ case VK_FORMAT_R8G8B8A8_UNORM:
+ case VK_FORMAT_R8G8B8A8_UINT:
+ case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
+ case VK_FORMAT_R8G8B8A8_SRGB:
+ c = Float4(*Pointer<Byte4>(element));
+ break;
+ case VK_FORMAT_R16G16B16A16_SINT:
+ c = Float4(*Pointer<Short4>(element));
+ break;
+ case VK_FORMAT_R16G16B16A16_UNORM:
+ case VK_FORMAT_R16G16B16A16_UINT:
+ c = Float4(*Pointer<UShort4>(element));
+ break;
+ case VK_FORMAT_R32G32B32A32_SINT:
+ c = Float4(*Pointer<Int4>(element));
+ break;
+ case VK_FORMAT_R32G32B32A32_UINT:
+ c = Float4(*Pointer<UInt4>(element));
+ break;
+ case VK_FORMAT_R8G8_SINT:
+ case VK_FORMAT_R8G8_SNORM:
+ c.x = Float(Int(*Pointer<SByte>(element + 0)));
+ c.y = Float(Int(*Pointer<SByte>(element + 1)));
+ c.w = float(0x7F);
+ break;
+ case VK_FORMAT_R8G8_UNORM:
+ case VK_FORMAT_R8G8_UINT:
+ case VK_FORMAT_R8G8_SRGB:
+ c.x = Float(Int(*Pointer<Byte>(element + 0)));
+ c.y = Float(Int(*Pointer<Byte>(element + 1)));
+ c.w = float(0xFF);
+ break;
+ case VK_FORMAT_R16G16_SINT:
+ case VK_FORMAT_R16G16_SNORM:
+ c.x = Float(Int(*Pointer<Short>(element + 0)));
+ c.y = Float(Int(*Pointer<Short>(element + 2)));
+ c.w = float(0x7FFF);
+ break;
+ case VK_FORMAT_R16G16_UNORM:
+ case VK_FORMAT_R16G16_UINT:
+ c.x = Float(Int(*Pointer<UShort>(element + 0)));
+ c.y = Float(Int(*Pointer<UShort>(element + 2)));
+ c.w = float(0xFFFF);
+ break;
+ case VK_FORMAT_R32G32_SINT:
+ c.x = Float(*Pointer<Int>(element + 0));
+ c.y = Float(*Pointer<Int>(element + 4));
+ c.w = float(0x7FFFFFFF);
+ break;
+ case VK_FORMAT_R32G32_UINT:
+ c.x = Float(*Pointer<UInt>(element + 0));
+ c.y = Float(*Pointer<UInt>(element + 4));
+ c.w = float(0xFFFFFFFF);
+ break;
+ case VK_FORMAT_R32G32B32A32_SFLOAT:
+ c = *Pointer<Float4>(element);
+ break;
+ case VK_FORMAT_R32G32_SFLOAT:
+ c.x = *Pointer<Float>(element + 0);
+ c.y = *Pointer<Float>(element + 4);
+ break;
+ case VK_FORMAT_R32_SFLOAT:
+ c.x = *Pointer<Float>(element);
+ break;
+ case VK_FORMAT_R16G16B16A16_SFLOAT:
+ c.w = Float(*Pointer<Half>(element + 6));
+ case VK_FORMAT_R16G16B16_SFLOAT:
+ c.z = Float(*Pointer<Half>(element + 4));
+ case VK_FORMAT_R16G16_SFLOAT:
+ c.y = Float(*Pointer<Half>(element + 2));
+ case VK_FORMAT_R16_SFLOAT:
+ c.x = Float(*Pointer<Half>(element));
+ break;
+ case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
+ c = r11g11b10Unpack(*Pointer<UInt>(element));
+ break;
+ case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
+ // This type contains a common 5 bit exponent (E) and a 9 bit the mantissa for R, G and B.
+ c.x = Float(*Pointer<UInt>(element) & UInt(0x000001FF)); // R's mantissa (bits 0-8)
+ c.y = Float((*Pointer<UInt>(element) & UInt(0x0003FE00)) >> 9); // G's mantissa (bits 9-17)
+ c.z = Float((*Pointer<UInt>(element) & UInt(0x07FC0000)) >> 18); // B's mantissa (bits 18-26)
+ c *= Float4(
+ // 2^E, using the exponent (bits 27-31) and treating it as an unsigned integer value
+ Float(UInt(1) << ((*Pointer<UInt>(element) & UInt(0xF8000000)) >> 27)) *
+ // Since the 9 bit mantissa values currently stored in RGB were converted straight
+ // from int to float (in the [0, 1<<9] range instead of the [0, 1] range), they
+ // are (1 << 9) times too high.
+ // Also, the exponent has 5 bits and we compute the exponent bias of floating point
+ // formats using "2^(k-1) - 1", so, in this case, the exponent bias is 2^(5-1)-1 = 15
+ // Exponent bias (15) + number of mantissa bits per component (9) = 24
+ Float(1.0f / (1 << 24)));
+ c.w = 1.0f;
+ break;
+ case VK_FORMAT_R5G6B5_UNORM_PACK16:
+ c.x = Float(Int((*Pointer<UShort>(element) & UShort(0xF800)) >> UShort(11)));
+ c.y = Float(Int((*Pointer<UShort>(element) & UShort(0x07E0)) >> UShort(5)));
+ c.z = Float(Int(*Pointer<UShort>(element) & UShort(0x001F)));
+ break;
+ case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
+ c.w = Float(Int((*Pointer<UShort>(element) & UShort(0x8000)) >> UShort(15)));
+ c.x = Float(Int((*Pointer<UShort>(element) & UShort(0x7C00)) >> UShort(10)));
+ c.y = Float(Int((*Pointer<UShort>(element) & UShort(0x03E0)) >> UShort(5)));
+ c.z = Float(Int(*Pointer<UShort>(element) & UShort(0x001F)));
+ break;
+ case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
+ case VK_FORMAT_A2B10G10R10_UINT_PACK32:
+ c.x = Float(Int((*Pointer<UInt>(element) & UInt(0x000003FF))));
+ c.y = Float(Int((*Pointer<UInt>(element) & UInt(0x000FFC00)) >> 10));
+ c.z = Float(Int((*Pointer<UInt>(element) & UInt(0x3FF00000)) >> 20));
+ c.w = Float(Int((*Pointer<UInt>(element) & UInt(0xC0000000)) >> 30));
+ break;
+ case VK_FORMAT_D16_UNORM:
+ c.x = Float(Int((*Pointer<UShort>(element))));
+ break;
+ case VK_FORMAT_X8_D24_UNORM_PACK32:
+ c.x = Float(Int((*Pointer<UInt>(element) & UInt(0xFFFFFF00)) >> 8));
+ break;
+ case VK_FORMAT_D32_SFLOAT:
+ c.x = *Pointer<Float>(element);
+ break;
+ case VK_FORMAT_S8_UINT:
+ c.x = Float(Int(*Pointer<Byte>(element)));
+ break;
+ default:
+ UNSUPPORTED("Blitter source format %d", (int)state.sourceFormat);
}
return c;
@@ -464,150 +461,147 @@
switch(state.destFormat)
{
- case VK_FORMAT_R4G4_UNORM_PACK8:
- if(writeR | writeG)
- {
- if(!writeR)
+ case VK_FORMAT_R4G4_UNORM_PACK8:
+ if(writeR | writeG)
{
- *Pointer<Byte>(element) = (Byte(RoundInt(Float(c.y))) & Byte(0xF)) |
- (*Pointer<Byte>(element) & Byte(0xF0));
+ if(!writeR)
+ {
+ *Pointer<Byte>(element) = (Byte(RoundInt(Float(c.y))) & Byte(0xF)) |
+ (*Pointer<Byte>(element) & Byte(0xF0));
+ }
+ else if(!writeG)
+ {
+ *Pointer<Byte>(element) = (*Pointer<Byte>(element) & Byte(0xF)) |
+ (Byte(RoundInt(Float(c.x))) << Byte(4));
+ }
+ else
+ {
+ *Pointer<Byte>(element) = (Byte(RoundInt(Float(c.y))) & Byte(0xF)) |
+ (Byte(RoundInt(Float(c.x))) << Byte(4));
+ }
}
- else if(!writeG)
+ break;
+ case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
+ if(writeR || writeG || writeB || writeA)
{
- *Pointer<Byte>(element) = (*Pointer<Byte>(element) & Byte(0xF)) |
- (Byte(RoundInt(Float(c.x))) << Byte(4));
+ *Pointer<UShort>(element) = (writeR ? ((UShort(RoundInt(Float(c.x))) & UShort(0xF)) << UShort(12)) : (*Pointer<UShort>(element) & UShort(0x000F))) |
+ (writeG ? ((UShort(RoundInt(Float(c.y))) & UShort(0xF)) << UShort(8)) : (*Pointer<UShort>(element) & UShort(0x00F0))) |
+ (writeB ? ((UShort(RoundInt(Float(c.z))) & UShort(0xF)) << UShort(4)) : (*Pointer<UShort>(element) & UShort(0x0F00))) |
+ (writeA ? (UShort(RoundInt(Float(c.w))) & UShort(0xF)) : (*Pointer<UShort>(element) & UShort(0xF000)));
+ }
+ break;
+ case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
+ if(writeRGBA)
+ {
+ *Pointer<UShort>(element) = UShort(RoundInt(Float(c.w)) & Int(0xF)) |
+ UShort((RoundInt(Float(c.x)) & Int(0xF)) << 4) |
+ UShort((RoundInt(Float(c.y)) & Int(0xF)) << 8) |
+ UShort((RoundInt(Float(c.z)) & Int(0xF)) << 12);
}
else
{
- *Pointer<Byte>(element) = (Byte(RoundInt(Float(c.y))) & Byte(0xF)) |
- (Byte(RoundInt(Float(c.x))) << Byte(4));
+ unsigned short mask = (writeA ? 0x000F : 0x0000) |
+ (writeR ? 0x00F0 : 0x0000) |
+ (writeG ? 0x0F00 : 0x0000) |
+ (writeB ? 0xF000 : 0x0000);
+ unsigned short unmask = ~mask;
+ *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
+ ((UShort(RoundInt(Float(c.w)) & Int(0xF)) |
+ UShort((RoundInt(Float(c.x)) & Int(0xF)) << 4) |
+ UShort((RoundInt(Float(c.y)) & Int(0xF)) << 8) |
+ UShort((RoundInt(Float(c.z)) & Int(0xF)) << 12)) &
+ UShort(mask));
}
- }
- break;
- case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
- if(writeR || writeG || writeB || writeA)
- {
- *Pointer<UShort>(element) = (writeR ? ((UShort(RoundInt(Float(c.x))) & UShort(0xF)) << UShort(12)) :
- (*Pointer<UShort>(element) & UShort(0x000F))) |
- (writeG ? ((UShort(RoundInt(Float(c.y))) & UShort(0xF)) << UShort(8)) :
- (*Pointer<UShort>(element) & UShort(0x00F0))) |
- (writeB ? ((UShort(RoundInt(Float(c.z))) & UShort(0xF)) << UShort(4)) :
- (*Pointer<UShort>(element) & UShort(0x0F00))) |
- (writeA ? (UShort(RoundInt(Float(c.w))) & UShort(0xF)) :
- (*Pointer<UShort>(element) & UShort(0xF000)));
- }
- break;
- case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
- if(writeRGBA)
- {
- *Pointer<UShort>(element) = UShort(RoundInt(Float(c.w)) & Int(0xF)) |
- UShort((RoundInt(Float(c.x)) & Int(0xF)) << 4) |
- UShort((RoundInt(Float(c.y)) & Int(0xF)) << 8) |
- UShort((RoundInt(Float(c.z)) & Int(0xF)) << 12);
- }
- else
- {
- unsigned short mask = (writeA ? 0x000F : 0x0000) |
- (writeR ? 0x00F0 : 0x0000) |
- (writeG ? 0x0F00 : 0x0000) |
- (writeB ? 0xF000 : 0x0000);
- unsigned short unmask = ~mask;
- *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
- ((UShort(RoundInt(Float(c.w)) & Int(0xF)) |
- UShort((RoundInt(Float(c.x)) & Int(0xF)) << 4) |
- UShort((RoundInt(Float(c.y)) & Int(0xF)) << 8) |
- UShort((RoundInt(Float(c.z)) & Int(0xF)) << 12)) & UShort(mask));
- }
- break;
- case VK_FORMAT_B8G8R8A8_SRGB:
- case VK_FORMAT_B8G8R8A8_UNORM:
- if(writeRGBA)
- {
- Short4 c0 = RoundShort4(c.zyxw);
- *Pointer<Byte4>(element) = Byte4(PackUnsigned(c0, c0));
- }
- else
- {
+ break;
+ case VK_FORMAT_B8G8R8A8_SRGB:
+ case VK_FORMAT_B8G8R8A8_UNORM:
+ if(writeRGBA)
+ {
+ Short4 c0 = RoundShort4(c.zyxw);
+ *Pointer<Byte4>(element) = Byte4(PackUnsigned(c0, c0));
+ }
+ else
+ {
+ if(writeB) { *Pointer<Byte>(element + 0) = Byte(RoundInt(Float(c.z))); }
+ if(writeG) { *Pointer<Byte>(element + 1) = Byte(RoundInt(Float(c.y))); }
+ if(writeR) { *Pointer<Byte>(element + 2) = Byte(RoundInt(Float(c.x))); }
+ if(writeA) { *Pointer<Byte>(element + 3) = Byte(RoundInt(Float(c.w))); }
+ }
+ break;
+ case VK_FORMAT_B8G8R8_SNORM:
+ if(writeB) { *Pointer<SByte>(element + 0) = SByte(RoundInt(Float(c.z))); }
+ if(writeG) { *Pointer<SByte>(element + 1) = SByte(RoundInt(Float(c.y))); }
+ if(writeR) { *Pointer<SByte>(element + 2) = SByte(RoundInt(Float(c.x))); }
+ break;
+ case VK_FORMAT_B8G8R8_UNORM:
+ case VK_FORMAT_B8G8R8_SRGB:
if(writeB) { *Pointer<Byte>(element + 0) = Byte(RoundInt(Float(c.z))); }
if(writeG) { *Pointer<Byte>(element + 1) = Byte(RoundInt(Float(c.y))); }
if(writeR) { *Pointer<Byte>(element + 2) = Byte(RoundInt(Float(c.x))); }
- if(writeA) { *Pointer<Byte>(element + 3) = Byte(RoundInt(Float(c.w))); }
- }
- break;
- case VK_FORMAT_B8G8R8_SNORM:
- if(writeB) { *Pointer<SByte>(element + 0) = SByte(RoundInt(Float(c.z))); }
- if(writeG) { *Pointer<SByte>(element + 1) = SByte(RoundInt(Float(c.y))); }
- if(writeR) { *Pointer<SByte>(element + 2) = SByte(RoundInt(Float(c.x))); }
- break;
- case VK_FORMAT_B8G8R8_UNORM:
- case VK_FORMAT_B8G8R8_SRGB:
- if(writeB) { *Pointer<Byte>(element + 0) = Byte(RoundInt(Float(c.z))); }
- if(writeG) { *Pointer<Byte>(element + 1) = Byte(RoundInt(Float(c.y))); }
- if(writeR) { *Pointer<Byte>(element + 2) = Byte(RoundInt(Float(c.x))); }
- break;
- case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
- case VK_FORMAT_R8G8B8A8_UNORM:
- case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
- case VK_FORMAT_R8G8B8A8_SRGB:
- case VK_FORMAT_A8B8G8R8_UINT_PACK32:
- case VK_FORMAT_R8G8B8A8_UINT:
- case VK_FORMAT_R8G8B8A8_USCALED:
- case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
- if(writeRGBA)
- {
- Short4 c0 = RoundShort4(c);
- *Pointer<Byte4>(element) = Byte4(PackUnsigned(c0, c0));
- }
- else
- {
- if(writeR) { *Pointer<Byte>(element + 0) = Byte(RoundInt(Float(c.x))); }
- if(writeG) { *Pointer<Byte>(element + 1) = Byte(RoundInt(Float(c.y))); }
- if(writeB) { *Pointer<Byte>(element + 2) = Byte(RoundInt(Float(c.z))); }
- if(writeA) { *Pointer<Byte>(element + 3) = Byte(RoundInt(Float(c.w))); }
- }
- break;
- case VK_FORMAT_R32G32B32A32_SFLOAT:
- if(writeRGBA)
- {
- *Pointer<Float4>(element) = c;
- }
- else
- {
+ break;
+ case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
+ case VK_FORMAT_R8G8B8A8_UNORM:
+ case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
+ case VK_FORMAT_R8G8B8A8_SRGB:
+ case VK_FORMAT_A8B8G8R8_UINT_PACK32:
+ case VK_FORMAT_R8G8B8A8_UINT:
+ case VK_FORMAT_R8G8B8A8_USCALED:
+ case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
+ if(writeRGBA)
+ {
+ Short4 c0 = RoundShort4(c);
+ *Pointer<Byte4>(element) = Byte4(PackUnsigned(c0, c0));
+ }
+ else
+ {
+ if(writeR) { *Pointer<Byte>(element + 0) = Byte(RoundInt(Float(c.x))); }
+ if(writeG) { *Pointer<Byte>(element + 1) = Byte(RoundInt(Float(c.y))); }
+ if(writeB) { *Pointer<Byte>(element + 2) = Byte(RoundInt(Float(c.z))); }
+ if(writeA) { *Pointer<Byte>(element + 3) = Byte(RoundInt(Float(c.w))); }
+ }
+ break;
+ case VK_FORMAT_R32G32B32A32_SFLOAT:
+ if(writeRGBA)
+ {
+ *Pointer<Float4>(element) = c;
+ }
+ else
+ {
+ if(writeR) { *Pointer<Float>(element) = c.x; }
+ if(writeG) { *Pointer<Float>(element + 4) = c.y; }
+ if(writeB) { *Pointer<Float>(element + 8) = c.z; }
+ if(writeA) { *Pointer<Float>(element + 12) = c.w; }
+ }
+ break;
+ case VK_FORMAT_R32G32B32_SFLOAT:
if(writeR) { *Pointer<Float>(element) = c.x; }
if(writeG) { *Pointer<Float>(element + 4) = c.y; }
if(writeB) { *Pointer<Float>(element + 8) = c.z; }
- if(writeA) { *Pointer<Float>(element + 12) = c.w; }
- }
- break;
- case VK_FORMAT_R32G32B32_SFLOAT:
- if(writeR) { *Pointer<Float>(element) = c.x; }
- if(writeG) { *Pointer<Float>(element + 4) = c.y; }
- if(writeB) { *Pointer<Float>(element + 8) = c.z; }
- break;
- case VK_FORMAT_R32G32_SFLOAT:
- if(writeR && writeG)
- {
- *Pointer<Float2>(element) = Float2(c);
- }
- else
- {
+ break;
+ case VK_FORMAT_R32G32_SFLOAT:
+ if(writeR && writeG)
+ {
+ *Pointer<Float2>(element) = Float2(c);
+ }
+ else
+ {
+ if(writeR) { *Pointer<Float>(element) = c.x; }
+ if(writeG) { *Pointer<Float>(element + 4) = c.y; }
+ }
+ break;
+ case VK_FORMAT_R32_SFLOAT:
if(writeR) { *Pointer<Float>(element) = c.x; }
- if(writeG) { *Pointer<Float>(element + 4) = c.y; }
- }
- break;
- case VK_FORMAT_R32_SFLOAT:
- if(writeR) { *Pointer<Float>(element) = c.x; }
- break;
- case VK_FORMAT_R16G16B16A16_SFLOAT:
- if(writeA) { *Pointer<Half>(element + 6) = Half(c.w); }
- case VK_FORMAT_R16G16B16_SFLOAT:
- if(writeB) { *Pointer<Half>(element + 4) = Half(c.z); }
- case VK_FORMAT_R16G16_SFLOAT:
- if(writeG) { *Pointer<Half>(element + 2) = Half(c.y); }
- case VK_FORMAT_R16_SFLOAT:
- if(writeR) { *Pointer<Half>(element) = Half(c.x); }
- break;
- case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
+ break;
+ case VK_FORMAT_R16G16B16A16_SFLOAT:
+ if(writeA) { *Pointer<Half>(element + 6) = Half(c.w); }
+ case VK_FORMAT_R16G16B16_SFLOAT:
+ if(writeB) { *Pointer<Half>(element + 4) = Half(c.z); }
+ case VK_FORMAT_R16G16_SFLOAT:
+ if(writeG) { *Pointer<Half>(element + 2) = Half(c.y); }
+ case VK_FORMAT_R16_SFLOAT:
+ if(writeR) { *Pointer<Half>(element) = Half(c.x); }
+ break;
+ case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
{
UInt rgb = r11g11b10Pack(c);
@@ -620,7 +614,7 @@
*Pointer<UInt>(element) = (rgb & mask) | (old & ~mask);
}
break;
- case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
+ case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
{
ASSERT(writeRGBA); // Can't sensibly write just part of this format.
@@ -634,9 +628,9 @@
constexpr float sharedexp_max = ((static_cast<float>(1 << N) - 1) / static_cast<float>(1 << N)) * static_cast<float>(1 << (E_max - B));
// Clamp components to valid range. NaN becomes 0.
- Float red_c = Min(IfThenElse(!(c.x > 0), Float(0), Float(c.x)), sharedexp_max);
+ Float red_c = Min(IfThenElse(!(c.x > 0), Float(0), Float(c.x)), sharedexp_max);
Float green_c = Min(IfThenElse(!(c.y > 0), Float(0), Float(c.y)), sharedexp_max);
- Float blue_c = Min(IfThenElse(!(c.z > 0), Float(0), Float(c.z)), sharedexp_max);
+ Float blue_c = Min(IfThenElse(!(c.z > 0), Float(0), Float(c.z)), sharedexp_max);
// We're reducing the mantissa to 9 bits, so we must round up if the next
// bit is 1. In other words add 0.5 to the new mantissa's position and
@@ -666,314 +660,320 @@
*Pointer<UInt>(element) = E5B9G9R9;
}
break;
- case VK_FORMAT_B8G8R8A8_SNORM:
- if(writeB) { *Pointer<SByte>(element) = SByte(RoundInt(Float(c.z))); }
- if(writeG) { *Pointer<SByte>(element + 1) = SByte(RoundInt(Float(c.y))); }
- if(writeR) { *Pointer<SByte>(element + 2) = SByte(RoundInt(Float(c.x))); }
- if(writeA) { *Pointer<SByte>(element + 3) = SByte(RoundInt(Float(c.w))); }
- break;
- case VK_FORMAT_A8B8G8R8_SINT_PACK32:
- case VK_FORMAT_R8G8B8A8_SINT:
- case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
- case VK_FORMAT_R8G8B8A8_SNORM:
- case VK_FORMAT_R8G8B8A8_SSCALED:
- case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
- if(writeA) { *Pointer<SByte>(element + 3) = SByte(RoundInt(Float(c.w))); }
- case VK_FORMAT_R8G8B8_SINT:
- case VK_FORMAT_R8G8B8_SNORM:
- case VK_FORMAT_R8G8B8_SSCALED:
- if(writeB) { *Pointer<SByte>(element + 2) = SByte(RoundInt(Float(c.z))); }
- case VK_FORMAT_R8G8_SINT:
- case VK_FORMAT_R8G8_SNORM:
- case VK_FORMAT_R8G8_SSCALED:
- if(writeG) { *Pointer<SByte>(element + 1) = SByte(RoundInt(Float(c.y))); }
- case VK_FORMAT_R8_SINT:
- case VK_FORMAT_R8_SNORM:
- case VK_FORMAT_R8_SSCALED:
- if(writeR) { *Pointer<SByte>(element) = SByte(RoundInt(Float(c.x))); }
- break;
- case VK_FORMAT_R8G8B8_UINT:
- case VK_FORMAT_R8G8B8_UNORM:
- case VK_FORMAT_R8G8B8_USCALED:
- case VK_FORMAT_R8G8B8_SRGB:
- if(writeB) { *Pointer<Byte>(element + 2) = Byte(RoundInt(Float(c.z))); }
- case VK_FORMAT_R8G8_UINT:
- case VK_FORMAT_R8G8_UNORM:
- case VK_FORMAT_R8G8_USCALED:
- case VK_FORMAT_R8G8_SRGB:
- if(writeG) { *Pointer<Byte>(element + 1) = Byte(RoundInt(Float(c.y))); }
- case VK_FORMAT_R8_UINT:
- case VK_FORMAT_R8_UNORM:
- case VK_FORMAT_R8_USCALED:
- case VK_FORMAT_R8_SRGB:
- if(writeR) { *Pointer<Byte>(element) = Byte(RoundInt(Float(c.x))); }
- break;
- case VK_FORMAT_R16G16B16A16_SINT:
- case VK_FORMAT_R16G16B16A16_SNORM:
- case VK_FORMAT_R16G16B16A16_SSCALED:
- if(writeRGBA)
- {
- *Pointer<Short4>(element) = Short4(RoundInt(c));
- }
- else
- {
+ case VK_FORMAT_B8G8R8A8_SNORM:
+ if(writeB) { *Pointer<SByte>(element) = SByte(RoundInt(Float(c.z))); }
+ if(writeG) { *Pointer<SByte>(element + 1) = SByte(RoundInt(Float(c.y))); }
+ if(writeR) { *Pointer<SByte>(element + 2) = SByte(RoundInt(Float(c.x))); }
+ if(writeA) { *Pointer<SByte>(element + 3) = SByte(RoundInt(Float(c.w))); }
+ break;
+ case VK_FORMAT_A8B8G8R8_SINT_PACK32:
+ case VK_FORMAT_R8G8B8A8_SINT:
+ case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
+ case VK_FORMAT_R8G8B8A8_SNORM:
+ case VK_FORMAT_R8G8B8A8_SSCALED:
+ case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
+ if(writeA) { *Pointer<SByte>(element + 3) = SByte(RoundInt(Float(c.w))); }
+ case VK_FORMAT_R8G8B8_SINT:
+ case VK_FORMAT_R8G8B8_SNORM:
+ case VK_FORMAT_R8G8B8_SSCALED:
+ if(writeB) { *Pointer<SByte>(element + 2) = SByte(RoundInt(Float(c.z))); }
+ case VK_FORMAT_R8G8_SINT:
+ case VK_FORMAT_R8G8_SNORM:
+ case VK_FORMAT_R8G8_SSCALED:
+ if(writeG) { *Pointer<SByte>(element + 1) = SByte(RoundInt(Float(c.y))); }
+ case VK_FORMAT_R8_SINT:
+ case VK_FORMAT_R8_SNORM:
+ case VK_FORMAT_R8_SSCALED:
+ if(writeR) { *Pointer<SByte>(element) = SByte(RoundInt(Float(c.x))); }
+ break;
+ case VK_FORMAT_R8G8B8_UINT:
+ case VK_FORMAT_R8G8B8_UNORM:
+ case VK_FORMAT_R8G8B8_USCALED:
+ case VK_FORMAT_R8G8B8_SRGB:
+ if(writeB) { *Pointer<Byte>(element + 2) = Byte(RoundInt(Float(c.z))); }
+ case VK_FORMAT_R8G8_UINT:
+ case VK_FORMAT_R8G8_UNORM:
+ case VK_FORMAT_R8G8_USCALED:
+ case VK_FORMAT_R8G8_SRGB:
+ if(writeG) { *Pointer<Byte>(element + 1) = Byte(RoundInt(Float(c.y))); }
+ case VK_FORMAT_R8_UINT:
+ case VK_FORMAT_R8_UNORM:
+ case VK_FORMAT_R8_USCALED:
+ case VK_FORMAT_R8_SRGB:
+ if(writeR) { *Pointer<Byte>(element) = Byte(RoundInt(Float(c.x))); }
+ break;
+ case VK_FORMAT_R16G16B16A16_SINT:
+ case VK_FORMAT_R16G16B16A16_SNORM:
+ case VK_FORMAT_R16G16B16A16_SSCALED:
+ if(writeRGBA)
+ {
+ *Pointer<Short4>(element) = Short4(RoundInt(c));
+ }
+ else
+ {
+ if(writeR) { *Pointer<Short>(element) = Short(RoundInt(Float(c.x))); }
+ if(writeG) { *Pointer<Short>(element + 2) = Short(RoundInt(Float(c.y))); }
+ if(writeB) { *Pointer<Short>(element + 4) = Short(RoundInt(Float(c.z))); }
+ if(writeA) { *Pointer<Short>(element + 6) = Short(RoundInt(Float(c.w))); }
+ }
+ break;
+ case VK_FORMAT_R16G16B16_SINT:
+ case VK_FORMAT_R16G16B16_SNORM:
+ case VK_FORMAT_R16G16B16_SSCALED:
if(writeR) { *Pointer<Short>(element) = Short(RoundInt(Float(c.x))); }
if(writeG) { *Pointer<Short>(element + 2) = Short(RoundInt(Float(c.y))); }
if(writeB) { *Pointer<Short>(element + 4) = Short(RoundInt(Float(c.z))); }
- if(writeA) { *Pointer<Short>(element + 6) = Short(RoundInt(Float(c.w))); }
- }
- break;
- case VK_FORMAT_R16G16B16_SINT:
- case VK_FORMAT_R16G16B16_SNORM:
- case VK_FORMAT_R16G16B16_SSCALED:
- if(writeR) { *Pointer<Short>(element) = Short(RoundInt(Float(c.x))); }
- if(writeG) { *Pointer<Short>(element + 2) = Short(RoundInt(Float(c.y))); }
- if(writeB) { *Pointer<Short>(element + 4) = Short(RoundInt(Float(c.z))); }
- break;
- case VK_FORMAT_R16G16_SINT:
- case VK_FORMAT_R16G16_SNORM:
- case VK_FORMAT_R16G16_SSCALED:
- if(writeR && writeG)
- {
- *Pointer<Short2>(element) = Short2(Short4(RoundInt(c)));
- }
- else
- {
+ break;
+ case VK_FORMAT_R16G16_SINT:
+ case VK_FORMAT_R16G16_SNORM:
+ case VK_FORMAT_R16G16_SSCALED:
+ if(writeR && writeG)
+ {
+ *Pointer<Short2>(element) = Short2(Short4(RoundInt(c)));
+ }
+ else
+ {
+ if(writeR) { *Pointer<Short>(element) = Short(RoundInt(Float(c.x))); }
+ if(writeG) { *Pointer<Short>(element + 2) = Short(RoundInt(Float(c.y))); }
+ }
+ break;
+ case VK_FORMAT_R16_SINT:
+ case VK_FORMAT_R16_SNORM:
+ case VK_FORMAT_R16_SSCALED:
if(writeR) { *Pointer<Short>(element) = Short(RoundInt(Float(c.x))); }
- if(writeG) { *Pointer<Short>(element + 2) = Short(RoundInt(Float(c.y))); }
- }
- break;
- case VK_FORMAT_R16_SINT:
- case VK_FORMAT_R16_SNORM:
- case VK_FORMAT_R16_SSCALED:
- if(writeR) { *Pointer<Short>(element) = Short(RoundInt(Float(c.x))); }
- break;
- case VK_FORMAT_R16G16B16A16_UINT:
- case VK_FORMAT_R16G16B16A16_UNORM:
- case VK_FORMAT_R16G16B16A16_USCALED:
- if(writeRGBA)
- {
- *Pointer<UShort4>(element) = UShort4(RoundInt(c));
- }
- else
- {
+ break;
+ case VK_FORMAT_R16G16B16A16_UINT:
+ case VK_FORMAT_R16G16B16A16_UNORM:
+ case VK_FORMAT_R16G16B16A16_USCALED:
+ if(writeRGBA)
+ {
+ *Pointer<UShort4>(element) = UShort4(RoundInt(c));
+ }
+ else
+ {
+ if(writeR) { *Pointer<UShort>(element) = UShort(RoundInt(Float(c.x))); }
+ if(writeG) { *Pointer<UShort>(element + 2) = UShort(RoundInt(Float(c.y))); }
+ if(writeB) { *Pointer<UShort>(element + 4) = UShort(RoundInt(Float(c.z))); }
+ if(writeA) { *Pointer<UShort>(element + 6) = UShort(RoundInt(Float(c.w))); }
+ }
+ break;
+ case VK_FORMAT_R16G16B16_UINT:
+ case VK_FORMAT_R16G16B16_UNORM:
+ case VK_FORMAT_R16G16B16_USCALED:
if(writeR) { *Pointer<UShort>(element) = UShort(RoundInt(Float(c.x))); }
if(writeG) { *Pointer<UShort>(element + 2) = UShort(RoundInt(Float(c.y))); }
if(writeB) { *Pointer<UShort>(element + 4) = UShort(RoundInt(Float(c.z))); }
- if(writeA) { *Pointer<UShort>(element + 6) = UShort(RoundInt(Float(c.w))); }
- }
- break;
- case VK_FORMAT_R16G16B16_UINT:
- case VK_FORMAT_R16G16B16_UNORM:
- case VK_FORMAT_R16G16B16_USCALED:
- if(writeR) { *Pointer<UShort>(element) = UShort(RoundInt(Float(c.x))); }
- if(writeG) { *Pointer<UShort>(element + 2) = UShort(RoundInt(Float(c.y))); }
- if(writeB) { *Pointer<UShort>(element + 4) = UShort(RoundInt(Float(c.z))); }
- break;
- case VK_FORMAT_R16G16_UINT:
- case VK_FORMAT_R16G16_UNORM:
- case VK_FORMAT_R16G16_USCALED:
- if(writeR && writeG)
- {
- *Pointer<UShort2>(element) = UShort2(UShort4(RoundInt(c)));
- }
- else
- {
+ break;
+ case VK_FORMAT_R16G16_UINT:
+ case VK_FORMAT_R16G16_UNORM:
+ case VK_FORMAT_R16G16_USCALED:
+ if(writeR && writeG)
+ {
+ *Pointer<UShort2>(element) = UShort2(UShort4(RoundInt(c)));
+ }
+ else
+ {
+ if(writeR) { *Pointer<UShort>(element) = UShort(RoundInt(Float(c.x))); }
+ if(writeG) { *Pointer<UShort>(element + 2) = UShort(RoundInt(Float(c.y))); }
+ }
+ break;
+ case VK_FORMAT_R16_UINT:
+ case VK_FORMAT_R16_UNORM:
+ case VK_FORMAT_R16_USCALED:
if(writeR) { *Pointer<UShort>(element) = UShort(RoundInt(Float(c.x))); }
- if(writeG) { *Pointer<UShort>(element + 2) = UShort(RoundInt(Float(c.y))); }
- }
- break;
- case VK_FORMAT_R16_UINT:
- case VK_FORMAT_R16_UNORM:
- case VK_FORMAT_R16_USCALED:
- if(writeR) { *Pointer<UShort>(element) = UShort(RoundInt(Float(c.x))); }
- break;
- case VK_FORMAT_R32G32B32A32_SINT:
- if(writeRGBA)
- {
- *Pointer<Int4>(element) = RoundInt(c);
- }
- else
- {
- if(writeR) { *Pointer<Int>(element) = RoundInt(Float(c.x)); }
- if(writeG) { *Pointer<Int>(element + 4) = RoundInt(Float(c.y)); }
+ break;
+ case VK_FORMAT_R32G32B32A32_SINT:
+ if(writeRGBA)
+ {
+ *Pointer<Int4>(element) = RoundInt(c);
+ }
+ else
+ {
+ if(writeR) { *Pointer<Int>(element) = RoundInt(Float(c.x)); }
+ if(writeG) { *Pointer<Int>(element + 4) = RoundInt(Float(c.y)); }
+ if(writeB) { *Pointer<Int>(element + 8) = RoundInt(Float(c.z)); }
+ if(writeA) { *Pointer<Int>(element + 12) = RoundInt(Float(c.w)); }
+ }
+ break;
+ case VK_FORMAT_R32G32B32_SINT:
if(writeB) { *Pointer<Int>(element + 8) = RoundInt(Float(c.z)); }
- if(writeA) { *Pointer<Int>(element + 12) = RoundInt(Float(c.w)); }
- }
- break;
- case VK_FORMAT_R32G32B32_SINT:
- if(writeB) { *Pointer<Int>(element + 8) = RoundInt(Float(c.z)); }
- case VK_FORMAT_R32G32_SINT:
- if(writeG) { *Pointer<Int>(element + 4) = RoundInt(Float(c.y)); }
- case VK_FORMAT_R32_SINT:
- if(writeR) { *Pointer<Int>(element) = RoundInt(Float(c.x)); }
- break;
- case VK_FORMAT_R32G32B32A32_UINT:
- if(writeRGBA)
- {
- *Pointer<UInt4>(element) = UInt4(RoundInt(c));
- }
- else
- {
- if(writeR) { *Pointer<UInt>(element) = As<UInt>(RoundInt(Float(c.x))); }
- if(writeG) { *Pointer<UInt>(element + 4) = As<UInt>(RoundInt(Float(c.y))); }
+ case VK_FORMAT_R32G32_SINT:
+ if(writeG) { *Pointer<Int>(element + 4) = RoundInt(Float(c.y)); }
+ case VK_FORMAT_R32_SINT:
+ if(writeR) { *Pointer<Int>(element) = RoundInt(Float(c.x)); }
+ break;
+ case VK_FORMAT_R32G32B32A32_UINT:
+ if(writeRGBA)
+ {
+ *Pointer<UInt4>(element) = UInt4(RoundInt(c));
+ }
+ else
+ {
+ if(writeR) { *Pointer<UInt>(element) = As<UInt>(RoundInt(Float(c.x))); }
+ if(writeG) { *Pointer<UInt>(element + 4) = As<UInt>(RoundInt(Float(c.y))); }
+ if(writeB) { *Pointer<UInt>(element + 8) = As<UInt>(RoundInt(Float(c.z))); }
+ if(writeA) { *Pointer<UInt>(element + 12) = As<UInt>(RoundInt(Float(c.w))); }
+ }
+ break;
+ case VK_FORMAT_R32G32B32_UINT:
if(writeB) { *Pointer<UInt>(element + 8) = As<UInt>(RoundInt(Float(c.z))); }
- if(writeA) { *Pointer<UInt>(element + 12) = As<UInt>(RoundInt(Float(c.w))); }
- }
- break;
- case VK_FORMAT_R32G32B32_UINT:
- if(writeB) { *Pointer<UInt>(element + 8) = As<UInt>(RoundInt(Float(c.z))); }
- case VK_FORMAT_R32G32_UINT:
- if(writeG) { *Pointer<UInt>(element + 4) = As<UInt>(RoundInt(Float(c.y))); }
- case VK_FORMAT_R32_UINT:
- if(writeR) { *Pointer<UInt>(element) = As<UInt>(RoundInt(Float(c.x))); }
- break;
- case VK_FORMAT_R5G6B5_UNORM_PACK16:
- if(writeR && writeG && writeB)
- {
- *Pointer<UShort>(element) = UShort(RoundInt(Float(c.z)) |
- (RoundInt(Float(c.y)) << Int(5)) |
- (RoundInt(Float(c.x)) << Int(11)));
- }
- else
- {
- unsigned short mask = (writeB ? 0x001F : 0x0000) | (writeG ? 0x07E0 : 0x0000) | (writeR ? 0xF800 : 0x0000);
- unsigned short unmask = ~mask;
- *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
- (UShort(RoundInt(Float(c.z)) |
- (RoundInt(Float(c.y)) << Int(5)) |
- (RoundInt(Float(c.x)) << Int(11))) & UShort(mask));
- }
- break;
- case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
- if(writeRGBA)
- {
- *Pointer<UShort>(element) = UShort(RoundInt(Float(c.w)) |
- (RoundInt(Float(c.z)) << Int(1)) |
- (RoundInt(Float(c.y)) << Int(6)) |
- (RoundInt(Float(c.x)) << Int(11)));
- }
- else
- {
- unsigned short mask = (writeA ? 0x8000 : 0x0000) |
- (writeR ? 0x7C00 : 0x0000) |
- (writeG ? 0x03E0 : 0x0000) |
- (writeB ? 0x001F : 0x0000);
- unsigned short unmask = ~mask;
- *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
- (UShort(RoundInt(Float(c.w)) |
- (RoundInt(Float(c.z)) << Int(1)) |
- (RoundInt(Float(c.y)) << Int(6)) |
- (RoundInt(Float(c.x)) << Int(11))) & UShort(mask));
- }
- break;
- case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
- if(writeRGBA)
- {
- *Pointer<UShort>(element) = UShort(RoundInt(Float(c.w)) |
- (RoundInt(Float(c.x)) << Int(1)) |
- (RoundInt(Float(c.y)) << Int(6)) |
- (RoundInt(Float(c.z)) << Int(11)));
- }
- else
- {
- unsigned short mask = (writeA ? 0x8000 : 0x0000) |
- (writeR ? 0x7C00 : 0x0000) |
- (writeG ? 0x03E0 : 0x0000) |
- (writeB ? 0x001F : 0x0000);
- unsigned short unmask = ~mask;
- *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
- (UShort(RoundInt(Float(c.w)) |
- (RoundInt(Float(c.x)) << Int(1)) |
- (RoundInt(Float(c.y)) << Int(6)) |
- (RoundInt(Float(c.z)) << Int(11))) & UShort(mask));
- }
- break;
- case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
- if(writeRGBA)
- {
- *Pointer<UShort>(element) = UShort(RoundInt(Float(c.z)) |
- (RoundInt(Float(c.y)) << Int(5)) |
- (RoundInt(Float(c.x)) << Int(10)) |
- (RoundInt(Float(c.w)) << Int(15)));
- }
- else
- {
- unsigned short mask = (writeA ? 0x8000 : 0x0000) |
- (writeR ? 0x7C00 : 0x0000) |
- (writeG ? 0x03E0 : 0x0000) |
- (writeB ? 0x001F : 0x0000);
- unsigned short unmask = ~mask;
- *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
- (UShort(RoundInt(Float(c.z)) |
- (RoundInt(Float(c.y)) << Int(5)) |
- (RoundInt(Float(c.x)) << Int(10)) |
- (RoundInt(Float(c.w)) << Int(15))) & UShort(mask));
- }
- break;
- case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
- case VK_FORMAT_A2B10G10R10_UINT_PACK32:
- case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
- if(writeRGBA)
- {
- *Pointer<UInt>(element) = UInt(RoundInt(Float(c.x)) |
- (RoundInt(Float(c.y)) << 10) |
- (RoundInt(Float(c.z)) << 20) |
- (RoundInt(Float(c.w)) << 30));
- }
- else
- {
- unsigned int mask = (writeA ? 0xC0000000 : 0x0000) |
- (writeB ? 0x3FF00000 : 0x0000) |
- (writeG ? 0x000FFC00 : 0x0000) |
- (writeR ? 0x000003FF : 0x0000);
- unsigned int unmask = ~mask;
- *Pointer<UInt>(element) = (*Pointer<UInt>(element) & UInt(unmask)) |
- (UInt(RoundInt(Float(c.x)) |
- (RoundInt(Float(c.y)) << 10) |
- (RoundInt(Float(c.z)) << 20) |
- (RoundInt(Float(c.w)) << 30)) & UInt(mask));
- }
- break;
- case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
- case VK_FORMAT_A2R10G10B10_UINT_PACK32:
- case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
- if(writeRGBA)
- {
- *Pointer<UInt>(element) = UInt(RoundInt(Float(c.z)) |
- (RoundInt(Float(c.y)) << 10) |
- (RoundInt(Float(c.x)) << 20) |
- (RoundInt(Float(c.w)) << 30));
- }
- else
- {
- unsigned int mask = (writeA ? 0xC0000000 : 0x0000) |
- (writeR ? 0x3FF00000 : 0x0000) |
- (writeG ? 0x000FFC00 : 0x0000) |
- (writeB ? 0x000003FF : 0x0000);
- unsigned int unmask = ~mask;
- *Pointer<UInt>(element) = (*Pointer<UInt>(element) & UInt(unmask)) |
- (UInt(RoundInt(Float(c.z)) |
- (RoundInt(Float(c.y)) << 10) |
- (RoundInt(Float(c.x)) << 20) |
- (RoundInt(Float(c.w)) << 30)) & UInt(mask));
- }
- break;
- case VK_FORMAT_D16_UNORM:
- *Pointer<UShort>(element) = UShort(RoundInt(Float(c.x)));
- break;
- case VK_FORMAT_X8_D24_UNORM_PACK32:
- *Pointer<UInt>(element) = UInt(RoundInt(Float(c.x)) << 8);
- break;
- case VK_FORMAT_D32_SFLOAT:
- *Pointer<Float>(element) = c.x;
- break;
- case VK_FORMAT_S8_UINT:
- *Pointer<Byte>(element) = Byte(RoundInt(Float(c.x)));
- break;
- default:
- UNSUPPORTED("Blitter destination format %d", (int)state.destFormat);
- break;
+ case VK_FORMAT_R32G32_UINT:
+ if(writeG) { *Pointer<UInt>(element + 4) = As<UInt>(RoundInt(Float(c.y))); }
+ case VK_FORMAT_R32_UINT:
+ if(writeR) { *Pointer<UInt>(element) = As<UInt>(RoundInt(Float(c.x))); }
+ break;
+ case VK_FORMAT_R5G6B5_UNORM_PACK16:
+ if(writeR && writeG && writeB)
+ {
+ *Pointer<UShort>(element) = UShort(RoundInt(Float(c.z)) |
+ (RoundInt(Float(c.y)) << Int(5)) |
+ (RoundInt(Float(c.x)) << Int(11)));
+ }
+ else
+ {
+ unsigned short mask = (writeB ? 0x001F : 0x0000) | (writeG ? 0x07E0 : 0x0000) | (writeR ? 0xF800 : 0x0000);
+ unsigned short unmask = ~mask;
+ *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
+ (UShort(RoundInt(Float(c.z)) |
+ (RoundInt(Float(c.y)) << Int(5)) |
+ (RoundInt(Float(c.x)) << Int(11))) &
+ UShort(mask));
+ }
+ break;
+ case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
+ if(writeRGBA)
+ {
+ *Pointer<UShort>(element) = UShort(RoundInt(Float(c.w)) |
+ (RoundInt(Float(c.z)) << Int(1)) |
+ (RoundInt(Float(c.y)) << Int(6)) |
+ (RoundInt(Float(c.x)) << Int(11)));
+ }
+ else
+ {
+ unsigned short mask = (writeA ? 0x8000 : 0x0000) |
+ (writeR ? 0x7C00 : 0x0000) |
+ (writeG ? 0x03E0 : 0x0000) |
+ (writeB ? 0x001F : 0x0000);
+ unsigned short unmask = ~mask;
+ *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
+ (UShort(RoundInt(Float(c.w)) |
+ (RoundInt(Float(c.z)) << Int(1)) |
+ (RoundInt(Float(c.y)) << Int(6)) |
+ (RoundInt(Float(c.x)) << Int(11))) &
+ UShort(mask));
+ }
+ break;
+ case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
+ if(writeRGBA)
+ {
+ *Pointer<UShort>(element) = UShort(RoundInt(Float(c.w)) |
+ (RoundInt(Float(c.x)) << Int(1)) |
+ (RoundInt(Float(c.y)) << Int(6)) |
+ (RoundInt(Float(c.z)) << Int(11)));
+ }
+ else
+ {
+ unsigned short mask = (writeA ? 0x8000 : 0x0000) |
+ (writeR ? 0x7C00 : 0x0000) |
+ (writeG ? 0x03E0 : 0x0000) |
+ (writeB ? 0x001F : 0x0000);
+ unsigned short unmask = ~mask;
+ *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
+ (UShort(RoundInt(Float(c.w)) |
+ (RoundInt(Float(c.x)) << Int(1)) |
+ (RoundInt(Float(c.y)) << Int(6)) |
+ (RoundInt(Float(c.z)) << Int(11))) &
+ UShort(mask));
+ }
+ break;
+ case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
+ if(writeRGBA)
+ {
+ *Pointer<UShort>(element) = UShort(RoundInt(Float(c.z)) |
+ (RoundInt(Float(c.y)) << Int(5)) |
+ (RoundInt(Float(c.x)) << Int(10)) |
+ (RoundInt(Float(c.w)) << Int(15)));
+ }
+ else
+ {
+ unsigned short mask = (writeA ? 0x8000 : 0x0000) |
+ (writeR ? 0x7C00 : 0x0000) |
+ (writeG ? 0x03E0 : 0x0000) |
+ (writeB ? 0x001F : 0x0000);
+ unsigned short unmask = ~mask;
+ *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
+ (UShort(RoundInt(Float(c.z)) |
+ (RoundInt(Float(c.y)) << Int(5)) |
+ (RoundInt(Float(c.x)) << Int(10)) |
+ (RoundInt(Float(c.w)) << Int(15))) &
+ UShort(mask));
+ }
+ break;
+ case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
+ case VK_FORMAT_A2B10G10R10_UINT_PACK32:
+ case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
+ if(writeRGBA)
+ {
+ *Pointer<UInt>(element) = UInt(RoundInt(Float(c.x)) |
+ (RoundInt(Float(c.y)) << 10) |
+ (RoundInt(Float(c.z)) << 20) |
+ (RoundInt(Float(c.w)) << 30));
+ }
+ else
+ {
+ unsigned int mask = (writeA ? 0xC0000000 : 0x0000) |
+ (writeB ? 0x3FF00000 : 0x0000) |
+ (writeG ? 0x000FFC00 : 0x0000) |
+ (writeR ? 0x000003FF : 0x0000);
+ unsigned int unmask = ~mask;
+ *Pointer<UInt>(element) = (*Pointer<UInt>(element) & UInt(unmask)) |
+ (UInt(RoundInt(Float(c.x)) |
+ (RoundInt(Float(c.y)) << 10) |
+ (RoundInt(Float(c.z)) << 20) |
+ (RoundInt(Float(c.w)) << 30)) &
+ UInt(mask));
+ }
+ break;
+ case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
+ case VK_FORMAT_A2R10G10B10_UINT_PACK32:
+ case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
+ if(writeRGBA)
+ {
+ *Pointer<UInt>(element) = UInt(RoundInt(Float(c.z)) |
+ (RoundInt(Float(c.y)) << 10) |
+ (RoundInt(Float(c.x)) << 20) |
+ (RoundInt(Float(c.w)) << 30));
+ }
+ else
+ {
+ unsigned int mask = (writeA ? 0xC0000000 : 0x0000) |
+ (writeR ? 0x3FF00000 : 0x0000) |
+ (writeG ? 0x000FFC00 : 0x0000) |
+ (writeB ? 0x000003FF : 0x0000);
+ unsigned int unmask = ~mask;
+ *Pointer<UInt>(element) = (*Pointer<UInt>(element) & UInt(unmask)) |
+ (UInt(RoundInt(Float(c.z)) |
+ (RoundInt(Float(c.y)) << 10) |
+ (RoundInt(Float(c.x)) << 20) |
+ (RoundInt(Float(c.w)) << 30)) &
+ UInt(mask));
+ }
+ break;
+ case VK_FORMAT_D16_UNORM:
+ *Pointer<UShort>(element) = UShort(RoundInt(Float(c.x)));
+ break;
+ case VK_FORMAT_X8_D24_UNORM_PACK32:
+ *Pointer<UInt>(element) = UInt(RoundInt(Float(c.x)) << 8);
+ break;
+ case VK_FORMAT_D32_SFLOAT:
+ *Pointer<Float>(element) = c.x;
+ break;
+ case VK_FORMAT_S8_UINT:
+ *Pointer<Byte>(element) = Byte(RoundInt(Float(c.x)));
+ break;
+ default:
+ UNSUPPORTED("Blitter destination format %d", (int)state.destFormat);
+ break;
}
}
@@ -983,60 +983,60 @@
switch(state.sourceFormat)
{
- case VK_FORMAT_A8B8G8R8_SINT_PACK32:
- case VK_FORMAT_R8G8B8A8_SINT:
- c = Insert(c, Int(*Pointer<SByte>(element + 3)), 3);
- c = Insert(c, Int(*Pointer<SByte>(element + 2)), 2);
- case VK_FORMAT_R8G8_SINT:
- c = Insert(c, Int(*Pointer<SByte>(element + 1)), 1);
- case VK_FORMAT_R8_SINT:
- c = Insert(c, Int(*Pointer<SByte>(element)), 0);
- break;
- case VK_FORMAT_A2B10G10R10_UINT_PACK32:
- c = Insert(c, Int((*Pointer<UInt>(element) & UInt(0x000003FF))), 0);
- c = Insert(c, Int((*Pointer<UInt>(element) & UInt(0x000FFC00)) >> 10), 1);
- c = Insert(c, Int((*Pointer<UInt>(element) & UInt(0x3FF00000)) >> 20), 2);
- c = Insert(c, Int((*Pointer<UInt>(element) & UInt(0xC0000000)) >> 30), 3);
- break;
- case VK_FORMAT_A8B8G8R8_UINT_PACK32:
- case VK_FORMAT_R8G8B8A8_UINT:
- c = Insert(c, Int(*Pointer<Byte>(element + 3)), 3);
- c = Insert(c, Int(*Pointer<Byte>(element + 2)), 2);
- case VK_FORMAT_R8G8_UINT:
- c = Insert(c, Int(*Pointer<Byte>(element + 1)), 1);
- case VK_FORMAT_R8_UINT:
- case VK_FORMAT_S8_UINT:
- c = Insert(c, Int(*Pointer<Byte>(element)), 0);
- break;
- case VK_FORMAT_R16G16B16A16_SINT:
- c = Insert(c, Int(*Pointer<Short>(element + 6)), 3);
- c = Insert(c, Int(*Pointer<Short>(element + 4)), 2);
- case VK_FORMAT_R16G16_SINT:
- c = Insert(c, Int(*Pointer<Short>(element + 2)), 1);
- case VK_FORMAT_R16_SINT:
- c = Insert(c, Int(*Pointer<Short>(element)), 0);
- break;
- case VK_FORMAT_R16G16B16A16_UINT:
- c = Insert(c, Int(*Pointer<UShort>(element + 6)), 3);
- c = Insert(c, Int(*Pointer<UShort>(element + 4)), 2);
- case VK_FORMAT_R16G16_UINT:
- c = Insert(c, Int(*Pointer<UShort>(element + 2)), 1);
- case VK_FORMAT_R16_UINT:
- c = Insert(c, Int(*Pointer<UShort>(element)), 0);
- break;
- case VK_FORMAT_R32G32B32A32_SINT:
- case VK_FORMAT_R32G32B32A32_UINT:
- c = *Pointer<Int4>(element);
- break;
- case VK_FORMAT_R32G32_SINT:
- case VK_FORMAT_R32G32_UINT:
- c = Insert(c, *Pointer<Int>(element + 4), 1);
- case VK_FORMAT_R32_SINT:
- case VK_FORMAT_R32_UINT:
- c = Insert(c, *Pointer<Int>(element), 0);
- break;
- default:
- UNSUPPORTED("Blitter source format %d", (int)state.sourceFormat);
+ case VK_FORMAT_A8B8G8R8_SINT_PACK32:
+ case VK_FORMAT_R8G8B8A8_SINT:
+ c = Insert(c, Int(*Pointer<SByte>(element + 3)), 3);
+ c = Insert(c, Int(*Pointer<SByte>(element + 2)), 2);
+ case VK_FORMAT_R8G8_SINT:
+ c = Insert(c, Int(*Pointer<SByte>(element + 1)), 1);
+ case VK_FORMAT_R8_SINT:
+ c = Insert(c, Int(*Pointer<SByte>(element)), 0);
+ break;
+ case VK_FORMAT_A2B10G10R10_UINT_PACK32:
+ c = Insert(c, Int((*Pointer<UInt>(element) & UInt(0x000003FF))), 0);
+ c = Insert(c, Int((*Pointer<UInt>(element) & UInt(0x000FFC00)) >> 10), 1);
+ c = Insert(c, Int((*Pointer<UInt>(element) & UInt(0x3FF00000)) >> 20), 2);
+ c = Insert(c, Int((*Pointer<UInt>(element) & UInt(0xC0000000)) >> 30), 3);
+ break;
+ case VK_FORMAT_A8B8G8R8_UINT_PACK32:
+ case VK_FORMAT_R8G8B8A8_UINT:
+ c = Insert(c, Int(*Pointer<Byte>(element + 3)), 3);
+ c = Insert(c, Int(*Pointer<Byte>(element + 2)), 2);
+ case VK_FORMAT_R8G8_UINT:
+ c = Insert(c, Int(*Pointer<Byte>(element + 1)), 1);
+ case VK_FORMAT_R8_UINT:
+ case VK_FORMAT_S8_UINT:
+ c = Insert(c, Int(*Pointer<Byte>(element)), 0);
+ break;
+ case VK_FORMAT_R16G16B16A16_SINT:
+ c = Insert(c, Int(*Pointer<Short>(element + 6)), 3);
+ c = Insert(c, Int(*Pointer<Short>(element + 4)), 2);
+ case VK_FORMAT_R16G16_SINT:
+ c = Insert(c, Int(*Pointer<Short>(element + 2)), 1);
+ case VK_FORMAT_R16_SINT:
+ c = Insert(c, Int(*Pointer<Short>(element)), 0);
+ break;
+ case VK_FORMAT_R16G16B16A16_UINT:
+ c = Insert(c, Int(*Pointer<UShort>(element + 6)), 3);
+ c = Insert(c, Int(*Pointer<UShort>(element + 4)), 2);
+ case VK_FORMAT_R16G16_UINT:
+ c = Insert(c, Int(*Pointer<UShort>(element + 2)), 1);
+ case VK_FORMAT_R16_UINT:
+ c = Insert(c, Int(*Pointer<UShort>(element)), 0);
+ break;
+ case VK_FORMAT_R32G32B32A32_SINT:
+ case VK_FORMAT_R32G32B32A32_UINT:
+ c = *Pointer<Int4>(element);
+ break;
+ case VK_FORMAT_R32G32_SINT:
+ case VK_FORMAT_R32G32_UINT:
+ c = Insert(c, *Pointer<Int>(element + 4), 1);
+ case VK_FORMAT_R32_SINT:
+ case VK_FORMAT_R32_UINT:
+ c = Insert(c, *Pointer<Int>(element), 0);
+ break;
+ default:
+ UNSUPPORTED("Blitter source format %d", (int)state.sourceFormat);
}
return c;
@@ -1052,220 +1052,220 @@
switch(state.destFormat)
{
- case VK_FORMAT_A2B10G10R10_UINT_PACK32:
- c = Min(As<UInt4>(c), UInt4(0x03FF, 0x03FF, 0x03FF, 0x0003));
- break;
- case VK_FORMAT_A8B8G8R8_UINT_PACK32:
- case VK_FORMAT_R8G8B8A8_UINT:
- case VK_FORMAT_R8G8B8_UINT:
- case VK_FORMAT_R8G8_UINT:
- case VK_FORMAT_R8_UINT:
- case VK_FORMAT_R8G8B8A8_USCALED:
- case VK_FORMAT_R8G8B8_USCALED:
- case VK_FORMAT_R8G8_USCALED:
- case VK_FORMAT_R8_USCALED:
- case VK_FORMAT_S8_UINT:
- c = Min(As<UInt4>(c), UInt4(0xFF));
- break;
- case VK_FORMAT_R16G16B16A16_UINT:
- case VK_FORMAT_R16G16B16_UINT:
- case VK_FORMAT_R16G16_UINT:
- case VK_FORMAT_R16_UINT:
- case VK_FORMAT_R16G16B16A16_USCALED:
- case VK_FORMAT_R16G16B16_USCALED:
- case VK_FORMAT_R16G16_USCALED:
- case VK_FORMAT_R16_USCALED:
- c = Min(As<UInt4>(c), UInt4(0xFFFF));
- break;
- case VK_FORMAT_A8B8G8R8_SINT_PACK32:
- case VK_FORMAT_R8G8B8A8_SINT:
- case VK_FORMAT_R8G8_SINT:
- case VK_FORMAT_R8_SINT:
- case VK_FORMAT_R8G8B8A8_SSCALED:
- case VK_FORMAT_R8G8B8_SSCALED:
- case VK_FORMAT_R8G8_SSCALED:
- case VK_FORMAT_R8_SSCALED:
- c = Min(Max(c, Int4(-0x80)), Int4(0x7F));
- break;
- case VK_FORMAT_R16G16B16A16_SINT:
- case VK_FORMAT_R16G16B16_SINT:
- case VK_FORMAT_R16G16_SINT:
- case VK_FORMAT_R16_SINT:
- case VK_FORMAT_R16G16B16A16_SSCALED:
- case VK_FORMAT_R16G16B16_SSCALED:
- case VK_FORMAT_R16G16_SSCALED:
- case VK_FORMAT_R16_SSCALED:
- c = Min(Max(c, Int4(-0x8000)), Int4(0x7FFF));
- break;
- default:
- break;
+ case VK_FORMAT_A2B10G10R10_UINT_PACK32:
+ c = Min(As<UInt4>(c), UInt4(0x03FF, 0x03FF, 0x03FF, 0x0003));
+ break;
+ case VK_FORMAT_A8B8G8R8_UINT_PACK32:
+ case VK_FORMAT_R8G8B8A8_UINT:
+ case VK_FORMAT_R8G8B8_UINT:
+ case VK_FORMAT_R8G8_UINT:
+ case VK_FORMAT_R8_UINT:
+ case VK_FORMAT_R8G8B8A8_USCALED:
+ case VK_FORMAT_R8G8B8_USCALED:
+ case VK_FORMAT_R8G8_USCALED:
+ case VK_FORMAT_R8_USCALED:
+ case VK_FORMAT_S8_UINT:
+ c = Min(As<UInt4>(c), UInt4(0xFF));
+ break;
+ case VK_FORMAT_R16G16B16A16_UINT:
+ case VK_FORMAT_R16G16B16_UINT:
+ case VK_FORMAT_R16G16_UINT:
+ case VK_FORMAT_R16_UINT:
+ case VK_FORMAT_R16G16B16A16_USCALED:
+ case VK_FORMAT_R16G16B16_USCALED:
+ case VK_FORMAT_R16G16_USCALED:
+ case VK_FORMAT_R16_USCALED:
+ c = Min(As<UInt4>(c), UInt4(0xFFFF));
+ break;
+ case VK_FORMAT_A8B8G8R8_SINT_PACK32:
+ case VK_FORMAT_R8G8B8A8_SINT:
+ case VK_FORMAT_R8G8_SINT:
+ case VK_FORMAT_R8_SINT:
+ case VK_FORMAT_R8G8B8A8_SSCALED:
+ case VK_FORMAT_R8G8B8_SSCALED:
+ case VK_FORMAT_R8G8_SSCALED:
+ case VK_FORMAT_R8_SSCALED:
+ c = Min(Max(c, Int4(-0x80)), Int4(0x7F));
+ break;
+ case VK_FORMAT_R16G16B16A16_SINT:
+ case VK_FORMAT_R16G16B16_SINT:
+ case VK_FORMAT_R16G16_SINT:
+ case VK_FORMAT_R16_SINT:
+ case VK_FORMAT_R16G16B16A16_SSCALED:
+ case VK_FORMAT_R16G16B16_SSCALED:
+ case VK_FORMAT_R16G16_SSCALED:
+ case VK_FORMAT_R16_SSCALED:
+ c = Min(Max(c, Int4(-0x8000)), Int4(0x7FFF));
+ break;
+ default:
+ break;
}
switch(state.destFormat)
{
- case VK_FORMAT_B8G8R8A8_SINT:
- case VK_FORMAT_B8G8R8A8_SSCALED:
- if(writeA) { *Pointer<SByte>(element + 3) = SByte(Extract(c, 3)); }
- case VK_FORMAT_B8G8R8_SINT:
- case VK_FORMAT_B8G8R8_SSCALED:
- if(writeB) { *Pointer<SByte>(element) = SByte(Extract(c, 2)); }
- if(writeG) { *Pointer<SByte>(element + 1) = SByte(Extract(c, 1)); }
- if(writeR) { *Pointer<SByte>(element + 2) = SByte(Extract(c, 0)); }
- break;
- case VK_FORMAT_A8B8G8R8_SINT_PACK32:
- case VK_FORMAT_R8G8B8A8_SINT:
- case VK_FORMAT_R8G8B8A8_SSCALED:
- case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
- if(writeA) { *Pointer<SByte>(element + 3) = SByte(Extract(c, 3)); }
- case VK_FORMAT_R8G8B8_SINT:
- case VK_FORMAT_R8G8B8_SSCALED:
- if(writeB) { *Pointer<SByte>(element + 2) = SByte(Extract(c, 2)); }
- case VK_FORMAT_R8G8_SINT:
- case VK_FORMAT_R8G8_SSCALED:
- if(writeG) { *Pointer<SByte>(element + 1) = SByte(Extract(c, 1)); }
- case VK_FORMAT_R8_SINT:
- case VK_FORMAT_R8_SSCALED:
- if(writeR) { *Pointer<SByte>(element) = SByte(Extract(c, 0)); }
- break;
- case VK_FORMAT_A2B10G10R10_UINT_PACK32:
- case VK_FORMAT_A2B10G10R10_SINT_PACK32:
- case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
- case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
- if(writeRGBA)
- {
- *Pointer<UInt>(element) =
- UInt((Extract(c, 0)) | (Extract(c, 1) << 10) | (Extract(c, 2) << 20) | (Extract(c, 3) << 30));
- }
- else
- {
- unsigned int mask = (writeA ? 0xC0000000 : 0x0000) |
- (writeB ? 0x3FF00000 : 0x0000) |
- (writeG ? 0x000FFC00 : 0x0000) |
- (writeR ? 0x000003FF : 0x0000);
- unsigned int unmask = ~mask;
- *Pointer<UInt>(element) = (*Pointer<UInt>(element) & UInt(unmask)) |
- (UInt(Extract(c, 0) | (Extract(c, 1) << 10) | (Extract(c, 2) << 20) | (Extract(c, 3) << 30)) & UInt(mask));
- }
- break;
- case VK_FORMAT_A2R10G10B10_UINT_PACK32:
- case VK_FORMAT_A2R10G10B10_SINT_PACK32:
- case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
- case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
- if(writeRGBA)
- {
- *Pointer<UInt>(element) =
- UInt((Extract(c, 2)) | (Extract(c, 1) << 10) | (Extract(c, 0) << 20) | (Extract(c, 3) << 30));
- }
- else
- {
- unsigned int mask = (writeA ? 0xC0000000 : 0x0000) |
- (writeR ? 0x3FF00000 : 0x0000) |
- (writeG ? 0x000FFC00 : 0x0000) |
- (writeB ? 0x000003FF : 0x0000);
- unsigned int unmask = ~mask;
- *Pointer<UInt>(element) = (*Pointer<UInt>(element) & UInt(unmask)) |
- (UInt(Extract(c, 2) | (Extract(c, 1) << 10) | (Extract(c, 0) << 20) | (Extract(c, 3) << 30)) & UInt(mask));
- }
- break;
- case VK_FORMAT_B8G8R8A8_UINT:
- case VK_FORMAT_B8G8R8A8_USCALED:
- if(writeA) { *Pointer<Byte>(element + 3) = Byte(Extract(c, 3)); }
- case VK_FORMAT_B8G8R8_UINT:
- case VK_FORMAT_B8G8R8_USCALED:
- case VK_FORMAT_B8G8R8_SRGB:
- if(writeB) { *Pointer<Byte>(element) = Byte(Extract(c, 2)); }
- if(writeG) { *Pointer<Byte>(element + 1) = Byte(Extract(c, 1)); }
- if(writeR) { *Pointer<Byte>(element + 2) = Byte(Extract(c, 0)); }
- break;
- case VK_FORMAT_A8B8G8R8_UINT_PACK32:
- case VK_FORMAT_R8G8B8A8_UINT:
- case VK_FORMAT_R8G8B8A8_USCALED:
- case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
- if(writeA) { *Pointer<Byte>(element + 3) = Byte(Extract(c, 3)); }
- case VK_FORMAT_R8G8B8_UINT:
- case VK_FORMAT_R8G8B8_USCALED:
- if(writeB) { *Pointer<Byte>(element + 2) = Byte(Extract(c, 2)); }
- case VK_FORMAT_R8G8_UINT:
- case VK_FORMAT_R8G8_USCALED:
- if(writeG) { *Pointer<Byte>(element + 1) = Byte(Extract(c, 1)); }
- case VK_FORMAT_R8_UINT:
- case VK_FORMAT_R8_USCALED:
- case VK_FORMAT_S8_UINT:
- if(writeR) { *Pointer<Byte>(element) = Byte(Extract(c, 0)); }
- break;
- case VK_FORMAT_R16G16B16A16_SINT:
- case VK_FORMAT_R16G16B16A16_SSCALED:
- if(writeA) { *Pointer<Short>(element + 6) = Short(Extract(c, 3)); }
- case VK_FORMAT_R16G16B16_SINT:
- case VK_FORMAT_R16G16B16_SSCALED:
- if(writeB) { *Pointer<Short>(element + 4) = Short(Extract(c, 2)); }
- case VK_FORMAT_R16G16_SINT:
- case VK_FORMAT_R16G16_SSCALED:
- if(writeG) { *Pointer<Short>(element + 2) = Short(Extract(c, 1)); }
- case VK_FORMAT_R16_SINT:
- case VK_FORMAT_R16_SSCALED:
- if(writeR) { *Pointer<Short>(element) = Short(Extract(c, 0)); }
- break;
- case VK_FORMAT_R16G16B16A16_UINT:
- case VK_FORMAT_R16G16B16A16_USCALED:
- if(writeA) { *Pointer<UShort>(element + 6) = UShort(Extract(c, 3)); }
- case VK_FORMAT_R16G16B16_UINT:
- case VK_FORMAT_R16G16B16_USCALED:
- if(writeB) { *Pointer<UShort>(element + 4) = UShort(Extract(c, 2)); }
- case VK_FORMAT_R16G16_UINT:
- case VK_FORMAT_R16G16_USCALED:
- if(writeG) { *Pointer<UShort>(element + 2) = UShort(Extract(c, 1)); }
- case VK_FORMAT_R16_UINT:
- case VK_FORMAT_R16_USCALED:
- if(writeR) { *Pointer<UShort>(element) = UShort(Extract(c, 0)); }
- break;
- case VK_FORMAT_R32G32B32A32_SINT:
- if(writeRGBA)
- {
- *Pointer<Int4>(element) = c;
- }
- else
- {
+ case VK_FORMAT_B8G8R8A8_SINT:
+ case VK_FORMAT_B8G8R8A8_SSCALED:
+ if(writeA) { *Pointer<SByte>(element + 3) = SByte(Extract(c, 3)); }
+ case VK_FORMAT_B8G8R8_SINT:
+ case VK_FORMAT_B8G8R8_SSCALED:
+ if(writeB) { *Pointer<SByte>(element) = SByte(Extract(c, 2)); }
+ if(writeG) { *Pointer<SByte>(element + 1) = SByte(Extract(c, 1)); }
+ if(writeR) { *Pointer<SByte>(element + 2) = SByte(Extract(c, 0)); }
+ break;
+ case VK_FORMAT_A8B8G8R8_SINT_PACK32:
+ case VK_FORMAT_R8G8B8A8_SINT:
+ case VK_FORMAT_R8G8B8A8_SSCALED:
+ case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
+ if(writeA) { *Pointer<SByte>(element + 3) = SByte(Extract(c, 3)); }
+ case VK_FORMAT_R8G8B8_SINT:
+ case VK_FORMAT_R8G8B8_SSCALED:
+ if(writeB) { *Pointer<SByte>(element + 2) = SByte(Extract(c, 2)); }
+ case VK_FORMAT_R8G8_SINT:
+ case VK_FORMAT_R8G8_SSCALED:
+ if(writeG) { *Pointer<SByte>(element + 1) = SByte(Extract(c, 1)); }
+ case VK_FORMAT_R8_SINT:
+ case VK_FORMAT_R8_SSCALED:
+ if(writeR) { *Pointer<SByte>(element) = SByte(Extract(c, 0)); }
+ break;
+ case VK_FORMAT_A2B10G10R10_UINT_PACK32:
+ case VK_FORMAT_A2B10G10R10_SINT_PACK32:
+ case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
+ case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
+ if(writeRGBA)
+ {
+ *Pointer<UInt>(element) =
+ UInt((Extract(c, 0)) | (Extract(c, 1) << 10) | (Extract(c, 2) << 20) | (Extract(c, 3) << 30));
+ }
+ else
+ {
+ unsigned int mask = (writeA ? 0xC0000000 : 0x0000) |
+ (writeB ? 0x3FF00000 : 0x0000) |
+ (writeG ? 0x000FFC00 : 0x0000) |
+ (writeR ? 0x000003FF : 0x0000);
+ unsigned int unmask = ~mask;
+ *Pointer<UInt>(element) = (*Pointer<UInt>(element) & UInt(unmask)) |
+ (UInt(Extract(c, 0) | (Extract(c, 1) << 10) | (Extract(c, 2) << 20) | (Extract(c, 3) << 30)) & UInt(mask));
+ }
+ break;
+ case VK_FORMAT_A2R10G10B10_UINT_PACK32:
+ case VK_FORMAT_A2R10G10B10_SINT_PACK32:
+ case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
+ case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
+ if(writeRGBA)
+ {
+ *Pointer<UInt>(element) =
+ UInt((Extract(c, 2)) | (Extract(c, 1) << 10) | (Extract(c, 0) << 20) | (Extract(c, 3) << 30));
+ }
+ else
+ {
+ unsigned int mask = (writeA ? 0xC0000000 : 0x0000) |
+ (writeR ? 0x3FF00000 : 0x0000) |
+ (writeG ? 0x000FFC00 : 0x0000) |
+ (writeB ? 0x000003FF : 0x0000);
+ unsigned int unmask = ~mask;
+ *Pointer<UInt>(element) = (*Pointer<UInt>(element) & UInt(unmask)) |
+ (UInt(Extract(c, 2) | (Extract(c, 1) << 10) | (Extract(c, 0) << 20) | (Extract(c, 3) << 30)) & UInt(mask));
+ }
+ break;
+ case VK_FORMAT_B8G8R8A8_UINT:
+ case VK_FORMAT_B8G8R8A8_USCALED:
+ if(writeA) { *Pointer<Byte>(element + 3) = Byte(Extract(c, 3)); }
+ case VK_FORMAT_B8G8R8_UINT:
+ case VK_FORMAT_B8G8R8_USCALED:
+ case VK_FORMAT_B8G8R8_SRGB:
+ if(writeB) { *Pointer<Byte>(element) = Byte(Extract(c, 2)); }
+ if(writeG) { *Pointer<Byte>(element + 1) = Byte(Extract(c, 1)); }
+ if(writeR) { *Pointer<Byte>(element + 2) = Byte(Extract(c, 0)); }
+ break;
+ case VK_FORMAT_A8B8G8R8_UINT_PACK32:
+ case VK_FORMAT_R8G8B8A8_UINT:
+ case VK_FORMAT_R8G8B8A8_USCALED:
+ case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
+ if(writeA) { *Pointer<Byte>(element + 3) = Byte(Extract(c, 3)); }
+ case VK_FORMAT_R8G8B8_UINT:
+ case VK_FORMAT_R8G8B8_USCALED:
+ if(writeB) { *Pointer<Byte>(element + 2) = Byte(Extract(c, 2)); }
+ case VK_FORMAT_R8G8_UINT:
+ case VK_FORMAT_R8G8_USCALED:
+ if(writeG) { *Pointer<Byte>(element + 1) = Byte(Extract(c, 1)); }
+ case VK_FORMAT_R8_UINT:
+ case VK_FORMAT_R8_USCALED:
+ case VK_FORMAT_S8_UINT:
+ if(writeR) { *Pointer<Byte>(element) = Byte(Extract(c, 0)); }
+ break;
+ case VK_FORMAT_R16G16B16A16_SINT:
+ case VK_FORMAT_R16G16B16A16_SSCALED:
+ if(writeA) { *Pointer<Short>(element + 6) = Short(Extract(c, 3)); }
+ case VK_FORMAT_R16G16B16_SINT:
+ case VK_FORMAT_R16G16B16_SSCALED:
+ if(writeB) { *Pointer<Short>(element + 4) = Short(Extract(c, 2)); }
+ case VK_FORMAT_R16G16_SINT:
+ case VK_FORMAT_R16G16_SSCALED:
+ if(writeG) { *Pointer<Short>(element + 2) = Short(Extract(c, 1)); }
+ case VK_FORMAT_R16_SINT:
+ case VK_FORMAT_R16_SSCALED:
+ if(writeR) { *Pointer<Short>(element) = Short(Extract(c, 0)); }
+ break;
+ case VK_FORMAT_R16G16B16A16_UINT:
+ case VK_FORMAT_R16G16B16A16_USCALED:
+ if(writeA) { *Pointer<UShort>(element + 6) = UShort(Extract(c, 3)); }
+ case VK_FORMAT_R16G16B16_UINT:
+ case VK_FORMAT_R16G16B16_USCALED:
+ if(writeB) { *Pointer<UShort>(element + 4) = UShort(Extract(c, 2)); }
+ case VK_FORMAT_R16G16_UINT:
+ case VK_FORMAT_R16G16_USCALED:
+ if(writeG) { *Pointer<UShort>(element + 2) = UShort(Extract(c, 1)); }
+ case VK_FORMAT_R16_UINT:
+ case VK_FORMAT_R16_USCALED:
+ if(writeR) { *Pointer<UShort>(element) = UShort(Extract(c, 0)); }
+ break;
+ case VK_FORMAT_R32G32B32A32_SINT:
+ if(writeRGBA)
+ {
+ *Pointer<Int4>(element) = c;
+ }
+ else
+ {
+ if(writeR) { *Pointer<Int>(element) = Extract(c, 0); }
+ if(writeG) { *Pointer<Int>(element + 4) = Extract(c, 1); }
+ if(writeB) { *Pointer<Int>(element + 8) = Extract(c, 2); }
+ if(writeA) { *Pointer<Int>(element + 12) = Extract(c, 3); }
+ }
+ break;
+ case VK_FORMAT_R32G32B32_SINT:
if(writeR) { *Pointer<Int>(element) = Extract(c, 0); }
if(writeG) { *Pointer<Int>(element + 4) = Extract(c, 1); }
if(writeB) { *Pointer<Int>(element + 8) = Extract(c, 2); }
- if(writeA) { *Pointer<Int>(element + 12) = Extract(c, 3); }
- }
- break;
- case VK_FORMAT_R32G32B32_SINT:
- if(writeR) { *Pointer<Int>(element) = Extract(c, 0); }
- if(writeG) { *Pointer<Int>(element + 4) = Extract(c, 1); }
- if(writeB) { *Pointer<Int>(element + 8) = Extract(c, 2); }
- break;
- case VK_FORMAT_R32G32_SINT:
- if(writeR) { *Pointer<Int>(element) = Extract(c, 0); }
- if(writeG) { *Pointer<Int>(element + 4) = Extract(c, 1); }
- break;
- case VK_FORMAT_R32_SINT:
- if(writeR) { *Pointer<Int>(element) = Extract(c, 0); }
- break;
- case VK_FORMAT_R32G32B32A32_UINT:
- if(writeRGBA)
- {
- *Pointer<UInt4>(element) = As<UInt4>(c);
- }
- else
- {
- if(writeR) { *Pointer<UInt>(element) = As<UInt>(Extract(c, 0)); }
- if(writeG) { *Pointer<UInt>(element + 4) = As<UInt>(Extract(c, 1)); }
+ break;
+ case VK_FORMAT_R32G32_SINT:
+ if(writeR) { *Pointer<Int>(element) = Extract(c, 0); }
+ if(writeG) { *Pointer<Int>(element + 4) = Extract(c, 1); }
+ break;
+ case VK_FORMAT_R32_SINT:
+ if(writeR) { *Pointer<Int>(element) = Extract(c, 0); }
+ break;
+ case VK_FORMAT_R32G32B32A32_UINT:
+ if(writeRGBA)
+ {
+ *Pointer<UInt4>(element) = As<UInt4>(c);
+ }
+ else
+ {
+ if(writeR) { *Pointer<UInt>(element) = As<UInt>(Extract(c, 0)); }
+ if(writeG) { *Pointer<UInt>(element + 4) = As<UInt>(Extract(c, 1)); }
+ if(writeB) { *Pointer<UInt>(element + 8) = As<UInt>(Extract(c, 2)); }
+ if(writeA) { *Pointer<UInt>(element + 12) = As<UInt>(Extract(c, 3)); }
+ }
+ break;
+ case VK_FORMAT_R32G32B32_UINT:
if(writeB) { *Pointer<UInt>(element + 8) = As<UInt>(Extract(c, 2)); }
- if(writeA) { *Pointer<UInt>(element + 12) = As<UInt>(Extract(c, 3)); }
- }
- break;
- case VK_FORMAT_R32G32B32_UINT:
- if(writeB) { *Pointer<UInt>(element + 8) = As<UInt>(Extract(c, 2)); }
- case VK_FORMAT_R32G32_UINT:
- if(writeG) { *Pointer<UInt>(element + 4) = As<UInt>(Extract(c, 1)); }
- case VK_FORMAT_R32_UINT:
- if(writeR) { *Pointer<UInt>(element) = As<UInt>(Extract(c, 0)); }
- break;
- default:
- UNSUPPORTED("Blitter destination format %d", (int)state.destFormat);
+ case VK_FORMAT_R32G32_UINT:
+ if(writeG) { *Pointer<UInt>(element + 4) = As<UInt>(Extract(c, 1)); }
+ case VK_FORMAT_R32_UINT:
+ if(writeR) { *Pointer<UInt>(element) = As<UInt>(Extract(c, 0)); }
+ break;
+ default:
+ UNSUPPORTED("Blitter destination format %d", (int)state.destFormat);
}
}
@@ -1281,14 +1281,14 @@
// then the whole range of the int or uint color must be scaled between 0 and 1.
switch(state.sourceFormat)
{
- case VK_FORMAT_R32G32B32A32_SINT:
- unscale = float4(static_cast<float>(0x7FFFFFFF));
- break;
- case VK_FORMAT_R32G32B32A32_UINT:
- unscale = float4(static_cast<float>(0xFFFFFFFF));
- break;
- default:
- UNSUPPORTED("Blitter source format %d", (int)state.sourceFormat);
+ case VK_FORMAT_R32G32B32A32_SINT:
+ unscale = float4(static_cast<float>(0x7FFFFFFF));
+ break;
+ case VK_FORMAT_R32G32B32A32_UINT:
+ unscale = float4(static_cast<float>(0xFFFFFFFF));
+ break;
+ default:
+ UNSUPPORTED("Blitter source format %d", (int)state.sourceFormat);
}
}
else
@@ -1301,12 +1301,12 @@
bool srcSRGB = state.sourceFormat.isSRGBformat();
bool dstSRGB = state.destFormat.isSRGBformat();
- if(state.allowSRGBConversion && ((srcSRGB && !preScaled) || dstSRGB)) // One of the formats is sRGB encoded.
+ if(state.allowSRGBConversion && ((srcSRGB && !preScaled) || dstSRGB)) // One of the formats is sRGB encoded.
{
- value *= preScaled ? Float4(1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z, 1.0f / scale.w) : // Unapply scale
- Float4(1.0f / unscale.x, 1.0f / unscale.y, 1.0f / unscale.z, 1.0f / unscale.w); // Apply unscale
+ value *= preScaled ? Float4(1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z, 1.0f / scale.w) : // Unapply scale
+ Float4(1.0f / unscale.x, 1.0f / unscale.y, 1.0f / unscale.z, 1.0f / unscale.w); // Apply unscale
value = (srcSRGB && !preScaled) ? sRGBtoLinear(value) : LinearToSRGB(value);
- value *= Float4(scale.x, scale.y, scale.z, scale.w); // Apply scale
+ value *= Float4(scale.x, scale.y, scale.z, scale.w); // Apply scale
}
else if(unscale != scale)
{
@@ -1348,7 +1348,7 @@
Int4 linear = CmpLT(c, Float4(0.04045f));
Float4 s = c;
- s.xyz = As<Float4>((linear & As<Int4>(lc)) | (~linear & As<Int4>(ec))); // TODO: IfThenElse()
+ s.xyz = As<Float4>((linear & As<Int4>(lc)) | (~linear & As<Int4>(ec))); // TODO: IfThenElse()
return s;
}
@@ -1359,23 +1359,23 @@
{
Pointer<Byte> blit(function.Arg<0>());
- Pointer<Byte> source = *Pointer<Pointer<Byte>>(blit + OFFSET(BlitData,source));
- Pointer<Byte> dest = *Pointer<Pointer<Byte>>(blit + OFFSET(BlitData,dest));
- Int sPitchB = *Pointer<Int>(blit + OFFSET(BlitData,sPitchB));
- Int dPitchB = *Pointer<Int>(blit + OFFSET(BlitData,dPitchB));
+ Pointer<Byte> source = *Pointer<Pointer<Byte>>(blit + OFFSET(BlitData, source));
+ Pointer<Byte> dest = *Pointer<Pointer<Byte>>(blit + OFFSET(BlitData, dest));
+ Int sPitchB = *Pointer<Int>(blit + OFFSET(BlitData, sPitchB));
+ Int dPitchB = *Pointer<Int>(blit + OFFSET(BlitData, dPitchB));
- Float x0 = *Pointer<Float>(blit + OFFSET(BlitData,x0));
- Float y0 = *Pointer<Float>(blit + OFFSET(BlitData,y0));
- Float w = *Pointer<Float>(blit + OFFSET(BlitData,w));
- Float h = *Pointer<Float>(blit + OFFSET(BlitData,h));
+ Float x0 = *Pointer<Float>(blit + OFFSET(BlitData, x0));
+ Float y0 = *Pointer<Float>(blit + OFFSET(BlitData, y0));
+ Float w = *Pointer<Float>(blit + OFFSET(BlitData, w));
+ Float h = *Pointer<Float>(blit + OFFSET(BlitData, h));
- Int x0d = *Pointer<Int>(blit + OFFSET(BlitData,x0d));
- Int x1d = *Pointer<Int>(blit + OFFSET(BlitData,x1d));
- Int y0d = *Pointer<Int>(blit + OFFSET(BlitData,y0d));
- Int y1d = *Pointer<Int>(blit + OFFSET(BlitData,y1d));
+ Int x0d = *Pointer<Int>(blit + OFFSET(BlitData, x0d));
+ Int x1d = *Pointer<Int>(blit + OFFSET(BlitData, x1d));
+ Int y0d = *Pointer<Int>(blit + OFFSET(BlitData, y0d));
+ Int y1d = *Pointer<Int>(blit + OFFSET(BlitData, y1d));
- Int sWidth = *Pointer<Int>(blit + OFFSET(BlitData,sWidth));
- Int sHeight = *Pointer<Int>(blit + OFFSET(BlitData,sHeight));
+ Int sWidth = *Pointer<Int>(blit + OFFSET(BlitData, sWidth));
+ Int sHeight = *Pointer<Int>(blit + OFFSET(BlitData, sHeight));
bool intSrc = state.sourceFormat.isNonNormalizedInteger();
bool intDst = state.destFormat.isNonNormalizedInteger();
@@ -1389,7 +1389,7 @@
Float4 constantColorF;
if(state.clearOperation)
{
- if(intBoth) // Integer types
+ if(intBoth) // Integer types
{
constantColorI = readInt4(source, state);
hasConstantColorI = true;
@@ -1431,7 +1431,7 @@
d += *Pointer<Int>(blit + OFFSET(BlitData, dSliceB));
}
}
- else if(intBoth) // Integer types do not support filtering
+ else if(intBoth) // Integer types do not support filtering
{
Int X = Int(x);
Int Y = Int(y);
@@ -1450,7 +1450,7 @@
{
write(color, d, state);
- d += *Pointer<Int>(blit + OFFSET(BlitData,dSliceB));
+ d += *Pointer<Int>(blit + OFFSET(BlitData, dSliceB));
}
}
else
@@ -1473,9 +1473,9 @@
color = readFloat4(s, state);
- if(state.srcSamples > 1) // Resolve multisampled source
+ if(state.srcSamples > 1) // Resolve multisampled source
{
- if(state.allowSRGBConversion && state.sourceFormat.isSRGBformat()) // sRGB -> RGB
+ if(state.allowSRGBConversion && state.sourceFormat.isSRGBformat()) // sRGB -> RGB
{
ApplyScaleAndClamp(color, state);
preScaled = true;
@@ -1486,7 +1486,7 @@
s += *Pointer<Int>(blit + OFFSET(BlitData, sSliceB));
color = readFloat4(s, state);
- if(state.allowSRGBConversion && state.sourceFormat.isSRGBformat()) // sRGB -> RGB
+ if(state.allowSRGBConversion && state.sourceFormat.isSRGBformat()) // sRGB -> RGB
{
ApplyScaleAndClamp(color, state);
preScaled = true;
@@ -1496,7 +1496,7 @@
color = accum * Float4(1.0f / static_cast<float>(state.srcSamples));
}
}
- else // Bilinear filtering
+ else // Bilinear filtering
{
Float X = x;
Float Y = y;
@@ -1528,7 +1528,7 @@
Float4 c10 = readFloat4(s10, state);
Float4 c11 = readFloat4(s11, state);
- if(state.allowSRGBConversion && state.sourceFormat.isSRGBformat()) // sRGB -> RGB
+ if(state.allowSRGBConversion && state.sourceFormat.isSRGBformat()) // sRGB -> RGB
{
ApplyScaleAndClamp(c00, state);
ApplyScaleAndClamp(c01, state);
@@ -1552,7 +1552,7 @@
{
write(color, d, state);
- d += *Pointer<Int>(blit + OFFSET(BlitData,dSliceB));
+ d += *Pointer<Int>(blit + OFFSET(BlitData, dSliceB));
}
}
}
@@ -1594,7 +1594,7 @@
{
auto aspect = static_cast<VkImageAspectFlagBits>(subresource.aspectMask);
auto format = src->getFormat(aspect);
- State state(format, format, VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT, Options{false, false});
+ State state(format, format, VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT, Options{ false, false });
auto blitRoutine = getBlitRoutine(state);
if(!blitRoutine)
@@ -1602,24 +1602,23 @@
return;
}
- BlitData data =
- {
- nullptr, // source
- dst, // dest
- src->rowPitchBytes(aspect, subresource.mipLevel), // sPitchB
- bufferRowPitch, // dPitchB
- src->slicePitchBytes(aspect, subresource.mipLevel), // sSliceB
- bufferSlicePitch, // dSliceB
+ BlitData data = {
+ nullptr, // source
+ dst, // dest
+ src->rowPitchBytes(aspect, subresource.mipLevel), // sPitchB
+ bufferRowPitch, // dPitchB
+ src->slicePitchBytes(aspect, subresource.mipLevel), // sSliceB
+ bufferSlicePitch, // dSliceB
0, 0, 1, 1,
- 0, // y0d
- static_cast<int>(extent.height), // y1d
- 0, // x0d
- static_cast<int>(extent.width), // x1d
+ 0, // y0d
+ static_cast<int>(extent.height), // y1d
+ 0, // x0d
+ static_cast<int>(extent.width), // x1d
- static_cast<int>(extent.width), // sWidth
- static_cast<int>(extent.height) // sHeight;
+ static_cast<int>(extent.width), // sWidth
+ static_cast<int>(extent.height) // sHeight;
};
VkOffset3D srcOffset = { 0, 0, offset.z };
@@ -1627,8 +1626,7 @@
VkImageSubresourceLayers srcSubresLayers = subresource;
srcSubresLayers.layerCount = 1;
- VkImageSubresourceRange srcSubresRange =
- {
+ VkImageSubresourceRange srcSubresRange = {
subresource.aspectMask,
subresource.mipLevel,
1,
@@ -1657,7 +1655,7 @@
{
auto aspect = static_cast<VkImageAspectFlagBits>(subresource.aspectMask);
auto format = dst->getFormat(aspect);
- State state(format, format, VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT, Options{false, false});
+ State state(format, format, VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT, Options{ false, false });
auto blitRoutine = getBlitRoutine(state);
if(!blitRoutine)
@@ -1665,27 +1663,26 @@
return;
}
- BlitData data =
- {
- src, // source
- nullptr, // dest
- bufferRowPitch, // sPitchB
- dst->rowPitchBytes(aspect, subresource.mipLevel), // dPitchB
- bufferSlicePitch, // sSliceB
- dst->slicePitchBytes(aspect, subresource.mipLevel), // dSliceB
+ BlitData data = {
+ src, // source
+ nullptr, // dest
+ bufferRowPitch, // sPitchB
+ dst->rowPitchBytes(aspect, subresource.mipLevel), // dPitchB
+ bufferSlicePitch, // sSliceB
+ dst->slicePitchBytes(aspect, subresource.mipLevel), // dSliceB
- static_cast<float>(-offset.x), // x0
- static_cast<float>(-offset.y), // y0
- 1.0f, // w
- 1.0f, // h
+ static_cast<float>(-offset.x), // x0
+ static_cast<float>(-offset.y), // y0
+ 1.0f, // w
+ 1.0f, // h
- offset.y, // y0d
- static_cast<int>(offset.y + extent.height), // y1d
- offset.x, // x0d
- static_cast<int>(offset.x + extent.width), // x1d
+ offset.y, // y0d
+ static_cast<int>(offset.y + extent.height), // y1d
+ offset.x, // x0d
+ static_cast<int>(offset.x + extent.width), // x1d
- static_cast<int>(extent.width), // sWidth
- static_cast<int>(extent.height) // sHeight;
+ static_cast<int>(extent.width), // sWidth
+ static_cast<int>(extent.height) // sHeight;
};
VkOffset3D dstOffset = { 0, 0, offset.z };
@@ -1693,8 +1690,7 @@
VkImageSubresourceLayers dstSubresLayers = subresource;
dstSubresLayers.layerCount = 1;
- VkImageSubresourceRange dstSubresRange =
- {
+ VkImageSubresourceRange dstSubresRange = {
subresource.aspectMask,
subresource.mipLevel,
1,
@@ -1763,9 +1759,9 @@
bool doFilter = (filter != VK_FILTER_NEAREST);
bool allowSRGBConversion =
- doFilter ||
- (src->getSampleCountFlagBits() > 1) ||
- (srcFormat.isSRGBformat() != dstFormat.isSRGBformat());
+ doFilter ||
+ (src->getSampleCountFlagBits() > 1) ||
+ (srcFormat.isSRGBformat() != dstFormat.isSRGBformat());
State state(src->getFormat(srcAspect), dst->getFormat(dstAspect), src->getSampleCountFlagBits(), dst->getSampleCountFlagBits(),
Options{ doFilter, allowSRGBConversion });
@@ -1781,50 +1777,46 @@
return;
}
- BlitData data =
- {
- nullptr, // source
- nullptr, // dest
- src->rowPitchBytes(srcAspect, region.srcSubresource.mipLevel), // sPitchB
- dst->rowPitchBytes(dstAspect, region.dstSubresource.mipLevel), // dPitchB
- src->slicePitchBytes(srcAspect, region.srcSubresource.mipLevel), // sSliceB
- dst->slicePitchBytes(dstAspect, region.dstSubresource.mipLevel), // dSliceB
+ BlitData data = {
+ nullptr, // source
+ nullptr, // dest
+ src->rowPitchBytes(srcAspect, region.srcSubresource.mipLevel), // sPitchB
+ dst->rowPitchBytes(dstAspect, region.dstSubresource.mipLevel), // dPitchB
+ src->slicePitchBytes(srcAspect, region.srcSubresource.mipLevel), // sSliceB
+ dst->slicePitchBytes(dstAspect, region.dstSubresource.mipLevel), // dSliceB
x0,
y0,
widthRatio,
heightRatio,
- region.dstOffsets[0].y, // y0d
- region.dstOffsets[1].y, // y1d
- region.dstOffsets[0].x, // x0d
- region.dstOffsets[1].x, // x1d
+ region.dstOffsets[0].y, // y0d
+ region.dstOffsets[1].y, // y1d
+ region.dstOffsets[0].x, // x0d
+ region.dstOffsets[1].x, // x1d
- static_cast<int>(srcExtent.width), // sWidth
- static_cast<int>(srcExtent.height) // sHeight;
+ static_cast<int>(srcExtent.width), // sWidth
+ static_cast<int>(srcExtent.height) // sHeight;
};
VkOffset3D srcOffset = { 0, 0, region.srcOffsets[0].z };
VkOffset3D dstOffset = { 0, 0, region.dstOffsets[0].z };
- VkImageSubresourceLayers srcSubresLayers =
- {
+ VkImageSubresourceLayers srcSubresLayers = {
region.srcSubresource.aspectMask,
region.srcSubresource.mipLevel,
region.srcSubresource.baseArrayLayer,
1
};
- VkImageSubresourceLayers dstSubresLayers =
- {
+ VkImageSubresourceLayers dstSubresLayers = {
region.dstSubresource.aspectMask,
region.dstSubresource.mipLevel,
region.dstSubresource.baseArrayLayer,
1
};
- VkImageSubresourceRange srcSubresRange =
- {
+ VkImageSubresourceRange srcSubresRange = {
region.srcSubresource.aspectMask,
region.srcSubresource.mipLevel,
1,
@@ -1854,7 +1846,7 @@
}
}
-void Blitter::computeCubeCorner(Pointer<Byte>& layer, Int& x0, Int& x1, Int& y0, Int& y1, Int& pitchB, const State& state)
+void Blitter::computeCubeCorner(Pointer<Byte> &layer, Int &x0, Int &x1, Int &y0, Int &y1, Int &pitchB, const State &state)
{
int bytes = state.sourceFormat.bytes();
@@ -1867,7 +1859,7 @@
write(c, layer + ComputeOffset(x0, y0, pitchB, bytes), state);
}
-Blitter::CornerUpdateRoutineType Blitter::generateCornerUpdate(const State& state)
+Blitter::CornerUpdateRoutineType Blitter::generateCornerUpdate(const State &state)
{
// Reading and writing from/to the same image
ASSERT(state.sourceFormat == state.destFormat);
@@ -1888,7 +1880,7 @@
UInt dim = *Pointer<Int>(blit + OFFSET(CubeBorderData, dim));
// Low Border, Low Pixel, High Border, High Pixel
- Int LB(-1), LP(0), HB(dim), HP(dim-1);
+ Int LB(-1), LP(0), HB(dim), HP(dim - 1);
for(int face = 0; face < 6; face++)
{
@@ -1903,7 +1895,7 @@
return function("BlitRoutine");
}
-void Blitter::updateBorders(vk::Image* image, const VkImageSubresourceLayers& subresourceLayers)
+void Blitter::updateBorders(vk::Image *image, const VkImageSubresourceLayers &subresourceLayers)
{
if(image->getArrayLayers() < (subresourceLayers.baseArrayLayer + 6))
{
@@ -1975,8 +1967,7 @@
}
VkExtent3D extent = image->getMipLevelExtent(aspect, subresourceLayers.mipLevel);
- CubeBorderData data =
- {
+ CubeBorderData data = {
image->getTexelPointer({ 0, 0, 0 }, posX),
image->rowPitchBytes(aspect, subresourceLayers.mipLevel),
static_cast<uint32_t>(image->getLayerSize(aspect)),
@@ -1985,9 +1976,9 @@
cornerUpdateRoutine(&data);
}
-void Blitter::copyCubeEdge(vk::Image* image,
- const VkImageSubresourceLayers& dstSubresourceLayers, Edge dstEdge,
- const VkImageSubresourceLayers& srcSubresourceLayers, Edge srcEdge)
+void Blitter::copyCubeEdge(vk::Image *image,
+ const VkImageSubresourceLayers &dstSubresourceLayers, Edge dstEdge,
+ const VkImageSubresourceLayers &srcSubresourceLayers, Edge srcEdge)
{
ASSERT(srcSubresourceLayers.aspectMask == dstSubresourceLayers.aspectMask);
ASSERT(srcSubresourceLayers.mipLevel == dstSubresourceLayers.mipLevel);
@@ -2041,8 +2032,8 @@
dstOffset.y += reverse ? h : 1;
}
- const uint8_t* src = static_cast<const uint8_t*>(image->getTexelPointer(srcOffset, srcSubresourceLayers));
- uint8_t *dst = static_cast<uint8_t*>(image->getTexelPointer(dstOffset, dstSubresourceLayers));
+ const uint8_t *src = static_cast<const uint8_t *>(image->getTexelPointer(srcOffset, srcSubresourceLayers));
+ uint8_t *dst = static_cast<uint8_t *>(image->getTexelPointer(dstOffset, dstSubresourceLayers));
ASSERT((src < image->end()) && ((src + (w * srcDelta)) < image->end()));
ASSERT((dst < image->end()) && ((dst + (w * dstDelta)) < image->end()));
@@ -2052,4 +2043,4 @@
}
}
-} // namepspace sw
+} // namespace sw
diff --git a/src/Device/Blitter.hpp b/src/Device/Blitter.hpp
index 317fdcc..ef8977e 100644
--- a/src/Device/Blitter.hpp
+++ b/src/Device/Blitter.hpp
@@ -20,8 +20,8 @@
#include "Reactor/Reactor.hpp"
#include "Vulkan/VkFormat.h"
-#include <mutex>
#include <cstring>
+#include <mutex>
namespace vk {
@@ -38,9 +38,19 @@
{
explicit Options() = default;
explicit Options(bool filter, bool allowSRGBConversion)
- : writeMask(0xF), clearOperation(false), filter(filter), allowSRGBConversion(allowSRGBConversion), clampToEdge(false) {}
+ : writeMask(0xF)
+ , clearOperation(false)
+ , filter(filter)
+ , allowSRGBConversion(allowSRGBConversion)
+ , clampToEdge(false)
+ {}
explicit Options(unsigned int writeMask)
- : writeMask(writeMask), clearOperation(true), filter(false), allowSRGBConversion(true), clampToEdge(false) {}
+ : writeMask(writeMask)
+ , clearOperation(true)
+ , filter(false)
+ , allowSRGBConversion(true)
+ , clampToEdge(false)
+ {}
union
{
@@ -63,10 +73,21 @@
struct State : Memset<State>, Options
{
- State() : Memset(this, 0) {}
- State(const Options &options) : Memset(this, 0), Options(options) {}
- State(vk::Format sourceFormat, vk::Format destFormat, int srcSamples, int destSamples, const Options &options) :
- Memset(this, 0), Options(options), sourceFormat(sourceFormat), destFormat(destFormat), srcSamples(srcSamples), destSamples(destSamples) {}
+ State()
+ : Memset(this, 0)
+ {}
+ State(const Options &options)
+ : Memset(this, 0)
+ , Options(options)
+ {}
+ State(vk::Format sourceFormat, vk::Format destFormat, int srcSamples, int destSamples, const Options &options)
+ : Memset(this, 0)
+ , Options(options)
+ , sourceFormat(sourceFormat)
+ , destFormat(destFormat)
+ , srcSamples(srcSamples)
+ , destSamples(destSamples)
+ {}
bool operator==(const State &state) const
{
@@ -115,18 +136,24 @@
Blitter();
virtual ~Blitter();
- void clear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea = nullptr);
+ void clear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format &viewFormat, const VkImageSubresourceRange &subresourceRange, const VkRect2D *renderArea = nullptr);
void blit(const vk::Image *src, vk::Image *dst, VkImageBlit region, VkFilter filter);
void blitToBuffer(const vk::Image *src, VkImageSubresourceLayers subresource, VkOffset3D offset, VkExtent3D extent, uint8_t *dst, int bufferRowPitch, int bufferSlicePitch);
void blitFromBuffer(const vk::Image *dst, VkImageSubresourceLayers subresource, VkOffset3D offset, VkExtent3D extent, uint8_t *src, int bufferRowPitch, int bufferSlicePitch);
- void updateBorders(vk::Image* image, const VkImageSubresourceLayers& subresourceLayers);
+ void updateBorders(vk::Image *image, const VkImageSubresourceLayers &subresourceLayers);
private:
- enum Edge { TOP, BOTTOM, RIGHT, LEFT };
+ enum Edge
+ {
+ TOP,
+ BOTTOM,
+ RIGHT,
+ LEFT
+ };
- bool fastClear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea);
+ bool fastClear(void *pixel, vk::Format format, vk::Image *dest, const vk::Format &viewFormat, const VkImageSubresourceRange &subresourceRange, const VkRect2D *renderArea);
Float4 readFloat4(Pointer<Byte> element, const State &state);
void write(Float4 &color, Pointer<Byte> element, const State &state);
@@ -137,27 +164,27 @@
static Float4 LinearToSRGB(Float4 &color);
static Float4 sRGBtoLinear(Float4 &color);
- using BlitFunction = FunctionT<void(const BlitData*)>;
+ using BlitFunction = FunctionT<void(const BlitData *)>;
using BlitRoutineType = BlitFunction::RoutineType;
BlitRoutineType getBlitRoutine(const State &state);
BlitRoutineType generate(const State &state);
- using CornerUpdateFunction = FunctionT<void(const CubeBorderData*)>;
+ using CornerUpdateFunction = FunctionT<void(const CubeBorderData *)>;
using CornerUpdateRoutineType = CornerUpdateFunction::RoutineType;
CornerUpdateRoutineType getCornerUpdateRoutine(const State &state);
- CornerUpdateRoutineType generateCornerUpdate(const State& state);
- void computeCubeCorner(Pointer<Byte>& layer, Int& x0, Int& x1, Int& y0, Int& y1, Int& pitchB, const State& state);
+ CornerUpdateRoutineType generateCornerUpdate(const State &state);
+ void computeCubeCorner(Pointer<Byte> &layer, Int &x0, Int &x1, Int &y0, Int &y1, Int &pitchB, const State &state);
- void copyCubeEdge(vk::Image* image,
- const VkImageSubresourceLayers& dstSubresourceLayers, Edge dstEdge,
- const VkImageSubresourceLayers& srcSubresourceLayers, Edge srcEdge);
+ void copyCubeEdge(vk::Image *image,
+ const VkImageSubresourceLayers &dstSubresourceLayers, Edge dstEdge,
+ const VkImageSubresourceLayers &srcSubresourceLayers, Edge srcEdge);
std::mutex blitMutex;
- RoutineCacheT<State, BlitFunction::CFunctionType> blitCache; // guarded by blitMutex
+ RoutineCacheT<State, BlitFunction::CFunctionType> blitCache; // guarded by blitMutex
std::mutex cornerUpdateMutex;
- RoutineCacheT<State, CornerUpdateFunction::CFunctionType> cornerUpdateCache; // guarded by cornerUpdateMutex
+ RoutineCacheT<State, CornerUpdateFunction::CFunctionType> cornerUpdateCache; // guarded by cornerUpdateMutex
};
} // namespace sw
-#endif // sw_Blitter_hpp
+#endif // sw_Blitter_hpp
diff --git a/src/Device/Clipper.cpp b/src/Device/Clipper.cpp
index d36de8c..f5a75e5 100644
--- a/src/Device/Clipper.cpp
+++ b/src/Device/Clipper.cpp
@@ -263,31 +263,40 @@
unsigned int Clipper::ComputeClipFlags(const float4 &v)
{
- return ((v.x > v.w) ? CLIP_RIGHT : 0) |
- ((v.y > v.w) ? CLIP_TOP : 0) |
- ((v.z > v.w) ? CLIP_FAR : 0) |
- ((v.x < -v.w) ? CLIP_LEFT : 0) |
- ((v.y < -v.w) ? CLIP_BOTTOM : 0) |
- ((v.z < 0) ? CLIP_NEAR : 0) |
- Clipper::CLIP_FINITE; // FIXME: xyz finite
+ return ((v.x > v.w) ? CLIP_RIGHT : 0) |
+ ((v.y > v.w) ? CLIP_TOP : 0) |
+ ((v.z > v.w) ? CLIP_FAR : 0) |
+ ((v.x < -v.w) ? CLIP_LEFT : 0) |
+ ((v.y < -v.w) ? CLIP_BOTTOM : 0) |
+ ((v.z < 0) ? CLIP_NEAR : 0) |
+ Clipper::CLIP_FINITE; // FIXME: xyz finite
}
bool Clipper::Clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw)
{
if(clipFlagsOr & CLIP_FRUSTUM)
{
- if(clipFlagsOr & CLIP_NEAR) clipNear(polygon);
- if(polygon.n >= 3) {
- if(clipFlagsOr & CLIP_FAR) clipFar(polygon);
- if(polygon.n >= 3) {
- if(clipFlagsOr & CLIP_LEFT) clipLeft(polygon);
- if(polygon.n >= 3) {
- if(clipFlagsOr & CLIP_RIGHT) clipRight(polygon);
- if(polygon.n >= 3) {
- if(clipFlagsOr & CLIP_TOP) clipTop(polygon);
- if(polygon.n >= 3) {
- if(clipFlagsOr & CLIP_BOTTOM) clipBottom(polygon);
- }}}}}
+ if(clipFlagsOr & CLIP_NEAR) clipNear(polygon);
+ if(polygon.n >= 3)
+ {
+ if(clipFlagsOr & CLIP_FAR) clipFar(polygon);
+ if(polygon.n >= 3)
+ {
+ if(clipFlagsOr & CLIP_LEFT) clipLeft(polygon);
+ if(polygon.n >= 3)
+ {
+ if(clipFlagsOr & CLIP_RIGHT) clipRight(polygon);
+ if(polygon.n >= 3)
+ {
+ if(clipFlagsOr & CLIP_TOP) clipTop(polygon);
+ if(polygon.n >= 3)
+ {
+ if(clipFlagsOr & CLIP_BOTTOM) clipBottom(polygon);
+ }
+ }
+ }
+ }
+ }
}
return polygon.n >= 3;
diff --git a/src/Device/Clipper.hpp b/src/Device/Clipper.hpp
index 524a373..c696caf 100644
--- a/src/Device/Clipper.hpp
+++ b/src/Device/Clipper.hpp
@@ -27,16 +27,16 @@
enum ClipFlags
{
// Indicates the vertex is outside the respective frustum plane
- CLIP_RIGHT = 1 << 0,
- CLIP_TOP = 1 << 1,
- CLIP_FAR = 1 << 2,
- CLIP_LEFT = 1 << 3,
+ CLIP_RIGHT = 1 << 0,
+ CLIP_TOP = 1 << 1,
+ CLIP_FAR = 1 << 2,
+ CLIP_LEFT = 1 << 3,
CLIP_BOTTOM = 1 << 4,
- CLIP_NEAR = 1 << 5,
+ CLIP_NEAR = 1 << 5,
CLIP_FRUSTUM = 0x003F,
- CLIP_FINITE = 1 << 7, // All position coordinates are finite
+ CLIP_FINITE = 1 << 7, // All position coordinates are finite
};
static unsigned int ComputeClipFlags(const float4 &v);
@@ -45,4 +45,4 @@
} // namespace sw
-#endif // sw_Clipper_hpp
+#endif // sw_Clipper_hpp
diff --git a/src/Device/Color.hpp b/src/Device/Color.hpp
index 2b27e86..a7af805 100644
--- a/src/Device/Color.hpp
+++ b/src/Device/Color.hpp
@@ -15,8 +15,8 @@
#ifndef sw_Color_hpp
#define sw_Color_hpp
-#include "System/Types.hpp"
#include "System/Math.hpp"
+#include "System/Types.hpp"
namespace sw {
@@ -28,12 +28,12 @@
Color(const Color<byte> &c);
Color(const Color<short> &c);
Color(const Color<float> &c);
-
+
Color(int c);
Color(unsigned short c);
Color(unsigned long c);
Color(unsigned int c);
-
+
Color(T r, T g, T b, T a = 1);
operator unsigned int() const;
@@ -44,13 +44,13 @@
Color<T> operator+() const;
Color<T> operator-() const;
- Color<T>& operator=(const Color<T>& c);
+ Color<T> &operator=(const Color<T> &c);
Color<T> &operator+=(const Color<T> &c);
Color<T> &operator*=(float l);
- static Color<T> gradient(const Color<T> &c1, const Color<T> &c2, float d);
- static Color<T> shade(const Color<T> &c1, const Color<T> &c2, float d);
+ static Color<T> gradient(const Color<T> &c1, const Color<T> &c2, float d);
+ static Color<T> shade(const Color<T> &c1, const Color<T> &c2, float d);
template<class S>
friend Color<S> operator+(const Color<S> &c1, const Color<S> &c2);
@@ -69,7 +69,7 @@
T b;
T a;
};
-}
+} // namespace sw
#include "System/Math.hpp"
@@ -312,7 +312,7 @@
return (b << 0) +
(g << 8) +
(r << 16) +
- (a << 24);
+ (a << 24);
}
template<class T>
@@ -340,7 +340,7 @@
}
template<class T>
-inline Color<T> &Color<T>::operator=(const Color& c)
+inline Color<T> &Color<T>::operator=(const Color &c)
{
r = c.r;
g = c.g;
@@ -375,7 +375,7 @@
return Color<T>(c1.r + c2.r,
c1.g + c2.g,
c1.b + c2.b,
- c1.a + c2.a);
+ c1.a + c2.a);
}
template<class T>
@@ -384,7 +384,7 @@
return Color<T>(c1.r - c2.r,
c1.g - c2.g,
c1.b - c2.b,
- c1.a - c2.a);
+ c1.a - c2.a);
}
template<class T>
@@ -434,7 +434,7 @@
template<class T>
inline Color<T> operator/(const Color<T> &c, float l)
{
- l = 1.0f / l;
+ l = 1.0f / l;
T r = (T)(l * c.r);
T g = (T)(l * c.g);
@@ -447,7 +447,7 @@
template<class T>
inline Color<T> Color<T>::gradient(const Color<T> &c1, const Color<T> &c2, float d)
{
- d = 1.0f / d;
+ d = 1.0f / d;
T r = (c2.r - c1.r) * d;
T g = (c2.g - c1.g) * d;
@@ -458,7 +458,7 @@
}
template<class T>
-inline Color<T> Color<T>::shade(const Color<T> &c1, const Color<T> &c2, float d)
+inline Color<T> Color<T>::shade(const Color<T> &c1, const Color<T> &c2, float d)
{
T r = c1.r + (T)(d * (c2.r - c1.r));
T g = c1.g + (T)(d * (c2.g - c1.g));
@@ -470,4 +470,4 @@
} // namespace sw
-#endif // sw_Color_hpp
+#endif // sw_Color_hpp
diff --git a/src/Device/Config.hpp b/src/Device/Config.hpp
index 7584f07..1e4947f 100644
--- a/src/Device/Config.hpp
+++ b/src/Device/Config.hpp
@@ -47,7 +47,7 @@
enum
{
- OUTLINE_RESOLUTION = 8192, // Maximum vertical resolution of the render target
+ OUTLINE_RESOLUTION = 8192, // Maximum vertical resolution of the render target
MIPMAP_LEVELS = 14,
MAX_UNIFORM_BLOCK_SIZE = 16384,
MAX_CLIP_DISTANCES = 8,
@@ -56,11 +56,11 @@
MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 64,
MIN_TEXEL_OFFSET = -8,
MAX_TEXEL_OFFSET = 7,
- MAX_TEXTURE_LOD = MIPMAP_LEVELS - 2, // Trilinear accesses lod+1
+ MAX_TEXTURE_LOD = MIPMAP_LEVELS - 2, // Trilinear accesses lod+1
RENDERTARGETS = 8,
MAX_INTERFACE_COMPONENTS = 32 * 4, // Must be multiple of 4 for 16-byte alignment.
};
} // namespace sw
-#endif // sw_Config_hpp
+#endif // sw_Config_hpp
diff --git a/src/Device/Context.cpp b/src/Device/Context.cpp
index 03987f4..5275e67 100644
--- a/src/Device/Context.cpp
+++ b/src/Device/Context.cpp
@@ -15,10 +15,10 @@
#include "Context.hpp"
#include "Primitive.hpp"
+#include "Pipeline/SpirvShader.hpp"
#include "System/Memory.hpp"
#include "Vulkan/VkDebug.hpp"
#include "Vulkan/VkImageView.hpp"
-#include "Pipeline/SpirvShader.hpp"
#include <string.h>
@@ -33,17 +33,17 @@
{
switch(topology)
{
- case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
- return true;
- case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
- case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
- return false;
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
- return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_POINT) : false;
- default:
- UNIMPLEMENTED("topology %d", int(topology));
+ case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
+ return true;
+ case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
+ case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
+ return false;
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
+ return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_POINT) : false;
+ default:
+ UNIMPLEMENTED("topology %d", int(topology));
}
return false;
}
@@ -52,17 +52,17 @@
{
switch(topology)
{
- case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
- return false;
- case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
- case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
- return true;
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
- return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_LINE) : false;
- default:
- UNIMPLEMENTED("topology %d", int(topology));
+ case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
+ return false;
+ case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
+ case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
+ return true;
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
+ return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_LINE) : false;
+ default:
+ UNIMPLEMENTED("topology %d", int(topology));
}
return false;
}
@@ -71,16 +71,16 @@
{
switch(topology)
{
- case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
- case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
- case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
- return false;
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
- return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_FILL) : true;
- default:
- UNIMPLEMENTED("topology %d", int(topology));
+ case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
+ case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
+ case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
+ return false;
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
+ return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_FILL) : true;
+ default:
+ UNIMPLEMENTED("topology %d", int(topology));
}
return false;
}
@@ -201,16 +201,16 @@
switch(blendState[index].blendOperation)
{
- case VK_BLEND_OP_ADD:
- case VK_BLEND_OP_SUBTRACT:
- case VK_BLEND_OP_REVERSE_SUBTRACT:
- return blendState[index].sourceBlendFactor;
- case VK_BLEND_OP_MIN:
- return VK_BLEND_FACTOR_ONE;
- case VK_BLEND_OP_MAX:
- return VK_BLEND_FACTOR_ONE;
- default:
- ASSERT(false);
+ case VK_BLEND_OP_ADD:
+ case VK_BLEND_OP_SUBTRACT:
+ case VK_BLEND_OP_REVERSE_SUBTRACT:
+ return blendState[index].sourceBlendFactor;
+ case VK_BLEND_OP_MIN:
+ return VK_BLEND_FACTOR_ONE;
+ case VK_BLEND_OP_MAX:
+ return VK_BLEND_FACTOR_ONE;
+ default:
+ ASSERT(false);
}
return blendState[index].sourceBlendFactor;
@@ -224,16 +224,16 @@
switch(blendState[index].blendOperation)
{
- case VK_BLEND_OP_ADD:
- case VK_BLEND_OP_SUBTRACT:
- case VK_BLEND_OP_REVERSE_SUBTRACT:
- return blendState[index].destBlendFactor;
- case VK_BLEND_OP_MIN:
- return VK_BLEND_FACTOR_ONE;
- case VK_BLEND_OP_MAX:
- return VK_BLEND_FACTOR_ONE;
- default:
- ASSERT(false);
+ case VK_BLEND_OP_ADD:
+ case VK_BLEND_OP_SUBTRACT:
+ case VK_BLEND_OP_REVERSE_SUBTRACT:
+ return blendState[index].destBlendFactor;
+ case VK_BLEND_OP_MIN:
+ return VK_BLEND_FACTOR_ONE;
+ case VK_BLEND_OP_MAX:
+ return VK_BLEND_FACTOR_ONE;
+ default:
+ ASSERT(false);
}
return blendState[index].destBlendFactor;
@@ -261,107 +261,107 @@
switch(blendState[index].blendOperation)
{
- case VK_BLEND_OP_ADD:
- if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
- {
- if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+ case VK_BLEND_OP_ADD:
+ if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
{
- return VK_BLEND_OP_ZERO_EXT;
+ if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_ZERO_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_DST_EXT;
+ }
+ }
+ else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
+ {
+ if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_SRC_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_ADD;
+ }
}
else
{
- return VK_BLEND_OP_DST_EXT;
+ if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_SRC_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_ADD;
+ }
}
- }
- else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
- {
- if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+ case VK_BLEND_OP_SUBTRACT:
+ if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
{
- return VK_BLEND_OP_SRC_EXT;
+ return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
+ }
+ else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
+ {
+ if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_SRC_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_SUBTRACT;
+ }
}
else
{
- return VK_BLEND_OP_ADD;
+ if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_SRC_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_SUBTRACT;
+ }
}
- }
- else
- {
- if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+ case VK_BLEND_OP_REVERSE_SUBTRACT:
+ if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
{
- return VK_BLEND_OP_SRC_EXT;
+ if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_ZERO_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_DST_EXT;
+ }
+ }
+ else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
+ {
+ if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
+ {
+ return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
+ }
+ else
+ {
+ return VK_BLEND_OP_REVERSE_SUBTRACT;
+ }
}
else
{
- return VK_BLEND_OP_ADD;
+ if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
+ {
+ return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
+ }
+ else
+ {
+ return VK_BLEND_OP_REVERSE_SUBTRACT;
+ }
}
- }
- case VK_BLEND_OP_SUBTRACT:
- if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
- {
- return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
- }
- else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
- {
- if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
- {
- return VK_BLEND_OP_SRC_EXT;
- }
- else
- {
- return VK_BLEND_OP_SUBTRACT;
- }
- }
- else
- {
- if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
- {
- return VK_BLEND_OP_SRC_EXT;
- }
- else
- {
- return VK_BLEND_OP_SUBTRACT;
- }
- }
- case VK_BLEND_OP_REVERSE_SUBTRACT:
- if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
- {
- if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
- {
- return VK_BLEND_OP_ZERO_EXT;
- }
- else
- {
- return VK_BLEND_OP_DST_EXT;
- }
- }
- else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
- {
- if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
- {
- return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
- }
- else
- {
- return VK_BLEND_OP_REVERSE_SUBTRACT;
- }
- }
- else
- {
- if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
- {
- return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
- }
- else
- {
- return VK_BLEND_OP_REVERSE_SUBTRACT;
- }
- }
- case VK_BLEND_OP_MIN:
- return VK_BLEND_OP_MIN;
- case VK_BLEND_OP_MAX:
- return VK_BLEND_OP_MAX;
- default:
- ASSERT(false);
+ case VK_BLEND_OP_MIN:
+ return VK_BLEND_OP_MIN;
+ case VK_BLEND_OP_MAX:
+ return VK_BLEND_OP_MAX;
+ default:
+ ASSERT(false);
}
return blendState[index].blendOperation;
@@ -373,16 +373,16 @@
switch(blendState[index].blendOperationAlpha)
{
- case VK_BLEND_OP_ADD:
- case VK_BLEND_OP_SUBTRACT:
- case VK_BLEND_OP_REVERSE_SUBTRACT:
- return blendState[index].sourceBlendFactorAlpha;
- case VK_BLEND_OP_MIN:
- return VK_BLEND_FACTOR_ONE;
- case VK_BLEND_OP_MAX:
- return VK_BLEND_FACTOR_ONE;
- default:
- ASSERT(false);
+ case VK_BLEND_OP_ADD:
+ case VK_BLEND_OP_SUBTRACT:
+ case VK_BLEND_OP_REVERSE_SUBTRACT:
+ return blendState[index].sourceBlendFactorAlpha;
+ case VK_BLEND_OP_MIN:
+ return VK_BLEND_FACTOR_ONE;
+ case VK_BLEND_OP_MAX:
+ return VK_BLEND_FACTOR_ONE;
+ default:
+ ASSERT(false);
}
return blendState[index].sourceBlendFactorAlpha;
@@ -394,16 +394,16 @@
switch(blendState[index].blendOperationAlpha)
{
- case VK_BLEND_OP_ADD:
- case VK_BLEND_OP_SUBTRACT:
- case VK_BLEND_OP_REVERSE_SUBTRACT:
- return blendState[index].destBlendFactorAlpha;
- case VK_BLEND_OP_MIN:
- return VK_BLEND_FACTOR_ONE;
- case VK_BLEND_OP_MAX:
- return VK_BLEND_FACTOR_ONE;
- default:
- ASSERT(false);
+ case VK_BLEND_OP_ADD:
+ case VK_BLEND_OP_SUBTRACT:
+ case VK_BLEND_OP_REVERSE_SUBTRACT:
+ return blendState[index].destBlendFactorAlpha;
+ case VK_BLEND_OP_MIN:
+ return VK_BLEND_FACTOR_ONE;
+ case VK_BLEND_OP_MAX:
+ return VK_BLEND_FACTOR_ONE;
+ default:
+ ASSERT(false);
}
return blendState[index].destBlendFactorAlpha;
@@ -415,107 +415,107 @@
switch(blendState[index].blendOperationAlpha)
{
- case VK_BLEND_OP_ADD:
- if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
- {
- if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+ case VK_BLEND_OP_ADD:
+ if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
{
- return VK_BLEND_OP_ZERO_EXT;
+ if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_ZERO_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_DST_EXT;
+ }
+ }
+ else if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
+ {
+ if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_SRC_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_ADD;
+ }
}
else
{
- return VK_BLEND_OP_DST_EXT;
+ if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_SRC_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_ADD;
+ }
}
- }
- else if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
- {
- if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+ case VK_BLEND_OP_SUBTRACT:
+ if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
{
- return VK_BLEND_OP_SRC_EXT;
+ return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
+ }
+ else if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
+ {
+ if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_SRC_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_SUBTRACT;
+ }
}
else
{
- return VK_BLEND_OP_ADD;
+ if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_SRC_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_SUBTRACT;
+ }
}
- }
- else
- {
- if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+ case VK_BLEND_OP_REVERSE_SUBTRACT:
+ if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
{
- return VK_BLEND_OP_SRC_EXT;
+ if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+ {
+ return VK_BLEND_OP_ZERO_EXT;
+ }
+ else
+ {
+ return VK_BLEND_OP_DST_EXT;
+ }
+ }
+ else if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
+ {
+ if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
+ {
+ return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
+ }
+ else
+ {
+ return VK_BLEND_OP_REVERSE_SUBTRACT;
+ }
}
else
{
- return VK_BLEND_OP_ADD;
+ if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
+ {
+ return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
+ }
+ else
+ {
+ return VK_BLEND_OP_REVERSE_SUBTRACT;
+ }
}
- }
- case VK_BLEND_OP_SUBTRACT:
- if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
- {
- return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
- }
- else if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
- {
- if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
- {
- return VK_BLEND_OP_SRC_EXT;
- }
- else
- {
- return VK_BLEND_OP_SUBTRACT;
- }
- }
- else
- {
- if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
- {
- return VK_BLEND_OP_SRC_EXT;
- }
- else
- {
- return VK_BLEND_OP_SUBTRACT;
- }
- }
- case VK_BLEND_OP_REVERSE_SUBTRACT:
- if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
- {
- if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
- {
- return VK_BLEND_OP_ZERO_EXT;
- }
- else
- {
- return VK_BLEND_OP_DST_EXT;
- }
- }
- else if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
- {
- if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
- {
- return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
- }
- else
- {
- return VK_BLEND_OP_REVERSE_SUBTRACT;
- }
- }
- else
- {
- if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
- {
- return VK_BLEND_OP_ZERO_EXT; // Negative, clamped to zero
- }
- else
- {
- return VK_BLEND_OP_REVERSE_SUBTRACT;
- }
- }
- case VK_BLEND_OP_MIN:
- return VK_BLEND_OP_MIN;
- case VK_BLEND_OP_MAX:
- return VK_BLEND_OP_MAX;
- default:
- ASSERT(false);
+ case VK_BLEND_OP_MIN:
+ return VK_BLEND_OP_MIN;
+ case VK_BLEND_OP_MAX:
+ return VK_BLEND_OP_MAX;
+ default:
+ ASSERT(false);
}
return blendState[index].blendOperationAlpha;
diff --git a/src/Device/Context.hpp b/src/Device/Context.hpp
index 20bc089..4aec203 100644
--- a/src/Device/Context.hpp
+++ b/src/Device/Context.hpp
@@ -15,12 +15,12 @@
#ifndef sw_Context_hpp
#define sw_Context_hpp
-#include "Vulkan/VkConfig.h"
-#include "Vulkan/VkDescriptorSet.hpp"
#include "Config.hpp"
#include "Memset.hpp"
#include "Stream.hpp"
#include "System/Types.hpp"
+#include "Vulkan/VkConfig.h"
+#include "Vulkan/VkDescriptorSet.hpp"
namespace vk {
@@ -40,7 +40,9 @@
struct BlendState : Memset<BlendState>
{
- BlendState() : Memset(this, 0) {}
+ BlendState()
+ : Memset(this, 0)
+ {}
BlendState(bool alphaBlendEnable,
VkBlendFactor sourceBlendFactor,
@@ -48,15 +50,15 @@
VkBlendOp blendOperation,
VkBlendFactor sourceBlendFactorAlpha,
VkBlendFactor destBlendFactorAlpha,
- VkBlendOp blendOperationAlpha) :
- Memset(this, 0),
- alphaBlendEnable(alphaBlendEnable),
- sourceBlendFactor(sourceBlendFactor),
- destBlendFactor(destBlendFactor),
- blendOperation(blendOperation),
- sourceBlendFactorAlpha(sourceBlendFactorAlpha),
- destBlendFactorAlpha(destBlendFactorAlpha),
- blendOperationAlpha(blendOperationAlpha)
+ VkBlendOp blendOperationAlpha)
+ : Memset(this, 0)
+ , alphaBlendEnable(alphaBlendEnable)
+ , sourceBlendFactor(sourceBlendFactor)
+ , destBlendFactor(destBlendFactor)
+ , blendOperation(blendOperation)
+ , sourceBlendFactorAlpha(sourceBlendFactorAlpha)
+ , destBlendFactorAlpha(destBlendFactorAlpha)
+ , blendOperationAlpha(blendOperationAlpha)
{}
bool alphaBlendEnable;
@@ -133,7 +135,7 @@
float lineWidth;
- int colorWriteMask[RENDERTARGETS]; // RGBA
+ int colorWriteMask[RENDERTARGETS]; // RGBA
unsigned int sampleMask;
unsigned int multiSampleMask;
int sampleCount;
@@ -157,4 +159,4 @@
} // namespace sw
-#endif // sw_Context_hpp
+#endif // sw_Context_hpp
diff --git a/src/Device/ETC_Decoder.cpp b/src/Device/ETC_Decoder.cpp
index aba807f..d3fcf6e 100644
--- a/src/Device/ETC_Decoder.cpp
+++ b/src/Device/ETC_Decoder.cpp
@@ -14,622 +14,615 @@
#include "ETC_Decoder.hpp"
-namespace
+namespace {
+inline unsigned char clampByte(int value)
{
- inline unsigned char clampByte(int value)
+ return static_cast<unsigned char>((value < 0) ? 0 : ((value > 255) ? 255 : value));
+}
+
+inline signed char clampSByte(int value)
+{
+ return static_cast<signed char>((value < -128) ? -128 : ((value > 127) ? 127 : value));
+}
+
+inline short clampEAC(int value, bool isSigned)
+{
+ short min = isSigned ? -1023 : 0;
+ short max = isSigned ? 1023 : 2047;
+ return static_cast<short>(((value < min) ? min : ((value > max) ? max : value)) << 5);
+}
+
+struct bgra8
+{
+ unsigned char b;
+ unsigned char g;
+ unsigned char r;
+ unsigned char a;
+
+ inline bgra8()
{
- return static_cast<unsigned char>((value < 0) ? 0 : ((value > 255) ? 255 : value));
}
- inline signed char clampSByte(int value)
+ inline void set(int red, int green, int blue)
{
- return static_cast<signed char>((value < -128) ? -128 : ((value > 127) ? 127 : value));
+ r = clampByte(red);
+ g = clampByte(green);
+ b = clampByte(blue);
}
- inline short clampEAC(int value, bool isSigned)
+ inline void set(int red, int green, int blue, int alpha)
{
- short min = isSigned ? -1023 : 0;
- short max = isSigned ? 1023 : 2047;
- return static_cast<short>(((value < min) ? min : ((value > max) ? max : value)) << 5);
+ r = clampByte(red);
+ g = clampByte(green);
+ b = clampByte(blue);
+ a = clampByte(alpha);
}
- struct bgra8
+ const bgra8 &addA(unsigned char alpha)
{
- unsigned char b;
- unsigned char g;
- unsigned char r;
- unsigned char a;
+ a = alpha;
+ return *this;
+ }
+};
- inline bgra8()
+inline int extend_4to8bits(int x)
+{
+ return (x << 4) | x;
+}
+
+inline int extend_5to8bits(int x)
+{
+ return (x << 3) | (x >> 2);
+}
+
+inline int extend_6to8bits(int x)
+{
+ return (x << 2) | (x >> 4);
+}
+
+inline int extend_7to8bits(int x)
+{
+ return (x << 1) | (x >> 6);
+}
+
+struct ETC2
+{
+ // Decodes unsigned single or dual channel block to bytes
+ static void DecodeBlock(const ETC2 **sources, unsigned char *dest, int nbChannels, int x, int y, int w, int h, int pitch, bool isSigned, bool isEAC)
+ {
+ if(isEAC)
{
- }
-
- inline void set(int red, int green, int blue)
- {
- r = clampByte(red);
- g = clampByte(green);
- b = clampByte(blue);
- }
-
- inline void set(int red, int green, int blue, int alpha)
- {
- r = clampByte(red);
- g = clampByte(green);
- b = clampByte(blue);
- a = clampByte(alpha);
- }
-
- const bgra8& addA(unsigned char alpha)
- {
- a = alpha;
- return *this;
- }
- };
-
- inline int extend_4to8bits(int x)
- {
- return (x << 4) | x;
- }
-
- inline int extend_5to8bits(int x)
- {
- return (x << 3) | (x >> 2);
- }
-
- inline int extend_6to8bits(int x)
- {
- return (x << 2) | (x >> 4);
- }
-
- inline int extend_7to8bits(int x)
- {
- return (x << 1) | (x >> 6);
- }
-
- struct ETC2
- {
- // Decodes unsigned single or dual channel block to bytes
- static void DecodeBlock(const ETC2** sources, unsigned char *dest, int nbChannels, int x, int y, int w, int h, int pitch, bool isSigned, bool isEAC)
- {
- if(isEAC)
+ for(int j = 0; j < 4 && (y + j) < h; j++)
{
+ short *sDst = reinterpret_cast<short *>(dest);
+ for(int i = 0; i < 4 && (x + i) < w; i++)
+ {
+ for(int c = nbChannels - 1; c >= 0; c--)
+ {
+ sDst[i * nbChannels + c] = clampEAC(sources[c]->getSingleChannel(i, j, isSigned, true), isSigned);
+ }
+ }
+ dest += pitch;
+ }
+ }
+ else
+ {
+ if(isSigned)
+ {
+ signed char *sDst = reinterpret_cast<signed char *>(dest);
for(int j = 0; j < 4 && (y + j) < h; j++)
{
- short* sDst = reinterpret_cast<short*>(dest);
for(int i = 0; i < 4 && (x + i) < w; i++)
{
for(int c = nbChannels - 1; c >= 0; c--)
{
- sDst[i * nbChannels + c] = clampEAC(sources[c]->getSingleChannel(i, j, isSigned, true), isSigned);
+ sDst[i * nbChannels + c] = clampSByte(sources[c]->getSingleChannel(i, j, isSigned, false));
}
}
- dest += pitch;
- }
- }
- else
- {
- if(isSigned)
- {
- signed char* sDst = reinterpret_cast<signed char*>(dest);
- for(int j = 0; j < 4 && (y + j) < h; j++)
- {
- for(int i = 0; i < 4 && (x + i) < w; i++)
- {
- for(int c = nbChannels - 1; c >= 0; c--)
- {
- sDst[i * nbChannels + c] = clampSByte(sources[c]->getSingleChannel(i, j, isSigned, false));
- }
- }
- sDst += pitch;
- }
- }
- else
- {
- for(int j = 0; j < 4 && (y + j) < h; j++)
- {
- for(int i = 0; i < 4 && (x + i) < w; i++)
- {
- for(int c = nbChannels - 1; c >= 0; c--)
- {
- dest[i * nbChannels + c] = clampByte(sources[c]->getSingleChannel(i, j, isSigned, false));
- }
- }
- dest += pitch;
- }
- }
- }
- }
-
- // Decodes RGB block to bgra8
- void decodeBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4], bool punchThroughAlpha) const
- {
- bool opaqueBit = diffbit;
- bool nonOpaquePunchThroughAlpha = punchThroughAlpha && !opaqueBit;
-
- // Select mode
- if(diffbit || punchThroughAlpha)
- {
- int r = (R + dR);
- int g = (G + dG);
- int b = (B + dB);
- if(r < 0 || r > 31)
- {
- decodeTBlock(dest, x, y, w, h, pitch, alphaValues, nonOpaquePunchThroughAlpha);
- }
- else if(g < 0 || g > 31)
- {
- decodeHBlock(dest, x, y, w, h, pitch, alphaValues, nonOpaquePunchThroughAlpha);
- }
- else if(b < 0 || b > 31)
- {
- decodePlanarBlock(dest, x, y, w, h, pitch, alphaValues);
- }
- else
- {
- decodeDifferentialBlock(dest, x, y, w, h, pitch, alphaValues, nonOpaquePunchThroughAlpha);
- }
- }
- else
- {
- decodeIndividualBlock(dest, x, y, w, h, pitch, alphaValues, nonOpaquePunchThroughAlpha);
- }
- }
-
- private:
- struct
- {
- union
- {
- // Individual, differential, H and T modes
- struct
- {
- union
- {
- // Individual and differential modes
- struct
- {
- union
- {
- struct // Individual colors
- {
- unsigned char R2 : 4;
- unsigned char R1 : 4;
- unsigned char G2 : 4;
- unsigned char G1 : 4;
- unsigned char B2 : 4;
- unsigned char B1 : 4;
- };
-
- struct // Differential colors
- {
- signed char dR : 3;
- unsigned char R : 5;
- signed char dG : 3;
- unsigned char G : 5;
- signed char dB : 3;
- unsigned char B : 5;
- };
- };
-
- bool flipbit : 1;
- bool diffbit : 1;
- unsigned char cw2 : 3;
- unsigned char cw1 : 3;
- };
-
- // T mode
- struct
- {
- // Byte 1
- unsigned char TR1b : 2;
- unsigned char TdummyB : 1;
- unsigned char TR1a : 2;
- unsigned char TdummyA : 3;
-
- // Byte 2
- unsigned char TB1 : 4;
- unsigned char TG1 : 4;
-
- // Byte 3
- unsigned char TG2 : 4;
- unsigned char TR2 : 4;
-
- // Byte 4
- unsigned char Tdb : 1;
- bool Tflipbit : 1;
- unsigned char Tda : 2;
- unsigned char TB2 : 4;
- };
-
- // H mode
- struct
- {
- // Byte 1
- unsigned char HG1a : 3;
- unsigned char HR1 : 4;
- unsigned char HdummyA : 1;
-
- // Byte 2
- unsigned char HB1b : 2;
- unsigned char HdummyC : 1;
- unsigned char HB1a : 1;
- unsigned char HG1b : 1;
- unsigned char HdummyB : 3;
-
- // Byte 3
- unsigned char HG2a : 3;
- unsigned char HR2 : 4;
- unsigned char HB1c : 1;
-
- // Byte 4
- unsigned char Hdb : 1;
- bool Hflipbit : 1;
- unsigned char Hda : 1;
- unsigned char HB2 : 4;
- unsigned char HG2b : 1;
- };
- };
-
- unsigned char pixelIndexMSB[2];
- unsigned char pixelIndexLSB[2];
- };
-
- // planar mode
- struct
- {
- // Byte 1
- unsigned char GO1 : 1;
- unsigned char RO : 6;
- unsigned char PdummyA : 1;
-
- // Byte 2
- unsigned char BO1 : 1;
- unsigned char GO2 : 6;
- unsigned char PdummyB : 1;
-
- // Byte 3
- unsigned char BO3a : 2;
- unsigned char PdummyD : 1;
- unsigned char BO2 : 2;
- unsigned char PdummyC : 3;
-
- // Byte 4
- unsigned char RH2 : 1;
- bool Pflipbit : 1;
- unsigned char RH1 : 5;
- unsigned char BO3b : 1;
-
- // Byte 5
- unsigned char BHa : 1;
- unsigned char GH : 7;
-
- // Byte 6
- unsigned char RVa : 3;
- unsigned char BHb : 5;
-
- // Byte 7
- unsigned char GVa : 5;
- unsigned char RVb : 3;
-
- // Byte 8
- unsigned char BV : 6;
- unsigned char GVb : 2;
- };
-
- // Single channel block
- struct
- {
- union
- {
- unsigned char base_codeword;
- signed char signed_base_codeword;
- };
-
- unsigned char table_index : 4;
- unsigned char multiplier : 4;
-
- unsigned char mc1 : 2;
- unsigned char mb : 3;
- unsigned char ma : 3;
-
- unsigned char mf1 : 1;
- unsigned char me : 3;
- unsigned char md : 3;
- unsigned char mc2 : 1;
-
- unsigned char mh : 3;
- unsigned char mg : 3;
- unsigned char mf2 : 2;
-
- unsigned char mk1 : 2;
- unsigned char mj : 3;
- unsigned char mi : 3;
-
- unsigned char mn1 : 1;
- unsigned char mm : 3;
- unsigned char ml : 3;
- unsigned char mk2 : 1;
-
- unsigned char mp : 3;
- unsigned char mo : 3;
- unsigned char mn2 : 2;
- };
- };
- };
-
- void decodeIndividualBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4], bool nonOpaquePunchThroughAlpha) const
- {
- int r1 = extend_4to8bits(R1);
- int g1 = extend_4to8bits(G1);
- int b1 = extend_4to8bits(B1);
-
- int r2 = extend_4to8bits(R2);
- int g2 = extend_4to8bits(G2);
- int b2 = extend_4to8bits(B2);
-
- decodeIndividualOrDifferentialBlock(dest, x, y, w, h, pitch, r1, g1, b1, r2, g2, b2, alphaValues, nonOpaquePunchThroughAlpha);
- }
-
- void decodeDifferentialBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4], bool nonOpaquePunchThroughAlpha) const
- {
- int b1 = extend_5to8bits(B);
- int g1 = extend_5to8bits(G);
- int r1 = extend_5to8bits(R);
-
- int r2 = extend_5to8bits(R + dR);
- int g2 = extend_5to8bits(G + dG);
- int b2 = extend_5to8bits(B + dB);
-
- decodeIndividualOrDifferentialBlock(dest, x, y, w, h, pitch, r1, g1, b1, r2, g2, b2, alphaValues, nonOpaquePunchThroughAlpha);
- }
-
- void decodeIndividualOrDifferentialBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, int r1, int g1, int b1, int r2, int g2, int b2, unsigned char alphaValues[4][4], bool nonOpaquePunchThroughAlpha) const
- {
- // Table 3.17.2 sorted according to table 3.17.3
- static const int intensityModifierDefault[8][4] =
- {
- { 2, 8, -2, -8 },
- { 5, 17, -5, -17 },
- { 9, 29, -9, -29 },
- { 13, 42, -13, -42 },
- { 18, 60, -18, -60 },
- { 24, 80, -24, -80 },
- { 33, 106, -33, -106 },
- { 47, 183, -47, -183 }
- };
-
- // Table C.12, intensity modifier for non opaque punchthrough alpha
- static const int intensityModifierNonOpaque[8][4] =
- {
- { 0, 8, 0, -8 },
- { 0, 17, 0, -17 },
- { 0, 29, 0, -29 },
- { 0, 42, 0, -42 },
- { 0, 60, 0, -60 },
- { 0, 80, 0, -80 },
- { 0, 106, 0, -106 },
- { 0, 183, 0, -183 }
- };
-
- const int(&intensityModifier)[8][4] = nonOpaquePunchThroughAlpha ? intensityModifierNonOpaque : intensityModifierDefault;
-
- bgra8 subblockColors0[4];
- bgra8 subblockColors1[4];
-
- const int i10 = intensityModifier[cw1][0];
- const int i11 = intensityModifier[cw1][1];
- const int i12 = intensityModifier[cw1][2];
- const int i13 = intensityModifier[cw1][3];
-
- subblockColors0[0].set(r1 + i10, g1 + i10, b1 + i10);
- subblockColors0[1].set(r1 + i11, g1 + i11, b1 + i11);
- subblockColors0[2].set(r1 + i12, g1 + i12, b1 + i12);
- subblockColors0[3].set(r1 + i13, g1 + i13, b1 + i13);
-
- const int i20 = intensityModifier[cw2][0];
- const int i21 = intensityModifier[cw2][1];
- const int i22 = intensityModifier[cw2][2];
- const int i23 = intensityModifier[cw2][3];
-
- subblockColors1[0].set(r2 + i20, g2 + i20, b2 + i20);
- subblockColors1[1].set(r2 + i21, g2 + i21, b2 + i21);
- subblockColors1[2].set(r2 + i22, g2 + i22, b2 + i22);
- subblockColors1[3].set(r2 + i23, g2 + i23, b2 + i23);
-
- unsigned char* destStart = dest;
-
- if(flipbit)
- {
- for(int j = 0; j < 2 && (y + j) < h; j++)
- {
- bgra8* color = (bgra8*)dest;
- if((x + 0) < w) color[0] = subblockColors0[getIndex(0, j)].addA(alphaValues[j][0]);
- if((x + 1) < w) color[1] = subblockColors0[getIndex(1, j)].addA(alphaValues[j][1]);
- if((x + 2) < w) color[2] = subblockColors0[getIndex(2, j)].addA(alphaValues[j][2]);
- if((x + 3) < w) color[3] = subblockColors0[getIndex(3, j)].addA(alphaValues[j][3]);
- dest += pitch;
- }
-
- for(int j = 2; j < 4 && (y + j) < h; j++)
- {
- bgra8* color = (bgra8*)dest;
- if((x + 0) < w) color[0] = subblockColors1[getIndex(0, j)].addA(alphaValues[j][0]);
- if((x + 1) < w) color[1] = subblockColors1[getIndex(1, j)].addA(alphaValues[j][1]);
- if((x + 2) < w) color[2] = subblockColors1[getIndex(2, j)].addA(alphaValues[j][2]);
- if((x + 3) < w) color[3] = subblockColors1[getIndex(3, j)].addA(alphaValues[j][3]);
- dest += pitch;
+ sDst += pitch;
}
}
else
{
for(int j = 0; j < 4 && (y + j) < h; j++)
{
- bgra8* color = (bgra8*)dest;
- if((x + 0) < w) color[0] = subblockColors0[getIndex(0, j)].addA(alphaValues[j][0]);
- if((x + 1) < w) color[1] = subblockColors0[getIndex(1, j)].addA(alphaValues[j][1]);
- if((x + 2) < w) color[2] = subblockColors1[getIndex(2, j)].addA(alphaValues[j][2]);
- if((x + 3) < w) color[3] = subblockColors1[getIndex(3, j)].addA(alphaValues[j][3]);
+ for(int i = 0; i < 4 && (x + i) < w; i++)
+ {
+ for(int c = nbChannels - 1; c >= 0; c--)
+ {
+ dest[i * nbChannels + c] = clampByte(sources[c]->getSingleChannel(i, j, isSigned, false));
+ }
+ }
dest += pitch;
}
}
+ }
+ }
- if(nonOpaquePunchThroughAlpha)
+ // Decodes RGB block to bgra8
+ void decodeBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4], bool punchThroughAlpha) const
+ {
+ bool opaqueBit = diffbit;
+ bool nonOpaquePunchThroughAlpha = punchThroughAlpha && !opaqueBit;
+
+ // Select mode
+ if(diffbit || punchThroughAlpha)
+ {
+ int r = (R + dR);
+ int g = (G + dG);
+ int b = (B + dB);
+ if(r < 0 || r > 31)
{
- decodePunchThroughAlphaBlock(destStart, x, y, w, h, pitch);
+ decodeTBlock(dest, x, y, w, h, pitch, alphaValues, nonOpaquePunchThroughAlpha);
+ }
+ else if(g < 0 || g > 31)
+ {
+ decodeHBlock(dest, x, y, w, h, pitch, alphaValues, nonOpaquePunchThroughAlpha);
+ }
+ else if(b < 0 || b > 31)
+ {
+ decodePlanarBlock(dest, x, y, w, h, pitch, alphaValues);
+ }
+ else
+ {
+ decodeDifferentialBlock(dest, x, y, w, h, pitch, alphaValues, nonOpaquePunchThroughAlpha);
}
}
-
- void decodeTBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4], bool nonOpaquePunchThroughAlpha) const
+ else
{
- // Table C.8, distance index fot T and H modes
- static const int distance[8] = { 3, 6, 11, 16, 23, 32, 41, 64 };
-
- bgra8 paintColors[4];
-
- int r1 = extend_4to8bits(TR1a << 2 | TR1b);
- int g1 = extend_4to8bits(TG1);
- int b1 = extend_4to8bits(TB1);
-
- int r2 = extend_4to8bits(TR2);
- int g2 = extend_4to8bits(TG2);
- int b2 = extend_4to8bits(TB2);
-
- const int d = distance[Tda << 1 | Tdb];
-
- paintColors[0].set(r1, g1, b1);
- paintColors[1].set(r2 + d, g2 + d, b2 + d);
- paintColors[2].set(r2, g2, b2);
- paintColors[3].set(r2 - d, g2 - d, b2 - d);
-
- unsigned char* destStart = dest;
-
- for(int j = 0; j < 4 && (y + j) < h; j++)
- {
- bgra8* color = (bgra8*)dest;
- if((x + 0) < w) color[0] = paintColors[getIndex(0, j)].addA(alphaValues[j][0]);
- if((x + 1) < w) color[1] = paintColors[getIndex(1, j)].addA(alphaValues[j][1]);
- if((x + 2) < w) color[2] = paintColors[getIndex(2, j)].addA(alphaValues[j][2]);
- if((x + 3) < w) color[3] = paintColors[getIndex(3, j)].addA(alphaValues[j][3]);
- dest += pitch;
- }
-
- if(nonOpaquePunchThroughAlpha)
- {
- decodePunchThroughAlphaBlock(destStart, x, y, w, h, pitch);
- }
+ decodeIndividualBlock(dest, x, y, w, h, pitch, alphaValues, nonOpaquePunchThroughAlpha);
}
+ }
- void decodeHBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4], bool nonOpaquePunchThroughAlpha) const
+private:
+ struct
+ {
+ union
{
- // Table C.8, distance index fot T and H modes
- static const int distance[8] = { 3, 6, 11, 16, 23, 32, 41, 64 };
-
- bgra8 paintColors[4];
-
- int r1 = extend_4to8bits(HR1);
- int g1 = extend_4to8bits(HG1a << 1 | HG1b);
- int b1 = extend_4to8bits(HB1a << 3 | HB1b << 1 | HB1c);
-
- int r2 = extend_4to8bits(HR2);
- int g2 = extend_4to8bits(HG2a << 1 | HG2b);
- int b2 = extend_4to8bits(HB2);
-
- const int d = distance[(Hda << 2) | (Hdb << 1) | ((r1 << 16 | g1 << 8 | b1) >= (r2 << 16 | g2 << 8 | b2) ? 1 : 0)];
-
- paintColors[0].set(r1 + d, g1 + d, b1 + d);
- paintColors[1].set(r1 - d, g1 - d, b1 - d);
- paintColors[2].set(r2 + d, g2 + d, b2 + d);
- paintColors[3].set(r2 - d, g2 - d, b2 - d);
-
- unsigned char* destStart = dest;
-
- for(int j = 0; j < 4 && (y + j) < h; j++)
+ // Individual, differential, H and T modes
+ struct
{
- bgra8* color = (bgra8*)dest;
- if((x + 0) < w) color[0] = paintColors[getIndex(0, j)].addA(alphaValues[j][0]);
- if((x + 1) < w) color[1] = paintColors[getIndex(1, j)].addA(alphaValues[j][1]);
- if((x + 2) < w) color[2] = paintColors[getIndex(2, j)].addA(alphaValues[j][2]);
- if((x + 3) < w) color[3] = paintColors[getIndex(3, j)].addA(alphaValues[j][3]);
- dest += pitch;
- }
-
- if(nonOpaquePunchThroughAlpha)
- {
- decodePunchThroughAlphaBlock(destStart, x, y, w, h, pitch);
- }
- }
-
- void decodePlanarBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4]) const
- {
- int ro = extend_6to8bits(RO);
- int go = extend_7to8bits(GO1 << 6 | GO2);
- int bo = extend_6to8bits(BO1 << 5 | BO2 << 3 | BO3a << 1 | BO3b);
-
- int rh = extend_6to8bits(RH1 << 1 | RH2);
- int gh = extend_7to8bits(GH);
- int bh = extend_6to8bits(BHa << 5 | BHb);
-
- int rv = extend_6to8bits(RVa << 3 | RVb);
- int gv = extend_7to8bits(GVa << 2 | GVb);
- int bv = extend_6to8bits(BV);
-
- for(int j = 0; j < 4 && (y + j) < h; j++)
- {
- int ry = j * (rv - ro) + 2;
- int gy = j * (gv - go) + 2;
- int by = j * (bv - bo) + 2;
- for(int i = 0; i < 4 && (x + i) < w; i++)
+ union
{
- ((bgra8*)(dest))[i].set(((i * (rh - ro) + ry) >> 2) + ro,
- ((i * (gh - go) + gy) >> 2) + go,
- ((i * (bh - bo) + by) >> 2) + bo,
- alphaValues[j][i]);
- }
- dest += pitch;
- }
- }
-
- // Index for individual, differential, H and T modes
- inline int getIndex(int x, int y) const
- {
- int bitIndex = x * 4 + y;
- int bitOffset = bitIndex & 7;
- int lsb = (pixelIndexLSB[1 - (bitIndex >> 3)] >> bitOffset) & 1;
- int msb = (pixelIndexMSB[1 - (bitIndex >> 3)] >> bitOffset) & 1;
-
- return (msb << 1) | lsb;
- }
-
- void decodePunchThroughAlphaBlock(unsigned char *dest, int x, int y, int w, int h, int pitch) const
- {
- for(int j = 0; j < 4 && (y + j) < h; j++)
- {
- for(int i = 0; i < 4 && (x + i) < w; i++)
- {
- if(getIndex(i, j) == 2) // msb == 1 && lsb == 0
+ // Individual and differential modes
+ struct
{
- ((bgra8*)dest)[i].set(0, 0, 0, 0);
- }
- }
+ union
+ {
+ struct // Individual colors
+ {
+ unsigned char R2 : 4;
+ unsigned char R1 : 4;
+ unsigned char G2 : 4;
+ unsigned char G1 : 4;
+ unsigned char B2 : 4;
+ unsigned char B1 : 4;
+ };
+
+ struct // Differential colors
+ {
+ signed char dR : 3;
+ unsigned char R : 5;
+ signed char dG : 3;
+ unsigned char G : 5;
+ signed char dB : 3;
+ unsigned char B : 5;
+ };
+ };
+
+ bool flipbit : 1;
+ bool diffbit : 1;
+ unsigned char cw2 : 3;
+ unsigned char cw1 : 3;
+ };
+
+ // T mode
+ struct
+ {
+ // Byte 1
+ unsigned char TR1b : 2;
+ unsigned char TdummyB : 1;
+ unsigned char TR1a : 2;
+ unsigned char TdummyA : 3;
+
+ // Byte 2
+ unsigned char TB1 : 4;
+ unsigned char TG1 : 4;
+
+ // Byte 3
+ unsigned char TG2 : 4;
+ unsigned char TR2 : 4;
+
+ // Byte 4
+ unsigned char Tdb : 1;
+ bool Tflipbit : 1;
+ unsigned char Tda : 2;
+ unsigned char TB2 : 4;
+ };
+
+ // H mode
+ struct
+ {
+ // Byte 1
+ unsigned char HG1a : 3;
+ unsigned char HR1 : 4;
+ unsigned char HdummyA : 1;
+
+ // Byte 2
+ unsigned char HB1b : 2;
+ unsigned char HdummyC : 1;
+ unsigned char HB1a : 1;
+ unsigned char HG1b : 1;
+ unsigned char HdummyB : 3;
+
+ // Byte 3
+ unsigned char HG2a : 3;
+ unsigned char HR2 : 4;
+ unsigned char HB1c : 1;
+
+ // Byte 4
+ unsigned char Hdb : 1;
+ bool Hflipbit : 1;
+ unsigned char Hda : 1;
+ unsigned char HB2 : 4;
+ unsigned char HG2b : 1;
+ };
+ };
+
+ unsigned char pixelIndexMSB[2];
+ unsigned char pixelIndexLSB[2];
+ };
+
+ // planar mode
+ struct
+ {
+ // Byte 1
+ unsigned char GO1 : 1;
+ unsigned char RO : 6;
+ unsigned char PdummyA : 1;
+
+ // Byte 2
+ unsigned char BO1 : 1;
+ unsigned char GO2 : 6;
+ unsigned char PdummyB : 1;
+
+ // Byte 3
+ unsigned char BO3a : 2;
+ unsigned char PdummyD : 1;
+ unsigned char BO2 : 2;
+ unsigned char PdummyC : 3;
+
+ // Byte 4
+ unsigned char RH2 : 1;
+ bool Pflipbit : 1;
+ unsigned char RH1 : 5;
+ unsigned char BO3b : 1;
+
+ // Byte 5
+ unsigned char BHa : 1;
+ unsigned char GH : 7;
+
+ // Byte 6
+ unsigned char RVa : 3;
+ unsigned char BHb : 5;
+
+ // Byte 7
+ unsigned char GVa : 5;
+ unsigned char RVb : 3;
+
+ // Byte 8
+ unsigned char BV : 6;
+ unsigned char GVb : 2;
+ };
+
+ // Single channel block
+ struct
+ {
+ union
+ {
+ unsigned char base_codeword;
+ signed char signed_base_codeword;
+ };
+
+ unsigned char table_index : 4;
+ unsigned char multiplier : 4;
+
+ unsigned char mc1 : 2;
+ unsigned char mb : 3;
+ unsigned char ma : 3;
+
+ unsigned char mf1 : 1;
+ unsigned char me : 3;
+ unsigned char md : 3;
+ unsigned char mc2 : 1;
+
+ unsigned char mh : 3;
+ unsigned char mg : 3;
+ unsigned char mf2 : 2;
+
+ unsigned char mk1 : 2;
+ unsigned char mj : 3;
+ unsigned char mi : 3;
+
+ unsigned char mn1 : 1;
+ unsigned char mm : 3;
+ unsigned char ml : 3;
+ unsigned char mk2 : 1;
+
+ unsigned char mp : 3;
+ unsigned char mo : 3;
+ unsigned char mn2 : 2;
+ };
+ };
+ };
+
+ void decodeIndividualBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4], bool nonOpaquePunchThroughAlpha) const
+ {
+ int r1 = extend_4to8bits(R1);
+ int g1 = extend_4to8bits(G1);
+ int b1 = extend_4to8bits(B1);
+
+ int r2 = extend_4to8bits(R2);
+ int g2 = extend_4to8bits(G2);
+ int b2 = extend_4to8bits(B2);
+
+ decodeIndividualOrDifferentialBlock(dest, x, y, w, h, pitch, r1, g1, b1, r2, g2, b2, alphaValues, nonOpaquePunchThroughAlpha);
+ }
+
+ void decodeDifferentialBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4], bool nonOpaquePunchThroughAlpha) const
+ {
+ int b1 = extend_5to8bits(B);
+ int g1 = extend_5to8bits(G);
+ int r1 = extend_5to8bits(R);
+
+ int r2 = extend_5to8bits(R + dR);
+ int g2 = extend_5to8bits(G + dG);
+ int b2 = extend_5to8bits(B + dB);
+
+ decodeIndividualOrDifferentialBlock(dest, x, y, w, h, pitch, r1, g1, b1, r2, g2, b2, alphaValues, nonOpaquePunchThroughAlpha);
+ }
+
+ void decodeIndividualOrDifferentialBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, int r1, int g1, int b1, int r2, int g2, int b2, unsigned char alphaValues[4][4], bool nonOpaquePunchThroughAlpha) const
+ {
+ // Table 3.17.2 sorted according to table 3.17.3
+ static const int intensityModifierDefault[8][4] = {
+ { 2, 8, -2, -8 },
+ { 5, 17, -5, -17 },
+ { 9, 29, -9, -29 },
+ { 13, 42, -13, -42 },
+ { 18, 60, -18, -60 },
+ { 24, 80, -24, -80 },
+ { 33, 106, -33, -106 },
+ { 47, 183, -47, -183 }
+ };
+
+ // Table C.12, intensity modifier for non opaque punchthrough alpha
+ static const int intensityModifierNonOpaque[8][4] = {
+ { 0, 8, 0, -8 },
+ { 0, 17, 0, -17 },
+ { 0, 29, 0, -29 },
+ { 0, 42, 0, -42 },
+ { 0, 60, 0, -60 },
+ { 0, 80, 0, -80 },
+ { 0, 106, 0, -106 },
+ { 0, 183, 0, -183 }
+ };
+
+ const int(&intensityModifier)[8][4] = nonOpaquePunchThroughAlpha ? intensityModifierNonOpaque : intensityModifierDefault;
+
+ bgra8 subblockColors0[4];
+ bgra8 subblockColors1[4];
+
+ const int i10 = intensityModifier[cw1][0];
+ const int i11 = intensityModifier[cw1][1];
+ const int i12 = intensityModifier[cw1][2];
+ const int i13 = intensityModifier[cw1][3];
+
+ subblockColors0[0].set(r1 + i10, g1 + i10, b1 + i10);
+ subblockColors0[1].set(r1 + i11, g1 + i11, b1 + i11);
+ subblockColors0[2].set(r1 + i12, g1 + i12, b1 + i12);
+ subblockColors0[3].set(r1 + i13, g1 + i13, b1 + i13);
+
+ const int i20 = intensityModifier[cw2][0];
+ const int i21 = intensityModifier[cw2][1];
+ const int i22 = intensityModifier[cw2][2];
+ const int i23 = intensityModifier[cw2][3];
+
+ subblockColors1[0].set(r2 + i20, g2 + i20, b2 + i20);
+ subblockColors1[1].set(r2 + i21, g2 + i21, b2 + i21);
+ subblockColors1[2].set(r2 + i22, g2 + i22, b2 + i22);
+ subblockColors1[3].set(r2 + i23, g2 + i23, b2 + i23);
+
+ unsigned char *destStart = dest;
+
+ if(flipbit)
+ {
+ for(int j = 0; j < 2 && (y + j) < h; j++)
+ {
+ bgra8 *color = (bgra8 *)dest;
+ if((x + 0) < w) color[0] = subblockColors0[getIndex(0, j)].addA(alphaValues[j][0]);
+ if((x + 1) < w) color[1] = subblockColors0[getIndex(1, j)].addA(alphaValues[j][1]);
+ if((x + 2) < w) color[2] = subblockColors0[getIndex(2, j)].addA(alphaValues[j][2]);
+ if((x + 3) < w) color[3] = subblockColors0[getIndex(3, j)].addA(alphaValues[j][3]);
+ dest += pitch;
+ }
+
+ for(int j = 2; j < 4 && (y + j) < h; j++)
+ {
+ bgra8 *color = (bgra8 *)dest;
+ if((x + 0) < w) color[0] = subblockColors1[getIndex(0, j)].addA(alphaValues[j][0]);
+ if((x + 1) < w) color[1] = subblockColors1[getIndex(1, j)].addA(alphaValues[j][1]);
+ if((x + 2) < w) color[2] = subblockColors1[getIndex(2, j)].addA(alphaValues[j][2]);
+ if((x + 3) < w) color[3] = subblockColors1[getIndex(3, j)].addA(alphaValues[j][3]);
+ dest += pitch;
+ }
+ }
+ else
+ {
+ for(int j = 0; j < 4 && (y + j) < h; j++)
+ {
+ bgra8 *color = (bgra8 *)dest;
+ if((x + 0) < w) color[0] = subblockColors0[getIndex(0, j)].addA(alphaValues[j][0]);
+ if((x + 1) < w) color[1] = subblockColors0[getIndex(1, j)].addA(alphaValues[j][1]);
+ if((x + 2) < w) color[2] = subblockColors1[getIndex(2, j)].addA(alphaValues[j][2]);
+ if((x + 3) < w) color[3] = subblockColors1[getIndex(3, j)].addA(alphaValues[j][3]);
dest += pitch;
}
}
- // Single channel utility functions
- inline int getSingleChannel(int x, int y, bool isSigned, bool isEAC) const
+ if(nonOpaquePunchThroughAlpha)
{
- int codeword = isSigned ? signed_base_codeword : base_codeword;
- return isEAC ?
- ((multiplier == 0) ?
- (codeword * 8 + 4 + getSingleChannelModifier(x, y)) :
- (codeword * 8 + 4 + getSingleChannelModifier(x, y) * multiplier * 8)) :
- codeword + getSingleChannelModifier(x, y) * multiplier;
+ decodePunchThroughAlphaBlock(destStart, x, y, w, h, pitch);
+ }
+ }
+
+ void decodeTBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4], bool nonOpaquePunchThroughAlpha) const
+ {
+ // Table C.8, distance index fot T and H modes
+ static const int distance[8] = { 3, 6, 11, 16, 23, 32, 41, 64 };
+
+ bgra8 paintColors[4];
+
+ int r1 = extend_4to8bits(TR1a << 2 | TR1b);
+ int g1 = extend_4to8bits(TG1);
+ int b1 = extend_4to8bits(TB1);
+
+ int r2 = extend_4to8bits(TR2);
+ int g2 = extend_4to8bits(TG2);
+ int b2 = extend_4to8bits(TB2);
+
+ const int d = distance[Tda << 1 | Tdb];
+
+ paintColors[0].set(r1, g1, b1);
+ paintColors[1].set(r2 + d, g2 + d, b2 + d);
+ paintColors[2].set(r2, g2, b2);
+ paintColors[3].set(r2 - d, g2 - d, b2 - d);
+
+ unsigned char *destStart = dest;
+
+ for(int j = 0; j < 4 && (y + j) < h; j++)
+ {
+ bgra8 *color = (bgra8 *)dest;
+ if((x + 0) < w) color[0] = paintColors[getIndex(0, j)].addA(alphaValues[j][0]);
+ if((x + 1) < w) color[1] = paintColors[getIndex(1, j)].addA(alphaValues[j][1]);
+ if((x + 2) < w) color[2] = paintColors[getIndex(2, j)].addA(alphaValues[j][2]);
+ if((x + 3) < w) color[3] = paintColors[getIndex(3, j)].addA(alphaValues[j][3]);
+ dest += pitch;
}
- inline int getSingleChannelIndex(int x, int y) const
+ if(nonOpaquePunchThroughAlpha)
{
- switch(x * 4 + y)
+ decodePunchThroughAlphaBlock(destStart, x, y, w, h, pitch);
+ }
+ }
+
+ void decodeHBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4], bool nonOpaquePunchThroughAlpha) const
+ {
+ // Table C.8, distance index fot T and H modes
+ static const int distance[8] = { 3, 6, 11, 16, 23, 32, 41, 64 };
+
+ bgra8 paintColors[4];
+
+ int r1 = extend_4to8bits(HR1);
+ int g1 = extend_4to8bits(HG1a << 1 | HG1b);
+ int b1 = extend_4to8bits(HB1a << 3 | HB1b << 1 | HB1c);
+
+ int r2 = extend_4to8bits(HR2);
+ int g2 = extend_4to8bits(HG2a << 1 | HG2b);
+ int b2 = extend_4to8bits(HB2);
+
+ const int d = distance[(Hda << 2) | (Hdb << 1) | ((r1 << 16 | g1 << 8 | b1) >= (r2 << 16 | g2 << 8 | b2) ? 1 : 0)];
+
+ paintColors[0].set(r1 + d, g1 + d, b1 + d);
+ paintColors[1].set(r1 - d, g1 - d, b1 - d);
+ paintColors[2].set(r2 + d, g2 + d, b2 + d);
+ paintColors[3].set(r2 - d, g2 - d, b2 - d);
+
+ unsigned char *destStart = dest;
+
+ for(int j = 0; j < 4 && (y + j) < h; j++)
+ {
+ bgra8 *color = (bgra8 *)dest;
+ if((x + 0) < w) color[0] = paintColors[getIndex(0, j)].addA(alphaValues[j][0]);
+ if((x + 1) < w) color[1] = paintColors[getIndex(1, j)].addA(alphaValues[j][1]);
+ if((x + 2) < w) color[2] = paintColors[getIndex(2, j)].addA(alphaValues[j][2]);
+ if((x + 3) < w) color[3] = paintColors[getIndex(3, j)].addA(alphaValues[j][3]);
+ dest += pitch;
+ }
+
+ if(nonOpaquePunchThroughAlpha)
+ {
+ decodePunchThroughAlphaBlock(destStart, x, y, w, h, pitch);
+ }
+ }
+
+ void decodePlanarBlock(unsigned char *dest, int x, int y, int w, int h, int pitch, unsigned char alphaValues[4][4]) const
+ {
+ int ro = extend_6to8bits(RO);
+ int go = extend_7to8bits(GO1 << 6 | GO2);
+ int bo = extend_6to8bits(BO1 << 5 | BO2 << 3 | BO3a << 1 | BO3b);
+
+ int rh = extend_6to8bits(RH1 << 1 | RH2);
+ int gh = extend_7to8bits(GH);
+ int bh = extend_6to8bits(BHa << 5 | BHb);
+
+ int rv = extend_6to8bits(RVa << 3 | RVb);
+ int gv = extend_7to8bits(GVa << 2 | GVb);
+ int bv = extend_6to8bits(BV);
+
+ for(int j = 0; j < 4 && (y + j) < h; j++)
+ {
+ int ry = j * (rv - ro) + 2;
+ int gy = j * (gv - go) + 2;
+ int by = j * (bv - bo) + 2;
+ for(int i = 0; i < 4 && (x + i) < w; i++)
{
+ ((bgra8 *)(dest))[i].set(((i * (rh - ro) + ry) >> 2) + ro,
+ ((i * (gh - go) + gy) >> 2) + go,
+ ((i * (bh - bo) + by) >> 2) + bo,
+ alphaValues[j][i]);
+ }
+ dest += pitch;
+ }
+ }
+
+ // Index for individual, differential, H and T modes
+ inline int getIndex(int x, int y) const
+ {
+ int bitIndex = x * 4 + y;
+ int bitOffset = bitIndex & 7;
+ int lsb = (pixelIndexLSB[1 - (bitIndex >> 3)] >> bitOffset) & 1;
+ int msb = (pixelIndexMSB[1 - (bitIndex >> 3)] >> bitOffset) & 1;
+
+ return (msb << 1) | lsb;
+ }
+
+ void decodePunchThroughAlphaBlock(unsigned char *dest, int x, int y, int w, int h, int pitch) const
+ {
+ for(int j = 0; j < 4 && (y + j) < h; j++)
+ {
+ for(int i = 0; i < 4 && (x + i) < w; i++)
+ {
+ if(getIndex(i, j) == 2) // msb == 1 && lsb == 0
+ {
+ ((bgra8 *)dest)[i].set(0, 0, 0, 0);
+ }
+ }
+ dest += pitch;
+ }
+ }
+
+ // Single channel utility functions
+ inline int getSingleChannel(int x, int y, bool isSigned, bool isEAC) const
+ {
+ int codeword = isSigned ? signed_base_codeword : base_codeword;
+ return isEAC ? ((multiplier == 0) ? (codeword * 8 + 4 + getSingleChannelModifier(x, y)) : (codeword * 8 + 4 + getSingleChannelModifier(x, y) * multiplier * 8)) : codeword + getSingleChannelModifier(x, y) * multiplier;
+ }
+
+ inline int getSingleChannelIndex(int x, int y) const
+ {
+ switch(x * 4 + y)
+ {
case 0: return ma;
case 1: return mb;
case 2: return mc1 << 1 | mc2;
@@ -645,96 +638,96 @@
case 12: return mm;
case 13: return mn1 << 2 | mn2;
case 14: return mo;
- default: return mp; // 15
- }
+ default: return mp; // 15
}
+ }
- inline int getSingleChannelModifier(int x, int y) const
- {
- static const int modifierTable[16][8] = { { -3, -6, -9, -15, 2, 5, 8, 14 },
- { -3, -7, -10, -13, 2, 6, 9, 12 },
- { -2, -5, -8, -13, 1, 4, 7, 12 },
- { -2, -4, -6, -13, 1, 3, 5, 12 },
- { -3, -6, -8, -12, 2, 5, 7, 11 },
- { -3, -7, -9, -11, 2, 6, 8, 10 },
- { -4, -7, -8, -11, 3, 6, 7, 10 },
- { -3, -5, -8, -11, 2, 4, 7, 10 },
- { -2, -6, -8, -10, 1, 5, 7, 9 },
- { -2, -5, -8, -10, 1, 4, 7, 9 },
- { -2, -4, -8, -10, 1, 3, 7, 9 },
- { -2, -5, -7, -10, 1, 4, 6, 9 },
- { -3, -4, -7, -10, 2, 3, 6, 9 },
- { -1, -2, -3, -10, 0, 1, 2, 9 },
- { -4, -6, -8, -9, 3, 5, 7, 8 },
- { -3, -5, -7, -9, 2, 4, 6, 8 } };
+ inline int getSingleChannelModifier(int x, int y) const
+ {
+ static const int modifierTable[16][8] = { { -3, -6, -9, -15, 2, 5, 8, 14 },
+ { -3, -7, -10, -13, 2, 6, 9, 12 },
+ { -2, -5, -8, -13, 1, 4, 7, 12 },
+ { -2, -4, -6, -13, 1, 3, 5, 12 },
+ { -3, -6, -8, -12, 2, 5, 7, 11 },
+ { -3, -7, -9, -11, 2, 6, 8, 10 },
+ { -4, -7, -8, -11, 3, 6, 7, 10 },
+ { -3, -5, -8, -11, 2, 4, 7, 10 },
+ { -2, -6, -8, -10, 1, 5, 7, 9 },
+ { -2, -5, -8, -10, 1, 4, 7, 9 },
+ { -2, -4, -8, -10, 1, 3, 7, 9 },
+ { -2, -5, -7, -10, 1, 4, 6, 9 },
+ { -3, -4, -7, -10, 2, 3, 6, 9 },
+ { -1, -2, -3, -10, 0, 1, 2, 9 },
+ { -4, -6, -8, -9, 3, 5, 7, 8 },
+ { -3, -5, -7, -9, 2, 4, 6, 8 } };
- return modifierTable[table_index][getSingleChannelIndex(x, y)];
- }
- };
-}
+ return modifierTable[table_index][getSingleChannelIndex(x, y)];
+ }
+};
+} // namespace
// Decodes 1 to 4 channel images to 8 bit output
-bool ETC_Decoder::Decode(const unsigned char* src, unsigned char *dst, int w, int h, int dstW, int dstH, int dstPitch, int dstBpp, InputType inputType)
+bool ETC_Decoder::Decode(const unsigned char *src, unsigned char *dst, int w, int h, int dstW, int dstH, int dstPitch, int dstBpp, InputType inputType)
{
- const ETC2* sources[2];
- sources[0] = (const ETC2*)src;
+ const ETC2 *sources[2];
+ sources[0] = (const ETC2 *)src;
unsigned char alphaValues[4][4] = { { 255, 255, 255, 255 }, { 255, 255, 255, 255 }, { 255, 255, 255, 255 }, { 255, 255, 255, 255 } };
switch(inputType)
{
- case ETC_R_SIGNED:
- case ETC_R_UNSIGNED:
- for(int y = 0; y < h; y += 4)
- {
- unsigned char *dstRow = dst + (y * dstPitch);
- for(int x = 0; x < w; x += 4, sources[0]++)
+ case ETC_R_SIGNED:
+ case ETC_R_UNSIGNED:
+ for(int y = 0; y < h; y += 4)
{
- ETC2::DecodeBlock(sources, dstRow + (x * dstBpp), 1, x, y, dstW, dstH, dstPitch, inputType == ETC_R_SIGNED, true);
+ unsigned char *dstRow = dst + (y * dstPitch);
+ for(int x = 0; x < w; x += 4, sources[0]++)
+ {
+ ETC2::DecodeBlock(sources, dstRow + (x * dstBpp), 1, x, y, dstW, dstH, dstPitch, inputType == ETC_R_SIGNED, true);
+ }
}
- }
- break;
- case ETC_RG_SIGNED:
- case ETC_RG_UNSIGNED:
- sources[1] = sources[0] + 1;
- for(int y = 0; y < h; y += 4)
- {
- unsigned char *dstRow = dst + (y * dstPitch);
- for(int x = 0; x < w; x += 4, sources[0] += 2, sources[1] += 2)
+ break;
+ case ETC_RG_SIGNED:
+ case ETC_RG_UNSIGNED:
+ sources[1] = sources[0] + 1;
+ for(int y = 0; y < h; y += 4)
{
- ETC2::DecodeBlock(sources, dstRow + (x * dstBpp), 2, x, y, dstW, dstH, dstPitch, inputType == ETC_RG_SIGNED, true);
+ unsigned char *dstRow = dst + (y * dstPitch);
+ for(int x = 0; x < w; x += 4, sources[0] += 2, sources[1] += 2)
+ {
+ ETC2::DecodeBlock(sources, dstRow + (x * dstBpp), 2, x, y, dstW, dstH, dstPitch, inputType == ETC_RG_SIGNED, true);
+ }
}
- }
- break;
- case ETC_RGB:
- case ETC_RGB_PUNCHTHROUGH_ALPHA:
- for(int y = 0; y < h; y += 4)
- {
- unsigned char *dstRow = dst + (y * dstPitch);
- for(int x = 0; x < w; x += 4, sources[0]++)
+ break;
+ case ETC_RGB:
+ case ETC_RGB_PUNCHTHROUGH_ALPHA:
+ for(int y = 0; y < h; y += 4)
{
- sources[0]->decodeBlock(dstRow + (x * dstBpp), x, y, dstW, dstH, dstPitch, alphaValues, inputType == ETC_RGB_PUNCHTHROUGH_ALPHA);
+ unsigned char *dstRow = dst + (y * dstPitch);
+ for(int x = 0; x < w; x += 4, sources[0]++)
+ {
+ sources[0]->decodeBlock(dstRow + (x * dstBpp), x, y, dstW, dstH, dstPitch, alphaValues, inputType == ETC_RGB_PUNCHTHROUGH_ALPHA);
+ }
}
- }
- break;
- case ETC_RGBA:
- for(int y = 0; y < h; y += 4)
- {
- unsigned char *dstRow = dst + (y * dstPitch);
- for(int x = 0; x < w; x += 4)
+ break;
+ case ETC_RGBA:
+ for(int y = 0; y < h; y += 4)
{
- // Decode Alpha
- ETC2::DecodeBlock(&sources[0], &(alphaValues[0][0]), 1, x, y, dstW, dstH, 4, false, false);
- sources[0]++; // RGBA packets are 128 bits, so move on to the next 64 bit packet to decode the RGB color
+ unsigned char *dstRow = dst + (y * dstPitch);
+ for(int x = 0; x < w; x += 4)
+ {
+ // Decode Alpha
+ ETC2::DecodeBlock(&sources[0], &(alphaValues[0][0]), 1, x, y, dstW, dstH, 4, false, false);
+ sources[0]++; // RGBA packets are 128 bits, so move on to the next 64 bit packet to decode the RGB color
- // Decode RGB
- sources[0]->decodeBlock(dstRow + (x * dstBpp), x, y, dstW, dstH, dstPitch, alphaValues, false);
- sources[0]++;
+ // Decode RGB
+ sources[0]->decodeBlock(dstRow + (x * dstBpp), x, y, dstW, dstH, dstPitch, alphaValues, false);
+ sources[0]++;
+ }
}
- }
- break;
- default:
- return false;
+ break;
+ default:
+ return false;
}
return true;
diff --git a/src/Device/ETC_Decoder.hpp b/src/Device/ETC_Decoder.hpp
index 1039b37..f202bec 100644
--- a/src/Device/ETC_Decoder.hpp
+++ b/src/Device/ETC_Decoder.hpp
@@ -37,5 +37,5 @@
/// @param dstBpp dst image bytes per pixel
/// @param inputType src's format
/// @return true if the decoding was performed
- static bool Decode(const unsigned char* src, unsigned char *dst, int w, int h, int dstW, int dstH, int dstPitch, int dstBpp, InputType inputType);
+ static bool Decode(const unsigned char *src, unsigned char *dst, int w, int h, int dstW, int dstH, int dstPitch, int dstBpp, InputType inputType);
};
diff --git a/src/Device/LRUCache.hpp b/src/Device/LRUCache.hpp
index f549769..d4d2bdb 100644
--- a/src/Device/LRUCache.hpp
+++ b/src/Device/LRUCache.hpp
@@ -33,8 +33,8 @@
Data query(const Key &key) const;
virtual Data add(const Key &key, const Data &data);
- int getSize() {return size;}
- Key &getKey(int i) {return key[i];}
+ int getSize() { return size; }
+ Key &getKey(int i) { return key[i]; }
protected:
int size;
@@ -51,18 +51,21 @@
class LRUConstCache : public LRUCache<Key, Data>
{
using LRUBase = LRUCache<Key, Data>;
+
public:
- LRUConstCache(int n) : LRUBase(n) {}
+ LRUConstCache(int n)
+ : LRUBase(n)
+ {}
~LRUConstCache() { clearConstCache(); }
- Data add(const Key &key, const Data& data) override
+ Data add(const Key &key, const Data &data) override
{
constCacheNeedsUpdate = true;
return LRUBase::add(key, data);
}
void updateConstCache();
- const Data& queryConstCache(const Key &key) const;
+ const Data &queryConstCache(const Key &key) const;
private:
void clearConstCache();
@@ -75,15 +78,15 @@
template<typename T>
struct is_memcmparable
{
- // std::is_trivially_copyable is not available in older GCC versions.
- #if !defined(__GNUC__) || __GNUC__ > 5
- static const bool value = std::is_trivially_copyable<T>::value;
- #else
- // At least check it doesn't have virtual methods.
- static const bool value = !std::is_polymorphic<T>::value;
- #endif
+// std::is_trivially_copyable is not available in older GCC versions.
+#if !defined(__GNUC__) || __GNUC__ > 5
+ static const bool value = std::is_trivially_copyable<T>::value;
+#else
+ // At least check it doesn't have virtual methods.
+ static const bool value = !std::is_polymorphic<T>::value;
+#endif
};
-}
+} // namespace sw
namespace sw {
@@ -96,7 +99,7 @@
fill = 0;
key = new Key[size];
- ref = new Key*[size];
+ ref = new Key *[size];
data = new Data[size];
for(int i = 0; i < size; i++)
@@ -147,7 +150,7 @@
}
}
- return {}; // Not found
+ return {}; // Not found
}
template<class Key, class Data>
@@ -188,7 +191,7 @@
}
template<class Key, class Data, class Hasher>
-const Data& LRUConstCache<Key, Data, Hasher>::queryConstCache(const Key &key) const
+const Data &LRUConstCache<Key, Data, Hasher>::queryConstCache(const Key &key) const
{
auto it = constCache.find(key);
static Data null = {};
@@ -197,4 +200,4 @@
} // namespace sw
-#endif // sw_LRUCache_hpp
+#endif // sw_LRUCache_hpp
diff --git a/src/Device/Matrix.cpp b/src/Device/Matrix.cpp
index 006ca1b..b45facf 100644
--- a/src/Device/Matrix.cpp
+++ b/src/Device/Matrix.cpp
@@ -21,13 +21,13 @@
Matrix Matrix::diag(float m11, float m22, float m33, float m44)
{
- return Matrix(m11, 0, 0, 0,
- 0, m22, 0, 0,
- 0, 0, m33, 0,
- 0, 0, 0, m44);
+ return Matrix(m11, 0, 0, 0,
+ 0, m22, 0, 0,
+ 0, 0, m33, 0,
+ 0, 0, 0, m44);
}
-Matrix::operator float*()
+Matrix::operator float *()
{
return &(*this)(1, 1);
}
@@ -41,9 +41,9 @@
{
const Matrix &M = *this;
- return Matrix(-M(1, 1), -M(1, 2), -M(1, 3), -M(1, 4),
- -M(2, 1), -M(2, 2), -M(2, 3), -M(2, 4),
- -M(3, 1), -M(3, 2), -M(3, 3), -M(3, 4),
+ return Matrix(-M(1, 1), -M(1, 2), -M(1, 3), -M(1, 4),
+ -M(2, 1), -M(2, 2), -M(2, 3), -M(2, 4),
+ -M(3, 1), -M(3, 2), -M(3, 3), -M(3, 4),
-M(4, 1), -M(4, 2), -M(4, 3), -M(4, 4));
}
@@ -72,25 +72,25 @@
float M1223 = M(1, 2) * M(2, 3) - M(2, 2) * M(1, 3);
// Adjoint Matrix
- I(1, 1) = M(2, 2) * M3344 - M(3, 2) * M2344 + M(4, 2) * M2334;
+ I(1, 1) = M(2, 2) * M3344 - M(3, 2) * M2344 + M(4, 2) * M2334;
I(2, 1) = -M(2, 1) * M3344 + M(3, 1) * M2344 - M(4, 1) * M2334;
- I(3, 1) = M(2, 1) * M3244 - M(3, 1) * M2244 + M(4, 1) * M2234;
+ I(3, 1) = M(2, 1) * M3244 - M(3, 1) * M2244 + M(4, 1) * M2234;
I(4, 1) = -M(2, 1) * M3243 + M(3, 1) * M2243 - M(4, 1) * M2233;
I(1, 2) = -M(1, 2) * M3344 + M(3, 2) * M1344 - M(4, 2) * M1334;
- I(2, 2) = M(1, 1) * M3344 - M(3, 1) * M1344 + M(4, 1) * M1334;
+ I(2, 2) = M(1, 1) * M3344 - M(3, 1) * M1344 + M(4, 1) * M1334;
I(3, 2) = -M(1, 1) * M3244 + M(3, 1) * M1244 - M(4, 1) * M1234;
- I(4, 2) = M(1, 1) * M3243 - M(3, 1) * M1243 + M(4, 1) * M1233;
+ I(4, 2) = M(1, 1) * M3243 - M(3, 1) * M1243 + M(4, 1) * M1233;
- I(1, 3) = M(1, 2) * M2344 - M(2, 2) * M1344 + M(4, 2) * M1324;
+ I(1, 3) = M(1, 2) * M2344 - M(2, 2) * M1344 + M(4, 2) * M1324;
I(2, 3) = -M(1, 1) * M2344 + M(2, 1) * M1344 - M(4, 1) * M1324;
- I(3, 3) = M(1, 1) * M2244 - M(2, 1) * M1244 + M(4, 1) * M1224;
+ I(3, 3) = M(1, 1) * M2244 - M(2, 1) * M1244 + M(4, 1) * M1224;
I(4, 3) = -M(1, 1) * M2243 + M(2, 1) * M1243 - M(4, 1) * M1223;
I(1, 4) = -M(1, 2) * M2334 + M(2, 2) * M1334 - M(3, 2) * M1324;
- I(2, 4) = M(1, 1) * M2334 - M(2, 1) * M1334 + M(3, 1) * M1324;
+ I(2, 4) = M(1, 1) * M2334 - M(2, 1) * M1334 + M(3, 1) * M1324;
I(3, 4) = -M(1, 1) * M2234 + M(2, 1) * M1234 - M(3, 1) * M1224;
- I(4, 4) = M(1, 1) * M2233 - M(2, 1) * M1233 + M(3, 1) * M1223;
+ I(4, 4) = M(1, 1) * M2233 - M(2, 1) * M1233 + M(3, 1) * M1223;
// Division by determinant
I /= M(1, 1) * I(1, 1) +
@@ -105,9 +105,9 @@
{
const Matrix &M = *this;
- return Matrix(M(1, 1), M(2, 1), M(3, 1), M(4, 1),
- M(1, 2), M(2, 2), M(3, 2), M(4, 2),
- M(1, 3), M(2, 3), M(3, 3), M(4, 3),
+ return Matrix(M(1, 1), M(2, 1), M(3, 1), M(4, 1),
+ M(1, 2), M(2, 2), M(3, 2), M(4, 2),
+ M(1, 3), M(2, 3), M(3, 3), M(4, 3),
M(1, 4), M(2, 4), M(3, 4), M(4, 4));
}
@@ -115,10 +115,22 @@
{
Matrix &M = *this;
- M(1, 1) += N(1, 1); M(1, 2) += N(1, 2); M(1, 3) += N(1, 3); M(1, 4) += N(1, 4);
- M(2, 1) += N(2, 1); M(2, 2) += N(2, 2); M(2, 3) += N(2, 3); M(2, 4) += N(2, 4);
- M(3, 1) += N(3, 1); M(3, 2) += N(3, 2); M(3, 3) += N(3, 3); M(3, 4) += N(3, 4);
- M(4, 1) += N(4, 1); M(4, 2) += N(4, 2); M(4, 3) += N(4, 3); M(4, 4) += N(4, 4);
+ M(1, 1) += N(1, 1);
+ M(1, 2) += N(1, 2);
+ M(1, 3) += N(1, 3);
+ M(1, 4) += N(1, 4);
+ M(2, 1) += N(2, 1);
+ M(2, 2) += N(2, 2);
+ M(2, 3) += N(2, 3);
+ M(2, 4) += N(2, 4);
+ M(3, 1) += N(3, 1);
+ M(3, 2) += N(3, 2);
+ M(3, 3) += N(3, 3);
+ M(3, 4) += N(3, 4);
+ M(4, 1) += N(4, 1);
+ M(4, 2) += N(4, 2);
+ M(4, 3) += N(4, 3);
+ M(4, 4) += N(4, 4);
return M;
}
@@ -127,10 +139,22 @@
{
Matrix &M = *this;
- M(1, 1) -= N(1, 1); M(1, 2) -= N(1, 2); M(1, 3) -= N(1, 3); M(1, 4) -= N(1, 4);
- M(2, 1) -= N(2, 1); M(2, 2) -= N(2, 2); M(2, 3) -= N(2, 3); M(2, 4) -= N(2, 4);
- M(3, 1) -= N(3, 1); M(3, 2) -= N(3, 2); M(3, 3) -= N(3, 3); M(3, 4) -= N(3, 4);
- M(4, 1) -= N(4, 1); M(4, 2) -= N(4, 2); M(4, 3) -= N(4, 3); M(4, 4) -= N(4, 4);
+ M(1, 1) -= N(1, 1);
+ M(1, 2) -= N(1, 2);
+ M(1, 3) -= N(1, 3);
+ M(1, 4) -= N(1, 4);
+ M(2, 1) -= N(2, 1);
+ M(2, 2) -= N(2, 2);
+ M(2, 3) -= N(2, 3);
+ M(2, 4) -= N(2, 4);
+ M(3, 1) -= N(3, 1);
+ M(3, 2) -= N(3, 2);
+ M(3, 3) -= N(3, 3);
+ M(3, 4) -= N(3, 4);
+ M(4, 1) -= N(4, 1);
+ M(4, 2) -= N(4, 2);
+ M(4, 3) -= N(4, 3);
+ M(4, 4) -= N(4, 4);
return M;
}
@@ -139,10 +163,22 @@
{
Matrix &M = *this;
- M(1, 1) *= s; M(1, 2) *= s; M(1, 3) *= s; M(1, 4) *= s;
- M(2, 1) *= s; M(2, 2) *= s; M(2, 3) *= s; M(2, 4) *= s;
- M(3, 1) *= s; M(3, 2) *= s; M(3, 3) *= s; M(3, 4) *= s;
- M(4, 1) *= s; M(4, 2) *= s; M(4, 3) *= s; M(4, 4) *= s;
+ M(1, 1) *= s;
+ M(1, 2) *= s;
+ M(1, 3) *= s;
+ M(1, 4) *= s;
+ M(2, 1) *= s;
+ M(2, 2) *= s;
+ M(2, 3) *= s;
+ M(2, 4) *= s;
+ M(3, 1) *= s;
+ M(3, 2) *= s;
+ M(3, 3) *= s;
+ M(3, 4) *= s;
+ M(4, 1) *= s;
+ M(4, 2) *= s;
+ M(4, 3) *= s;
+ M(4, 4) *= s;
return M;
}
@@ -183,41 +219,41 @@
Matrix operator+(const Matrix &M, const Matrix &N)
{
- return Matrix(M(1, 1) + N(1, 1), M(1, 2) + N(1, 2), M(1, 3) + N(1, 3), M(1, 4) + N(1, 4),
- M(2, 1) + N(2, 1), M(2, 2) + N(2, 2), M(2, 3) + N(2, 3), M(2, 4) + N(2, 4),
- M(3, 1) + N(3, 1), M(3, 2) + N(3, 2), M(3, 3) + N(3, 3), M(3, 4) + N(3, 4),
+ return Matrix(M(1, 1) + N(1, 1), M(1, 2) + N(1, 2), M(1, 3) + N(1, 3), M(1, 4) + N(1, 4),
+ M(2, 1) + N(2, 1), M(2, 2) + N(2, 2), M(2, 3) + N(2, 3), M(2, 4) + N(2, 4),
+ M(3, 1) + N(3, 1), M(3, 2) + N(3, 2), M(3, 3) + N(3, 3), M(3, 4) + N(3, 4),
M(4, 1) + N(4, 1), M(4, 2) + N(4, 2), M(4, 3) + N(4, 3), M(4, 4) + N(4, 4));
}
Matrix operator-(const Matrix &M, const Matrix &N)
{
- return Matrix(M(1, 1) - N(1, 1), M(1, 2) - N(1, 2), M(1, 3) - N(1, 3), M(1, 4) - N(1, 4),
- M(2, 1) - N(2, 1), M(2, 2) - N(2, 2), M(2, 3) - N(2, 3), M(2, 4) - N(2, 4),
- M(3, 1) - N(3, 1), M(3, 2) - N(3, 2), M(3, 3) - N(3, 3), M(3, 4) - N(3, 4),
+ return Matrix(M(1, 1) - N(1, 1), M(1, 2) - N(1, 2), M(1, 3) - N(1, 3), M(1, 4) - N(1, 4),
+ M(2, 1) - N(2, 1), M(2, 2) - N(2, 2), M(2, 3) - N(2, 3), M(2, 4) - N(2, 4),
+ M(3, 1) - N(3, 1), M(3, 2) - N(3, 2), M(3, 3) - N(3, 3), M(3, 4) - N(3, 4),
M(4, 1) - N(4, 1), M(4, 2) - N(4, 2), M(4, 3) - N(4, 3), M(4, 4) - N(4, 4));
}
Matrix operator*(float s, const Matrix &M)
{
- return Matrix(s * M(1, 1), s * M(1, 2), s * M(1, 3), s * M(1, 4),
- s * M(2, 1), s * M(2, 2), s * M(2, 3), s * M(2, 4),
- s * M(3, 1), s * M(3, 2), s * M(3, 3), s * M(3, 4),
+ return Matrix(s * M(1, 1), s * M(1, 2), s * M(1, 3), s * M(1, 4),
+ s * M(2, 1), s * M(2, 2), s * M(2, 3), s * M(2, 4),
+ s * M(3, 1), s * M(3, 2), s * M(3, 3), s * M(3, 4),
s * M(4, 1), s * M(4, 2), s * M(4, 3), s * M(4, 4));
}
Matrix operator*(const Matrix &M, float s)
{
- return Matrix(M(1, 1) * s, M(1, 2) * s, M(1, 3) * s, M(1, 4) * s,
- M(2, 1) * s, M(2, 2) * s, M(2, 3) * s, M(2, 4) * s,
- M(3, 1) * s, M(3, 2) * s, M(3, 3) * s, M(3, 4) * s,
+ return Matrix(M(1, 1) * s, M(1, 2) * s, M(1, 3) * s, M(1, 4) * s,
+ M(2, 1) * s, M(2, 2) * s, M(2, 3) * s, M(2, 4) * s,
+ M(3, 1) * s, M(3, 2) * s, M(3, 3) * s, M(3, 4) * s,
M(4, 1) * s, M(4, 2) * s, M(4, 3) * s, M(4, 4) * s);
}
Matrix operator*(const Matrix &M, const Matrix &N)
{
- return Matrix(M(1, 1) * N(1, 1) + M(1, 2) * N(2, 1) + M(1, 3) * N(3, 1) + M(1, 4) * N(4, 1), M(1, 1) * N(1, 2) + M(1, 2) * N(2, 2) + M(1, 3) * N(3, 2) + M(1, 4) * N(4, 2), M(1, 1) * N(1, 3) + M(1, 2) * N(2, 3) + M(1, 3) * N(3, 3) + M(1, 4) * N(4, 3), M(1, 1) * N(1, 4) + M(1, 2) * N(2, 4) + M(1, 3) * N(3, 4) + M(1, 4) * N(4, 4),
- M(2, 1) * N(1, 1) + M(2, 2) * N(2, 1) + M(2, 3) * N(3, 1) + M(2, 4) * N(4, 1), M(2, 1) * N(1, 2) + M(2, 2) * N(2, 2) + M(2, 3) * N(3, 2) + M(2, 4) * N(4, 2), M(2, 1) * N(1, 3) + M(2, 2) * N(2, 3) + M(2, 3) * N(3, 3) + M(2, 4) * N(4, 3), M(2, 1) * N(1, 4) + M(2, 2) * N(2, 4) + M(2, 3) * N(3, 4) + M(2, 4) * N(4, 4),
- M(3, 1) * N(1, 1) + M(3, 2) * N(2, 1) + M(3, 3) * N(3, 1) + M(3, 4) * N(4, 1), M(3, 1) * N(1, 2) + M(3, 2) * N(2, 2) + M(3, 3) * N(3, 2) + M(3, 4) * N(4, 2), M(3, 1) * N(1, 3) + M(3, 2) * N(2, 3) + M(3, 3) * N(3, 3) + M(3, 4) * N(4, 3), M(3, 1) * N(1, 4) + M(3, 2) * N(2, 4) + M(3, 3) * N(3, 4) + M(3, 4) * N(4, 4),
+ return Matrix(M(1, 1) * N(1, 1) + M(1, 2) * N(2, 1) + M(1, 3) * N(3, 1) + M(1, 4) * N(4, 1), M(1, 1) * N(1, 2) + M(1, 2) * N(2, 2) + M(1, 3) * N(3, 2) + M(1, 4) * N(4, 2), M(1, 1) * N(1, 3) + M(1, 2) * N(2, 3) + M(1, 3) * N(3, 3) + M(1, 4) * N(4, 3), M(1, 1) * N(1, 4) + M(1, 2) * N(2, 4) + M(1, 3) * N(3, 4) + M(1, 4) * N(4, 4),
+ M(2, 1) * N(1, 1) + M(2, 2) * N(2, 1) + M(2, 3) * N(3, 1) + M(2, 4) * N(4, 1), M(2, 1) * N(1, 2) + M(2, 2) * N(2, 2) + M(2, 3) * N(3, 2) + M(2, 4) * N(4, 2), M(2, 1) * N(1, 3) + M(2, 2) * N(2, 3) + M(2, 3) * N(3, 3) + M(2, 4) * N(4, 3), M(2, 1) * N(1, 4) + M(2, 2) * N(2, 4) + M(2, 3) * N(3, 4) + M(2, 4) * N(4, 4),
+ M(3, 1) * N(1, 1) + M(3, 2) * N(2, 1) + M(3, 3) * N(3, 1) + M(3, 4) * N(4, 1), M(3, 1) * N(1, 2) + M(3, 2) * N(2, 2) + M(3, 3) * N(3, 2) + M(3, 4) * N(4, 2), M(3, 1) * N(1, 3) + M(3, 2) * N(2, 3) + M(3, 3) * N(3, 3) + M(3, 4) * N(4, 3), M(3, 1) * N(1, 4) + M(3, 2) * N(2, 4) + M(3, 3) * N(3, 4) + M(3, 4) * N(4, 4),
M(4, 1) * N(1, 1) + M(4, 2) * N(2, 1) + M(4, 3) * N(3, 1) + M(4, 4) * N(4, 1), M(4, 1) * N(1, 2) + M(4, 2) * N(2, 2) + M(4, 3) * N(3, 2) + M(4, 4) * N(4, 2), M(4, 1) * N(1, 3) + M(4, 2) * N(2, 3) + M(4, 3) * N(3, 3) + M(4, 4) * N(4, 3), M(4, 1) * N(1, 4) + M(4, 2) * N(2, 4) + M(4, 3) * N(3, 4) + M(4, 4) * N(4, 4));
}
@@ -236,7 +272,7 @@
float Mz = M(3, 1) * v.x + M(3, 2) * v.y + M(3, 3) * v.z + M(3, 4) * v.w;
float Mw = M(4, 1) * v.x + M(4, 2) * v.y + M(4, 3) * v.z + M(4, 4) * v.w;
- return {Mx, My, Mz, Mw};
+ return { Mx, My, Mz, Mw };
}
float Matrix::det(const Matrix &M)
@@ -259,14 +295,14 @@
return m11;
}
-float Matrix::det(float m11, float m12,
+float Matrix::det(float m11, float m12,
float m21, float m22)
{
- return m11 * m22 - m12 * m21;
+ return m11 * m22 - m12 * m21;
}
-float Matrix::det(float m11, float m12, float m13,
- float m21, float m22, float m23,
+float Matrix::det(float m11, float m12, float m13,
+ float m21, float m22, float m23,
float m31, float m32, float m33)
{
return m11 * (m22 * m33 - m32 * m23) -
@@ -274,9 +310,9 @@
m31 * (m12 * m23 - m22 * m13);
}
-float Matrix::det(float m11, float m12, float m13, float m14,
- float m21, float m22, float m23, float m24,
- float m31, float m32, float m33, float m34,
+float Matrix::det(float m11, float m12, float m13, float m14,
+ float m21, float m22, float m23, float m24,
+ float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44)
{
float M3344 = m33 * m44 - m43 * m34;
@@ -327,9 +363,15 @@
v2 /= Vector::N(v2);
v3 /= Vector::N(v3);
- M(1, 1) = v1.x; M(1, 2) = v2.x; M(1, 3) = v3.x;
- M(2, 1) = v1.y; M(2, 2) = v2.y; M(2, 3) = v3.y;
- M(3, 1) = v1.z; M(3, 2) = v2.z; M(3, 3) = v3.z;
+ M(1, 1) = v1.x;
+ M(1, 2) = v2.x;
+ M(1, 3) = v3.x;
+ M(2, 1) = v1.y;
+ M(2, 2) = v2.y;
+ M(2, 3) = v3.y;
+ M(3, 1) = v1.z;
+ M(3, 2) = v2.z;
+ M(3, 3) = v3.z;
return *this;
}
@@ -347,8 +389,8 @@
float sxcy = sx * cy;
return Matrix(cy * cz - sxsy * sz, -cy * sz - sxsy * cz, -sy * cx,
- cx * sz, cx * cz, -sx,
- sy * cz + sxcy * sz, -sy * sz + sxcy * cz, cy * cx);
+ cx * sz, cx * cz, -sx,
+ sy * cz + sxcy * sz, -sy * sz + sxcy * cz, cy * cx);
}
Matrix Matrix::eulerRotate(float x, float y, float z)
@@ -371,9 +413,9 @@
Matrix Matrix::scale(const Vector &v)
{
- return Matrix(v.x, 0, 0,
- 0, v.y, 0,
- 0, 0, v.z);
+ return Matrix(v.x, 0, 0,
+ 0, v.y, 0,
+ 0, 0, v.z);
}
Matrix Matrix::scale(float x, float y, float z)
diff --git a/src/Device/Matrix.hpp b/src/Device/Matrix.hpp
index 2dd4e3c..d5a525a 100644
--- a/src/Device/Matrix.hpp
+++ b/src/Device/Matrix.hpp
@@ -35,7 +35,7 @@
float m21, float m22, float m23, float m24,
float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44);
- Matrix(const Vector &v1, const Vector &v2, const Vector &v3); // Column vectors
+ Matrix(const Vector &v1, const Vector &v2, const Vector &v3); // Column vectors
Matrix &operator=(const Matrix &N);
@@ -44,13 +44,13 @@
static Matrix diag(float m11, float m22, float m33, float m44);
- operator float*();
+ operator float *();
Matrix operator+() const;
Matrix operator-() const;
- Matrix operator!() const; // Inverse
- Matrix operator~() const; // Transpose
+ Matrix operator!() const; // Inverse
+ Matrix operator~() const; // Transpose
Matrix &operator+=(const Matrix &N);
Matrix &operator-=(const Matrix &N);
@@ -58,10 +58,10 @@
Matrix &operator*=(const Matrix &N);
Matrix &operator/=(float s);
- float *operator[](int i); // Access element [row][col], starting with [0][0]
+ float *operator[](int i); // Access element [row][col], starting with [0][0]
const float *operator[](int i) const;
- float &operator()(int i, int j); // Access element (row, col), starting with (1, 1)
+ float &operator()(int i, int j); // Access element (row, col), starting with (1, 1)
const float &operator()(int i, int j) const;
friend bool operator==(const Matrix &M, const Matrix &N);
@@ -91,21 +91,21 @@
static float tr(const Matrix &M);
- Matrix &orthogonalise(); // Gram-Schmidt orthogonalisation of 3x3 submatrix
+ Matrix &orthogonalise(); // Gram-Schmidt orthogonalisation of 3x3 submatrix
static Matrix eulerRotate(const Vector &v);
static Matrix eulerRotate(float x, float y, float z);
static Matrix translate(const Vector &v);
static Matrix translate(float x, float y, float z);
-
+
static Matrix scale(const Vector &v);
static Matrix scale(float x, float y, float z);
static Matrix lookAt(const Vector &v);
static Matrix lookAt(float x, float y, float z);
};
-}
+} // namespace sw
#include "Vector.hpp"
@@ -121,75 +121,159 @@
Matrix &M = *this;
- M(1, 1) = s; M(1, 2) = 0; M(1, 3) = 0; M(1, 4) = 0;
- M(2, 1) = 0; M(2, 2) = s; M(2, 3) = 0; M(2, 4) = 0;
- M(3, 1) = 0; M(3, 2) = 0; M(3, 3) = s; M(3, 4) = 0;
- M(4, 1) = 0; M(4, 2) = 0; M(4, 3) = 0; M(4, 4) = s;
+ M(1, 1) = s;
+ M(1, 2) = 0;
+ M(1, 3) = 0;
+ M(1, 4) = 0;
+ M(2, 1) = 0;
+ M(2, 2) = s;
+ M(2, 3) = 0;
+ M(2, 4) = 0;
+ M(3, 1) = 0;
+ M(3, 2) = 0;
+ M(3, 3) = s;
+ M(3, 4) = 0;
+ M(4, 1) = 0;
+ M(4, 2) = 0;
+ M(4, 3) = 0;
+ M(4, 4) = s;
}
inline Matrix::Matrix(const float m[16])
{
Matrix &M = *this;
- M(1, 1) = m[0]; M(1, 2) = m[1]; M(1, 3) = m[2]; M(1, 4) = m[3];
- M(2, 1) = m[4]; M(2, 2) = m[5]; M(2, 3) = m[6]; M(2, 4) = m[7];
- M(3, 1) = m[8]; M(3, 2) = m[8]; M(3, 3) = m[10]; M(3, 4) = m[11];
- M(4, 1) = m[12]; M(4, 2) = m[13]; M(4, 3) = m[14]; M(4, 4) = m[15];
+ M(1, 1) = m[0];
+ M(1, 2) = m[1];
+ M(1, 3) = m[2];
+ M(1, 4) = m[3];
+ M(2, 1) = m[4];
+ M(2, 2) = m[5];
+ M(2, 3) = m[6];
+ M(2, 4) = m[7];
+ M(3, 1) = m[8];
+ M(3, 2) = m[8];
+ M(3, 3) = m[10];
+ M(3, 4) = m[11];
+ M(4, 1) = m[12];
+ M(4, 2) = m[13];
+ M(4, 3) = m[14];
+ M(4, 4) = m[15];
}
inline Matrix::Matrix(const float m[4][4])
{
Matrix &M = *this;
- M[0][0] = m[0][0]; M[0][1] = m[0][1]; M[0][2] = m[0][2]; M[0][3] = m[0][3];
- M[1][0] = m[1][0]; M[1][1] = m[1][1]; M[1][2] = m[1][2]; M[1][3] = m[1][3];
- M[2][0] = m[2][0]; M[2][1] = m[2][1]; M[2][2] = m[2][2]; M[2][3] = m[2][3];
- M[3][0] = m[3][0]; M[3][1] = m[3][1]; M[3][2] = m[3][2]; M[3][3] = m[3][3];
+ M[0][0] = m[0][0];
+ M[0][1] = m[0][1];
+ M[0][2] = m[0][2];
+ M[0][3] = m[0][3];
+ M[1][0] = m[1][0];
+ M[1][1] = m[1][1];
+ M[1][2] = m[1][2];
+ M[1][3] = m[1][3];
+ M[2][0] = m[2][0];
+ M[2][1] = m[2][1];
+ M[2][2] = m[2][2];
+ M[2][3] = m[2][3];
+ M[3][0] = m[3][0];
+ M[3][1] = m[3][1];
+ M[3][2] = m[3][2];
+ M[3][3] = m[3][3];
}
-inline Matrix::Matrix(float m11, float m12, float m13,
- float m21, float m22, float m23,
+inline Matrix::Matrix(float m11, float m12, float m13,
+ float m21, float m22, float m23,
float m31, float m32, float m33)
{
Matrix &M = *this;
- M(1, 1) = m11; M(1, 2) = m12; M(1, 3) = m13; M(1, 4) = 0;
- M(2, 1) = m21; M(2, 2) = m22; M(2, 3) = m23; M(2, 4) = 0;
- M(3, 1) = m31; M(3, 2) = m32; M(3, 3) = m33; M(3, 4) = 0;
- M(4, 1) = 0; M(4, 2) = 0; M(4, 3) = 0; M(4, 4) = 1;
+ M(1, 1) = m11;
+ M(1, 2) = m12;
+ M(1, 3) = m13;
+ M(1, 4) = 0;
+ M(2, 1) = m21;
+ M(2, 2) = m22;
+ M(2, 3) = m23;
+ M(2, 4) = 0;
+ M(3, 1) = m31;
+ M(3, 2) = m32;
+ M(3, 3) = m33;
+ M(3, 4) = 0;
+ M(4, 1) = 0;
+ M(4, 2) = 0;
+ M(4, 3) = 0;
+ M(4, 4) = 1;
}
-inline Matrix::Matrix(float m11, float m12, float m13, float m14,
- float m21, float m22, float m23, float m24,
- float m31, float m32, float m33, float m34,
+inline Matrix::Matrix(float m11, float m12, float m13, float m14,
+ float m21, float m22, float m23, float m24,
+ float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44)
{
Matrix &M = *this;
- M(1, 1) = m11; M(1, 2) = m12; M(1, 3) = m13; M(1, 4) = m14;
- M(2, 1) = m21; M(2, 2) = m22; M(2, 3) = m23; M(2, 4) = m24;
- M(3, 1) = m31; M(3, 2) = m32; M(3, 3) = m33; M(3, 4) = m34;
- M(4, 1) = m41; M(4, 2) = m42; M(4, 3) = m43; M(4, 4) = m44;
+ M(1, 1) = m11;
+ M(1, 2) = m12;
+ M(1, 3) = m13;
+ M(1, 4) = m14;
+ M(2, 1) = m21;
+ M(2, 2) = m22;
+ M(2, 3) = m23;
+ M(2, 4) = m24;
+ M(3, 1) = m31;
+ M(3, 2) = m32;
+ M(3, 3) = m33;
+ M(3, 4) = m34;
+ M(4, 1) = m41;
+ M(4, 2) = m42;
+ M(4, 3) = m43;
+ M(4, 4) = m44;
}
inline Matrix::Matrix(const Vector &v1, const Vector &v2, const Vector &v3)
{
Matrix &M = *this;
- M(1, 1) = v1.x; M(1, 2) = v2.x; M(1, 3) = v3.x; M(1, 4) = 0;
- M(2, 1) = v1.y; M(2, 2) = v2.y; M(2, 3) = v3.y; M(2, 4) = 0;
- M(3, 1) = v1.z; M(3, 2) = v2.z; M(3, 3) = v3.z; M(3, 4) = 0;
- M(4, 1) = 0; M(4, 2) = 0; M(4, 3) = 0; M(4, 4) = 1;
+ M(1, 1) = v1.x;
+ M(1, 2) = v2.x;
+ M(1, 3) = v3.x;
+ M(1, 4) = 0;
+ M(2, 1) = v1.y;
+ M(2, 2) = v2.y;
+ M(2, 3) = v3.y;
+ M(2, 4) = 0;
+ M(3, 1) = v1.z;
+ M(3, 2) = v2.z;
+ M(3, 3) = v3.z;
+ M(3, 4) = 0;
+ M(4, 1) = 0;
+ M(4, 2) = 0;
+ M(4, 3) = 0;
+ M(4, 4) = 1;
}
inline Matrix &Matrix::operator=(const Matrix &N)
{
Matrix &M = *this;
- M(1, 1) = N(1, 1); M(1, 2) = N(1, 2); M(1, 3) = N(1, 3); M(1, 4) = N(1, 4);
- M(2, 1) = N(2, 1); M(2, 2) = N(2, 2); M(2, 3) = N(2, 3); M(2, 4) = N(2, 4);
- M(3, 1) = N(3, 1); M(3, 2) = N(3, 2); M(3, 3) = N(3, 3); M(3, 4) = N(3, 4);
- M(4, 1) = N(4, 1); M(4, 2) = N(4, 2); M(4, 3) = N(4, 3); M(4, 4) = N(4, 4);
+ M(1, 1) = N(1, 1);
+ M(1, 2) = N(1, 2);
+ M(1, 3) = N(1, 3);
+ M(1, 4) = N(1, 4);
+ M(2, 1) = N(2, 1);
+ M(2, 2) = N(2, 2);
+ M(2, 3) = N(2, 3);
+ M(2, 4) = N(2, 4);
+ M(3, 1) = N(3, 1);
+ M(3, 2) = N(3, 2);
+ M(3, 3) = N(3, 3);
+ M(3, 4) = N(3, 4);
+ M(4, 1) = N(4, 1);
+ M(4, 2) = N(4, 2);
+ M(4, 3) = N(4, 3);
+ M(4, 4) = N(4, 4);
return M;
}
@@ -216,4 +300,4 @@
} // namespace sw
-#endif // Matrix_hpp
+#endif // Matrix_hpp
diff --git a/src/Device/Memset.hpp b/src/Device/Memset.hpp
index 9db5d47..6ce53ae 100644
--- a/src/Device/Memset.hpp
+++ b/src/Device/Memset.hpp
@@ -30,23 +30,23 @@
{
static_assert(std::is_base_of<Memset<T>, T>::value, "Memset<T> must only clear the memory of a type of which it is a base class");
- // GCC 8+ warns that
- // "‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘T’;
- // use assignment or value-initialization instead [-Werror=class-memaccess]"
- // This is benign iff it happens before any of the base or member constructrs are called.
- #if defined(__GNUC__) && (__GNUC__ >= 8)
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wclass-memaccess"
- #endif
+// GCC 8+ warns that
+// "‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘T’;
+// use assignment or value-initialization instead [-Werror=class-memaccess]"
+// This is benign iff it happens before any of the base or member constructrs are called.
+#if defined(__GNUC__) && (__GNUC__ >= 8)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wclass-memaccess"
+#endif
memset(object, 0, sizeof(T));
- #if defined(__GNUC__) && (__GNUC__ >= 8)
- #pragma GCC diagnostic pop
- #endif
+#if defined(__GNUC__) && (__GNUC__ >= 8)
+# pragma GCC diagnostic pop
+#endif
}
};
} // namespace sw
-#endif // sw_Memset_hpp
\ No newline at end of file
+#endif // sw_Memset_hpp
\ No newline at end of file
diff --git a/src/Device/PixelProcessor.cpp b/src/Device/PixelProcessor.cpp
index 1c81a24..91644a1 100644
--- a/src/Device/PixelProcessor.cpp
+++ b/src/Device/PixelProcessor.cpp
@@ -15,8 +15,8 @@
#include "PixelProcessor.hpp"
#include "Primitive.hpp"
-#include "Pipeline/PixelProgram.hpp"
#include "Pipeline/Constants.hpp"
+#include "Pipeline/PixelProgram.hpp"
#include "Vulkan/VkDebug.hpp"
#include "Vulkan/VkImageView.hpp"
@@ -26,7 +26,7 @@
uint32_t PixelProcessor::States::computeHash()
{
- uint32_t *state = reinterpret_cast<uint32_t*>(this);
+ uint32_t *state = reinterpret_cast<uint32_t *>(this);
uint32_t hash = 0;
for(unsigned int i = 0; i < sizeof(States) / sizeof(uint32_t); i++)
@@ -45,7 +45,7 @@
}
static_assert(is_memcmparable<State>::value, "Cannot memcmp State");
- return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
+ return memcmp(static_cast<const States *>(this), static_cast<const States *>(&state), sizeof(States)) == 0;
}
PixelProcessor::PixelProcessor()
@@ -90,7 +90,7 @@
routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536));
}
-const PixelProcessor::State PixelProcessor::update(const Context* context) const
+const PixelProcessor::State PixelProcessor::update(const Context *context) const
{
State state;
@@ -151,9 +151,9 @@
}
PixelProcessor::RoutineType PixelProcessor::routine(const State &state,
- vk::PipelineLayout const *pipelineLayout,
- SpirvShader const *pixelShader,
- const vk::DescriptorSet::Bindings &descriptorSets)
+ vk::PipelineLayout const *pipelineLayout,
+ SpirvShader const *pixelShader,
+ const vk::DescriptorSet::Bindings &descriptorSets)
{
auto routine = routineCache->query(state);
diff --git a/src/Device/PixelProcessor.hpp b/src/Device/PixelProcessor.hpp
index 8bc19ab..4679b16 100644
--- a/src/Device/PixelProcessor.hpp
+++ b/src/Device/PixelProcessor.hpp
@@ -28,7 +28,7 @@
struct DrawData;
struct Primitive;
-using RasterizerFunction = FunctionT<void(const Primitive* primitive, int count, int cluster, int clusterCount, DrawData* draw)>;
+using RasterizerFunction = FunctionT<void(const Primitive *primitive, int count, int cluster, int clusterCount, DrawData *draw)>;
class PixelProcessor
{
@@ -39,25 +39,27 @@
// (it doesn't require a different program to be generated)
struct StencilOpState
{
- VkStencilOp failOp;
- VkStencilOp passOp;
- VkStencilOp depthFailOp;
- VkCompareOp compareOp;
- uint32_t compareMask;
- uint32_t writeMask;
+ VkStencilOp failOp;
+ VkStencilOp passOp;
+ VkStencilOp depthFailOp;
+ VkCompareOp compareOp;
+ uint32_t compareMask;
+ uint32_t writeMask;
void operator=(const VkStencilOpState &rhs)
{
- failOp = rhs.failOp;
- passOp = rhs.passOp;
- depthFailOp = rhs.depthFailOp;
- compareOp = rhs.compareOp;
- compareMask = rhs.compareMask;
+ failOp = rhs.failOp;
+ passOp = rhs.passOp;
+ depthFailOp = rhs.depthFailOp;
+ compareOp = rhs.compareOp;
+ compareMask = rhs.compareMask;
writeMask = rhs.writeMask;
}
};
- States() : Memset(this, 0) {}
+ States()
+ : Memset(this, 0)
+ {}
uint32_t computeHash();
@@ -150,7 +152,7 @@
void setBlendConstant(const Color<float> &blendConstant);
protected:
- const State update(const Context* context) const;
+ const State update(const Context *context) const;
RoutineType routine(const State &state, vk::PipelineLayout const *pipelineLayout,
SpirvShader const *pixelShader, const vk::DescriptorSet::Bindings &descriptorSets);
void setRoutineCacheSize(int routineCacheSize);
@@ -165,4 +167,4 @@
} // namespace sw
-#endif // sw_PixelProcessor_hpp
+#endif // sw_PixelProcessor_hpp
diff --git a/src/Device/Plane.hpp b/src/Device/Plane.hpp
index dcce294..13da81a 100644
--- a/src/Device/Plane.hpp
+++ b/src/Device/Plane.hpp
@@ -29,13 +29,13 @@
float D;
Plane();
- Plane(float A, float B, float C, float D); // Plane equation
+ Plane(float A, float B, float C, float D); // Plane equation
Plane(const float ABCD[4]);
- friend Plane operator*(const Plane &p, const Matrix &A); // Transform plane by matrix (post-multiply)
- friend Plane operator*(const Matrix &A, const Plane &p); // Transform plane by matrix (pre-multiply)
+ friend Plane operator*(const Plane &p, const Matrix &A); // Transform plane by matrix (post-multiply)
+ friend Plane operator*(const Matrix &A, const Plane &p); // Transform plane by matrix (pre-multiply)
};
} // namespace sw
-#endif // Plane_hpp
+#endif // Plane_hpp
diff --git a/src/Device/Point.hpp b/src/Device/Point.hpp
index 5602209..318b5c4 100644
--- a/src/Device/Point.hpp
+++ b/src/Device/Point.hpp
@@ -35,7 +35,7 @@
float p[3];
struct
- {
+ {
float x;
float y;
float z;
@@ -56,15 +56,15 @@
friend Vector operator-(const Point &P, const Point &Q);
- friend Point operator*(const Matrix &M, const Point& P);
+ friend Point operator*(const Matrix &M, const Point &P);
friend Point operator*(const Point &P, const Matrix &M);
friend Point &operator*=(Point &P, const Matrix &M);
float d(const Point &P) const; // Distance between two points
- float d2(const Point &P) const; // Squared distance between two points
+ float d2(const Point &P) const; // Squared distance between two points
static float d(const Point &P, const Point &Q); // Distance between two points
- static float d2(const Point &P, const Point &Q); // Squared distance between two points
+ static float d2(const Point &P, const Point &Q); // Squared distance between two points
};
} // namespace sw
@@ -138,4 +138,4 @@
} // namespace sw
-#endif // Point_hpp
+#endif // Point_hpp
diff --git a/src/Device/Polygon.hpp b/src/Device/Polygon.hpp
index 5412128..c4152f9 100644
--- a/src/Device/Polygon.hpp
+++ b/src/Device/Polygon.hpp
@@ -44,14 +44,14 @@
this->b = 0;
}
- float4 B[16]; // Buffer for clipped vertices
- const float4 *P[16][16]; // Pointers to clipped polygon's vertices
+ float4 B[16]; // Buffer for clipped vertices
+ const float4 *P[16][16]; // Pointers to clipped polygon's vertices
- int n; // Number of vertices
- int i; // Level of P to use
- int b; // Next available new vertex
+ int n; // Number of vertices
+ int i; // Level of P to use
+ int b; // Next available new vertex
};
} // namespace sw
-#endif // sw_Polygon_hpp
+#endif // sw_Polygon_hpp
diff --git a/src/Device/Primitive.hpp b/src/Device/Primitive.hpp
index 85a9db4..591b974 100644
--- a/src/Device/Primitive.hpp
+++ b/src/Device/Primitive.hpp
@@ -22,35 +22,41 @@
namespace sw {
-struct Triangle MEMORY_SANITIZER_ONLY(: Memset<Triangle>)
+struct Triangle MEMORY_SANITIZER_ONLY(
+ : Memset<Triangle>)
{
#if MEMORY_SANITIZER_ENABLED
// Memory sanitizer cannot 'see' writes from JIT'd code, and can raise
// false-positives when read. By clearing the struct in the constructor,
// we can avoid triggering these false-positives.
- inline Triangle() : Memset<Triangle>(this, 0) {}
-#endif // MEMORY_SANITIZER_ENABLED
+ inline Triangle()
+ : Memset<Triangle>(this, 0)
+ {}
+#endif // MEMORY_SANITIZER_ENABLED
Vertex v0;
Vertex v1;
Vertex v2;
};
-struct PlaneEquation // z = A * x + B * y + C
+struct PlaneEquation // z = A * x + B * y + C
{
float4 A;
float4 B;
float4 C;
};
-struct Primitive MEMORY_SANITIZER_ONLY(: Memset<Primitive>)
+struct Primitive MEMORY_SANITIZER_ONLY(
+ : Memset<Primitive>)
{
#if MEMORY_SANITIZER_ENABLED
// Memory sanitizer cannot 'see' writes from JIT'd code, and can raise
// false-positives when read. By clearing the struct in the constructor,
// we can avoid triggering these false-positives.
- inline Primitive() : Memset<Primitive>(this, 0) {}
-#endif // MEMORY_SANITIZER_ENABLED
+ inline Primitive()
+ : Memset<Primitive>(this, 0)
+ {}
+#endif // MEMORY_SANITIZER_ENABLED
int yMin;
int yMax;
@@ -87,4 +93,4 @@
} // namespace sw
-#endif // sw_Primitive_hpp
+#endif // sw_Primitive_hpp
diff --git a/src/Device/QuadRasterizer.cpp b/src/Device/QuadRasterizer.cpp
index e589e15..36db635 100644
--- a/src/Device/QuadRasterizer.cpp
+++ b/src/Device/QuadRasterizer.cpp
@@ -22,7 +22,9 @@
namespace sw {
-QuadRasterizer::QuadRasterizer(const PixelProcessor::State &state, SpirvShader const *spirvShader) : state(state), spirvShader{spirvShader}
+QuadRasterizer::QuadRasterizer(const PixelProcessor::State &state, SpirvShader const *spirvShader)
+ : state(state)
+ , spirvShader{ spirvShader }
{
}
@@ -32,13 +34,13 @@
void QuadRasterizer::generate()
{
- constants = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData,constants));
+ constants = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData, constants));
occlusion = 0;
Do
{
- Int yMin = *Pointer<Int>(primitive + OFFSET(Primitive,yMin));
- Int yMax = *Pointer<Int>(primitive + OFFSET(Primitive,yMax));
+ Int yMin = *Pointer<Int>(primitive + OFFSET(Primitive, yMin));
+ Int yMax = *Pointer<Int>(primitive + OFFSET(Primitive, yMax));
Int cluster2 = cluster + cluster;
yMin += clusterCount * 2 - 2 - cluster2;
@@ -57,9 +59,9 @@
if(state.occlusionEnabled)
{
- UInt clusterOcclusion = *Pointer<UInt>(data + OFFSET(DrawData,occlusion) + 4 * cluster);
+ UInt clusterOcclusion = *Pointer<UInt>(data + OFFSET(DrawData, occlusion) + 4 * cluster);
clusterOcclusion += occlusion;
- *Pointer<UInt>(data + OFFSET(DrawData,occlusion) + 4 * cluster) = clusterOcclusion;
+ *Pointer<UInt>(data + OFFSET(DrawData, occlusion) + 4 * cluster) = clusterOcclusion;
}
Return();
@@ -77,49 +79,49 @@
{
if(state.colorWriteActive(index))
{
- cBuffer[index] = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData,colorBuffer[index])) + yMin * *Pointer<Int>(data + OFFSET(DrawData,colorPitchB[index]));
+ cBuffer[index] = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData, colorBuffer[index])) + yMin * *Pointer<Int>(data + OFFSET(DrawData, colorPitchB[index]));
}
}
if(state.depthTestActive)
{
- zBuffer = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData,depthBuffer)) + yMin * *Pointer<Int>(data + OFFSET(DrawData,depthPitchB));
+ zBuffer = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData, depthBuffer)) + yMin * *Pointer<Int>(data + OFFSET(DrawData, depthPitchB));
}
if(state.stencilActive)
{
- sBuffer = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData,stencilBuffer)) + yMin * *Pointer<Int>(data + OFFSET(DrawData,stencilPitchB));
+ sBuffer = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData, stencilBuffer)) + yMin * *Pointer<Int>(data + OFFSET(DrawData, stencilPitchB));
}
Int y = yMin;
Do
{
- Int x0a = Int(*Pointer<Short>(primitive + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span)));
- Int x0b = Int(*Pointer<Short>(primitive + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span)));
+ Int x0a = Int(*Pointer<Short>(primitive + OFFSET(Primitive, outline->left) + (y + 0) * sizeof(Primitive::Span)));
+ Int x0b = Int(*Pointer<Short>(primitive + OFFSET(Primitive, outline->left) + (y + 1) * sizeof(Primitive::Span)));
Int x0 = Min(x0a, x0b);
for(unsigned int q = 1; q < state.multiSample; q++)
{
- x0a = Int(*Pointer<Short>(primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span)));
- x0b = Int(*Pointer<Short>(primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span)));
+ x0a = Int(*Pointer<Short>(primitive + q * sizeof(Primitive) + OFFSET(Primitive, outline->left) + (y + 0) * sizeof(Primitive::Span)));
+ x0b = Int(*Pointer<Short>(primitive + q * sizeof(Primitive) + OFFSET(Primitive, outline->left) + (y + 1) * sizeof(Primitive::Span)));
x0 = Min(x0, Min(x0a, x0b));
}
x0 &= 0xFFFFFFFE;
- Int x1a = Int(*Pointer<Short>(primitive + OFFSET(Primitive,outline->right) + (y + 0) * sizeof(Primitive::Span)));
- Int x1b = Int(*Pointer<Short>(primitive + OFFSET(Primitive,outline->right) + (y + 1) * sizeof(Primitive::Span)));
+ Int x1a = Int(*Pointer<Short>(primitive + OFFSET(Primitive, outline->right) + (y + 0) * sizeof(Primitive::Span)));
+ Int x1b = Int(*Pointer<Short>(primitive + OFFSET(Primitive, outline->right) + (y + 1) * sizeof(Primitive::Span)));
Int x1 = Max(x1a, x1b);
for(unsigned int q = 1; q < state.multiSample; q++)
{
- x1a = Int(*Pointer<Short>(primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->right) + (y + 0) * sizeof(Primitive::Span)));
- x1b = Int(*Pointer<Short>(primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->right) + (y + 1) * sizeof(Primitive::Span)));
+ x1a = Int(*Pointer<Short>(primitive + q * sizeof(Primitive) + OFFSET(Primitive, outline->right) + (y + 0) * sizeof(Primitive::Span)));
+ x1b = Int(*Pointer<Short>(primitive + q * sizeof(Primitive) + OFFSET(Primitive, outline->right) + (y + 1) * sizeof(Primitive::Span)));
x1 = Max(x1, Max(x1a, x1b));
}
- Float4 yyyy = Float4(Float(y)) + *Pointer<Float4>(primitive + OFFSET(Primitive,yQuad), 16);
+ Float4 yyyy = Float4(Float(y)) + *Pointer<Float4>(primitive + OFFSET(Primitive, yQuad), 16);
if(interpolateZ())
{
@@ -129,10 +131,10 @@
if(state.multiSample > 1)
{
- y -= *Pointer<Float4>(constants + OFFSET(Constants,Y) + q * sizeof(float4));
+ y -= *Pointer<Float4>(constants + OFFSET(Constants, Y) + q * sizeof(float4));
}
- Dz[q] = *Pointer<Float4>(primitive + OFFSET(Primitive,z.C), 16) + y * *Pointer<Float4>(primitive + OFFSET(Primitive,z.B), 16);
+ Dz[q] = *Pointer<Float4>(primitive + OFFSET(Primitive, z.C), 16) + y * *Pointer<Float4>(primitive + OFFSET(Primitive, z.B), 16);
}
}
@@ -140,7 +142,7 @@
{
if(interpolateW())
{
- Dw = *Pointer<Float4>(primitive + OFFSET(Primitive,w.C), 16) + yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive,w.B), 16);
+ Dw = *Pointer<Float4>(primitive + OFFSET(Primitive, w.C), 16) + yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive, w.B), 16);
}
if(spirvShader)
@@ -154,20 +156,20 @@
if(!spirvShader->inputs[interpolant].Flat)
{
Dv[interpolant] +=
- yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive, V[interpolant].B), 16);
+ yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive, V[interpolant].B), 16);
}
}
for(unsigned int i = 0; i < state.numClipDistances; i++)
{
DclipDistance[i] = *Pointer<Float4>(primitive + OFFSET(Primitive, clipDistance[i].C), 16) +
- yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive, clipDistance[i].B), 16);
+ yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive, clipDistance[i].B), 16);
}
for(unsigned int i = 0; i < state.numCullDistances; i++)
{
DcullDistance[i] = *Pointer<Float4>(primitive + OFFSET(Primitive, cullDistance[i].C), 16) +
- yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive, cullDistance[i].B), 16);
+ yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive, cullDistance[i].B), 16);
}
}
@@ -176,7 +178,7 @@
for(unsigned int q = 0; q < state.multiSample; q++)
{
- xLeft[q] = *Pointer<Short4>(primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline) + y * sizeof(Primitive::Span));
+ xLeft[q] = *Pointer<Short4>(primitive + q * sizeof(Primitive) + OFFSET(Primitive, outline) + y * sizeof(Primitive::Span));
xRight[q] = xLeft[q];
xLeft[q] = Swizzle(xLeft[q], 0x0022) - Short4(1, 2, 1, 2);
@@ -190,7 +192,7 @@
for(unsigned int q = 0; q < state.multiSample; q++)
{
- if(state.multiSampleMask & (1<<q))
+ if(state.multiSampleMask & (1 << q))
{
unsigned int i = state.multiSampledBresenham ? 0 : q;
Short4 mask = CmpGT(xxxx, xLeft[i]) & CmpGT(xRight[i], xxxx);
@@ -210,18 +212,18 @@
{
if(state.colorWriteActive(index))
{
- cBuffer[index] += *Pointer<Int>(data + OFFSET(DrawData,colorPitchB[index])) << (1 + clusterCountLog2); // FIXME: Precompute
+ cBuffer[index] += *Pointer<Int>(data + OFFSET(DrawData, colorPitchB[index])) << (1 + clusterCountLog2); // FIXME: Precompute
}
}
if(state.depthTestActive)
{
- zBuffer += *Pointer<Int>(data + OFFSET(DrawData,depthPitchB)) << (1 + clusterCountLog2); // FIXME: Precompute
+ zBuffer += *Pointer<Int>(data + OFFSET(DrawData, depthPitchB)) << (1 + clusterCountLog2); // FIXME: Precompute
}
if(state.stencilActive)
{
- sBuffer += *Pointer<Int>(data + OFFSET(DrawData,stencilPitchB)) << (1 + clusterCountLog2); // FIXME: Precompute
+ sBuffer += *Pointer<Int>(data + OFFSET(DrawData, stencilPitchB)) << (1 + clusterCountLog2); // FIXME: Precompute
}
y += 2 * clusterCount;
diff --git a/src/Device/QuadRasterizer.hpp b/src/Device/QuadRasterizer.hpp
index 0311d8a..f24e80e 100644
--- a/src/Device/QuadRasterizer.hpp
+++ b/src/Device/QuadRasterizer.hpp
@@ -57,4 +57,4 @@
} // namespace sw
-#endif // sw_QuadRasterizer_hpp
+#endif // sw_QuadRasterizer_hpp
diff --git a/src/Device/Rasterizer.hpp b/src/Device/Rasterizer.hpp
index cf229e6..0c33857 100644
--- a/src/Device/Rasterizer.hpp
+++ b/src/Device/Rasterizer.hpp
@@ -24,7 +24,13 @@
class Rasterizer : public RasterizerFunction
{
public:
- Rasterizer() : primitive(Arg<0>()), count(Arg<1>()), cluster(Arg<2>()), clusterCount(Arg<3>()), data(Arg<4>()) {}
+ Rasterizer()
+ : primitive(Arg<0>())
+ , count(Arg<1>())
+ , cluster(Arg<2>())
+ , clusterCount(Arg<3>())
+ , data(Arg<4>())
+ {}
virtual ~Rasterizer() {}
protected:
@@ -37,4 +43,4 @@
} // namespace sw
-#endif // sw_Rasterizer_hpp
+#endif // sw_Rasterizer_hpp
diff --git a/src/Device/Renderer.cpp b/src/Device/Renderer.cpp
index 80a2662..966d9e5 100644
--- a/src/Device/Renderer.cpp
+++ b/src/Device/Renderer.cpp
@@ -15,13 +15,15 @@
#include "Renderer.hpp"
#include "Clipper.hpp"
-#include "Primitive.hpp"
#include "Polygon.hpp"
-#include "Reactor/Reactor.hpp"
+#include "Primitive.hpp"
+#include "Vertex.hpp"
#include "Pipeline/Constants.hpp"
-#include "System/Memory.hpp"
+#include "Pipeline/SpirvShader.hpp"
+#include "Reactor/Reactor.hpp"
#include "System/Half.hpp"
#include "System/Math.hpp"
+#include "System/Memory.hpp"
#include "System/Timer.hpp"
#include "Vulkan/VkConfig.h"
#include "Vulkan/VkDebug.hpp"
@@ -29,8 +31,6 @@
#include "Vulkan/VkFence.hpp"
#include "Vulkan/VkImageView.hpp"
#include "Vulkan/VkQueryPool.hpp"
-#include "Pipeline/SpirvShader.hpp"
-#include "Vertex.hpp"
#include "marl/containers.h"
#include "marl/defer.h"
@@ -52,91 +52,91 @@
switch(topology)
{
- case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
- {
- auto index = start;
- auto pointBatch = &(batch[0][0]);
- for(unsigned int i = 0; i < triangleCount; i++)
+ case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
{
- *pointBatch++ = indices[index++];
- }
+ auto index = start;
+ auto pointBatch = &(batch[0][0]);
+ for(unsigned int i = 0; i < triangleCount; i++)
+ {
+ *pointBatch++ = indices[index++];
+ }
- // Repeat the last index to allow for SIMD width overrun.
- index--;
- for(unsigned int i = 0; i < 3; i++)
- {
- *pointBatch++ = indices[index];
+ // Repeat the last index to allow for SIMD width overrun.
+ index--;
+ for(unsigned int i = 0; i < 3; i++)
+ {
+ *pointBatch++ = indices[index];
+ }
+ break;
}
- break;
- }
- case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
- {
- auto index = 2 * start;
- for(unsigned int i = 0; i < triangleCount; i++)
+ case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
{
- batch[i][0] = indices[index + (provokeFirst ? 0 : 1)];
- batch[i][1] = indices[index + (provokeFirst ? 1 : 0)];
- batch[i][2] = indices[index + 1];
+ auto index = 2 * start;
+ for(unsigned int i = 0; i < triangleCount; i++)
+ {
+ batch[i][0] = indices[index + (provokeFirst ? 0 : 1)];
+ batch[i][1] = indices[index + (provokeFirst ? 1 : 0)];
+ batch[i][2] = indices[index + 1];
- index += 2;
+ index += 2;
+ }
+ break;
}
- break;
- }
- case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
- {
- auto index = start;
- for(unsigned int i = 0; i < triangleCount; i++)
+ case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
{
- batch[i][0] = indices[index + (provokeFirst ? 0 : 1)];
- batch[i][1] = indices[index + (provokeFirst ? 1 : 0)];
- batch[i][2] = indices[index + 1];
+ auto index = start;
+ for(unsigned int i = 0; i < triangleCount; i++)
+ {
+ batch[i][0] = indices[index + (provokeFirst ? 0 : 1)];
+ batch[i][1] = indices[index + (provokeFirst ? 1 : 0)];
+ batch[i][2] = indices[index + 1];
- index += 1;
+ index += 1;
+ }
+ break;
}
- break;
- }
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
- {
- auto index = 3 * start;
- for(unsigned int i = 0; i < triangleCount; i++)
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
{
- batch[i][0] = indices[index + (provokeFirst ? 0 : 2)];
- batch[i][1] = indices[index + (provokeFirst ? 1 : 0)];
- batch[i][2] = indices[index + (provokeFirst ? 2 : 1)];
+ auto index = 3 * start;
+ for(unsigned int i = 0; i < triangleCount; i++)
+ {
+ batch[i][0] = indices[index + (provokeFirst ? 0 : 2)];
+ batch[i][1] = indices[index + (provokeFirst ? 1 : 0)];
+ batch[i][2] = indices[index + (provokeFirst ? 2 : 1)];
- index += 3;
+ index += 3;
+ }
+ break;
}
- break;
- }
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
- {
- auto index = start;
- for(unsigned int i = 0; i < triangleCount; i++)
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
{
- batch[i][0] = indices[index + (provokeFirst ? 0 : 2)];
- batch[i][1] = indices[index + ((start + i) & 1) + (provokeFirst ? 1 : 0)];
- batch[i][2] = indices[index + (~(start + i) & 1) + (provokeFirst ? 1 : 0)];
+ auto index = start;
+ for(unsigned int i = 0; i < triangleCount; i++)
+ {
+ batch[i][0] = indices[index + (provokeFirst ? 0 : 2)];
+ batch[i][1] = indices[index + ((start + i) & 1) + (provokeFirst ? 1 : 0)];
+ batch[i][2] = indices[index + (~(start + i) & 1) + (provokeFirst ? 1 : 0)];
- index += 1;
+ index += 1;
+ }
+ break;
}
- break;
- }
- case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
- {
- auto index = start + 1;
- for(unsigned int i = 0; i < triangleCount; i++)
+ case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
{
- batch[i][provokeFirst ? 0 : 2] = indices[index + 0];
- batch[i][provokeFirst ? 1 : 0] = indices[index + 1];
- batch[i][provokeFirst ? 2 : 1] = indices[0];
+ auto index = start + 1;
+ for(unsigned int i = 0; i < triangleCount; i++)
+ {
+ batch[i][provokeFirst ? 0 : 2] = indices[index + 0];
+ batch[i][provokeFirst ? 1 : 0] = indices[index + 1];
+ batch[i][provokeFirst ? 2 : 1] = indices[0];
- index += 1;
+ index += 1;
+ }
+ break;
}
- break;
- }
- default:
- ASSERT(false);
- return false;
+ default:
+ ASSERT(false);
+ return false;
}
return true;
@@ -144,7 +144,7 @@
DrawCall::DrawCall()
{
- data = (DrawData*)allocate(sizeof(DrawData));
+ data = (DrawData *)allocate(sizeof(DrawData));
data->constants = &constants;
}
@@ -153,7 +153,8 @@
deallocate(data);
}
-Renderer::Renderer(vk::Device* device) : device(device)
+Renderer::Renderer(vk::Device *device)
+ : device(device)
{
VertexProcessor::setRoutineCacheSize(1024);
PixelProcessor::setRoutineCacheSize(1024);
@@ -166,27 +167,27 @@
}
// Renderer objects have to be mem aligned to the alignment provided in the class declaration
-void* Renderer::operator new(size_t size)
+void *Renderer::operator new(size_t size)
{
ASSERT(size == sizeof(Renderer)); // This operator can't be called from a derived class
return vk::allocate(sizeof(Renderer), alignof(Renderer), vk::DEVICE_MEMORY, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
}
-void Renderer::operator delete(void* mem)
+void Renderer::operator delete(void *mem)
{
vk::deallocate(mem, vk::DEVICE_MEMORY);
}
-void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex,
- TaskEvents *events, int instanceID, int viewID, void *indexBuffer, const VkExtent3D& framebufferExtent,
- PushConstantStorage const & pushConstants, bool update)
+void Renderer::draw(const sw::Context *context, VkIndexType indexType, unsigned int count, int baseVertex,
+ TaskEvents *events, int instanceID, int viewID, void *indexBuffer, const VkExtent3D &framebufferExtent,
+ PushConstantStorage const &pushConstants, bool update)
{
if(count == 0) { return; }
auto id = nextDrawID++;
MARL_SCOPED_EVENT("draw %d", id);
- #ifndef NDEBUG
+#ifndef NDEBUG
{
unsigned int minPrimitives = 1;
unsigned int maxPrimitives = 1 << 21;
@@ -195,7 +196,7 @@
return;
}
}
- #endif
+#endif
int ms = context->sampleCount;
@@ -230,20 +231,20 @@
{
switch(context->polygonMode)
{
- case VK_POLYGON_MODE_FILL:
- setupPrimitives = &DrawCall::setupSolidTriangles;
- break;
- case VK_POLYGON_MODE_LINE:
- setupPrimitives = &DrawCall::setupWireframeTriangles;
- numPrimitivesPerBatch /= 3;
- break;
- case VK_POLYGON_MODE_POINT:
- setupPrimitives = &DrawCall::setupPointTriangles;
- numPrimitivesPerBatch /= 3;
- break;
- default:
- UNSUPPORTED("polygon mode: %d", int(context->polygonMode));
- return;
+ case VK_POLYGON_MODE_FILL:
+ setupPrimitives = &DrawCall::setupSolidTriangles;
+ break;
+ case VK_POLYGON_MODE_LINE:
+ setupPrimitives = &DrawCall::setupWireframeTriangles;
+ numPrimitivesPerBatch /= 3;
+ break;
+ case VK_POLYGON_MODE_POINT:
+ setupPrimitives = &DrawCall::setupPointTriangles;
+ numPrimitivesPerBatch /= 3;
+ break;
+ default:
+ UNSUPPORTED("polygon mode: %d", int(context->polygonMode));
+ return;
}
}
else if(context->isDrawLine(false))
@@ -275,7 +276,7 @@
data->descriptorSets = context->descriptorSets;
data->descriptorDynamicOffsets = context->descriptorDynamicOffsets;
- for(int i = 0; i < MAX_INTERFACE_COMPONENTS/4; i++)
+ for(int i = 0; i < MAX_INTERFACE_COMPONENTS / 4; i++)
{
data->input[i] = context->input[i].buffer;
data->robustnessSize[i] = context->input[i].robustnessSize;
@@ -311,7 +312,8 @@
data->a2c0 = float4(0.25f);
data->a2c1 = float4(0.75f);
}
- else ASSERT(false);
+ else
+ ASSERT(false);
}
if(pixelState.occlusionEnabled)
@@ -358,7 +360,7 @@
if(draw->renderTarget[index])
{
- data->colorBuffer[index] = (unsigned int*)context->renderTarget[index]->getOffsetPointer({0, 0, 0}, VK_IMAGE_ASPECT_COLOR_BIT, 0, data->viewID);
+ data->colorBuffer[index] = (unsigned int *)context->renderTarget[index]->getOffsetPointer({ 0, 0, 0 }, VK_IMAGE_ASPECT_COLOR_BIT, 0, data->viewID);
data->colorPitchB[index] = context->renderTarget[index]->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
data->colorSliceB[index] = context->renderTarget[index]->slicePitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
}
@@ -369,14 +371,14 @@
if(draw->depthBuffer)
{
- data->depthBuffer = (float*)context->depthBuffer->getOffsetPointer({0, 0, 0}, VK_IMAGE_ASPECT_DEPTH_BIT, 0, data->viewID);
+ data->depthBuffer = (float *)context->depthBuffer->getOffsetPointer({ 0, 0, 0 }, VK_IMAGE_ASPECT_DEPTH_BIT, 0, data->viewID);
data->depthPitchB = context->depthBuffer->rowPitchBytes(VK_IMAGE_ASPECT_DEPTH_BIT, 0);
data->depthSliceB = context->depthBuffer->slicePitchBytes(VK_IMAGE_ASPECT_DEPTH_BIT, 0);
}
if(draw->stencilBuffer)
{
- data->stencilBuffer = (unsigned char*)context->stencilBuffer->getOffsetPointer({0, 0, 0}, VK_IMAGE_ASPECT_STENCIL_BIT, 0, data->viewID);
+ data->stencilBuffer = (unsigned char *)context->stencilBuffer->getOffsetPointer({ 0, 0, 0 }, VK_IMAGE_ASPECT_STENCIL_BIT, 0, data->viewID);
data->stencilPitchB = context->stencilBuffer->rowPitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT, 0);
data->stencilSliceB = context->stencilBuffer->slicePitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT, 0);
}
@@ -435,7 +437,7 @@
pixelRoutine = {};
}
-void DrawCall::run(const marl::Loan<DrawCall>& draw, marl::Ticket::Queue* tickets, marl::Ticket::Queue clusterQueues[MaxClusterCount])
+void DrawCall::run(const marl::Loan<DrawCall> &draw, marl::Ticket::Queue *tickets, marl::Ticket::Queue clusterQueues[MaxClusterCount])
{
draw->setup();
@@ -463,7 +465,6 @@
}
marl::schedule([draw, batch, finally] {
-
processVertices(draw.get(), batch.get());
if(!draw->setupState.rasterizerDiscard)
@@ -485,7 +486,7 @@
}
}
-void DrawCall::processVertices(DrawCall* draw, BatchData* batch)
+void DrawCall::processVertices(DrawCall *draw, BatchData *batch)
{
MARL_SCOPED_EVENT("VERTEX draw %d, batch %d", draw->id, batch->id);
@@ -493,16 +494,16 @@
{
MARL_SCOPED_EVENT("processPrimitiveVertices");
processPrimitiveVertices(
- triangleIndices,
- draw->data->indices,
- draw->indexType,
- batch->firstPrimitive,
- batch->numPrimitives,
- draw->topology,
- draw->provokingVertexMode);
+ triangleIndices,
+ draw->data->indices,
+ draw->indexType,
+ batch->firstPrimitive,
+ batch->numPrimitives,
+ draw->topology,
+ draw->provokingVertexMode);
}
- auto& vertexTask = batch->vertexTask;
+ auto &vertexTask = batch->vertexTask;
vertexTask.primitiveStart = batch->firstPrimitive;
// We're only using batch compaction for points, not lines
vertexTask.vertexCount = batch->numPrimitives * ((draw->topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST) ? 1 : 3);
@@ -515,7 +516,7 @@
draw->vertexRoutine(&batch->triangles.front().v0, &triangleIndices[0][0], &vertexTask, draw->data);
}
-void DrawCall::processPrimitives(DrawCall* draw, BatchData* batch)
+void DrawCall::processPrimitives(DrawCall *draw, BatchData *batch)
{
MARL_SCOPED_EVENT("PRIMITIVES draw %d batch %d", draw->id, batch->id);
auto triangles = &batch->triangles[0];
@@ -523,12 +524,15 @@
batch->numVisible = draw->setupPrimitives(triangles, primitives, draw, batch->numPrimitives);
}
-void DrawCall::processPixels(const marl::Loan<DrawCall>& draw, const marl::Loan<BatchData>& batch, const std::shared_ptr<marl::Finally>& finally)
+void DrawCall::processPixels(const marl::Loan<DrawCall> &draw, const marl::Loan<BatchData> &batch, const std::shared_ptr<marl::Finally> &finally)
{
struct Data
{
- Data(const marl::Loan<DrawCall>& draw, const marl::Loan<BatchData>& batch, const std::shared_ptr<marl::Finally>& finally)
- : draw(draw), batch(batch), finally(finally) {}
+ Data(const marl::Loan<DrawCall> &draw, const marl::Loan<BatchData> &batch, const std::shared_ptr<marl::Finally> &finally)
+ : draw(draw)
+ , batch(batch)
+ , finally(finally)
+ {}
marl::Loan<DrawCall> draw;
marl::Loan<BatchData> batch;
std::shared_ptr<marl::Finally> finally;
@@ -536,10 +540,9 @@
auto data = std::make_shared<Data>(draw, batch, finally);
for(int cluster = 0; cluster < MaxClusterCount; cluster++)
{
- batch->clusterTickets[cluster].onCall([data, cluster]
- {
- auto& draw = data->draw;
- auto& batch = data->batch;
+ batch->clusterTickets[cluster].onCall([data, cluster] {
+ auto &draw = data->draw;
+ auto &batch = data->batch;
MARL_SCOPED_EVENT("PIXEL draw %d, batch %d, cluster %d", draw->id, batch->id, cluster);
draw->pixelRoutine(&batch->primitives.front(), batch->numVisible, cluster, MaxClusterCount, draw->data);
batch->clusterTickets[cluster].done();
@@ -557,13 +560,13 @@
}
void DrawCall::processPrimitiveVertices(
- unsigned int triangleIndicesOut[MaxBatchSize + 1][3],
- const void *primitiveIndices,
- VkIndexType indexType,
- unsigned int start,
- unsigned int triangleCount,
- VkPrimitiveTopology topology,
- VkProvokingVertexModeEXT provokingVertexMode)
+ unsigned int triangleIndicesOut[MaxBatchSize + 1][3],
+ const void *primitiveIndices,
+ VkIndexType indexType,
+ unsigned int start,
+ unsigned int triangleCount,
+ VkPrimitiveTopology topology,
+ VkProvokingVertexModeEXT provokingVertexMode)
{
if(!primitiveIndices)
{
@@ -581,22 +584,22 @@
{
switch(indexType)
{
- case VK_INDEX_TYPE_UINT16:
- if(!setBatchIndices(triangleIndicesOut, topology, provokingVertexMode, static_cast<const uint16_t*>(primitiveIndices), start, triangleCount))
- {
+ case VK_INDEX_TYPE_UINT16:
+ if(!setBatchIndices(triangleIndicesOut, topology, provokingVertexMode, static_cast<const uint16_t *>(primitiveIndices), start, triangleCount))
+ {
+ return;
+ }
+ break;
+ case VK_INDEX_TYPE_UINT32:
+ if(!setBatchIndices(triangleIndicesOut, topology, provokingVertexMode, static_cast<const uint32_t *>(primitiveIndices), start, triangleCount))
+ {
+ return;
+ }
+ break;
+ break;
+ default:
+ ASSERT(false);
return;
- }
- break;
- case VK_INDEX_TYPE_UINT32:
- if(!setBatchIndices(triangleIndicesOut, topology, provokingVertexMode, static_cast<const uint32_t*>(primitiveIndices), start, triangleCount))
- {
- return;
- }
- break;
- break;
- default:
- ASSERT(false);
- return;
}
}
@@ -626,7 +629,6 @@
Polygon polygon(&v0.position, &v1.position, &v2.position);
-
if((v0.cullMask | v1.cullMask | v2.cullMask) == 0)
{
continue;
@@ -658,7 +660,7 @@
int DrawCall::setupWireframeTriangles(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count)
{
- auto& state = drawCall->setupState;
+ auto &state = drawCall->setupState;
int ms = state.multiSample;
int visible = 0;
@@ -706,7 +708,7 @@
int DrawCall::setupPointTriangles(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count)
{
- auto& state = drawCall->setupState;
+ auto &state = drawCall->setupState;
int ms = state.multiSample;
int visible = 0;
@@ -838,7 +840,7 @@
P[2] = P1;
P[3] = P0;
- float scale = lineWidth * 0.5f / sqrt(dx*dx + dy*dy);
+ float scale = lineWidth * 0.5f / sqrt(dx * dx + dy * dy);
dx *= scale;
dy *= scale;
@@ -937,7 +939,7 @@
if(dx > -dy)
{
- if(dx > dy) // Right
+ if(dx > dy) // Right
{
L[0] = P[0];
L[1] = P[1];
@@ -946,7 +948,7 @@
L[4] = P[7];
L[5] = P[3];
}
- else // Down
+ else // Down
{
L[0] = P[0];
L[1] = P[4];
@@ -958,7 +960,7 @@
}
else
{
- if(dx > dy) // Up
+ if(dx > dy) // Up
{
L[0] = P[0];
L[1] = P[1];
@@ -967,7 +969,7 @@
L[4] = P[7];
L[5] = P[4];
}
- else // Left
+ else // Left
{
L[0] = P[1];
L[1] = P[2];
@@ -1029,14 +1031,14 @@
if(dx > -dy)
{
- if(dx > dy) // Right
+ if(dx > dy) // Right
{
L[0] = P[1];
L[1] = P[5];
L[2] = P[7];
L[3] = P[3];
}
- else // Down
+ else // Down
{
L[0] = P[0];
L[1] = P[4];
@@ -1046,14 +1048,14 @@
}
else
{
- if(dx > dy) // Up
+ if(dx > dy) // Up
{
L[0] = P[0];
L[1] = P[2];
L[2] = P[6];
L[3] = P[4];
}
- else // Left
+ else // Left
{
L[0] = P[1];
L[1] = P[3];
@@ -1150,7 +1152,7 @@
constexpr float subPixF = vk::SUBPIXEL_PRECISION_FACTOR;
triangle.v1.projected.x += iround(subPixF * 0.5f * pSize);
- triangle.v2.projected.y -= iround(subPixF * 0.5f * pSize) * (data.HxF[0] > 0.0f ? 1 : -1); // Both Direct3D and OpenGL expect (0, 0) in the top-left corner
+ triangle.v2.projected.y -= iround(subPixF * 0.5f * pSize) * (data.HxF[0] > 0.0f ? 1 : -1); // Both Direct3D and OpenGL expect (0, 0) in the top-left corner
return draw.setupRoutine(&primitive, &triangle, &polygon, &data);
}
@@ -1173,7 +1175,7 @@
occlusionQuery = nullptr;
}
-void Renderer::advanceInstanceAttributes(Stream* inputs)
+void Renderer::advanceInstanceAttributes(Stream *inputs)
{
for(uint32_t i = 0; i < vk::MAX_VERTEX_INPUT_BINDINGS; i++)
{
diff --git a/src/Device/Renderer.hpp b/src/Device/Renderer.hpp
index 1598c11..8723fbc 100644
--- a/src/Device/Renderer.hpp
+++ b/src/Device/Renderer.hpp
@@ -15,17 +15,17 @@
#ifndef sw_Renderer_hpp
#define sw_Renderer_hpp
-#include "VertexProcessor.hpp"
+#include "Blitter.hpp"
#include "PixelProcessor.hpp"
-#include "SetupProcessor.hpp"
#include "Plane.hpp"
#include "Primitive.hpp"
-#include "Blitter.hpp"
+#include "SetupProcessor.hpp"
+#include "VertexProcessor.hpp"
#include "Device/Config.hpp"
#include "Vulkan/VkDescriptorSet.hpp"
-#include "marl/pool.h"
#include "marl/finally.h"
+#include "marl/pool.h"
#include "marl/ticket.h"
#include <atomic>
@@ -76,9 +76,9 @@
float lineWidth;
int viewID;
- PixelProcessor::Stencil stencil[2]; // clockwise, counterclockwise
+ PixelProcessor::Stencil stencil[2]; // clockwise, counterclockwise
PixelProcessor::Factor factor;
- unsigned int occlusion[MaxClusterCount]; // Number of pixels passing depth test
+ unsigned int occlusion[MaxClusterCount]; // Number of pixels passing depth test
float4 WxF;
float4 HxF;
@@ -131,15 +131,15 @@
};
using Pool = marl::BoundedPool<DrawCall, MaxDrawCount, marl::PoolPolicy::Preserve>;
- using SetupFunction = int(*)(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count);
+ using SetupFunction = int (*)(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count);
DrawCall();
~DrawCall();
- static void run(const marl::Loan<DrawCall>& draw, marl::Ticket::Queue* tickets, marl::Ticket::Queue clusterQueues[MaxClusterCount]);
- static void processVertices(DrawCall* draw, BatchData* batch);
- static void processPrimitives(DrawCall* draw, BatchData* batch);
- static void processPixels(const marl::Loan<DrawCall>& draw, const marl::Loan<BatchData>& batch, const std::shared_ptr<marl::Finally>& finally);
+ static void run(const marl::Loan<DrawCall> &draw, marl::Ticket::Queue *tickets, marl::Ticket::Queue clusterQueues[MaxClusterCount]);
+ static void processVertices(DrawCall *draw, BatchData *batch);
+ static void processPrimitives(DrawCall *draw, BatchData *batch);
+ static void processPixels(const marl::Loan<DrawCall> &draw, const marl::Loan<BatchData> &batch, const std::shared_ptr<marl::Finally> &finally);
void setup();
void teardown();
@@ -167,22 +167,22 @@
vk::ImageView *stencilBuffer;
TaskEvents *events;
- vk::Query* occlusionQuery;
+ vk::Query *occlusionQuery;
DrawData *data;
static void processPrimitiveVertices(
- unsigned int triangleIndicesOut[MaxBatchSize + 1][3],
- const void *primitiveIndices,
- VkIndexType indexType,
- unsigned int start,
- unsigned int triangleCount,
- VkPrimitiveTopology topology,
- VkProvokingVertexModeEXT provokingVertexMode);
+ unsigned int triangleIndicesOut[MaxBatchSize + 1][3],
+ const void *primitiveIndices,
+ VkIndexType indexType,
+ unsigned int start,
+ unsigned int triangleCount,
+ VkPrimitiveTopology topology,
+ VkProvokingVertexModeEXT provokingVertexMode);
- static int setupSolidTriangles(Triangle* triangles, Primitive* primitives, const DrawCall* drawCall, int count);
- static int setupWireframeTriangles(Triangle* triangles, Primitive* primitives, const DrawCall* drawCall, int count);
- static int setupPointTriangles(Triangle* triangles, Primitive* primitives, const DrawCall* drawCall, int count);
+ static int setupSolidTriangles(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count);
+ static int setupWireframeTriangles(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count);
+ static int setupPointTriangles(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count);
static int setupLines(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count);
static int setupPoints(Triangle *triangles, Primitive *primitives, const DrawCall *drawCall, int count);
@@ -193,18 +193,18 @@
class alignas(16) Renderer : public VertexProcessor, public PixelProcessor, public SetupProcessor
{
public:
- Renderer(vk::Device* device);
+ Renderer(vk::Device *device);
virtual ~Renderer();
- void* operator new(size_t size);
- void operator delete(void* mem);
+ void *operator new(size_t size);
+ void operator delete(void *mem);
bool hasOcclusionQuery() const { return occlusionQuery != nullptr; }
- void draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex,
- TaskEvents *events, int instanceID, int viewID, void *indexBuffer, const VkExtent3D& framebufferExtent,
- PushConstantStorage const & pushConstants, bool update = true);
+ void draw(const sw::Context *context, VkIndexType indexType, unsigned int count, int baseVertex,
+ TaskEvents *events, int instanceID, int viewID, void *indexBuffer, const VkExtent3D &framebufferExtent,
+ PushConstantStorage const &pushConstants, bool update = true);
// Viewport & Clipper
void setViewport(const VkViewport &viewport);
@@ -213,7 +213,7 @@
void addQuery(vk::Query *query);
void removeQuery(vk::Query *query);
- void advanceInstanceAttributes(Stream* inputs);
+ void advanceInstanceAttributes(Stream *inputs);
void synchronize();
@@ -224,7 +224,7 @@
DrawCall::Pool drawCallPool;
DrawCall::BatchData::Pool batchDataPool;
- std::atomic<int> nextDrawID = {0};
+ std::atomic<int> nextDrawID = { 0 };
vk::Query *occlusionQuery = nullptr;
marl::Ticket::Queue drawTickets;
@@ -238,9 +238,9 @@
SetupProcessor::RoutineType setupRoutine;
PixelProcessor::RoutineType pixelRoutine;
- vk::Device* device;
+ vk::Device *device;
};
} // namespace sw
-#endif // sw_Renderer_hpp
+#endif // sw_Renderer_hpp
diff --git a/src/Device/RoutineCache.hpp b/src/Device/RoutineCache.hpp
index 9bde0d5..ce48e42 100644
--- a/src/Device/RoutineCache.hpp
+++ b/src/Device/RoutineCache.hpp
@@ -29,6 +29,6 @@
template<class State, class FunctionType>
using RoutineCacheT = LRUCache<State, RoutineT<FunctionType>>;
-}
+} // namespace sw
-#endif // sw_RoutineCache_hpp
+#endif // sw_RoutineCache_hpp
diff --git a/src/Device/Sampler.hpp b/src/Device/Sampler.hpp
index a836ce2..a377ea0 100644
--- a/src/Device/Sampler.hpp
+++ b/src/Device/Sampler.hpp
@@ -20,7 +20,9 @@
#include "System/Types.hpp"
#include "Vulkan/VkFormat.h"
-namespace vk { class Image; }
+namespace vk {
+class Image;
+}
namespace sw {
@@ -79,10 +81,10 @@
ADDRESSING_CLAMP,
ADDRESSING_MIRROR,
ADDRESSING_MIRRORONCE,
- ADDRESSING_BORDER, // Single color
- ADDRESSING_SEAMLESS, // Border of pixels
- ADDRESSING_CUBEFACE, // Cube face layer
- ADDRESSING_LAYER, // Array layer
+ ADDRESSING_BORDER, // Single color
+ ADDRESSING_SEAMLESS, // Border of pixels
+ ADDRESSING_CUBEFACE, // Cube face layer
+ ADDRESSING_LAYER, // Array layer
ADDRESSING_TEXELFETCH,
ADDRESSING_LAST = ADDRESSING_TEXELFETCH
@@ -114,4 +116,4 @@
} // namespace sw
-#endif // sw_Sampler_hpp
+#endif // sw_Sampler_hpp
diff --git a/src/Device/SetupProcessor.cpp b/src/Device/SetupProcessor.cpp
index e5057b9..2271cb8 100644
--- a/src/Device/SetupProcessor.cpp
+++ b/src/Device/SetupProcessor.cpp
@@ -14,14 +14,14 @@
#include "SetupProcessor.hpp"
-#include "Primitive.hpp"
-#include "Polygon.hpp"
#include "Context.hpp"
+#include "Polygon.hpp"
+#include "Primitive.hpp"
#include "Renderer.hpp"
-#include "Pipeline/SetupRoutine.hpp"
#include "Pipeline/Constants.hpp"
-#include "Vulkan/VkDebug.hpp"
+#include "Pipeline/SetupRoutine.hpp"
#include "Pipeline/SpirvShader.hpp"
+#include "Vulkan/VkDebug.hpp"
#include <cstring>
@@ -29,7 +29,7 @@
uint32_t SetupProcessor::States::computeHash()
{
- uint32_t *state = reinterpret_cast<uint32_t*>(this);
+ uint32_t *state = reinterpret_cast<uint32_t *>(this);
uint32_t hash = 0;
for(unsigned int i = 0; i < sizeof(States) / sizeof(uint32_t); i++)
@@ -48,7 +48,7 @@
}
static_assert(is_memcmparable<State>::value, "Cannot memcmp States");
- return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
+ return memcmp(static_cast<const States *>(this), static_cast<const States *>(&state), sizeof(States)) == 0;
}
SetupProcessor::SetupProcessor()
@@ -63,7 +63,7 @@
routineCache = nullptr;
}
-SetupProcessor::State SetupProcessor::update(const sw::Context* context) const
+SetupProcessor::State SetupProcessor::update(const sw::Context *context) const
{
State state;
diff --git a/src/Device/SetupProcessor.hpp b/src/Device/SetupProcessor.hpp
index 4b6d5a8..e418bc9 100644
--- a/src/Device/SetupProcessor.hpp
+++ b/src/Device/SetupProcessor.hpp
@@ -15,11 +15,11 @@
#ifndef sw_SetupProcessor_hpp
#define sw_SetupProcessor_hpp
-#include <Pipeline/SpirvShader.hpp>
#include "Context.hpp"
#include "Memset.hpp"
#include "RoutineCache.hpp"
#include "System/Types.hpp"
+#include <Pipeline/SpirvShader.hpp>
namespace sw {
@@ -30,29 +30,31 @@
struct DrawCall;
struct DrawData;
-using SetupFunction = FunctionT<int(Primitive* primitive, const Triangle* triangle, const Polygon* polygon, const DrawData* draw)>;
+using SetupFunction = FunctionT<int(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw)>;
class SetupProcessor
{
public:
struct States : Memset<States>
{
- States() : Memset(this, 0) {}
+ States()
+ : Memset(this, 0)
+ {}
uint32_t computeHash();
- bool isDrawPoint : 1;
- bool isDrawLine : 1;
- bool isDrawTriangle : 1;
- bool applySlopeDepthBias : 1;
- bool interpolateZ : 1;
- bool interpolateW : 1;
- VkFrontFace frontFace : BITS(VK_FRONT_FACE_MAX_ENUM);
- VkCullModeFlags cullMode : BITS(VK_CULL_MODE_FLAG_BITS_MAX_ENUM);
- unsigned int multiSample : 3; // 1, 2 or 4
- bool rasterizerDiscard : 1;
- unsigned int numClipDistances : 4; // [0 - 8]
- unsigned int numCullDistances : 4; // [0 - 8]
+ bool isDrawPoint : 1;
+ bool isDrawLine : 1;
+ bool isDrawTriangle : 1;
+ bool applySlopeDepthBias : 1;
+ bool interpolateZ : 1;
+ bool interpolateW : 1;
+ VkFrontFace frontFace : BITS(VK_FRONT_FACE_MAX_ENUM);
+ VkCullModeFlags cullMode : BITS(VK_CULL_MODE_FLAG_BITS_MAX_ENUM);
+ unsigned int multiSample : 3; // 1, 2 or 4
+ bool rasterizerDiscard : 1;
+ unsigned int numClipDistances : 4; // [0 - 8]
+ unsigned int numCullDistances : 4; // [0 - 8]
SpirvShader::InterfaceComponent gradient[MAX_INTERFACE_COMPONENTS];
};
@@ -71,7 +73,7 @@
~SetupProcessor();
protected:
- State update(const sw::Context* context) const;
+ State update(const sw::Context *context) const;
RoutineType routine(const State &state);
void setRoutineCacheSize(int cacheSize);
@@ -83,4 +85,4 @@
} // namespace sw
-#endif // sw_SetupProcessor_hpp
+#endif // sw_SetupProcessor_hpp
diff --git a/src/Device/Stream.hpp b/src/Device/Stream.hpp
index f83d97a..8e2fd98 100644
--- a/src/Device/Stream.hpp
+++ b/src/Device/Stream.hpp
@@ -21,15 +21,15 @@
enum StreamType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
- STREAMTYPE_COLOR, // 4 normalized unsigned bytes, ZYXW order
- STREAMTYPE_FLOAT, // Normalization ignored
+ STREAMTYPE_COLOR, // 4 normalized unsigned bytes, ZYXW order
+ STREAMTYPE_FLOAT, // Normalization ignored
STREAMTYPE_BYTE,
STREAMTYPE_SBYTE,
STREAMTYPE_SHORT,
STREAMTYPE_USHORT,
STREAMTYPE_INT,
STREAMTYPE_UINT,
- STREAMTYPE_HALF, // Normalization ignored
+ STREAMTYPE_HALF, // Normalization ignored
STREAMTYPE_2_10_10_10_INT,
STREAMTYPE_2_10_10_10_UINT,
@@ -51,4 +51,4 @@
} // namespace sw
-#endif // sw_Stream_hpp
+#endif // sw_Stream_hpp
diff --git a/src/Device/Triangle.hpp b/src/Device/Triangle.hpp
index 7cb4055..d99fe84 100644
--- a/src/Device/Triangle.hpp
+++ b/src/Device/Triangle.hpp
@@ -28,4 +28,4 @@
} // namespace sw
-#endif // sw_Triangle_hpp
+#endif // sw_Triangle_hpp
diff --git a/src/Device/Vector.cpp b/src/Device/Vector.cpp
index 511b51f..681efc3 100644
--- a/src/Device/Vector.cpp
+++ b/src/Device/Vector.cpp
@@ -81,7 +81,7 @@
bool operator>(const Vector &u, const Vector &v)
{
- if((u^2) > (v^2))
+ if((u ^ 2) > (v ^ 2))
return true;
else
return false;
@@ -89,7 +89,7 @@
bool operator<(const Vector &u, const Vector &v)
{
- if((u^2) < (v^2))
+ if((u ^ 2) < (v ^ 2))
return true;
else
return false;
@@ -158,12 +158,12 @@
float Vector::N(const Vector &v)
{
- return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
+ return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
float Vector::N2(const Vector &v)
{
- return v.x*v.x + v.y*v.y + v.z*v.z;
+ return v.x * v.x + v.y * v.y + v.z * v.z;
}
Vector lerp(const Vector &u, const Vector &v, float t)
diff --git a/src/Device/Vector.hpp b/src/Device/Vector.hpp
index 0df6f5a..a398943 100644
--- a/src/Device/Vector.hpp
+++ b/src/Device/Vector.hpp
@@ -62,19 +62,19 @@
friend Vector operator+(const Vector &u, const Vector &v);
friend Vector operator-(const Vector &u, const Vector &v);
- friend float operator*(const Vector &u, const Vector &v); // Dot product
+ friend float operator*(const Vector &u, const Vector &v); // Dot product
friend Vector operator*(float s, const Vector &v);
friend Vector operator*(const Vector &v, float s);
friend Vector operator/(const Vector &v, float s);
friend float operator^(const Vector &u, const Vector &v); // Angle between vectors
- friend Vector operator%(const Vector &u, const Vector &v); // Cross product
+ friend Vector operator%(const Vector &u, const Vector &v); // Cross product
- friend Vector operator*(const Matrix &M, const Vector& v);
+ friend Vector operator*(const Matrix &M, const Vector &v);
friend Vector operator*(const Vector &v, const Matrix &M);
friend Vector &operator*=(Vector &v, const Matrix &M);
static float N(const Vector &v); // Norm
- static float N2(const Vector &v); // Squared norm
+ static float N2(const Vector &v); // Squared norm
static Vector mirror(const Vector &v, const Plane &p);
static Vector reflect(const Vector &v, const Plane &p);
@@ -154,4 +154,4 @@
} // namespace sw
-#endif // Vector_hpp
+#endif // Vector_hpp
diff --git a/src/Device/Vertex.hpp b/src/Device/Vertex.hpp
index f6436e9..b328c44 100644
--- a/src/Device/Vertex.hpp
+++ b/src/Device/Vertex.hpp
@@ -16,8 +16,8 @@
#define Vertex_hpp
#include "Color.hpp"
-#include "System/Types.hpp"
#include "Device/Config.hpp"
+#include "System/Types.hpp"
namespace sw {
@@ -58,4 +58,4 @@
} // namespace sw
-#endif // Vertex_hpp
+#endif // Vertex_hpp
diff --git a/src/Device/VertexProcessor.cpp b/src/Device/VertexProcessor.cpp
index e77b2f7..3f72121 100644
--- a/src/Device/VertexProcessor.cpp
+++ b/src/Device/VertexProcessor.cpp
@@ -14,8 +14,8 @@
#include "VertexProcessor.hpp"
-#include "Pipeline/VertexProgram.hpp"
#include "Pipeline/Constants.hpp"
+#include "Pipeline/VertexProgram.hpp"
#include "System/Math.hpp"
#include "Vulkan/VkDebug.hpp"
@@ -33,7 +33,7 @@
uint32_t VertexProcessor::States::computeHash()
{
- uint32_t *state = reinterpret_cast<uint32_t*>(this);
+ uint32_t *state = reinterpret_cast<uint32_t *>(this);
uint32_t hash = 0;
for(unsigned int i = 0; i < sizeof(States) / sizeof(uint32_t); i++)
@@ -48,23 +48,23 @@
{
switch(type)
{
- case STREAMTYPE_FLOAT:
- case STREAMTYPE_INT:
- case STREAMTYPE_UINT:
- return count * sizeof(uint32_t);
- case STREAMTYPE_HALF:
- case STREAMTYPE_SHORT:
- case STREAMTYPE_USHORT:
- return count * sizeof(uint16_t);
- case STREAMTYPE_BYTE:
- case STREAMTYPE_SBYTE:
- return count * sizeof(uint8_t);
- case STREAMTYPE_COLOR:
- case STREAMTYPE_2_10_10_10_INT:
- case STREAMTYPE_2_10_10_10_UINT:
- return sizeof(int);
- default:
- UNSUPPORTED("stream.type %d", int(type));
+ case STREAMTYPE_FLOAT:
+ case STREAMTYPE_INT:
+ case STREAMTYPE_UINT:
+ return count * sizeof(uint32_t);
+ case STREAMTYPE_HALF:
+ case STREAMTYPE_SHORT:
+ case STREAMTYPE_USHORT:
+ return count * sizeof(uint16_t);
+ case STREAMTYPE_BYTE:
+ case STREAMTYPE_SBYTE:
+ return count * sizeof(uint8_t);
+ case STREAMTYPE_COLOR:
+ case STREAMTYPE_2_10_10_10_INT:
+ case STREAMTYPE_2_10_10_10_UINT:
+ return sizeof(int);
+ default:
+ UNSUPPORTED("stream.type %d", int(type));
}
return 0;
@@ -78,7 +78,7 @@
}
static_assert(is_memcmparable<State>::value, "Cannot memcmp States");
- return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
+ return memcmp(static_cast<const States *>(this), static_cast<const States *>(&state), sizeof(States)) == 0;
}
VertexProcessor::VertexProcessor()
@@ -99,7 +99,7 @@
routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536));
}
-const VertexProcessor::State VertexProcessor::update(const sw::Context* context)
+const VertexProcessor::State VertexProcessor::update(const sw::Context *context)
{
State state;
@@ -114,7 +114,7 @@
state.input[i].normalized = context->input[i].normalized;
// TODO: get rid of attribType -- just keep the VK format all the way through, this fully determines
// how to handle the attribute.
- state.input[i].attribType = context->vertexShader->inputs[i*4].Type;
+ state.input[i].attribType = context->vertexShader->inputs[i * 4].Type;
}
state.hash = state.computeHash();
@@ -129,7 +129,7 @@
{
auto routine = routineCache->query(state);
- if(!routine) // Create one
+ if(!routine) // Create one
{
VertexRoutine *generator = new VertexProgram(state, pipelineLayout, vertexShader, descriptorSets);
generator->generate();
diff --git a/src/Device/VertexProcessor.hpp b/src/Device/VertexProcessor.hpp
index c94e82e..d72fd10 100644
--- a/src/Device/VertexProcessor.hpp
+++ b/src/Device/VertexProcessor.hpp
@@ -29,7 +29,7 @@
// Basic direct mapped vertex cache.
struct VertexCache
{
- static constexpr uint32_t SIZE = 64; // TODO: Variable size?
+ static constexpr uint32_t SIZE = 64; // TODO: Variable size?
static constexpr uint32_t TAG_MASK = SIZE - 1; // Size must be power of 2.
void clear();
@@ -50,14 +50,16 @@
VertexCache vertexCache;
};
-using VertexRoutineFunction = FunctionT<void(Vertex* output, unsigned int* batch, VertexTask* vertextask, DrawData* draw)>;
+using VertexRoutineFunction = FunctionT<void(Vertex *output, unsigned int *batch, VertexTask *vertextask, DrawData *draw)>;
class VertexProcessor
{
public:
struct States : Memset<States>
{
- States() : Memset(this, 0) {}
+ States()
+ : Memset(this, 0)
+ {}
uint32_t computeHash();
@@ -65,16 +67,16 @@
struct Input
{
- operator bool() const // Returns true if stream contains data
+ operator bool() const // Returns true if stream contains data
{
return count != 0;
}
unsigned int bytesPerAttrib() const;
- StreamType type : BITS(STREAMTYPE_LAST);
+ StreamType type : BITS(STREAMTYPE_LAST);
unsigned int count : 3;
- bool normalized : 1;
+ bool normalized : 1;
unsigned int attribType : BITS(SpirvShader::ATTRIBTYPE_LAST);
};
@@ -97,7 +99,7 @@
virtual ~VertexProcessor();
protected:
- const State update(const sw::Context* context);
+ const State update(const sw::Context *context);
RoutineType routine(const State &state, vk::PipelineLayout const *pipelineLayout,
SpirvShader const *vertexShader, const vk::DescriptorSet::Bindings &descriptorSets);
@@ -110,4 +112,4 @@
} // namespace sw
-#endif // sw_VertexProcessor_hpp
+#endif // sw_VertexProcessor_hpp