Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blit_impl: Use <algorithm> with unseq policy #7115

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 19 additions & 57 deletions Source/engine/render/blit_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

#include <cstdint>
#include <cstring>
#include <execution>
#include <version>

#include "engine/palette.h"
#include "utils/attributes.h"

namespace devilution {

#if __cpp_lib_execution >= 201902L
#define DEVILUTIONX_BLIT_EXECUTION_POLICY std::execution::unseq,
#else
#define DEVILUTIONX_BLIT_EXECUTION_POLICY
#endif

enum class BlitType : uint8_t {
Transparent,
Pixels,
Expand Down Expand Up @@ -56,57 +64,23 @@ DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void BlitFillWithMap(uint8_t *dst, unsigned
DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void BlitPixelsWithMap(uint8_t *DVL_RESTRICT dst, const uint8_t *DVL_RESTRICT src, unsigned length, const uint8_t *DVL_RESTRICT colorMap)
{
assert(length != 0);
const uint8_t *end = src + length;
while (src + 3 < end) {
*dst++ = colorMap[*src++];
*dst++ = colorMap[*src++];
*dst++ = colorMap[*src++];
*dst++ = colorMap[*src++];
}
while (src < end) {
*dst++ = colorMap[*src++];
}
std::transform(DEVILUTIONX_BLIT_EXECUTION_POLICY src, src + length, dst, [colorMap](uint8_t srcColor) { return colorMap[srcColor]; });
}

DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void BlitFillBlended(uint8_t *dst, unsigned length, uint8_t color)
{
assert(length != 0);
const uint8_t *end = dst + length;
const uint8_t *const tbl = paletteTransparencyLookup[color];
while (dst + 3 < end) {
*dst = tbl[*dst];
++dst;
*dst = tbl[*dst];
++dst;
*dst = tbl[*dst];
++dst;
*dst = tbl[*dst];
++dst;
}
while (dst < end) {
*dst = tbl[*dst];
++dst;
}
std::for_each(DEVILUTIONX_BLIT_EXECUTION_POLICY dst, dst + length, [tbl = paletteTransparencyLookup[color]](uint8_t &dstColor) {
dstColor = tbl[dstColor];
});
}

DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void BlitPixelsBlended(uint8_t *DVL_RESTRICT dst, const uint8_t *DVL_RESTRICT src, unsigned length)
{
assert(length != 0);
const uint8_t *end = src + length;
while (src + 3 < end) {
*dst = paletteTransparencyLookup[*dst][*src++];
++dst;
*dst = paletteTransparencyLookup[*dst][*src++];
++dst;
*dst = paletteTransparencyLookup[*dst][*src++];
++dst;
*dst = paletteTransparencyLookup[*dst][*src++];
++dst;
}
while (src < end) {
*dst = paletteTransparencyLookup[*dst][*src++];
++dst;
}
std::transform(DEVILUTIONX_BLIT_EXECUTION_POLICY src, src + length, dst, dst, [pal = paletteTransparencyLookup](uint8_t srcColor, uint8_t dstColor) {
return pal[srcColor][dstColor];
});
}

struct BlitWithMap {
Expand All @@ -130,25 +104,13 @@ struct BlitWithMap {
DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void BlitPixelsBlendedWithMap(uint8_t *DVL_RESTRICT dst, const uint8_t *DVL_RESTRICT src, unsigned length, const uint8_t *DVL_RESTRICT colorMap)
{
assert(length != 0);
const uint8_t *end = src + length;
while (src + 3 < end) {
*dst = paletteTransparencyLookup[*dst][colorMap[*src++]];
++dst;
*dst = paletteTransparencyLookup[*dst][colorMap[*src++]];
++dst;
*dst = paletteTransparencyLookup[*dst][colorMap[*src++]];
++dst;
*dst = paletteTransparencyLookup[*dst][colorMap[*src++]];
++dst;
}
while (src < end) {
*dst = paletteTransparencyLookup[*dst][colorMap[*src++]];
++dst;
}
std::transform(DEVILUTIONX_BLIT_EXECUTION_POLICY src, src + length, dst, dst, [colorMap, pal = paletteTransparencyLookup](uint8_t srcColor, uint8_t dstColor) {
return pal[dstColor][colorMap[srcColor]];
});
}

struct BlitBlendedWithMap {
const uint8_t *colorMap;
const uint8_t *DVL_RESTRICT colorMap;

DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void operator()(BlitCommand cmd, uint8_t *DVL_RESTRICT dst, const uint8_t *DVL_RESTRICT src) const
{
Expand Down
Loading