mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-19 23:29:05 +00:00
Switches to much more straightforward Line/LineMetadata storage.
Spoiler: covering this whole segment behind producer_mutex_ seems to resolve all output issues, so clearly the existing logic isn't functioning correctly. Making it simpler seems like a pretty obvious way to get to the bottom of that.
This commit is contained in:
parent
02f41ee513
commit
72a8fef989
@ -157,17 +157,6 @@ void BufferingScanTarget::end_scan() {
|
|||||||
vended_scan_->scan.end_points[0].data_offset += TextureAddressGetX(vended_write_area_pointer_);
|
vended_scan_->scan.end_points[0].data_offset += TextureAddressGetX(vended_write_area_pointer_);
|
||||||
vended_scan_->scan.end_points[1].data_offset += TextureAddressGetX(vended_write_area_pointer_);
|
vended_scan_->scan.end_points[1].data_offset += TextureAddressGetX(vended_write_area_pointer_);
|
||||||
vended_scan_ = nullptr;
|
vended_scan_ = nullptr;
|
||||||
|
|
||||||
#ifdef LOG_SCANS
|
|
||||||
if(vended_scan_->scan.composite_amplitude) {
|
|
||||||
std::cout << "S: ";
|
|
||||||
std::cout << vended_scan_->scan.end_points[0].composite_angle << "/" << vended_scan_->scan.end_points[0].data_offset << "/" << vended_scan_->scan.end_points[0].cycles_since_end_of_horizontal_retrace << " -> ";
|
|
||||||
std::cout << vended_scan_->scan.end_points[1].composite_angle << "/" << vended_scan_->scan.end_points[1].data_offset << "/" << vended_scan_->scan.end_points[1].cycles_since_end_of_horizontal_retrace << " => ";
|
|
||||||
std::cout << double(vended_scan_->scan.end_points[1].composite_angle - vended_scan_->scan.end_points[0].composite_angle) / (double(vended_scan_->scan.end_points[1].data_offset - vended_scan_->scan.end_points[0].data_offset) * 64.0f) << "/";
|
|
||||||
std::cout << double(vended_scan_->scan.end_points[1].composite_angle - vended_scan_->scan.end_points[0].composite_angle) / (double(vended_scan_->scan.end_points[1].cycles_since_end_of_horizontal_retrace - vended_scan_->scan.end_points[0].cycles_since_end_of_horizontal_retrace) * 64.0f);
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,34 +178,23 @@ void BufferingScanTarget::announce(Event event, bool is_visible, const Outputs::
|
|||||||
frame_is_complete_ = true;
|
frame_is_complete_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proceed only if a change in visibility has occurred.
|
// Proceed from here only if a change in visibility has occurred.
|
||||||
if(output_is_visible_ == is_visible) return;
|
if(output_is_visible_ == is_visible) return;
|
||||||
output_is_visible_ = is_visible;
|
output_is_visible_ = is_visible;
|
||||||
|
|
||||||
if(is_visible) {
|
if(is_visible) {
|
||||||
const auto read_pointers = read_pointers_.load(std::memory_order::memory_order_relaxed);
|
const auto read_pointers = read_pointers_.load(std::memory_order::memory_order_relaxed);
|
||||||
|
|
||||||
// Commit the most recent line only if any scans fell on it.
|
// Attempt to allocate a new line, noting allocation failure if necessary.
|
||||||
// Otherwise there's no point outputting it, it'll contribute nothing.
|
const auto next_line = uint16_t((write_pointers_.line + 1) % line_buffer_size_);
|
||||||
if(provided_scans_) {
|
if(next_line == read_pointers.line) {
|
||||||
// Store metadata if concluding a previous line.
|
allocation_has_failed_ = true;
|
||||||
if(active_line_) {
|
active_line_ = nullptr;
|
||||||
line_metadata_buffer_[size_t(write_pointers_.line)].is_first_in_frame = is_first_in_frame_;
|
} else {
|
||||||
line_metadata_buffer_[size_t(write_pointers_.line)].previous_frame_was_complete = previous_frame_was_complete_;
|
write_pointers_.line = next_line;
|
||||||
is_first_in_frame_ = false;
|
active_line_ = &line_buffer_[size_t(write_pointers_.line)];
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to allocate a new line; note allocation failure if necessary.
|
|
||||||
const auto next_line = uint16_t((write_pointers_.line + 1) % line_buffer_size_);
|
|
||||||
if(next_line == read_pointers.line) {
|
|
||||||
allocation_has_failed_ = true;
|
|
||||||
active_line_ = nullptr;
|
|
||||||
} else {
|
|
||||||
write_pointers_.line = next_line;
|
|
||||||
active_line_ = &line_buffer_[size_t(write_pointers_.line)];
|
|
||||||
}
|
|
||||||
provided_scans_ = 0;
|
|
||||||
}
|
}
|
||||||
|
provided_scans_ = 0;
|
||||||
|
|
||||||
// If there was space for a new line, establish its start.
|
// If there was space for a new line, establish its start.
|
||||||
if(active_line_) {
|
if(active_line_) {
|
||||||
@ -228,39 +206,31 @@ void BufferingScanTarget::announce(Event event, bool is_visible, const Outputs::
|
|||||||
active_line_->composite_amplitude = composite_amplitude;
|
active_line_->composite_amplitude = composite_amplitude;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Complete the current line if there is one.
|
// Commit the most recent line only if any scans fell on it and all allocation was successful.
|
||||||
if(active_line_) {
|
if(active_line_ && provided_scans_ && !allocation_has_failed_) {
|
||||||
|
// Store metadata.
|
||||||
|
line_metadata_buffer_[size_t(write_pointers_.line)].is_first_in_frame = is_first_in_frame_;
|
||||||
|
line_metadata_buffer_[size_t(write_pointers_.line)].previous_frame_was_complete = previous_frame_was_complete_;
|
||||||
|
is_first_in_frame_ = false;
|
||||||
|
|
||||||
|
// Store actual line data.
|
||||||
active_line_->end_points[1].x = location.x;
|
active_line_->end_points[1].x = location.x;
|
||||||
active_line_->end_points[1].y = location.y;
|
active_line_->end_points[1].y = location.y;
|
||||||
active_line_->end_points[1].cycles_since_end_of_horizontal_retrace = location.cycles_since_end_of_horizontal_retrace;
|
active_line_->end_points[1].cycles_since_end_of_horizontal_retrace = location.cycles_since_end_of_horizontal_retrace;
|
||||||
active_line_->end_points[1].composite_angle = location.composite_angle;
|
active_line_->end_points[1].composite_angle = location.composite_angle;
|
||||||
|
|
||||||
#ifdef LOG_LINES
|
// Update the submit pointers with all lines, scans and data written during this line.
|
||||||
if(active_line_->composite_amplitude) {
|
|
||||||
std::cout << "L: ";
|
|
||||||
std::cout << active_line_->end_points[0].composite_angle << "/" << active_line_->end_points[0].cycles_since_end_of_horizontal_retrace << " -> ";
|
|
||||||
std::cout << active_line_->end_points[1].composite_angle << "/" << active_line_->end_points[1].cycles_since_end_of_horizontal_retrace << " => ";
|
|
||||||
std::cout << (active_line_->end_points[1].composite_angle - active_line_->end_points[0].composite_angle) << "/" << (active_line_->end_points[1].cycles_since_end_of_horizontal_retrace - active_line_->end_points[0].cycles_since_end_of_horizontal_retrace) << " => ";
|
|
||||||
std::cout << double(active_line_->end_points[1].composite_angle - active_line_->end_points[0].composite_angle) / (double(active_line_->end_points[1].cycles_since_end_of_horizontal_retrace - active_line_->end_points[0].cycles_since_end_of_horizontal_retrace) * 64.0f);
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if(allocation_has_failed_) {
|
|
||||||
// If allocation failed at any point, reset all pointers to where they
|
|
||||||
// were before this line, note that the frame will now be incomplete and
|
|
||||||
// throw away the active line.
|
|
||||||
write_pointers_ = submit_pointers_.load();
|
|
||||||
frame_is_complete_ = false;
|
|
||||||
active_line_ = nullptr;
|
|
||||||
} else {
|
|
||||||
// The line ended and there were no allocation failures. So enqueue the
|
|
||||||
// latest line for potential output.
|
|
||||||
submit_pointers_.store(write_pointers_, std::memory_order::memory_order_release);
|
submit_pointers_.store(write_pointers_, std::memory_order::memory_order_release);
|
||||||
|
} else {
|
||||||
|
// Something failed, so reset all pointers to where they
|
||||||
|
// were before this line and note that the frame will now be incomplete.
|
||||||
|
write_pointers_ = submit_pointers_.load(std::memory_order::memory_order_relaxed);
|
||||||
|
frame_is_complete_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the allocation-has-failed flag for the next line.
|
// Reset the allocation-has-failed flag for the next line
|
||||||
|
// and mark no line as active.
|
||||||
|
active_line_ = nullptr;
|
||||||
allocation_has_failed_ = false;
|
allocation_has_failed_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user