Skip to content
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

Memory sync test for buffer: write after write in the same pass #384

Merged
merged 4 commits into from
Dec 1, 2020

Conversation

Richard-Yunchao
Copy link
Contributor

PTAL. Thanks. The naming like verifyAlternativeData and expectAlternativeContents might not be very good, though. But I can't think of a better one.

src/webgpu/gpu_test.ts Outdated Show resolved Hide resolved
src/webgpu/gpu_test.ts Outdated Show resolved Hide resolved
@@ -83,12 +83,54 @@ g.test('two_draws_in_the_same_render_pass')
a storage buffer. The second write will write 2 into the same buffer in the same pass. Expected
data in buffer is either 1 or 2. It may use bundle in each draw.`
)
.unimplemented();
.params(pbool('useBundle'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that I'm looking at the implementation, I think we should test at least these three options:

  • same pass, no bundle
  • same pass, different bundles
  • same bundle

Copy link
Contributor Author

@Richard-Yunchao Richard-Yunchao Nov 24, 2020

Choose a reason for hiding this comment

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

Agreed. I was meant to test 1) same pass, no bundle; 2) same pass, one bundle; 3) same pass, two separate bundles. But I wrote it wrongly. And I missed same bundle (definitely one pass).
Now I added all of them. Note that I separated the tests two-draws-in-the-same-bundle from the original one. I tried to merge into the same one, but it requires unless and multiple ifs, making the code logic in a mess. So I think it is better to write a standalone test for same-bundle test.

niceStack.message = check1 + check2;
niceStack.message = <span class="x x-first x-last">`Expected one of the following two checks to succeed:</span>
- ${check1}
- ${check2}`;
Copy link
Contributor Author

@Richard-Yunchao Richard-Yunchao Nov 24, 2020

Choose a reason for hiding this comment

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

@kainino0x , do you know why this code snippet failed to build? I removed <span> stuff, it works.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have no idea where the span stuff came from?? It must have been a GitHub bug.

Copy link
Collaborator

@Kangz Kangz left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -167,6 +167,35 @@ export class GPUTest extends Fixture {
});
}

expectContentsMultipleValidValues(
src: GPUBuffer,
expected1: TypedArrayBufferView,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If anything, I think this should take a sequence<TypedArrayBufferView>. Maybe we could also refactor the expectContents to take a validator function so it's easy to build additional variations in the future.

Copy link
Contributor Author

@Richard-Yunchao Richard-Yunchao Dec 1, 2020

Choose a reason for hiding this comment

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

Thanks for your suggestions, Corentin. I considered about this too but didn't do this because: 1) it is somehow over-engineering. 2) actually we have two directions to expand this function:

  • expand two values to an array (or a sequence), and the expected result should fall into any value of the array. it is just like any() function. This direction is what you said.
  • expand two values to two vectors, and the expected result should be a vector whose value at any index should be either of the two values at the same index of the two vectors. Take (R, G, B, A) as an example, if two vectors are (0, 0, 0, 0) and (255, 255, 255, 255), then there are 16 correct values like (0, 0, 0, 0), (0, 0, 0, 255), ..., (0, 255, 255, 0), ..., (255, 255, 255, 255). This is another possible expansion. If we have multiple values in the buffer, a race condition of write after write is more likely to behave in this direction. But I don't want to make the test too complicated.

Considering that we have two directions and it will bring unnecessary complex, I didn't expand this function.

How about we keep it and expand this function to whatever we want if we do need it in future?

Copy link
Collaborator

@Kangz Kangz Dec 1, 2020

Choose a reason for hiding this comment

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

While I think it is ok in this test fixture, I have concerns keeping the method in the harness as-is: it says 'multiple values" but only take two. In general the harness needs to be higher quality and more future proof than test code.

What we could do is do the refactor of expectContents to to have a version that takes a validator and make the validator check agains the two values in the fixture.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. I have concerns about the naming stuff too (I said about the naming problem at the very beginning). I hesitated to pick up a name like alternative, either, two, multiple, etc. Let's be clear and just say "two" valid values here. And we can expand it to multiple valid values or two mixed vectors if needed in future. I understand that the code should be future-proof but I don't think it is very clear that which direction is the future (maybe neither of them is needed). So I added a comment about it. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment is inconsistent with the idea of passing a validator function, but it links to this discussion, so it's fine. I also considered suggesting passing an array here (instead of 2 values); it wouldn't really be over-engineering as it wouldn't be any more complex. However I think a validator function makes more sense in the future. A validator function pattern also works much better for texture content expectation. (I was thinking of passing a function(x,y,z)->expected value into expectTextureContents but a validator is more flexible.)

@@ -255,4 +255,12 @@ export class BufferSyncTest extends GPUTest {
bufferData[0] = expectedValue;
this.expectContents(buffer, bufferData);
}

verifyDataMultipleValidValues(buffer: GPUBuffer, expectedValue1: number, expectedValue2: number) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this could take a sequence<number>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same reason

src/webgpu/api/operation/memory_sync/buffer/ww.spec.ts Outdated Show resolved Hide resolved
@@ -167,6 +167,35 @@ export class GPUTest extends Fixture {
});
}

expectContentsMultipleValidValues(
src: GPUBuffer,
expected1: TypedArrayBufferView,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment is inconsistent with the idea of passing a validator function, but it links to this discussion, so it's fine. I also considered suggesting passing an array here (instead of 2 values); it wouldn't really be over-engineering as it wouldn't be any more complex. However I think a validator function makes more sense in the future. A validator function pattern also works much better for texture content expectation. (I was thinking of passing a function(x,y,z)->expected value into expectTextureContents but a validator is more flexible.)

@kainino0x kainino0x merged commit 3c2fe38 into gpuweb:main Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants