Commit Graph

98 Commits

Author SHA1 Message Date
Corentin Wallez 943a1a2d7a Add SwapChain::GetCurrentTexture
This is to eventually allow more using swapchain textures as CopySrc and
CopyDst. Note that this commit doesn't add any additional usages.

Because textures can reflect their creation parameters, swapchains now
need to pass in the correct texture descriptor in all code paths. This
requires additional handling in dawn::native error swapchains, and
dawn::wire::client's SwapChain reservation and Device::CreateSwapChain
code.

Tests are added for all of these code paths except
dawn::wire::client::Device::CreateSwapChain because there is no way to
create a Surface in wire tests at the moment (they don't have an
instance).

Bug: dawn:1551
Change-Id: I22d5e909e1e94d48eb52cae57aabff8a7f0c04c1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133463
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
2023-05-26 10:32:17 +00:00
Gregg Tavares 110358f2e6 Compat: Reject non-matching blend state / write mask
Bug: dawn:1839
Change-Id: I1284fb0c5b6a0d21603d9a9806d31e931b17b615
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/134061
Reviewed-by: Stephen White <senorblanco@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Gregg Tavares <gman@chromium.org>
2023-05-25 04:37:12 +00:00
Jiawei Shao daffe42b6a Implement device.CreateErrorShaderModule()
This patch implements device.CreateErrorShaderModule() for Blink to
directly create an error shader module and insert validation and
compilation errors when anything wrong is detected.

Bug: dawn:1345
Test: dawn_unittests
Change-Id: I1415aaf0609febaff49c40ebbfedbbcefa2e5504
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/134104
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
2023-05-25 03:32:41 +00:00
Gregg Tavares 0bdf2da9b8 Compat: Reject CubeArrays via Validation
Bug: dawn:1825
Change-Id: I32917a479c3eea457c8f315cfc089351b64292b6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133320
Commit-Queue: Gregg Tavares <gman@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-05-24 12:39:46 +00:00
jchen10 cd1fb68767 d3d11: enable DynamicBufferOffsetTests
This binds UAV slots all together at the same time.

Bug: dawn:1816
Bug: dawn:1705

Change-Id: Iea7af9cf00caf126a3964cc43bbf2162b35f80e0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132600
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
2023-05-23 00:54:15 +00:00
Brandon Jones 112b7fd856 Allow device lost callback to be passed at creation
This change updates the Device descriptor to allow a device lost
callback to be passed in at device creation time. This will be
important for allowing the API to return devices which have
already been lost in a future CL, which is the behavior required
by the spec.

This change does not yet deprecate the old method for setting the
callback, as there's still some tricky scenarios that will need to
be worked around to enable that and this CL is already fairly
large. (The uses in question pass the device or a value created
from the device as the userdata.)

Bug: chromium:1234617
Change-Id: I1adea5ceffdfdcfedff9fff4960f12303abba29c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121041
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Brandon Jones <bajones@chromium.org>
2023-05-17 01:52:30 +00:00
Austin Eng 039e886f9b Reland "Allow internal errors for pipeline creation failure"
This is a reland of commit e241d64d25
It adds handling and tests for internal errors in the wire

Original change's description:
> Allow internal errors for pipeline creation failure
>
> Change-Id: I6b8c109ae67e230fea3fb14511c2b3562191c0fa
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132300
> Kokoro: Kokoro <noreply+kokoro@google.com>
> Commit-Queue: Austin Eng <enga@chromium.org>
> Reviewed-by: Loko Kung <lokokung@google.com>

Change-Id: Icfda2d04bbb340fc4fdacf5ae65593bf958172fb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132441
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-05-11 00:06:38 +00:00
Austin Eng ccc78f6be4 Revert "Allow internal errors for pipeline creation failure"
This reverts commit e241d64d25.

Reason for revert: Missing the change to handle the enums in the wire

Original change's description:
> Allow internal errors for pipeline creation failure
>
> Change-Id: I6b8c109ae67e230fea3fb14511c2b3562191c0fa
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132300
> Kokoro: Kokoro <noreply+kokoro@google.com>
> Commit-Queue: Austin Eng <enga@chromium.org>
> Reviewed-by: Loko Kung <lokokung@google.com>

