Skip to content

Commit 210ac4b

Browse files
committed
[GPU] Fix gamma ramp writing after RegisterFile API change (#2262)
1 parent 8e7301f commit 210ac4b

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/xenia/gpu/command_processor.cc

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void CommandProcessor::WriteRegister(uint32_t index, uint32_t value) {
369369
case XE_GPU_REG_DC_LUT_SEQ_COLOR: {
370370
// Should be in the 256-entry table writing mode.
371371
assert_zero(regs[XE_GPU_REG_DC_LUT_RW_MODE] & 0b1);
372-
auto& gamma_ramp_rw_index = regs.Get<reg::DC_LUT_RW_INDEX>();
372+
auto gamma_ramp_rw_index = regs.Get<reg::DC_LUT_RW_INDEX>();
373373
// DC_LUT_SEQ_COLOR is in the red, green, blue order, but the write
374374
// enable mask is blue, green, red.
375375
bool write_gamma_ramp_component =
@@ -395,7 +395,11 @@ void CommandProcessor::WriteRegister(uint32_t index, uint32_t value) {
395395
}
396396
if (++gamma_ramp_rw_component_ >= 3) {
397397
gamma_ramp_rw_component_ = 0;
398-
++gamma_ramp_rw_index.rw_index;
398+
reg::DC_LUT_RW_INDEX new_gamma_ramp_rw_index = gamma_ramp_rw_index;
399+
++new_gamma_ramp_rw_index.rw_index;
400+
WriteRegister(
401+
XE_GPU_REG_DC_LUT_RW_INDEX,
402+
xe::memory::Reinterpret<uint32_t>(new_gamma_ramp_rw_index));
399403
}
400404
if (write_gamma_ramp_component) {
401405
OnGammaRamp256EntryTableValueWritten();
@@ -405,7 +409,7 @@ void CommandProcessor::WriteRegister(uint32_t index, uint32_t value) {
405409
case XE_GPU_REG_DC_LUT_PWL_DATA: {
406410
// Should be in the PWL writing mode.
407411
assert_not_zero(regs[XE_GPU_REG_DC_LUT_RW_MODE] & 0b1);
408-
auto& gamma_ramp_rw_index = regs.Get<reg::DC_LUT_RW_INDEX>();
412+
auto gamma_ramp_rw_index = regs.Get<reg::DC_LUT_RW_INDEX>();
409413
// Bit 7 of the index is ignored for PWL.
410414
uint32_t gamma_ramp_rw_index_pwl = gamma_ramp_rw_index.rw_index & 0x7F;
411415
// DC_LUT_PWL_DATA is likely in the red, green, blue order because
@@ -424,13 +428,17 @@ void CommandProcessor::WriteRegister(uint32_t index, uint32_t value) {
424428
}
425429
if (++gamma_ramp_rw_component_ >= 3) {
426430
gamma_ramp_rw_component_ = 0;
431+
reg::DC_LUT_RW_INDEX new_gamma_ramp_rw_index = gamma_ramp_rw_index;
427432
// TODO(Triang3l): Should this increase beyond 7 bits for PWL?
428433
// Direct3D 9 explicitly sets rw_index to 0x80 after writing the last
429434
// PWL entry. However, the DC_LUT_RW_INDEX documentation says that for
430435
// PWL, the bit 7 is ignored.
431-
gamma_ramp_rw_index.rw_index =
436+
new_gamma_ramp_rw_index.rw_index =
432437
(gamma_ramp_rw_index.rw_index & ~UINT32_C(0x7F)) |
433438
((gamma_ramp_rw_index_pwl + 1) & 0x7F);
439+
WriteRegister(
440+
XE_GPU_REG_DC_LUT_RW_INDEX,
441+
xe::memory::Reinterpret<uint32_t>(new_gamma_ramp_rw_index));
434442
}
435443
if (write_gamma_ramp_component) {
436444
OnGammaRampPWLValueWritten();
@@ -440,7 +448,7 @@ void CommandProcessor::WriteRegister(uint32_t index, uint32_t value) {
440448
case XE_GPU_REG_DC_LUT_30_COLOR: {
441449
// Should be in the 256-entry table writing mode.
442450
assert_zero(regs[XE_GPU_REG_DC_LUT_RW_MODE] & 0b1);
443-
auto& gamma_ramp_rw_index = regs.Get<reg::DC_LUT_RW_INDEX>();
451+
auto gamma_ramp_rw_index = regs.Get<reg::DC_LUT_RW_INDEX>();
444452
uint32_t gamma_ramp_write_enable_mask =
445453
regs[XE_GPU_REG_DC_LUT_WRITE_EN_MASK] & 0b111;
446454
if (gamma_ramp_write_enable_mask) {
@@ -457,11 +465,16 @@ void CommandProcessor::WriteRegister(uint32_t index, uint32_t value) {
457465
gamma_ramp_entry.color_10_red = gamma_ramp_value.color_10_red;
458466
}
459467
}
460-
++gamma_ramp_rw_index.rw_index;
461468
// TODO(Triang3l): Should this reset the component write index? If this
462469
// increase is assumed to behave like a full DC_LUT_RW_INDEX write, it
463-
// probably should.
470+
// probably should. Currently this also calls WriteRegister for
471+
// DC_LUT_RW_INDEX, which resets gamma_ramp_rw_component_ as well.
464472
gamma_ramp_rw_component_ = 0;
473+
reg::DC_LUT_RW_INDEX new_gamma_ramp_rw_index = gamma_ramp_rw_index;
474+
++new_gamma_ramp_rw_index.rw_index;
475+
WriteRegister(
476+
XE_GPU_REG_DC_LUT_RW_INDEX,
477+
xe::memory::Reinterpret<uint32_t>(new_gamma_ramp_rw_index));
465478
if (gamma_ramp_write_enable_mask) {
466479
OnGammaRamp256EntryTableValueWritten();
467480
}

0 commit comments

Comments
 (0)