Skip to content

Commit

Permalink
update features and limits
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Aug 30, 2023
1 parent db3c4fc commit 8f71622
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
29 changes: 21 additions & 8 deletions webgpu/lessons/resources/elem.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,28 @@ const c = (tag, children = [], textContent = '') => {
return createElem(tag, {textContent}, children);
};

/**
* ```
* const addRow = makeTable(parent, ['name', 'location']);
* addRow(['Gregg', 'SF']);
* addRow(['Tami', 'Glendora']);
* addRow(['Mom', 'Temecula']);
* addRow([['red', 'apple'], ['yellow', 'banana']]);
* // makes
* // <tr>
* // <td><span class="red">apple</span></td>
* // <td><span class="green">banana</span></td>
* // </tr>
* addRow([createElem('div')])
* ```
*/
export function makeTable(parent, columnNames) {
const makeRow = (arr, tag = 'td') => c('tr', arr.map(v => c(tag, [], v)));
const makeRow = (arr, tag = 'td') => c('tr', arr.map(
v => v instanceof HTMLElement
? createElem(tag, {}, [v])
: Array.isArray(v)
? createElem(tag, {className: v[0], textContent: v[1]})
: c(tag, [], v)));

const tbody = c('tbody');
parent.appendChild(c('table', [
Expand All @@ -42,13 +62,6 @@ export function makeTable(parent, columnNames) {
};
}

/*
const addRow = makeTable(parent, ['name', 'location']);
addRow(['Gregg', 'SF']);
addRow(['Tami', 'Glendora']);
addRow(['Mom', 'Temecula']);
*/

export function radio(label, options, value, callback) {
const name = crypto.randomUUID();
const parent = el('div', {className: 'radio center', textContent: `${label}:`}, options.map(option => {
Expand Down
2 changes: 2 additions & 0 deletions webgpu/lessons/resources/lesson.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
--diagram-bg-color: #DDD;
--column-rule-color: #888;
--line-through-color: rgba(0, 0, 0, 0.3);
--good-fg-color: green;
}

.x-axis, .x-axis * { color: red !important; }
Expand Down Expand Up @@ -50,6 +51,7 @@
--selected-fg-color: orange;
--diagram-bg-color: #222;
--line-through-color: rgba(255, 255, 255, 0.4);
--good-fg-color: hsl(120, 100%, 40%);
}
.x-axis, .x-axis * { color: red !important; }
.y-axis, .y-axis * { color: hsl(120, 100%, 40%) !important; }
Expand Down
15 changes: 14 additions & 1 deletion webgpu/lessons/webgpu-limits-and-features.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
.limits table,
.limits td,
.features td {
padding: 0.25em;
}
.limits table {
text-align: right;
}
.limits td:nth-child(2),
.limits td:nth-child(3) {
text-align: right;
}
.features table {
text-align: left;
}
.features td:nth-child(2) {
text-align: center;
}
.exceeds-limit {
color: var(--good-fg-color);
}
6 changes: 3 additions & 3 deletions webgpu/lessons/webgpu-limits-and-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ window.k = kFeatures;
const adapter = await navigator.gpu?.requestAdapter();

function withShortSize(v) {
return `${v} (${shortSize(v)})`;
return v >= 1024 ? `${v} (${shortSize(v)})` : `${v}`;
}

renderDiagrams({
limits(elem) {
const addRow = makeTable(elem, ['limit', 'your device', 'min']);
const addRow = makeTable(elem, ['limit name', 'your device', 'min']);
for (const key in adapter.limits) {
addRow([key, withShortSize(adapter.limits[key]), withShortSize(kLimitInfo[key].default)]);
addRow([key, [adapter.limits[key] > kLimitInfo[key].default ? 'exceeds-limit' : '', withShortSize(adapter.limits[key])], withShortSize(kLimitInfo[key].default)]);
}
},

Expand Down

0 comments on commit 8f71622

Please sign in to comment.