Skip to content

Commit ea7711d

Browse files
brianosmanSkia Commit-Bot
authored andcommitted
Tweak pointlight3d sample to work in Raster backend
- Once we add all the missing intrinsics, the locally defined ones can go away. - Having the default interpreter vector width match the raster pipeline is a huge perf win. Change-Id: I482e409e57791b78a0e6fb15929ae77eb0e76bf3 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/265600 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
1 parent 51a813d commit ea7711d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

samplecode/Sample3D.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,22 @@ class SamplePointLight3D : public Sample3DView {
338338
uniform float4x4 localToWorld;
339339
uniform float3 lightPos;
340340
341+
// TODO: Remove these helpers once all intrinsics work on the raster backend
342+
float3 normalize_(float3 v) {
343+
return v / sqrt(dot(v, v));
344+
}
345+
346+
float max_(float a, float b) {
347+
return a > b ? a : b;
348+
}
349+
341350
void main(float x, float y, inout half4 color) {
342351
float3 plane_pos = (localToWorld * float4(x, y, 0, 1)).xyz;
343-
float3 plane_norm = normalize((localToWorld * float4(0, 0, 1, 0)).xyz);
344-
float3 light_dir = normalize(lightPos - plane_pos);
352+
float3 plane_norm = normalize_((localToWorld * float4(0, 0, 1, 0)).xyz);
353+
float3 light_dir = normalize_(lightPos - plane_pos);
345354
float ambient = 0.5;
346355
float dp = dot(plane_norm, light_dir);
347-
float scale = ambient + max(dp, 0);
356+
float scale = ambient + max_(dp, 0);
348357
349358
color = color * half4(float4(scale, scale, scale, 1));
350359
}

src/sksl/SkSLByteCode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ enum class TypeCategory {
220220

221221
class SK_API ByteCode {
222222
public:
223-
static constexpr int kVecWidth = 16;
223+
static constexpr int kVecWidth = 8;
224224

225225
ByteCode() = default;
226226

0 commit comments

Comments
 (0)