Use const pointers for source data.
Our uniform data could be in a const buffer, so we should try to
be const-correct where we can.
Change-Id: Iecc9ae152e1153de464407d856c434b713f447d2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/620227
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/core/SkRasterPipeline.h b/src/core/SkRasterPipeline.h
index f9fb771..42f3254 100644
--- a/src/core/SkRasterPipeline.h
+++ b/src/core/SkRasterPipeline.h
@@ -291,7 +291,8 @@
};
struct SkRasterPipeline_CopySlotsCtx {
- float *dst, *src;
+ float *dst;
+ const float *src;
};
struct SkRasterPipeline_SwizzleCtx {
diff --git a/src/core/SkRasterPipelineUtils.cpp b/src/core/SkRasterPipelineUtils.cpp
index 5452c10..977fcc8 100644
--- a/src/core/SkRasterPipelineUtils.cpp
+++ b/src/core/SkRasterPipelineUtils.cpp
@@ -11,7 +11,7 @@
void SkRasterPipelineUtils_Base::appendCopy(SkArenaAlloc* alloc,
SkRasterPipeline::Stage baseStage,
float* dst, int dstStride,
- float* src, int srcStride,
+ const float* src, int srcStride,
int numSlots) {
SkASSERT(numSlots >= 0);
while (numSlots > 4) {
@@ -33,7 +33,7 @@
void SkRasterPipelineUtils_Base::appendCopySlotsMasked(SkArenaAlloc* alloc,
float* dst,
- float* src,
+ const float* src,
int numSlots) {
this->appendCopy(alloc,
SkRasterPipeline::copy_slot_masked,
@@ -44,7 +44,7 @@
void SkRasterPipelineUtils_Base::appendCopySlotsUnmasked(SkArenaAlloc* alloc,
float* dst,
- float* src,
+ const float* src,
int numSlots) {
this->appendCopy(alloc,
SkRasterPipeline::copy_slot_unmasked,
@@ -55,7 +55,7 @@
void SkRasterPipelineUtils_Base::appendCopyConstants(SkArenaAlloc* alloc,
float* dst,
- float* src,
+ const float* src,
int numSlots) {
this->appendCopy(alloc,
SkRasterPipeline::copy_constant,
@@ -88,7 +88,7 @@
void SkRasterPipelineUtils_Base::appendAdjacentMultiSlotOp(SkArenaAlloc* alloc,
SkRasterPipeline::Stage baseStage,
float* dst,
- float* src,
+ const float* src,
int numSlots) {
// The source and destination must be directly next to one another.
SkASSERT(numSlots >= 0);
@@ -109,7 +109,7 @@
void SkRasterPipelineUtils_Base::appendAdjacentSingleSlotOp(SkRasterPipeline::Stage stage,
float* dst,
- float* src) {
+ const float* src) {
// The source and destination must be directly next to one another.
SkASSERT((dst + SkOpts::raster_pipeline_highp_stride) == src);
this->append(stage, dst);
diff --git a/src/core/SkRasterPipelineUtils.h b/src/core/SkRasterPipelineUtils.h
index 891488b..a419586 100644
--- a/src/core/SkRasterPipelineUtils.h
+++ b/src/core/SkRasterPipelineUtils.h
@@ -17,9 +17,9 @@
virtual void append(SkRasterPipeline::Stage stage, void* ctx) = 0;
// Appends one or more `copy_n_slots_[un]masked` stages to the pipeline, based on `numSlots`.
- void appendCopySlotsMasked(SkArenaAlloc* alloc, float* dst, float* src, int numSlots);
- void appendCopySlotsUnmasked(SkArenaAlloc* alloc, float* dst, float* src, int numSlots);
- void appendCopyConstants(SkArenaAlloc* alloc, float* dst, float* src, int numSlots);
+ void appendCopySlotsMasked(SkArenaAlloc* alloc, float* dst, const float* src, int numSlots);
+ void appendCopySlotsUnmasked(SkArenaAlloc* alloc, float* dst, const float* src, int numSlots);
+ void appendCopyConstants(SkArenaAlloc* alloc, float* dst, const float* src, int numSlots);
// Appends one or more `zero_n_slots_unmasked` stages to the pipeline, based on `numSlots`.
void appendZeroSlotsUnmasked(float* dst, int numSlots);
@@ -33,18 +33,18 @@
void appendAdjacentMultiSlotOp(SkArenaAlloc* alloc,
SkRasterPipeline::Stage baseStage,
float* dst,
- float* src,
+ const float* src,
int numSlots);
// Appends a math operation with two inputs (dst op src) and one output (dst) to the pipeline.
// `src` must be _immediately_ after `dst` in memory.
- void appendAdjacentSingleSlotOp(SkRasterPipeline::Stage stage, float* dst, float* src);
+ void appendAdjacentSingleSlotOp(SkRasterPipeline::Stage stage, float* dst, const float* src);
private:
void appendCopy(SkArenaAlloc* alloc,
SkRasterPipeline::Stage baseStage,
float* dst, int dstStride,
- float* src, int srcStride,
+ const float* src, int srcStride,
int numSlots);
};
diff --git a/src/opts/SkRasterPipeline_opts.h b/src/opts/SkRasterPipeline_opts.h
index 1500188..536f843 100644
--- a/src/opts/SkRasterPipeline_opts.h
+++ b/src/opts/SkRasterPipeline_opts.h
@@ -3152,25 +3152,25 @@
}
STAGE(copy_constant, SkRasterPipeline_CopySlotsCtx* ctx) {
- float* src = ctx->src;
+ const float* src = ctx->src;
F* dst = (F*)ctx->dst;
dst[0] = src[0];
}
STAGE(copy_2_constants, SkRasterPipeline_CopySlotsCtx* ctx) {
- float* src = ctx->src;
+ const float* src = ctx->src;
F* dst = (F*)ctx->dst;
dst[0] = src[0];
dst[1] = src[1];
}
STAGE(copy_3_constants, SkRasterPipeline_CopySlotsCtx* ctx) {
- float* src = ctx->src;
+ const float* src = ctx->src;
F* dst = (F*)ctx->dst;
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
}
STAGE(copy_4_constants, SkRasterPipeline_CopySlotsCtx* ctx) {
- float* src = ctx->src;
+ const float* src = ctx->src;
F* dst = (F*)ctx->dst;
dst[0] = src[0];
dst[1] = src[1];
diff --git a/src/sksl/codegen/SkSLRasterPipelineBuilder.cpp b/src/sksl/codegen/SkSLRasterPipelineBuilder.cpp
index 575bf47..27c1579 100644
--- a/src/sksl/codegen/SkSLRasterPipelineBuilder.cpp
+++ b/src/sksl/codegen/SkSLRasterPipelineBuilder.cpp
@@ -514,8 +514,8 @@
const Stage& stage = stages[index];
// Interpret the context value as a branch offset.
- auto BranchOffset = [&](void* ctx) -> std::string {
- int *ctxAsInt = static_cast<int*>(ctx);
+ auto BranchOffset = [&](const void* ctx) -> std::string {
+ const int *ctxAsInt = static_cast<const int*>(ctx);
return SkSL::String::printf("%+d (#%d)", *ctxAsInt, *ctxAsInt + index + 1);
};
@@ -547,8 +547,8 @@
};
// Interpret the context value as a pointer, most likely to a slot range.
- auto PtrCtx = [&](void* ctx, int numSlots) -> std::string {
- float *ctxAsSlot = static_cast<float*>(ctx);
+ auto PtrCtx = [&](const void* ctx, int numSlots) -> std::string {
+ const float *ctxAsSlot = static_cast<const float*>(ctx);
if (fDebugTrace) {
// Handle pointers to named slots.
if (ctxAsSlot >= slotBase && ctxAsSlot < slotEnd) {
@@ -586,22 +586,24 @@
};
// Interpret the context value as a pointer to two adjacent values.
- auto AdjacentPtrCtx = [&](void* ctx, int numSlots) -> std::tuple<std::string, std::string> {
- float *ctxAsSlot = static_cast<float*>(ctx);
+ auto AdjacentPtrCtx = [&](const void* ctx,
+ int numSlots) -> std::tuple<std::string, std::string> {
+ const float *ctxAsSlot = static_cast<const float*>(ctx);
return std::make_tuple(PtrCtx(ctxAsSlot, numSlots),
PtrCtx(ctxAsSlot + (N * numSlots), numSlots));
};
// Interpret the context value as a CopySlots structure.
- auto CopySlotsCtx = [&](void* v, int numSlots) -> std::tuple<std::string, std::string> {
- auto *ctx = static_cast<SkRasterPipeline_CopySlotsCtx*>(v);
+ auto CopySlotsCtx = [&](const void* v,
+ int numSlots) -> std::tuple<std::string, std::string> {
+ const auto *ctx = static_cast<const SkRasterPipeline_CopySlotsCtx*>(v);
return std::make_tuple(PtrCtx(ctx->dst, numSlots),
PtrCtx(ctx->src, numSlots));
};
// Interpret the context value as a CopySlots structure.
- auto AdjacentCopySlotsCtx = [&](void* v) -> std::tuple<std::string, std::string> {
- auto *ctx = static_cast<SkRasterPipeline_CopySlotsCtx*>(v);
+ auto AdjacentCopySlotsCtx = [&](const void* v) -> std::tuple<std::string, std::string> {
+ const auto *ctx = static_cast<const SkRasterPipeline_CopySlotsCtx*>(v);
int numSlots = ctx->src - ctx->dst;
return std::make_tuple(PtrCtx(ctx->dst, numSlots),
PtrCtx(ctx->src, numSlots));
@@ -610,8 +612,9 @@
// Interpret the context value as a Swizzle structure. Note that the slot-width of the
// source expression is not preserved in the instruction encoding, so we need to do our best
// using the data we have. (e.g., myFloat4.y would be indistinguishable from myFloat2.y.)
- auto SwizzleCtx = [&](SkRP::Stage op, void* v) -> std::tuple<std::string, std::string> {
- auto* ctx = static_cast<SkRasterPipeline_SwizzleCtx*>(v);
+ auto SwizzleCtx = [&](SkRP::Stage op,
+ const void* v) -> std::tuple<std::string, std::string> {
+ const auto* ctx = static_cast<const SkRasterPipeline_SwizzleCtx*>(v);
int destSlots = (int)op - (int)SkRP::swizzle_1 + 1;
int highestComponent =