Skip to content

Commit

Permalink
Use hardware textureGather on hlsl
Browse files Browse the repository at this point in the history
Diffs=
e816b03089 Use hardware textureGather on hlsl (#9016)

Co-authored-by: Chris Dalton <[email protected]>
  • Loading branch information
csmartdalton and csmartdalton committed Feb 11, 2025
1 parent e694a1b commit 33d561d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
633c8ef979c22715dd1a64694c2e406d923cde7a
e816b03089efc637b6161d55e8a1543d07bdbae9
32 changes: 16 additions & 16 deletions renderer/path_fiddle/path_fiddle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ static float2 s_pts[] = {{260 + 2 * 100, 60 + 2 * 500},
{260 + 2 * 400, 60 + 2 * 200},
{260 + 2 * 213, 60 + 2 * 200},
{260 + 2 * 213, 60 + 2 * 300},
{260 + 2 * 391, 60 + 2 * 480}};
{260 + 2 * 391, 60 + 2 * 480},
{1400, 1400}}; // Feather control.
constexpr static int kNumInteractivePts = sizeof(s_pts) / sizeof(*s_pts);

static float s_strokeWidth = 70;
static float featherPower = 0;

static float2 s_translate;
static float s_scale = 1;

static StrokeJoin s_join = StrokeJoin::miter;
static StrokeCap s_cap = StrokeCap::butt;
static StrokeJoin s_join = StrokeJoin::round;
static StrokeCap s_cap = StrokeCap::round;

static bool s_doClose = false;
static bool s_paused = false;
Expand Down Expand Up @@ -256,12 +256,6 @@ static void key_callback(GLFWwindow* window,
case GLFW_KEY_EQUAL:
s_strokeWidth *= 1.5f;
break;
case GLFW_KEY_F:
if (!shift)
++featherPower;
else
featherPower = std::max(featherPower - 1, 0.f);
break;
case GLFW_KEY_W:
s_wireframe = !s_wireframe;
break;
Expand Down Expand Up @@ -293,7 +287,7 @@ static void key_callback(GLFWwindow* window,
s_disableStroke = !s_disableStroke;
}
break;
case GLFW_KEY_I:
case GLFW_KEY_F:
s_disableFill = !s_disableFill;
break;
case GLFW_KEY_X:
Expand Down Expand Up @@ -857,9 +851,10 @@ void riveMainLoop()
auto path = factory->makeRenderPath(rawPath, FillRule::clockwise);

auto fillPaint = factory->makeRenderPaint();
if (featherPower != 0)
float feather = powf(1.5f, (1400 - s_pts[std::size(s_pts) - 1].y) / 75);
if (feather > 1)
{
fillPaint->feather(powf(1.5f, featherPower));
fillPaint->feather(feather);
}
fillPaint->color(0xd0ffffff);

Expand All @@ -871,13 +866,12 @@ void riveMainLoop()
strokePaint->style(RenderPaintStyle::stroke);
strokePaint->color(0x8000ffff);
strokePaint->thickness(s_strokeWidth);
if (featherPower != 0)
if (feather > 1)
{
strokePaint->feather(powf(1.5f, featherPower));
strokePaint->feather(feather);
}
strokePaint->join(s_join);
strokePaint->cap(s_cap);

renderer->drawPath(path.get(), strokePaint.get());

// Draw the interactive points.
Expand All @@ -895,7 +889,13 @@ void riveMainLoop()
pointPath->moveTo(pt.x, pt.y);
pointPath->close();
}
renderer->drawPath(pointPath.get(), pointPaint.get());

// Draw the feather control point.
pointPaint->color(0xffff0000);
pointPath = factory->makeEmptyRenderPath();
float2 pt = s_pts[std::size(s_pts) - 1] + s_translate;
pointPath->moveTo(pt.x, pt.y);
renderer->drawPath(pointPath.get(), pointPaint.get());
}
}
Expand Down
3 changes: 3 additions & 0 deletions renderer/src/d3d/render_context_d3d_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,9 @@ void RenderContextD3DImpl::flush(const FlushDescriptor& desc)
m_gpuContext->VSSetConstantBuffers(FLUSH_UNIFORM_BUFFER_IDX,
std::size(uniformBuffers),
uniformBuffers);
m_gpuContext->PSSetConstantBuffers(FLUSH_UNIFORM_BUFFER_IDX,
std::size(uniformBuffers),
uniformBuffers);

// All programs use the same storage buffers.
ID3D11ShaderResourceView* storageBufferBufferSRVs[] = {
Expand Down
5 changes: 1 addition & 4 deletions renderer/src/shaders/hlsl.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ $typedef $uint ushort;
#define TEXTURE_SAMPLE_GRAD(NAME, SAMPLER_NAME, COORD, DDX, DDY) \
NAME.$SampleGrad(SAMPLER_NAME, COORD, DDX, DDY)
#define TEXTURE_GATHER(NAME, SAMPLER_NAME, COORD, TEXTURE_INVERSE_SIZE) \
make_half4(TEXEL_FETCH(NAME, int2(COORD) + int2(-1, 0)).r, \
TEXEL_FETCH(NAME, int2(COORD) + int2(0, 0)).r, \
TEXEL_FETCH(NAME, int2(COORD) + int2(0, -1)).r, \
TEXEL_FETCH(NAME, int2(COORD) + int2(-1, -1)).r)
NAME.$Gather(SAMPLER_NAME, (COORD) * (TEXTURE_INVERSE_SIZE))

#define PLS_INTERLOCK_BEGIN
#define PLS_INTERLOCK_END
Expand Down

0 comments on commit 33d561d

Please sign in to comment.