Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/typegpu/src/core/pipeline/webgpuLimitations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,17 @@ function requiredAlignOf(schema: BaseData) {
* See https://www.w3.org/TR/WGSL/#address-space-layout-constraints
*/
export function warnIfNotUniformAligned(schema: BaseData) {
if (!logger.isEnabled('uniform-schema-misaligned')) {
Comment thread
iwoplaza marked this conversation as resolved.
// Silenced by default in production, and computing memory layouts isn't free
return;
}

checkUniformAlignment(schema);
}

function checkUniformAlignment(schema: BaseData) {
if (isWgslArray(schema)) {
warnIfNotUniformAligned(schema.elementType);
checkUniformAlignment(schema.elementType);

const stride = roundUp(sizeOf(schema.elementType), alignmentOf(schema.elementType));
if (stride % 16 !== 0) {
Expand All @@ -62,7 +71,7 @@ To address this, put the element schema in a struct and wrap the prop in 'd.alig
}
}
if (isWgslStruct(schema)) {
Object.values(schema.propTypes).forEach(warnIfNotUniformAligned);
Object.values(schema.propTypes).forEach(checkUniformAlignment);

Object.entries(schema.propTypes).forEach(([key, value]) => {
const offset = memoryLayoutOf(schema, (schema) => schema[key]).offset;
Expand Down
6 changes: 6 additions & 0 deletions packages/typegpu/src/tgpuLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type WarningType = (typeof warningTypes)[number];

// internal API
interface Logger {
/** Lets callers skip computing what a warning needs when it wouldn't be shown anyway. */
isEnabled(type: WarningType): boolean;
warn(type: WarningType, ...args: unknown[]): void;
warnOnce(type: WarningType, key: object, tag: string, ...args: unknown[]): void;
}
Expand Down Expand Up @@ -67,6 +69,10 @@ export class TgpuLogger implements Logger, Warn {
this.#enabledWarnings = new Set(this.#initialEnabledWarnings);
}

isEnabled(type: WarningType): boolean {
return this.#enabledWarnings.has(type);
}

warn(type: WarningType, ...args: unknown[]) {
if (this.#enabledWarnings.has(type)) {
console.warn(`⚠️ [${type}] `, ...args);
Expand Down
Loading