TBR=enga@chromium.org,noreply+kokoro@google.com,dawn-scoped@luci-project-accounts.iam.gserviceaccount.com,lokokung@google.com

Change-Id: I12309e85e888cc400729f88bb2340e8ecdf6b798
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132440
Auto-Submit: Austin Eng <enga@chromium.org>
Kokoro: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
2023-05-10 20:36:33 +00:00
François Beaufort 48e2b114be Emit warning if zero-size dispatch/draw
This CL make sure developers are warned when zero-size dispatches and
draws occur. Even though those are valid, it is good to encourage
developers to avoid them when possible.

Bug: dawn:1786
Change-Id: I99cbe8d556569d2e779b7b9c64739c3e5da8e290
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132222
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Fr <beaufort.francois@gmail.com>
2023-05-10 18:30:55 +00:00
Austin Eng e241d64d25 Allow internal errors for pipeline creation failure
Change-Id: I6b8c109ae67e230fea3fb14511c2b3562191c0fa
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132300
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
2023-05-09 21:27:20 +00:00
Loko Kung 0edb5204ab Adds AllowUnsafeAPIs toggle and fixes code-paths to use it.
- Note unsafe API paths currently check both AllowUnsafeAPIs and
  DisallowUnsafeAPIs toggle, allowing unsafe APIs if either is set to
  explicitly allow them. This will be removed once users have been
  updated.

Bug: dawn:1685
Change-Id: If322cc6dbe5ac3a02a31956df6fed0f5d3ec8e8f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/131400
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
2023-05-04 21:09:40 +00:00
Loko Kung b27e2bfa71 Adds generation for WGSL descriptor to rename source->code.
- Adds a deprecation warning for the incorrect usage.
- Adds test to verify that the warning is emitted and that the results
  are equal.
- Fixes all existing tests to use the newer code path.

Change-Id: I01bf85137ad1c66966e1aa0259ae03fc5247ba25
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/130320
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
2023-05-03 02:23:25 +00:00
Stephen White fed6b6b35b Turn AdapterBase into a wrapper class.
Change AdapterBase from an alias to PhysicalDeviceBase to a thin
wrapper class holding a ref to a PhysicalDeviceBase. This way,
mutiple AdapterBases can point at the same PhysicalDeviceBase.

For now, InstanceBase wraps all PhysicalDeviceBases discovered by a
backend in a single AdapterBase. In the future, this relationship will
become many-to-one.

Since Devices now maintain a ref on the AdapterBase wrapper (in order to
query toggles, etc), PhysicalDeviceBase::CreateDeviceImpl() now takes
the AdapterBase as an argument, so that the PhysicalDeviceBase knows
which AdapterBase to vend a Device for.

Note that the Toggles also still remain on the PhysicalDeviceBase, to
be moved up to the AdapterBase in a future change.

Bug: dawn:1774
Change-Id: Idef5d24fbd66d8552959230e246e453abddcc736
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/131001
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Stephen White <senorblanco@chromium.org>
2023-05-03 01:29:44 +00:00
Stephen White 9091b46278 Rename AdapterD3D* -> PhysicalDeviceD3D*.
Bug: dawn:1774

Change-Id: I9eca75c75c1ec162112915af3bd8371e808c2d60
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/130421
Commit-Queue: Stephen White <senorblanco@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-05-01 23:10:47 +00:00
Loko Kung 4e9ebeff02 Deprecates PopErrorScope returning a bool.
Bug: dawn:526
Change-Id: Ia4e985fbe4fcb5edb3fe80849f5b0df0190eea00
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/130340
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-05-01 19:25:18 +00:00
Stephen White e4877b7e68 Rename AdapterBase -> PhysicalDeviceBase.
AdapterBase will become a (thin) wrapper class in an upcoming patch,
allowing a single PhysicalDeviceBase to be wrapped in multiple AdapterBases,
each with different toggles and flags.

For now, alias AdapterBase to PhysicalDeviceBase.

Design doc: https://docs.google.com/document/d/1Ag3UAD6D1OVt9-MwKltzLefVhwKRdX0RqML2etrYVS4/edit

