Commit aaa64b76 by Antonio Maiorano

Modify Blitter to implement FunctionT

Bug: b/143479561 Change-Id: I25e68cc24f6141611493ea7dc24f90ab4b2e4d4b Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/37711Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 62edf14b
...@@ -75,8 +75,6 @@ namespace sw ...@@ -75,8 +75,6 @@ namespace sw
return; return;
} }
void(*blitFunction)(const BlitData *data) = (void(*)(const BlitData*))blitRoutine->getEntry();
VkImageSubresourceLayers subresLayers = VkImageSubresourceLayers subresLayers =
{ {
subresourceRange.aspectMask, subresourceRange.aspectMask,
...@@ -129,7 +127,7 @@ namespace sw ...@@ -129,7 +127,7 @@ namespace sw
for (uint32_t depth = subresourceRange.baseArrayLayer; depth <= lastLayer; depth++) 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);
blitFunction(&data); blitRoutine(&data);
} }
} }
else else
...@@ -140,7 +138,7 @@ namespace sw ...@@ -140,7 +138,7 @@ namespace sw
{ {
data.dest = dest->getTexelPointer({ 0, 0, static_cast<int32_t>(depth) }, subresLayers); data.dest = dest->getTexelPointer({ 0, 0, static_cast<int32_t>(depth) }, subresLayers);
blitFunction(&data); blitRoutine(&data);
} }
} }
} }
...@@ -1389,9 +1387,9 @@ namespace sw ...@@ -1389,9 +1387,9 @@ namespace sw
return s; return s;
} }
std::shared_ptr<Routine> Blitter::generate(const State &state) Blitter::BlitRoutineType Blitter::generate(const State &state)
{ {
Function<Void(Pointer<Byte>)> function; BlitFunction function;
{ {
Pointer<Byte> blit(function.Arg<0>()); Pointer<Byte> blit(function.Arg<0>());
...@@ -1600,7 +1598,7 @@ namespace sw ...@@ -1600,7 +1598,7 @@ namespace sw
return function("BlitRoutine"); return function("BlitRoutine");
} }
std::shared_ptr<Routine> Blitter::getBlitRoutine(const State &state) Blitter::BlitRoutineType Blitter::getBlitRoutine(const State &state)
{ {
std::unique_lock<std::mutex> lock(blitMutex); std::unique_lock<std::mutex> lock(blitMutex);
auto blitRoutine = blitCache.query(state); auto blitRoutine = blitCache.query(state);
...@@ -1614,7 +1612,7 @@ namespace sw ...@@ -1614,7 +1612,7 @@ namespace sw
return blitRoutine; return blitRoutine;
} }
std::shared_ptr<Routine> Blitter::getCornerUpdateRoutine(const State &state) Blitter::CornerUpdateRoutineType Blitter::getCornerUpdateRoutine(const State &state)
{ {
std::unique_lock<std::mutex> lock(cornerUpdateMutex); std::unique_lock<std::mutex> lock(cornerUpdateMutex);
auto cornerUpdateRoutine = cornerUpdateCache.query(state); auto cornerUpdateRoutine = cornerUpdateCache.query(state);
...@@ -1641,8 +1639,6 @@ namespace sw ...@@ -1641,8 +1639,6 @@ namespace sw
return; return;
} }
void(*blitFunction)(const BlitData *data) = (void(*)(const BlitData*))blitRoutine->getEntry();
BlitData data = BlitData data =
{ {
nullptr, // source nullptr, // source
...@@ -1687,7 +1683,7 @@ namespace sw ...@@ -1687,7 +1683,7 @@ namespace sw
{ {
data.source = src->getTexelPointer(srcOffset, srcSubresLayers); data.source = src->getTexelPointer(srcOffset, srcSubresLayers);
ASSERT(data.source < src->end()); ASSERT(data.source < src->end());
blitFunction(&data); blitRoutine(&data);
srcOffset.z++; srcOffset.z++;
data.dest = (dst += bufferSlicePitch); data.dest = (dst += bufferSlicePitch);
} }
...@@ -1707,8 +1703,6 @@ namespace sw ...@@ -1707,8 +1703,6 @@ namespace sw
return; return;
} }
void(*blitFunction)(const BlitData *data) = (void(*)(const BlitData*))blitRoutine->getEntry();
BlitData data = BlitData data =
{ {
src, // source src, // source
...@@ -1756,7 +1750,7 @@ namespace sw ...@@ -1756,7 +1750,7 @@ namespace sw
{ {
data.dest = dst->getTexelPointer(dstOffset, dstSubresLayers); data.dest = dst->getTexelPointer(dstOffset, dstSubresLayers);
ASSERT(data.dest < dst->end()); ASSERT(data.dest < dst->end());
blitFunction(&data); blitRoutine(&data);
dstOffset.z++; dstOffset.z++;
data.source = (src += bufferSlicePitch); data.source = (src += bufferSlicePitch);
} }
...@@ -1825,8 +1819,6 @@ namespace sw ...@@ -1825,8 +1819,6 @@ namespace sw
return; return;
} }
void(*blitFunction)(const BlitData *data) = (void(*)(const BlitData*))blitRoutine->getEntry();
BlitData data = BlitData data =
{ {
nullptr, // source nullptr, // source
...@@ -1893,7 +1885,7 @@ namespace sw ...@@ -1893,7 +1885,7 @@ namespace sw
ASSERT(data.source < src->end()); ASSERT(data.source < src->end());
ASSERT(data.dest < dst->end()); ASSERT(data.dest < dst->end());
blitFunction(&data); blitRoutine(&data);
srcOffset.z++; srcOffset.z++;
dstOffset.z++; dstOffset.z++;
} }
...@@ -1914,7 +1906,7 @@ namespace sw ...@@ -1914,7 +1906,7 @@ namespace sw
write(c, layer + ComputeOffset(x0, y0, pitchB, bytes, quadLayout), state); write(c, layer + ComputeOffset(x0, y0, pitchB, bytes, quadLayout), state);
} }
std::shared_ptr<Routine> Blitter::generateCornerUpdate(const State& state) Blitter::CornerUpdateRoutineType Blitter::generateCornerUpdate(const State& state)
{ {
// Reading and writing from/to the same image // Reading and writing from/to the same image
ASSERT(state.sourceFormat == state.destFormat); ASSERT(state.sourceFormat == state.destFormat);
...@@ -1925,7 +1917,7 @@ namespace sw ...@@ -1925,7 +1917,7 @@ namespace sw
UNIMPLEMENTED("state.srcSamples %d", state.srcSamples); UNIMPLEMENTED("state.srcSamples %d", state.srcSamples);
} }
Function<Void(Pointer<Byte>)> function; CornerUpdateFunction function;
{ {
Pointer<Byte> blit(function.Arg<0>()); Pointer<Byte> blit(function.Arg<0>());
...@@ -2021,8 +2013,6 @@ namespace sw ...@@ -2021,8 +2013,6 @@ namespace sw
return; return;
} }
void(*cornerUpdateFunction)(const CubeBorderData *data) = (void(*)(const CubeBorderData*))cornerUpdateRoutine->getEntry();
VkExtent3D extent = image->getMipLevelExtent(aspect, subresourceLayers.mipLevel); VkExtent3D extent = image->getMipLevelExtent(aspect, subresourceLayers.mipLevel);
CubeBorderData data = CubeBorderData data =
{ {
...@@ -2031,7 +2021,7 @@ namespace sw ...@@ -2031,7 +2021,7 @@ namespace sw
static_cast<uint32_t>(image->getLayerSize(aspect)), static_cast<uint32_t>(image->getLayerSize(aspect)),
extent.width extent.width
}; };
cornerUpdateFunction(&data); cornerUpdateRoutine(&data);
} }
void Blitter::copyCubeEdge(vk::Image* image, void Blitter::copyCubeEdge(vk::Image* image,
......
...@@ -135,10 +135,16 @@ namespace sw ...@@ -135,10 +135,16 @@ namespace sw
static Int ComputeOffset(Int &x, Int &y, Int &pitchB, int bytes, bool quadLayout); static Int ComputeOffset(Int &x, Int &y, Int &pitchB, int bytes, bool quadLayout);
static Float4 LinearToSRGB(Float4 &color); static Float4 LinearToSRGB(Float4 &color);
static Float4 sRGBtoLinear(Float4 &color); static Float4 sRGBtoLinear(Float4 &color);
std::shared_ptr<Routine> getBlitRoutine(const State &state);
std::shared_ptr<Routine> generate(const State &state); using BlitFunction = FunctionT<void(const BlitData*)>;
std::shared_ptr<Routine> getCornerUpdateRoutine(const State &state); using BlitRoutineType = BlitFunction::RoutineType;
std::shared_ptr<Routine> generateCornerUpdate(const State& state); BlitRoutineType getBlitRoutine(const State &state);
BlitRoutineType generate(const State &state);
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); void computeCubeCorner(Pointer<Byte>& layer, Int& x0, Int& x1, Int& y0, Int& y1, Int& pitchB, const State& state);
void copyCubeEdge(vk::Image* image, void copyCubeEdge(vk::Image* image,
...@@ -146,9 +152,9 @@ namespace sw ...@@ -146,9 +152,9 @@ namespace sw
const VkImageSubresourceLayers& srcSubresourceLayers, Edge srcEdge); const VkImageSubresourceLayers& srcSubresourceLayers, Edge srcEdge);
std::mutex blitMutex; std::mutex blitMutex;
RoutineCache<State> blitCache; // guarded by blitMutex RoutineCacheT<State, BlitFunction::CFunctionType> blitCache; // guarded by blitMutex
std::mutex cornerUpdateMutex; std::mutex cornerUpdateMutex;
RoutineCache<State> cornerUpdateCache; // guarded by cornerUpdateMutex RoutineCacheT<State, CornerUpdateFunction::CFunctionType> cornerUpdateCache; // guarded by cornerUpdateMutex
}; };
} }
......
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