Skip to content

Commit

Permalink
Handle dual cycle noise.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed May 25, 2024
1 parent 66b9bf3 commit c84dc7f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions parallel-rdp/rdp_data_structures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ enum StaticRasterizationFlagBits
RASTERIZATION_CONVERT_ONE_BIT = 1 << 22,
RASTERIZATION_BILERP_0_BIT = 1 << 23,
RASTERIZATION_BILERP_1_BIT = 1 << 24,
RASTERIZATION_NEED_NOISE_DUAL_BIT = 1 << 25,
RASTERIZATION_UPSCALING_LOG2_BIT_OFFSET = 26,
// Bit 26 and 27 holds upscaling factor in LOG2.
RASTERIZATION_NEED_NOISE_BIT = 1 << 28,
RASTERIZATION_USE_STATIC_TEXTURE_SIZE_FORMAT_BIT = 1 << 29,
RASTERIZATION_USE_SPECIALIZATION_CONSTANT_BIT = 1 << 30
Expand Down
11 changes: 8 additions & 3 deletions parallel-rdp/rdp_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ static bool combiner_uses_lod_frac(const StaticRasterizationState &state)
void Renderer::deduce_noise_state()
{
auto &state = stream.static_raster_state;
state.flags &= ~RASTERIZATION_NEED_NOISE_BIT;
state.flags &= ~(RASTERIZATION_NEED_NOISE_BIT | RASTERIZATION_NEED_NOISE_DUAL_BIT);

// Figure out if we need to seed noise variable for this primitive.
if ((state.dither & 3) == 2 || ((state.dither >> 2) & 3) == 2)
Expand All @@ -1144,13 +1144,18 @@ void Renderer::deduce_noise_state()
return;

if ((state.flags & RASTERIZATION_MULTI_CYCLE_BIT) != 0)
{
if (state.combiner[0].rgb.muladd == RGBMulAdd::Noise)
state.flags |= RASTERIZATION_NEED_NOISE_BIT;
}

if (state.combiner[1].rgb.muladd == RGBMulAdd::Noise)
state.flags |= RASTERIZATION_NEED_NOISE_BIT;

// If both cycles use noise, they need to observe different values.
if ((state.flags & RASTERIZATION_MULTI_CYCLE_BIT) != 0 &&
state.combiner[0].rgb.muladd == RGBMulAdd::Noise &&
state.combiner[1].rgb.muladd == RGBMulAdd::Noise)
state.flags |= RASTERIZATION_NEED_NOISE_DUAL_BIT;

if ((state.flags & (RASTERIZATION_ALPHA_TEST_BIT | RASTERIZATION_ALPHA_TEST_DITHER_BIT)) ==
(RASTERIZATION_ALPHA_TEST_BIT | RASTERIZATION_ALPHA_TEST_DITHER_BIT))
{
Expand Down
1 change: 1 addition & 0 deletions parallel-rdp/shaders/data_structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const int RASTERIZATION_USES_PIPELINED_TEXEL1_BIT = 1 << 21;
const int RASTERIZATION_CONVERT_ONE_BIT = 1 << 22;
const int RASTERIZATION_BILERP_0_BIT = 1 << 23;
const int RASTERIZATION_BILERP_1_BIT = 1 << 24;
const int RASTERIZATION_NEED_NOISE_DUAL_BIT = 1 << 25;
const int RASTERIZATION_UPSCALING_LOG2_BIT_OFFSET = 26;
const int RASTERIZATION_NEED_NOISE_BIT = 1 << 28;
const int RASTERIZATION_USE_STATIC_TEXTURE_SIZE_FORMAT_BIT = 1 << 29;
Expand Down
8 changes: 8 additions & 0 deletions parallel-rdp/shaders/shading.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ bool shade_pixel(int x, int y, uint primitive_index, out ShadedData shaded)
// but let's not go there ...
combined_inputs.texel1 = tmp_texel;

// Resample the noise at some arbitrary other offset.
// This only matters if both noise combiner inputs take noise (very weird).
if ((static_state_flags & RASTERIZATION_NEED_NOISE_DUAL_BIT) != 0)
{
reseed_noise(x + 1023, y + 7, primitive_index + global_constants.fb_info.base_primitive_index + 11);
combined_inputs.noise = noise_get_combiner();
}

combined = u8x4(combiner_cycle1(combined_inputs,
combiner_inputs_rgb1,
combiner_inputs_alpha1,
Expand Down

0 comments on commit c84dc7f

Please sign in to comment.