-
-
Notifications
You must be signed in to change notification settings - Fork 61
fix: Support for PrimitiveOffsetInfo in render pipeline draw...Indirect methods
#2337
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
Open
cieplypolar
wants to merge
14
commits into
main
Choose a base branch
from
fix/primitive-offset-info-support-in-draw
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
adc2a54
drawIndirect, drawIndexedIndirect and refactor
cieplypolar 187c997
indirect dispatch accepts raw gpu buffer + tests
cieplypolar b6e8be8
one more test for compute pipeline
cieplypolar 4e970f7
render pipeline tests
cieplypolar 4f8aafb
Merge branch 'main' into fix/primitive-offset-info-support-in-draw
cieplypolar a07bfc8
ox
cieplypolar 60e8fc0
review changes
cieplypolar 0f9c3ac
Merge branch 'main' into fix/primitive-offset-info-support-in-draw
cieplypolar 22f7b6d
review fixes
cieplypolar 9a73c26
Merge branch 'main' into fix/primitive-offset-info-support-in-draw
cieplypolar a3f7071
Merge branch 'main' into fix/primitive-offset-info-support-in-draw
cieplypolar ad31c60
review fixes
cieplypolar 51069f3
Merge branch 'main' into fix/primitive-offset-info-support-in-draw
cieplypolar 1c2ae28
Merge branch 'main' into fix/primitive-offset-info-support-in-draw
cieplypolar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import type { IndirectFlag, TgpuBuffer } from '../buffer/buffer.ts'; | ||
| import { memoryLayoutOf, type PrimitiveOffsetInfo } from '../../data/offsetUtils.ts'; | ||
| import { sizeOf } from '../../data/sizeOf.ts'; | ||
| import type { BaseData } from '../../data/wgslTypes.ts'; | ||
| import { isGPUBuffer } from '../../types.ts'; | ||
|
|
||
| type IndirectOperation = 'dispatchWorkgroupsIndirect' | 'drawIndirect' | 'drawIndexedIndirect'; | ||
| const IndirectOperationToRequiredData = { | ||
| dispatchWorkgroupsIndirect: '3 x u32', | ||
| drawIndirect: '4 x u32', | ||
| drawIndexedIndirect: '3 x u32, i32, u32', | ||
| } as const satisfies Record<IndirectOperation, string>; | ||
|
|
||
| function validateIndirectBufferSize( | ||
| bufferSize: number, | ||
| offset: number, | ||
| requiredBytes: number, | ||
| operation: IndirectOperation, | ||
| ): void { | ||
| if (offset + requiredBytes > bufferSize) { | ||
| throw new Error( | ||
| `Buffer too small for ${operation}. Required: ${requiredBytes} bytes at offset ${offset}, but buffer is only ${bufferSize} bytes.`, | ||
| ); | ||
| } | ||
|
|
||
| if (offset % 4 !== 0) { | ||
| throw new Error(`Indirect buffer offset must be a multiple of 4. Got: ${offset}`); | ||
| } | ||
| } | ||
|
|
||
| export function resolveIndirectOffset( | ||
| indirectBuffer: (TgpuBuffer<BaseData> & IndirectFlag) | GPUBuffer, | ||
| start: PrimitiveOffsetInfo | number | undefined, | ||
| requiredSize: number, | ||
| operation: IndirectOperation, | ||
| ): number { | ||
| if (isGPUBuffer(indirectBuffer)) { | ||
| const offset = typeof start === 'number' ? start : (start?.offset ?? 0); | ||
| validateIndirectBufferSize(indirectBuffer.size, offset, requiredSize, operation); | ||
| return offset; | ||
| } | ||
|
|
||
| const offsetInfo = start | ||
| ? typeof start === 'number' | ||
| ? { offset: start, contiguous: requiredSize } | ||
| : start | ||
| : memoryLayoutOf(indirectBuffer.dataType); | ||
|
|
||
| const { offset, contiguous } = offsetInfo; | ||
|
|
||
| validateIndirectBufferSize(sizeOf(indirectBuffer.dataType), offset, requiredSize, operation); | ||
cieplypolar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (contiguous < requiredSize) { | ||
| console.warn( | ||
| `${operation}: Starting at offset ${offset}, only ${contiguous} contiguous bytes are available before padding. '${operation}' requires ${requiredSize} bytes (${IndirectOperationToRequiredData[operation]}). Reading across padding may result in undefined behavior.`, | ||
| ); | ||
| } | ||
|
|
||
| return offset; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.