Diff
Modified: trunk/Source/WebGPU/ChangeLog (292553 => 292554)
--- trunk/Source/WebGPU/ChangeLog 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/ChangeLog 2022-04-07 19:42:41 UTC (rev 292554)
@@ -1,5 +1,106 @@
2022-04-07 Myles C. Maxfield <[email protected]>
+ [WebGPU] Delete redundant spec quotes
+ https://bugs.webkit.org/show_bug.cgi?id=238711
+
+ Reviewed by Kimmo Kinnunen.
+
+ I actually prefer to have lots and lots of spec quotes throughout the implementation,
+ but enough people have commented about it that it's become clear that we probably
+ shouldn't have them. This deletes almost all of them (and leaves just the ones that
+ are particularly insightful).
+
+ * WebGPU/Buffer.h:
+ * WebGPU/Buffer.mm:
+ (WebGPU::validateDescriptor):
+ (WebGPU::validateCreateBuffer):
+ (WebGPU::Device::createBuffer):
+ (WebGPU::Buffer::destroy):
+ (WebGPU::Buffer::validateGetMappedRange const):
+ (WebGPU::Buffer::getMappedRange):
+ (WebGPU::Buffer::validateMapAsync const):
+ (WebGPU::Buffer::mapAsync):
+ (WebGPU::Buffer::validateUnmap const):
+ (WebGPU::Buffer::unmap):
+ * WebGPU/CommandEncoder.mm:
+ (WebGPU::validateCopyBufferToBuffer):
+ (WebGPU::CommandEncoder::copyBufferToBuffer):
+ (WebGPU::validateImageCopyBuffer):
+ (WebGPU::validateCopyBufferToTexture):
+ (WebGPU::CommandEncoder::copyBufferToTexture):
+ (WebGPU::validateCopyTextureToBuffer):
+ (WebGPU::CommandEncoder::copyTextureToBuffer):
+ (WebGPU::areCopyCompatible):
+ (WebGPU::validateCopyTextureToTexture):
+ (WebGPU::CommandEncoder::copyTextureToTexture):
+ (WebGPU::validateClearBuffer):
+ (WebGPU::CommandEncoder::clearBuffer):
+ (WebGPU::CommandEncoder::validateFinish const):
+ (WebGPU::CommandEncoder::finish):
+ (WebGPU::CommandEncoder::insertDebugMarker):
+ (WebGPU::CommandEncoder::validatePopDebugGroup const):
+ (WebGPU::CommandEncoder::popDebugGroup):
+ (WebGPU::CommandEncoder::pushDebugGroup):
+ * WebGPU/ComputePassEncoder.mm:
+ (WebGPU::ComputePassEncoder::insertDebugMarker):
+ (WebGPU::ComputePassEncoder::validatePopDebugGroup const):
+ (WebGPU::ComputePassEncoder::popDebugGroup):
+ (WebGPU::ComputePassEncoder::pushDebugGroup):
+ * WebGPU/Device.h:
+ * WebGPU/Device.mm:
+ (WebGPU::Device::currentErrorScope):
+ (WebGPU::Device::generateAValidationError):
+ (WebGPU::Device::validatePopErrorScope const):
+ (WebGPU::Device::popErrorScope):
+ (WebGPU::Device::pushErrorScope):
+ * WebGPU/Queue.mm:
+ (WebGPU::Queue::submit):
+ (WebGPU::validateWriteBufferInitial):
+ (WebGPU::Queue::validateWriteBuffer const):
+ (WebGPU::Queue::writeBuffer):
+ (WebGPU::validateWriteTexture):
+ (WebGPU::Queue::writeTexture):
+ * WebGPU/RenderBundleEncoder.mm:
+ (WebGPU::RenderBundleEncoder::insertDebugMarker):
+ (WebGPU::RenderBundleEncoder::validatePopDebugGroup const):
+ (WebGPU::RenderBundleEncoder::popDebugGroup):
+ (WebGPU::RenderBundleEncoder::pushDebugGroup):
+ * WebGPU/RenderPassEncoder.mm:
+ (WebGPU::RenderPassEncoder::insertDebugMarker):
+ (WebGPU::RenderPassEncoder::validatePopDebugGroup const):
+ (WebGPU::RenderPassEncoder::popDebugGroup):
+ (WebGPU::RenderPassEncoder::pushDebugGroup):
+ * WebGPU/Sampler.h:
+ (WebGPU::Sampler::descriptor const):
+ (WebGPU::Sampler::isComparison const):
+ * WebGPU/Sampler.mm:
+ (WebGPU::validateCreateSampler):
+ (WebGPU::Device::createSampler):
+ * WebGPU/Texture.h:
+ * WebGPU/Texture.mm:
+ (WebGPU::isCompressedFormat):
+ (WebGPU::Texture::isDepthOrStencilFormat):
+ (WebGPU::Texture::texelBlockWidth):
+ (WebGPU::Texture::texelBlockHeight):
+ (WebGPU::isRenderableFormat):
+ (WebGPU::supportsMultisampling):
+ (WebGPU::maximumMiplevelCount):
+ (WebGPU::Device::validateCreateTexture):
+ (WebGPU::Device::createTexture):
+ (WebGPU::Texture::resolveTextureViewDescriptorDefaults const):
+ (WebGPU::Texture::arrayLayerCount const):
+ (WebGPU::Texture::validateCreateView const):
+ (WebGPU::computeRenderExtent):
+ (WebGPU::Texture::createView):
+ (WebGPU::Texture::logicalMiplevelSpecificTextureExtent):
+ (WebGPU::Texture::physicalMiplevelSpecificTextureExtent):
+ (WebGPU::imageCopyTextureSubresourceSize):
+ (WebGPU::Texture::validateImageCopyTexture):
+ (WebGPU::Texture::validateTextureCopyRange):
+ (WebGPU::Texture::validateLinearTextureData):
+
+2022-04-07 Myles C. Maxfield <[email protected]>
+
[WebGPU] Implement Texture view format compatibility
https://bugs.webkit.org/show_bug.cgi?id=238710
Modified: trunk/Source/WebGPU/WebGPU/Buffer.h (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/Buffer.h 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/Buffer.h 2022-04-07 19:42:41 UTC (rev 292554)
@@ -66,11 +66,11 @@
// https://gpuweb.github.io/gpuweb/#buffer-state
// Each GPUBuffer has a current buffer state on the Content timeline which is one of the following:
enum class State : uint8_t {
- Mapped, // "where the GPUBuffer is available for CPU operations on its content."
- MappedAtCreation, // "where the GPUBuffer was just created and is available for CPU operations on its content."
- MappingPending, // "where the GPUBuffer is being made available for CPU operations on its content."
- Unmapped, // "where the GPUBuffer is available for GPU operations."
- Destroyed, // "where the GPUBuffer is no longer available for any operations except destroy."
+ Mapped,
+ MappedAtCreation,
+ MappingPending,
+ Unmapped,
+ Destroyed,
};
id<MTLBuffer> buffer() const { return m_buffer; }
@@ -88,15 +88,15 @@
id<MTLBuffer> m_buffer { nil };
// https://gpuweb.github.io/gpuweb/#buffer-interface
- // "GPUBuffer has the following internal slots:"
- const uint64_t m_size { 0 }; // "The length of the GPUBuffer allocation in bytes."
- const WGPUBufferUsageFlags m_usage { 0 }; // "The allowed usages for this GPUBuffer."
- State m_state { State::Unmapped }; // "The current state of the GPUBuffer."
- // "[[mapping]] of type ArrayBuffer or Promise or null." This is unnecessary; we can just use m_device.contents.
- MappingRange m_mappingRange { 0, 0 }; // "[[mapping_range]] of type list<unsigned long long> or null."
+
+ const uint64_t m_size { 0 };
+ const WGPUBufferUsageFlags m_usage { 0 };
+ State m_state { State::Unmapped };
+ // [[mapping]] is unnecessary; we can just use m_device.contents.
+ MappingRange m_mappingRange { 0, 0 };
using MappedRanges = RangeSet<Range<size_t>>;
- MappedRanges m_mappedRanges; // "[[mapped_ranges]] of type list<ArrayBuffer> or null."
- WGPUMapModeFlags m_mapMode { WGPUMapMode_None }; // "The GPUMapModeFlags of the last call to mapAsync() (if any)."
+ MappedRanges m_mappedRanges;
+ WGPUMapModeFlags m_mapMode { WGPUMapMode_None };
const Ref<Device> m_device;
};
Modified: trunk/Source/WebGPU/WebGPU/Buffer.mm (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-04-07 19:42:41 UTC (rev 292554)
@@ -42,7 +42,6 @@
// FIXME: "If any of the bits of descriptor’s usage aren’t present in this device’s [[allowed buffer usages]] return false."
- // "If both the MAP_READ and MAP_WRITE bits of descriptor’s usage attribute are set, return false."
if ((descriptor.usage & WGPUBufferUsage_MapRead) && (descriptor.usage & WGPUBufferUsage_MapWrite))
return false;
@@ -53,27 +52,22 @@
{
// FIXME: "this is a valid GPUDevice."
- // "validating GPUBufferDescriptor(this, descriptor) returns true."
if (!validateDescriptor(device, descriptor))
return false;
- // "descriptor.usage must not be 0."
if (!descriptor.usage)
return false;
// FIXME: "descriptor.usage is a subset of this.[[allowed buffer usages]]."
- // "If descriptor.usage contains MAP_READ: descriptor.usage contains no other flags except COPY_DST."
if ((descriptor.usage & WGPUBufferUsage_MapRead)
&& (descriptor.usage & ~WGPUBufferUsage_CopyDst & ~WGPUBufferUsage_MapRead))
return false;
- // "If descriptor.usage contains MAP_WRITE: descriptor.usage contains no other flags except COPY_SRC."
if ((descriptor.usage & WGPUBufferUsage_MapWrite)
&& (descriptor.usage & ~WGPUBufferUsage_CopySrc & ~WGPUBufferUsage_MapWrite))
return false;
- // "If descriptor.mappedAtCreation is true: descriptor.size is a multiple of 4."
if (descriptor.mappedAtCreation && (descriptor.size % 4))
return false;
@@ -112,7 +106,6 @@
// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbuffer
- // "If any of the following conditions are unsatisfied, return an error buffer and stop."
if (!validateCreateBuffer(*this, descriptor))
return nullptr;
@@ -125,29 +118,9 @@
buffer.label = fromAPI(descriptor.label);
- // FIXME: Handle descriptor.mappedAtCreation.
- // Because non-mappable buffers can be mapped at creation,
- // this means we have to have a temporary buffer mapped,
- // and we can to schedule a copy command when it gets unmapped,
- // presumably at first use.
-
- // "Let b be a new GPUBuffer object."
- // "Set b.[[size]] to descriptor.size."
- // "Set b.[[usage]] to descriptor.usage."
-
- // "If descriptor.mappedAtCreation is true:"
- if (descriptor.mappedAtCreation) {
- // "Set b.[[mapping]] to a new ArrayBuffer of size b.[[size]]." This is unnecessary.
- // "Set b.[[mapping_range]] to [0, descriptor.size]."
- // "Set b.[[mapped_ranges]] to []."
- // "Set b.[[state]] to mapped at creation."
+ if (descriptor.mappedAtCreation)
return Buffer::create(buffer, descriptor.size, descriptor.usage, Buffer::State::MappedAtCreation, { static_cast<size_t>(0), static_cast<size_t>(descriptor.size) }, *this);
- }
- // "Set b.[[mapping]] to null." This is unnecessary.
- // "Set b.[[mapping_range]] to null."
- // "Set b.[[mapped_ranges]] to null."
- // "Set b.[[state]] to unmapped."
return Buffer::create(buffer, descriptor.size, descriptor.usage, Buffer::State::Unmapped, { static_cast<size_t>(0), static_cast<size_t>(0) }, *this);
}
@@ -167,13 +140,11 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpubuffer-destroy
- // "If the this.[[state]] is not either of unmapped or destroyed: Run the steps to unmap this."
if (m_state != State::Unmapped && m_state != State::Destroyed) {
// FIXME: ASSERT() that this call doesn't fail.
unmap();
}
- // "Set this.[[state]] to destroyed."
m_state = State::Destroyed;
m_buffer = nil;
@@ -186,29 +157,23 @@
bool Buffer::validateGetMappedRange(size_t offset, size_t rangeSize) const
{
- // "this.[[state]] is mapped or mapped at creation."
if (m_state != State::Mapped && m_state != State::MappedAtCreation)
return false;
- // "offset is a multiple of 8."
if (offset % 8)
return false;
- // "rangeSize is a multiple of 4."
if (rangeSize % 4)
return false;
- // "offset is greater than or equal to this.[[mapping_range]][0]."
if (offset < m_mappingRange.beginOffset)
return false;
- // "offset + rangeSize is less than or equal to this.[[mapping_range]][1]."
// FIXME: Used checked arithmetic.
auto endOffset = offset + rangeSize;
if (endOffset > m_mappingRange.endOffset)
return false;
- // "[offset, offset + rangeSize) does not overlap another range in this.[[mapped_ranges]]."
if (m_mappedRanges.overlaps({ offset, endOffset }))
return false;
@@ -219,25 +184,19 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpubuffer-getmappedrange
- // "If size is missing: Let rangeSize be max(0, this.[[size]] - offset)."
// FIXME: Use checked arithmetic.
auto rangeSize = size;
if (size == WGPU_WHOLE_MAP_SIZE)
rangeSize = static_cast<size_t>(std::max(static_cast<uint64_t>(0), m_size - static_cast<uint64_t>(offset)));
- // "If any of the following conditions are unsatisfied"
if (!validateGetMappedRange(offset, rangeSize)) {
// FIXME: "throw an OperationError and stop."
return nullptr;
}
- // "Let m be a new ArrayBuffer of size rangeSize pointing at the content of this.[[mapping]] at offset offset - this.[[mapping_range]][0]."
-
- // "Append m to this.[[mapped_ranges]]."
m_mappedRanges.add({ offset, offset + rangeSize });
m_mappedRanges.compact();
- // "Return m."
return static_cast<char*>(m_buffer.contents) + offset;
}
@@ -245,33 +204,26 @@
{
// FIXME: "this is a valid GPUBuffer. TODO: check destroyed state?"
- // "offset is a multiple of 8."
if (offset % 8)
return false;
- // "rangeSize is a multiple of 4."
if (rangeSize % 4)
return false;
- // "offset + rangeSize is less or equal to this.[[size]]"
// FIXME: Use checked arithmetic.
if (static_cast<uint64_t>(offset + rangeSize) > m_size)
return false;
- // "this.[[state]] is unmapped"
if (m_state != State::Unmapped)
return false;
- // "mode contains exactly one of READ or WRITE."
auto readWriteModeFlags = mode & (WGPUMapMode_Read | WGPUMapMode_Write);
if (readWriteModeFlags != WGPUMapMode_Read && readWriteModeFlags != WGPUMapMode_Write)
return false;
- // "If mode contains READ then this.[[usage]] must contain MAP_READ."
if ((mode & WGPUMapMode_Read) && !(m_usage & WGPUBufferUsage_MapRead))
return false;
- // "If mode contains WRITE then this.[[usage]] must contain MAP_WRITE."
if ((mode & WGPUMapMode_Write) && !(m_usage & WGPUBufferUsage_MapWrite))
return false;
@@ -282,51 +234,31 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpubuffer-mapasync
- // "If size is missing: Let rangeSize be max(0, this.[[size]] - offset)."
// FIXME: Use checked arithmetic.
auto rangeSize = size;
if (size == WGPU_WHOLE_MAP_SIZE)
rangeSize = static_cast<size_t>(std::max(static_cast<uint64_t>(0), static_cast<uint64_t>(m_size - offset)));
- // "If any of the following conditions are unsatisfied:"
if (!validateMapAsync(mode, offset, rangeSize)) {
- // "Record a validation error on the current scope."
m_device->generateAValidationError("Validation failure."_s);
- // "Return a promise rejected with an OperationError on the Device timeline."
callback(WGPUBufferMapAsyncStatus_Error);
return;
}
- // "Set this.[[mapping]] to p."
-
- // "Set this.[[state]] to mapping pending."
m_state = State::MappingPending;
- // "Set this.[[map_mode]] to mode."
m_mapMode = mode;
- // "Enqueue an operation on the default queue’s Queue timeline that will execute the following:"
m_device->getQueue().onSubmittedWorkDone(0, [protectedThis = Ref { *this }, offset, rangeSize, callback = WTFMove(callback)](WGPUQueueWorkDoneStatus status) mutable {
- // "If this.[[state]] is mapping pending:"
if (protectedThis->m_state == State::MappingPending) {
- // "Let m be a new ArrayBuffer of size rangeSize."
-
- // "Set the content of m to the content of this’s allocation starting at offset offset and for rangeSize bytes."
-
- // "Set this.[[mapping]] to m."
-
- // "Set this.[[state]] to mapped."
protectedThis->m_state = State::Mapped;
- // "Set this.[[mapping_range]] to [offset, offset + rangeSize]."
protectedThis->m_mappingRange = { offset, offset + rangeSize };
- // "Set this.[[mapped_ranges]] to []."
protectedThis->m_mappedRanges = MappedRanges();
}
- // "Resolve p."
switch (status) {
case WGPUQueueWorkDoneStatus_Success:
callback(WGPUBufferMapAsyncStatus_Success);
@@ -350,7 +282,6 @@
bool Buffer::validateUnmap() const
{
- // "this.[[state]] must be mapped at creation, mapping pending, or mapped."
if (m_state != State::MappedAtCreation
&& m_state != State::MappingPending
&& m_state != State::Mapped)
@@ -363,36 +294,15 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpubuffer-unmap
- // "If any of the following requirements are unmet"
if (!validateUnmap()) {
- // "generate a validation error and stop."
m_device->generateAValidationError("Validation failure."_s);
return;
}
- // "If this.[[state]] is mapping pending:"
- if (m_state == State::MappingPending) {
- // FIXME: "Reject [[mapping]] with an AbortError."
+ // FIXME: "If this.[[state]] is mapping pending: Reject [[mapping]] with an AbortError."
- // "Set this.[[mapping]] to null."
- }
+ // FIXME: Handle array buffer detaching.
- // "If this.[[state]] is mapped or mapped at creation:"
- if (m_state == State::Mapped || m_state == State::MappedAtCreation) {
- // "If one of the two following conditions holds:"
- // "this.[[state]] is mapped at creation"
- // "this.[[state]] is mapped and this.[[map_mode]] contains WRITE"
- // "Enqueue an operation on the default queue’s Queue timeline that updates the this.[[mapping_range]] of this’s allocation to the content of this.[[mapping]]."
-
- // "Detach each ArrayBuffer in this.[[mapped_ranges]] from its content."
-
- // "Set this.[[mapping]] to null."
-
- // "Set this.[[mapping_range]] to null."
-
- // "Set this.[[mapped_ranges]] to null."
- }
-
#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
if (m_state == State::MappedAtCreation && m_buffer.storageMode == MTLStorageModeManaged) {
for (const auto& mappedRange : m_mappedRanges)
@@ -400,7 +310,6 @@
}
#endif
- // "Set this.[[state]] to unmapped."
m_state = State::Unmapped;
}
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.mm (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-04-07 19:42:41 UTC (rev 292554)
@@ -98,23 +98,18 @@
// FIXME: "destination is valid to use with this."
- // "source.[[usage]] contains COPY_SRC."
if (!(source.usage() & WGPUBufferUsage_CopySrc))
return false;
- // "destination.[[usage]] contains COPY_DST."
if (!(destination.usage() & WGPUBufferUsage_CopyDst))
return false;
- // "size is a multiple of 4."
if (size % 4)
return false;
- // "sourceOffset is a multiple of 4."
if (sourceOffset % 4)
return false;
- // "destinationOffset is a multiple of 4."
if (destinationOffset % 4)
return false;
@@ -143,13 +138,10 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copybuffertobuffer
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "If any of the following conditions are unsatisfied
if (!validateCopyBufferToBuffer(source, sourceOffset, destination, destinationOffset, size)) {
- // "generate a validation error and stop."
m_device->generateAValidationError("Validation failure."_s);
return;
}
@@ -165,7 +157,6 @@
// FIXME: "imageCopyBuffer.buffer must be a valid GPUBuffer."
- // "imageCopyBuffer.bytesPerRow must be a multiple of 256."
if (imageCopyBuffer.layout.bytesPerRow % 256)
return false;
@@ -189,66 +180,49 @@
static bool validateCopyBufferToTexture(const WGPUImageCopyBuffer& source, const WGPUImageCopyTexture& destination, const WGPUExtent3D& copySize)
{
- // "Let dstTextureDesc be destination.texture.[[descriptor]]."
const auto& dstTextureDesc = fromAPI(destination.texture).descriptor();
- // "validating GPUImageCopyBuffer(source) returns true."
if (!validateImageCopyBuffer(source))
return false;
- // "source.buffer.[[usage]] contains COPY_SRC."
if (!(fromAPI(source.buffer).usage() & WGPUBufferUsage_CopySrc))
return false;
- // "validating GPUImageCopyTexture(destination, copySize) returns true."
if (!Texture::validateImageCopyTexture(destination, copySize))
return false;
- // "dstTextureDesc.usage contains COPY_DST."
if (!(dstTextureDesc.usage & WGPUTextureUsage_CopyDst))
return false;
- // "dstTextureDesc.sampleCount is 1."
if (dstTextureDesc.sampleCount != 1)
return false;
- // "Let aspectSpecificFormat = dstTextureDesc.format."
WGPUTextureFormat aspectSpecificFormat = dstTextureDesc.format;
- // "If dstTextureDesc.format is a depth-or-stencil format:"
if (Texture::isDepthOrStencilFormat(dstTextureDesc.format)) {
- // "destination.aspect must refer to a single aspect of dstTextureDesc.format"
if (!Texture::refersToSingleAspect(dstTextureDesc.format, destination.aspect))
return false;
- // "That aspect must be a valid image copy destination according to § 25.1.2 Depth-stencil formats."
if (!Texture::isValidImageCopyDestination(dstTextureDesc.format, destination.aspect))
return false;
- // "Set aspectSpecificFormat to the aspect-specific format according to § 25.1.2 Depth-stencil formats."
aspectSpecificFormat = Texture::aspectSpecificFormat(dstTextureDesc.format, destination.aspect);
}
- // "validating texture copy range(destination, copySize) return true."
if (!Texture::validateTextureCopyRange(destination, copySize))
return false;
- // "If dstTextureDesc.format is not a depth-or-stencil format:"
if (!Texture::isDepthOrStencilFormat(dstTextureDesc.format)) {
- // "source.offset is a multiple of the texel block size of dstTextureDesc.format."
auto texelBlockSize = Texture::texelBlockSize(dstTextureDesc.format);
if (source.layout.offset % texelBlockSize)
return false;
}
- // "If dstTextureDesc.format is a depth-or-stencil format:"
if (Texture::isDepthOrStencilFormat(dstTextureDesc.format)) {
- // "source.offset is a multiple of 4."
if (source.layout.offset % 4)
return false;
}
- // "validating linear texture data(source, source.buffer.[[size]], aspectSpecificFormat, copySize) succeeds."
if (!Texture::validateLinearTextureData(source.layout, fromAPI(source.buffer).size(), aspectSpecificFormat, copySize))
return false;
@@ -262,13 +236,10 @@
// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copybuffertotexture
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "If any of the following conditions are unsatisfied"
if (!validateCopyBufferToTexture(source, destination, copySize)) {
- // "generate a validation error and stop."
m_device->generateAValidationError("Validation failure."_s);
return;
}
@@ -374,66 +345,49 @@
static bool validateCopyTextureToBuffer(const WGPUImageCopyTexture& source, const WGPUImageCopyBuffer& destination, const WGPUExtent3D& copySize)
{
- // "Let srcTextureDesc be source.texture.[[descriptor]]."
const auto& srcTextureDesc = fromAPI(source.texture).descriptor();
- // "validating GPUImageCopyTexture(source, copySize) returns true."
if (!Texture::validateImageCopyTexture(source, copySize))
return false;
- // "srcTextureDesc.usage contains COPY_SRC."
if (!(srcTextureDesc.usage & WGPUBufferUsage_CopySrc))
return false;
- // "srcTextureDesc.sampleCount is 1."
if (srcTextureDesc.sampleCount != 1)
return false;
- // "Let aspectSpecificFormat = dstTextureDesc.format."
WGPUTextureFormat aspectSpecificFormat = srcTextureDesc.format;
- // "If srcTextureDesc.format is a depth-stencil format:"
if (Texture::isDepthOrStencilFormat(srcTextureDesc.format)) {
- // "source.aspect must refer to a single aspect of srcTextureDesc.format"
if (!Texture::refersToSingleAspect(srcTextureDesc.format, source.aspect))
return false;
- // "and that aspect must be a valid image copy source according to § 25.1.2 Depth-stencil formats."
if (!Texture::isValidImageCopySource(srcTextureDesc.format, source.aspect))
return false;
- // "Set aspectSpecificFormat to the aspect-specific format according to § 25.1.2 Depth-stencil formats."
aspectSpecificFormat = Texture::aspectSpecificFormat(srcTextureDesc.format, source.aspect);
}
- // "validating GPUImageCopyBuffer(destination) returns true."
if (!validateImageCopyBuffer(destination))
return false;
- // "destination.buffer.[[usage]] contains COPY_DST."
if (!(fromAPI(destination.buffer).usage() & WGPUBufferUsage_CopyDst))
return false;
- // "validating texture copy range(source, copySize) returns true."
if (!Texture::validateTextureCopyRange(source, copySize))
return false;
- // "If srcTextureDesc.format is not a depth-or-stencil format:"
if (!Texture::isDepthOrStencilFormat(srcTextureDesc.format)) {
- // "destination.offset is a multiple of the texel block size of srcTextureDesc.format."
auto texelBlockSize = Texture::texelBlockSize(srcTextureDesc.format);
if (destination.layout.offset % texelBlockSize)
return false;
}
- // "If srcTextureDesc.format is a depth-or-stencil format:"
if (Texture::isDepthOrStencilFormat(srcTextureDesc.format)) {
- // "destination.offset is a multiple of 4."
if (destination.layout.offset % 4)
return false;
}
- // "validating linear texture data(destination, destination.buffer.[[size]], aspectSpecificFormat, copySize) succeeds."
if (!Texture::validateLinearTextureData(destination.layout, fromAPI(destination.buffer).size(), aspectSpecificFormat, copySize))
return false;
@@ -447,13 +401,10 @@
// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copytexturetobuffer
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "If any of the following conditions are unsatisfied"
if (!validateCopyTextureToBuffer(source, destination, copySize)) {
- // "generate a validation error and stop."
m_device->generateAValidationError("Validation failure."_s);
return;
}
@@ -561,63 +512,48 @@
{
// https://gpuweb.github.io/gpuweb/#copy-compatible
- // "format1 equals format2"
if (format1 == format2)
return true;
- // "format1 and format2 differ only in whether they are srgb formats (have the -srgb suffix)."
return Texture::removeSRGBSuffix(format1) == Texture::removeSRGBSuffix(format2);
}
static bool validateCopyTextureToTexture(const WGPUImageCopyTexture& source, const WGPUImageCopyTexture& destination, const WGPUExtent3D& copySize)
{
- // "Let srcTextureDesc be source.texture.[[descriptor]]."
const auto& srcTextureDesc = fromAPI(source.texture).descriptor();
- // "Let dstTextureDesc be destination.texture.[[descriptor]]."
const auto& dstTextureDesc = fromAPI(destination.texture).descriptor();
- // "validating GPUImageCopyTexture(source, copySize) returns true."
if (!Texture::validateImageCopyTexture(source, copySize))
return false;
- // "srcTextureDesc.usage contains COPY_SRC."
if (!(srcTextureDesc.usage & WGPUTextureUsage_CopySrc))
return false;
- // "validating GPUImageCopyTexture(destination, copySize) returns true."
if (!Texture::validateImageCopyTexture(destination, copySize))
return false;
- // "dstTextureDesc.usage contains COPY_DST."
if (!(dstTextureDesc.usage & WGPUTextureUsage_CopyDst))
return false;
- // "srcTextureDesc.sampleCount is equal to dstTextureDesc.sampleCount."
if (srcTextureDesc.sampleCount != dstTextureDesc.sampleCount)
return false;
- // "srcTextureDesc.format and dstTextureDesc.format must be copy-compatible."
if (!areCopyCompatible(srcTextureDesc.format, dstTextureDesc.format))
return false;
- // "If srcTextureDesc.format is a depth-stencil format:"
if (Texture::isDepthOrStencilFormat(srcTextureDesc.format)) {
- // "source.aspect and destination.aspect must both refer to all aspects of srcTextureDesc.format and dstTextureDesc.format, respectively."
if (!refersToAllAspects(srcTextureDesc.format, source.aspect)
|| !refersToAllAspects(dstTextureDesc.format, destination.aspect))
return false;
}
- // "validating texture copy range(source, copySize) returns true."
if (!Texture::validateTextureCopyRange(source, copySize))
return false;
- // "validating texture copy range(destination, copySize) returns true."
if (!Texture::validateTextureCopyRange(destination, copySize))
return false;
- // "The set of subresources for texture copy(source, copySize) and the set of subresources for texture copy(destination, copySize) is disjoint."
// https://gpuweb.github.io/gpuweb/#abstract-opdef-set-of-subresources-for-texture-copy
if (source.texture == destination.texture) {
// Mip levels are never ranges.
@@ -624,11 +560,8 @@
if (source.mipLevel == destination.mipLevel) {
switch (fromAPI(source.texture).descriptor().dimension) {
case WGPUTextureDimension_1D:
- // "The subresource of imageCopyTexture.texture at mipmap level imageCopyTexture.mipLevel."
return false;
case WGPUTextureDimension_2D: {
- // "For each arrayLayer of the copySize.depthOrArrayLayers array layers starting at imageCopyTexture.origin.z:"
- // "The subresource of imageCopyTexture.texture at mipmap level imageCopyTexture.mipLevel and array layer arrayLayer."
Range<uint32_t> sourceRange(source.origin.z, source.origin.z + copySize.depthOrArrayLayers);
Range<uint32_t> destinationRange(destination.origin.z, source.origin.z + copySize.depthOrArrayLayers);
if (sourceRange.overlaps(destinationRange))
@@ -636,7 +569,6 @@
break;
}
case WGPUTextureDimension_3D:
- // "The subresource of imageCopyTexture.texture at mipmap level imageCopyTexture.mipLevel."
return false;
case WGPUTextureDimension_Force32:
ASSERT_NOT_REACHED();
@@ -655,13 +587,10 @@
// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copytexturetotexture
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "If any of the following conditions are unsatisfied"
if (!validateCopyTextureToTexture(source, destination, copySize)) {
- // "generate a validation error and stop."
m_device->generateAValidationError("Validation failure."_s);
return;
}
@@ -744,19 +673,15 @@
{
// FIXME: "buffer is valid to use with this."
- // "buffer.[[usage]] contains COPY_DST."
if (!(buffer.usage() & WGPUBufferUsage_CopyDst))
return false;
- // "size is a multiple of 4."
if (size % 4)
return false;
- // "offset is a multiple of 4."
if (offset % 4)
return false;
- // "buffer.[[size]] is greater than or equal to (offset + size)."
// FIXME: Use checked arithmetic.
if (buffer.size() < offset + size)
return false;
@@ -768,19 +693,15 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-clearbuffer
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "If size is missing, set size to max(0, |buffer|.{{GPUBuffer/[[size]]}} - |offset|)."
if (size == WGPU_WHOLE_SIZE) {
// FIXME: Use checked arithmetic.
size = buffer.size() - offset;
}
- // "If any of the following conditions are unsatisfied"
if (!validateClearBuffer(buffer, offset, size)) {
- // "generate a validation error and stop."
m_device->generateAValidationError("Validation failure."_s);
return;
}
@@ -792,11 +713,8 @@
bool CommandEncoder::validateFinish() const
{
- // "Let validationSucceeded be true if all of the following requirements are met, and false otherwise."
-
// FIXME: "this must be valid."
- // "this.[[state]] must be "open"."
if (m_state != EncoderState::Open)
return false;
@@ -814,15 +732,11 @@
// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-finish
- // "Let validationSucceeded be true if all of the following requirements are met, and false otherwise."
auto validationFailed = !validateFinish();
- // "Set this.[[state]] to "ended"."
m_state = EncoderState::Ended;
- // "If validationSucceeded is false, then:"
if (validationFailed) {
- // "Generate a validation error."
m_device->generateAValidationError("Validation failure."_s);
// FIXME: "Return a new invalid GPUCommandBuffer."
@@ -831,7 +745,6 @@
finalizeBlitCommandEncoder();
- // "Set commandBuffer.[[command_list]] to this.[[commands]]."
auto *commandBuffer = m_commandBuffer;
m_commandBuffer = nil;
@@ -844,7 +757,6 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-insertdebugmarker
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
@@ -857,7 +769,6 @@
bool CommandEncoder::validatePopDebugGroup() const
{
- // "this.[[debug_group_stack]] must not be empty."
if (!m_debugGroupStackSize)
return false;
@@ -868,11 +779,9 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-popdebuggroup
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "If any of the following requirements are unmet"
if (!validatePopDebugGroup()) {
// FIXME: "make this invalid, and stop."
return;
@@ -880,7 +789,6 @@
finalizeBlitCommandEncoder();
- // "Pop an entry off of this.[[debug_group_stack]]."
--m_debugGroupStackSize;
[m_commandBuffer popDebugGroup];
}
@@ -889,13 +797,11 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-pushdebuggroup
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
finalizeBlitCommandEncoder();
- // "Push groupLabel onto this.[[debug_group_stack]]."
++m_debugGroupStackSize;
[m_commandBuffer pushDebugGroup:groupLabel];
}
Modified: trunk/Source/WebGPU/WebGPU/ComputePassEncoder.mm (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/ComputePassEncoder.mm 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/ComputePassEncoder.mm 2022-04-07 19:42:41 UTC (rev 292554)
@@ -72,7 +72,6 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-insertdebugmarker
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
@@ -81,7 +80,6 @@
bool ComputePassEncoder::validatePopDebugGroup() const
{
- // "this.[[debug_group_stack]] must not be empty."
if (!m_debugGroupStackSize)
return false;
@@ -92,17 +90,14 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-popdebuggroup
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "If any of the following requirements are unmet"
if (!validatePopDebugGroup()) {
// FIXME: "make this invalid, and stop."
return;
}
- // "Pop an entry off of this.[[debug_group_stack]]."
--m_debugGroupStackSize;
[m_computeCommandEncoder popDebugGroup];
}
@@ -111,11 +106,9 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-pushdebuggroup
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "Push groupLabel onto this.[[debug_group_stack]]."
++m_debugGroupStackSize;
[m_computeCommandEncoder pushDebugGroup:groupLabel];
}
Modified: trunk/Source/WebGPU/WebGPU/Device.h (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/Device.h 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/Device.h 2022-04-07 19:42:41 UTC (rev 292554)
@@ -110,8 +110,8 @@
String message;
};
struct ErrorScope {
- std::optional<Error> error; // "The first GPUError, if any, observed while the GPU error scope was current."
- const WGPUErrorFilter filter; // Determines what type of GPUError this GPU error scope observes.
+ std::optional<Error> error;
+ const WGPUErrorFilter filter;
};
const id<MTLDevice> m_device { nil };
@@ -119,7 +119,7 @@
const Ref<Instance> m_instance;
Function<void(WGPUErrorType, String&&)> m_uncapturedErrorCallback;
- Vector<ErrorScope> m_errorScopeStack; // "A stack of GPU error scopes that have been pushed to the GPUDevice."
+ Vector<ErrorScope> m_errorScopeStack;
};
} // namespace WebGPU
Modified: trunk/Source/WebGPU/WebGPU/Device.mm (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/Device.mm 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/Device.mm 2022-04-07 19:42:41 UTC (rev 292554)
@@ -106,15 +106,10 @@
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-current-error-scope
- // "Let scope be the last item of device.[[errorScopeStack]]."
- // "While scope is not undefined:"
for (auto iterator = m_errorScopeStack.rbegin(); iterator != m_errorScopeStack.rend(); ++iterator) {
- // "If scope.[[filter]] is type, return scope."
if (iterator->filter == type)
return &*iterator;
- // "Set scope to the previous item of device.[[errorScopeStack]]."
}
- // "Return undefined."
return nullptr;
}
@@ -122,20 +117,14 @@
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-generate-a-validation-error
- // "Let scope be the current error scope for error and device."
auto* scope = currentErrorScope(WGPUErrorFilter_Validation);
- // "If scope is not undefined:"
if (scope) {
- // "If scope.[[error]] is null, set scope.[[error]] to error."
if (!scope->error)
scope->error = Error { WGPUErrorType_Validation, WTFMove(message) };
- // "Stop."
return;
}
- // "Otherwise issue the following steps to the Content timeline:"
- // "If the user agent chooses, queue a task to fire a GPUUncapturedErrorEvent named "uncapturederror" on device with an error of error."
if (m_uncapturedErrorCallback) {
m_instance->scheduleWork([protectedThis = Ref { *this }, message = WTFMove(message)]() mutable {
protectedThis->m_uncapturedErrorCallback(WGPUErrorType_Validation, WTFMove(message));
@@ -147,7 +136,6 @@
{
// FIXME: "this must not be lost."
- // "this.[[errorScopeStack]].size > 0."
if (m_errorScopeStack.isEmpty())
return false;
@@ -158,17 +146,13 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudevice-poperrorscope
- // "If any of the following requirements are unmet"
if (!validatePopErrorScope()) {
- // "reject promise with an OperationError and stop."
callback(WGPUErrorType_Unknown, "popErrorScope() failed validation."_s);
return false;
}
- // "Let scope be the result of popping an item off of this.[[errorScopeStack]]."
auto scope = m_errorScopeStack.takeLast();
- // "Resolve promise with scope.[[error]]."
m_instance->scheduleWork([scope = WTFMove(scope), callback = WTFMove(callback)]() mutable {
if (scope.error)
callback(scope.error->type, WTFMove(scope.error->message));
@@ -184,11 +168,8 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudevice-pusherrorscope
- // "Let scope be a new GPU error scope."
- // "Set scope.[[filter]] to filter."
ErrorScope scope { std::nullopt, filter };
- // "Push scope onto this.[[errorScopeStack]]."
m_errorScopeStack.append(WTFMove(scope));
}
Modified: trunk/Source/WebGPU/WebGPU/Queue.mm (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/Queue.mm 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/Queue.mm 2022-04-07 19:42:41 UTC (rev 292554)
@@ -129,9 +129,7 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpuqueue-submit
- // "If any of the following conditions are unsatisfied"
if (!validateSubmit()) {
- // "generate a validation error and stop."
m_device.generateAValidationError("Validation failure."_s);
return;
}
@@ -138,20 +136,12 @@
finalizeBlitCommandEncoder();
- // "For each commandBuffer in commandBuffers:"
- for (auto commandBuffer : commands) {
- // "Execute each command in commandBuffer.[[command_list]]."
+ for (auto commandBuffer : commands)
commitMTLCommandBuffer(commandBuffer.get().commandBuffer());
- }
}
static bool validateWriteBufferInitial(size_t size)
{
- // "contentsSize ≥ 0."
-
- // "dataOffset + contentsSize ≤ dataSize."
-
- // "contentsSize, converted to bytes, is a multiple of 4 bytes."
if (size % 4)
return false;
@@ -162,19 +152,15 @@
{
// FIXME: "buffer is valid to use with this."
- // "buffer.[[state]] is unmapped."
if (buffer.state() != Buffer::State::Unmapped)
return false;
- // "buffer.[[usage]] includes COPY_DST."
if (!(buffer.usage() & WGPUBufferUsage_CopyDst))
return false;
- // "bufferOffset, converted to bytes, is a multiple of 4 bytes."
if (bufferOffset % 4)
return false;
- // "bufferOffset + contentsSize, converted to bytes, ≤ buffer.[[size]] bytes."
// FIXME: Use checked arithmetic
if (bufferOffset + size > buffer.size())
return false;
@@ -186,30 +172,16 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpuqueue-writebuffer
- // "If data is an ArrayBuffer or DataView, let the element type be "byte". Otherwise, data is a TypedArray; let the element type be the type of the TypedArray."
-
- // "Let dataSize be the size of data, in elements."
-
- // "If size is missing, let contentsSize be dataSize − dataOffset. Otherwise, let contentsSize be size."
-
- // "If any of the following conditions are unsatisfied"
if (!validateWriteBufferInitial(size)) {
// FIXME: "throw OperationError and stop."
return;
}
- // "Let dataContents be a copy of the bytes held by the buffer source."
-
- // "Let contents be the contentsSize elements of dataContents starting at an offset of dataOffset elements."
-
- // "If any of the following conditions are unsatisfied"
if (!validateWriteBuffer(buffer, bufferOffset, size)) {
- // "generate a validation error and stop."
m_device.generateAValidationError("Validation failure."_s);
return;
}
- // "Write contents into buffer starting at bufferOffset."
if (!size)
return;
@@ -251,40 +223,29 @@
static bool validateWriteTexture(const WGPUImageCopyTexture& destination, const WGPUTextureDataLayout& dataLayout, const WGPUExtent3D& size, size_t dataByteSize, const WGPUTextureDescriptor& textureDesc)
{
- // "validating GPUImageCopyTexture(destination, size) returns true."
if (!Texture::validateImageCopyTexture(destination, size))
return false;
- // "textureDesc.usage includes COPY_DST."
if (!(textureDesc.usage & WGPUTextureUsage_CopyDst))
return false;
- // "textureDesc.sampleCount is 1."
if (textureDesc.sampleCount != 1)
return false;
- // "validating texture copy range(destination, size) return true."
if (!Texture::validateTextureCopyRange(destination, size))
return false;
- // "destination.aspect must refer to a single aspect of textureDesc.format."
if (!Texture::refersToSingleAspect(textureDesc.format, destination.aspect))
return false;
- // "That aspect must be a valid image copy destination according to § 25.1.2 Depth-stencil formats."
if (!Texture::isValidImageCopyDestination(textureDesc.format, destination.aspect))
return false;
- // "Let aspectSpecificFormat = textureDesc.format."
auto aspectSpecificFormat = textureDesc.format;
- // "If textureDesc.format is a depth-or-stencil format:"
- if (Texture::isDepthOrStencilFormat(textureDesc.format)) {
- // "Set aspectSpecificFormat to the aspect-specific format of textureDesc.format according to § 25.1.2 Depth-stencil formats."
+ if (Texture::isDepthOrStencilFormat(textureDesc.format))
aspectSpecificFormat = Texture::aspectSpecificFormat(textureDesc.format, destination.aspect);
- }
- // "validating linear texture data(dataLayout, dataByteSize, aspectSpecificFormat, size) succeeds."
if (!Texture::validateLinearTextureData(dataLayout, dataByteSize, aspectSpecificFormat, size))
return false;
@@ -298,23 +259,15 @@
// https://gpuweb.github.io/gpuweb/#dom-gpuqueue-writetexture
- // "Let dataBytes be a copy of the bytes held by the buffer source data."
- // "Let dataByteSize be the number of bytes in dataBytes."
auto dataByteSize = dataSize;
- // "Let textureDesc be destination.texture.[[descriptor]]."
const auto& textureDesc = fromAPI(destination.texture).descriptor();
- // "Let contents be the contents of the images seen by viewing dataBytes with dataLayout and size."
-
- // "If any of the following conditions are unsatisfied"
if (!validateWriteTexture(destination, dataLayout, size, dataByteSize, textureDesc)) {
- // "generate a validation error and stop."
m_device.generateAValidationError("Validation failure."_s);
return;
}
- // "Write contents into destination."
if (!dataSize)
return;
Modified: trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm 2022-04-07 19:42:41 UTC (rev 292554)
@@ -87,7 +87,6 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-insertdebugmarker
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
@@ -96,7 +95,6 @@
bool RenderBundleEncoder::validatePopDebugGroup() const
{
- // "this.[[debug_group_stack]] must not be empty."
if (!m_debugGroupStackSize)
return false;
@@ -107,17 +105,14 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-popdebuggroup
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "If any of the following requirements are unmet"
if (!validatePopDebugGroup()) {
// FIXME: "make this invalid, and stop."
return;
}
- // "Pop an entry off of this.[[debug_group_stack]]."
--m_debugGroupStackSize;
// MTLIndirectCommandBuffers don't support debug commands.
}
@@ -126,11 +121,9 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-pushdebuggroup
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "Push groupLabel onto this.[[debug_group_stack]]."
++m_debugGroupStackSize;
// MTLIndirectCommandBuffers don't support debug commands.
}
Modified: trunk/Source/WebGPU/WebGPU/RenderPassEncoder.mm (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/RenderPassEncoder.mm 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/RenderPassEncoder.mm 2022-04-07 19:42:41 UTC (rev 292554)
@@ -106,7 +106,6 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-insertdebugmarker
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
@@ -115,7 +114,6 @@
bool RenderPassEncoder::validatePopDebugGroup() const
{
- // "this.[[debug_group_stack]] must not be empty."
if (!m_debugGroupStackSize)
return false;
@@ -126,17 +124,14 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-popdebuggroup
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "If any of the following requirements are unmet"
if (!validatePopDebugGroup()) {
// FIXME: "make this invalid, and stop."
return;
}
- // "Pop an entry off of this.[[debug_group_stack]]."
--m_debugGroupStackSize;
[m_renderCommandEncoder popDebugGroup];
}
@@ -145,11 +140,9 @@
{
// https://gpuweb.github.io/gpuweb/#dom-gpudebugcommandsmixin-pushdebuggroup
- // "Prepare the encoder state of this. If it returns false, stop."
if (!prepareTheEncoderState())
return;
- // "Push groupLabel onto this.[[debug_group_stack]]."
++m_debugGroupStackSize;
[m_renderCommandEncoder pushDebugGroup:groupLabel];
}
Modified: trunk/Source/WebGPU/WebGPU/Sampler.h (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/Sampler.h 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/Sampler.h 2022-04-07 19:42:41 UTC (rev 292554)
@@ -50,9 +50,7 @@
id<MTLSamplerState> samplerState() const { return m_samplerState; }
const WGPUSamplerDescriptor& descriptor() const { return m_descriptor; }
- // "Set s.[[isComparison]] to false if the compare attribute of s.[[descriptor]] is null or undefined. Otherwise, set it to true."
bool isComparison() const { return descriptor().compare != WGPUCompareFunction_Undefined; }
- // "Set s.[[isFiltering]] to false if none of minFilter, magFilter, or mipmapFilter has the value of "linear". Otherwise, set it to true."
bool isFiltering() const { return descriptor().minFilter == WGPUFilterMode_Linear || descriptor().magFilter == WGPUFilterMode_Linear || descriptor().mipmapFilter == WGPUFilterMode_Linear; }
private:
@@ -60,9 +58,7 @@
const id<MTLSamplerState> m_samplerState { nil };
- const WGPUSamplerDescriptor m_descriptor { }; // "The GPUSamplerDescriptor with which the GPUSampler was created."
- // "[[isComparison]] of type boolean." This is unnecessary; it's implemented in isComparison().
- // "[[isFiltering]] of type boolean." This is unnecessary; it's implemented in isFiltering().
+ const WGPUSamplerDescriptor m_descriptor { };
const Ref<Device> m_device;
};
Modified: trunk/Source/WebGPU/WebGPU/Sampler.mm (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/Sampler.mm 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/Sampler.mm 2022-04-07 19:42:41 UTC (rev 292554)
@@ -38,21 +38,16 @@
// FIXME: "device is valid."
- // "descriptor.lodMinClamp is greater than or equal to 0."
if (std::isnan(descriptor.lodMinClamp) || descriptor.lodMinClamp < 0)
return false;
- // "descriptor.lodMaxClamp is greater than or equal to descriptor.lodMinClamp."
if (std::isnan(descriptor.lodMaxClamp) || descriptor.lodMaxClamp < descriptor.lodMinClamp)
return false;
- // "descriptor.maxAnisotropy is greater than or equal to 1."
if (descriptor.maxAnisotropy < 1)
return false;
- // "When descriptor.maxAnisotropy is greater than 1"
if (descriptor.maxAnisotropy > 1) {
- // "descriptor.magFilter, descriptor.minFilter, and descriptor.mipmapFilter must be equal to "linear"."
if (descriptor.magFilter != WGPUFilterMode_Linear
|| descriptor.minFilter != WGPUFilterMode_Linear
|| descriptor.mipmapFilter != WGPUFilterMode_Linear)
@@ -136,12 +131,9 @@
// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createsampler
- // "If validating GPUSamplerDescriptor(this, descriptor) returns false:"
if (!validateCreateSampler(*this, descriptor)) {
- // "Generate a validation error."
generateAValidationError("Validation failure."_s);
- // "Create a new invalid GPUSampler and return the result."
return nullptr;
}
@@ -157,7 +149,6 @@
samplerDescriptor.lodMaxClamp = descriptor.lodMaxClamp;
samplerDescriptor.compareFunction = compareFunction(descriptor.compare);
- // "The used value of maxAnisotropy will be clamped to the maximum value that the platform supports."
// https://developer.apple.com/documentation/metal/mtlsamplerdescriptor/1516164-maxanisotropy?language=objc
// "Values must be between 1 and 16, inclusive."
samplerDescriptor.maxAnisotropy = std::min<uint16_t>(descriptor.maxAnisotropy, 16);
@@ -168,12 +159,6 @@
if (!samplerState)
return nullptr;
- // "Let s be a new GPUSampler object."
- // "Set s.[[descriptor]] to descriptor."
- // "Set s.[[isComparison]] to false if the compare attribute of s.[[descriptor]] is null or undefined. Otherwise, set it to true."
- // "Set s.[[isFiltering]] to false if none of minFilter, magFilter, or mipmapFilter has the value of "linear". Otherwise, set it to true."
- // "Return s."
-
return Sampler::create(samplerState, descriptor, *this);
}
Modified: trunk/Source/WebGPU/WebGPU/Texture.h (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/Texture.h 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/Texture.h 2022-04-07 19:42:41 UTC (rev 292554)
@@ -85,7 +85,7 @@
const id<MTLTexture> m_texture { nil };
- const WGPUTextureDescriptor m_descriptor { }; // "The GPUTextureDescriptor describing this texture."
+ const WGPUTextureDescriptor m_descriptor { };
const Vector<WGPUTextureFormat> m_viewFormats;
const Ref<Device> m_device;
Modified: trunk/Source/WebGPU/WebGPU/Texture.mm (292553 => 292554)
--- trunk/Source/WebGPU/WebGPU/Texture.mm 2022-04-07 19:40:12 UTC (rev 292553)
+++ trunk/Source/WebGPU/WebGPU/Texture.mm 2022-04-07 19:42:41 UTC (rev 292554)
@@ -147,7 +147,6 @@
static bool isCompressedFormat(WGPUTextureFormat format)
{
// https://gpuweb.github.io/gpuweb/#packed-formats
- // "A compressed format is any format with a block size greater than 1 × 1."
switch (format) {
case WGPUTextureFormat_BC1RGBAUnorm:
case WGPUTextureFormat_BC1RGBAUnormSrgb:
@@ -495,7 +494,6 @@
bool Texture::isDepthOrStencilFormat(WGPUTextureFormat format)
{
// https://gpuweb.github.io/gpuweb/#depth-formats
- // "A depth-or-stencil format is any format with depth and/or stencil aspects."
return containsDepthAspect(format) || containsStencilAspect(format);
}
@@ -563,7 +561,6 @@
case WGPUTextureFormat_ASTC12x12Unorm:
case WGPUTextureFormat_ASTC12x12UnormSrgb:
return 12;
- // "For pixel-based GPUTextureFormats, the texel block width and texel block height are always 1."
case WGPUTextureFormat_R8Unorm:
case WGPUTextureFormat_R8Snorm:
case WGPUTextureFormat_R8Uint:
@@ -684,7 +681,6 @@
case WGPUTextureFormat_ASTC12x12Unorm:
case WGPUTextureFormat_ASTC12x12UnormSrgb:
return 12;
- // "For pixel-based GPUTextureFormats, the texel block width and texel block height are always 1."
case WGPUTextureFormat_R8Unorm:
case WGPUTextureFormat_R8Snorm:
case WGPUTextureFormat_R8Uint:
@@ -739,8 +735,6 @@
static bool isRenderableFormat(WGPUTextureFormat format)
{
// https://gpuweb.github.io/gpuweb/#renderable-format
- // "If a format is listed in § 25.1.1 Plain color formats with RENDER_ATTACHMENT capability, it is a color renderable format. Any other format is not a color renderable format. All depth-or-stencil formats are renderable."
- // https://gpuweb.github.io/gpuweb/#plain-color-formats
switch (format) {
case WGPUTextureFormat_R8Unorm:
case WGPUTextureFormat_R8Uint:
@@ -879,7 +873,6 @@
case WGPUTextureFormat_RGBA16Sint:
case WGPUTextureFormat_RGBA16Float:
// https://gpuweb.github.io/gpuweb/#depth-formats
- // "All of these formats support multisampling."
case WGPUTextureFormat_Stencil8:
case WGPUTextureFormat_Depth16Unorm:
case WGPUTextureFormat_Depth24Plus:
@@ -960,20 +953,15 @@
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-maximum-miplevel-count
- // "Calculate the max dimension value m:"
uint32_t m = 0;
- // "If dimension is:"
switch (dimension) {
case WGPUTextureDimension_1D:
- // "Return 1."
return 1;
case WGPUTextureDimension_2D:
- // "Let m = max(size.width, size.height)."
m = std::max(size.width, size.height);
break;
case WGPUTextureDimension_3D:
- // "Let m = max(max(size.width, size.height), size.depthOrArrayLayer)."
m = std::max(std::max(size.width, size.height), size.depthOrArrayLayers);
break;
case WGPUTextureDimension_Force32:
@@ -981,7 +969,6 @@
return 0;
}
- // "Return floor(log2(m)) + 1."
auto isPowerOf2 = !(m & (m - 1));
if (isPowerOf2)
return WTF::fastLog2(m) + 1;
@@ -1243,40 +1230,31 @@
{
// FIXME: "this must be a valid GPUDevice."
- // "descriptor.usage must not be 0."
if (!descriptor.usage)
return false;
- // "descriptor.size.width, descriptor.size.height, and descriptor.size.depthOrArrayLayers must be greater than zero."
if (!descriptor.size.width || !descriptor.size.height || !descriptor.size.depthOrArrayLayers)
return false;
- // "descriptor.mipLevelCount must be greater than zero."
if (!descriptor.mipLevelCount)
return false;
- // "descriptor.sampleCount must be either 1 or 4."
if (descriptor.sampleCount != 1 && descriptor.sampleCount != 4)
return false;
- // "If descriptor.dimension is:"
switch (descriptor.dimension) {
case WGPUTextureDimension_1D:
// FIXME: "descriptor.size.width must be less than or equal to this.limits.maxTextureDimension1D."
- // "descriptor.size.height must be 1."
if (descriptor.size.height != 1)
return false;
- // "descriptor.size.depthOrArrayLayers must be 1."
if (descriptor.size.depthOrArrayLayers != 1)
return false;
- // "descriptor.sampleCount must be 1."
if (descriptor.sampleCount != 1)
return false;
- // "descriptor.format must not be a compressed format or depth-or-stencil format."
if (isCompressedFormat(descriptor.format) || Texture::isDepthOrStencilFormat(descriptor.format))
return false;
break;
@@ -1294,11 +1272,9 @@
// FIXME: "descriptor.size.depthOrArrayLayers must be less than or equal to this.limits.maxTextureDimension3D."
- // "descriptor.sampleCount must be 1."
if (descriptor.sampleCount != 1)
return false;
- // "descriptor.format must not be a compressed format or depth-or-stencil format."
if (isCompressedFormat(descriptor.format) || Texture::isDepthOrStencilFormat(descriptor.format))
return false;
break;
@@ -1307,64 +1283,46 @@
return false;
}
- // "descriptor.size.width must be multiple of texel block width."
if (descriptor.size.width % Texture::texelBlockWidth(descriptor.format))
return false;
- // "descriptor.size.height must be multiple of texel block height."
if (descriptor.size.height % Texture::texelBlockHeight(descriptor.format))
return false;
- // "If descriptor.sampleCount > 1:"
if (descriptor.sampleCount > 1) {
- // "descriptor.mipLevelCount must be 1."
if (descriptor.mipLevelCount != 1)
return false;
- // "descriptor.size.depthOrArrayLayers must be 1."
if (descriptor.size.depthOrArrayLayers != 1)
return false;
- // "descriptor.usage must not include the STORAGE_BINDING bit."
if (descriptor.usage & WGPUTextureUsage_StorageBinding)
return false;
- // "descriptor.format must be a renderable format"
if (!isRenderableFormat(descriptor.format))
return false;
- // "and support multisampling according to § 25.1 Texture Format Capabilities."
if (!supportsMultisampling(descriptor.format))
return false;
}
- // "descriptor.mipLevelCount must be less than or equal to maximum mipLevel count(descriptor.dimension, descriptor.size)."
if (descriptor.mipLevelCount > maximumMiplevelCount(descriptor.dimension, descriptor.size))
return false;
- // "descriptor.usage must be a combination of GPUTextureUsage values."
-
- // "If descriptor.usage includes the RENDER_ATTACHMENT bit:"
if (descriptor.usage & WGPUTextureUsage_RenderAttachment) {
- // "descriptor.format must be a renderable format."
if (!isRenderableFormat(descriptor.format))
return false;
- // "descriptor.dimension must be "2d"."
if (descriptor.dimension != WGPUTextureDimension_2D)
return false;
}
- // "If descriptor.usage includes the STORAGE_BINDING bit:"
if (descriptor.usage & WGPUTextureUsage_StorageBinding) {
- // "descriptor.format must be listed in § 25.1.1 Plain color formats table with STORAGE_BINDING capability."
if (!hasStorageBindingCapability(descriptor.format))
return false;
}
- // "For each viewFormat in descriptor.viewFormats"
for (auto viewFormat : viewFormats) {
- // "descriptor.format and viewFormat must be texture view format compatible."
if (!textureViewFormatCompatible(descriptor.format, viewFormat))
return false;
}
@@ -2020,15 +1978,12 @@
// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createtexture
- // "If descriptor.format is a GPUTextureFormat that requires a feature (see § 25.1 Texture Format Capabilities)
if (featureRequirementForFormat(descriptor.format)) {
// FIXME: "but this.[[device]].[[features]] does not contain the feature, throw a TypeError."
return nullptr;
}
- // "If any of the following requirements are unmet:"
if (!validateCreateTexture(descriptor, viewFormats)) {
- // "Generate a validation error."
generateAValidationError("Validation failure."_s);
// FIXME: "Return a new invalid GPUTexture."
return nullptr;
@@ -2095,10 +2050,6 @@
texture.label = fromAPI(descriptor.label);
- // "Let t be a new GPUTexture object."
- // "Set t.[[descriptor]] to descriptor."
- // "Return t."
-
return Texture::create(texture, descriptor, WTFMove(viewFormats), *this);
}
@@ -2116,36 +2067,25 @@
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-resolving-gputextureviewdescriptor-defaults
- // "Let resolved be a copy of descriptor."
WGPUTextureViewDescriptor resolved = descriptor;
- // "If resolved.format is undefined"
- if (resolved.format == WGPUTextureFormat_Undefined) {
- // "set resolved.format to texture.[[descriptor]].format."
+ if (resolved.format == WGPUTextureFormat_Undefined)
resolved.format = m_descriptor.format;
- }
- // "If resolved.mipLevelCount is undefined"
if (resolved.mipLevelCount == WGPU_MIP_LEVEL_COUNT_UNDEFINED) {
- // "set resolved.mipLevelCount to texture.[[descriptor]].mipLevelCount − resolved.baseMipLevel."
// FIXME: Use checked arithmetic.
resolved.mipLevelCount = m_descriptor.mipLevelCount - resolved.baseMipLevel;
}
- // "If resolved.dimension is undefined"
if (resolved.dimension == WGPUTextureViewDimension_Undefined) {
- // "and texture.[[descriptor]].dimension is:"
switch (m_descriptor.dimension) {
case WGPUTextureDimension_1D:
- // "Set resolved.dimension to "1d"."
resolved.dimension = WGPUTextureViewDimension_1D;
break;
case WGPUTextureDimension_2D:
- // "Set resolved.dimension to "2d"."
resolved.dimension = WGPUTextureViewDimension_2D;
break;
case WGPUTextureDimension_3D:
- // "Set resolved.dimension to "3d"."
resolved.dimension = WGPUTextureViewDimension_3D;
break;
case WGPUTextureDimension_Force32:
@@ -2154,26 +2094,20 @@
}
}
- // "If resolved.arrayLayerCount is undefined"
if (resolved.arrayLayerCount == WGPU_ARRAY_LAYER_COUNT_UNDEFINED) {
- // "and resolved.dimension is:"
switch (resolved.dimension) {
case WGPUTextureViewDimension_Undefined:
- ASSERT_NOT_REACHED();
return resolved;
case WGPUTextureViewDimension_1D:
case WGPUTextureViewDimension_2D:
case WGPUTextureViewDimension_3D:
- // "Set resolved.arrayLayerCount to 1."
resolved.arrayLayerCount = 1;
break;
case WGPUTextureViewDimension_Cube:
- // "Set resolved.arrayLayerCount to 6."
resolved.arrayLayerCount = 6;
break;
case WGPUTextureViewDimension_2DArray:
case WGPUTextureViewDimension_CubeArray:
- // "Set resolved.arrayLayerCount to texture.[[descriptor]].size.depthOrArrayLayers − baseArrayLayer."
// FIXME: Use checked arithmetic
resolved.arrayLayerCount = m_descriptor.size.depthOrArrayLayers - resolved.baseArrayLayer;
break;
@@ -2183,7 +2117,6 @@
}
}
- // "Return resolved."
return resolved;
}
@@ -2191,16 +2124,12 @@
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-array-layer-count
- // "If texture.[[descriptor]].dimension is:"
switch (m_descriptor.dimension) {
case WGPUTextureDimension_1D:
- // "Return 1."
return 1;
case WGPUTextureDimension_2D:
- // "Return texture.[[descriptor]].size.depthOrArrayLayers."
return m_descriptor.size.depthOrArrayLayers;
case WGPUTextureDimension_3D:
- // "Return 1."
return 1;
case WGPUTextureDimension_Force32:
ASSERT_NOT_REACHED();
@@ -2212,17 +2141,14 @@
{
// FIXME: "this is valid"
- // "If the descriptor.aspect is"
switch (descriptor.aspect) {
case WGPUTextureAspect_All:
break;
case WGPUTextureAspect_StencilOnly:
- // "this.[[descriptor]].format must be a depth-or-stencil format which has a stencil aspect."
if (!containsStencilAspect(m_descriptor.format))
return false;
break;
case WGPUTextureAspect_DepthOnly:
- // "this.[[descriptor]].format must be a depth-or-stencil format which has a depth aspect."
if (!containsDepthAspect(m_descriptor.format))
return false;
break;
@@ -2231,20 +2157,16 @@
return false;
}
- // "descriptor.mipLevelCount must be > 0."
if (!descriptor.mipLevelCount)
return false;
- // "descriptor.baseMipLevel + descriptor.mipLevelCount must be ≤ this.[[descriptor]].mipLevelCount."
// FIXME: Use checked arithmetic.
if (descriptor.baseMipLevel + descriptor.mipLevelCount > m_descriptor.mipLevelCount)
return false;
- // "descriptor.arrayLayerCount must be > 0."
if (!descriptor.arrayLayerCount)
return false;
- // "descriptor.baseArrayLayer + descriptor.arrayLayerCount must be ≤ the array layer count of this."
// FIXME: Use checked arithmetic.
if (descriptor.baseArrayLayer + descriptor.arrayLayerCount > arrayLayerCount())
return false;
@@ -2253,65 +2175,51 @@
if (descriptor.format != m_descriptor.format && !m_viewFormats.contains(descriptor.format))
return false;
- // "If descriptor.dimension is:"
switch (descriptor.dimension) {
case WGPUTextureViewDimension_Undefined:
return false;
case WGPUTextureViewDimension_1D:
- // "this.[[descriptor]].dimension must be "1d"."
if (m_descriptor.dimension != WGPUTextureDimension_1D)
return false;
- // "descriptor.arrayLayerCount must be 1."
if (descriptor.arrayLayerCount != 1)
return false;
break;
case WGPUTextureViewDimension_2D:
- // "this.[[descriptor]].dimension must be "2d"."
if (m_descriptor.dimension != WGPUTextureDimension_2D)
return false;
- // "descriptor.arrayLayerCount must be 1."
if (descriptor.arrayLayerCount != 1)
return false;
break;
case WGPUTextureViewDimension_2DArray:
- // "this.[[descriptor]].dimension must be "2d"."
if (m_descriptor.dimension != WGPUTextureDimension_2D)
return false;
break;
case WGPUTextureViewDimension_Cube:
- // "this.[[descriptor]].dimension must be "2d"."
if (m_descriptor.dimension != WGPUTextureDimension_2D)
return false;
- // "descriptor.arrayLayerCount must be 6."
if (descriptor.arrayLayerCount != 6)
return false;
- // "this.[[descriptor]].size.width must be this.[[descriptor]].size.height."
if (m_descriptor.size.width != m_descriptor.size.height)
return false;
break;
case WGPUTextureViewDimension_CubeArray:
- // "this.[[descriptor]].dimension must be "2d"."
if (m_descriptor.dimension != WGPUTextureDimension_2D)
return false;
- // "descriptor.arrayLayerCount must be a multiple of 6."
if (descriptor.arrayLayerCount % 6)
return false;
- // "this.[[descriptor]].size.width must be this.[[descriptor]].size.height."
if (m_descriptor.size.width != m_descriptor.size.height)
return false;
break;
case WGPUTextureViewDimension_3D:
- // "this.[[descriptor]].dimension must be "3d"."
if (m_descriptor.dimension != WGPUTextureDimension_3D)
return false;
- // "descriptor.arrayLayerCount must be 1."
if (descriptor.arrayLayerCount != 1)
return false;
break;
@@ -2327,19 +2235,14 @@
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-compute-render-extent
- // "Let extent be a new GPUExtent3DDict object."
WGPUExtent3D extent { };
- // "Set extent.width to max(1, baseSize.width ≫ mipLevel)."
extent.width = std::max(static_cast<uint32_t>(1), baseSize.width >> mipLevel);
- // "Set extent.height to max(1, baseSize.height ≫ mipLevel)."
extent.height = std::max(static_cast<uint32_t>(1), baseSize.height >> mipLevel);
- // "Set extent.depthOrArrayLayers to 1."
extent.depthOrArrayLayers = 1;
- // "Return extent."
return extent;
}
@@ -2350,12 +2253,9 @@
// https://gpuweb.github.io/gpuweb/#dom-gputexture-createview
- // "Set descriptor to the result of resolving GPUTextureViewDescriptor defaults with descriptor."
auto descriptor = resolveTextureViewDescriptorDefaults(inputDescriptor);
- // "If any of the following requirements are unmet:"
if (!validateCreateView(descriptor)) {
- // "Generate a validation error."
m_device->generateAValidationError("Validation failure."_s);
// FIXME: "Return a new invalid GPUTextureView."
@@ -2434,19 +2334,10 @@
texture.label = fromAPI(descriptor.label);
- // "Let view be a new GPUTextureView object."
- // "Set view.[[texture]] to this."
- // "Set view.[[descriptor]] to descriptor."
-
- // "If this.[[descriptor]].usage contains RENDER_ATTACHMENT:"
std::optional<WGPUExtent3D> renderExtent;
- if (m_descriptor.usage & WGPUTextureUsage_RenderAttachment) {
- // "Let renderExtent be compute render extent(this.[[descriptor]].size, descriptor.baseMipLevel)."
- // "Set view.[[renderExtent]] to renderExtent."
+ if (m_descriptor.usage & WGPUTextureUsage_RenderAttachment)
renderExtent = computeRenderExtent(m_descriptor.size, descriptor.baseMipLevel);
- }
- // "Return view."
return TextureView::create(texture, descriptor, renderExtent);
}
@@ -2466,27 +2357,18 @@
switch (m_descriptor.dimension) {
case WGPUTextureDimension_1D:
return {
- // "Set extent.width to max(1, descriptor.size.width ≫ mipLevel)."
std::max(static_cast<uint32_t>(1), m_descriptor.size.width >> mipLevel),
- // "Set extent.height to 1."
1,
- // "Set extent.depthOrArrayLayers to descriptor.size.depthOrArrayLayers."
m_descriptor.size.depthOrArrayLayers };
case WGPUTextureDimension_2D:
return {
- // "Set extent.width to max(1, descriptor.size.width ≫ mipLevel)."
std::max(static_cast<uint32_t>(1), m_descriptor.size.width >> mipLevel),
- // "Set extent.height to max(1, descriptor.size.height ≫ mipLevel)."
std::max(static_cast<uint32_t>(1), m_descriptor.size.height >> mipLevel),
- // "Set extent.depthOrArrayLayers to descriptor.size.depthOrArrayLayers."
m_descriptor.size.depthOrArrayLayers };
case WGPUTextureDimension_3D:
return {
- // "Set extent.width to max(1, descriptor.size.width ≫ mipLevel)."
std::max(static_cast<uint32_t>(1), m_descriptor.size.width >> mipLevel),
- // "Set extent.height to max(1, descriptor.size.height ≫ mipLevel)."
std::max(static_cast<uint32_t>(1), m_descriptor.size.height >> mipLevel),
- // "Set extent.depthOrArrayLayers to max(1, descriptor.size.depthOrArrayLayers ≫ mipLevel)."
std::max(static_cast<uint32_t>(1), m_descriptor.size.depthOrArrayLayers >> mipLevel) };
case WGPUTextureDimension_Force32:
ASSERT_NOT_REACHED();
@@ -2498,33 +2380,23 @@
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-physical-miplevel-specific-texture-extent
- // "Let logicalExtent be logical miplevel-specific texture extent(descriptor, mipLevel)."
auto logicalExtent = logicalMiplevelSpecificTextureExtent(mipLevel);
switch (m_descriptor.dimension) {
case WGPUTextureDimension_1D:
return {
- // "Set extent.width to logicalExtent.width rounded up to the nearest multiple of descriptor’s texel block width."
static_cast<uint32_t>(WTF::roundUpToMultipleOf(texelBlockWidth(m_descriptor.format), logicalExtent.width)),
- // "Set extent.height to 1."
1,
- // "Set extent.depthOrArrayLayers to logicalExtent.depthOrArrayLayers."
logicalExtent.depthOrArrayLayers };
case WGPUTextureDimension_2D:
return {
- // "Set extent.width to logicalExtent.width rounded up to the nearest multiple of descriptor’s texel block width."
static_cast<uint32_t>(WTF::roundUpToMultipleOf(texelBlockWidth(m_descriptor.format), logicalExtent.width)),
- // "Set extent.height to logicalExtent.height rounded up to the nearest multiple of descriptor’s texel block height."
static_cast<uint32_t>(WTF::roundUpToMultipleOf(texelBlockHeight(m_descriptor.format), logicalExtent.height)),
- // "Set extent.depthOrArrayLayers to logicalExtent.depthOrArrayLayers."
logicalExtent.depthOrArrayLayers };
case WGPUTextureDimension_3D:
return {
- // "Set extent.width to logicalExtent.width rounded up to the nearest multiple of descriptor’s texel block width."
static_cast<uint32_t>(WTF::roundUpToMultipleOf(texelBlockWidth(m_descriptor.format), logicalExtent.width)),
- // "Set extent.height to logicalExtent.height rounded up to the nearest multiple of descriptor’s texel block height."
static_cast<uint32_t>(WTF::roundUpToMultipleOf(texelBlockHeight(m_descriptor.format), logicalExtent.height)),
- // "Set extent.depthOrArrayLayers to logicalExtent.depthOrArrayLayers."
logicalExtent.depthOrArrayLayers };
case WGPUTextureDimension_Force32:
ASSERT_NOT_REACHED();
@@ -2536,7 +2408,6 @@
{
// https://gpuweb.github.io/gpuweb/#imagecopytexture-subresource-size
- // "Its width, height and depthOrArrayLayers are the width, height, and depth, respectively, of the physical size of imageCopyTexture.texture subresource at mipmap level imageCopyTexture.mipLevel."
return fromAPI(imageCopyTexture.texture).physicalMiplevelSpecificTextureExtent(imageCopyTexture.mipLevel);
}
@@ -2544,31 +2415,23 @@
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validating-gpuimagecopytexture
- // "blockWidth be the texel block width of imageCopyTexture.texture.[[descriptor]].format."
uint32_t blockWidth = Texture::texelBlockWidth(fromAPI(imageCopyTexture.texture).descriptor().format);
- // "blockHeight be the texel block height of imageCopyTexture.texture.[[descriptor]].format."
uint32_t blockHeight = Texture::texelBlockHeight(fromAPI(imageCopyTexture.texture).descriptor().format);
// FIXME: "imageCopyTexture.texture must be a valid GPUTexture."
- // "imageCopyTexture.mipLevel must be less than the [[descriptor]].mipLevelCount of imageCopyTexture.texture."
if (imageCopyTexture.mipLevel >= fromAPI(imageCopyTexture.texture).descriptor().mipLevelCount)
return false;
- // "imageCopyTexture.origin.x must be a multiple of blockWidth."
if (imageCopyTexture.origin.x % blockWidth)
return false;
- // "imageCopyTexture.origin.y must be a multiple of blockHeight."
if (imageCopyTexture.origin.y % blockHeight)
return false;
- // "imageCopyTexture.texture.[[descriptor]].format is a depth-stencil format."
- // "imageCopyTexture.texture.[[descriptor]].sampleCount is greater than 1."
if (Texture::isDepthOrStencilFormat(fromAPI(imageCopyTexture.texture).descriptor().format)
|| fromAPI(imageCopyTexture.texture).descriptor().sampleCount > 1) {
- // "The imageCopyTexture subresource size of imageCopyTexture is equal to copySize"
auto subresourceSize = imageCopyTextureSubresourceSize(imageCopyTexture);
if (subresourceSize.width != copySize.width
|| subresourceSize.height != copySize.height
@@ -2834,35 +2697,27 @@
{
// https://gpuweb.github.io/gpuweb/#validating-texture-copy-range
- // "Let blockWidth be the texel block width of imageCopyTexture.texture.[[descriptor]].format."
auto blockWidth = Texture::texelBlockWidth(fromAPI(imageCopyTexture.texture).descriptor().format);
- // "Let blockHeight be the texel block height of imageCopyTexture.texture.[[descriptor]].format."
auto blockHeight = Texture::texelBlockHeight(fromAPI(imageCopyTexture.texture).descriptor().format);
- // "Let subresourceSize be the imageCopyTexture subresource size of imageCopyTexture."
auto subresourceSize = imageCopyTextureSubresourceSize(imageCopyTexture);
- // "(imageCopyTexture.origin.x + copySize.width) ≤ subresourceSize.width"
// FIXME: Used checked arithmetic
if (imageCopyTexture.origin.x + copySize.width > subresourceSize.width)
return false;
- // "(imageCopyTexture.origin.y + copySize.height) ≤ subresourceSize.height"
// FIXME: Used checked arithmetic
if ((imageCopyTexture.origin.y + copySize.height) > subresourceSize.height)
return false;
- // "(imageCopyTexture.origin.z + copySize.depthOrArrayLayers) ≤ subresourceSize.depthOrArrayLayers"
// FIXME: Used checked arithmetic
if ((imageCopyTexture.origin.z + copySize.depthOrArrayLayers) > subresourceSize.depthOrArrayLayers)
return false;
- // "copySize.width must be a multiple of blockWidth."
if (copySize.width % blockWidth)
return false;
- // "copySize.height must be a multiple of blockHeight."
if (copySize.height % blockHeight)
return false;
@@ -2873,88 +2728,62 @@
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validating-linear-texture-data
- // "Let blockWidth, blockHeight, and blockSize be the texel block width, height, and size of format."
uint32_t blockWidth = Texture::texelBlockWidth(format);
uint32_t blockHeight = Texture::texelBlockHeight(format);
uint32_t blockSize = Texture::texelBlockSize(format);
- // "It is assumed that copyExtent.width is a multiple of blockWidth and copyExtent.height is a multiple of blockHeight."
-
- // "widthInBlocks be copyExtent.width ÷ blockWidth."
auto widthInBlocks = copyExtent.width / blockWidth;
- // "heightInBlocks be copyExtent.height ÷ blockHeight."
auto heightInBlocks = copyExtent.height / blockHeight;
- // "bytesInLastRow be blockSize × widthInBlocks."
// FIXME: Use checked arithmetic.
auto bytesInLastRow = blockSize * widthInBlocks;
- // "If heightInBlocks > 1"
if (heightInBlocks > 1) {
- // "layout.bytesPerRow must be specified."
if (layout.bytesPerRow == WGPU_COPY_STRIDE_UNDEFINED)
return false;
}
- // "If copyExtent.depthOrArrayLayers > 1"
if (copyExtent.depthOrArrayLayers > 1) {
- // "layout.bytesPerRow and layout.rowsPerImage must be specified."
if (layout.bytesPerRow == WGPU_COPY_STRIDE_UNDEFINED || layout.rowsPerImage == WGPU_COPY_STRIDE_UNDEFINED)
return false;
}
- // "If specified"
if (layout.bytesPerRow != WGPU_COPY_STRIDE_UNDEFINED) {
- // "layout.bytesPerRow must be greater than or equal to bytesInLastRow."
if (layout.bytesPerRow < bytesInLastRow)
return false;
}
- // "If specified"
if (layout.rowsPerImage != WGPU_COPY_STRIDE_UNDEFINED) {
- // "layout.rowsPerImage must be greater than or equal to heightInBlocks."
if (layout.rowsPerImage < heightInBlocks)
return false;
}
- // "Let requiredBytesInCopy be 0."
uint64_t requiredBytesInCopy = 0;
- // "If copyExtent.depthOrArrayLayers > 1:"
if (copyExtent.depthOrArrayLayers > 1) {
- // "Let bytesPerImage be layout.bytesPerRow × layout.rowsPerImage."
// FIXME: Use checked arithmetic.
auto bytesPerImage = layout.bytesPerRow * layout.rowsPerImage;
- // "Let bytesBeforeLastImage be bytesPerImage × (copyExtent.depthOrArrayLayers − 1)."
// FIXME: Use checked arithmetic.
auto bytesBeforeLastImage = bytesPerImage * (copyExtent.depthOrArrayLayers - 1);
- // "Add bytesBeforeLastImage to requiredBytesInCopy."
// FIXME: Use checked arithmetic.
requiredBytesInCopy += bytesBeforeLastImage;
}
- // "If copyExtent.depthOrArrayLayers > 0:"
if (copyExtent.depthOrArrayLayers > 0) {
- // "If heightInBlocks > 1"
if (heightInBlocks > 1) {
- // "add layout.bytesPerRow × (heightInBlocks − 1) to requiredBytesInCopy."
// FIXME: Use checked arithmetic.
requiredBytesInCopy += layout.bytesPerRow * (heightInBlocks - 1);
}
- // "If heightInBlocks > 0"
if (heightInBlocks > 0) {
- // "add bytesInLastRow to requiredBytesInCopy."
// FIXME: Use checked arithmetic.
requiredBytesInCopy += bytesInLastRow;
}
}
- // "Fail if the following conditions are not satisfied:"
- // "layout.offset + requiredBytesInCopy ≤ byteSize."
// FIXME: Use checked arithmetic.
if (layout.offset + requiredBytesInCopy > byteSize)
return false;