Change-Id: Ie77e99508be5285b651aa24ccb412bc9ff8b0111
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/130300
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
2023-05-01 16:39:04 +00:00
Quyen Le 87f51237b4 Revert "Disable frontend cache when implicit device sync is on."
This reverts commit 8cc6205bf7.

Reason for revert: Graphite actually reuses the bind groups between
draw calls using different pipelines and this change prevents it
from happening.

Original change's description:
> Disable frontend cache when implicit device sync is on.
>
> Normal behavior of ApiObjectBase's APIRelease() which only locks the
> device when last ref dropped is not thread safe if the object is cached
> as raw pointers by the device. Example of cached objects: bind group
> layout, pipeline, sampler, shader module.
>
> The following scenario could happen:
>  - thread A:
>     - shaderModuleA.APIRealease()
>     - shaderModuleA.refCount.Decrement() == true (ref count has reached zero)
>     - going to call shaderModuleA.LockAndDeleteThis().
>  - thread B:
>     - device.CreateShaderModule().
>     - lock()
>     - device.GetOrCreateShaderModule()
>     - shaderModuleA is in the cache, so return it.
>     - unlock()
>  - thread A:
>     - starting to call shaderModuleA.LockAndDeleteThis()
>     - lock()
>     - erase shaderModuleA from the cache.
>     - delete shaderModuleA.
>     - unlock()
>
> This CL disables caching when ImplicitDeviceSynchronization is turned on
> until we find a better solution.
>
> Bug: dawn:1769
> Change-Id: Ideb2a717ece0a40e18bd1c2bef00817262bd25da
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127900
> Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
> Reviewed-by: Austin Eng <enga@chromium.org>
> Kokoro: Kokoro <noreply+kokoro@google.com>

TBR=cwallez@chromium.org,enga@chromium.org,noreply+kokoro@google.com,dawn-scoped@luci-project-accounts.iam.gserviceaccount.com,lehoangquyen@chromium.org

Change-Id: Ib13bba8005402d06963865fae919388a91e718f0
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: dawn:1769
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128440
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
2023-04-21 03:10:12 +00:00
Brandon Jones 6cb055b6aa Retain descriptor labels for error objects
Since these objects are more likely to be included in error messages
it's important that we keep the labels that the developer has given
them.

Bug: dawn:1771
Change-Id: I78f4ccc23ce40d8eeceed8ca7dd563dff949b4fb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128420
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Brandon Jones <bajones@chromium.org>
2023-04-20 23:35:14 +00:00
Le Hoang Quyen 8cc6205bf7 Disable frontend cache when implicit device sync is on.
Normal behavior of ApiObjectBase's APIRelease() which only locks the
device when last ref dropped is not thread safe if the object is cached
as raw pointers by the device. Example of cached objects: bind group
layout, pipeline, sampler, shader module.

The following scenario could happen:
 - thread A:
    - shaderModuleA.APIRealease()
    - shaderModuleA.refCount.Decrement() == true (ref count has reached zero)
    - going to call shaderModuleA.LockAndDeleteThis().
 - thread B:
    - device.CreateShaderModule().
    - lock()
    - device.GetOrCreateShaderModule()
    - shaderModuleA is in the cache, so return it.
    - unlock()
 - thread A:
    - starting to call shaderModuleA.LockAndDeleteThis()
    - lock()
    - erase shaderModuleA from the cache.
    - delete shaderModuleA.
    - unlock()

This CL disables caching when ImplicitDeviceSynchronization is turned on
until we find a better solution.

Bug: dawn:1769
Change-Id: Ideb2a717ece0a40e18bd1c2bef00817262bd25da
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127900
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-04-20 21:12:25 +00:00
Le Hoang Quyen 335573116c Add Device::GetSupportedSurfaceUsage() method.
This method will return supported usage flags that can be used to create
a swap chain.

Bug: dawn:1760
Change-Id: I7699c2c4ef7142c6bd06e72239d6e4f9112f15a3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127440
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
2023-04-20 20:42:05 +00:00
Le Hoang Quyen 3e7a114a6e Add missing lock to APIBeginRender/ComputePass.
Add tests to verify multithreading behaviors of encoding render/compute
passes.

Bug: dawn:1662
Change-Id: I9bc6a0dd5d94b53b59e7e49a4611d4d55cc36e60
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/126980
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-04-12 21:07:31 +00:00
Corentin Wallez 1226684b09 Merge NewSwapChainBase in SwapChainBase
Bug: dawn:269
Change-Id: I514c210f88e2bf1f501e2d814f8ab931c5ed724f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/126423
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-04-07 13:30:50 +00:00
Le Hoang Quyen 7971bfe16f Add an option to enable implicit device synchronization.
1. Auto-generate mutex locking code in DawnNative's ProcTable's
functions. Using a mutex owned by the related Device.
  - Unless the function/class has "no autolock" attribute (new) in
  dawn.json. In which cases, no locking code will be auto-generated.
  - Currently Instance, Adapter, Surface, Encoder classes and
  Reference/Release method have "no autolock".

2. Added Feature::ImplicitDeviceSynchronization to enable Device's
mutex.
  - If this feature is disabled, lock/unlock Device's mutex is no-op.
  Auto-generated locking code will have no effect. This is the default.
  - This approach is used instead of generating two sets of ProcTable
  because it's cleaner and the internal code doesn't need to care about
  whether there is a mutex being locked or not. Furthermore, if there
  were two sets of ProcTable, and user used dawnProcSetProcs() to set
  global ProcTable, it would affect all other modules using different
  Devices. Even though those modules don't need thread safety.

Bug: dawn:1662
Change-Id: I75f0d28959f333318e4159916b259131581f79f5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119940
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
2023-04-05 19:35:07 +00:00
Austin Eng 78c496395c Always flush device callbacks when the callbacks are changed
With the wire, callbacks reference device-related data which is
freed when the device is unregistered from the wire. However,
the device that the wire refers to can live longer than this
and have its callbacks invoked at a later time, leading to a
use-after-free. Always flush the callbacks so that when the
wire unregisters a device and clears its callbacks, they are
called immediately and no dangling pointers remain.

Bug: chromium:1430221
Change-Id: Ib753b58cee5e7cb4d90ebd703958a0ddd5873573
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/126481
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-04-05 17:10:58 +00:00
Corentin Wallez 8a6ed63809 Remove OldSwapChain*
Bug: dawn:269
Change-Id: I5bc6f5f8b98a88c5d0bd69e0d2eaf1e4bbd12e2b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/126422
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
2023-04-05 10:13:01 +00:00
Le Hoang Quyen de078bad8d Forward callbacks to Instance after Device is destroyed.
When InstanceBase::ProcessEvents() iterates through list of devices, one
device might be being destructed on another thread. Even if we try to
increase ref count of that device inside the ProcessEvents(), the device
might be in the middle of destructor call on another thread, increasing
the ref count is invalid in this case.

This CL attempts to fix this issue by removing the device's pointer
from InstanceBase earlier: when DeviceBase::WillDropLastExternalRef()
is called. After this point, any callback registered to this device will
be forwarded to InstanceBase's callback queue instead.

Bug: dawn:752
Change-Id: I8ae86575e34f753e52a76f5fc774bbb5366a1b85
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/124281
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
2023-03-23 15:16:46 +00:00
Le Hoang Quyen 69e1c4b638 DawnNative: implement Instance::ProcessEvents
Since https://dawn-review.googlesource.com/c/dawn/+/120940, callbacks
will be deferred to be executed in next device.APITick() instead of
immediately.
However, if the device is already destroyed (last ref dropped),
user/wire_server has no chance to call device.APITick() anymore, leading
to the callbacks waiting in queue forever.

This is also possibly the cause of memory leaks in cluserfuzz tests.

This CL attempt to fix it by implementing Instance::ProcessEvents():
In this method, every created device will invoke APITick() even if it is
already lost/externally released.

bug: chromium:1422507
bug: dawn:752
Change-Id: Iec69ad3b547a7e88c6e1a2225b13ad060a501a4f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123420
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
2023-03-14 19:03:10 +00:00
Le Hoang Quyen 8ab7dbe424 DawnNative: Defer callbacks' triggerings to APITick().
Currently in the middle of some functions, we execute callbacks
immediately such as inside Buffer::APIMapAsync(), Device::HandleError()
or Queue::Submit().

Firstly, this has risks. The functions might be in a middle of modifying
internal states. By triggering callbacks, users might call API
functions again which could further modify the internal states
unexpectedly or access the states in an inconsistent way.

Secondly, upcoming thread safe API which locks the public functions with
a mutex might encounter deadlock. Because callbacks might cause
re-entrances which would unexpectedly lock the public function again.

This CL attempts to limit number of functions that are allowed to
trigger callbacks. Other functions that want to trigger callbacks will
instead enqueue a request to execute callbacks in the next
Device::APITick() call.

Currently the functions that will be allowed to trigger callbacks are:
- Device::WillDropLastExternalRef()
- Device::APITick()
- Device::APISetLoggingCallback()
- Device::APISetUncapturedErrorCallback()
- Device::APISetDeviceLostCallback()

Bug: dawn:1672
Change-Id: Iabca00f1b6f8f69eb5e966ffaa43dda5ae20fa8b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120940
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-03-06 19:03:26 +00:00
Loko Kung d81aca7106 Make ConsumedError require handling the returned bool.
This change makes it harder to misuse ConsumedError which can cause
device loss. When it is a known error, instead use HandleError to
bypass the "unlikely" if clause.

Bug: dawn:1336
Change-Id: I3052db343fe4080b257f1c2f9535f743a0e78526
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120384
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-03-02 01:24:03 +00:00
Loko Kung 53893a3d77 Adds error promoting to device loss when disallowed error occurs in a scope.
- Defaults consume error calls to only allow validation and device loss
  errors.
- Allows OOM errors on Buffers, QuerySets, and Textures only.
- Adds initial suite of unit tests (and any necessary updates to mock
  framework).

Bug: dawn:1336
Change-Id: I82112ea6c147e894280e605bf8ae0ce00488c9f3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119800
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-02-28 04:34:32 +00:00
Loko Kung f35f1ff98c Refactors native mock classes to be more like the Null device.
- Plumbs all descriptors through so that the objects act much more like
  a real implementation.
- Lots of changes to DestroyObjectTests.cpp to update usages and test
  through the APIs when applicable.
- Put in defaults for the mock device and make it as easy to use as
  possible.

Change-Id: I85b243a18ec1872aff0172549aec0f599967ea0e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119821
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
2023-02-22 20:38:37 +00:00
Corentin Wallez 5860a14591 Use the correct Validation/InternalError status for CreatePipelineAsync
Bug: chromium:1404422
Change-Id: I88d354688d2a0c39be120919a8ea4b234ce9c9af
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119460
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Shrek Shao <shrekshao@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
2023-02-16 19:44:05 +00:00
Zhaoming Jiang 63b777b552 Dawn: Refactor device toggles
This CL refactor the logic adapter creating device toggles set when
creating device and the way device holding its toggles. This CL also
introduce the concept "toggle stage", currently "device stage" only but
in future will add "instance stage" and "adapter stage" for instance and
adapter toggles. No changes on Dawn API.
More details:
1. Introduce `TogglesState` objects that represent the complete toggles
   state of a device (and will used for instance and adapter in future).
2. When creating a device, adapter set up a TogglesState object for it
   in `AdapterBase::CreateDeviceInternal` and
   `Adapter::SetupBackendDeviceToggles`, no other place would change
   the device's toggles state. This change simplify the logic.
3. Introduce the `ToggleStage` enum for every toggle and `TogglesState`
   object. Currently we only have `Device` toggle stage, but in future
   will have `Instance` and `Adapter` for instance and adapter toggles.

Bug: dawn:1495
Change-Id: Ifafac6a6a075b5b9a733159574ae5b6d4f3ebde9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118030
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
2023-02-10 01:43:55 +00:00
Austin Eng 00dbf0bf67 Add workarounds to blit a buffer to a depth/stencil texture
Works around issues on Metal Intel where CopyB2T and WriteTexture
with depth/stencil textures do not work correctly.
Fixes test failures with depth16unorm in the CTS.

Deletes UseTempTextureInStencilTextureToBufferCopy in favor of
the stencil blit. The former supposedly fixes a problem where
the stencil data is not flushed into the real stencil texture
by performing another T2T copy. This only works because the Metal
Intel backend also happens to allocate s8 as d32s8. Copying
the depth aspect as well seems to make the driver remember to
flush the data.
The stencil blit is a better fix for the problem since entirely
avoids getting the driver into a bad state where the stencil data
is not in sync.

Fixed: dawn:1389
Change-Id: If34b1d58996157036c164a5bc329e38b5e53f67a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117910
Reviewed-by: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
2023-01-30 17:13:12 +00:00
Brandon Jones 61d2cf297a Making SPIR-V ingestion and validation optional
Browsers won't be exposing the ability to pass SPIR-V shaders, and the
ability to consume and validate them is adding a non-trivial amount to
the browser binary size on platforms like Android. To avoid that
overhead, this change puts those features behind a flag so that browser
usage can easily omit them.

Bug: dawn:286
Change-Id: Idf70683f2c4ccf479b723c00ba6914e27e4f765f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117241
Commit-Queue: Brandon Jones <bajones@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
2023-01-19 21:17:42 +00:00
Austin Eng 03b69ff573 Delete StagingBuffer in favor of mappable buffers
This CL removes StagingBuffer to start to unify implementation
code paths for WriteTexture/Buffer and CopyBufferToTexture/Buffer.

This will help implementing a buffer-to-stencil copy workaround.

Bug: dawn:1389
Change-Id: Ieb23b8d871f14544ef01445a495dc1077274c9f2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117167
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2023-01-19 02:54:07 +00:00
Corentin Wallez 0963142273 Add wgpu::Device::ValidateTextureDescriptor
Bug: chromium:1266549
Change-Id: Iaef63ca6f4e447450953dfb0633b43931d8c2552
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116294
Reviewed-by: Brandon Jones <bajones@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
2023-01-10 15:17:26 +00:00
Loko Kung e70563ac03 Implements maxColorAttachmentBytesPerSample
- Adds the limit
- Adds relevant format-specific data into format table
- Adds deprecation validations regarding the limit
- Adds deprecation validation unit tests and helpful utils
- Moves deprecated api tests from end2end to unittests, allowing tests
  to be cross-files for ease after deprecation.
- Updates some validation messages to include helpful contexts.

Bug: dawn:1522
Change-Id: Ib05f9adb60808ff4d68061d9646e76c729a23643
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113543
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
2022-12-12 20:55:05 +00:00
Shrek Shao 0982dcea69 Add DisallowDeprecatedPath toggle
The runtime toggle is off by default. When turned on,
the deprecation warning will be turned into validation error.

Replace device->EmitDeprecationWarning with
DAWN_MAKE_DEPRECATION_ERROR macro which make an internal
validation error or make a MaybeError{} based on the toggle.
The callsite can wrap it with a DAWN_TRY.

Bug: dawn:1563, dawn:1525, dawn:1269, dawn:1602
Change-Id: I7fd6f4f8ffc2e054e5fc5fc4aaf23c47f5733847
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/111321
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Shrek Shao <shrekshao@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-11-29 23:05:30 +00:00
Loko Kung bf3fecfc4b Ensures blob cache is always available, even if it is just a placeholder
Bug: dawn:549
Change-Id: I7efbaa58d93691648107fc6b94d76596a77f6516
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/111140
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
2022-11-23 08:55:57 +00:00
Jiawei Shao 806c58324c Wire: Make validation error prior to OOM if mappedAtCreation == false
This patch updates the validations about CreateBuffer() with dawn_wire
to match the latest WebGPU SPEC.

According to the SPEC, the validations in CreateBuffer() should be
executed in the below order:
1. If mappedAtCreation == true, return nullptr and a RangeError will be
   generated in Chromium.
2. Validate BufferDescriptor and check if there is OOM at device timeline
3. Check if there is OOM at content timeline

Bug: dawn:1586
Change-Id: I97ff5f82a42208442ddf6e46e66381c3b3680450
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/109040
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
2022-11-23 02:06:11 +00:00
Loko Kung edbeeee285 Fix cache default on condition.
- Messed up the conditon in previous change so it required both the
  enable flag to be on and the disable to be off, but then we can't
  deprecate the enable flag in Chromium.

Bug: dawn:549
Change-Id: I1c730939104aafaef48182238fa32ed7fa6a1e16
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/110983
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
2022-11-22 03:38:51 +00:00
Loko Kung aa527ba348 Adds toggle to disable blob cache.
- The disable toggle will supercede the enable one once Chromium side
  deprecates usage of the enable one.

Bug: dawn:549
Change-Id: I5c5bd60161917fe2654cfce55a6f29e8a7e79962
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/110728
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-11-21 21:46:18 +00:00
jchen10 61d6d21091 Byte counting WriteBuffer/Texture to submit
Only tag to submit when the total size is larger than the threshold,
so that we can make as few submits as possible meanwhile avoiding OOM.

Bug: chromium:1258986
Change-Id: I7190e1bb942bfaffc5cd424ce4743173735b25e3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106418
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
2022-11-03 09:58:59 +00:00
jchen10 5722f2878d Remove the future serial
This adds 'HasScheduledCommands()', with which Dawn no longer needs the
future serial to tick and track the async tasks.

Bug: dawn:1413
Change-Id: Ide9ba69b796a46fa8bb70b002f4e2aeb1622bffd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98720
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
2022-10-29 03:28:20 +00:00
shrekshao d1a5f93630 Add maxBufferSize limit
Also emits a warning when create buffer size exceeds
the maxBufferSize limit during the deprecation period.

Bug: dawn:1525
Change-Id: I7b47ae5c85b116035fdcea8b68fb574c0a550729
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/103660
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Auto-Submit: Shrek Shao <shrekshao@google.com>
Commit-Queue: Shrek Shao <shrekshao@google.com>
2022-09-29 19:02:11 +00:00
Corentin Wallez 00aced1bbf Allow usage chromium_disable_uniformity_analysis
Only when unsafe APIs are allowed.

Bug: None
Change-Id: Idbe0494bec29bb623c0af39d3fb65d4995bb1a9b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104100
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-09-28 17:55:27 +00:00
Loko Kung 18dfc4797c Track TextureViews in Textures so that they can be chain-destroyed.
- Adds Prepend function to LinkedList to avoid directly using the
  insert functions on the LinkNodes. (And tests for this as well.)
- Adds ApiObjectList class for tracking lists of objects for
  destruction.
- Renames and virtualizes some tracking interfaces so that they can be
  overriden for the TextureView/Texture cases.
- Removes explicit destroying of TextureViews from Device since
  destroying Textures will destroy TextureViews now.

Fixed: dawn:1355
Change-Id: I3522383ea7724d6e41ac0c805793a6c34d9bec27
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101762
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-09-15 21:06:51 +00:00
Zhaoming Jiang 7ca82ac4d0 dawn: Refactor device creation and add shader-f16 feature
This CL modifies the way adapter creating devices, adds `shader-f16`
feature, and deprecates the `dawn-shader-float16` feature which is no
longer used.
Details:
1. Parse the toggles chained with device descriptor in
`adapter::CreateDeviceInternal`, which are then used to validate
features requirement within `CreateDeviceInternal` and passed to device
constructor as initializer.
2. When creating device, validate features requirement in
`CreateDeviceInternal` with toggles known, make sure to fail the device
creation if a required feature is not supported by adapter or is guarded
by certain toggles which were not enabled/disabled. Feature ShaderF16
and ChromiumExperimentalDp4a are validated in this way. Unittest is
added to check creating devices with toggles-guarded features required.
3. Add `shader-f16` feature, which allow `using f16;` in WGSL code.
End-to-end tests are added to test a trival f16 WGSL shader could be
used if and only if the device has `shader-f16` feature.
4. Deprecate the `dawn-shader-float16` feature, which will be completely
removed after cleaning up Blink code.

Bug: dawn:1510
Change-Id: I6cb2dcbe1ee584fdd6131c62df1ee850b881dbd2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100802
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
2022-09-08 00:11:04 +00:00
Loko Kung 3a53edcf18 Promote LoseForTesting to ForceLoss device so that user agents can use.
Bug: chromium:1356738
Change-Id: I348837ad4224124d9adba1ecf69a05b2060760c9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100566
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
2022-08-29 22:33:50 +00:00