-
Notifications
You must be signed in to change notification settings - Fork 308
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
Proposal: Add a usage bit to allow creating a view with different format when creating a texture #168
Comments
GPU could support casting between fully typed resources; if so, typeless is not required. In D3D, this is done by querying |
Thank you for investigation @Jiawei-Shao ! In general, I like the idea of specifying whether the user intends to create views of a texture with different formats up-front. The particular mechanism to do so is concerning: we have a clear definition of "usage", and we shouldn't add more flags there that don't fit this definition. Perhaps, we could introduce a new flag type: interface WebGPUTextureCapabilities {
const u32 NONE = 0;
const u32 VIEW_AS_DIFFERENT_FORMAT = 1;
const u32 VIEW_AS_CUBE = 2;
}; Compatibility specMajor things missing from the investigation are:
Correction-1: D3D12The link you provided for D3D12 API is really about D3D11 programming guide. The D3D12 docs on
Digging deeper, the rules for casting seem to be very complex: https://docs.microsoft.com/en-us/windows/desktop/direct3ddxgi/hardware-support-for-direct3d-12-0-formats Look at the "PCS" versus "FCS" versus "FNS" there... ouch Correction-2: D3D12
IIRC, this only applies to RTV and SRV, where the number of bits for each component must match. For UAVs D3D12 allows RGBA8 to be treated as Uint32, for example. I don't know if that's just specified on a case-by-case basis, or simply requires the total number of bits to match. Would be great to get some clarity from @RafaelCintron . Correction-3: Metal
I don't think we can do this. We'd still need |
https://developer.apple.com/documentation/metal/mtltexture/1515598-maketextureview
|
I prefer if we aim for the subset of "compatible classes" of formats between the underlying APIs. Vulkan has largely the same classes as Metal, (Vulkan spec "Format Compatibility Classes") though Vulkan is more compatible between compressed textures, but does restrict some formats that are otherwise of the same bit-per-block count. (R10X6G10X6B10X6A10X6 is not compatible with R16G16B16A16) @RafaelCintron will confirm what the compatibility landscape is for D3D12. |
Here is the breakdown of the D3D's texture families.
|
@RafaelCintron documentation for SRV creation has an explicit section casting from typeless to typed formats, and the families you provided are applicable there. However, documentation for either RTV, DSV, or UAV don't mention any compatibility requirements with the original resource format. Please clarify if this is an oversight in documentation, or the rules for SRV are indeed different? |
@kvark , this information is missing from the documentation. The rules are the same for RTV and DSV as they are for SRV. |
@RafaelCintron I don't think this is true, or at least there appears to be something missing here.
The UAV however succeeded, even though the target type is outside of the source type family. There is also a relevant documentation piece about casting to |
Thank you for keeping me honest, @kvark
|
Hopefully comprehensive spreadsheet that we can reference when adding a "reinterpretable" flag: #744 (comment) |
What's the rationale for this being in V1? |
RGB vs. SRGB seems pretty important but I don't know for sure. Other reinterpretations don't seem that useful for V1 though. |
Unorm vs Uint
Unorm vs Uint also seems important. |
Why? |
Meeting result: this probably* won't be super urgent, and it's not obvious how we expose this: usage bit (like metal(?)) vs list of formats (like vulkan(?)). Myles will continue internal discussions and come back, but if after that we're not able to come to a conclusion on this quickly, we're OK bumping it to post-V1. |
* Unless we find a particular use case that will need this (and texture-to-buffer-to-texture copy would be a problem). |
This is triggered by the implementation of CopyExternalImageToTexture. We find that, for example, rgba8unorm and rgba8uint is not allowed to copy from/to each other directly. Instead, we need to employee a render pipeline to do the blit. Since the content of the texture are same, if we support the direct copy, we don't need to start a pipeline and do some calculation in shaders. But I don't know any practical use cases from developers. Maybe someone use the same texture in render pipeline with unorm format and compute pipeline with uint format. |
It seems sometimes using uint is more "precise" than unorm. For example,
So now when writing tests I prefer using the pixel values like 0.2, 0.4, 0.6 or 0.8 because they will always generate exactly same values when copying from texture to buffer. |
Note that the issue with 0.5 is because a unorm texture represents values of the form, i / 255. 0.5 is exactly halfway between 127 / 255 and 128 / 255. If you use exact values the formats work correctly (I made tests for this in Dawn). |
Right, this makes sense. Thanks for the explanation.
Even if the destination texture is R8Unorm, a shader is still capable of writing precise values into it. It can execute a scale-round-unscale operation before writing the result. I understand that the texture view solution is more elegant than this solution. However, I'm not sure the texture view solution is required for V1 if there's a fairly straightforward workaround which is already achievable today. |
For reference, #744 seems to have all the research into it. https://docs.google.com/spreadsheets/d/1PRiOja_AVse0QuB6rDH_YzidGw5fucQIRz0md9Sg4m8/edit?usp=sharing is the big spreadsheet with the allowed conversions in all the 3 APIs. |
In this issue and #744, the only proposal I see is adding a single flag to |
Oh, I think there's another possible solution: do it like like D3D. The application asks whether two formats are compatible, and the device can return an enum: {yes, no, slow}. If the application asks for a "slow" reinterpretation, the texture must have been created with some This solution has pros and cons. Yet again, I'm thinking that this topic should be postponed because it's a not-insignificant design problem, and solving it isn't urgent. |
+1, I don't think we have a use case for which this feature is critical yet. |
In games, it's common to do most of your world rendering in linear space, and then do tonemapping, and then render the UI in gamma space. If you have textures that you need to reuse between the world and UI, then you need to sample with both sRGB and linear texture formats. A classic example is particle effects that need to appear in both the world and the UI. In WebGL 2, you would have to upload the same texture data twice, which is unfortunate. There's other examples too, though I don't know if format reinterpretation would work for them, like writing to a framebuffer texture in sRGB-format, and then sampling from that same framebuffer texture by a separate non-sRGB-format view, which effectively does gamma correction in the hardware. |
I really wish we could just make |
Considering that the evolution of sRGB texture reads started as a sampler flag (e.g. D3DSAMP_SRGBTEXTURE in D3D9) rather than a separate texture format, I can't imagine it's very expensive on desktop hardware, but that's just a hunch, I'd be curious to hear from IHVs. |
Intel had some reservations about adding SRGB compatibility by default because some GPU generation can use color compression for non-SRGB formats but not for SRGB formats, so that disables framebuffer color compression altogether (ccs_e). See this table that seems to indicate it would prevent color compression on RGBA8Unorm on Intel Gen9 (HD 630 and friends, really popular GPUs). |
Is that for render target writes only? Or does it apply to just normal textures as well. If it's just render target writes, does mesa/the GL driver have to do a full decompression step if I run |
That's true. So on Intel it will be more performant if the image is created with |
Some more thoughts on viewFormats list (#811) vs flag (this issue / #744), and the proposal in #2336. IIRC @litherum previously expressed was that a single reinterpretation flag was strongly preferable. Since I think we've we concretely determined we need more than a single flag (none, vs srgb, vs wider reinterpretation), #2336 attempts a reasonable middle ground. I think it's a fair argument, at least from a porting standpoint, that not having any presets would be a pain point for developers trying to assume reinterpretability later on. That said, I'm not concerned about it - I don't think format reinterpretation comes up extremely often, and when it does, developers can just hardcode the compatibility families that they might actually need - which might end up being smaller and more efficient than the families they would get with a preset option. We can infer from the existence of In any case, we previously seemed to be moving toward not tackling this problem until post-V1. If we do that, we just need a reasonably future-looking API that could be compatible with any of the other future designs (hence exploring those future designs in depth). Hence the proposal in #2336. |
That alternative proposal in IDL form:
|
Is this intended to capture the semantics of Vulkan's |
That's a difficult enterprise. We'd have to understand all the open-source driver logic and anticipate what happens in closed-source drivers. We can't get it perfect. There is a different approach we could take. We could define the set of formats that can be viewed with, portably, in all APIs. And then ask the user to specify exactly the ones they want:
I believe this is more future-proof, since we don't have to expose the nasty details of the drivers. |
Exactly my point, we can't get it perfect especially for future hardware. We can only get closer to perfect, with better granularity.
I think this is the same as #811. If we allowed a list of formats we should definitely always enforce strictly specified compatibility rules, not vary by platform.
Ah yeah, that was what I had in mind, I just forgot what the name in Vulkan was. (I just didn't think about it too hard because I think it's impossible in D3D12 anyway so we wouldn't be able to expose it.) |
We got inputs from the mesa driver team about creating *-srgb texture views on non-srgb texture.
So we(Intel) support Kai's proposal. |
WGSL meeting minutes 2022-01-19
|
Initially allows only srgb formats; further rules for format compatibility can follow. Issue: gpuweb#168 CC: gpuweb#2322
Initially allows only srgb formats; further rules for format compatibility can follow. Issue: gpuweb#168 CC: gpuweb#2322
I think there's more to discuss here:
|
Each format should have a list of compatible formats (that is portable to all APIs of course) that are supposed to all be compatible with each other. Using a
That wouldn't be allowed, the list of compatible formats should be portable (except for optional features of course).
I'm not sure I understand. On HD630 you get a slowdown. On other systems you don't. That's the point of having a creation argument that says whether there's reinterpretation. |
Note that #2540 correctly restricts the set of formats that can be reinterpreted:
|
* Always allow reassociation (gpuweb#2403) Fixed: gpuweb#2402 * Update question.md * Fix GPUBuffer.destroy when "mapping pending" (gpuweb#2411) Fixes gpuweb#2410 * CopyExternalImageToTexture: Support copy from webgpu context canvas/offscreenCanvas (gpuweb#2375) Address gpuweb#2350. * Fix typo in requestDevice and clarify error cases (gpuweb#2415) * Disallow empty buffer/texture usages (gpuweb#2422) * Specify dispatchIndirect behavior when exceeding limit (gpuweb#2417) The rest of the behavior of this command isn't specified yet, but this gets this into the spec so we can close the issue and edit later. Fixes gpuweb#323 * Require buffer bindings to have non-zero size (gpuweb#2419) * Require depth clear value in 0.0-1.0 (gpuweb#2421) * Require depth clear value in 0.0-1.0 * clarify handling of union * Fix error conventions for optional features (gpuweb#2420) * Fix error conventions for optional features * relax claim * Add increment and decrement statements (gpuweb#2342) * Add increment and decrement statements Phrased in terms of += and -= complex assignments Fixes: gpuweb#2320 * Remove the note about ++ and -- being reserved * Specify order of evaluation for expressions (gpuweb#2413) Fixes gpuweb#2261 * Expressions (and function parameters) are evaluated in left-to-right order * Remove todos that are covered elsewhere in the spec * variable lifetime * statement and intra-statement order * Remove [[block]] attribute from sample (gpuweb#2439) * Enable dynamic indexing on matrix and array values (gpuweb#2427) Fixes: gpuweb#1782 * Behaviour of empty statement is {Next} (gpuweb#2432) Fixes: gpuweb#2431 * wgsl: Fix TODOs in Execution section (gpuweb#2433) - in Technical overiew, say that evaluation of module-scope constants is the first thing to be executed - Remove "Before an entry point begins" because that's now fully covered by the Technical overview - Add introductory prose in the "Execution" top level section - remove parens from "Program order (within an invocation)" section. * wgsl: Fix "Entry Point" section TODOs (gpuweb#2443) - Link 'stage' attribute text to definitions later on - Move definition of "entry point" to the top of the "Entry Points" section, away from the "Entry point declaration" section. - Rework and simplify the first part of "Entry point declaration". Link to other parts of the spec, e.g. to user-defined function. * wgsl: Allow 0X for hex prefix (gpuweb#2446) Fixes: gpuweb#1453 * Specify compilation message order/locations are impl-defined (gpuweb#2451) Issue gpuweb#2435 * Disallow pipe for hex literals and allow capital (gpuweb#2449) * Remove [SameObject] from GPUUncapturedErrorEvent.error (gpuweb#2423) Implements the same behavior by prose rather than by WebIDL attribute. The WebIDL attribute isn't currently valid on union types, and we have to define this in prose anyway since [SameObject] is pure documentation (has no behavioral impact on its own). Fixes gpuweb#1225 * Make GPUDevice.lost return the same Promise object (gpuweb#2457) Fixes gpuweb#2147 * Require alignment limits to be powers of 2 (gpuweb#2456) Fixes gpuweb#2099 * Define GPUTextureViewDimension values (gpuweb#2455) including the order of faces in cube maps. Fixes gpuweb#1946 * Restore the box around algorithm divs (gpuweb#2453) When the spec template changed, algorithms stopped having an outline around them, which makes the spec hard to read. * Add source image orientation to copyExternalImageToTexture (gpuweb#2376) * Add 'originBottomLeft' attribute in GPUImageCopyTextureTagged Resolved gpuweb#2324 * Simplify the description and move originBottomLeft to GPUImageCopyExternalImage * Update spec/index.bs Address Kai's description. Co-authored-by: Kai Ninomiya <kainino1@gmail.com> * Fix typo * Apply suggestions from code review * Update spec/index.bs Co-authored-by: Kai Ninomiya <kainino1@gmail.com> * Clarify that attachments may not alias (gpuweb#2454) Fixes gpuweb#1358 * Fix examples classes, globals, and previews (gpuweb#2412) * Rework encoder state and mixins (gpuweb#2452) * GPUDebugCommandsMixin * Move state and command list to a GPUCommandsMixin * Propagate commands in endPass * fix which [[commands]] is appended * nits * "Validate"->"Prepare" the encoder state * Fully describe validation of render attachments (gpuweb#2458) * Fully describe validation of render attachments Fixes gpuweb#2303 * typos * more typo * Texture format caps for MSAA and resolve (gpuweb#2463) * Texture forma caps for MSAA and resolve * Fix missing columns, add notes * Add multisample flags even where rendering isn't supported * [editorial] wgsl: left shifts are logical (gpuweb#2472) * Remove 'read','read_write','write' as keywords, image formats as keywords (gpuweb#2474) * Texture format names are not keywords Issue: gpuweb#2428 * read, write, read_write are not keywords Fixes: gpuweb#2428 * Only define image format names usable for storage textures (gpuweb#2475) * Only define image format names usable for storage textures Fixes: gpuweb#2473 * Sort texel format names by channel width first Make it consistent with the other tables in the WGSL spec, and with the Plain Color Formats table in the WebGPU spec. * [editorial] Rename "built-in variable" -> "built-in value" (gpuweb#2476) * Rename "built-in variable" -> "built-in value" Fixes: gpuweb#2445 * Rewrite builtin-in inputs and outputs section It needed an overhaul because with pipeline I/O via entry point parameters and return types. Previously it was phrased in terms of *variables*, and some things just didn't make sense. Added rules expressing the need to match builtin stage and direction with entry point stage and parameter vs. return type. This also prevents mixing builtins from different stages or conflicting directions within a structure. * Move Limits section to under "WGSL Program" (gpuweb#2480) I think it makes more sense there. * Fix declaration-and-scope section for out-of-order decls (gpuweb#2479) * Fix declaration-and-scope section for out-of-order decls Also reorganize to bring "resolves to" closer to the definition of "in scope". Fixes: gpuweb#2477 * Apply review feedback * Behaviors: Ban obviously infinite loops (gpuweb#2430) Fixes: gpuweb#2414 * Clarify fract (gpuweb#2485) * Officially add Brandon as a spec editor (gpuweb#2418) Brandon has de facto equal standing as an editor and I think it's time to recognize it. * Require 1D texture mipLevelCount to be 1. (gpuweb#2491) Fixes gpuweb#2490 * Add simple examples for create, init, and error handling functions * Address feedback from Kai * Tweak to device loss comments * wsgl: Add bit-finding functions. (gpuweb#2467) * wsgl: Add bit-finding functions. - countLeadingZeros, countTrailingZeros - Same as MSL clz, ctz - firstBitHigh, firstBitLow - Same as HLSL firstbithi, firstbitlow - Same as GLSL findMSB, findLSB - Same as SPIR-V's GLSL.std.450 FindSMsb FindUMsb, FindILsb Fixes: gpuweb#2130 * Apply review feedback - Better description for countLeadingZeros countTrailingZeros - For i32, we can say -1 instead of |T|(-1) * Apply review feedback: drop "positions" * wgsl: Add extractBits, insertBits (gpuweb#2466) * wgsl: Add extractBits, insertBits Fixed: gpuweb#2129 gpuweb#288 * Formatting: break lines between parameters * insertBits operates on both signed and unsigned integral types * Add mixed vector-scalar float % operator (gpuweb#2495) Fixes: gpuweb#2450 * wgsl: Remove notes about non-ref dynamic indexing (gpuweb#2483) We re-enabled dynamically indexing into non-ref arrays and matrices in gpuweb#2427, as discussed in gpuweb#1782. * Disallow aliasing writable resources (gpuweb#2441) * Describe resource aliasing rules Fixes gpuweb#1842 * Update spec/index.bs Co-authored-by: Kai Ninomiya <kainino1@gmail.com> * Update spec/index.bs Co-authored-by: Kai Ninomiya <kainino1@gmail.com> * Editorial changes * Editorial: split out aliasing analysis * Consider only used bind groups and consider visibility flags * Consider aliasing between read-only and writable bindings * Tentatively add note about implementations * editorial nits * Fix algorithm * Remove loop over shader stages * Rephrase as "TODO figure out what happens" * clarify * Add back loop over shader stages * map -> list Co-authored-by: Myles C. Maxfield <mmaxfield@apple.com> Co-authored-by: Myles C. Maxfield <litherum@icloud.com> * Fix map/list confusion from gpuweb#2441 (gpuweb#2504) I forgot to save the file before committing my last fix to gpuweb#2441. * Fix a typo in packing built-in functions list (gpuweb#2513) * Remove tiny duplicates (gpuweb#2514) This removes a few tiny duplicates found in the spec. * integer division corresponds to OpSRem (gpuweb#2518) * wgsl: OpMod -> OpRem for integers * OpURem -> OpUMod again Co-authored-by: munrocket <munrocket@pm.me> * Remove stride attribute (gpuweb#2503) * Remove stride attribute Fixes: gpuweb#2493 Rework the examples for satisfying uniform buffer layout, using align and stride. * Remove attribute list from array declaration grammar rule Fixes: gpuweb#1534 since this is the last attribute that may be applied to a type declaration. * Switch to `@` for Attributes (gpuweb#2517) * Switch to `@` for Attributes * Convert new examples * Struct decl does not have to end in a semicolon (gpuweb#2499) Fixes: gpuweb#2492 * wgsl: float to integer conversion saturates (gpuweb#2434) * wgsl: float to integer conversion saturates Fixes a TODO * Saturation follows rounding toward zero. Simplify the wording of the rule. Explain what goes on at the extreme value (as discussed in the issue and agreed at the group), how you don't actually get the max value in the target type because of imprecision. * Store type for buffer does not have to be structure (gpuweb#2401) * Store type for buffer does not have to be structure * Modify an example showing a runtime-sized array as the store type for a storage buffer. Fixes: gpuweb#2188 * Update the API-side rules about minBindingSize The store type of the corresponding variable is not always going to be a structure type. Qualify the rule accordingly. * Rework minimum binding size in both WebGPU and WGSL spec Define 'minimum binding size' in WGSL spec, and link to it from WebGPU. Repeat the rule in both places (to be helpful). The minimum binding size for a var with store type |T| is max(AlignOf(T),SizeOf(T)), and explain why the AlignOf part is needed: it's because sometimes we have to wrap |T| in a struct. This also replaces the old rule in WGSL which confusingly dependend on the storage class. The storage class aspect is already embedded in the alignment and size constraints for the variable. * Simplify minimum binding size to Sizeof(store-type) Underlying APIs don't need the extra padding at the end of any structure which might wrap the store type for the buffer variable. * Update API-side to SizeOf(store-type) * Apply review feedback - Link to SizeOf in the WGSL spec - More carefully describe the motivation for the min-binding-size constraint. * Simplify, and avoid using the word "mapping" "Mapping" is how the buffer's storage is paged into host-accessible address space. That's a different concept entirely, and would only confuse things. * Remove duplicated words (gpuweb#2529) * Remove duplicated words `be` Remove two duplicated `be` from the WebGPU spec. * remove another duplicated `the` * editorial: streamline array and structure layout descriptions (gpuweb#2521) * Simplify array layout section - move definition of element stride to start of memory layout section - remove redundant explanation of array size and alignment - remaining material in that example is just examples - Add more detail to examples, including computing N_runtime for runtime-sized array * Streamline structure layout section - Make 'alignment' and 'size' defined terms - Don't repeat the rule for overall struct alignment and size. - Rename "Structure Layout Rules" to "Structure Member Layout" because that's all that remains. - Streamline the text in this section. Fixes: gpuweb#2497 * Apply review feedback: - state constraints at definition of the align and size attributes - rename 'size' definition to 'byte-size' - use the term "memory location" when defining alignment. - rename the incorrectly-named "lastOffset" to "justPastLastMember" - in the description of internal layout, state the general rule that the original buffer byte offset k must divide the alignment of the type. * Change notation: say i'th member instead of M<sub>i</sub> * Remove stray sentence fragment * Change GPUObjectBase.label from nullable to union-with-undefined (gpuweb#2496) * Separate loadOp and clear values * Add note explaining how dispatch args and workgroup sizes interact (gpuweb#2519) * Add a note explaining how the dispatch arguments and workgroup sizes interact * Address feedback * Address feedback from Kai * Refine the supported swapchain formats (gpuweb#2522) This removes the "-srgb" formats, and adds "rgba16float". Fixes: gpuweb#1231 * wgsl: Fix example's builtin name (gpuweb#2530) * wgsl: detailed semantics of integer division and remainder (gpuweb#1830) * wgsl: detailed semantics of integer division and remander Adds definition for `truncate` For divide by zero and signed integer division overlow, say they produce a "dynamic error". Fixes: gpuweb#1774 * Assume polyfill for the overflow case This pins down the result for both division and remainder. * Specify definite results for int division, % by zero These are no longer "dynamic errors". For integer division: e1 / 0 = e1 For integers, e1 % 0 = 0 The % case is somewhat arbitrary, but it makes this true: e1 = (e1 / 0) + (e1 % 0) Another way of formulating the signed integer cases is to forcibly use a divisor of 1 in the edge cases: where MINIT = most negative value in |T| where Divisor = select(e2, 1, (e2==0) | ((e1 == MININT) & (e2 == -1))) then "e1 / e2" = truncate(e1 / Divisor) "e1 % e2" = e1 - truncate(e1/Divisor) * Divisor The unsigned integer case is similar but doesn't have (MININT,-1) case. * Add override declarations (gpuweb#2404) * Add override declarations * Refactor `var` and `let` section * have a general value declaration subsection * subsections on values for let and override * move override requirements from module constants to override declarations * introduce override keyword * remove override attribute and add id attribute * literal parameter is now required * Update many references in the spec to be clearer about a let declaration vs an override declaration * update examples * Make handling of `offset` parameter for texture builtins consistent * always either const_expression or module scope let * Changes for review * combine grammar rules * refactor validation rules for overrides * fix typos * add todo for creation-time constant * fix example * combine grammar rules * Rename storage class into address space (gpuweb#2524) * Rename storage class into address space * Davids review findings, plus renaming of |SC| * Add an explainer for Adapter Identifiers to facilitate further design discussion. * Explain smoothStep better (gpuweb#2534) - Use more suggestive formal parameter names - Give the formula at the function definition, not just at the error bounds explanation. * Fix clamp arity in error bounds section (gpuweb#2533) Also at the definitions, use more suggestive formal parameter names (e,low,high) instead of the less readable (e1,e2,e3) * Use consistent capitalisation in section titles (gpuweb#2544) * remove some unnecessary `dfn` tags * Remove unnecessary todos (gpuweb#2543) * Defer API linkage issues to the API spec * remove issues and todos that are covered in the API * remove todo about array syntax Co-authored-by: David Neto <dneto@google.com> * Add GPUTextureDescriptor viewFormats list (gpuweb#2540) * Add GPUTextureDescriptor viewFormats list Initially allows only srgb formats; further rules for format compatibility can follow. Issue: gpuweb#168 CC: gpuweb#2322 * note on canvas config * Enforce presence of an initializer for module-scope let (gpuweb#2538) * Enforce presence of an initializer for module-scope let * Since pipeline-overridable constants were split from let declarations the grammar for let declarations can enforce the presence of an initializer * Remove global_const_intiailizer since it was only used in for a single grammar production (module-scope let) and only had a single grammar itself * Update extract_grammar to initialize type declarations with zero-value expressions * fix typos * Make depth/stencil LoadOp and StoreOp optional again This change was landed as part of gpuweb#2387 but was then accidentally reverted when gpuweb#2386 landed out of order. * Add the uniformity analysis to the WGSL spec (gpuweb#1571) * Add the uniformity analysis to the WGSL spec Make the information computed more explicit per Corentin's suggestion Add uniformity of builtins, limit the singleton rule to {Next}, do some minor cleanup Make the typography more uniform and hopefully less confusing Add rule for switch, and simplify rule for if Clarify the role of CF_start, and remove two instances of the word 'simply' Remove TODO and allow accesses to read-only global variables to be uniform Mark functions that use implicit derivatives as ReturnValueCannotBeUniform * s/#builtin-variables/#builtin-values/ after rebasing * Add (trivial) rules for let/var, as suggested by @alan-baker and @dneto * Add rules for non-shortcircuiting operators, as suggested by @alan-baker and @dneto * Use the rowspan attribute to simplify the tables in the uniformity section * Fix syntax of statement sequencing/blocks in the uniformity rules, following an earlier fix to the behavior analysis. * s/adressing/addressing/, as suggested by @alan-baker in an earlier review. * Clarify 'local variable' * Deal with non-reconvergence at the end of functions * s/global/module-scope/, s/built-in variable/built-in value/, and mention let-declarations * Address the last issues found by @dneto0 * CannotBeUniform -> MayBeNonUniform * Apply Dzmitry's suggestions * s/MustBeUniform/RequiredToBeUniform/g Co-authored-by: Robin Morisset <rmorisset@apple.com> * Vectors consist of components (gpuweb#2552) * Vectors consist of components * Update index.bs * Make depth/stencil LoadOp and StoreOp optional again (pt.2) This change was landed as part of gpuweb#2387 but was then accidentally reverted when gpuweb#2386 landed out of order. * WGSL: Replace [SHORTNAME] with WGSL (gpuweb#2564) Fixes gpuweb#1589 * Fix step() logic (gpuweb#2566) * Relax vertex stride requirements (gpuweb#2554) * s/endPass/end/ for pass encoders (gpuweb#2560) Fixes gpuweb#2555 * Fix canvas resizing example * Rework "validating texture copy range" for 1D/3D textures. (gpuweb#2548) That algorithm special cased 1D and 2D textures, making empty copies valid for 2D and not for 1D. 3D textures where just not discussed. Fix this by just checking that the copy fits in the subresource size, and also turn "validating texture copy range" into an algorithm with arguments. Co-authored-by: Dzmitry Malyshau <kvark@fastmail.com> * Add optional trailing comma for the attribute syntax. (gpuweb#2563) All places that use a variable number of comma-separated things now support trailing commas. However things with a fixed number of comma-separated arguments don't. They are: - array_type_decl - texture_sampler_types - type_decl - variable_qualifier Fixes gpuweb#1243 * wgsl: reserve `demote` and `demote_to_helper` (gpuweb#2579) * if,switch param does not require parentheses (gpuweb#2585) Fixes: gpuweb#2575 * Add while loop (gpuweb#2590) Update behaviour analysis and uniformity analysis. Fixes: gpuweb#2578 * Allow sparse color attachments and ignored FS outputs (gpuweb#2562) * Allow sparse color attachments and ignored FS outputs Fixes gpuweb#1250 Fixes gpuweb#2060 * Update pipeline matching rules Co-authored-by: Dzmitry Malyshau <kvark@fastmail.com> * Render -- as is (gpuweb#2576) * Render -- as is * Use backticks * Use backticks for plus plus too * Better separate Security and Privacy sections (gpuweb#2592) * Better separate Security and Privacy sections They were largely already separate but the header levels were a bit confusing so this CL normalizes them and renames the sections to "Security Considerations" and "Privacy Considerations" as requested by the W3C security review guidelines. Also expands the privacy section with a brief header, another mention of driver bugs as a potentially identifying factor, and a note indicating that discussions about adapter identifiers are ongoing. * Simplify adapter info privacy considerations note. * Remove SPIR-V mappings (gpuweb#2594) * Remove most references to SPIR-V opcodes and types in the specification * References remain transitively in the Memory Model section as it is necessary for the specification * Removed goal section as they only described SPIR-V * Complete the Errors & Debugging section * Addressed feedback * Update spec/index.bs Co-authored-by: Kai Ninomiya <kainino@chromium.org> * Update spec/index.bs Co-authored-by: Kai Ninomiya <kainino@chromium.org> * Make firing the unhandlederror event optional in the algorithm * Refactored algorithms for more sensible names. * Fix typo in "validating texture copy range" argument (gpuweb#2596) * Fix a typo in a note "applicaitions". (gpuweb#2602) * Disallow renderable 3D textures (gpuweb#2603) * `createSampler` creates a `GPUSampler` (gpuweb#2604) Correct the link that errantly pointed to `GPUBindGroupLayout`. * Extend lifetime of GPUExternalTexture imported from video element (gpuweb#2302) * Extend lifetime of GPUExternalTexture imported from video element Original PR: gpuweb#1666 Discussion: gpuweb#2124 * adjust lifetime, add flag * editorial * wgsl: reserve 'std', 'wgsl' (gpuweb#2606) Fixes: gpuweb#2591 * wgsl: Fix typos (gpuweb#2610) `signficant` -> `significant` `consectuive` -> `consecutive` * wgsl: Rename `firstBitHigh` and `firstBitLow` The current names are confusing, as `High` or `Low` may refer to scanning from the MSB or LSB, or that it is scanning for the bits `1` or `0`. By renaming to `firstLeadingBit` and `firstTrailingBit` the ambiguity is reduced, and we have a consistent terminology with `countLeadingZeros` / `countTrailingZeros`. * Update override examples (gpuweb#2614) Fixes gpuweb#2613 * Update WGSL syntax for overridable constants * Fix a typo in FP32 internal layout (gpuweb#2615) * Fix a typo in FP32 internal layout In the internal layout of float32, Bits 0 through 6 of byte k+2 contain bits 16 through 22 of the fraction, which has a total of 23 bits. * remove duplicated "bit" * WGSL style guide: in progress extensions developed outside main spec (gpuweb#2616) Fixes: gpuweb#2608 * Clarify when a built-in function name can be redefined (gpuweb#2621) * wgsl: Cleanup internal layout of matrix type (gpuweb#2624) * Cleanup internal layout of matrix type Use alignOf() to cleanup the description of internal layout of matrix type. * Use "i x AlignOf()" instead of "AlignOf() x i" * [editorial] Fix uniformity table widths (gpuweb#2623) * Reduce table width by allowing more line breaks * Make op consistently italicized * Add break-if as optional at end of continuing (gpuweb#2618) * Add break-if as optional at end of continuing A break-if can only appear as the last statement in a continuing clause. Simplifies the rule about where a bare 'break' can occur: It must not be placed such that it would exit a continuing clause. Fixes: gpuweb#1867 Also refactor the grammar to make: continuing_compound_statement case_compound_statement These are called out as special forms of compound statement, so that the scope rule of declarations within a compound statement also clearly apply to them. * Add statement behaviour of break-if The expresison always includes {Next}. When the expression is true, the {Break} behaviour is invoked. Otherwise, the {Next} behaviour is invoked. So it's B - {Next} + {Next, Break} or B + {Break} * Add uniformity analysis for break-if * Apply review feedback - Tighten the wording about where control is transferred for break and break-if - Allow "break" to be used in a while loop. * Avoid double-avoid * wgsl: Reserve words from common programming languages (gpuweb#2617) * wgsl: Reserve words from common programming languages Reserves words from C++, Rust, ECMAScript, and Smalltalk Add a script to automatically generate the contents of the _reserved grammar rule. Update extract-grammar.py to strip HTML comments before processing. * List WGSL as a reason for a keyword reservation * Reserve 'null' * Reserve keywrods from GLSL 4,6 and HLSL * Use ECMAScript 2022 instead of ECMAScript 5.1 * Reserve HLSL keywords * Add acosh, asinh, atanh builtin functions (gpuweb#2581) * Add acosh, asinh, atanh builtin functions Use the polyfills from Vulkan. Fixes: gpuweb#1622 * Result is 0 in regions that make no mathematical sense: acosh, atanh * wgsl: Cleanup the internal memory layout of vector using SizeOf (gpuweb#2626) * Cleanup the internal memory layout of vector using SizeOf Descript the internal memory layout of vector types vecN<T> with SizeOf(T) rather than literal number. * Fix typo * Fix typos of accuracy of exp and exp2 (gpuweb#2634) Fix the accuracy requirement of exp and exp2 to 3 + 2 * abs(x) ULP. * Reland: Only allow depth/stencil load/store ops when they have an effect * Validate query index overwrite in timestampWrites of render pass (gpuweb#2627) Vulkan requires the query set must be reset between uses and the reset command must be called outside render pass, which makes it impossable to overwrite a query index in same query set in a render pass, but we can do that in different query set or different render pass. * Add definitions for uniformity terms (gpuweb#2638) * add definitions (and link back to them) for: * uniform control flow * uniform value * uniform variable * define the scope of uniform control flow for different shader stages * Allow statically unreachable code (gpuweb#2622) * Allow statically unreachable code Fix gpuweb#2378 * modify behavior analysis to allow statically unreachable code * unreachable code does not contribute to behaviors * modify uniformity analysis to not analyze unreachable code * unreachable statements are not added to the uniformity graph * Improve examples * Clarify when sequential statement behaviour leads to a different behaviour from that of the individual statement * improve example comment formatting to reduce possible horizontal scrolling * Name in enable directive can be a keyword or reserved word (gpuweb#2650) Fixes: gpuweb#2649 Also simplify description of where an enable directive can appear. They must appear before any declaration. * GPUDevice.createBuffer() requires a valid GPUBufferDescriptor (gpuweb#2643) * Typo in definition of finish() * Allow unmasked adapter info fields to be requested individually. * Update design/AdapterIdentifiers.md Co-authored-by: Kai Ninomiya <kainino@chromium.org> * Explicitly note that declined consent rejects the promise * Uses commas to separate struct members intead of semicolons (gpuweb#2656) Fixes gpuweb#2587 * Change the separator for struct members from semicolons to commas * Comma is optional after the last member * Changes the grammar to require one or more struct members * Already required by the prose of the spec * [editorial] Compress expression tables (gpuweb#2658) * [editorial] Compress expression tables * Combine arithmetic and comparison expression table entries for integral and floating-point entries * since SPIR-V mappings were removed there is no strong need to have separate entries * improved wording * make online should die on everything (gpuweb#2644) * Commiting GPUCommandBuffers to the wrong GPUDevice is an error (gpuweb#2666) Eventually we'll want to add more logic to make sure that command buffers are only valid on the queue they're created from. Right now, though, every device just has exactly one queue, so matching devices is the same as matching queues. * Mipmap filtering might be extended separately from min/mag filtering in the future * Add a way of setting the initial label for the default queue * add rAF/rVFC examples * [Process] Add RequirementsForAdditionalFunctionality.md * Addressing Kai and Dzmitry's comments * GPUSamplerDescriptor.maxAnisotropy gets clamped to a platform-specific maximum (gpuweb#2670) Co-authored
This landed in the spec, so tentatively closing this issue. |
Introduction
Explicit APIs all provide mechanisms to specify if we can create a texture view with different format when creating a texture to optimize the access of textures when the texture is never interpreted in a different format. This proposal intends to add a new usage bit in
WebGPUTextureDescriptor
to make full use of this type of optimization provided by all explicit APIs.Native APIs
D3D12
In D3D, there are two ways to specify the layout (or memory footprint) of a resource:
D3D document also mentions creating a fully-typed resource enables the runtime to optimize access, especially if the resource is created with flags indicating that it cannot be mapped by the application.
However fully-typed resources cannot be reinterpreted using the view mechanism unless the resource was created with the
D3D10_DDI_BIND_PRESENT
flag.On a typeless resource, the data type is unknown when the resource is first created. The exact data format (whether the memory will be interpreted as integers, floating point values, unsigned integers etc.) will not be determined until the resource is bound to the pipeline with a resource view. The format specified must be from the same family as the typeless format used when creating the resource. For example, a resource created with the
R8G8B8A8_TYPELESS
format cannot be viewed as aR32_FLOAT
resource even though both formats may be the same size in memory.Metal
In Metal, a texture must be created with
MTLTextureUsagePixelFormatView
usage if you want to callmakeTextureView()
on this texture.Vulkan
Vulkan defines
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
for the memberflag
inVkImageViewCreateInfo
struct.VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
specifies that the image can be used to create aVkImageView
with a different format from the image.If
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
is not set, the drivers will be able to do optimizations on the storage of the image. For example, according to the implementation in Mesa, for the images in some formats and created without this flag, their storage will be compressed inside the driver and the performance of all clearing, texturing and rendering operations on these images will be able to get improved.Proposal
Here is our proposal on WebGPU texture view in IDL.
As D3D12, Metal and Vulkan all provide mechanisms to restrict the format of the texture view must be the same as the original texture, it is necessary to expose this ability to WebGPU.
In our proposal a new usage bit
VIEW_IN_DIFFERENT_FORMAT
is added toWebGPUTextureUsage
to specify if we can create a texture view with a different format when creating the WebGPU texture. This usage bit can be implemented as follows on each backends:MTLTextureUsagePixelFormatView
flag when creating Metal textures.VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
when creating Vulkan images.The text was updated successfully, but these errors were encountered: