Commit fccfc566 by Ben Clayton

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: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent d4e6447c
......@@ -14,14 +14,13 @@
#include "BC_Decoder.hpp"
namespace
{
static constexpr int BlockWidth = 4;
static constexpr int BlockHeight = 4;
namespace {
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
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
{
Color c[4];
c[0].extract565(c0);
......@@ -46,12 +45,12 @@ namespace
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:
private:
struct Color
{
Color()
......@@ -107,7 +106,7 @@ namespace
return res;
}
Color operator+(Color const& obj) const
Color operator+(Color const &obj) const
{
Color res;
for(int i = 0; i < 4; ++i)
......@@ -130,11 +129,11 @@ namespace
unsigned short c0;
unsigned short c1;
unsigned int idx;
};
};
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
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
{
int c[8] = { 0 };
......@@ -175,7 +174,7 @@ namespace
}
}
private:
private:
unsigned char getIdx(int i) const
{
int offset = i * 3 + 16;
......@@ -183,16 +182,16 @@ namespace
}
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
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;
unsigned char *dstRow = dst;
for(int i = 0; i < BlockWidth && (x + i) < dstW; i++, dstRow += dstBpp)
{
*dstRow = getAlpha(j * BlockHeight + i);
......@@ -200,7 +199,7 @@ namespace
}
}
private:
private:
unsigned char getAlpha(int i) const
{
int offset = i << 2;
......@@ -209,11 +208,11 @@ namespace
}
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");
......@@ -228,10 +227,10 @@ bool BC_Decoder::Decode(const unsigned char* src, unsigned char* dst, int w, int
{
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);
......@@ -241,11 +240,11 @@ bool BC_Decoder::Decode(const unsigned char* src, unsigned char* dst, int w, int
break;
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);
......@@ -256,11 +255,11 @@ bool BC_Decoder::Decode(const unsigned char* src, unsigned char* dst, int w, int
break;
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);
......@@ -271,10 +270,10 @@ bool BC_Decoder::Decode(const unsigned char* src, unsigned char* dst, int w, int
break;
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);
......@@ -284,11 +283,11 @@ bool BC_Decoder::Decode(const unsigned char* src, unsigned char* dst, int w, int
break;
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);
......
......@@ -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 @@ public:
/// @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);
};
......@@ -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 @@ Blitter::~Blitter()
{
}
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 @@ void Blitter::clear(void *pixel, vk::Format format, vk::Image *dest, const vk::F
return;
}
VkImageSubresourceLayers subresLayers =
{
VkImageSubresourceLayers subresLayers = {
subresourceRange.aspectMask,
subresourceRange.baseMipLevel,
subresourceRange.baseArrayLayer,
......@@ -102,8 +101,7 @@ void Blitter::clear(void *pixel, vk::Format format, vk::Image *dest, const vk::F
area.extent.height = extent.height;
}
BlitData data =
{
BlitData data = {
pixel, nullptr, // source, dest
format.bytes(), // sPitchB
......@@ -126,7 +124,7 @@ void Blitter::clear(void *pixel, vk::Format format, vk::Image *dest, const vk::F
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 @@ void Blitter::clear(void *pixel, vk::Format format, vk::Image *dest, const vk::F
}
}
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];
......@@ -197,8 +195,7 @@ bool Blitter::fastClear(void *pixel, vk::Format format, vk::Image *dest, const v
return false;
}
VkImageSubresourceLayers subresLayers =
{
VkImageSubresourceLayers subresLayers = {
subresourceRange.aspectMask,
subresourceRange.baseMipLevel,
subresourceRange.baseArrayLayer,
......@@ -233,7 +230,7 @@ bool Blitter::fastClear(void *pixel, vk::Format format, vk::Image *dest, const v
{
for(uint32_t depth = 0; depth < extent.depth; depth++)
{
uint8_t *slice = (uint8_t*)dest->getTexelPointer(
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++)
......@@ -246,7 +243,7 @@ bool Blitter::fastClear(void *pixel, vk::Format format, vk::Image *dest, const v
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);
sw::clear((uint16_t *)d, static_cast<uint16_t>(packed), area.extent.width);
d += rowPitchBytes;
}
break;
......@@ -254,7 +251,7 @@ bool Blitter::fastClear(void *pixel, vk::Format format, vk::Image *dest, const v
for(uint32_t i = 0; i < area.extent.height; i++)
{
ASSERT(d < dest->end());
sw::clear((uint32_t*)d, packed, area.extent.width);
sw::clear((uint32_t *)d, packed, area.extent.width);
d += rowPitchBytes;
}
break;
......@@ -487,14 +484,10 @@ void Blitter::write(Float4 &c, Pointer<Byte> element, const State &state)
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)));
*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:
......@@ -516,7 +509,8 @@ void Blitter::write(Float4 &c, Pointer<Byte> element, const State &state)
((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));
UShort((RoundInt(Float(c.z)) & Int(0xF)) << 12)) &
UShort(mask));
}
break;
case VK_FORMAT_B8G8R8A8_SRGB:
......@@ -842,7 +836,8 @@ void Blitter::write(Float4 &c, Pointer<Byte> element, const State &state)
*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));
(RoundInt(Float(c.x)) << Int(11))) &
UShort(mask));
}
break;
case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
......@@ -864,7 +859,8 @@ void Blitter::write(Float4 &c, Pointer<Byte> element, const State &state)
(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));
(RoundInt(Float(c.x)) << Int(11))) &
UShort(mask));
}
break;
case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
......@@ -886,7 +882,8 @@ void Blitter::write(Float4 &c, Pointer<Byte> element, const State &state)
(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));
(RoundInt(Float(c.z)) << Int(11))) &
UShort(mask));
}
break;
case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
......@@ -908,7 +905,8 @@ void Blitter::write(Float4 &c, Pointer<Byte> element, const State &state)
(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));
(RoundInt(Float(c.w)) << Int(15))) &
UShort(mask));
}
break;
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
......@@ -932,7 +930,8 @@ void Blitter::write(Float4 &c, Pointer<Byte> element, const State &state)
(UInt(RoundInt(Float(c.x)) |
(RoundInt(Float(c.y)) << 10) |
(RoundInt(Float(c.z)) << 20) |
(RoundInt(Float(c.w)) << 30)) & UInt(mask));
(RoundInt(Float(c.w)) << 30)) &
UInt(mask));
}
break;
case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
......@@ -956,7 +955,8 @@ void Blitter::write(Float4 &c, Pointer<Byte> element, const State &state)
(UInt(RoundInt(Float(c.z)) |
(RoundInt(Float(c.y)) << 10) |
(RoundInt(Float(c.x)) << 20) |
(RoundInt(Float(c.w)) << 30)) & UInt(mask));
(RoundInt(Float(c.w)) << 30)) &
UInt(mask));
}
break;
case VK_FORMAT_D16_UNORM:
......@@ -1359,23 +1359,23 @@ Blitter::BlitRoutineType Blitter::generate(const State &state)
{
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();
......@@ -1450,7 +1450,7 @@ Blitter::BlitRoutineType Blitter::generate(const State &state)
{
write(color, d, state);
d += *Pointer<Int>(blit + OFFSET(BlitData,dSliceB));
d += *Pointer<Int>(blit + OFFSET(BlitData, dSliceB));
}
}
else
......@@ -1552,7 +1552,7 @@ Blitter::BlitRoutineType Blitter::generate(const State &state)
{
write(color, d, state);
d += *Pointer<Int>(blit + OFFSET(BlitData,dSliceB));
d += *Pointer<Int>(blit + OFFSET(BlitData, dSliceB));
}
}
}
......@@ -1594,7 +1594,7 @@ void Blitter::blitToBuffer(const vk::Image *src, VkImageSubresourceLayers subres
{
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,8 +1602,7 @@ void Blitter::blitToBuffer(const vk::Image *src, VkImageSubresourceLayers subres
return;
}
BlitData data =
{
BlitData data = {
nullptr, // source
dst, // dest
src->rowPitchBytes(aspect, subresource.mipLevel), // sPitchB
......@@ -1627,8 +1626,7 @@ void Blitter::blitToBuffer(const vk::Image *src, VkImageSubresourceLayers subres
VkImageSubresourceLayers srcSubresLayers = subresource;
srcSubresLayers.layerCount = 1;
VkImageSubresourceRange srcSubresRange =
{
VkImageSubresourceRange srcSubresRange = {
subresource.aspectMask,
subresource.mipLevel,
1,
......@@ -1657,7 +1655,7 @@ void Blitter::blitFromBuffer(const vk::Image *dst, VkImageSubresourceLayers subr
{
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,8 +1663,7 @@ void Blitter::blitFromBuffer(const vk::Image *dst, VkImageSubresourceLayers subr
return;
}
BlitData data =
{
BlitData data = {
src, // source
nullptr, // dest
bufferRowPitch, // sPitchB
......@@ -1693,8 +1690,7 @@ void Blitter::blitFromBuffer(const vk::Image *dst, VkImageSubresourceLayers subr
VkImageSubresourceLayers dstSubresLayers = subresource;
dstSubresLayers.layerCount = 1;
VkImageSubresourceRange dstSubresRange =
{
VkImageSubresourceRange dstSubresRange = {
subresource.aspectMask,
subresource.mipLevel,
1,
......@@ -1781,8 +1777,7 @@ void Blitter::blit(const vk::Image *src, vk::Image *dst, VkImageBlit region, VkF
return;
}
BlitData data =
{
BlitData data = {
nullptr, // source
nullptr, // dest
src->rowPitchBytes(srcAspect, region.srcSubresource.mipLevel), // sPitchB
......@@ -1807,24 +1802,21 @@ void Blitter::blit(const vk::Image *src, vk::Image *dst, VkImageBlit region, VkF
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::blit(const vk::Image *src, vk::Image *dst, VkImageBlit region, VkF
}
}
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 @@ void Blitter::computeCubeCorner(Pointer<Byte>& layer, Int& x0, Int& x1, Int& y0,
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 @@ Blitter::CornerUpdateRoutineType Blitter::generateCornerUpdate(const State& stat
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 @@ Blitter::CornerUpdateRoutineType Blitter::generateCornerUpdate(const State& stat
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 @@ void Blitter::updateBorders(vk::Image* image, const VkImageSubresourceLayers& su
}
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 @@ void Blitter::updateBorders(vk::Image* image, const VkImageSubresourceLayers& su
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 @@ void Blitter::copyCubeEdge(vk::Image* image,
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 @@ void Blitter::copyCubeEdge(vk::Image* image,
}
}
} // namepspace sw
} // namespace sw
......@@ -20,8 +20,8 @@
#include "Reactor/Reactor.hpp"
#include "Vulkan/VkFormat.h"
#include <mutex>
#include <cstring>
#include <mutex>
namespace vk {
......@@ -38,9 +38,19 @@ class Blitter
{
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 @@ class Blitter
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 @@ public:
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,20 +164,20 @@ private:
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
......
......@@ -277,17 +277,26 @@ 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(polygon.n >= 3)
{
if(clipFlagsOr & CLIP_FAR) clipFar(polygon);
if(polygon.n >= 3) {
if(polygon.n >= 3)
{
if(clipFlagsOr & CLIP_LEFT) clipLeft(polygon);
if(polygon.n >= 3) {
if(polygon.n >= 3)
{
if(clipFlagsOr & CLIP_RIGHT) clipRight(polygon);
if(polygon.n >= 3) {
if(polygon.n >= 3)
{
if(clipFlagsOr & CLIP_TOP) clipTop(polygon);
if(polygon.n >= 3) {
if(polygon.n >= 3)
{
if(clipFlagsOr & CLIP_BOTTOM) clipBottom(polygon);
}}}}}
}
}
}
}
}
}
return polygon.n >= 3;
......
......@@ -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 {
......@@ -44,7 +44,7 @@ struct Color
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);
......@@ -69,7 +69,7 @@ struct Color
T b;
T a;
};
}
} // namespace sw
#include "System/Math.hpp"
......@@ -340,7 +340,7 @@ inline Color<T> Color<T>::operator-() const
}
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;
......
......@@ -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>
......
......@@ -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 PushConstantStorage
struct BlendState : Memset<BlendState>
{
BlendState() : Memset(this, 0) {}
BlendState()
: Memset(this, 0)
{}
BlendState(bool alphaBlendEnable,
VkBlendFactor sourceBlendFactor,
......@@ -48,15 +50,15 @@ struct BlendState : Memset<BlendState>
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;
......
......@@ -14,27 +14,26 @@
#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)
{
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)
{
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
{
struct bgra8
{
unsigned char b;
unsigned char g;
unsigned char r;
......@@ -59,43 +58,43 @@ namespace
a = clampByte(alpha);
}
const bgra8& addA(unsigned char alpha)
const bgra8 &addA(unsigned char alpha)
{
a = alpha;
return *this;
}
};
};
inline int extend_4to8bits(int x)
{
inline int extend_4to8bits(int x)
{
return (x << 4) | x;
}
}
inline int extend_5to8bits(int x)
{
inline int extend_5to8bits(int x)
{
return (x << 3) | (x >> 2);
}
}
inline int extend_6to8bits(int x)
{
inline int extend_6to8bits(int x)
{
return (x << 2) | (x >> 4);
}
}
inline int extend_7to8bits(int x)
{
inline int extend_7to8bits(int x)
{
return (x << 1) | (x >> 6);
}
}
struct ETC2
{
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)
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);
short *sDst = reinterpret_cast<short *>(dest);
for(int i = 0; i < 4 && (x + i) < w; i++)
{
for(int c = nbChannels - 1; c >= 0; c--)
......@@ -110,7 +109,7 @@ namespace
{
if(isSigned)
{
signed char* sDst = reinterpret_cast<signed char*>(dest);
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++)
......@@ -175,7 +174,7 @@ namespace
}
}
private:
private:
struct
{
union
......@@ -386,8 +385,7 @@ namespace
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] =
{
static const int intensityModifierDefault[8][4] = {
{ 2, 8, -2, -8 },
{ 5, 17, -5, -17 },
{ 9, 29, -9, -29 },
......@@ -399,8 +397,7 @@ namespace
};
// Table C.12, intensity modifier for non opaque punchthrough alpha
static const int intensityModifierNonOpaque[8][4] =
{
static const int intensityModifierNonOpaque[8][4] = {
{ 0, 8, 0, -8 },
{ 0, 17, 0, -17 },
{ 0, 29, 0, -29 },
......@@ -436,13 +433,13 @@ namespace
subblockColors1[2].set(r2 + i22, g2 + i22, b2 + i22);
subblockColors1[3].set(r2 + i23, g2 + i23, b2 + i23);
unsigned char* destStart = dest;
unsigned char *destStart = dest;
if(flipbit)
{
for(int j = 0; j < 2 && (y + j) < h; j++)
{
bgra8* color = (bgra8*)dest;
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]);
......@@ -452,7 +449,7 @@ namespace
for(int j = 2; j < 4 && (y + j) < h; j++)
{
bgra8* color = (bgra8*)dest;
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]);
......@@ -464,7 +461,7 @@ namespace
{
for(int j = 0; j < 4 && (y + j) < h; j++)
{
bgra8* color = (bgra8*)dest;
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]);
......@@ -501,11 +498,11 @@ namespace
paintColors[2].set(r2, g2, b2);
paintColors[3].set(r2 - d, g2 - d, b2 - d);
unsigned char* destStart = dest;
unsigned char *destStart = dest;
for(int j = 0; j < 4 && (y + j) < h; j++)
{
bgra8* color = (bgra8*)dest;
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]);
......@@ -541,11 +538,11 @@ namespace
paintColors[2].set(r2 + d, g2 + d, b2 + d);
paintColors[3].set(r2 - d, g2 - d, b2 - d);
unsigned char* destStart = dest;
unsigned char *destStart = dest;
for(int j = 0; j < 4 && (y + j) < h; j++)
{
bgra8* color = (bgra8*)dest;
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]);
......@@ -580,7 +577,7 @@ namespace
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,
((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]);
......@@ -608,7 +605,7 @@ namespace
{
if(getIndex(i, j) == 2) // msb == 1 && lsb == 0
{
((bgra8*)dest)[i].set(0, 0, 0, 0);
((bgra8 *)dest)[i].set(0, 0, 0, 0);
}
}
dest += pitch;
......@@ -619,11 +616,7 @@ namespace
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;
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
......@@ -670,14 +663,14 @@ namespace
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 } };
......
......@@ -37,5 +37,5 @@ public:
/// @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);
};
......@@ -33,8 +33,8 @@ public:
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 @@ template<class Key, class Data, class Hasher = std::hash<Key>>
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 @@ private:
template<typename T>
struct is_memcmparable
{
// std::is_trivially_copyable is not available in older GCC versions.
#if !defined(__GNUC__) || __GNUC__ > 5
// 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
#else
// At least check it doesn't have virtual methods.
static const bool value = !std::is_polymorphic<T>::value;
#endif
#endif
};
}
} // namespace sw
namespace sw {
......@@ -96,7 +99,7 @@ LRUCache<Key, Data>::LRUCache(int n)
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++)
......@@ -188,7 +191,7 @@ void LRUConstCache<Key, Data, Hasher>::updateConstCache()
}
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 = {};
......
......@@ -27,7 +27,7 @@ Matrix Matrix::diag(float m11, float m22, float m33, float m44)
0, 0, 0, m44);
}
Matrix::operator float*()
Matrix::operator float *()
{
return &(*this)(1, 1);
}
......@@ -115,10 +115,22 @@ 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;
}
......@@ -127,10 +139,22 @@ 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;
}
......@@ -139,10 +163,22 @@ Matrix &Matrix::operator*=(float s)
{
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;
}
......@@ -236,7 +272,7 @@ float4 Matrix::operator*(const float4 &v) const
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)
......@@ -327,9 +363,15 @@ Matrix &Matrix::orthogonalise()
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;
}
......
......@@ -44,7 +44,7 @@ struct Matrix
static Matrix diag(float m11, float m22, float m33, float m44);
operator float*();
operator float *();
Matrix operator+() const;
Matrix operator-() const;
......@@ -105,7 +105,7 @@ struct Matrix
static Matrix lookAt(const Vector &v);
static Matrix lookAt(float x, float y, float z);
};
}
} // namespace sw
#include "Vector.hpp"
......@@ -121,30 +121,66 @@ inline Matrix::Matrix(const int i)
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,
......@@ -153,10 +189,22 @@ inline Matrix::Matrix(float m11, float m12, float m13,
{
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,
......@@ -166,30 +214,66 @@ inline Matrix::Matrix(float m11, float m12, float m13, float m14,
{
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;
}
......
......@@ -30,20 +30,20 @@ struct Memset
{
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
}
};
......
......@@ -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 @@ namespace sw {
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 @@ bool PixelProcessor::State::operator==(const State &state) const
}
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 @@ void PixelProcessor::setRoutineCacheSize(int cacheSize)
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;
......
......@@ -28,7 +28,7 @@ struct Texture;
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
{
......@@ -57,7 +57,9 @@ public:
}
};
States() : Memset(this, 0) {}
States()
: Memset(this, 0)
{}
uint32_t computeHash();
......@@ -150,7 +152,7 @@ public:
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);
......
......@@ -56,7 +56,7 @@ struct Point
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);
......
......@@ -22,13 +22,16 @@
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) {}
inline Triangle()
: Memset<Triangle>(this, 0)
{}
#endif // MEMORY_SANITIZER_ENABLED
Vertex v0;
......@@ -43,13 +46,16 @@ struct PlaneEquation // z = A * x + B * y + C
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) {}
inline Primitive()
: Memset<Primitive>(this, 0)
{}
#endif // MEMORY_SANITIZER_ENABLED
int yMin;
......
......@@ -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 @@ QuadRasterizer::~QuadRasterizer()
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 @@ void QuadRasterizer::generate()
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 @@ void QuadRasterizer::rasterize(Int &yMin, Int &yMax)
{
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 @@ void QuadRasterizer::rasterize(Int &yMin, Int &yMax)
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 @@ void QuadRasterizer::rasterize(Int &yMin, Int &yMax)
{
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)
......@@ -176,7 +178,7 @@ void QuadRasterizer::rasterize(Int &yMin, Int &yMax)
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 @@ void QuadRasterizer::rasterize(Int &yMin, Int &yMax)
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 @@ void QuadRasterizer::rasterize(Int &yMin, Int &yMax)
{
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;
......
......@@ -24,7 +24,13 @@ namespace sw {
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:
......
......@@ -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"
......@@ -144,7 +144,7 @@ inline bool setBatchIndices(unsigned int batch[128][3], VkPrimitiveTopology topo
DrawCall::DrawCall()
{
data = (DrawData*)allocate(sizeof(DrawData));
data = (DrawData *)allocate(sizeof(DrawData));
data->constants = &constants;
}
......@@ -153,7 +153,8 @@ DrawCall::~DrawCall()
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::~Renderer()
}
// 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 @@ void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned
return;
}
}
#endif
#endif
int ms = context->sampleCount;
......@@ -275,7 +276,7 @@ void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned
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 @@ void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned
data->a2c0 = float4(0.25f);
data->a2c1 = float4(0.75f);
}
else ASSERT(false);
else
ASSERT(false);
}
if(pixelState.occlusionEnabled)
......@@ -358,7 +360,7 @@ void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned
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 @@ void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned
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 @@ void DrawCall::teardown()
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 @@ void DrawCall::run(const marl::Loan<DrawCall>& draw, marl::Ticket::Queue* ticket
}
marl::schedule([draw, batch, finally] {
processVertices(draw.get(), batch.get());
if(!draw->setupState.rasterizerDiscard)
......@@ -485,7 +486,7 @@ void DrawCall::run(const marl::Loan<DrawCall>& draw, marl::Ticket::Queue* ticket
}
}
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);
......@@ -502,7 +503,7 @@ void DrawCall::processVertices(DrawCall* draw, BatchData* batch)
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 @@ void DrawCall::processVertices(DrawCall* draw, BatchData* batch)
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 @@ void DrawCall::processPrimitives(DrawCall* draw, BatchData* batch)
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 @@ void DrawCall::processPixels(const marl::Loan<DrawCall>& draw, const marl::Loan<
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();
......@@ -582,13 +585,13 @@ void DrawCall::processPrimitiveVertices(
switch(indexType)
{
case VK_INDEX_TYPE_UINT16:
if(!setBatchIndices(triangleIndicesOut, topology, provokingVertexMode, static_cast<const uint16_t*>(primitiveIndices), start, triangleCount))
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))
if(!setBatchIndices(triangleIndicesOut, topology, provokingVertexMode, static_cast<const uint32_t *>(primitiveIndices), start, triangleCount))
{
return;
}
......@@ -626,7 +629,6 @@ int DrawCall::setupSolidTriangles(Triangle *triangles, Primitive *primitives, co
Polygon polygon(&v0.position, &v1.position, &v2.position);
if((v0.cullMask | v1.cullMask | v2.cullMask) == 0)
{
continue;
......@@ -658,7 +660,7 @@ int DrawCall::setupSolidTriangles(Triangle *triangles, Primitive *primitives, co
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::setupWireframeTriangles(Triangle *triangles, Primitive *primitives
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 @@ bool DrawCall::setupLine(Primitive &primitive, Triangle &triangle, const DrawCal
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;
......@@ -1173,7 +1175,7 @@ void Renderer::removeQuery(vk::Query *query)
occlusionQuery = nullptr;
}
void Renderer::advanceInstanceAttributes(Stream* inputs)
void Renderer::advanceInstanceAttributes(Stream *inputs)
{
for(uint32_t i = 0; i < vk::MAX_VERTEX_INPUT_BINDINGS; i++)
{
......
......@@ -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>
......@@ -131,15 +131,15 @@ struct DrawCall
};
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,7 +167,7 @@ struct DrawCall
vk::ImageView *stencilBuffer;
TaskEvents *events;
vk::Query* occlusionQuery;
vk::Query *occlusionQuery;
DrawData *data;
......@@ -180,9 +180,9 @@ struct DrawCall
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 @@ struct DrawCall
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 @@ public:
void addQuery(vk::Query *query);
void removeQuery(vk::Query *query);
void advanceInstanceAttributes(Stream* inputs);
void advanceInstanceAttributes(Stream *inputs);
void synchronize();
......@@ -224,7 +224,7 @@ private:
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,7 +238,7 @@ private:
SetupProcessor::RoutineType setupRoutine;
PixelProcessor::RoutineType pixelRoutine;
vk::Device* device;
vk::Device *device;
};
} // namespace sw
......
......@@ -29,6 +29,6 @@ using RoutineCache = LRUCache<State, std::shared_ptr<Routine>>;
template<class State, class FunctionType>
using RoutineCacheT = LRUCache<State, RoutineT<FunctionType>>;
}
} // namespace sw
#endif // sw_RoutineCache_hpp
......@@ -20,7 +20,9 @@
#include "System/Types.hpp"
#include "Vulkan/VkFormat.h"
namespace vk { class Image; }
namespace vk {
class Image;
}
namespace sw {
......
......@@ -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 @@ namespace sw {
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 @@ bool SetupProcessor::State::operator==(const State &state) const
}
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 @@ SetupProcessor::~SetupProcessor()
routineCache = nullptr;
}
SetupProcessor::State SetupProcessor::update(const sw::Context* context) const
SetupProcessor::State SetupProcessor::update(const sw::Context *context) const
{
State state;
......
......@@ -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,14 +30,16 @@ struct Vertex;
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();
......@@ -71,7 +73,7 @@ public:
~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);
......
......@@ -81,7 +81,7 @@ bool operator!=(const Vector &U, const Vector &v)
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)
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 @@ Vector &operator*=(Vector &v, const Matrix &M)
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)
......
......@@ -69,7 +69,7 @@ struct Vector
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 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);
......
......@@ -16,8 +16,8 @@
#define Vertex_hpp
#include "Color.hpp"
#include "System/Types.hpp"
#include "Device/Config.hpp"
#include "System/Types.hpp"
namespace sw {
......
......@@ -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 @@ void VertexCache::clear()
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++)
......@@ -78,7 +78,7 @@ bool VertexProcessor::State::operator==(const State &state) const
}
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 @@ void VertexProcessor::setRoutineCacheSize(int cacheSize)
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 @@ const VertexProcessor::State VertexProcessor::update(const sw::Context* context)
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();
......
......@@ -50,14 +50,16 @@ struct VertexTask
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();
......@@ -97,7 +99,7 @@ public:
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment