Skip to content

Adding command buffer and test command #1911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 15, 2025

Conversation

johnbaumann
Copy link
Collaborator

No description provided.

Copy link
Contributor

coderabbitai bot commented Mar 22, 2025

Caution

Review failed

The head commit changed during the review from 9b6521e to 04a955c.

Walkthrough

This pull request introduces a new header defining the CDRomCommandBuffer structure with variadic argument support constrained by a concept. It also expands the CDRomDevice class with three new testing methods—test, scheduleTest, and testBlocking—and adds corresponding test action logic in a new test file. Additionally, the CommandFifo structure in the hardware layer now provides an overload to send a command along with a command buffer. Several copyright headers and include directives were updated accordingly.

Changes

File(s) Summary
src/mips/psyqo/cdrom-commandbuffer.hh Added CDRomCommandBuffer struct with a variadic set method and overloaded recursiveSet methods, and introduced the CDRomArgumentType concept.
src/mips/psyqo/cdrom-device.hh
src/mips/psyqo/src/cdrom-device-test.cpp
Added new testing methods (test, scheduleTest, testBlocking) to CDRomDevice and implemented a TestAction class for managing test state and actions; updated copyright year.
src/mips/psyqo/hardware/cdrom.hh Added new header includes (<stdint.h>, <concepts>, <type_traits>), updated the copyright year, and extended CommandFifo with an overload of send that accepts both a CDL command and a CDRomCommandBuffer.
src/mips/psyqo/examples/cdrom-demo/cdrom-demo.cpp Included CDRomCommandBuffer in the cdrom-demo.cpp file, created an instance, and utilized it in the createScene method with the testBlocking function call.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant CDRomDevice
    participant TestAction
    participant CommandFifo

    Client->>CDRomDevice: test(commandBuffer, callback)
    CDRomDevice->>TestAction: initiate test action
    TestAction->>CommandFifo: send(CDL command, commandBuffer)
    CommandFifo-->>TestAction: command processed
    TestAction-->>CDRomDevice: complete test (callback invoked)
Loading

Possibly related PRs

Suggested reviewers

  • nicolasnoble

Poem

I'm a rabbit, hopping through code with glee,
New commands and tests set our bytes free!
In buffers and devices, magic unfolds,
Recursive pathways and functions bold.
With every hop, our code sings in delight 🐰🎶!
Leap on, dear coder, into the night!


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/mips/psyqo/src/cdrom-device-test.cpp (1)

42-62: Add error handling to response processing.

The complete and acknowledge methods always set success to true without examining the response. Consider implementing proper error detection based on the response content.

-    bool complete(const psyqo::CDRomDevice::Response &) override {
+    bool complete(const psyqo::CDRomDevice::Response &response) override {
+        // Check response for potential errors
+        if (!response.empty() && (response[0] & 0x01)) {
+            setSuccess(false);
+            return true;
+        }
         setSuccess(true);
         return true;
     }
-    bool acknowledge(const psyqo::CDRomDevice::Response &response) override {
+    bool acknowledge(const psyqo::CDRomDevice::Response &response) override {
+        // Check response for potential errors
+        if (!response.empty() && (response[0] & 0x01)) {
+            setSuccess(false);
+            return true;
+        }
         setSuccess(true);
         return true;
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cc3aa2 and e9aea0d.

📒 Files selected for processing (4)
  • src/mips/psyqo/cdrom-commandbuffer.hh (1 hunks)
  • src/mips/psyqo/cdrom-device.hh (3 hunks)
  • src/mips/psyqo/hardware/cdrom.hh (3 hunks)
  • src/mips/psyqo/src/cdrom-device-test.cpp (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: macos-intel-build-and-test
  • GitHub Check: macos-arm-build-and-test
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: asan
  • GitHub Check: coverage
  • GitHub Check: toolchain
  • GitHub Check: aur-build
  • GitHub Check: build
  • GitHub Check: macos-build-and-test-toolchain
  • GitHub Check: cross-arm64
🔇 Additional comments (16)
src/mips/psyqo/hardware/cdrom.hh (3)

5-5: Copyright year updated to 2025.

The copyright year has been updated from 2023 to 2025.


29-34: LGTM! New header includes support implementation requirements.

The added headers provide necessary support for the new functionality:

  • <stdint.h> for integer type definitions
  • <concepts> and <type_traits> for concept-based constraints
  • "psyqo/cdrom-commandbuffer.hh" to use the new command buffer structure

87-93: LGTM! Well-structured implementation for command buffer sending.

The new method correctly extends the existing functionality to support sending commands with variable-length command buffers:

  1. Initializes Ctrl register to 0
  2. Populates the Fifo register with each byte from the command buffer
  3. Sets the Response register with the command value

This maintains consistency with the existing send method pattern.

src/mips/psyqo/cdrom-commandbuffer.hh (5)

1-25: LGTM! Standard MIT license header.

The license header follows the project's standard format.


27-32: LGTM! Appropriate header includes.

The file includes the necessary headers for the implementation:

  • <stdint.h> for integer type definitions
  • <concepts> and <type_traits> for concept-based constraint definition

34-35: LGTM! Well-designed concept for command arguments.

The concept CDRomArgumentType correctly constrains command arguments to integral types, ensuring type safety for the command buffer.


37-46: LGTM! Well-structured command buffer implementation.

The CDRomCommandBuffer structure implements a clean interface for setting variable-length command arguments:

  • Uses template metaprogramming with concept constraints
  • Efficiently calculates buffer size from argument count
  • Initializes buffer contents through recursive calls

47-54: LGTM! Clean implementation of recursive buffer initialization.

The private implementation uses an elegant recursive pattern:

  • Base case for a single argument
  • Recursive case for multiple arguments
  • Correctly increments position for each recursive call
src/mips/psyqo/cdrom-device.hh (3)

5-5: Copyright year updated to 2025.

The copyright year has been updated from 2022 to 2025.


38-38: LGTM! Added include for command buffer support.

The include for the new cdrom-commandbuffer.hh header is appropriately placed among the other includes.


416-424: LGTM! Well-documented CD-ROM test functionality.

The new methods for testing the CD-ROM follow the established pattern in this class:

  1. test: Async version with callback
  2. scheduleTest: Task-queue version for scheduled execution
  3. testBlocking: Synchronous version

The documentation clearly explains the purpose of these methods.

src/mips/psyqo/src/cdrom-device-test.cpp (5)

1-34: LGTM! Standard headers and includes.

The file includes:

  • Standard MIT license header
  • Necessary headers for implementation
  • EASTL atomic for synchronization

35-41: LGTM! TestActionState enum follows existing patterns.

The TestActionState enum correctly defines the necessary states for the test action:

  • IDLE at value 0 (meeting the CDRomDeviceStateEnum concept requirements)
  • TEST state for ongoing operations

68-71: LGTM! Test method implementation follows established patterns.

The test method correctly:

  1. Asserts that no other action is pending
  2. Starts the test action with the provided command buffer and callback

73-76: LGTM! Well-implemented scheduled test method.

The scheduleTest method follows the established pattern for creating task-queue tasks, capturing the command buffer and converting the completion callback.


78-85: LGTM! Blocking test method implementation.

The testBlocking method correctly:

  1. Asserts no pending actions
  2. Uses the BlockingAction RAII pattern for synchronization
  3. Captures the success result from the callback


#include <concepts>
#include <type_traits>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're missing a namespace here. Probably psyqo::Hardware::CDRom

*
* @param callback The callback to call when the command operation is complete.
*/
void test(CDRomCommandBuffer commandBuffer, eastl::function<void(bool)> &&callback);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be a const reference, for all 3.

public:
TestAction() : Action("TestAction") {}

void start(psyqo::CDRomDevice *device, CDRomCommandBuffer commandBuffer, eastl::function<void(bool)> &&callback) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CDRomCommandBuffer should be a const reference.


psyqo::TaskQueue::Task psyqo::CDRomDevice::scheduleTest(CDRomCommandBuffer commandBuffer) {
return TaskQueue::Task(
[this, commandBuffer](auto task) { test(commandBuffer, [task](bool success) { task->complete(success); }); });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this one will allocate memory implicitly, which isn't something we want. What we should be doing instead here is the following:

  • Create a CDRomCommandBuffer inside the s_testAction.
  • Copy the buffer to it.
  • Add a new start override without the buffer as a parameter, which should just call into the normal start version.
  • Call start from within the task's lambda instead.

This way there's no need to capture the command buffer inside the task's lambda, and the action will hold it statically.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/mips/psyqo/src/cdrom-device-test.cpp (1)

5-5: Copyright year should be consistent with other files.

The copyright year is set to 2025, which differs from the 2022 used in other files (like cdrom-device.hh).

-Copyright (c) 2025 PCSX-Redux authors
+Copyright (c) 2022 PCSX-Redux authors
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9aea0d and 6d733a6.

📒 Files selected for processing (5)
  • src/mips/psyqo/cdrom-commandbuffer.hh (1 hunks)
  • src/mips/psyqo/cdrom-device.hh (2 hunks)
  • src/mips/psyqo/examples/cdrom-demo/cdrom-demo.cpp (2 hunks)
  • src/mips/psyqo/hardware/cdrom.hh (2 hunks)
  • src/mips/psyqo/src/cdrom-device-test.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/mips/psyqo/hardware/cdrom.hh
  • src/mips/psyqo/cdrom-commandbuffer.hh
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/mips/psyqo/src/cdrom-device-test.cpp (1)
src/core/system.h (1)
  • atomic_signal_fence (165-168)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build
  • GitHub Check: asan
  • GitHub Check: build-openbios
  • GitHub Check: coverage
  • GitHub Check: aur-build
  • GitHub Check: cross-arm64
  • GitHub Check: macos-build-and-test-toolchain
  • GitHub Check: toolchain
🔇 Additional comments (11)
src/mips/psyqo/examples/cdrom-demo/cdrom-demo.cpp (2)

30-30: Appropriate header inclusion.

The inclusion of the new header file for CDRomCommandBuffer is correctly placed with the other CD-ROM related headers.


81-83: LGTM! Demonstrates new test functionality.

The code correctly demonstrates the use of the new CDRom test functionality by:

  1. Creating a command buffer
  2. Setting it with test values
  3. Invoking the new testBlocking method

This provides a good example of how to use the new feature.

src/mips/psyqo/cdrom-device.hh (2)

38-38: Appropriate header inclusion.

The inclusion of the new header file for CDRomCommandBuffer is correctly placed before it's used in the class declaration.


416-424: Well-documented function declarations with proper parameter types.

The three new test methods are well-documented with Doxygen-style comments and correctly take the command buffer as a const reference, as previously suggested in the code review.

The function declarations follow the established pattern in this class:

  • A method that takes a callback
  • A method that returns a task
  • A blocking method variant
src/mips/psyqo/src/cdrom-device-test.cpp (7)

37-40: Well-structured enum class definition.

The TestActionState enum class correctly follows the pattern established for other action states, with IDLE as the first state with value 0, which satisfies the IsCDRomDeviceStateEnum concept requirement.


46-54: Properly implemented start method with const reference parameter.

The implementation correctly takes the command buffer as a const reference, as previously suggested in the code review.

The method follows the established pattern for starting actions:

  1. Asserting that the device is idle
  2. Registering the action
  3. Setting up the callback
  4. Setting the appropriate state
  5. Using an atomic fence for memory ordering
  6. Sending the command

55-57: Efficient overloaded start method.

This overload correctly reuses the other start method, passing the internal command buffer, which avoids code duplication.


67-67: Appropriate member variable for command buffer.

The class includes a member variable to store the command buffer, which addresses the previous review comment about memory allocation in the task lambda.


74-78: Correctly implemented test method.

The method properly asserts that there's no pending action and delegates to the TestAction class.


80-86: Memory-efficient scheduleTest implementation.

The implementation addresses the previous review comment by:

  1. Copying the command buffer to the static action's member variable
  2. Creating a task that uses the overloaded start method without capturing the command buffer

This avoids implicit memory allocation in the lambda capture.


88-95: Proper implementation of the blocking test method.

The method correctly:

  1. Asserts that there's no pending action
  2. Creates a BlockingAction to handle synchronization
  3. Starts the test action with a callback that captures the result

Following the established pattern for blocking methods in this class.

nicolasnoble
nicolasnoble previously approved these changes Apr 15, 2025

psyqo::Hardware::CDRom::CDRomCommandBuffer commandBuffer;
commandBuffer.set(0x50, 0xf2, 0xde, 0xad);
m_cdrom.testBlocking(gpu(), commandBuffer);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize I committed this change to the repo - is there a clean way to roll back this change or prevent it from getting merged in? Otherwise I can just revert the changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, no need to rewrite history for this. Just push a commit to remove it if you want it gone.

@johnbaumann johnbaumann merged commit 7e0a17f into grumpycoders:main Apr 15, 2025
21 checks passed
@nicolasnoble nicolasnoble deleted the psyqo-test-command branch April 15, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants