diff --git a/examples/Animometer.cpp b/examples/Animometer.cpp index 7194a187c8..32d1a6612e 100644 --- a/examples/Animometer.cpp +++ b/examples/Animometer.cpp @@ -156,7 +156,6 @@ void frame() { } queue.Submit(1, &commands); - backbuffer.TransitionUsage(nxt::TextureUsageBit::Present); swapchain.Present(backbuffer); DoFlush(); fprintf(stderr, "frame %i\n", f); diff --git a/examples/CHelloTriangle.cpp b/examples/CHelloTriangle.cpp index df0f5e693c..0ec9cb81c0 100644 --- a/examples/CHelloTriangle.cpp +++ b/examples/CHelloTriangle.cpp @@ -96,7 +96,6 @@ void frame() { nxtQueueSubmit(queue, 1, &commands); nxtCommandBufferRelease(commands); - nxtTextureTransitionUsage(backbuffer, NXT_TEXTURE_USAGE_BIT_PRESENT); nxtSwapChainPresent(swapchain, backbuffer); nxtRenderPassDescriptorRelease(renderpassInfo); nxtTextureViewRelease(backbufferView); diff --git a/examples/ComputeBoids.cpp b/examples/ComputeBoids.cpp index 6b05433512..0e8489c80f 100644 --- a/examples/ComputeBoids.cpp +++ b/examples/ComputeBoids.cpp @@ -63,10 +63,10 @@ void initBuffers() { {0.01, -0.02}, {0.00, 0.02}, }; - modelBuffer = utils::CreateFrozenBufferFromData(device, model, sizeof(model), nxt::BufferUsageBit::Vertex); + modelBuffer = utils::CreateBufferFromData(device, model, sizeof(model), nxt::BufferUsageBit::Vertex); SimParams params = { 0.04f, 0.1f, 0.025f, 0.025f, 0.02f, 0.05f, 0.005f, kNumParticles }; - updateParams = utils::CreateFrozenBufferFromData(device, ¶ms, sizeof(params), nxt::BufferUsageBit::Uniform); + updateParams = utils::CreateBufferFromData(device, ¶ms, sizeof(params), nxt::BufferUsageBit::Uniform); std::vector initialParticles(kNumParticles); { @@ -82,7 +82,6 @@ void initBuffers() { for (size_t i = 0; i < 2; i++) { particleBuffers[i] = device.CreateBufferBuilder() .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Storage) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .SetSize(sizeof(Particle) * kNumParticles) .GetResult(); @@ -261,20 +260,16 @@ void initSim() { nxt::CommandBuffer createCommandBuffer(const nxt::RenderPassDescriptor& renderPass, size_t i) { static const uint32_t zeroOffsets[1] = {0}; - auto& bufferSrc = particleBuffers[i]; auto& bufferDst = particleBuffers[(i + 1) % 2]; return device.CreateCommandBufferBuilder() .BeginComputePass() .SetComputePipeline(updatePipeline) - .TransitionBufferUsage(bufferSrc, nxt::BufferUsageBit::Storage) - .TransitionBufferUsage(bufferDst, nxt::BufferUsageBit::Storage) .SetBindGroup(0, updateBGs[i]) .Dispatch(kNumParticles, 1, 1) .EndComputePass() .BeginRenderPass(renderPass) .SetRenderPipeline(renderPipeline) - .TransitionBufferUsage(bufferDst, nxt::BufferUsageBit::Vertex) .SetVertexBuffers(0, 1, &bufferDst, zeroOffsets) .SetVertexBuffers(1, 1, &modelBuffer, zeroOffsets) .DrawArrays(3, kNumParticles, 0, 0) @@ -303,7 +298,6 @@ void frame() { nxt::CommandBuffer commandBuffer = createCommandBuffer(renderPass, pingpong); queue.Submit(1, &commandBuffer); - backbuffer.TransitionUsage(nxt::TextureUsageBit::Present); swapchain.Present(backbuffer); DoFlush(); diff --git a/examples/CppHelloTriangle.cpp b/examples/CppHelloTriangle.cpp index 5a650ae0c9..20ad5b2521 100644 --- a/examples/CppHelloTriangle.cpp +++ b/examples/CppHelloTriangle.cpp @@ -37,14 +37,14 @@ void initBuffers() { static const uint32_t indexData[3] = { 0, 1, 2, }; - indexBuffer = utils::CreateFrozenBufferFromData(device, indexData, sizeof(indexData), nxt::BufferUsageBit::Index); + indexBuffer = utils::CreateBufferFromData(device, indexData, sizeof(indexData), nxt::BufferUsageBit::Index); static const float vertexData[12] = { 0.0f, 0.5f, 0.0f, 1.0f, -0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, }; - vertexBuffer = utils::CreateFrozenBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex); + vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex); } void initTextures() { @@ -66,14 +66,12 @@ void initTextures() { } - nxt::Buffer stagingBuffer = utils::CreateFrozenBufferFromData(device, data.data(), static_cast(data.size()), nxt::BufferUsageBit::TransferSrc); + nxt::Buffer stagingBuffer = utils::CreateBufferFromData(device, data.data(), static_cast(data.size()), nxt::BufferUsageBit::TransferSrc); nxt::CommandBuffer copy = device.CreateCommandBufferBuilder() - .TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst) .CopyBufferToTexture(stagingBuffer, 0, 0, texture, 0, 0, 0, 1024, 1024, 1, 0) .GetResult(); queue.Submit(1, ©); - texture.FreezeUsage(nxt::TextureUsageBit::Sampled); } void init() { @@ -162,7 +160,6 @@ void frame() { .GetResult(); queue.Submit(1, &commands); - backbuffer.TransitionUsage(nxt::TextureUsageBit::Present); swapchain.Present(backbuffer); DoFlush(); } diff --git a/examples/CubeReflection.cpp b/examples/CubeReflection.cpp index a469a07924..f1e7d3cfce 100644 --- a/examples/CubeReflection.cpp +++ b/examples/CubeReflection.cpp @@ -61,7 +61,7 @@ void initBuffers() { 20, 21, 22, 20, 22, 23 }; - indexBuffer = utils::CreateFrozenBufferFromData(device, indexData, sizeof(indexData), nxt::BufferUsageBit::Index); + indexBuffer = utils::CreateBufferFromData(device, indexData, sizeof(indexData), nxt::BufferUsageBit::Index); static const float vertexData[6 * 4 * 6] = { -1.0, -1.0, 1.0, 1.0, 0.0, 0.0, @@ -94,7 +94,7 @@ void initBuffers() { -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0 }; - vertexBuffer = utils::CreateFrozenBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex); + vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex); static const float planeData[6 * 4] = { -2.0, -1.0, -2.0, 0.5, 0.5, 0.5, @@ -102,7 +102,7 @@ void initBuffers() { 2.0, -1.0, 2.0, 0.5, 0.5, 0.5, -2.0, -1.0, 2.0, 0.5, 0.5, 0.5, }; - planeBuffer = utils::CreateFrozenBufferFromData(device, planeData, sizeof(planeData), nxt::BufferUsageBit::Vertex); + planeBuffer = utils::CreateBufferFromData(device, planeData, sizeof(planeData), nxt::BufferUsageBit::Vertex); } struct CameraData { @@ -171,15 +171,14 @@ void init() { cameraBuffer = device.CreateBufferBuilder() .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Uniform) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .SetSize(sizeof(CameraData)) .GetResult(); glm::mat4 transform(1.0); - transformBuffer[0] = utils::CreateFrozenBufferFromData(device, &transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform); + transformBuffer[0] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform); transform = glm::translate(transform, glm::vec3(0.f, -2.f, 0.f)); - transformBuffer[1] = utils::CreateFrozenBufferFromData(device, &transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform); + transformBuffer[1] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform); nxt::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder() .SetExtent(0, sizeof(CameraData)) @@ -274,7 +273,6 @@ void frame() { glm::vec3(0.0f, -1.0f, 0.0f) ); - cameraBuffer.TransitionUsage(nxt::BufferUsageBit::TransferDst); cameraBuffer.SetSubData(0, sizeof(CameraData), reinterpret_cast(&cameraData)); nxt::Texture backbuffer; @@ -282,8 +280,6 @@ void frame() { GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass); nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() - .TransitionBufferUsage(cameraBuffer, nxt::BufferUsageBit::Uniform) - .BeginRenderPass(renderPass) .SetRenderPipeline(pipeline) .SetBindGroup(0, bindGroup[0]) @@ -305,7 +301,6 @@ void frame() { .GetResult(); queue.Submit(1, &commands); - backbuffer.TransitionUsage(nxt::TextureUsageBit::Present); swapchain.Present(backbuffer); DoFlush(); } diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp index 92e6064820..3d77f3c296 100644 --- a/examples/SampleUtils.cpp +++ b/examples/SampleUtils.cpp @@ -143,7 +143,6 @@ nxt::TextureView CreateDefaultDepthStencilView(const nxt::Device& device) { .SetMipLevels(1) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) .GetResult(); - depthStencilTexture.FreezeUsage(nxt::TextureUsageBit::OutputAttachment); return depthStencilTexture.CreateTextureViewBuilder() .GetResult(); } diff --git a/examples/glTFViewer/glTFViewer.cpp b/examples/glTFViewer/glTFViewer.cpp index 1e2b4c9fe4..8e73ff988b 100644 --- a/examples/glTFViewer/glTFViewer.cpp +++ b/examples/glTFViewer/glTFViewer.cpp @@ -125,7 +125,6 @@ namespace { .SetAllowedUsage(nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Index) .SetSize(256) .GetResult(); - defaultBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Index); for (const auto& bv : scene.bufferViews) { const auto& iBufferViewID = bv.first; @@ -151,7 +150,7 @@ namespace { size_t iBufferViewSize = iBufferView.byteLength ? iBufferView.byteLength : (iBuffer.data.size() - iBufferView.byteOffset); - auto oBuffer = utils::CreateFrozenBufferFromData(device, &iBuffer.data.at(iBufferView.byteOffset), static_cast(iBufferViewSize), usage); + auto oBuffer = utils::CreateBufferFromData(device, &iBuffer.data.at(iBufferView.byteOffset), static_cast(iBufferViewSize), usage); buffers[iBufferViewID] = std::move(oBuffer); } } @@ -299,7 +298,6 @@ namespace { auto uniformBuffer = device.CreateBufferBuilder() .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Uniform) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .SetSize(sizeof(u_transform_block)) .GetResult(); @@ -440,13 +438,11 @@ namespace { fprintf(stderr, "unsupported image.component %d\n", iImage.component); } - nxt::Buffer staging = utils::CreateFrozenBufferFromData(device, data, rowPitch * iImage.height, nxt::BufferUsageBit::TransferSrc); + nxt::Buffer staging = utils::CreateBufferFromData(device, data, rowPitch * iImage.height, nxt::BufferUsageBit::TransferSrc); auto cmdbuf = device.CreateCommandBufferBuilder() - .TransitionTextureUsage(oTexture, nxt::TextureUsageBit::TransferDst) .CopyBufferToTexture(staging, 0, rowPitch, oTexture, 0, 0, 0, iImage.width, iImage.height, 1, 0) .GetResult(); queue.Submit(1, &cmdbuf); - oTexture.FreezeUsage(nxt::TextureUsageBit::Sampled); textures[iTextureID] = oTexture.CreateTextureViewBuilder().GetResult(); } @@ -494,7 +490,6 @@ namespace { } } const MaterialInfo& material = getMaterial(iPrim.material, strides[0], strides[1], strides[2]); - material.uniformBuffer.TransitionUsage(nxt::BufferUsageBit::TransferDst); // TODO(cwallez@google.com): This is updating the uniform buffer with a device-level command // but the draw is queue level command that is pipelined. This causes bad rendering for models // that use the same part multiple time. @@ -502,7 +497,6 @@ namespace { sizeof(u_transform_block), reinterpret_cast(&transforms)); cmd.SetRenderPipeline(material.pipeline); - cmd.TransitionBufferUsage(material.uniformBuffer, nxt::BufferUsageBit::Uniform); cmd.SetBindGroup(0, material.bindGroup0); uint32_t vertexCount = 0; @@ -591,7 +585,6 @@ namespace { .GetResult(); queue.Submit(1, &commands); - backbuffer.TransitionUsage(nxt::TextureUsageBit::Present); swapchain.Present(backbuffer); DoFlush(); } diff --git a/next.json b/next.json index fd140c6a0b..e313c98368 100644 --- a/next.json +++ b/next.json @@ -221,18 +221,6 @@ }, { "name": "unmap" - }, - { - "name": "transition usage", - "args": [ - {"name": "usage", "type": "buffer usage bit"} - ] - }, - { - "name": "freeze usage", - "args": [ - {"name": "usage", "type": "buffer usage bit"} - ] } ] }, @@ -249,12 +237,6 @@ {"name": "usage", "type": "buffer usage bit"} ] }, - { - "name": "set initial usage", - "args": [ - {"name": "usage", "type": "buffer usage bit"} - ] - }, { "name": "set size", "args": [ @@ -507,20 +489,6 @@ {"name": "buffers", "type": "buffer", "annotation": "const*", "length": "count"}, {"name": "offsets", "type": "uint32_t", "annotation": "const*", "length": "count"} ] - }, - { - "name": "transition buffer usage", - "args": [ - {"name": "buffer", "type": "buffer"}, - {"name": "usage", "type": "buffer usage bit"} - ] - }, - { - "name": "transition texture usage", - "args": [ - {"name": "texture", "type": "texture"}, - {"name": "usage", "type": "texture usage bit"} - ] } ] }, @@ -1033,18 +1001,6 @@ { "name": "create texture view builder", "returns": "texture view builder" - }, - { - "name": "transition usage", - "args": [ - {"name": "usage", "type": "texture usage bit"} - ] - }, - { - "name": "freeze usage", - "args": [ - {"name": "usage", "type": "texture usage bit"} - ] } ] }, @@ -1086,12 +1042,6 @@ "args": [ {"name": "usage", "type": "texture usage bit"} ] - }, - { - "name": "set initial usage", - "args": [ - {"name": "usage", "type": "texture usage bit"} - ] } ] }, diff --git a/src/backend/Buffer.cpp b/src/backend/Buffer.cpp index 4b4b008946..e9cb65fc01 100644 --- a/src/backend/Buffer.cpp +++ b/src/backend/Buffer.cpp @@ -25,10 +25,7 @@ namespace backend { // Buffer BufferBase::BufferBase(BufferBuilder* builder) - : mDevice(builder->mDevice), - mSize(builder->mSize), - mAllowedUsage(builder->mAllowedUsage), - mCurrentUsage(builder->mCurrentUsage) { + : mDevice(builder->mDevice), mSize(builder->mSize), mAllowedUsage(builder->mAllowedUsage) { } BufferBase::~BufferBase() { @@ -54,10 +51,6 @@ namespace backend { return mAllowedUsage; } - nxt::BufferUsageBit BufferBase::GetUsage() const { - return mCurrentUsage; - } - void BufferBase::CallMapReadCallback(uint32_t serial, nxtBufferMapAsyncStatus status, const void* pointer) { @@ -90,7 +83,7 @@ namespace backend { return; } - if (!(mCurrentUsage & nxt::BufferUsageBit::TransferDst)) { + if (!(mAllowedUsage & nxt::BufferUsageBit::TransferDst)) { mDevice->HandleError("Buffer needs the transfer dst usage bit"); return; } @@ -155,59 +148,33 @@ namespace backend { mMapUserdata = 0; } - bool BufferBase::IsFrozen() const { - return mIsFrozen; - } - - bool BufferBase::HasFrozenUsage(nxt::BufferUsageBit usage) const { - return mIsFrozen && (usage & mAllowedUsage); - } - - bool BufferBase::IsUsagePossible(nxt::BufferUsageBit allowedUsage, nxt::BufferUsageBit usage) { - bool allowed = (usage & allowedUsage) == usage; - bool readOnly = (usage & kReadOnlyBufferUsages) == usage; - bool singleUse = nxt::HasZeroOrOneBits(usage); - return allowed && (readOnly || singleUse); - } - - bool BufferBase::IsTransitionPossible(nxt::BufferUsageBit usage) const { - if (mIsFrozen || mIsMapped) { + bool BufferBase::ValidateMapBase(uint32_t start, + uint32_t size, + nxt::BufferUsageBit requiredUsage) { + // TODO(cwallez@chromium.org): check for overflows. + if (start + size > GetSize()) { + mDevice->HandleError("Buffer map read out of range"); return false; } - return IsUsagePossible(mAllowedUsage, usage); - } - void BufferBase::UpdateUsageInternal(nxt::BufferUsageBit usage) { - ASSERT(IsTransitionPossible(usage)); - mCurrentUsage = usage; - } - - void BufferBase::TransitionUsage(nxt::BufferUsageBit usage) { - if (!IsTransitionPossible(usage)) { - mDevice->HandleError("Buffer frozen or usage not allowed"); - return; + if (mIsMapped) { + mDevice->HandleError("Buffer already mapped"); + return false; } - TransitionUsageImpl(mCurrentUsage, usage); - mCurrentUsage = usage; - } - void BufferBase::FreezeUsage(nxt::BufferUsageBit usage) { - if (!IsTransitionPossible(usage)) { - mDevice->HandleError("Buffer frozen or usage not allowed"); - return; + if (!(mAllowedUsage & requiredUsage)) { + mDevice->HandleError("Buffer needs the correct map usage bit"); + return false; } - mAllowedUsage = usage; - TransitionUsageImpl(mCurrentUsage, usage); - mCurrentUsage = usage; - mIsFrozen = true; + + return true; } // BufferBuilder enum BufferSetProperties { BUFFER_PROPERTY_ALLOWED_USAGE = 0x1, - BUFFER_PROPERTY_INITIAL_USAGE = 0x2, - BUFFER_PROPERTY_SIZE = 0x4, + BUFFER_PROPERTY_SIZE = 0x2, }; BufferBuilder::BufferBuilder(DeviceBase* device) : Builder(device) { @@ -236,11 +203,6 @@ namespace backend { return nullptr; } - if (!BufferBase::IsUsagePossible(mAllowedUsage, mCurrentUsage)) { - HandleError("Initial buffer usage is not allowed"); - return nullptr; - } - return mDevice->CreateBuffer(this); } @@ -254,16 +216,6 @@ namespace backend { mPropertiesSet |= BUFFER_PROPERTY_ALLOWED_USAGE; } - void BufferBuilder::SetInitialUsage(nxt::BufferUsageBit usage) { - if ((mPropertiesSet & BUFFER_PROPERTY_INITIAL_USAGE) != 0) { - HandleError("Buffer initialUsage property set multiple times"); - return; - } - - mCurrentUsage = usage; - mPropertiesSet |= BUFFER_PROPERTY_INITIAL_USAGE; - } - void BufferBuilder::SetSize(uint32_t size) { if ((mPropertiesSet & BUFFER_PROPERTY_SIZE) != 0) { HandleError("Buffer size property set multiple times"); @@ -274,27 +226,6 @@ namespace backend { mPropertiesSet |= BUFFER_PROPERTY_SIZE; } - bool BufferBase::ValidateMapBase(uint32_t start, - uint32_t size, - nxt::BufferUsageBit requiredUsage) { - if (start + size > GetSize()) { - mDevice->HandleError("Buffer map read out of range"); - return false; - } - - if (mIsMapped) { - mDevice->HandleError("Buffer already mapped"); - return false; - } - - if (!(mCurrentUsage & requiredUsage)) { - mDevice->HandleError("Buffer needs the correct map usage bit"); - return false; - } - - return true; - } - // BufferViewBase BufferViewBase::BufferViewBase(BufferViewBuilder* builder) diff --git a/src/backend/Buffer.h b/src/backend/Buffer.h index a0acef1e60..85d36a009a 100644 --- a/src/backend/Buffer.h +++ b/src/backend/Buffer.h @@ -38,12 +38,6 @@ namespace backend { uint32_t GetSize() const; nxt::BufferUsageBit GetAllowedUsage() const; - nxt::BufferUsageBit GetUsage() const; - static bool IsUsagePossible(nxt::BufferUsageBit allowedUsage, nxt::BufferUsageBit usage); - bool IsTransitionPossible(nxt::BufferUsageBit usage) const; - bool IsFrozen() const; - bool HasFrozenUsage(nxt::BufferUsageBit usage) const; - void UpdateUsageInternal(nxt::BufferUsageBit usage); DeviceBase* GetDevice() const; @@ -59,8 +53,6 @@ namespace backend { nxtBufferMapWriteCallback callback, nxtCallbackUserdata userdata); void Unmap(); - void TransitionUsage(nxt::BufferUsageBit usage); - void FreezeUsage(nxt::BufferUsageBit usage); protected: void CallMapReadCallback(uint32_t serial, @@ -73,22 +65,18 @@ namespace backend { virtual void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0; virtual void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0; virtual void UnmapImpl() = 0; - virtual void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, - nxt::BufferUsageBit targetUsage) = 0; bool ValidateMapBase(uint32_t start, uint32_t size, nxt::BufferUsageBit requiredUsage); DeviceBase* mDevice; uint32_t mSize; nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None; - nxt::BufferUsageBit mCurrentUsage = nxt::BufferUsageBit::None; nxtBufferMapReadCallback mMapReadCallback = nullptr; nxtBufferMapWriteCallback mMapWriteCallback = nullptr; nxtCallbackUserdata mMapUserdata = 0; uint32_t mMapSerial = 0; - bool mIsFrozen = false; bool mIsMapped = false; }; diff --git a/src/backend/CommandBuffer.cpp b/src/backend/CommandBuffer.cpp index 02ff7155c9..04ec426f7c 100644 --- a/src/backend/CommandBuffer.cpp +++ b/src/backend/CommandBuffer.cpp @@ -122,6 +122,30 @@ namespace backend { return true; } + bool ValidateCanUseAs(CommandBufferBuilder* builder, + BufferBase* buffer, + nxt::BufferUsageBit usage) { + ASSERT(HasZeroOrOneBits(usage)); + if (!(buffer->GetAllowedUsage() & usage)) { + builder->HandleError("buffer doesn't have the required usage."); + return false; + } + + return true; + } + + bool ValidateCanUseAs(CommandBufferBuilder* builder, + TextureBase* texture, + nxt::TextureUsageBit usage) { + ASSERT(HasZeroOrOneBits(usage)); + if (!(texture->GetAllowedUsage() & usage)) { + builder->HandleError("texture doesn't have the required usage."); + return false; + } + + return true; + } + enum class PassType { Render, Compute, @@ -263,25 +287,7 @@ namespace backend { // CommandBuffer CommandBufferBase::CommandBufferBase(CommandBufferBuilder* builder) - : mDevice(builder->mDevice), - mBuffersTransitioned(std::move(builder->mState->mBuffersTransitioned)), - mTexturesTransitioned(std::move(builder->mState->mTexturesTransitioned)) { - } - - bool CommandBufferBase::ValidateResourceUsagesImmediate() { - for (auto buffer : mBuffersTransitioned) { - if (buffer->IsFrozen()) { - mDevice->HandleError("Command buffer: cannot transition buffer with frozen usage"); - return false; - } - } - for (auto texture : mTexturesTransitioned) { - if (texture->IsFrozen()) { - mDevice->HandleError("Command buffer: cannot transition texture with frozen usage"); - return false; - } - } - return true; + : mDevice(builder->mDevice) { } DeviceBase* CommandBufferBase::GetDevice() { @@ -352,10 +358,10 @@ namespace backend { CopyBufferToBufferCmd* copy = mIterator.NextCommand(); if (!ValidateCopySizeFitsInBuffer(this, copy->source, copy->size) || !ValidateCopySizeFitsInBuffer(this, copy->destination, copy->size) || - !mState->ValidateCanUseBufferAs(copy->source.buffer.Get(), - nxt::BufferUsageBit::TransferSrc) || - !mState->ValidateCanUseBufferAs(copy->destination.buffer.Get(), - nxt::BufferUsageBit::TransferDst)) { + !ValidateCanUseAs(this, copy->source.buffer.Get(), + nxt::BufferUsageBit::TransferSrc) || + !ValidateCanUseAs(this, copy->destination.buffer.Get(), + nxt::BufferUsageBit::TransferDst)) { return false; } } break; @@ -371,10 +377,10 @@ namespace backend { !ValidateCopySizeFitsInBuffer(this, copy->source, bufferCopySize) || !ValidateTexelBufferOffset(this, copy->destination.texture.Get(), copy->source) || - !mState->ValidateCanUseBufferAs(copy->source.buffer.Get(), - nxt::BufferUsageBit::TransferSrc) || - !mState->ValidateCanUseTextureAs(copy->destination.texture.Get(), - nxt::TextureUsageBit::TransferDst)) { + !ValidateCanUseAs(this, copy->source.buffer.Get(), + nxt::BufferUsageBit::TransferSrc) || + !ValidateCanUseAs(this, copy->destination.texture.Get(), + nxt::TextureUsageBit::TransferDst)) { return false; } } break; @@ -390,31 +396,14 @@ namespace backend { !ValidateCopySizeFitsInBuffer(this, copy->destination, bufferCopySize) || !ValidateTexelBufferOffset(this, copy->source.texture.Get(), copy->destination) || - !mState->ValidateCanUseTextureAs(copy->source.texture.Get(), - nxt::TextureUsageBit::TransferSrc) || - !mState->ValidateCanUseBufferAs(copy->destination.buffer.Get(), - nxt::BufferUsageBit::TransferDst)) { + !ValidateCanUseAs(this, copy->source.texture.Get(), + nxt::TextureUsageBit::TransferSrc) || + !ValidateCanUseAs(this, copy->destination.buffer.Get(), + nxt::BufferUsageBit::TransferDst)) { return false; } } break; - case Command::TransitionBufferUsage: { - TransitionBufferUsageCmd* cmd = - mIterator.NextCommand(); - if (!mState->TransitionBufferUsage(cmd->buffer.Get(), cmd->usage)) { - return false; - } - } break; - - case Command::TransitionTextureUsage: { - TransitionTextureUsageCmd* cmd = - mIterator.NextCommand(); - if (!mState->TransitionTextureUsage(cmd->texture.Get(), cmd->usage)) { - return false; - } - - } break; - default: HandleError("Command disallowed outside of a pass"); return false; @@ -474,9 +463,7 @@ namespace backend { SetBindGroupCmd* cmd = mIterator.NextCommand(); TrackBindGroupResourceUsage(cmd->group.Get(), &usageTracker); - if (!mState->SetBindGroup(cmd->index, cmd->group.Get())) { - return false; - } + mState->SetBindGroup(cmd->index, cmd->group.Get()); } break; default: @@ -490,10 +477,6 @@ namespace backend { } bool CommandBufferBuilder::ValidateRenderPass(RenderPassDescriptorBase* renderPass) { - if (!mState->BeginRenderPass(renderPass)) { - return false; - } - PassResourceUsageTracker usageTracker; // Track usage of the render pass attachments @@ -581,16 +564,14 @@ namespace backend { SetBindGroupCmd* cmd = mIterator.NextCommand(); TrackBindGroupResourceUsage(cmd->group.Get(), &usageTracker); - if (!mState->SetBindGroup(cmd->index, cmd->group.Get())) { - return false; - } + mState->SetBindGroup(cmd->index, cmd->group.Get()); } break; case Command::SetIndexBuffer: { SetIndexBufferCmd* cmd = mIterator.NextCommand(); usageTracker.BufferUsedAs(cmd->buffer.Get(), nxt::BufferUsageBit::Index); - if (!mState->SetIndexBuffer(cmd->buffer.Get())) { + if (!mState->SetIndexBuffer()) { return false; } } break; @@ -602,7 +583,7 @@ namespace backend { for (uint32_t i = 0; i < cmd->count; ++i) { usageTracker.BufferUsedAs(buffers[i].Get(), nxt::BufferUsageBit::Vertex); - mState->SetVertexBuffer(cmd->startSlot + i, buffers[i].Get()); + mState->SetVertexBuffer(cmd->startSlot + i); } } break; @@ -848,22 +829,4 @@ namespace backend { memcpy(cmdOffsets, offsets, count * sizeof(uint32_t)); } - void CommandBufferBuilder::TransitionBufferUsage(BufferBase* buffer, - nxt::BufferUsageBit usage) { - TransitionBufferUsageCmd* cmd = - mAllocator.Allocate(Command::TransitionBufferUsage); - new (cmd) TransitionBufferUsageCmd; - cmd->buffer = buffer; - cmd->usage = usage; - } - - void CommandBufferBuilder::TransitionTextureUsage(TextureBase* texture, - nxt::TextureUsageBit usage) { - TransitionTextureUsageCmd* cmd = - mAllocator.Allocate(Command::TransitionTextureUsage); - new (cmd) TransitionTextureUsageCmd; - cmd->texture = texture; - cmd->usage = usage; - } - } // namespace backend diff --git a/src/backend/CommandBuffer.h b/src/backend/CommandBuffer.h index 0525daf8f0..7c0ef969f9 100644 --- a/src/backend/CommandBuffer.h +++ b/src/backend/CommandBuffer.h @@ -42,14 +42,11 @@ namespace backend { class CommandBufferBase : public RefCounted { public: CommandBufferBase(CommandBufferBuilder* builder); - bool ValidateResourceUsagesImmediate(); DeviceBase* GetDevice(); private: DeviceBase* mDevice; - std::set mBuffersTransitioned; - std::set mTexturesTransitioned; }; class CommandBufferBuilder : public Builder { @@ -130,7 +127,6 @@ namespace backend { uint32_t const* offsets); void TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage); - void TransitionTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage); private: friend class CommandBufferBase; diff --git a/src/backend/CommandBufferStateTracker.cpp b/src/backend/CommandBufferStateTracker.cpp index f67c60c25b..d8a60eb10c 100644 --- a/src/backend/CommandBufferStateTracker.cpp +++ b/src/backend/CommandBufferStateTracker.cpp @@ -33,24 +33,6 @@ namespace backend { : mBuilder(mBuilder) { } - bool CommandBufferStateTracker::ValidateCanUseBufferAs(BufferBase* buffer, - nxt::BufferUsageBit usage) const { - if (!BufferHasGuaranteedUsageBit(buffer, usage)) { - mBuilder->HandleError("Buffer is not in the necessary usage"); - return false; - } - return true; - } - - bool CommandBufferStateTracker::ValidateCanUseTextureAs(TextureBase* texture, - nxt::TextureUsageBit usage) const { - if (!TextureHasGuaranteedUsageBit(texture, usage)) { - mBuilder->HandleError("Texture is not in the necessary usage"); - return false; - } - return true; - } - bool CommandBufferStateTracker::ValidateCanDispatch() { constexpr ValidationAspects requiredAspects = 1 << VALIDATION_ASPECT_PIPELINE | 1 << VALIDATION_ASPECT_BIND_GROUPS; @@ -99,32 +81,7 @@ namespace backend { return RevalidateCanDraw(); } - bool CommandBufferStateTracker::BeginRenderPass(RenderPassDescriptorBase* info) { - for (uint32_t i : IterateBitSet(info->GetColorAttachmentMask())) { - TextureBase* texture = info->GetColorAttachment(i).view->GetTexture(); - if (!EnsureTextureUsage(texture, nxt::TextureUsageBit::OutputAttachment)) { - mBuilder->HandleError("Unable to ensure texture has OutputAttachment usage"); - return false; - } - mTexturesAttached.insert(texture); - } - - if (info->HasDepthStencilAttachment()) { - TextureBase* texture = info->GetDepthStencilAttachment().view->GetTexture(); - if (!EnsureTextureUsage(texture, nxt::TextureUsageBit::OutputAttachment)) { - mBuilder->HandleError("Unable to ensure texture has OutputAttachment usage"); - return false; - } - mTexturesAttached.insert(texture); - } - - return true; - } - void CommandBufferStateTracker::EndPass() { - // Everything in mTexturesAttached should be for the current render pass. - mTexturesAttached.clear(); - mInputsSet.reset(); mAspects = 0; mBindgroups.fill(nullptr); @@ -141,141 +98,31 @@ namespace backend { return true; } - bool CommandBufferStateTracker::SetBindGroup(uint32_t index, BindGroupBase* bindgroup) { - if (!ValidateBindGroupUsages(bindgroup)) { - return false; - } + void CommandBufferStateTracker::SetBindGroup(uint32_t index, BindGroupBase* bindgroup) { mBindgroupsSet.set(index); mBindgroups[index] = bindgroup; - - return true; } - bool CommandBufferStateTracker::SetIndexBuffer(BufferBase* buffer) { + bool CommandBufferStateTracker::SetIndexBuffer() { if (!HavePipeline()) { mBuilder->HandleError("Can't set the index buffer without a pipeline"); return false; } - auto usage = nxt::BufferUsageBit::Index; - if (!BufferHasGuaranteedUsageBit(buffer, usage)) { - mBuilder->HandleError("Buffer needs the index usage bit to be guaranteed"); - return false; - } - mAspects.set(VALIDATION_ASPECT_INDEX_BUFFER); return true; } - bool CommandBufferStateTracker::SetVertexBuffer(uint32_t index, BufferBase* buffer) { + bool CommandBufferStateTracker::SetVertexBuffer(uint32_t index) { if (!HavePipeline()) { mBuilder->HandleError("Can't set vertex buffers without a pipeline"); return false; } - auto usage = nxt::BufferUsageBit::Vertex; - if (!BufferHasGuaranteedUsageBit(buffer, usage)) { - mBuilder->HandleError("Buffer needs vertex usage bit to be guaranteed"); - return false; - } - mInputsSet.set(index); return true; } - bool CommandBufferStateTracker::TransitionBufferUsage(BufferBase* buffer, - nxt::BufferUsageBit usage) { - if (!buffer->IsTransitionPossible(usage)) { - if (buffer->IsFrozen()) { - mBuilder->HandleError("Buffer transition not possible (usage is frozen)"); - } else if (!BufferBase::IsUsagePossible(buffer->GetAllowedUsage(), usage)) { - mBuilder->HandleError("Buffer transition not possible (usage not allowed)"); - } else { - mBuilder->HandleError("Buffer transition not possible"); - } - return false; - } - - mMostRecentBufferUsages[buffer] = usage; - mBuffersTransitioned.insert(buffer); - return true; - } - - bool CommandBufferStateTracker::TransitionTextureUsage(TextureBase* texture, - nxt::TextureUsageBit usage) { - if (!IsExplicitTextureTransitionPossible(texture, usage)) { - if (texture->IsFrozen()) { - mBuilder->HandleError("Texture transition not possible (usage is frozen)"); - } else if (!TextureBase::IsUsagePossible(texture->GetAllowedUsage(), usage)) { - mBuilder->HandleError("Texture transition not possible (usage not allowed)"); - } else if (mTexturesAttached.find(texture) != mTexturesAttached.end()) { - mBuilder->HandleError( - "Texture transition not possible (texture is in use as a framebuffer " - "attachment)"); - } else { - mBuilder->HandleError("Texture transition not possible"); - } - return false; - } - - mMostRecentTextureUsages[texture] = usage; - mTexturesTransitioned.insert(texture); - return true; - } - - bool CommandBufferStateTracker::EnsureTextureUsage(TextureBase* texture, - nxt::TextureUsageBit usage) { - if (texture->HasFrozenUsage(usage)) { - return true; - } - if (!IsInternalTextureTransitionPossible(texture, usage)) { - return false; - } - mMostRecentTextureUsages[texture] = usage; - mTexturesTransitioned.insert(texture); - return true; - } - - bool CommandBufferStateTracker::BufferHasGuaranteedUsageBit(BufferBase* buffer, - nxt::BufferUsageBit usage) const { - ASSERT(usage != nxt::BufferUsageBit::None && nxt::HasZeroOrOneBits(usage)); - if (buffer->HasFrozenUsage(usage)) { - return true; - } - auto it = mMostRecentBufferUsages.find(buffer); - return it != mMostRecentBufferUsages.end() && (it->second & usage); - } - - bool CommandBufferStateTracker::TextureHasGuaranteedUsageBit(TextureBase* texture, - nxt::TextureUsageBit usage) const { - ASSERT(usage != nxt::TextureUsageBit::None && nxt::HasZeroOrOneBits(usage)); - if (texture->HasFrozenUsage(usage)) { - return true; - } - auto it = mMostRecentTextureUsages.find(texture); - return it != mMostRecentTextureUsages.end() && (it->second & usage); - } - - bool CommandBufferStateTracker::IsInternalTextureTransitionPossible( - TextureBase* texture, - nxt::TextureUsageBit usage) const { - ASSERT(usage != nxt::TextureUsageBit::None && nxt::HasZeroOrOneBits(usage)); - if (mTexturesAttached.find(texture) != mTexturesAttached.end()) { - return false; - } - return texture->IsTransitionPossible(usage); - } - - bool CommandBufferStateTracker::IsExplicitTextureTransitionPossible( - TextureBase* texture, - nxt::TextureUsageBit usage) const { - const nxt::TextureUsageBit attachmentUsages = nxt::TextureUsageBit::OutputAttachment; - if (usage & attachmentUsages) { - return false; - } - return IsInternalTextureTransitionPossible(texture, usage); - } - bool CommandBufferStateTracker::RecomputeHaveAspectBindGroups() { if (mAspects[VALIDATION_ASPECT_BIND_GROUPS]) { return true; @@ -314,53 +161,6 @@ namespace backend { return mAspects[VALIDATION_ASPECT_PIPELINE]; } - bool CommandBufferStateTracker::ValidateBindGroupUsages(BindGroupBase* group) const { - const auto& layoutInfo = group->GetLayout()->GetBindingInfo(); - for (size_t i = 0; i < kMaxBindingsPerGroup; ++i) { - if (!layoutInfo.mask[i]) { - continue; - } - - nxt::BindingType type = layoutInfo.types[i]; - switch (type) { - case nxt::BindingType::UniformBuffer: - case nxt::BindingType::StorageBuffer: { - nxt::BufferUsageBit requiredUsage = nxt::BufferUsageBit::None; - switch (type) { - case nxt::BindingType::UniformBuffer: - requiredUsage = nxt::BufferUsageBit::Uniform; - break; - - case nxt::BindingType::StorageBuffer: - requiredUsage = nxt::BufferUsageBit::Storage; - break; - - default: - UNREACHABLE(); - } - - auto buffer = group->GetBindingAsBufferView(i)->GetBuffer(); - if (!BufferHasGuaranteedUsageBit(buffer, requiredUsage)) { - mBuilder->HandleError("Can't guarantee buffer usage needed by bind group"); - return false; - } - } break; - case nxt::BindingType::SampledTexture: { - auto requiredUsage = nxt::TextureUsageBit::Sampled; - - auto texture = group->GetBindingAsTextureView(i)->GetTexture(); - if (!TextureHasGuaranteedUsageBit(texture, requiredUsage)) { - mBuilder->HandleError("Can't guarantee texture usage needed by bind group"); - return false; - } - } break; - case nxt::BindingType::Sampler: - continue; - } - } - return true; - } - bool CommandBufferStateTracker::RevalidateCanDraw() { if (!mAspects[VALIDATION_ASPECT_PIPELINE]) { mBuilder->HandleError("No active render pipeline"); diff --git a/src/backend/CommandBufferStateTracker.h b/src/backend/CommandBufferStateTracker.h index f03cc53e32..5a5f5613be 100644 --- a/src/backend/CommandBufferStateTracker.h +++ b/src/backend/CommandBufferStateTracker.h @@ -31,29 +31,17 @@ namespace backend { // Non-state-modifying validation functions bool ValidateCanCopy() const; - bool ValidateCanUseBufferAs(BufferBase* buffer, nxt::BufferUsageBit usage) const; - bool ValidateCanUseTextureAs(TextureBase* texture, nxt::TextureUsageBit usage) const; bool ValidateCanDispatch(); bool ValidateCanDrawArrays(); bool ValidateCanDrawElements(); // State-modifying methods void EndPass(); - bool BeginRenderPass(RenderPassDescriptorBase* info); bool SetComputePipeline(ComputePipelineBase* pipeline); bool SetRenderPipeline(RenderPipelineBase* pipeline); - bool SetBindGroup(uint32_t index, BindGroupBase* bindgroup); - bool SetIndexBuffer(BufferBase* buffer); - bool SetVertexBuffer(uint32_t index, BufferBase* buffer); - bool TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage); - bool TransitionTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage); - bool EnsureTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage); - - // These collections are copied to the CommandBuffer at build time. These pointers will - // remain valid since they are referenced by the bind groups which are referenced by this - // command buffer. - std::set mBuffersTransitioned; - std::set mTexturesTransitioned; + void SetBindGroup(uint32_t index, BindGroupBase* bindgroup); + bool SetIndexBuffer(); + bool SetVertexBuffer(uint32_t index); private: enum ValidationAspect { @@ -66,20 +54,11 @@ namespace backend { }; using ValidationAspects = std::bitset; - // Usage helper functions - bool BufferHasGuaranteedUsageBit(BufferBase* buffer, nxt::BufferUsageBit usage) const; - bool TextureHasGuaranteedUsageBit(TextureBase* texture, nxt::TextureUsageBit usage) const; - bool IsInternalTextureTransitionPossible(TextureBase* texture, - nxt::TextureUsageBit usage) const; - bool IsExplicitTextureTransitionPossible(TextureBase* texture, - nxt::TextureUsageBit usage) const; - // Queries for lazily evaluated aspects bool RecomputeHaveAspectBindGroups(); bool RecomputeHaveAspectVertexBuffers(); bool HavePipeline() const; - bool ValidateBindGroupUsages(BindGroupBase* group) const; bool RevalidateCanDraw(); void SetPipelineCommon(PipelineBase* pipeline); @@ -93,10 +72,6 @@ namespace backend { std::bitset mInputsSet; PipelineBase* mLastPipeline = nullptr; RenderPipelineBase* mLastRenderPipeline = nullptr; - - std::map mMostRecentBufferUsages; - std::map mMostRecentTextureUsages; - std::set mTexturesAttached; }; } // namespace backend diff --git a/src/backend/Commands.cpp b/src/backend/Commands.cpp index c4b77f1815..0aa3e27048 100644 --- a/src/backend/Commands.cpp +++ b/src/backend/Commands.cpp @@ -111,16 +111,6 @@ namespace backend { commands->NextData(cmd->count); cmd->~SetVertexBuffersCmd(); } break; - case Command::TransitionBufferUsage: { - TransitionBufferUsageCmd* cmd = - commands->NextCommand(); - cmd->~TransitionBufferUsageCmd(); - } break; - case Command::TransitionTextureUsage: { - TransitionTextureUsageCmd* cmd = - commands->NextCommand(); - cmd->~TransitionTextureUsageCmd(); - } break; } } commands->DataWasDestroyed(); @@ -206,14 +196,6 @@ namespace backend { commands->NextData>(cmd->count); commands->NextData(cmd->count); } break; - - case Command::TransitionBufferUsage: - commands->NextCommand(); - break; - - case Command::TransitionTextureUsage: - commands->NextCommand(); - break; } } diff --git a/src/backend/Commands.h b/src/backend/Commands.h index b10882341b..797deb2c1f 100644 --- a/src/backend/Commands.h +++ b/src/backend/Commands.h @@ -46,8 +46,6 @@ namespace backend { SetBindGroup, SetIndexBuffer, SetVertexBuffers, - TransitionBufferUsage, - TransitionTextureUsage, }; struct BeginComputePassCmd {}; @@ -151,18 +149,6 @@ namespace backend { uint32_t count; }; - struct TransitionBufferUsageCmd { - Ref buffer; - nxt::BufferUsageBit usage; - }; - - struct TransitionTextureUsageCmd { - Ref texture; - uint32_t startLevel; - uint32_t levelCount; - nxt::TextureUsageBit usage; - }; - // This needs to be called before the CommandIterator is freed so that the Ref<> present in // the commands have a chance to run their destructor and remove internal references. class CommandIterator; diff --git a/src/backend/Queue.cpp b/src/backend/Queue.cpp index a8d140bc3f..7b3d26d199 100644 --- a/src/backend/Queue.cpp +++ b/src/backend/Queue.cpp @@ -28,8 +28,9 @@ namespace backend { return mDevice; } - bool QueueBase::ValidateSubmitCommand(CommandBufferBase* command) { - return command->ValidateResourceUsagesImmediate(); + bool QueueBase::ValidateSubmitCommand(CommandBufferBase*) { + // TODO(cwallez@chromium.org): Validate resources referenced by command buffers can be used + return true; } } // namespace backend diff --git a/src/backend/SwapChain.cpp b/src/backend/SwapChain.cpp index a2a575241b..beb6e9360d 100644 --- a/src/backend/SwapChain.cpp +++ b/src/backend/SwapChain.cpp @@ -77,10 +77,6 @@ namespace backend { mDevice->HandleError("Tried to present something other than the last NextTexture"); return; } - if (texture->GetUsage() != nxt::TextureUsageBit::Present) { - mDevice->HandleError("Texture has not been transitioned to the Present usage"); - return; - } OnBeforePresent(texture); diff --git a/src/backend/Texture.cpp b/src/backend/Texture.cpp index dd642793d4..0c0255bec2 100644 --- a/src/backend/Texture.cpp +++ b/src/backend/Texture.cpp @@ -75,8 +75,7 @@ namespace backend { mHeight(builder->mHeight), mDepth(builder->mDepth), mNumMipLevels(builder->mNumMipLevels), - mAllowedUsage(builder->mAllowedUsage), - mCurrentUsage(builder->mCurrentUsage) { + mAllowedUsage(builder->mAllowedUsage) { } DeviceBase* TextureBase::GetDevice() const { @@ -104,64 +103,11 @@ namespace backend { nxt::TextureUsageBit TextureBase::GetAllowedUsage() const { return mAllowedUsage; } - nxt::TextureUsageBit TextureBase::GetUsage() const { - return mCurrentUsage; - } TextureViewBuilder* TextureBase::CreateTextureViewBuilder() { return new TextureViewBuilder(mDevice, this); } - bool TextureBase::IsFrozen() const { - return mIsFrozen; - } - - bool TextureBase::HasFrozenUsage(nxt::TextureUsageBit usage) const { - return mIsFrozen && (usage & mAllowedUsage); - } - - bool TextureBase::IsUsagePossible(nxt::TextureUsageBit allowedUsage, - nxt::TextureUsageBit usage) { - bool allowed = (usage & allowedUsage) == usage; - bool singleUse = nxt::HasZeroOrOneBits(usage); - return allowed && singleUse; - } - - bool TextureBase::IsTransitionPossible(nxt::TextureUsageBit usage) const { - if (mIsFrozen) { - return false; - } - if (mCurrentUsage == nxt::TextureUsageBit::Present) { - return false; - } - return IsUsagePossible(mAllowedUsage, usage); - } - - void TextureBase::UpdateUsageInternal(nxt::TextureUsageBit usage) { - ASSERT(IsTransitionPossible(usage)); - mCurrentUsage = usage; - } - - void TextureBase::TransitionUsage(nxt::TextureUsageBit usage) { - if (!IsTransitionPossible(usage)) { - mDevice->HandleError("Texture frozen or usage not allowed"); - return; - } - TransitionUsageImpl(mCurrentUsage, usage); - UpdateUsageInternal(usage); - } - - void TextureBase::FreezeUsage(nxt::TextureUsageBit usage) { - if (!IsTransitionPossible(usage)) { - mDevice->HandleError("Texture frozen or usage not allowed"); - return; - } - mAllowedUsage = usage; - TransitionUsageImpl(mCurrentUsage, usage); - UpdateUsageInternal(usage); - mIsFrozen = true; - } - // TextureBuilder enum TextureSetProperties { @@ -170,7 +116,6 @@ namespace backend { TEXTURE_PROPERTY_FORMAT = 0x4, TEXTURE_PROPERTY_MIP_LEVELS = 0x8, TEXTURE_PROPERTY_ALLOWED_USAGE = 0x10, - TEXTURE_PROPERTY_INITIAL_USAGE = 0x20, }; TextureBuilder::TextureBuilder(DeviceBase* device) : Builder(device) { @@ -185,11 +130,6 @@ namespace backend { return nullptr; } - if (!TextureBase::IsUsagePossible(mAllowedUsage, mCurrentUsage)) { - HandleError("Initial texture usage is not allowed"); - return nullptr; - } - // TODO(cwallez@chromium.org): check stuff based on the dimension return mDevice->CreateTexture(this); @@ -252,16 +192,6 @@ namespace backend { mAllowedUsage = usage; } - void TextureBuilder::SetInitialUsage(nxt::TextureUsageBit usage) { - if ((mPropertiesSet & TEXTURE_PROPERTY_INITIAL_USAGE) != 0) { - HandleError("Texture initial usage property set multiple times"); - return; - } - - mPropertiesSet |= TEXTURE_PROPERTY_INITIAL_USAGE; - mCurrentUsage = usage; - } - // TextureViewBase TextureViewBase::TextureViewBase(TextureViewBuilder* builder) : mTexture(builder->mTexture) { diff --git a/src/backend/Texture.h b/src/backend/Texture.h index 24aa2fbd19..e5f9658340 100644 --- a/src/backend/Texture.h +++ b/src/backend/Texture.h @@ -47,22 +47,10 @@ namespace backend { uint32_t GetDepth() const; uint32_t GetNumMipLevels() const; nxt::TextureUsageBit GetAllowedUsage() const; - nxt::TextureUsageBit GetUsage() const; - bool IsFrozen() const; - bool HasFrozenUsage(nxt::TextureUsageBit usage) const; - static bool IsUsagePossible(nxt::TextureUsageBit allowedUsage, nxt::TextureUsageBit usage); - bool IsTransitionPossible(nxt::TextureUsageBit usage) const; - void UpdateUsageInternal(nxt::TextureUsageBit usage); - DeviceBase* GetDevice() const; // NXT API TextureViewBuilder* CreateTextureViewBuilder(); - void TransitionUsage(nxt::TextureUsageBit usage); - void FreezeUsage(nxt::TextureUsageBit usage); - - virtual void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, - nxt::TextureUsageBit targetUsage) = 0; private: DeviceBase* mDevice; @@ -72,8 +60,6 @@ namespace backend { uint32_t mWidth, mHeight, mDepth; uint32_t mNumMipLevels; nxt::TextureUsageBit mAllowedUsage = nxt::TextureUsageBit::None; - nxt::TextureUsageBit mCurrentUsage = nxt::TextureUsageBit::None; - bool mIsFrozen = false; }; class TextureBuilder : public Builder { @@ -100,7 +86,6 @@ namespace backend { nxt::TextureFormat mFormat; uint32_t mNumMipLevels; nxt::TextureUsageBit mAllowedUsage = nxt::TextureUsageBit::None; - nxt::TextureUsageBit mCurrentUsage = nxt::TextureUsageBit::None; }; class TextureViewBase : public RefCounted { diff --git a/src/backend/d3d12/BufferD3D12.cpp b/src/backend/d3d12/BufferD3D12.cpp index f2dba3ddd4..955c83c2f7 100644 --- a/src/backend/d3d12/BufferD3D12.cpp +++ b/src/backend/d3d12/BufferD3D12.cpp @@ -198,9 +198,6 @@ namespace backend { namespace d3d12 { ToBackend(GetDevice())->GetResourceAllocator()->Release(mResource); } - void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) { - } - BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) { mCbvDesc.BufferLocation = ToBackend(GetBuffer())->GetVA() + GetOffset(); mCbvDesc.SizeInBytes = GetD3D12Size(); diff --git a/src/backend/d3d12/BufferD3D12.h b/src/backend/d3d12/BufferD3D12.h index e6bb6a54ef..2218927c19 100644 --- a/src/backend/d3d12/BufferD3D12.h +++ b/src/backend/d3d12/BufferD3D12.h @@ -43,8 +43,6 @@ namespace backend { namespace d3d12 { void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; void UnmapImpl() override; - void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, - nxt::BufferUsageBit targetUsage) override; ComPtr mResource; bool mFixedResourceState = false; diff --git a/src/backend/d3d12/CommandBufferD3D12.cpp b/src/backend/d3d12/CommandBufferD3D12.cpp index 7c1dd78d84..cfbb8932f6 100644 --- a/src/backend/d3d12/CommandBufferD3D12.cpp +++ b/src/backend/d3d12/CommandBufferD3D12.cpp @@ -408,18 +408,6 @@ namespace backend { namespace d3d12 { } } break; - case Command::TransitionBufferUsage: { - TransitionBufferUsageCmd* cmd = - mCommands.NextCommand(); - cmd->buffer->UpdateUsageInternal(cmd->usage); - } break; - - case Command::TransitionTextureUsage: { - TransitionTextureUsageCmd* cmd = - mCommands.NextCommand(); - cmd->texture->UpdateUsageInternal(cmd->usage); - } break; - default: { UNREACHABLE(); } break; } } @@ -464,6 +452,7 @@ namespace backend { namespace d3d12 { } } } + void CommandBuffer::RecordRenderPass(ComPtr commandList, BindGroupStateTracker* bindingTracker, RenderPassDescriptor* renderPass) { @@ -471,13 +460,6 @@ namespace backend { namespace d3d12 { { for (uint32_t i : IterateBitSet(renderPass->GetColorAttachmentMask())) { auto& attachmentInfo = renderPass->GetColorAttachment(i); - Texture* texture = ToBackend(attachmentInfo.view->GetTexture()); - - // It's already validated that this texture is either frozen to the correct - // usage, or not frozen. - if (!texture->IsFrozen()) { - texture->UpdateUsageInternal(nxt::TextureUsageBit::OutputAttachment); - } // Load op - color if (attachmentInfo.loadOp == nxt::LoadOp::Clear) { @@ -491,12 +473,6 @@ namespace backend { namespace d3d12 { auto& attachmentInfo = renderPass->GetDepthStencilAttachment(); Texture* texture = ToBackend(attachmentInfo.view->GetTexture()); - // It's already validated that this texture is either frozen to the correct - // usage, or not frozen. - if (!texture->IsFrozen()) { - texture->UpdateUsageInternal(nxt::TextureUsageBit::OutputAttachment); - } - // Load op - depth/stencil bool doDepthClear = TextureFormatHasDepth(texture->GetFormat()) && (attachmentInfo.depthLoadOp == nxt::LoadOp::Clear); diff --git a/src/backend/d3d12/TextureD3D12.cpp b/src/backend/d3d12/TextureD3D12.cpp index edba271b4f..d1591920fd 100644 --- a/src/backend/d3d12/TextureD3D12.cpp +++ b/src/backend/d3d12/TextureD3D12.cpp @@ -122,9 +122,8 @@ namespace backend { namespace d3d12 { resourceDescriptor.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; resourceDescriptor.Flags = D3D12ResourceFlags(GetAllowedUsage(), GetFormat()); - mResource = - mDevice->GetResourceAllocator()->Allocate(D3D12_HEAP_TYPE_DEFAULT, resourceDescriptor, - D3D12TextureUsage(GetUsage(), GetFormat())); + mResource = mDevice->GetResourceAllocator()->Allocate( + D3D12_HEAP_TYPE_DEFAULT, resourceDescriptor, D3D12_RESOURCE_STATE_COMMON); mResourcePtr = mResource.Get(); } @@ -174,9 +173,6 @@ namespace backend { namespace d3d12 { mLastUsage = usage; } - void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) { - } - TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) { mSrvDesc.Format = D3D12TextureFormat(GetTexture()->GetFormat()); mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; diff --git a/src/backend/d3d12/TextureD3D12.h b/src/backend/d3d12/TextureD3D12.h index fc837607c8..9466857a43 100644 --- a/src/backend/d3d12/TextureD3D12.h +++ b/src/backend/d3d12/TextureD3D12.h @@ -38,9 +38,6 @@ namespace backend { namespace d3d12 { nxt::TextureUsageBit usage); private: - void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, - nxt::TextureUsageBit targetUsage) override; - Device* mDevice; ComPtr mResource = {}; ID3D12Resource* mResourcePtr = nullptr; diff --git a/src/backend/metal/BufferMTL.h b/src/backend/metal/BufferMTL.h index 384c945a23..740d67b984 100644 --- a/src/backend/metal/BufferMTL.h +++ b/src/backend/metal/BufferMTL.h @@ -38,8 +38,6 @@ namespace backend { namespace metal { void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; void UnmapImpl() override; - void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, - nxt::BufferUsageBit targetUsage) override; id mMtlBuffer = nil; }; diff --git a/src/backend/metal/BufferMTL.mm b/src/backend/metal/BufferMTL.mm index d9a11c9639..805e1424aa 100644 --- a/src/backend/metal/BufferMTL.mm +++ b/src/backend/metal/BufferMTL.mm @@ -68,9 +68,6 @@ namespace backend { namespace metal { // Nothing to do, Metal StorageModeShared buffers are always mapped. } - void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) { - } - BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) { } diff --git a/src/backend/metal/CommandBufferMTL.mm b/src/backend/metal/CommandBufferMTL.mm index 8af7134b1e..0174224a1d 100644 --- a/src/backend/metal/CommandBufferMTL.mm +++ b/src/backend/metal/CommandBufferMTL.mm @@ -304,20 +304,6 @@ namespace backend { namespace metal { destinationBytesPerImage:copy->rowPitch * src.height]; } break; - case Command::TransitionBufferUsage: { - TransitionBufferUsageCmd* cmd = - mCommands.NextCommand(); - - cmd->buffer->UpdateUsageInternal(cmd->usage); - } break; - - case Command::TransitionTextureUsage: { - TransitionTextureUsageCmd* cmd = - mCommands.NextCommand(); - - cmd->texture->UpdateUsageInternal(cmd->usage); - } break; - default: { UNREACHABLE(); } break; } } diff --git a/src/backend/metal/TextureMTL.h b/src/backend/metal/TextureMTL.h index 2619c2c5de..e4934c3053 100644 --- a/src/backend/metal/TextureMTL.h +++ b/src/backend/metal/TextureMTL.h @@ -31,9 +31,6 @@ namespace backend { namespace metal { id GetMTLTexture(); - void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, - nxt::TextureUsageBit targetUsage) override; - private: id mMtlTexture = nil; }; diff --git a/src/backend/metal/TextureMTL.mm b/src/backend/metal/TextureMTL.mm index 27f8763539..4c0f598c74 100644 --- a/src/backend/metal/TextureMTL.mm +++ b/src/backend/metal/TextureMTL.mm @@ -70,7 +70,7 @@ namespace backend { namespace metal { auto desc = [MTLTextureDescriptor new]; [desc autorelease]; desc.textureType = MetalTextureType(GetDimension()); - desc.usage = MetalTextureUsage(GetUsage()); + desc.usage = MetalTextureUsage(GetAllowedUsage()); desc.pixelFormat = MetalPixelFormat(GetFormat()); desc.width = GetWidth(); desc.height = GetHeight(); @@ -96,9 +96,6 @@ namespace backend { namespace metal { return mMtlTexture; } - void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) { - } - TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) { } diff --git a/src/backend/null/NullBackend.cpp b/src/backend/null/NullBackend.cpp index 99f35818ba..797e5838e1 100644 --- a/src/backend/null/NullBackend.cpp +++ b/src/backend/null/NullBackend.cpp @@ -171,9 +171,6 @@ namespace backend { namespace null { void Buffer::UnmapImpl() { } - void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) { - } - // CommandBuffer CommandBuffer::CommandBuffer(CommandBufferBuilder* builder) @@ -184,27 +181,6 @@ namespace backend { namespace null { FreeCommands(&mCommands); } - void CommandBuffer::Execute() { - Command type; - while (mCommands.NextCommandId(&type)) { - switch (type) { - case Command::TransitionBufferUsage: { - TransitionBufferUsageCmd* cmd = - mCommands.NextCommand(); - cmd->buffer->UpdateUsageInternal(cmd->usage); - } break; - case Command::TransitionTextureUsage: { - TransitionTextureUsageCmd* cmd = - mCommands.NextCommand(); - cmd->texture->UpdateUsageInternal(cmd->usage); - } break; - default: - SkipCommand(&mCommands, type); - break; - } - } - } - // Queue Queue::Queue(Device* device) : QueueBase(device) { @@ -213,31 +189,16 @@ namespace backend { namespace null { Queue::~Queue() { } - void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) { + void Queue::Submit(uint32_t, CommandBuffer* const*) { auto operations = ToBackend(GetDevice())->AcquirePendingOperations(); for (auto& operation : operations) { operation->Execute(); } - for (uint32_t i = 0; i < numCommands; ++i) { - commands[i]->Execute(); - } - operations.clear(); } - // Texture - - Texture::Texture(TextureBuilder* builder) : TextureBase(builder) { - } - - Texture::~Texture() { - } - - void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) { - } - // SwapChain SwapChain::SwapChain(SwapChainBuilder* builder) : SwapChainBase(builder) { diff --git a/src/backend/null/NullBackend.h b/src/backend/null/NullBackend.h index 6b9e4a3fce..696141585e 100644 --- a/src/backend/null/NullBackend.h +++ b/src/backend/null/NullBackend.h @@ -55,7 +55,7 @@ namespace backend { namespace null { using Sampler = SamplerBase; using ShaderModule = ShaderModuleBase; class SwapChain; - class Texture; + using Texture = TextureBase; using TextureView = TextureViewBase; struct NullBackendTraits { @@ -140,8 +140,6 @@ namespace backend { namespace null { void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; void UnmapImpl() override; - void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, - nxt::BufferUsageBit targetUsage) override; void MapAsyncImplCommon(uint32_t serial, uint32_t start, uint32_t count, bool isWrite); @@ -153,8 +151,6 @@ namespace backend { namespace null { CommandBuffer(CommandBufferBuilder* builder); ~CommandBuffer(); - void Execute(); - private: CommandIterator mCommands; }; @@ -168,15 +164,6 @@ namespace backend { namespace null { void Submit(uint32_t numCommands, CommandBuffer* const* commands); }; - class Texture : public TextureBase { - public: - Texture(TextureBuilder* builder); - ~Texture(); - - void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, - nxt::TextureUsageBit targetUsage) override; - }; - class SwapChain : public SwapChainBase { public: SwapChain(SwapChainBuilder* builder); diff --git a/src/backend/opengl/BufferGL.cpp b/src/backend/opengl/BufferGL.cpp index e282975c6b..fb642adb51 100644 --- a/src/backend/opengl/BufferGL.cpp +++ b/src/backend/opengl/BufferGL.cpp @@ -54,9 +54,6 @@ namespace backend { namespace opengl { glUnmapBuffer(GL_ARRAY_BUFFER); } - void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) { - } - // BufferView BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) { diff --git a/src/backend/opengl/BufferGL.h b/src/backend/opengl/BufferGL.h index 27678bd581..6cedb08b21 100644 --- a/src/backend/opengl/BufferGL.h +++ b/src/backend/opengl/BufferGL.h @@ -34,8 +34,6 @@ namespace backend { namespace opengl { void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; void UnmapImpl() override; - void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, - nxt::BufferUsageBit targetUsage) override; GLuint mBuffer = 0; }; diff --git a/src/backend/opengl/CommandBufferGL.cpp b/src/backend/opengl/CommandBufferGL.cpp index bd20d7e322..17726811c9 100644 --- a/src/backend/opengl/CommandBufferGL.cpp +++ b/src/backend/opengl/CommandBufferGL.cpp @@ -374,20 +374,6 @@ namespace backend { namespace opengl { glDeleteFramebuffers(1, &readFBO); } break; - case Command::TransitionBufferUsage: { - TransitionBufferUsageCmd* cmd = - mCommands.NextCommand(); - - cmd->buffer->UpdateUsageInternal(cmd->usage); - } break; - - case Command::TransitionTextureUsage: { - TransitionTextureUsageCmd* cmd = - mCommands.NextCommand(); - - cmd->texture->UpdateUsageInternal(cmd->usage); - } break; - default: { UNREACHABLE(); } break; } } diff --git a/src/backend/opengl/TextureGL.cpp b/src/backend/opengl/TextureGL.cpp index 80fb6c2855..203fc05691 100644 --- a/src/backend/opengl/TextureGL.cpp +++ b/src/backend/opengl/TextureGL.cpp @@ -111,9 +111,6 @@ namespace backend { namespace opengl { return GetGLFormatInfo(GetFormat()); } - void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) { - } - // TextureView TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) { diff --git a/src/backend/opengl/TextureGL.h b/src/backend/opengl/TextureGL.h index 50756f41c8..a04e88cebd 100644 --- a/src/backend/opengl/TextureGL.h +++ b/src/backend/opengl/TextureGL.h @@ -37,9 +37,6 @@ namespace backend { namespace opengl { GLenum GetGLTarget() const; TextureFormatInfo GetGLFormat() const; - void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, - nxt::TextureUsageBit targetUsage) override; - private: GLuint mHandle; GLenum mTarget; diff --git a/src/backend/vulkan/BufferVk.cpp b/src/backend/vulkan/BufferVk.cpp index 9c47f16bc6..e4bb71175f 100644 --- a/src/backend/vulkan/BufferVk.cpp +++ b/src/backend/vulkan/BufferVk.cpp @@ -238,9 +238,6 @@ namespace backend { namespace vulkan { // No need to do anything, we keep CPU-visible memory mapped at all time. } - void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) { - } - // MapRequestTracker MapRequestTracker::MapRequestTracker(Device* device) : mDevice(device) { diff --git a/src/backend/vulkan/BufferVk.h b/src/backend/vulkan/BufferVk.h index ed873ec2ac..91db54dc14 100644 --- a/src/backend/vulkan/BufferVk.h +++ b/src/backend/vulkan/BufferVk.h @@ -45,8 +45,6 @@ namespace backend { namespace vulkan { void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; void UnmapImpl() override; - void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, - nxt::BufferUsageBit targetUsage) override; VkBuffer mHandle = VK_NULL_HANDLE; DeviceMemoryAllocation mMemoryAllocation; diff --git a/src/backend/vulkan/CommandBufferVk.cpp b/src/backend/vulkan/CommandBufferVk.cpp index 2fcc2acdf6..637556f292 100644 --- a/src/backend/vulkan/CommandBufferVk.cpp +++ b/src/backend/vulkan/CommandBufferVk.cpp @@ -222,22 +222,6 @@ namespace backend { namespace vulkan { nextPassNumber++; } break; - case Command::TransitionBufferUsage: { - TransitionBufferUsageCmd* cmd = - mCommands.NextCommand(); - - Buffer* buffer = ToBackend(cmd->buffer.Get()); - buffer->UpdateUsageInternal(cmd->usage); - } break; - - case Command::TransitionTextureUsage: { - TransitionTextureUsageCmd* cmd = - mCommands.NextCommand(); - - Texture* texture = ToBackend(cmd->texture.Get()); - texture->UpdateUsageInternal(cmd->usage); - } break; - default: { UNREACHABLE(); } break; } } diff --git a/src/backend/vulkan/TextureVk.cpp b/src/backend/vulkan/TextureVk.cpp index 4b4667078d..7dc12d7ed5 100644 --- a/src/backend/vulkan/TextureVk.cpp +++ b/src/backend/vulkan/TextureVk.cpp @@ -343,9 +343,6 @@ namespace backend { namespace vulkan { mLastUsage = usage; } - void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) { - } - TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) { Device* device = ToBackend(builder->GetDevice()); diff --git a/src/backend/vulkan/TextureVk.h b/src/backend/vulkan/TextureVk.h index 69ca429805..ded7fb9e7c 100644 --- a/src/backend/vulkan/TextureVk.h +++ b/src/backend/vulkan/TextureVk.h @@ -40,9 +40,6 @@ namespace backend { namespace vulkan { void TransitionUsageNow(VkCommandBuffer commands, nxt::TextureUsageBit usage); private: - void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, - nxt::TextureUsageBit targetUsage) override; - VkImage mHandle = VK_NULL_HANDLE; DeviceMemoryAllocation mMemoryAllocation; diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 1b7130a57d..0a525fd944 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -54,7 +54,6 @@ list(APPEND UNITTEST_SOURCES ${VALIDATION_TESTS_DIR}/PushConstantsValidationTests.cpp ${VALIDATION_TESTS_DIR}/RenderPassDescriptorValidationTests.cpp ${VALIDATION_TESTS_DIR}/RenderPipelineValidationTests.cpp - ${VALIDATION_TESTS_DIR}/UsageValidationTests.cpp ${VALIDATION_TESTS_DIR}/VertexBufferValidationTests.cpp ${VALIDATION_TESTS_DIR}/ValidationTest.cpp ${VALIDATION_TESTS_DIR}/ValidationTest.h diff --git a/src/tests/NXTTest.cpp b/src/tests/NXTTest.cpp index 5b8ffeb0cc..5a91018a64 100644 --- a/src/tests/NXTTest.cpp +++ b/src/tests/NXTTest.cpp @@ -212,8 +212,6 @@ std::ostringstream& NXTTest::AddBufferExpectation(const char* file, int line, co // We need to enqueue the copy immediately because by the time we resolve the expectation, // the buffer might have been modified. nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() - .TransitionBufferUsage(source, nxt::BufferUsageBit::TransferSrc) - .TransitionBufferUsage(readback.buffer, nxt::BufferUsageBit::TransferDst) .CopyBufferToBuffer(source, offset, readback.buffer, readback.offset, size) .GetResult(); @@ -244,8 +242,6 @@ std::ostringstream& NXTTest::AddTextureExpectation(const char* file, int line, c // We need to enqueue the copy immediately because by the time we resolve the expectation, // the texture might have been modified. nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() - .TransitionTextureUsage(source, nxt::TextureUsageBit::TransferSrc) - .TransitionBufferUsage(readback.buffer, nxt::BufferUsageBit::TransferDst) .CopyTextureToBuffer(source, x, y, 0, width, height, 1, level, readback.buffer, readback.offset, rowPitch) .GetResult(); @@ -276,7 +272,6 @@ void NXTTest::WaitABit() { void NXTTest::SwapBuffersForCapture() { // Insert a frame boundary for API capture tools. nxt::Texture backBuffer = swapchain.GetNextTexture(); - backBuffer.TransitionUsage(nxt::TextureUsageBit::Present); swapchain.Present(backBuffer); } @@ -295,7 +290,6 @@ NXTTest::ReadbackReservation NXTTest::ReserveReadback(uint32_t readbackSize) { slot.buffer = device.CreateBufferBuilder() .SetSize(readbackSize) .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); ReadbackReservation reservation; @@ -316,7 +310,6 @@ void NXTTest::MapSlotsSynchronously() { auto userdata = new MapReadUserdata{this, i}; auto& slot = mReadbackSlots[i]; - slot.buffer.TransitionUsage(nxt::BufferUsageBit::MapRead); slot.buffer.MapReadAsync(0, slot.bufferSize, SlotMapReadCallback, static_cast(reinterpret_cast(userdata))); } diff --git a/src/tests/end2end/BasicTests.cpp b/src/tests/end2end/BasicTests.cpp index fa400ee1a0..33883c4ea2 100644 --- a/src/tests/end2end/BasicTests.cpp +++ b/src/tests/end2end/BasicTests.cpp @@ -25,7 +25,6 @@ TEST_P(BasicTests, BufferSetSubData) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(4) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); uint8_t value = 187; diff --git a/src/tests/end2end/BlendStateTests.cpp b/src/tests/end2end/BlendStateTests.cpp index a4c4c5f47b..5fe7fb2f52 100644 --- a/src/tests/end2end/BlendStateTests.cpp +++ b/src/tests/end2end/BlendStateTests.cpp @@ -95,7 +95,7 @@ class BlendStateTest : public NXTTest { uint32_t bufferSize = static_cast(4 * N * sizeof(float)); - nxt::Buffer buffer = utils::CreateFrozenBufferFromData(device, &data, bufferSize, nxt::BufferUsageBit::Uniform); + nxt::Buffer buffer = utils::CreateBufferFromData(device, &data, bufferSize, nxt::BufferUsageBit::Uniform); nxt::BufferView view = buffer.CreateBufferViewBuilder() .SetExtent(0, bufferSize) @@ -110,8 +110,6 @@ class BlendStateTest : public NXTTest { // Test that after drawing a triangle with the base color, and then the given triangle spec, the color is as expected void DoSingleSourceTest(RGBA8 base, const TriangleSpec& triangle, const RGBA8& expected) { - renderPass.color.TransitionUsage(nxt::TextureUsageBit::OutputAttachment); - nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() .BeginRenderPass(renderPass.renderPassInfo) // First use the base pipeline to draw a triangle with no blending @@ -700,7 +698,6 @@ TEST_P(BlendStateTest, IndependentBlendState) { .SetFormat(nxt::TextureFormat::R8G8B8A8Unorm) .SetMipLevels(1) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::TransferSrc) - .SetInitialUsage(nxt::TextureUsageBit::OutputAttachment) .GetResult(); renderTargetViews[i] = renderTargets[i].CreateTextureViewBuilder().GetResult(); } @@ -789,11 +786,6 @@ TEST_P(BlendStateTest, IndependentBlendState) { RGBA8 expected2 = color2; RGBA8 expected3 = min(color3, base); - renderTargets[0].TransitionUsage(nxt::TextureUsageBit::OutputAttachment); - renderTargets[1].TransitionUsage(nxt::TextureUsageBit::OutputAttachment); - renderTargets[2].TransitionUsage(nxt::TextureUsageBit::OutputAttachment); - renderTargets[3].TransitionUsage(nxt::TextureUsageBit::OutputAttachment); - nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() .BeginRenderPass(renderpass) .SetRenderPipeline(basePipeline) diff --git a/src/tests/end2end/BufferTests.cpp b/src/tests/end2end/BufferTests.cpp index a45092aa54..005014f326 100644 --- a/src/tests/end2end/BufferTests.cpp +++ b/src/tests/end2end/BufferTests.cpp @@ -46,13 +46,11 @@ TEST_P(BufferMapReadTests, SmallReadAtZero) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(1) .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); uint8_t myData = 187; buffer.SetSubData(0, sizeof(myData), &myData); - buffer.TransitionUsage(nxt::BufferUsageBit::MapRead); const void* mappedData = MapReadAsyncAndWait(buffer, 0, 1); ASSERT_EQ(myData, *reinterpret_cast(mappedData)); @@ -64,13 +62,11 @@ TEST_P(BufferMapReadTests, SmallReadAtOffset) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(4000) .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); uint8_t myData = 234; buffer.SetSubData(2048, sizeof(myData), &myData); - buffer.TransitionUsage(nxt::BufferUsageBit::MapRead); const void* mappedData = MapReadAsyncAndWait(buffer, 2048, 4); ASSERT_EQ(myData, *reinterpret_cast(mappedData)); @@ -82,13 +78,11 @@ TEST_P(BufferMapReadTests, SmallReadAtUnalignedOffset) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(4000) .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); uint8_t myData = 213; buffer.SetSubData(3, 1, &myData); - buffer.TransitionUsage(nxt::BufferUsageBit::MapRead); const void* mappedData = MapReadAsyncAndWait(buffer, 3, 1); ASSERT_EQ(myData, *reinterpret_cast(mappedData)); @@ -106,12 +100,10 @@ TEST_P(BufferMapReadTests, LargeRead) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(static_cast(kDataSize * sizeof(uint32_t))) .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); buffer.SetSubData(0, kDataSize * sizeof(uint32_t), reinterpret_cast(myData.data())); - buffer.TransitionUsage(nxt::BufferUsageBit::MapRead); const void* mappedData = MapReadAsyncAndWait(buffer, 0, static_cast(kDataSize * sizeof(uint32_t))); ASSERT_EQ(0, memcmp(mappedData, myData.data(), kDataSize * sizeof(uint32_t))); @@ -150,7 +142,6 @@ TEST_P(BufferMapWriteTests, SmallWriteAtZero) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(4) .SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc) - .SetInitialUsage(nxt::BufferUsageBit::MapWrite) .GetResult(); uint32_t myData = 2934875; @@ -166,7 +157,6 @@ TEST_P(BufferMapWriteTests, SmallWriteAtOffset) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(4000) .SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc) - .SetInitialUsage(nxt::BufferUsageBit::MapWrite) .GetResult(); uint32_t myData = 2934875; @@ -188,7 +178,6 @@ TEST_P(BufferMapWriteTests, LargeWrite) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(static_cast(kDataSize * sizeof(uint32_t))) .SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc) - .SetInitialUsage(nxt::BufferUsageBit::MapWrite) .GetResult(); void* mappedData = MapWriteAsyncAndWait(buffer, 0, kDataSize * sizeof(uint32_t)); @@ -208,7 +197,6 @@ TEST_P(BufferSetSubDataTests, SmallDataAtZero) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(1) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); uint8_t value = 171; @@ -222,7 +210,6 @@ TEST_P(BufferSetSubDataTests, SmallDataAtOffset) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(4000) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); constexpr uint32_t kOffset = 2000; @@ -246,7 +233,6 @@ TEST_P(BufferSetSubDataTests, ManySetSubData) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(kSize) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); std::vector expectedData; @@ -265,7 +251,6 @@ TEST_P(BufferSetSubDataTests, LargeSetSubData) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(kSize) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); std::vector expectedData; diff --git a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp index 7be1e7d569..ef8a0112f3 100644 --- a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp +++ b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp @@ -48,7 +48,6 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) { .SetSize(kNumUints * sizeof(uint32_t)) .SetAllowedUsage(nxt::BufferUsageBit::Storage | nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); std::array expected; for (uint32_t i = 0; i < kNumUints; ++i) { @@ -65,7 +64,6 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) { .SetSize(kNumUints * sizeof(uint32_t)) .SetAllowedUsage(nxt::BufferUsageBit::Storage | nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); std::array zero{}; dst.SetSubData(0, sizeof(zero), reinterpret_cast(zero.data())); @@ -80,8 +78,6 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) { .SetBufferViews(1, 1, &dstView) .GetResult(); auto commands = device.CreateCommandBufferBuilder() - .TransitionBufferUsage(src, nxt::BufferUsageBit::Storage) - .TransitionBufferUsage(dst, nxt::BufferUsageBit::Storage) .BeginComputePass() .SetComputePipeline(pipeline) .SetBindGroup(0, bindGroup) diff --git a/src/tests/end2end/CopyTests.cpp b/src/tests/end2end/CopyTests.cpp index dd928bee10..6b7d632734 100644 --- a/src/tests/end2end/CopyTests.cpp +++ b/src/tests/end2end/CopyTests.cpp @@ -89,12 +89,11 @@ class CopyTests_T2B : public CopyTests { // Create an upload buffer and use it to populate the `level` mip of the texture std::vector textureData(texelCount); FillTextureData(width, height, rowPitch / kBytesPerTexel, textureData.data()); - nxt::Buffer uploadBuffer = utils::CreateFrozenBufferFromData(device, textureData.data(), static_cast(sizeof(RGBA8) * textureData.size()), nxt::BufferUsageBit::TransferSrc); + nxt::Buffer uploadBuffer = utils::CreateBufferFromData(device, textureData.data(), static_cast(sizeof(RGBA8) * textureData.size()), nxt::BufferUsageBit::TransferSrc); nxt::CommandBuffer commands[2]; commands[0] = device.CreateCommandBufferBuilder() - .TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst) .CopyBufferToTexture(uploadBuffer, 0, rowPitch, texture, 0, 0, 0, width, height, 1, textureSpec.level) .GetResult(); @@ -104,15 +103,12 @@ class CopyTests_T2B : public CopyTests { nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(bufferSpec.size) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); std::vector emptyData(bufferSpec.size / kBytesPerTexel); buffer.SetSubData(0, static_cast(emptyData.size() * sizeof(RGBA8)), reinterpret_cast(emptyData.data())); // Copy the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] from the `level` mip into the buffer at the specified `offset` and `rowPitch` commands[1] = device.CreateCommandBufferBuilder() - .TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferSrc) - .TransitionBufferUsage(buffer, nxt::BufferUsageBit::TransferDst) .CopyTextureToBuffer(texture, textureSpec.x, textureSpec.y, 0, textureSpec.copyWidth, textureSpec.copyHeight, 1, textureSpec.level, buffer, bufferSpec.offset, bufferSpec.rowPitch) .GetResult(); @@ -154,7 +150,6 @@ protected: nxt::Buffer buffer = device.CreateBufferBuilder() .SetSize(bufferSpec.size) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); std::vector bufferData(bufferSpec.size / kBytesPerTexel); FillBufferData(bufferData.data(), bufferData.size()); @@ -182,18 +177,15 @@ protected: uint32_t texelCount = texelsPerRow * (height - 1) + width; std::vector emptyData(texelCount); - nxt::Buffer uploadBuffer = utils::CreateFrozenBufferFromData(device, emptyData.data(), static_cast(sizeof(RGBA8) * emptyData.size()), nxt::BufferUsageBit::TransferSrc); + nxt::Buffer uploadBuffer = utils::CreateBufferFromData(device, emptyData.data(), static_cast(sizeof(RGBA8) * emptyData.size()), nxt::BufferUsageBit::TransferSrc); commands[0] = device.CreateCommandBufferBuilder() - .TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst) .CopyBufferToTexture(uploadBuffer, 0, rowPitch, texture, 0, 0, 0, width, height, 1, textureSpec.level) .GetResult(); } // Copy to the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] at the `level` mip from the buffer at the specified `offset` and `rowPitch` commands[1] = device.CreateCommandBufferBuilder() - .TransitionBufferUsage(buffer, nxt::BufferUsageBit::TransferSrc) - .TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst) .CopyBufferToTexture(buffer, bufferSpec.offset, bufferSpec.rowPitch, texture, textureSpec.x, textureSpec.y, 0, textureSpec.copyWidth, textureSpec.copyHeight, 1, textureSpec.level) .GetResult(); diff --git a/src/tests/end2end/DepthStencilStateTests.cpp b/src/tests/end2end/DepthStencilStateTests.cpp index ba752a5ad8..7984323a0a 100644 --- a/src/tests/end2end/DepthStencilStateTests.cpp +++ b/src/tests/end2end/DepthStencilStateTests.cpp @@ -30,7 +30,6 @@ class DepthStencilStateTest : public NXTTest { .SetFormat(nxt::TextureFormat::R8G8B8A8Unorm) .SetMipLevels(1) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::TransferSrc) - .SetInitialUsage(nxt::TextureUsageBit::OutputAttachment) .GetResult(); renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult(); @@ -41,7 +40,6 @@ class DepthStencilStateTest : public NXTTest { .SetFormat(nxt::TextureFormat::D32FloatS8Uint) .SetMipLevels(1) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) - .SetInitialUsage(nxt::TextureUsageBit::OutputAttachment) .GetResult(); depthTextureView = depthTexture.CreateTextureViewBuilder().GetResult(); @@ -193,7 +191,6 @@ class DepthStencilStateTest : public NXTTest { float depth; }; - renderTarget.TransitionUsage(nxt::TextureUsageBit::OutputAttachment); builder.BeginRenderPass(renderpass); for (size_t i = 0; i < testParams.size(); ++i) { @@ -204,7 +201,7 @@ class DepthStencilStateTest : public NXTTest { test.depth, }; // Upload a buffer for each triangle's depth and color data - nxt::Buffer buffer = utils::CreateFrozenBufferFromData(device, &data, sizeof(TriangleData), nxt::BufferUsageBit::Uniform); + nxt::Buffer buffer = utils::CreateBufferFromData(device, &data, sizeof(TriangleData), nxt::BufferUsageBit::Uniform); nxt::BufferView view = buffer.CreateBufferViewBuilder() .SetExtent(0, sizeof(TriangleData)) diff --git a/src/tests/end2end/DrawElementsTests.cpp b/src/tests/end2end/DrawElementsTests.cpp index 4e58675602..f43bf4862e 100644 --- a/src/tests/end2end/DrawElementsTests.cpp +++ b/src/tests/end2end/DrawElementsTests.cpp @@ -55,13 +55,13 @@ class DrawElementsTest : public NXTTest { .SetInputState(inputState) .GetResult(); - vertexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Vertex, { + vertexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Vertex, { -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f }); - indexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Index, { + indexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Index, { 0, 1, 2, 0, 3, 1 }); } diff --git a/src/tests/end2end/IndexFormatTests.cpp b/src/tests/end2end/IndexFormatTests.cpp index f2610bc69d..a47f0b4113 100644 --- a/src/tests/end2end/IndexFormatTests.cpp +++ b/src/tests/end2end/IndexFormatTests.cpp @@ -66,14 +66,14 @@ class IndexFormatTest : public NXTTest { TEST_P(IndexFormatTest, Uint32) { nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint32); - nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Vertex, { + nxt::Buffer vertexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Vertex, { -1.0f, 1.0f, 0.0f, 1.0f, // Note Vertices[0] = Vertices[1] -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f }); // If this is interpreted as Uint16, then it would be 0, 1, 0, ... and would draw nothing. - nxt::Buffer indexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Index, { + nxt::Buffer indexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Index, { 1, 2, 3 }); @@ -96,13 +96,13 @@ TEST_P(IndexFormatTest, Uint32) { TEST_P(IndexFormatTest, Uint16) { nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint16); - nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Vertex, { + nxt::Buffer vertexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Vertex, { -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f }); // If this is interpreted as uint32, it will have index 1 and 2 be both 0 and render nothing - nxt::Buffer indexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Index, { + nxt::Buffer indexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Index, { 1, 2, 0, 0, 0, 0 }); @@ -137,14 +137,14 @@ TEST_P(IndexFormatTest, Uint16) { TEST_P(IndexFormatTest, Uint32PrimitiveRestart) { nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint32); - nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Vertex, { + nxt::Buffer vertexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Vertex, { 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, }); - nxt::Buffer indexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Index, { + nxt::Buffer indexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Index, { 0, 1, 2, 0xFFFFFFFFu, 3, 4, 2, }); @@ -169,14 +169,14 @@ TEST_P(IndexFormatTest, Uint32PrimitiveRestart) { TEST_P(IndexFormatTest, Uint16PrimitiveRestart) { nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint16); - nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Vertex, { + nxt::Buffer vertexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Vertex, { 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, }); - nxt::Buffer indexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Index, { + nxt::Buffer indexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Index, { 0, 1, 2, 0xFFFFu, 3, 4, 2, }); @@ -209,14 +209,14 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) { nxt::RenderPipeline pipeline32 = MakeTestPipeline(nxt::IndexFormat::Uint32); nxt::RenderPipeline pipeline16 = MakeTestPipeline(nxt::IndexFormat::Uint16); - nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Vertex, { + nxt::Buffer vertexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Vertex, { -1.0f, 1.0f, 0.0f, 1.0f, // Note Vertices[0] = Vertices[1] -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f }); // If this is interpreted as Uint16, then it would be 0, 1, 0, ... and would draw nothing. - nxt::Buffer indexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Index, { + nxt::Buffer indexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Index, { 1, 2, 3 }); @@ -244,12 +244,12 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) { TEST_P(IndexFormatTest, DISABLED_SetIndexBufferBeforeSetPipeline) { nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint32); - nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Vertex, { + nxt::Buffer vertexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Vertex, { -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f }); - nxt::Buffer indexBuffer = utils::CreateFrozenBufferFromData(device, nxt::BufferUsageBit::Index, { + nxt::Buffer indexBuffer = utils::CreateBufferFromData(device, nxt::BufferUsageBit::Index, { 0, 1, 2 }); diff --git a/src/tests/end2end/InputStateTests.cpp b/src/tests/end2end/InputStateTests.cpp index 5326889573..1ccfc2d5e7 100644 --- a/src/tests/end2end/InputStateTests.cpp +++ b/src/tests/end2end/InputStateTests.cpp @@ -155,7 +155,7 @@ class InputStateTest : public NXTTest { template nxt::Buffer MakeVertexBuffer(std::vector data) { - return utils::CreateFrozenBufferFromData(device, data.data(), static_cast(data.size() * sizeof(T)), nxt::BufferUsageBit::Vertex); + return utils::CreateBufferFromData(device, data.data(), static_cast(data.size() * sizeof(T)), nxt::BufferUsageBit::Vertex); } struct DrawVertexBuffer { @@ -168,7 +168,6 @@ class InputStateTest : public NXTTest { nxt::CommandBufferBuilder builder = device.CreateCommandBufferBuilder(); - renderPass.color.TransitionUsage(nxt::TextureUsageBit::OutputAttachment); builder.BeginRenderPass(renderPass.renderPassInfo) .SetRenderPipeline(pipeline); diff --git a/src/tests/end2end/PrimitiveTopologyTests.cpp b/src/tests/end2end/PrimitiveTopologyTests.cpp index eeb41402a2..b3f72a6bd0 100644 --- a/src/tests/end2end/PrimitiveTopologyTests.cpp +++ b/src/tests/end2end/PrimitiveTopologyTests.cpp @@ -169,7 +169,7 @@ class PrimitiveTopologyTest : public NXTTest { .SetInput(0, 4 * sizeof(float), nxt::InputStepMode::Vertex) .GetResult(); - vertexBuffer = utils::CreateFrozenBufferFromData(device, kVertices, sizeof(kVertices), nxt::BufferUsageBit::Vertex); + vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices), nxt::BufferUsageBit::Vertex); } struct LocationSpec { @@ -193,7 +193,6 @@ class PrimitiveTopologyTest : public NXTTest { .SetPrimitiveTopology(primitiveTopology) .GetResult(); - renderPass.color.TransitionUsage(nxt::TextureUsageBit::OutputAttachment); static const uint32_t zeroOffset = 0; nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() .BeginRenderPass(renderPass.renderPassInfo) diff --git a/src/tests/end2end/PushConstantTests.cpp b/src/tests/end2end/PushConstantTests.cpp index f70a0a1921..75ecb9dc16 100644 --- a/src/tests/end2end/PushConstantTests.cpp +++ b/src/tests/end2end/PushConstantTests.cpp @@ -33,7 +33,6 @@ class PushConstantTest: public NXTTest { nxt::Buffer buf1 = device.CreateBufferBuilder() .SetSize(4) .SetAllowedUsage(nxt::BufferUsageBit::Storage | nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); uint32_t one = 1; buf1.SetSubData(0, sizeof(one), reinterpret_cast(&one)); @@ -42,7 +41,6 @@ class PushConstantTest: public NXTTest { .SetSize(4) .SetAllowedUsage(nxt::BufferUsageBit::Storage) .GetResult(); - buf2.FreezeUsage(nxt::BufferUsageBit::Storage); nxt::ShaderStageBit kAllStages = nxt::ShaderStageBit::Compute | nxt::ShaderStageBit::Fragment | nxt::ShaderStageBit::Vertex; constexpr nxt::ShaderStageBit kNoStages{}; @@ -213,7 +211,6 @@ TEST_P(PushConstantTest, ComputePassDefaultsToZero) { uint32_t notZero = 42; nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() - .TransitionBufferUsage(binding.resultBuffer, nxt::BufferUsageBit::Storage) .BeginComputePass() // Test compute push constants are set to zero by default. .SetComputePipeline(pipeline) @@ -273,7 +270,6 @@ TEST_P(PushConstantTest, VariousConstantTypes) { nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() - .TransitionBufferUsage(binding.resultBuffer, nxt::BufferUsageBit::Storage) .BeginComputePass() .SetPushConstants(nxt::ShaderStageBit::Compute, 0, 3, reinterpret_cast(&values)) .SetComputePipeline(pipeline) @@ -300,8 +296,6 @@ TEST_P(PushConstantTest, InheritThroughPipelineLayoutChange) { uint32_t one = 1; uint32_t two = 2; nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() - .TransitionBufferUsage(binding1.resultBuffer, nxt::BufferUsageBit::Storage) - .TransitionBufferUsage(binding2.resultBuffer, nxt::BufferUsageBit::Storage) .BeginComputePass() // Set Push constant before there is a pipeline set .SetPushConstants(nxt::ShaderStageBit::Compute, 0, 1, &one) @@ -335,7 +329,6 @@ TEST_P(PushConstantTest, SetAllConstantsToNonZero) { nxt::ComputePipeline pipeline = MakeTestComputePipeline(binding.layout, spec); nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() - .TransitionBufferUsage(binding.resultBuffer, nxt::BufferUsageBit::Storage) .BeginComputePass() .SetPushConstants(nxt::ShaderStageBit::Compute, 0, kMaxPushConstants, &values[0]) .SetComputePipeline(pipeline) diff --git a/src/tests/end2end/RenderPassLoadOpTests.cpp b/src/tests/end2end/RenderPassLoadOpTests.cpp index 9d2983ed32..fd551ba051 100644 --- a/src/tests/end2end/RenderPassLoadOpTests.cpp +++ b/src/tests/end2end/RenderPassLoadOpTests.cpp @@ -61,7 +61,6 @@ class RenderPassLoadOpTests : public NXTTest { .SetFormat(nxt::TextureFormat::R8G8B8A8Unorm) .SetMipLevels(1) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::TransferSrc) - .SetInitialUsage(nxt::TextureUsageBit::OutputAttachment) .GetResult(); renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult(); diff --git a/src/tests/end2end/SamplerTests.cpp b/src/tests/end2end/SamplerTests.cpp index f8324de8d7..81c16a21e8 100644 --- a/src/tests/end2end/SamplerTests.cpp +++ b/src/tests/end2end/SamplerTests.cpp @@ -41,7 +41,6 @@ protected: void SetUp() override { NXTTest::SetUp(); mRenderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); - mRenderPass.color.TransitionUsage(nxt::TextureUsageBit::OutputAttachment); mBindGroupLayout = utils::MakeBindGroupLayout( device, { @@ -97,14 +96,12 @@ protected: data[0] = data[rowPixels + 1] = black; data[1] = data[rowPixels] = white; - nxt::Buffer stagingBuffer = utils::CreateFrozenBufferFromData(device, data, sizeof(data), nxt::BufferUsageBit::TransferSrc); + nxt::Buffer stagingBuffer = utils::CreateBufferFromData(device, data, sizeof(data), nxt::BufferUsageBit::TransferSrc); nxt::CommandBuffer copy = device.CreateCommandBufferBuilder() - .TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst) .CopyBufferToTexture(stagingBuffer, 0, 256, texture, 0, 0, 0, 2, 2, 1, 0) .GetResult(); queue.Submit(1, ©); - texture.FreezeUsage(nxt::TextureUsageBit::Sampled); mTextureView = texture.CreateTextureViewBuilder().GetResult(); } diff --git a/src/tests/unittests/WireTests.cpp b/src/tests/unittests/WireTests.cpp index bde79553e4..4cb177c699 100644 --- a/src/tests/unittests/WireTests.cpp +++ b/src/tests/unittests/WireTests.cpp @@ -483,8 +483,8 @@ TEST_F(WireTests, CallsSkippedAfterBuilderError) { nxtBuffer buffer = nxtBufferBuilderGetResult(bufferBuilder); // Hey look an error! // These calls will be skipped because of the error - nxtBufferTransitionUsage(buffer, NXT_BUFFER_USAGE_BIT_UNIFORM); - nxtCommandBufferBuilderTransitionBufferUsage(cmdBufBuilder, buffer, NXT_BUFFER_USAGE_BIT_UNIFORM); + nxtBufferSetSubData(buffer, 0, 0, nullptr); + nxtCommandBufferBuilderSetIndexBuffer(cmdBufBuilder, buffer, 0); nxtCommandBufferBuilderGetResult(cmdBufBuilder); nxtCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder(); @@ -502,8 +502,8 @@ TEST_F(WireTests, CallsSkippedAfterBuilderError) { return nullptr; })); - EXPECT_CALL(api, BufferTransitionUsage(_, _)).Times(0); - EXPECT_CALL(api, CommandBufferBuilderTransitionBufferUsage(_, _, _)).Times(0); + EXPECT_CALL(api, BufferSetSubData(_, _, _, _)).Times(0); + EXPECT_CALL(api, CommandBufferBuilderSetIndexBuffer(_, _, _)).Times(0); EXPECT_CALL(api, CommandBufferBuilderGetResult(_)).Times(0); FlushClient(); diff --git a/src/tests/unittests/validation/BindGroupValidationTests.cpp b/src/tests/unittests/validation/BindGroupValidationTests.cpp index 209ab02627..4f9cf9e4a7 100644 --- a/src/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp @@ -26,7 +26,6 @@ TEST_F(BindGroupValidationTest, BufferViewOffset) { auto buffer = device.CreateBufferBuilder() .SetAllowedUsage(nxt::BufferUsageBit::Uniform) - .SetInitialUsage(nxt::BufferUsageBit::Uniform) .SetSize(512) .GetResult(); diff --git a/src/tests/unittests/validation/BufferValidationTests.cpp b/src/tests/unittests/validation/BufferValidationTests.cpp index 5836c0b11f..d2edd4c974 100644 --- a/src/tests/unittests/validation/BufferValidationTests.cpp +++ b/src/tests/unittests/validation/BufferValidationTests.cpp @@ -46,21 +46,18 @@ class BufferValidationTest : public ValidationTest { return device.CreateBufferBuilder() .SetSize(size) .SetAllowedUsage(nxt::BufferUsageBit::MapRead) - .SetInitialUsage(nxt::BufferUsageBit::MapRead) .GetResult(); } nxt::Buffer CreateMapWriteBuffer(uint32_t size) { return device.CreateBufferBuilder() .SetSize(size) .SetAllowedUsage(nxt::BufferUsageBit::MapWrite) - .SetInitialUsage(nxt::BufferUsageBit::MapWrite) .GetResult(); } nxt::Buffer CreateSetSubDataBuffer(uint32_t size) { return device.CreateBufferBuilder() .SetSize(size) .SetAllowedUsage(nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); } @@ -86,15 +83,6 @@ class BufferValidationTest : public ValidationTest { // Test case where creation should succeed TEST_F(BufferValidationTest, CreationSuccess) { // Success - { - nxt::Buffer buf = AssertWillBeSuccess(device.CreateBufferBuilder()) - .SetSize(4) - .SetAllowedUsage(nxt::BufferUsageBit::Uniform) - .SetInitialUsage(nxt::BufferUsageBit::Uniform) - .GetResult(); - } - - // Success, when no initial usage is set { nxt::Buffer buf = AssertWillBeSuccess(device.CreateBufferBuilder()) .SetSize(4) @@ -111,7 +99,6 @@ TEST_F(BufferValidationTest, CreationDuplicates) { .SetSize(4) .SetSize(3) .SetAllowedUsage(nxt::BufferUsageBit::Uniform) - .SetInitialUsage(nxt::BufferUsageBit::Uniform) .GetResult(); } @@ -121,28 +108,8 @@ TEST_F(BufferValidationTest, CreationDuplicates) { .SetSize(4) .SetAllowedUsage(nxt::BufferUsageBit::Vertex) .SetAllowedUsage(nxt::BufferUsageBit::Uniform) - .SetInitialUsage(nxt::BufferUsageBit::Uniform) .GetResult(); } - - // When initial usage is specified multiple times - { - nxt::Buffer buf = AssertWillBeError(device.CreateBufferBuilder()) - .SetSize(4) - .SetAllowedUsage(nxt::BufferUsageBit::Uniform | nxt::BufferUsageBit::Vertex) - .SetInitialUsage(nxt::BufferUsageBit::Uniform) - .SetInitialUsage(nxt::BufferUsageBit::Vertex) - .GetResult(); - } -} - -// Test failure when the initial usage isn't a subset of the allowed usage -TEST_F(BufferValidationTest, CreationInitialNotSubsetOfAllowed) { - nxt::Buffer buf = AssertWillBeError(device.CreateBufferBuilder()) - .SetSize(4) - .SetAllowedUsage(nxt::BufferUsageBit::Uniform) - .SetInitialUsage(nxt::BufferUsageBit::Vertex) - .GetResult(); } // Test failure when required properties are missing @@ -251,8 +218,7 @@ TEST_F(BufferValidationTest, MapWriteOutOfRange) { TEST_F(BufferValidationTest, MapReadWrongUsage) { nxt::Buffer buf = device.CreateBufferBuilder() .SetSize(4) - .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) + .SetAllowedUsage(nxt::BufferUsageBit::TransferDst) .GetResult(); nxt::CallbackUserdata userdata = 40600; @@ -266,8 +232,7 @@ TEST_F(BufferValidationTest, MapReadWrongUsage) { TEST_F(BufferValidationTest, MapWriteWrongUsage) { nxt::Buffer buf = device.CreateBufferBuilder() .SetSize(4) - .SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc) - .SetInitialUsage(nxt::BufferUsageBit::TransferSrc) + .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc) .GetResult(); nxt::CallbackUserdata userdata = 40600; @@ -505,8 +470,7 @@ TEST_F(BufferValidationTest, SetSubDataOutOfBounds) { TEST_F(BufferValidationTest, SetSubDataWrongUsage) { nxt::Buffer buf = device.CreateBufferBuilder() .SetSize(1) - .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Vertex) - .SetInitialUsage(nxt::BufferUsageBit::Vertex) + .SetAllowedUsage(nxt::BufferUsageBit::Vertex) .GetResult(); uint8_t foo = 0; diff --git a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp index efbff708bd..d268090f70 100644 --- a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp +++ b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp @@ -23,11 +23,10 @@ class CopyCommandTest : public ValidationTest { .SetSize(size) .SetAllowedUsage(usage) .GetResult(); - buf.FreezeUsage(usage); return buf; } - nxt::Texture CreateFrozen2DTexture(uint32_t width, uint32_t height, uint32_t levels, + nxt::Texture Create2DTexture(uint32_t width, uint32_t height, uint32_t levels, nxt::TextureFormat format, nxt::TextureUsageBit usage) { nxt::Texture tex = AssertWillBeSuccess(device.CreateTextureBuilder()) .SetDimension(nxt::TextureDimension::e2D) @@ -36,7 +35,6 @@ class CopyCommandTest : public ValidationTest { .SetMipLevels(levels) .SetAllowedUsage(usage) .GetResult(); - tex.FreezeUsage(usage); return tex; } @@ -123,7 +121,7 @@ class CopyCommandTest_B2T : public CopyCommandTest { TEST_F(CopyCommandTest_B2T, Success) { uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); nxt::Buffer source = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); - nxt::Texture destination = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture destination = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferDst); // Different copies, including some that touch the OOB condition @@ -169,7 +167,7 @@ TEST_F(CopyCommandTest_B2T, Success) { TEST_F(CopyCommandTest_B2T, OutOfBoundsOnBuffer) { uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); nxt::Buffer source = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); - nxt::Texture destination = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture destination = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferDst); // OOB on the buffer because we copy too many pixels @@ -209,7 +207,7 @@ TEST_F(CopyCommandTest_B2T, OutOfBoundsOnBuffer) { TEST_F(CopyCommandTest_B2T, OutOfBoundsOnTexture) { uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); nxt::Buffer source = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); - nxt::Texture destination = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture destination = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferDst); // OOB on the texture because x + width overflows @@ -244,7 +242,7 @@ TEST_F(CopyCommandTest_B2T, OutOfBoundsOnTexture) { // Test that we force Z=0 and Depth=1 on copies to 2D textures TEST_F(CopyCommandTest_B2T, ZDepthConstraintFor2DTextures) { nxt::Buffer source = CreateFrozenBuffer(16 * 4, nxt::BufferUsageBit::TransferSrc); - nxt::Texture destination = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture destination = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferDst); // Z=1 on an empty copy still errors @@ -266,9 +264,9 @@ TEST_F(CopyCommandTest_B2T, ZDepthConstraintFor2DTextures) { TEST_F(CopyCommandTest_B2T, IncorrectUsage) { nxt::Buffer source = CreateFrozenBuffer(16 * 4, nxt::BufferUsageBit::TransferSrc); nxt::Buffer vertex = CreateFrozenBuffer(16 * 4, nxt::BufferUsageBit::Vertex); - nxt::Texture destination = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture destination = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferDst); - nxt::Texture sampled = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture sampled = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::Sampled); // Incorrect source usage @@ -289,7 +287,7 @@ TEST_F(CopyCommandTest_B2T, IncorrectUsage) { TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) { uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1); nxt::Buffer source = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); - nxt::Texture destination = CreateFrozen2DTexture(128, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture destination = Create2DTexture(128, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferDst); // Default row pitch is not 256-byte aligned @@ -318,7 +316,7 @@ TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) { TEST_F(CopyCommandTest_B2T, IncorrectBufferOffset) { uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); nxt::Buffer source = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); - nxt::Texture destination = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture destination = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferDst); // Correct usage @@ -351,7 +349,7 @@ class CopyCommandTest_T2B : public CopyCommandTest { // Test a successfull T2B copy TEST_F(CopyCommandTest_T2B, Success) { uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); - nxt::Texture source = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture source = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferSrc); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); @@ -397,7 +395,7 @@ TEST_F(CopyCommandTest_T2B, Success) { // Test OOB conditions on the texture TEST_F(CopyCommandTest_T2B, OutOfBoundsOnTexture) { uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); - nxt::Texture source = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture source = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferSrc); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); @@ -433,7 +431,7 @@ TEST_F(CopyCommandTest_T2B, OutOfBoundsOnTexture) { // Test OOB conditions on the buffer TEST_F(CopyCommandTest_T2B, OutOfBoundsOnBuffer) { uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); - nxt::Texture source = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture source = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferSrc); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); @@ -473,7 +471,7 @@ TEST_F(CopyCommandTest_T2B, OutOfBoundsOnBuffer) { // Test that we force Z=0 and Depth=1 on copies from to 2D textures TEST_F(CopyCommandTest_T2B, ZDepthConstraintFor2DTextures) { uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); - nxt::Texture source = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture source = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferSrc); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); @@ -495,9 +493,9 @@ TEST_F(CopyCommandTest_T2B, ZDepthConstraintFor2DTextures) { // Test T2B copies with incorrect buffer usage TEST_F(CopyCommandTest_T2B, IncorrectUsage) { uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); - nxt::Texture source = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture source = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferSrc); - nxt::Texture sampled = CreateFrozen2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture sampled = Create2DTexture(16, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::Sampled); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); nxt::Buffer vertex = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::Vertex); @@ -519,7 +517,7 @@ TEST_F(CopyCommandTest_T2B, IncorrectUsage) { TEST_F(CopyCommandTest_T2B, IncorrectRowPitch) { uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1); - nxt::Texture source = CreateFrozen2DTexture(128, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture source = Create2DTexture(128, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferDst); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); @@ -548,7 +546,7 @@ TEST_F(CopyCommandTest_T2B, IncorrectRowPitch) { // Test T2B copies with incorrect buffer offset usage TEST_F(CopyCommandTest_T2B, IncorrectBufferOffset) { uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1); - nxt::Texture source = CreateFrozen2DTexture(128, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, + nxt::Texture source = Create2DTexture(128, 16, 5, nxt::TextureFormat::R8G8B8A8Unorm, nxt::TextureUsageBit::TransferSrc); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); diff --git a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp index 11314f96c8..891b031eb2 100644 --- a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp +++ b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp @@ -28,7 +28,6 @@ nxt::TextureView Create2DAttachment(nxt::Device& device, uint32_t width, uint32_ .SetFormat(format) .SetMipLevels(1) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) - .SetInitialUsage(nxt::TextureUsageBit::OutputAttachment) .GetResult(); return attachment.CreateTextureViewBuilder() diff --git a/src/tests/unittests/validation/UsageValidationTests.cpp b/src/tests/unittests/validation/UsageValidationTests.cpp deleted file mode 100644 index 4b24cb3163..0000000000 --- a/src/tests/unittests/validation/UsageValidationTests.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017 The NXT Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "tests/unittests/validation/ValidationTest.h" - -#include - -using namespace testing; - -class UsageValidationTest : public ValidationTest { - protected: - nxt::Queue queue; - - private: - void SetUp() override { - ValidationTest::SetUp(); - queue = device.CreateQueue(); - } -}; - -// Test that command buffer submit changes buffer usage -TEST_F(UsageValidationTest, UsageAfterCommandBuffer) { - // TODO(kainino@chromium.org): This needs to be tested on every backend. - // Should we make an end2end test that tests this as well? - - nxt::Buffer buf = device.CreateBufferBuilder() - .SetSize(1) - .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Vertex) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) - .GetResult(); - - uint8_t foo = 0; - buf.SetSubData(0, sizeof(foo), &foo); - - buf.TransitionUsage(nxt::BufferUsageBit::Vertex); - ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo)); - - nxt::CommandBuffer cmdbuf = device.CreateCommandBufferBuilder() - .TransitionBufferUsage(buf, nxt::BufferUsageBit::TransferDst) - .GetResult(); - queue.Submit(1, &cmdbuf); - // buf should be in TransferDst usage - - buf.SetSubData(0, sizeof(foo), &foo); -} diff --git a/src/tests/unittests/validation/ValidationTest.cpp b/src/tests/unittests/validation/ValidationTest.cpp index 07dab31425..6d89430a96 100644 --- a/src/tests/unittests/validation/ValidationTest.cpp +++ b/src/tests/unittests/validation/ValidationTest.cpp @@ -77,7 +77,6 @@ nxt::RenderPassDescriptor ValidationTest::CreateSimpleRenderPass() { .SetMipLevels(1) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) .GetResult(); - colorBuffer.FreezeUsage(nxt::TextureUsageBit::OutputAttachment); auto colorView = colorBuffer.CreateTextureViewBuilder() .GetResult(); @@ -126,7 +125,6 @@ ValidationTest::DummyRenderPass ValidationTest::CreateDummyRenderPass() { .SetMipLevels(1) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) .GetResult(); - dummy.attachment.FreezeUsage(nxt::TextureUsageBit::OutputAttachment); nxt::TextureView view = AssertWillBeSuccess(dummy.attachment.CreateTextureViewBuilder()).GetResult(); diff --git a/src/tests/unittests/validation/VertexBufferValidationTests.cpp b/src/tests/unittests/validation/VertexBufferValidationTests.cpp index 254783430a..e81b731514 100644 --- a/src/tests/unittests/validation/VertexBufferValidationTests.cpp +++ b/src/tests/unittests/validation/VertexBufferValidationTests.cpp @@ -41,7 +41,6 @@ class VertexBufferValidationTest : public ValidationTest { .SetSize(256) .SetAllowedUsage(nxt::BufferUsageBit::Vertex) .GetResult(); - buffer.FreezeUsage(nxt::BufferUsageBit::Vertex); } return buffers; } diff --git a/src/utils/NXTHelpers.cpp b/src/utils/NXTHelpers.cpp index 3c8206a4e0..8e0db409ad 100644 --- a/src/utils/NXTHelpers.cpp +++ b/src/utils/NXTHelpers.cpp @@ -97,17 +97,15 @@ namespace utils { return builder.GetResult(); } - nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, - const void* data, - uint32_t size, - nxt::BufferUsageBit usage) { + nxt::Buffer CreateBufferFromData(const nxt::Device& device, + const void* data, + uint32_t size, + nxt::BufferUsageBit usage) { nxt::Buffer buffer = device.CreateBufferBuilder() .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | usage) - .SetInitialUsage(nxt::BufferUsageBit::TransferDst) .SetSize(size) .GetResult(); buffer.SetSubData(0, size, reinterpret_cast(data)); - buffer.FreezeUsage(usage); return buffer; } @@ -126,7 +124,6 @@ namespace utils { .SetMipLevels(1) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::TransferSrc) - .SetInitialUsage(nxt::TextureUsageBit::OutputAttachment) .GetResult(); nxt::TextureView colorView = result.color.CreateTextureViewBuilder().GetResult(); diff --git a/src/utils/NXTHelpers.h b/src/utils/NXTHelpers.h index f6e07bf6c1..181f5effa2 100644 --- a/src/utils/NXTHelpers.h +++ b/src/utils/NXTHelpers.h @@ -24,17 +24,16 @@ namespace utils { nxt::ShaderModule CreateShaderModule(const nxt::Device& device, nxt::ShaderStage stage, const char* source); - nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, - const void* data, - uint32_t size, - nxt::BufferUsageBit usage); + nxt::Buffer CreateBufferFromData(const nxt::Device& device, + const void* data, + uint32_t size, + nxt::BufferUsageBit usage); template - nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, - nxt::BufferUsageBit usage, - std::initializer_list data) { - return CreateFrozenBufferFromData(device, data.begin(), uint32_t(sizeof(T) * data.size()), - usage); + nxt::Buffer CreateBufferFromData(const nxt::Device& device, + nxt::BufferUsageBit usage, + std::initializer_list data) { + return CreateBufferFromData(device, data.begin(), uint32_t(sizeof(T) * data.size()), usage); } struct BasicRenderPass {