Remove explicit usage transition from the API and validation

This removes the following for both Buffer and Texture:
 - The builder's SetInitialUsage
 - The object's FreezeUsage and TransitionUsage methods
 - The CommandBuffer Transition<Object>Usage methods

All samples and tests are simplified as a result. This also obsoletes
the UsageValidationTest which is removed.

Some validation was dependent on "current usage" and hasn't been
reintroduced for implicit transitions yet:
 - Buffers can be used while mapped
 - Swapchain textures can be used after they have been presented.

Validation for these will involve collecting all the resources used by a
command buffer and will be done in a follow-up patch.
This commit is contained in:
Corentin Wallez 2018-07-09 15:15:07 +02:00 committed by Corentin Wallez
parent d2312e8138
commit d8c068fb4f
67 changed files with 143 additions and 1012 deletions

View File

@ -156,7 +156,6 @@ void frame() {
} }
queue.Submit(1, &commands); queue.Submit(1, &commands);
backbuffer.TransitionUsage(nxt::TextureUsageBit::Present);
swapchain.Present(backbuffer); swapchain.Present(backbuffer);
DoFlush(); DoFlush();
fprintf(stderr, "frame %i\n", f); fprintf(stderr, "frame %i\n", f);

View File

@ -96,7 +96,6 @@ void frame() {
nxtQueueSubmit(queue, 1, &commands); nxtQueueSubmit(queue, 1, &commands);
nxtCommandBufferRelease(commands); nxtCommandBufferRelease(commands);
nxtTextureTransitionUsage(backbuffer, NXT_TEXTURE_USAGE_BIT_PRESENT);
nxtSwapChainPresent(swapchain, backbuffer); nxtSwapChainPresent(swapchain, backbuffer);
nxtRenderPassDescriptorRelease(renderpassInfo); nxtRenderPassDescriptorRelease(renderpassInfo);
nxtTextureViewRelease(backbufferView); nxtTextureViewRelease(backbufferView);

View File

@ -63,10 +63,10 @@ void initBuffers() {
{0.01, -0.02}, {0.01, -0.02},
{0.00, 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 }; SimParams params = { 0.04f, 0.1f, 0.025f, 0.025f, 0.02f, 0.05f, 0.005f, kNumParticles };
updateParams = utils::CreateFrozenBufferFromData(device, &params, sizeof(params), nxt::BufferUsageBit::Uniform); updateParams = utils::CreateBufferFromData(device, &params, sizeof(params), nxt::BufferUsageBit::Uniform);
std::vector<Particle> initialParticles(kNumParticles); std::vector<Particle> initialParticles(kNumParticles);
{ {
@ -82,7 +82,6 @@ void initBuffers() {
for (size_t i = 0; i < 2; i++) { for (size_t i = 0; i < 2; i++) {
particleBuffers[i] = device.CreateBufferBuilder() particleBuffers[i] = device.CreateBufferBuilder()
.SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Storage) .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Storage)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.SetSize(sizeof(Particle) * kNumParticles) .SetSize(sizeof(Particle) * kNumParticles)
.GetResult(); .GetResult();
@ -261,20 +260,16 @@ void initSim() {
nxt::CommandBuffer createCommandBuffer(const nxt::RenderPassDescriptor& renderPass, size_t i) { nxt::CommandBuffer createCommandBuffer(const nxt::RenderPassDescriptor& renderPass, size_t i) {
static const uint32_t zeroOffsets[1] = {0}; static const uint32_t zeroOffsets[1] = {0};
auto& bufferSrc = particleBuffers[i];
auto& bufferDst = particleBuffers[(i + 1) % 2]; auto& bufferDst = particleBuffers[(i + 1) % 2];
return device.CreateCommandBufferBuilder() return device.CreateCommandBufferBuilder()
.BeginComputePass() .BeginComputePass()
.SetComputePipeline(updatePipeline) .SetComputePipeline(updatePipeline)
.TransitionBufferUsage(bufferSrc, nxt::BufferUsageBit::Storage)
.TransitionBufferUsage(bufferDst, nxt::BufferUsageBit::Storage)
.SetBindGroup(0, updateBGs[i]) .SetBindGroup(0, updateBGs[i])
.Dispatch(kNumParticles, 1, 1) .Dispatch(kNumParticles, 1, 1)
.EndComputePass() .EndComputePass()
.BeginRenderPass(renderPass) .BeginRenderPass(renderPass)
.SetRenderPipeline(renderPipeline) .SetRenderPipeline(renderPipeline)
.TransitionBufferUsage(bufferDst, nxt::BufferUsageBit::Vertex)
.SetVertexBuffers(0, 1, &bufferDst, zeroOffsets) .SetVertexBuffers(0, 1, &bufferDst, zeroOffsets)
.SetVertexBuffers(1, 1, &modelBuffer, zeroOffsets) .SetVertexBuffers(1, 1, &modelBuffer, zeroOffsets)
.DrawArrays(3, kNumParticles, 0, 0) .DrawArrays(3, kNumParticles, 0, 0)
@ -303,7 +298,6 @@ void frame() {
nxt::CommandBuffer commandBuffer = createCommandBuffer(renderPass, pingpong); nxt::CommandBuffer commandBuffer = createCommandBuffer(renderPass, pingpong);
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
backbuffer.TransitionUsage(nxt::TextureUsageBit::Present);
swapchain.Present(backbuffer); swapchain.Present(backbuffer);
DoFlush(); DoFlush();

View File

@ -37,14 +37,14 @@ void initBuffers() {
static const uint32_t indexData[3] = { static const uint32_t indexData[3] = {
0, 1, 2, 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] = { static const float vertexData[12] = {
0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.0f, 1.0f, -0.5f, -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() { void initTextures() {
@ -66,14 +66,12 @@ void initTextures() {
} }
nxt::Buffer stagingBuffer = utils::CreateFrozenBufferFromData(device, data.data(), static_cast<uint32_t>(data.size()), nxt::BufferUsageBit::TransferSrc); nxt::Buffer stagingBuffer = utils::CreateBufferFromData(device, data.data(), static_cast<uint32_t>(data.size()), nxt::BufferUsageBit::TransferSrc);
nxt::CommandBuffer copy = device.CreateCommandBufferBuilder() nxt::CommandBuffer copy = device.CreateCommandBufferBuilder()
.TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst)
.CopyBufferToTexture(stagingBuffer, 0, 0, texture, 0, 0, 0, 1024, 1024, 1, 0) .CopyBufferToTexture(stagingBuffer, 0, 0, texture, 0, 0, 0, 1024, 1024, 1, 0)
.GetResult(); .GetResult();
queue.Submit(1, &copy); queue.Submit(1, &copy);
texture.FreezeUsage(nxt::TextureUsageBit::Sampled);
} }
void init() { void init() {
@ -162,7 +160,6 @@ void frame() {
.GetResult(); .GetResult();
queue.Submit(1, &commands); queue.Submit(1, &commands);
backbuffer.TransitionUsage(nxt::TextureUsageBit::Present);
swapchain.Present(backbuffer); swapchain.Present(backbuffer);
DoFlush(); DoFlush();
} }

View File

@ -61,7 +61,7 @@ void initBuffers() {
20, 21, 22, 20, 21, 22,
20, 22, 23 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] = { static const float vertexData[6 * 4 * 6] = {
-1.0, -1.0, 1.0, 1.0, 0.0, 0.0, -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,
-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] = { static const float planeData[6 * 4] = {
-2.0, -1.0, -2.0, 0.5, 0.5, 0.5, -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,
-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 { struct CameraData {
@ -171,15 +171,14 @@ void init() {
cameraBuffer = device.CreateBufferBuilder() cameraBuffer = device.CreateBufferBuilder()
.SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Uniform) .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Uniform)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.SetSize(sizeof(CameraData)) .SetSize(sizeof(CameraData))
.GetResult(); .GetResult();
glm::mat4 transform(1.0); 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)); 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() nxt::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder()
.SetExtent(0, sizeof(CameraData)) .SetExtent(0, sizeof(CameraData))
@ -274,7 +273,6 @@ void frame() {
glm::vec3(0.0f, -1.0f, 0.0f) glm::vec3(0.0f, -1.0f, 0.0f)
); );
cameraBuffer.TransitionUsage(nxt::BufferUsageBit::TransferDst);
cameraBuffer.SetSubData(0, sizeof(CameraData), reinterpret_cast<uint8_t*>(&cameraData)); cameraBuffer.SetSubData(0, sizeof(CameraData), reinterpret_cast<uint8_t*>(&cameraData));
nxt::Texture backbuffer; nxt::Texture backbuffer;
@ -282,8 +280,6 @@ void frame() {
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass); GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.TransitionBufferUsage(cameraBuffer, nxt::BufferUsageBit::Uniform)
.BeginRenderPass(renderPass) .BeginRenderPass(renderPass)
.SetRenderPipeline(pipeline) .SetRenderPipeline(pipeline)
.SetBindGroup(0, bindGroup[0]) .SetBindGroup(0, bindGroup[0])
@ -305,7 +301,6 @@ void frame() {
.GetResult(); .GetResult();
queue.Submit(1, &commands); queue.Submit(1, &commands);
backbuffer.TransitionUsage(nxt::TextureUsageBit::Present);
swapchain.Present(backbuffer); swapchain.Present(backbuffer);
DoFlush(); DoFlush();
} }

View File

@ -143,7 +143,6 @@ nxt::TextureView CreateDefaultDepthStencilView(const nxt::Device& device) {
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult(); .GetResult();
depthStencilTexture.FreezeUsage(nxt::TextureUsageBit::OutputAttachment);
return depthStencilTexture.CreateTextureViewBuilder() return depthStencilTexture.CreateTextureViewBuilder()
.GetResult(); .GetResult();
} }

View File

@ -125,7 +125,6 @@ namespace {
.SetAllowedUsage(nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Index) .SetAllowedUsage(nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Index)
.SetSize(256) .SetSize(256)
.GetResult(); .GetResult();
defaultBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Index);
for (const auto& bv : scene.bufferViews) { for (const auto& bv : scene.bufferViews) {
const auto& iBufferViewID = bv.first; const auto& iBufferViewID = bv.first;
@ -151,7 +150,7 @@ namespace {
size_t iBufferViewSize = size_t iBufferViewSize =
iBufferView.byteLength ? iBufferView.byteLength : iBufferView.byteLength ? iBufferView.byteLength :
(iBuffer.data.size() - iBufferView.byteOffset); (iBuffer.data.size() - iBufferView.byteOffset);
auto oBuffer = utils::CreateFrozenBufferFromData(device, &iBuffer.data.at(iBufferView.byteOffset), static_cast<uint32_t>(iBufferViewSize), usage); auto oBuffer = utils::CreateBufferFromData(device, &iBuffer.data.at(iBufferView.byteOffset), static_cast<uint32_t>(iBufferViewSize), usage);
buffers[iBufferViewID] = std::move(oBuffer); buffers[iBufferViewID] = std::move(oBuffer);
} }
} }
@ -299,7 +298,6 @@ namespace {
auto uniformBuffer = device.CreateBufferBuilder() auto uniformBuffer = device.CreateBufferBuilder()
.SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Uniform) .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Uniform)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.SetSize(sizeof(u_transform_block)) .SetSize(sizeof(u_transform_block))
.GetResult(); .GetResult();
@ -440,13 +438,11 @@ namespace {
fprintf(stderr, "unsupported image.component %d\n", iImage.component); 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() auto cmdbuf = device.CreateCommandBufferBuilder()
.TransitionTextureUsage(oTexture, nxt::TextureUsageBit::TransferDst)
.CopyBufferToTexture(staging, 0, rowPitch, oTexture, 0, 0, 0, iImage.width, iImage.height, 1, 0) .CopyBufferToTexture(staging, 0, rowPitch, oTexture, 0, 0, 0, iImage.width, iImage.height, 1, 0)
.GetResult(); .GetResult();
queue.Submit(1, &cmdbuf); queue.Submit(1, &cmdbuf);
oTexture.FreezeUsage(nxt::TextureUsageBit::Sampled);
textures[iTextureID] = oTexture.CreateTextureViewBuilder().GetResult(); textures[iTextureID] = oTexture.CreateTextureViewBuilder().GetResult();
} }
@ -494,7 +490,6 @@ namespace {
} }
} }
const MaterialInfo& material = getMaterial(iPrim.material, strides[0], strides[1], strides[2]); 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 // 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 // but the draw is queue level command that is pipelined. This causes bad rendering for models
// that use the same part multiple time. // that use the same part multiple time.
@ -502,7 +497,6 @@ namespace {
sizeof(u_transform_block), sizeof(u_transform_block),
reinterpret_cast<const uint8_t*>(&transforms)); reinterpret_cast<const uint8_t*>(&transforms));
cmd.SetRenderPipeline(material.pipeline); cmd.SetRenderPipeline(material.pipeline);
cmd.TransitionBufferUsage(material.uniformBuffer, nxt::BufferUsageBit::Uniform);
cmd.SetBindGroup(0, material.bindGroup0); cmd.SetBindGroup(0, material.bindGroup0);
uint32_t vertexCount = 0; uint32_t vertexCount = 0;
@ -591,7 +585,6 @@ namespace {
.GetResult(); .GetResult();
queue.Submit(1, &commands); queue.Submit(1, &commands);
backbuffer.TransitionUsage(nxt::TextureUsageBit::Present);
swapchain.Present(backbuffer); swapchain.Present(backbuffer);
DoFlush(); DoFlush();
} }

View File

@ -221,18 +221,6 @@
}, },
{ {
"name": "unmap" "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": "usage", "type": "buffer usage bit"}
] ]
}, },
{
"name": "set initial usage",
"args": [
{"name": "usage", "type": "buffer usage bit"}
]
},
{ {
"name": "set size", "name": "set size",
"args": [ "args": [
@ -507,20 +489,6 @@
{"name": "buffers", "type": "buffer", "annotation": "const*", "length": "count"}, {"name": "buffers", "type": "buffer", "annotation": "const*", "length": "count"},
{"name": "offsets", "type": "uint32_t", "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", "name": "create texture view builder",
"returns": "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": [ "args": [
{"name": "usage", "type": "texture usage bit"} {"name": "usage", "type": "texture usage bit"}
] ]
},
{
"name": "set initial usage",
"args": [
{"name": "usage", "type": "texture usage bit"}
]
} }
] ]
}, },

View File

@ -25,10 +25,7 @@ namespace backend {
// Buffer // Buffer
BufferBase::BufferBase(BufferBuilder* builder) BufferBase::BufferBase(BufferBuilder* builder)
: mDevice(builder->mDevice), : mDevice(builder->mDevice), mSize(builder->mSize), mAllowedUsage(builder->mAllowedUsage) {
mSize(builder->mSize),
mAllowedUsage(builder->mAllowedUsage),
mCurrentUsage(builder->mCurrentUsage) {
} }
BufferBase::~BufferBase() { BufferBase::~BufferBase() {
@ -54,10 +51,6 @@ namespace backend {
return mAllowedUsage; return mAllowedUsage;
} }
nxt::BufferUsageBit BufferBase::GetUsage() const {
return mCurrentUsage;
}
void BufferBase::CallMapReadCallback(uint32_t serial, void BufferBase::CallMapReadCallback(uint32_t serial,
nxtBufferMapAsyncStatus status, nxtBufferMapAsyncStatus status,
const void* pointer) { const void* pointer) {
@ -90,7 +83,7 @@ namespace backend {
return; return;
} }
if (!(mCurrentUsage & nxt::BufferUsageBit::TransferDst)) { if (!(mAllowedUsage & nxt::BufferUsageBit::TransferDst)) {
mDevice->HandleError("Buffer needs the transfer dst usage bit"); mDevice->HandleError("Buffer needs the transfer dst usage bit");
return; return;
} }
@ -155,59 +148,33 @@ namespace backend {
mMapUserdata = 0; mMapUserdata = 0;
} }
bool BufferBase::IsFrozen() const { bool BufferBase::ValidateMapBase(uint32_t start,
return mIsFrozen; uint32_t size,
} nxt::BufferUsageBit requiredUsage) {
// TODO(cwallez@chromium.org): check for overflows.
bool BufferBase::HasFrozenUsage(nxt::BufferUsageBit usage) const { if (start + size > GetSize()) {
return mIsFrozen && (usage & mAllowedUsage); mDevice->HandleError("Buffer map read out of range");
}
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) {
return false; return false;
} }
return IsUsagePossible(mAllowedUsage, usage);
if (mIsMapped) {
mDevice->HandleError("Buffer already mapped");
return false;
} }
void BufferBase::UpdateUsageInternal(nxt::BufferUsageBit usage) { if (!(mAllowedUsage & requiredUsage)) {
ASSERT(IsTransitionPossible(usage)); mDevice->HandleError("Buffer needs the correct map usage bit");
mCurrentUsage = usage; return false;
} }
void BufferBase::TransitionUsage(nxt::BufferUsageBit usage) { return true;
if (!IsTransitionPossible(usage)) {
mDevice->HandleError("Buffer frozen or usage not allowed");
return;
}
TransitionUsageImpl(mCurrentUsage, usage);
mCurrentUsage = usage;
}
void BufferBase::FreezeUsage(nxt::BufferUsageBit usage) {
if (!IsTransitionPossible(usage)) {
mDevice->HandleError("Buffer frozen or usage not allowed");
return;
}
mAllowedUsage = usage;
TransitionUsageImpl(mCurrentUsage, usage);
mCurrentUsage = usage;
mIsFrozen = true;
} }
// BufferBuilder // BufferBuilder
enum BufferSetProperties { enum BufferSetProperties {
BUFFER_PROPERTY_ALLOWED_USAGE = 0x1, BUFFER_PROPERTY_ALLOWED_USAGE = 0x1,
BUFFER_PROPERTY_INITIAL_USAGE = 0x2, BUFFER_PROPERTY_SIZE = 0x2,
BUFFER_PROPERTY_SIZE = 0x4,
}; };
BufferBuilder::BufferBuilder(DeviceBase* device) : Builder(device) { BufferBuilder::BufferBuilder(DeviceBase* device) : Builder(device) {
@ -236,11 +203,6 @@ namespace backend {
return nullptr; return nullptr;
} }
if (!BufferBase::IsUsagePossible(mAllowedUsage, mCurrentUsage)) {
HandleError("Initial buffer usage is not allowed");
return nullptr;
}
return mDevice->CreateBuffer(this); return mDevice->CreateBuffer(this);
} }
@ -254,16 +216,6 @@ namespace backend {
mPropertiesSet |= BUFFER_PROPERTY_ALLOWED_USAGE; 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) { void BufferBuilder::SetSize(uint32_t size) {
if ((mPropertiesSet & BUFFER_PROPERTY_SIZE) != 0) { if ((mPropertiesSet & BUFFER_PROPERTY_SIZE) != 0) {
HandleError("Buffer size property set multiple times"); HandleError("Buffer size property set multiple times");
@ -274,27 +226,6 @@ namespace backend {
mPropertiesSet |= BUFFER_PROPERTY_SIZE; 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::BufferViewBase(BufferViewBuilder* builder) BufferViewBase::BufferViewBase(BufferViewBuilder* builder)

View File

@ -38,12 +38,6 @@ namespace backend {
uint32_t GetSize() const; uint32_t GetSize() const;
nxt::BufferUsageBit GetAllowedUsage() 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; DeviceBase* GetDevice() const;
@ -59,8 +53,6 @@ namespace backend {
nxtBufferMapWriteCallback callback, nxtBufferMapWriteCallback callback,
nxtCallbackUserdata userdata); nxtCallbackUserdata userdata);
void Unmap(); void Unmap();
void TransitionUsage(nxt::BufferUsageBit usage);
void FreezeUsage(nxt::BufferUsageBit usage);
protected: protected:
void CallMapReadCallback(uint32_t serial, 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 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 MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0;
virtual void UnmapImpl() = 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); bool ValidateMapBase(uint32_t start, uint32_t size, nxt::BufferUsageBit requiredUsage);
DeviceBase* mDevice; DeviceBase* mDevice;
uint32_t mSize; uint32_t mSize;
nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None; nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None;
nxt::BufferUsageBit mCurrentUsage = nxt::BufferUsageBit::None;
nxtBufferMapReadCallback mMapReadCallback = nullptr; nxtBufferMapReadCallback mMapReadCallback = nullptr;
nxtBufferMapWriteCallback mMapWriteCallback = nullptr; nxtBufferMapWriteCallback mMapWriteCallback = nullptr;
nxtCallbackUserdata mMapUserdata = 0; nxtCallbackUserdata mMapUserdata = 0;
uint32_t mMapSerial = 0; uint32_t mMapSerial = 0;
bool mIsFrozen = false;
bool mIsMapped = false; bool mIsMapped = false;
}; };

View File

@ -122,6 +122,30 @@ namespace backend {
return true; 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 { enum class PassType {
Render, Render,
Compute, Compute,
@ -263,25 +287,7 @@ namespace backend {
// CommandBuffer // CommandBuffer
CommandBufferBase::CommandBufferBase(CommandBufferBuilder* builder) CommandBufferBase::CommandBufferBase(CommandBufferBuilder* builder)
: mDevice(builder->mDevice), : 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;
} }
DeviceBase* CommandBufferBase::GetDevice() { DeviceBase* CommandBufferBase::GetDevice() {
@ -352,9 +358,9 @@ namespace backend {
CopyBufferToBufferCmd* copy = mIterator.NextCommand<CopyBufferToBufferCmd>(); CopyBufferToBufferCmd* copy = mIterator.NextCommand<CopyBufferToBufferCmd>();
if (!ValidateCopySizeFitsInBuffer(this, copy->source, copy->size) || if (!ValidateCopySizeFitsInBuffer(this, copy->source, copy->size) ||
!ValidateCopySizeFitsInBuffer(this, copy->destination, copy->size) || !ValidateCopySizeFitsInBuffer(this, copy->destination, copy->size) ||
!mState->ValidateCanUseBufferAs(copy->source.buffer.Get(), !ValidateCanUseAs(this, copy->source.buffer.Get(),
nxt::BufferUsageBit::TransferSrc) || nxt::BufferUsageBit::TransferSrc) ||
!mState->ValidateCanUseBufferAs(copy->destination.buffer.Get(), !ValidateCanUseAs(this, copy->destination.buffer.Get(),
nxt::BufferUsageBit::TransferDst)) { nxt::BufferUsageBit::TransferDst)) {
return false; return false;
} }
@ -371,9 +377,9 @@ namespace backend {
!ValidateCopySizeFitsInBuffer(this, copy->source, bufferCopySize) || !ValidateCopySizeFitsInBuffer(this, copy->source, bufferCopySize) ||
!ValidateTexelBufferOffset(this, copy->destination.texture.Get(), !ValidateTexelBufferOffset(this, copy->destination.texture.Get(),
copy->source) || copy->source) ||
!mState->ValidateCanUseBufferAs(copy->source.buffer.Get(), !ValidateCanUseAs(this, copy->source.buffer.Get(),
nxt::BufferUsageBit::TransferSrc) || nxt::BufferUsageBit::TransferSrc) ||
!mState->ValidateCanUseTextureAs(copy->destination.texture.Get(), !ValidateCanUseAs(this, copy->destination.texture.Get(),
nxt::TextureUsageBit::TransferDst)) { nxt::TextureUsageBit::TransferDst)) {
return false; return false;
} }
@ -390,31 +396,14 @@ namespace backend {
!ValidateCopySizeFitsInBuffer(this, copy->destination, bufferCopySize) || !ValidateCopySizeFitsInBuffer(this, copy->destination, bufferCopySize) ||
!ValidateTexelBufferOffset(this, copy->source.texture.Get(), !ValidateTexelBufferOffset(this, copy->source.texture.Get(),
copy->destination) || copy->destination) ||
!mState->ValidateCanUseTextureAs(copy->source.texture.Get(), !ValidateCanUseAs(this, copy->source.texture.Get(),
nxt::TextureUsageBit::TransferSrc) || nxt::TextureUsageBit::TransferSrc) ||
!mState->ValidateCanUseBufferAs(copy->destination.buffer.Get(), !ValidateCanUseAs(this, copy->destination.buffer.Get(),
nxt::BufferUsageBit::TransferDst)) { nxt::BufferUsageBit::TransferDst)) {
return false; return false;
} }
} break; } break;
case Command::TransitionBufferUsage: {
TransitionBufferUsageCmd* cmd =
mIterator.NextCommand<TransitionBufferUsageCmd>();
if (!mState->TransitionBufferUsage(cmd->buffer.Get(), cmd->usage)) {
return false;
}
} break;
case Command::TransitionTextureUsage: {
TransitionTextureUsageCmd* cmd =
mIterator.NextCommand<TransitionTextureUsageCmd>();
if (!mState->TransitionTextureUsage(cmd->texture.Get(), cmd->usage)) {
return false;
}
} break;
default: default:
HandleError("Command disallowed outside of a pass"); HandleError("Command disallowed outside of a pass");
return false; return false;
@ -474,9 +463,7 @@ namespace backend {
SetBindGroupCmd* cmd = mIterator.NextCommand<SetBindGroupCmd>(); SetBindGroupCmd* cmd = mIterator.NextCommand<SetBindGroupCmd>();
TrackBindGroupResourceUsage(cmd->group.Get(), &usageTracker); TrackBindGroupResourceUsage(cmd->group.Get(), &usageTracker);
if (!mState->SetBindGroup(cmd->index, cmd->group.Get())) { mState->SetBindGroup(cmd->index, cmd->group.Get());
return false;
}
} break; } break;
default: default:
@ -490,10 +477,6 @@ namespace backend {
} }
bool CommandBufferBuilder::ValidateRenderPass(RenderPassDescriptorBase* renderPass) { bool CommandBufferBuilder::ValidateRenderPass(RenderPassDescriptorBase* renderPass) {
if (!mState->BeginRenderPass(renderPass)) {
return false;
}
PassResourceUsageTracker usageTracker; PassResourceUsageTracker usageTracker;
// Track usage of the render pass attachments // Track usage of the render pass attachments
@ -581,16 +564,14 @@ namespace backend {
SetBindGroupCmd* cmd = mIterator.NextCommand<SetBindGroupCmd>(); SetBindGroupCmd* cmd = mIterator.NextCommand<SetBindGroupCmd>();
TrackBindGroupResourceUsage(cmd->group.Get(), &usageTracker); TrackBindGroupResourceUsage(cmd->group.Get(), &usageTracker);
if (!mState->SetBindGroup(cmd->index, cmd->group.Get())) { mState->SetBindGroup(cmd->index, cmd->group.Get());
return false;
}
} break; } break;
case Command::SetIndexBuffer: { case Command::SetIndexBuffer: {
SetIndexBufferCmd* cmd = mIterator.NextCommand<SetIndexBufferCmd>(); SetIndexBufferCmd* cmd = mIterator.NextCommand<SetIndexBufferCmd>();
usageTracker.BufferUsedAs(cmd->buffer.Get(), nxt::BufferUsageBit::Index); usageTracker.BufferUsedAs(cmd->buffer.Get(), nxt::BufferUsageBit::Index);
if (!mState->SetIndexBuffer(cmd->buffer.Get())) { if (!mState->SetIndexBuffer()) {
return false; return false;
} }
} break; } break;
@ -602,7 +583,7 @@ namespace backend {
for (uint32_t i = 0; i < cmd->count; ++i) { for (uint32_t i = 0; i < cmd->count; ++i) {
usageTracker.BufferUsedAs(buffers[i].Get(), nxt::BufferUsageBit::Vertex); usageTracker.BufferUsedAs(buffers[i].Get(), nxt::BufferUsageBit::Vertex);
mState->SetVertexBuffer(cmd->startSlot + i, buffers[i].Get()); mState->SetVertexBuffer(cmd->startSlot + i);
} }
} break; } break;
@ -848,22 +829,4 @@ namespace backend {
memcpy(cmdOffsets, offsets, count * sizeof(uint32_t)); memcpy(cmdOffsets, offsets, count * sizeof(uint32_t));
} }
void CommandBufferBuilder::TransitionBufferUsage(BufferBase* buffer,
nxt::BufferUsageBit usage) {
TransitionBufferUsageCmd* cmd =
mAllocator.Allocate<TransitionBufferUsageCmd>(Command::TransitionBufferUsage);
new (cmd) TransitionBufferUsageCmd;
cmd->buffer = buffer;
cmd->usage = usage;
}
void CommandBufferBuilder::TransitionTextureUsage(TextureBase* texture,
nxt::TextureUsageBit usage) {
TransitionTextureUsageCmd* cmd =
mAllocator.Allocate<TransitionTextureUsageCmd>(Command::TransitionTextureUsage);
new (cmd) TransitionTextureUsageCmd;
cmd->texture = texture;
cmd->usage = usage;
}
} // namespace backend } // namespace backend

View File

@ -42,14 +42,11 @@ namespace backend {
class CommandBufferBase : public RefCounted { class CommandBufferBase : public RefCounted {
public: public:
CommandBufferBase(CommandBufferBuilder* builder); CommandBufferBase(CommandBufferBuilder* builder);
bool ValidateResourceUsagesImmediate();
DeviceBase* GetDevice(); DeviceBase* GetDevice();
private: private:
DeviceBase* mDevice; DeviceBase* mDevice;
std::set<BufferBase*> mBuffersTransitioned;
std::set<TextureBase*> mTexturesTransitioned;
}; };
class CommandBufferBuilder : public Builder<CommandBufferBase> { class CommandBufferBuilder : public Builder<CommandBufferBase> {
@ -130,7 +127,6 @@ namespace backend {
uint32_t const* offsets); uint32_t const* offsets);
void TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage); void TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage);
void TransitionTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage);
private: private:
friend class CommandBufferBase; friend class CommandBufferBase;

View File

@ -33,24 +33,6 @@ namespace backend {
: mBuilder(mBuilder) { : 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() { bool CommandBufferStateTracker::ValidateCanDispatch() {
constexpr ValidationAspects requiredAspects = constexpr ValidationAspects requiredAspects =
1 << VALIDATION_ASPECT_PIPELINE | 1 << VALIDATION_ASPECT_BIND_GROUPS; 1 << VALIDATION_ASPECT_PIPELINE | 1 << VALIDATION_ASPECT_BIND_GROUPS;
@ -99,32 +81,7 @@ namespace backend {
return RevalidateCanDraw(); 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() { void CommandBufferStateTracker::EndPass() {
// Everything in mTexturesAttached should be for the current render pass.
mTexturesAttached.clear();
mInputsSet.reset(); mInputsSet.reset();
mAspects = 0; mAspects = 0;
mBindgroups.fill(nullptr); mBindgroups.fill(nullptr);
@ -141,141 +98,31 @@ namespace backend {
return true; return true;
} }
bool CommandBufferStateTracker::SetBindGroup(uint32_t index, BindGroupBase* bindgroup) { void CommandBufferStateTracker::SetBindGroup(uint32_t index, BindGroupBase* bindgroup) {
if (!ValidateBindGroupUsages(bindgroup)) {
return false;
}
mBindgroupsSet.set(index); mBindgroupsSet.set(index);
mBindgroups[index] = bindgroup; mBindgroups[index] = bindgroup;
return true;
} }
bool CommandBufferStateTracker::SetIndexBuffer(BufferBase* buffer) { bool CommandBufferStateTracker::SetIndexBuffer() {
if (!HavePipeline()) { if (!HavePipeline()) {
mBuilder->HandleError("Can't set the index buffer without a pipeline"); mBuilder->HandleError("Can't set the index buffer without a pipeline");
return false; 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); mAspects.set(VALIDATION_ASPECT_INDEX_BUFFER);
return true; return true;
} }
bool CommandBufferStateTracker::SetVertexBuffer(uint32_t index, BufferBase* buffer) { bool CommandBufferStateTracker::SetVertexBuffer(uint32_t index) {
if (!HavePipeline()) { if (!HavePipeline()) {
mBuilder->HandleError("Can't set vertex buffers without a pipeline"); mBuilder->HandleError("Can't set vertex buffers without a pipeline");
return false; 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); mInputsSet.set(index);
return true; 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() { bool CommandBufferStateTracker::RecomputeHaveAspectBindGroups() {
if (mAspects[VALIDATION_ASPECT_BIND_GROUPS]) { if (mAspects[VALIDATION_ASPECT_BIND_GROUPS]) {
return true; return true;
@ -314,53 +161,6 @@ namespace backend {
return mAspects[VALIDATION_ASPECT_PIPELINE]; 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() { bool CommandBufferStateTracker::RevalidateCanDraw() {
if (!mAspects[VALIDATION_ASPECT_PIPELINE]) { if (!mAspects[VALIDATION_ASPECT_PIPELINE]) {
mBuilder->HandleError("No active render pipeline"); mBuilder->HandleError("No active render pipeline");

View File

@ -31,29 +31,17 @@ namespace backend {
// Non-state-modifying validation functions // Non-state-modifying validation functions
bool ValidateCanCopy() const; bool ValidateCanCopy() const;
bool ValidateCanUseBufferAs(BufferBase* buffer, nxt::BufferUsageBit usage) const;
bool ValidateCanUseTextureAs(TextureBase* texture, nxt::TextureUsageBit usage) const;
bool ValidateCanDispatch(); bool ValidateCanDispatch();
bool ValidateCanDrawArrays(); bool ValidateCanDrawArrays();
bool ValidateCanDrawElements(); bool ValidateCanDrawElements();
// State-modifying methods // State-modifying methods
void EndPass(); void EndPass();
bool BeginRenderPass(RenderPassDescriptorBase* info);
bool SetComputePipeline(ComputePipelineBase* pipeline); bool SetComputePipeline(ComputePipelineBase* pipeline);
bool SetRenderPipeline(RenderPipelineBase* pipeline); bool SetRenderPipeline(RenderPipelineBase* pipeline);
bool SetBindGroup(uint32_t index, BindGroupBase* bindgroup); void SetBindGroup(uint32_t index, BindGroupBase* bindgroup);
bool SetIndexBuffer(BufferBase* buffer); bool SetIndexBuffer();
bool SetVertexBuffer(uint32_t index, BufferBase* buffer); bool SetVertexBuffer(uint32_t index);
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<BufferBase*> mBuffersTransitioned;
std::set<TextureBase*> mTexturesTransitioned;
private: private:
enum ValidationAspect { enum ValidationAspect {
@ -66,20 +54,11 @@ namespace backend {
}; };
using ValidationAspects = std::bitset<VALIDATION_ASPECT_COUNT>; using ValidationAspects = std::bitset<VALIDATION_ASPECT_COUNT>;
// 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 // Queries for lazily evaluated aspects
bool RecomputeHaveAspectBindGroups(); bool RecomputeHaveAspectBindGroups();
bool RecomputeHaveAspectVertexBuffers(); bool RecomputeHaveAspectVertexBuffers();
bool HavePipeline() const; bool HavePipeline() const;
bool ValidateBindGroupUsages(BindGroupBase* group) const;
bool RevalidateCanDraw(); bool RevalidateCanDraw();
void SetPipelineCommon(PipelineBase* pipeline); void SetPipelineCommon(PipelineBase* pipeline);
@ -93,10 +72,6 @@ namespace backend {
std::bitset<kMaxVertexInputs> mInputsSet; std::bitset<kMaxVertexInputs> mInputsSet;
PipelineBase* mLastPipeline = nullptr; PipelineBase* mLastPipeline = nullptr;
RenderPipelineBase* mLastRenderPipeline = nullptr; RenderPipelineBase* mLastRenderPipeline = nullptr;
std::map<BufferBase*, nxt::BufferUsageBit> mMostRecentBufferUsages;
std::map<TextureBase*, nxt::TextureUsageBit> mMostRecentTextureUsages;
std::set<TextureBase*> mTexturesAttached;
}; };
} // namespace backend } // namespace backend

View File

@ -111,16 +111,6 @@ namespace backend {
commands->NextData<uint32_t>(cmd->count); commands->NextData<uint32_t>(cmd->count);
cmd->~SetVertexBuffersCmd(); cmd->~SetVertexBuffersCmd();
} break; } break;
case Command::TransitionBufferUsage: {
TransitionBufferUsageCmd* cmd =
commands->NextCommand<TransitionBufferUsageCmd>();
cmd->~TransitionBufferUsageCmd();
} break;
case Command::TransitionTextureUsage: {
TransitionTextureUsageCmd* cmd =
commands->NextCommand<TransitionTextureUsageCmd>();
cmd->~TransitionTextureUsageCmd();
} break;
} }
} }
commands->DataWasDestroyed(); commands->DataWasDestroyed();
@ -206,14 +196,6 @@ namespace backend {
commands->NextData<Ref<BufferBase>>(cmd->count); commands->NextData<Ref<BufferBase>>(cmd->count);
commands->NextData<uint32_t>(cmd->count); commands->NextData<uint32_t>(cmd->count);
} break; } break;
case Command::TransitionBufferUsage:
commands->NextCommand<TransitionBufferUsageCmd>();
break;
case Command::TransitionTextureUsage:
commands->NextCommand<TransitionTextureUsageCmd>();
break;
} }
} }

View File

@ -46,8 +46,6 @@ namespace backend {
SetBindGroup, SetBindGroup,
SetIndexBuffer, SetIndexBuffer,
SetVertexBuffers, SetVertexBuffers,
TransitionBufferUsage,
TransitionTextureUsage,
}; };
struct BeginComputePassCmd {}; struct BeginComputePassCmd {};
@ -151,18 +149,6 @@ namespace backend {
uint32_t count; uint32_t count;
}; };
struct TransitionBufferUsageCmd {
Ref<BufferBase> buffer;
nxt::BufferUsageBit usage;
};
struct TransitionTextureUsageCmd {
Ref<TextureBase> 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 // 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. // the commands have a chance to run their destructor and remove internal references.
class CommandIterator; class CommandIterator;

View File

@ -28,8 +28,9 @@ namespace backend {
return mDevice; return mDevice;
} }
bool QueueBase::ValidateSubmitCommand(CommandBufferBase* command) { bool QueueBase::ValidateSubmitCommand(CommandBufferBase*) {
return command->ValidateResourceUsagesImmediate(); // TODO(cwallez@chromium.org): Validate resources referenced by command buffers can be used
return true;
} }
} // namespace backend } // namespace backend

View File

@ -77,10 +77,6 @@ namespace backend {
mDevice->HandleError("Tried to present something other than the last NextTexture"); mDevice->HandleError("Tried to present something other than the last NextTexture");
return; return;
} }
if (texture->GetUsage() != nxt::TextureUsageBit::Present) {
mDevice->HandleError("Texture has not been transitioned to the Present usage");
return;
}
OnBeforePresent(texture); OnBeforePresent(texture);

View File

@ -75,8 +75,7 @@ namespace backend {
mHeight(builder->mHeight), mHeight(builder->mHeight),
mDepth(builder->mDepth), mDepth(builder->mDepth),
mNumMipLevels(builder->mNumMipLevels), mNumMipLevels(builder->mNumMipLevels),
mAllowedUsage(builder->mAllowedUsage), mAllowedUsage(builder->mAllowedUsage) {
mCurrentUsage(builder->mCurrentUsage) {
} }
DeviceBase* TextureBase::GetDevice() const { DeviceBase* TextureBase::GetDevice() const {
@ -104,64 +103,11 @@ namespace backend {
nxt::TextureUsageBit TextureBase::GetAllowedUsage() const { nxt::TextureUsageBit TextureBase::GetAllowedUsage() const {
return mAllowedUsage; return mAllowedUsage;
} }
nxt::TextureUsageBit TextureBase::GetUsage() const {
return mCurrentUsage;
}
TextureViewBuilder* TextureBase::CreateTextureViewBuilder() { TextureViewBuilder* TextureBase::CreateTextureViewBuilder() {
return new TextureViewBuilder(mDevice, this); 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 // TextureBuilder
enum TextureSetProperties { enum TextureSetProperties {
@ -170,7 +116,6 @@ namespace backend {
TEXTURE_PROPERTY_FORMAT = 0x4, TEXTURE_PROPERTY_FORMAT = 0x4,
TEXTURE_PROPERTY_MIP_LEVELS = 0x8, TEXTURE_PROPERTY_MIP_LEVELS = 0x8,
TEXTURE_PROPERTY_ALLOWED_USAGE = 0x10, TEXTURE_PROPERTY_ALLOWED_USAGE = 0x10,
TEXTURE_PROPERTY_INITIAL_USAGE = 0x20,
}; };
TextureBuilder::TextureBuilder(DeviceBase* device) : Builder(device) { TextureBuilder::TextureBuilder(DeviceBase* device) : Builder(device) {
@ -185,11 +130,6 @@ namespace backend {
return nullptr; 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 // TODO(cwallez@chromium.org): check stuff based on the dimension
return mDevice->CreateTexture(this); return mDevice->CreateTexture(this);
@ -252,16 +192,6 @@ namespace backend {
mAllowedUsage = usage; 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::TextureViewBase(TextureViewBuilder* builder) : mTexture(builder->mTexture) { TextureViewBase::TextureViewBase(TextureViewBuilder* builder) : mTexture(builder->mTexture) {

View File

@ -47,22 +47,10 @@ namespace backend {
uint32_t GetDepth() const; uint32_t GetDepth() const;
uint32_t GetNumMipLevels() const; uint32_t GetNumMipLevels() const;
nxt::TextureUsageBit GetAllowedUsage() 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; DeviceBase* GetDevice() const;
// NXT API // NXT API
TextureViewBuilder* CreateTextureViewBuilder(); TextureViewBuilder* CreateTextureViewBuilder();
void TransitionUsage(nxt::TextureUsageBit usage);
void FreezeUsage(nxt::TextureUsageBit usage);
virtual void TransitionUsageImpl(nxt::TextureUsageBit currentUsage,
nxt::TextureUsageBit targetUsage) = 0;
private: private:
DeviceBase* mDevice; DeviceBase* mDevice;
@ -72,8 +60,6 @@ namespace backend {
uint32_t mWidth, mHeight, mDepth; uint32_t mWidth, mHeight, mDepth;
uint32_t mNumMipLevels; uint32_t mNumMipLevels;
nxt::TextureUsageBit mAllowedUsage = nxt::TextureUsageBit::None; nxt::TextureUsageBit mAllowedUsage = nxt::TextureUsageBit::None;
nxt::TextureUsageBit mCurrentUsage = nxt::TextureUsageBit::None;
bool mIsFrozen = false;
}; };
class TextureBuilder : public Builder<TextureBase> { class TextureBuilder : public Builder<TextureBase> {
@ -100,7 +86,6 @@ namespace backend {
nxt::TextureFormat mFormat; nxt::TextureFormat mFormat;
uint32_t mNumMipLevels; uint32_t mNumMipLevels;
nxt::TextureUsageBit mAllowedUsage = nxt::TextureUsageBit::None; nxt::TextureUsageBit mAllowedUsage = nxt::TextureUsageBit::None;
nxt::TextureUsageBit mCurrentUsage = nxt::TextureUsageBit::None;
}; };
class TextureViewBase : public RefCounted { class TextureViewBase : public RefCounted {

View File

@ -198,9 +198,6 @@ namespace backend { namespace d3d12 {
ToBackend(GetDevice())->GetResourceAllocator()->Release(mResource); ToBackend(GetDevice())->GetResourceAllocator()->Release(mResource);
} }
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) {
}
BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) { BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) {
mCbvDesc.BufferLocation = ToBackend(GetBuffer())->GetVA() + GetOffset(); mCbvDesc.BufferLocation = ToBackend(GetBuffer())->GetVA() + GetOffset();
mCbvDesc.SizeInBytes = GetD3D12Size(); mCbvDesc.SizeInBytes = GetD3D12Size();

View File

@ -43,8 +43,6 @@ namespace backend { namespace d3d12 {
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; 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 MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override; void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage,
nxt::BufferUsageBit targetUsage) override;
ComPtr<ID3D12Resource> mResource; ComPtr<ID3D12Resource> mResource;
bool mFixedResourceState = false; bool mFixedResourceState = false;

View File

@ -408,18 +408,6 @@ namespace backend { namespace d3d12 {
} }
} break; } break;
case Command::TransitionBufferUsage: {
TransitionBufferUsageCmd* cmd =
mCommands.NextCommand<TransitionBufferUsageCmd>();
cmd->buffer->UpdateUsageInternal(cmd->usage);
} break;
case Command::TransitionTextureUsage: {
TransitionTextureUsageCmd* cmd =
mCommands.NextCommand<TransitionTextureUsageCmd>();
cmd->texture->UpdateUsageInternal(cmd->usage);
} break;
default: { UNREACHABLE(); } break; default: { UNREACHABLE(); } break;
} }
} }
@ -464,6 +452,7 @@ namespace backend { namespace d3d12 {
} }
} }
} }
void CommandBuffer::RecordRenderPass(ComPtr<ID3D12GraphicsCommandList> commandList, void CommandBuffer::RecordRenderPass(ComPtr<ID3D12GraphicsCommandList> commandList,
BindGroupStateTracker* bindingTracker, BindGroupStateTracker* bindingTracker,
RenderPassDescriptor* renderPass) { RenderPassDescriptor* renderPass) {
@ -471,13 +460,6 @@ namespace backend { namespace d3d12 {
{ {
for (uint32_t i : IterateBitSet(renderPass->GetColorAttachmentMask())) { for (uint32_t i : IterateBitSet(renderPass->GetColorAttachmentMask())) {
auto& attachmentInfo = renderPass->GetColorAttachment(i); 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 // Load op - color
if (attachmentInfo.loadOp == nxt::LoadOp::Clear) { if (attachmentInfo.loadOp == nxt::LoadOp::Clear) {
@ -491,12 +473,6 @@ namespace backend { namespace d3d12 {
auto& attachmentInfo = renderPass->GetDepthStencilAttachment(); auto& attachmentInfo = renderPass->GetDepthStencilAttachment();
Texture* texture = ToBackend(attachmentInfo.view->GetTexture()); 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 // Load op - depth/stencil
bool doDepthClear = TextureFormatHasDepth(texture->GetFormat()) && bool doDepthClear = TextureFormatHasDepth(texture->GetFormat()) &&
(attachmentInfo.depthLoadOp == nxt::LoadOp::Clear); (attachmentInfo.depthLoadOp == nxt::LoadOp::Clear);

View File

@ -122,9 +122,8 @@ namespace backend { namespace d3d12 {
resourceDescriptor.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; resourceDescriptor.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
resourceDescriptor.Flags = D3D12ResourceFlags(GetAllowedUsage(), GetFormat()); resourceDescriptor.Flags = D3D12ResourceFlags(GetAllowedUsage(), GetFormat());
mResource = mResource = mDevice->GetResourceAllocator()->Allocate(
mDevice->GetResourceAllocator()->Allocate(D3D12_HEAP_TYPE_DEFAULT, resourceDescriptor, D3D12_HEAP_TYPE_DEFAULT, resourceDescriptor, D3D12_RESOURCE_STATE_COMMON);
D3D12TextureUsage(GetUsage(), GetFormat()));
mResourcePtr = mResource.Get(); mResourcePtr = mResource.Get();
} }
@ -174,9 +173,6 @@ namespace backend { namespace d3d12 {
mLastUsage = usage; mLastUsage = usage;
} }
void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) {
}
TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) { TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) {
mSrvDesc.Format = D3D12TextureFormat(GetTexture()->GetFormat()); mSrvDesc.Format = D3D12TextureFormat(GetTexture()->GetFormat());
mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;

View File

@ -38,9 +38,6 @@ namespace backend { namespace d3d12 {
nxt::TextureUsageBit usage); nxt::TextureUsageBit usage);
private: private:
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage,
nxt::TextureUsageBit targetUsage) override;
Device* mDevice; Device* mDevice;
ComPtr<ID3D12Resource> mResource = {}; ComPtr<ID3D12Resource> mResource = {};
ID3D12Resource* mResourcePtr = nullptr; ID3D12Resource* mResourcePtr = nullptr;

View File

@ -38,8 +38,6 @@ namespace backend { namespace metal {
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; 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 MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override; void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage,
nxt::BufferUsageBit targetUsage) override;
id<MTLBuffer> mMtlBuffer = nil; id<MTLBuffer> mMtlBuffer = nil;
}; };

View File

@ -68,9 +68,6 @@ namespace backend { namespace metal {
// Nothing to do, Metal StorageModeShared buffers are always mapped. // Nothing to do, Metal StorageModeShared buffers are always mapped.
} }
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) {
}
BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) { BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) {
} }

View File

@ -304,20 +304,6 @@ namespace backend { namespace metal {
destinationBytesPerImage:copy->rowPitch * src.height]; destinationBytesPerImage:copy->rowPitch * src.height];
} break; } break;
case Command::TransitionBufferUsage: {
TransitionBufferUsageCmd* cmd =
mCommands.NextCommand<TransitionBufferUsageCmd>();
cmd->buffer->UpdateUsageInternal(cmd->usage);
} break;
case Command::TransitionTextureUsage: {
TransitionTextureUsageCmd* cmd =
mCommands.NextCommand<TransitionTextureUsageCmd>();
cmd->texture->UpdateUsageInternal(cmd->usage);
} break;
default: { UNREACHABLE(); } break; default: { UNREACHABLE(); } break;
} }
} }

View File

@ -31,9 +31,6 @@ namespace backend { namespace metal {
id<MTLTexture> GetMTLTexture(); id<MTLTexture> GetMTLTexture();
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage,
nxt::TextureUsageBit targetUsage) override;
private: private:
id<MTLTexture> mMtlTexture = nil; id<MTLTexture> mMtlTexture = nil;
}; };

View File

@ -70,7 +70,7 @@ namespace backend { namespace metal {
auto desc = [MTLTextureDescriptor new]; auto desc = [MTLTextureDescriptor new];
[desc autorelease]; [desc autorelease];
desc.textureType = MetalTextureType(GetDimension()); desc.textureType = MetalTextureType(GetDimension());
desc.usage = MetalTextureUsage(GetUsage()); desc.usage = MetalTextureUsage(GetAllowedUsage());
desc.pixelFormat = MetalPixelFormat(GetFormat()); desc.pixelFormat = MetalPixelFormat(GetFormat());
desc.width = GetWidth(); desc.width = GetWidth();
desc.height = GetHeight(); desc.height = GetHeight();
@ -96,9 +96,6 @@ namespace backend { namespace metal {
return mMtlTexture; return mMtlTexture;
} }
void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) {
}
TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) { TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) {
} }

View File

@ -171,9 +171,6 @@ namespace backend { namespace null {
void Buffer::UnmapImpl() { void Buffer::UnmapImpl() {
} }
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) {
}
// CommandBuffer // CommandBuffer
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder) CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
@ -184,27 +181,6 @@ namespace backend { namespace null {
FreeCommands(&mCommands); FreeCommands(&mCommands);
} }
void CommandBuffer::Execute() {
Command type;
while (mCommands.NextCommandId(&type)) {
switch (type) {
case Command::TransitionBufferUsage: {
TransitionBufferUsageCmd* cmd =
mCommands.NextCommand<TransitionBufferUsageCmd>();
cmd->buffer->UpdateUsageInternal(cmd->usage);
} break;
case Command::TransitionTextureUsage: {
TransitionTextureUsageCmd* cmd =
mCommands.NextCommand<TransitionTextureUsageCmd>();
cmd->texture->UpdateUsageInternal(cmd->usage);
} break;
default:
SkipCommand(&mCommands, type);
break;
}
}
}
// Queue // Queue
Queue::Queue(Device* device) : QueueBase(device) { Queue::Queue(Device* device) : QueueBase(device) {
@ -213,31 +189,16 @@ namespace backend { namespace null {
Queue::~Queue() { Queue::~Queue() {
} }
void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) { void Queue::Submit(uint32_t, CommandBuffer* const*) {
auto operations = ToBackend(GetDevice())->AcquirePendingOperations(); auto operations = ToBackend(GetDevice())->AcquirePendingOperations();
for (auto& operation : operations) { for (auto& operation : operations) {
operation->Execute(); operation->Execute();
} }
for (uint32_t i = 0; i < numCommands; ++i) {
commands[i]->Execute();
}
operations.clear(); operations.clear();
} }
// Texture
Texture::Texture(TextureBuilder* builder) : TextureBase(builder) {
}
Texture::~Texture() {
}
void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) {
}
// SwapChain // SwapChain
SwapChain::SwapChain(SwapChainBuilder* builder) : SwapChainBase(builder) { SwapChain::SwapChain(SwapChainBuilder* builder) : SwapChainBase(builder) {

View File

@ -55,7 +55,7 @@ namespace backend { namespace null {
using Sampler = SamplerBase; using Sampler = SamplerBase;
using ShaderModule = ShaderModuleBase; using ShaderModule = ShaderModuleBase;
class SwapChain; class SwapChain;
class Texture; using Texture = TextureBase;
using TextureView = TextureViewBase; using TextureView = TextureViewBase;
struct NullBackendTraits { struct NullBackendTraits {
@ -140,8 +140,6 @@ namespace backend { namespace null {
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; 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 MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() 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); 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(CommandBufferBuilder* builder);
~CommandBuffer(); ~CommandBuffer();
void Execute();
private: private:
CommandIterator mCommands; CommandIterator mCommands;
}; };
@ -168,15 +164,6 @@ namespace backend { namespace null {
void Submit(uint32_t numCommands, CommandBuffer* const* commands); 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 { class SwapChain : public SwapChainBase {
public: public:
SwapChain(SwapChainBuilder* builder); SwapChain(SwapChainBuilder* builder);

View File

@ -54,9 +54,6 @@ namespace backend { namespace opengl {
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
} }
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) {
}
// BufferView // BufferView
BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) { BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) {

View File

@ -34,8 +34,6 @@ namespace backend { namespace opengl {
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; 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 MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override; void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage,
nxt::BufferUsageBit targetUsage) override;
GLuint mBuffer = 0; GLuint mBuffer = 0;
}; };

View File

@ -374,20 +374,6 @@ namespace backend { namespace opengl {
glDeleteFramebuffers(1, &readFBO); glDeleteFramebuffers(1, &readFBO);
} break; } break;
case Command::TransitionBufferUsage: {
TransitionBufferUsageCmd* cmd =
mCommands.NextCommand<TransitionBufferUsageCmd>();
cmd->buffer->UpdateUsageInternal(cmd->usage);
} break;
case Command::TransitionTextureUsage: {
TransitionTextureUsageCmd* cmd =
mCommands.NextCommand<TransitionTextureUsageCmd>();
cmd->texture->UpdateUsageInternal(cmd->usage);
} break;
default: { UNREACHABLE(); } break; default: { UNREACHABLE(); } break;
} }
} }

View File

@ -111,9 +111,6 @@ namespace backend { namespace opengl {
return GetGLFormatInfo(GetFormat()); return GetGLFormatInfo(GetFormat());
} }
void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) {
}
// TextureView // TextureView
TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) { TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) {

View File

@ -37,9 +37,6 @@ namespace backend { namespace opengl {
GLenum GetGLTarget() const; GLenum GetGLTarget() const;
TextureFormatInfo GetGLFormat() const; TextureFormatInfo GetGLFormat() const;
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage,
nxt::TextureUsageBit targetUsage) override;
private: private:
GLuint mHandle; GLuint mHandle;
GLenum mTarget; GLenum mTarget;

View File

@ -238,9 +238,6 @@ namespace backend { namespace vulkan {
// No need to do anything, we keep CPU-visible memory mapped at all time. // No need to do anything, we keep CPU-visible memory mapped at all time.
} }
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit, nxt::BufferUsageBit) {
}
// MapRequestTracker // MapRequestTracker
MapRequestTracker::MapRequestTracker(Device* device) : mDevice(device) { MapRequestTracker::MapRequestTracker(Device* device) : mDevice(device) {

View File

@ -45,8 +45,6 @@ namespace backend { namespace vulkan {
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override; 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 MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override; void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage,
nxt::BufferUsageBit targetUsage) override;
VkBuffer mHandle = VK_NULL_HANDLE; VkBuffer mHandle = VK_NULL_HANDLE;
DeviceMemoryAllocation mMemoryAllocation; DeviceMemoryAllocation mMemoryAllocation;

View File

@ -222,22 +222,6 @@ namespace backend { namespace vulkan {
nextPassNumber++; nextPassNumber++;
} break; } break;
case Command::TransitionBufferUsage: {
TransitionBufferUsageCmd* cmd =
mCommands.NextCommand<TransitionBufferUsageCmd>();
Buffer* buffer = ToBackend(cmd->buffer.Get());
buffer->UpdateUsageInternal(cmd->usage);
} break;
case Command::TransitionTextureUsage: {
TransitionTextureUsageCmd* cmd =
mCommands.NextCommand<TransitionTextureUsageCmd>();
Texture* texture = ToBackend(cmd->texture.Get());
texture->UpdateUsageInternal(cmd->usage);
} break;
default: { UNREACHABLE(); } break; default: { UNREACHABLE(); } break;
} }
} }

View File

@ -343,9 +343,6 @@ namespace backend { namespace vulkan {
mLastUsage = usage; mLastUsage = usage;
} }
void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) {
}
TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) { TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) {
Device* device = ToBackend(builder->GetDevice()); Device* device = ToBackend(builder->GetDevice());

View File

@ -40,9 +40,6 @@ namespace backend { namespace vulkan {
void TransitionUsageNow(VkCommandBuffer commands, nxt::TextureUsageBit usage); void TransitionUsageNow(VkCommandBuffer commands, nxt::TextureUsageBit usage);
private: private:
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage,
nxt::TextureUsageBit targetUsage) override;
VkImage mHandle = VK_NULL_HANDLE; VkImage mHandle = VK_NULL_HANDLE;
DeviceMemoryAllocation mMemoryAllocation; DeviceMemoryAllocation mMemoryAllocation;

View File

@ -54,7 +54,6 @@ list(APPEND UNITTEST_SOURCES
${VALIDATION_TESTS_DIR}/PushConstantsValidationTests.cpp ${VALIDATION_TESTS_DIR}/PushConstantsValidationTests.cpp
${VALIDATION_TESTS_DIR}/RenderPassDescriptorValidationTests.cpp ${VALIDATION_TESTS_DIR}/RenderPassDescriptorValidationTests.cpp
${VALIDATION_TESTS_DIR}/RenderPipelineValidationTests.cpp ${VALIDATION_TESTS_DIR}/RenderPipelineValidationTests.cpp
${VALIDATION_TESTS_DIR}/UsageValidationTests.cpp
${VALIDATION_TESTS_DIR}/VertexBufferValidationTests.cpp ${VALIDATION_TESTS_DIR}/VertexBufferValidationTests.cpp
${VALIDATION_TESTS_DIR}/ValidationTest.cpp ${VALIDATION_TESTS_DIR}/ValidationTest.cpp
${VALIDATION_TESTS_DIR}/ValidationTest.h ${VALIDATION_TESTS_DIR}/ValidationTest.h

View File

@ -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, // We need to enqueue the copy immediately because by the time we resolve the expectation,
// the buffer might have been modified. // the buffer might have been modified.
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.TransitionBufferUsage(source, nxt::BufferUsageBit::TransferSrc)
.TransitionBufferUsage(readback.buffer, nxt::BufferUsageBit::TransferDst)
.CopyBufferToBuffer(source, offset, readback.buffer, readback.offset, size) .CopyBufferToBuffer(source, offset, readback.buffer, readback.offset, size)
.GetResult(); .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, // We need to enqueue the copy immediately because by the time we resolve the expectation,
// the texture might have been modified. // the texture might have been modified.
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() 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) .CopyTextureToBuffer(source, x, y, 0, width, height, 1, level, readback.buffer, readback.offset, rowPitch)
.GetResult(); .GetResult();
@ -276,7 +272,6 @@ void NXTTest::WaitABit() {
void NXTTest::SwapBuffersForCapture() { void NXTTest::SwapBuffersForCapture() {
// Insert a frame boundary for API capture tools. // Insert a frame boundary for API capture tools.
nxt::Texture backBuffer = swapchain.GetNextTexture(); nxt::Texture backBuffer = swapchain.GetNextTexture();
backBuffer.TransitionUsage(nxt::TextureUsageBit::Present);
swapchain.Present(backBuffer); swapchain.Present(backBuffer);
} }
@ -295,7 +290,6 @@ NXTTest::ReadbackReservation NXTTest::ReserveReadback(uint32_t readbackSize) {
slot.buffer = device.CreateBufferBuilder() slot.buffer = device.CreateBufferBuilder()
.SetSize(readbackSize) .SetSize(readbackSize)
.SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
ReadbackReservation reservation; ReadbackReservation reservation;
@ -316,7 +310,6 @@ void NXTTest::MapSlotsSynchronously() {
auto userdata = new MapReadUserdata{this, i}; auto userdata = new MapReadUserdata{this, i};
auto& slot = mReadbackSlots[i]; auto& slot = mReadbackSlots[i];
slot.buffer.TransitionUsage(nxt::BufferUsageBit::MapRead);
slot.buffer.MapReadAsync(0, slot.bufferSize, SlotMapReadCallback, static_cast<nxt::CallbackUserdata>(reinterpret_cast<uintptr_t>(userdata))); slot.buffer.MapReadAsync(0, slot.bufferSize, SlotMapReadCallback, static_cast<nxt::CallbackUserdata>(reinterpret_cast<uintptr_t>(userdata)));
} }

View File

@ -25,7 +25,6 @@ TEST_P(BasicTests, BufferSetSubData) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(4) .SetSize(4)
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
uint8_t value = 187; uint8_t value = 187;

View File

@ -95,7 +95,7 @@ class BlendStateTest : public NXTTest {
uint32_t bufferSize = static_cast<uint32_t>(4 * N * sizeof(float)); uint32_t bufferSize = static_cast<uint32_t>(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() nxt::BufferView view = buffer.CreateBufferViewBuilder()
.SetExtent(0, bufferSize) .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 // 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) { void DoSingleSourceTest(RGBA8 base, const TriangleSpec& triangle, const RGBA8& expected) {
renderPass.color.TransitionUsage(nxt::TextureUsageBit::OutputAttachment);
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderPass.renderPassInfo) .BeginRenderPass(renderPass.renderPassInfo)
// First use the base pipeline to draw a triangle with no blending // First use the base pipeline to draw a triangle with no blending
@ -700,7 +698,6 @@ TEST_P(BlendStateTest, IndependentBlendState) {
.SetFormat(nxt::TextureFormat::R8G8B8A8Unorm) .SetFormat(nxt::TextureFormat::R8G8B8A8Unorm)
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::TransferSrc) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::TransferSrc)
.SetInitialUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult(); .GetResult();
renderTargetViews[i] = renderTargets[i].CreateTextureViewBuilder().GetResult(); renderTargetViews[i] = renderTargets[i].CreateTextureViewBuilder().GetResult();
} }
@ -789,11 +786,6 @@ TEST_P(BlendStateTest, IndependentBlendState) {
RGBA8 expected2 = color2; RGBA8 expected2 = color2;
RGBA8 expected3 = min(color3, base); 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() nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderpass) .BeginRenderPass(renderpass)
.SetRenderPipeline(basePipeline) .SetRenderPipeline(basePipeline)

View File

@ -46,13 +46,11 @@ TEST_P(BufferMapReadTests, SmallReadAtZero) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(1) .SetSize(1)
.SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
uint8_t myData = 187; uint8_t myData = 187;
buffer.SetSubData(0, sizeof(myData), &myData); buffer.SetSubData(0, sizeof(myData), &myData);
buffer.TransitionUsage(nxt::BufferUsageBit::MapRead);
const void* mappedData = MapReadAsyncAndWait(buffer, 0, 1); const void* mappedData = MapReadAsyncAndWait(buffer, 0, 1);
ASSERT_EQ(myData, *reinterpret_cast<const uint8_t*>(mappedData)); ASSERT_EQ(myData, *reinterpret_cast<const uint8_t*>(mappedData));
@ -64,13 +62,11 @@ TEST_P(BufferMapReadTests, SmallReadAtOffset) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(4000) .SetSize(4000)
.SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
uint8_t myData = 234; uint8_t myData = 234;
buffer.SetSubData(2048, sizeof(myData), &myData); buffer.SetSubData(2048, sizeof(myData), &myData);
buffer.TransitionUsage(nxt::BufferUsageBit::MapRead);
const void* mappedData = MapReadAsyncAndWait(buffer, 2048, 4); const void* mappedData = MapReadAsyncAndWait(buffer, 2048, 4);
ASSERT_EQ(myData, *reinterpret_cast<const uint8_t*>(mappedData)); ASSERT_EQ(myData, *reinterpret_cast<const uint8_t*>(mappedData));
@ -82,13 +78,11 @@ TEST_P(BufferMapReadTests, SmallReadAtUnalignedOffset) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(4000) .SetSize(4000)
.SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
uint8_t myData = 213; uint8_t myData = 213;
buffer.SetSubData(3, 1, &myData); buffer.SetSubData(3, 1, &myData);
buffer.TransitionUsage(nxt::BufferUsageBit::MapRead);
const void* mappedData = MapReadAsyncAndWait(buffer, 3, 1); const void* mappedData = MapReadAsyncAndWait(buffer, 3, 1);
ASSERT_EQ(myData, *reinterpret_cast<const uint8_t*>(mappedData)); ASSERT_EQ(myData, *reinterpret_cast<const uint8_t*>(mappedData));
@ -106,12 +100,10 @@ TEST_P(BufferMapReadTests, LargeRead) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(static_cast<uint32_t>(kDataSize * sizeof(uint32_t))) .SetSize(static_cast<uint32_t>(kDataSize * sizeof(uint32_t)))
.SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
buffer.SetSubData(0, kDataSize * sizeof(uint32_t), reinterpret_cast<uint8_t*>(myData.data())); buffer.SetSubData(0, kDataSize * sizeof(uint32_t), reinterpret_cast<uint8_t*>(myData.data()));
buffer.TransitionUsage(nxt::BufferUsageBit::MapRead);
const void* mappedData = MapReadAsyncAndWait(buffer, 0, static_cast<uint32_t>(kDataSize * sizeof(uint32_t))); const void* mappedData = MapReadAsyncAndWait(buffer, 0, static_cast<uint32_t>(kDataSize * sizeof(uint32_t)));
ASSERT_EQ(0, memcmp(mappedData, myData.data(), 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() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(4) .SetSize(4)
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc) .SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc)
.SetInitialUsage(nxt::BufferUsageBit::MapWrite)
.GetResult(); .GetResult();
uint32_t myData = 2934875; uint32_t myData = 2934875;
@ -166,7 +157,6 @@ TEST_P(BufferMapWriteTests, SmallWriteAtOffset) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(4000) .SetSize(4000)
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc) .SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc)
.SetInitialUsage(nxt::BufferUsageBit::MapWrite)
.GetResult(); .GetResult();
uint32_t myData = 2934875; uint32_t myData = 2934875;
@ -188,7 +178,6 @@ TEST_P(BufferMapWriteTests, LargeWrite) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(static_cast<uint32_t>(kDataSize * sizeof(uint32_t))) .SetSize(static_cast<uint32_t>(kDataSize * sizeof(uint32_t)))
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc) .SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc)
.SetInitialUsage(nxt::BufferUsageBit::MapWrite)
.GetResult(); .GetResult();
void* mappedData = MapWriteAsyncAndWait(buffer, 0, kDataSize * sizeof(uint32_t)); void* mappedData = MapWriteAsyncAndWait(buffer, 0, kDataSize * sizeof(uint32_t));
@ -208,7 +197,6 @@ TEST_P(BufferSetSubDataTests, SmallDataAtZero) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(1) .SetSize(1)
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
uint8_t value = 171; uint8_t value = 171;
@ -222,7 +210,6 @@ TEST_P(BufferSetSubDataTests, SmallDataAtOffset) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(4000) .SetSize(4000)
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
constexpr uint32_t kOffset = 2000; constexpr uint32_t kOffset = 2000;
@ -246,7 +233,6 @@ TEST_P(BufferSetSubDataTests, ManySetSubData) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(kSize) .SetSize(kSize)
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
std::vector<uint32_t> expectedData; std::vector<uint32_t> expectedData;
@ -265,7 +251,6 @@ TEST_P(BufferSetSubDataTests, LargeSetSubData) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(kSize) .SetSize(kSize)
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
std::vector<uint32_t> expectedData; std::vector<uint32_t> expectedData;

View File

@ -48,7 +48,6 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) {
.SetSize(kNumUints * sizeof(uint32_t)) .SetSize(kNumUints * sizeof(uint32_t))
.SetAllowedUsage(nxt::BufferUsageBit::Storage | nxt::BufferUsageBit::TransferSrc | .SetAllowedUsage(nxt::BufferUsageBit::Storage | nxt::BufferUsageBit::TransferSrc |
nxt::BufferUsageBit::TransferDst) nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
std::array<uint32_t, kNumUints> expected; std::array<uint32_t, kNumUints> expected;
for (uint32_t i = 0; i < kNumUints; ++i) { for (uint32_t i = 0; i < kNumUints; ++i) {
@ -65,7 +64,6 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) {
.SetSize(kNumUints * sizeof(uint32_t)) .SetSize(kNumUints * sizeof(uint32_t))
.SetAllowedUsage(nxt::BufferUsageBit::Storage | nxt::BufferUsageBit::TransferSrc | .SetAllowedUsage(nxt::BufferUsageBit::Storage | nxt::BufferUsageBit::TransferSrc |
nxt::BufferUsageBit::TransferDst) nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
std::array<uint32_t, kNumUints> zero{}; std::array<uint32_t, kNumUints> zero{};
dst.SetSubData(0, sizeof(zero), reinterpret_cast<const uint8_t*>(zero.data())); dst.SetSubData(0, sizeof(zero), reinterpret_cast<const uint8_t*>(zero.data()));
@ -80,8 +78,6 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) {
.SetBufferViews(1, 1, &dstView) .SetBufferViews(1, 1, &dstView)
.GetResult(); .GetResult();
auto commands = device.CreateCommandBufferBuilder() auto commands = device.CreateCommandBufferBuilder()
.TransitionBufferUsage(src, nxt::BufferUsageBit::Storage)
.TransitionBufferUsage(dst, nxt::BufferUsageBit::Storage)
.BeginComputePass() .BeginComputePass()
.SetComputePipeline(pipeline) .SetComputePipeline(pipeline)
.SetBindGroup(0, bindGroup) .SetBindGroup(0, bindGroup)

View File

@ -89,12 +89,11 @@ class CopyTests_T2B : public CopyTests {
// Create an upload buffer and use it to populate the `level` mip of the texture // Create an upload buffer and use it to populate the `level` mip of the texture
std::vector<RGBA8> textureData(texelCount); std::vector<RGBA8> textureData(texelCount);
FillTextureData(width, height, rowPitch / kBytesPerTexel, textureData.data()); FillTextureData(width, height, rowPitch / kBytesPerTexel, textureData.data());
nxt::Buffer uploadBuffer = utils::CreateFrozenBufferFromData(device, textureData.data(), static_cast<uint32_t>(sizeof(RGBA8) * textureData.size()), nxt::BufferUsageBit::TransferSrc); nxt::Buffer uploadBuffer = utils::CreateBufferFromData(device, textureData.data(), static_cast<uint32_t>(sizeof(RGBA8) * textureData.size()), nxt::BufferUsageBit::TransferSrc);
nxt::CommandBuffer commands[2]; nxt::CommandBuffer commands[2];
commands[0] = device.CreateCommandBufferBuilder() commands[0] = device.CreateCommandBufferBuilder()
.TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst)
.CopyBufferToTexture(uploadBuffer, 0, rowPitch, texture, 0, 0, 0, width, height, 1, textureSpec.level) .CopyBufferToTexture(uploadBuffer, 0, rowPitch, texture, 0, 0, 0, width, height, 1, textureSpec.level)
.GetResult(); .GetResult();
@ -104,15 +103,12 @@ class CopyTests_T2B : public CopyTests {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(bufferSpec.size) .SetSize(bufferSpec.size)
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
std::vector<RGBA8> emptyData(bufferSpec.size / kBytesPerTexel); std::vector<RGBA8> emptyData(bufferSpec.size / kBytesPerTexel);
buffer.SetSubData(0, static_cast<uint32_t>(emptyData.size() * sizeof(RGBA8)), reinterpret_cast<const uint8_t*>(emptyData.data())); buffer.SetSubData(0, static_cast<uint32_t>(emptyData.size() * sizeof(RGBA8)), reinterpret_cast<const uint8_t*>(emptyData.data()));
// Copy the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] from the `level` mip into the buffer at the specified `offset` and `rowPitch` // 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() 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) .CopyTextureToBuffer(texture, textureSpec.x, textureSpec.y, 0, textureSpec.copyWidth, textureSpec.copyHeight, 1, textureSpec.level, buffer, bufferSpec.offset, bufferSpec.rowPitch)
.GetResult(); .GetResult();
@ -154,7 +150,6 @@ protected:
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetSize(bufferSpec.size) .SetSize(bufferSpec.size)
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
std::vector<RGBA8> bufferData(bufferSpec.size / kBytesPerTexel); std::vector<RGBA8> bufferData(bufferSpec.size / kBytesPerTexel);
FillBufferData(bufferData.data(), bufferData.size()); FillBufferData(bufferData.data(), bufferData.size());
@ -182,18 +177,15 @@ protected:
uint32_t texelCount = texelsPerRow * (height - 1) + width; uint32_t texelCount = texelsPerRow * (height - 1) + width;
std::vector<RGBA8> emptyData(texelCount); std::vector<RGBA8> emptyData(texelCount);
nxt::Buffer uploadBuffer = utils::CreateFrozenBufferFromData(device, emptyData.data(), static_cast<uint32_t>(sizeof(RGBA8) * emptyData.size()), nxt::BufferUsageBit::TransferSrc); nxt::Buffer uploadBuffer = utils::CreateBufferFromData(device, emptyData.data(), static_cast<uint32_t>(sizeof(RGBA8) * emptyData.size()), nxt::BufferUsageBit::TransferSrc);
commands[0] = device.CreateCommandBufferBuilder() commands[0] = device.CreateCommandBufferBuilder()
.TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst)
.CopyBufferToTexture(uploadBuffer, 0, rowPitch, texture, 0, 0, 0, width, height, 1, textureSpec.level) .CopyBufferToTexture(uploadBuffer, 0, rowPitch, texture, 0, 0, 0, width, height, 1, textureSpec.level)
.GetResult(); .GetResult();
} }
// Copy to the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] at the `level` mip from the buffer at the specified `offset` and `rowPitch` // 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() 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) .CopyBufferToTexture(buffer, bufferSpec.offset, bufferSpec.rowPitch, texture, textureSpec.x, textureSpec.y, 0, textureSpec.copyWidth, textureSpec.copyHeight, 1, textureSpec.level)
.GetResult(); .GetResult();

View File

@ -30,7 +30,6 @@ class DepthStencilStateTest : public NXTTest {
.SetFormat(nxt::TextureFormat::R8G8B8A8Unorm) .SetFormat(nxt::TextureFormat::R8G8B8A8Unorm)
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::TransferSrc) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::TransferSrc)
.SetInitialUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult(); .GetResult();
renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult(); renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult();
@ -41,7 +40,6 @@ class DepthStencilStateTest : public NXTTest {
.SetFormat(nxt::TextureFormat::D32FloatS8Uint) .SetFormat(nxt::TextureFormat::D32FloatS8Uint)
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment)
.SetInitialUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult(); .GetResult();
depthTextureView = depthTexture.CreateTextureViewBuilder().GetResult(); depthTextureView = depthTexture.CreateTextureViewBuilder().GetResult();
@ -193,7 +191,6 @@ class DepthStencilStateTest : public NXTTest {
float depth; float depth;
}; };
renderTarget.TransitionUsage(nxt::TextureUsageBit::OutputAttachment);
builder.BeginRenderPass(renderpass); builder.BeginRenderPass(renderpass);
for (size_t i = 0; i < testParams.size(); ++i) { for (size_t i = 0; i < testParams.size(); ++i) {
@ -204,7 +201,7 @@ class DepthStencilStateTest : public NXTTest {
test.depth, test.depth,
}; };
// Upload a buffer for each triangle's depth and color data // 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() nxt::BufferView view = buffer.CreateBufferViewBuilder()
.SetExtent(0, sizeof(TriangleData)) .SetExtent(0, sizeof(TriangleData))

View File

@ -55,13 +55,13 @@ class DrawElementsTest : public NXTTest {
.SetInputState(inputState) .SetInputState(inputState)
.GetResult(); .GetResult();
vertexBuffer = utils::CreateFrozenBufferFromData<float>(device, nxt::BufferUsageBit::Vertex, { vertexBuffer = utils::CreateBufferFromData<float>(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,
-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<uint32_t>(device, nxt::BufferUsageBit::Index, { indexBuffer = utils::CreateBufferFromData<uint32_t>(device, nxt::BufferUsageBit::Index, {
0, 1, 2, 0, 3, 1 0, 1, 2, 0, 3, 1
}); });
} }

View File

@ -66,14 +66,14 @@ class IndexFormatTest : public NXTTest {
TEST_P(IndexFormatTest, Uint32) { TEST_P(IndexFormatTest, Uint32) {
nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint32); nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint32);
nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData<float>(device, nxt::BufferUsageBit::Vertex, { nxt::Buffer vertexBuffer = utils::CreateBufferFromData<float>(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, // 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, 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. // If this is interpreted as Uint16, then it would be 0, 1, 0, ... and would draw nothing.
nxt::Buffer indexBuffer = utils::CreateFrozenBufferFromData<uint32_t>(device, nxt::BufferUsageBit::Index, { nxt::Buffer indexBuffer = utils::CreateBufferFromData<uint32_t>(device, nxt::BufferUsageBit::Index, {
1, 2, 3 1, 2, 3
}); });
@ -96,13 +96,13 @@ TEST_P(IndexFormatTest, Uint32) {
TEST_P(IndexFormatTest, Uint16) { TEST_P(IndexFormatTest, Uint16) {
nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint16); nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint16);
nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData<float>(device, nxt::BufferUsageBit::Vertex, { nxt::Buffer vertexBuffer = utils::CreateBufferFromData<float>(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,
-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 // If this is interpreted as uint32, it will have index 1 and 2 be both 0 and render nothing
nxt::Buffer indexBuffer = utils::CreateFrozenBufferFromData<uint16_t>(device, nxt::BufferUsageBit::Index, { nxt::Buffer indexBuffer = utils::CreateBufferFromData<uint16_t>(device, nxt::BufferUsageBit::Index, {
1, 2, 0, 0, 0, 0 1, 2, 0, 0, 0, 0
}); });
@ -137,14 +137,14 @@ TEST_P(IndexFormatTest, Uint16) {
TEST_P(IndexFormatTest, Uint32PrimitiveRestart) { TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint32); nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint32);
nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData<float>(device, nxt::BufferUsageBit::Vertex, { nxt::Buffer vertexBuffer = utils::CreateBufferFromData<float>(device, nxt::BufferUsageBit::Vertex, {
0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, -1.0f, 0.0f, 1.0f, 0.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<uint32_t>(device, nxt::BufferUsageBit::Index, { nxt::Buffer indexBuffer = utils::CreateBufferFromData<uint32_t>(device, nxt::BufferUsageBit::Index, {
0, 1, 2, 0xFFFFFFFFu, 3, 4, 2, 0, 1, 2, 0xFFFFFFFFu, 3, 4, 2,
}); });
@ -169,14 +169,14 @@ TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
TEST_P(IndexFormatTest, Uint16PrimitiveRestart) { TEST_P(IndexFormatTest, Uint16PrimitiveRestart) {
nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint16); nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint16);
nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData<float>(device, nxt::BufferUsageBit::Vertex, { nxt::Buffer vertexBuffer = utils::CreateBufferFromData<float>(device, nxt::BufferUsageBit::Vertex, {
0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, -1.0f, 0.0f, 1.0f, 0.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<uint16_t>(device, nxt::BufferUsageBit::Index, { nxt::Buffer indexBuffer = utils::CreateBufferFromData<uint16_t>(device, nxt::BufferUsageBit::Index, {
0, 1, 2, 0xFFFFu, 3, 4, 2, 0, 1, 2, 0xFFFFu, 3, 4, 2,
}); });
@ -209,14 +209,14 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) {
nxt::RenderPipeline pipeline32 = MakeTestPipeline(nxt::IndexFormat::Uint32); nxt::RenderPipeline pipeline32 = MakeTestPipeline(nxt::IndexFormat::Uint32);
nxt::RenderPipeline pipeline16 = MakeTestPipeline(nxt::IndexFormat::Uint16); nxt::RenderPipeline pipeline16 = MakeTestPipeline(nxt::IndexFormat::Uint16);
nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData<float>(device, nxt::BufferUsageBit::Vertex, { nxt::Buffer vertexBuffer = utils::CreateBufferFromData<float>(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, // 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, 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. // If this is interpreted as Uint16, then it would be 0, 1, 0, ... and would draw nothing.
nxt::Buffer indexBuffer = utils::CreateFrozenBufferFromData<uint32_t>(device, nxt::BufferUsageBit::Index, { nxt::Buffer indexBuffer = utils::CreateBufferFromData<uint32_t>(device, nxt::BufferUsageBit::Index, {
1, 2, 3 1, 2, 3
}); });
@ -244,12 +244,12 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) {
TEST_P(IndexFormatTest, DISABLED_SetIndexBufferBeforeSetPipeline) { TEST_P(IndexFormatTest, DISABLED_SetIndexBufferBeforeSetPipeline) {
nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint32); nxt::RenderPipeline pipeline = MakeTestPipeline(nxt::IndexFormat::Uint32);
nxt::Buffer vertexBuffer = utils::CreateFrozenBufferFromData<float>(device, nxt::BufferUsageBit::Vertex, { nxt::Buffer vertexBuffer = utils::CreateBufferFromData<float>(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,
-1.0f, -1.0f, 0.0f, 1.0f -1.0f, -1.0f, 0.0f, 1.0f
}); });
nxt::Buffer indexBuffer = utils::CreateFrozenBufferFromData<uint32_t>(device, nxt::BufferUsageBit::Index, { nxt::Buffer indexBuffer = utils::CreateBufferFromData<uint32_t>(device, nxt::BufferUsageBit::Index, {
0, 1, 2 0, 1, 2
}); });

View File

@ -155,7 +155,7 @@ class InputStateTest : public NXTTest {
template<typename T> template<typename T>
nxt::Buffer MakeVertexBuffer(std::vector<T> data) { nxt::Buffer MakeVertexBuffer(std::vector<T> data) {
return utils::CreateFrozenBufferFromData(device, data.data(), static_cast<uint32_t>(data.size() * sizeof(T)), nxt::BufferUsageBit::Vertex); return utils::CreateBufferFromData(device, data.data(), static_cast<uint32_t>(data.size() * sizeof(T)), nxt::BufferUsageBit::Vertex);
} }
struct DrawVertexBuffer { struct DrawVertexBuffer {
@ -168,7 +168,6 @@ class InputStateTest : public NXTTest {
nxt::CommandBufferBuilder builder = device.CreateCommandBufferBuilder(); nxt::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
renderPass.color.TransitionUsage(nxt::TextureUsageBit::OutputAttachment);
builder.BeginRenderPass(renderPass.renderPassInfo) builder.BeginRenderPass(renderPass.renderPassInfo)
.SetRenderPipeline(pipeline); .SetRenderPipeline(pipeline);

View File

@ -169,7 +169,7 @@ class PrimitiveTopologyTest : public NXTTest {
.SetInput(0, 4 * sizeof(float), nxt::InputStepMode::Vertex) .SetInput(0, 4 * sizeof(float), nxt::InputStepMode::Vertex)
.GetResult(); .GetResult();
vertexBuffer = utils::CreateFrozenBufferFromData(device, kVertices, sizeof(kVertices), nxt::BufferUsageBit::Vertex); vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices), nxt::BufferUsageBit::Vertex);
} }
struct LocationSpec { struct LocationSpec {
@ -193,7 +193,6 @@ class PrimitiveTopologyTest : public NXTTest {
.SetPrimitiveTopology(primitiveTopology) .SetPrimitiveTopology(primitiveTopology)
.GetResult(); .GetResult();
renderPass.color.TransitionUsage(nxt::TextureUsageBit::OutputAttachment);
static const uint32_t zeroOffset = 0; static const uint32_t zeroOffset = 0;
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderPass.renderPassInfo) .BeginRenderPass(renderPass.renderPassInfo)

View File

@ -33,7 +33,6 @@ class PushConstantTest: public NXTTest {
nxt::Buffer buf1 = device.CreateBufferBuilder() nxt::Buffer buf1 = device.CreateBufferBuilder()
.SetSize(4) .SetSize(4)
.SetAllowedUsage(nxt::BufferUsageBit::Storage | nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::Storage | nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
uint32_t one = 1; uint32_t one = 1;
buf1.SetSubData(0, sizeof(one), reinterpret_cast<uint8_t*>(&one)); buf1.SetSubData(0, sizeof(one), reinterpret_cast<uint8_t*>(&one));
@ -42,7 +41,6 @@ class PushConstantTest: public NXTTest {
.SetSize(4) .SetSize(4)
.SetAllowedUsage(nxt::BufferUsageBit::Storage) .SetAllowedUsage(nxt::BufferUsageBit::Storage)
.GetResult(); .GetResult();
buf2.FreezeUsage(nxt::BufferUsageBit::Storage);
nxt::ShaderStageBit kAllStages = nxt::ShaderStageBit::Compute | nxt::ShaderStageBit::Fragment | nxt::ShaderStageBit::Vertex; nxt::ShaderStageBit kAllStages = nxt::ShaderStageBit::Compute | nxt::ShaderStageBit::Fragment | nxt::ShaderStageBit::Vertex;
constexpr nxt::ShaderStageBit kNoStages{}; constexpr nxt::ShaderStageBit kNoStages{};
@ -213,7 +211,6 @@ TEST_P(PushConstantTest, ComputePassDefaultsToZero) {
uint32_t notZero = 42; uint32_t notZero = 42;
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.TransitionBufferUsage(binding.resultBuffer, nxt::BufferUsageBit::Storage)
.BeginComputePass() .BeginComputePass()
// Test compute push constants are set to zero by default. // Test compute push constants are set to zero by default.
.SetComputePipeline(pipeline) .SetComputePipeline(pipeline)
@ -273,7 +270,6 @@ TEST_P(PushConstantTest, VariousConstantTypes) {
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.TransitionBufferUsage(binding.resultBuffer, nxt::BufferUsageBit::Storage)
.BeginComputePass() .BeginComputePass()
.SetPushConstants(nxt::ShaderStageBit::Compute, 0, 3, reinterpret_cast<uint32_t*>(&values)) .SetPushConstants(nxt::ShaderStageBit::Compute, 0, 3, reinterpret_cast<uint32_t*>(&values))
.SetComputePipeline(pipeline) .SetComputePipeline(pipeline)
@ -300,8 +296,6 @@ TEST_P(PushConstantTest, InheritThroughPipelineLayoutChange) {
uint32_t one = 1; uint32_t one = 1;
uint32_t two = 2; uint32_t two = 2;
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.TransitionBufferUsage(binding1.resultBuffer, nxt::BufferUsageBit::Storage)
.TransitionBufferUsage(binding2.resultBuffer, nxt::BufferUsageBit::Storage)
.BeginComputePass() .BeginComputePass()
// Set Push constant before there is a pipeline set // Set Push constant before there is a pipeline set
.SetPushConstants(nxt::ShaderStageBit::Compute, 0, 1, &one) .SetPushConstants(nxt::ShaderStageBit::Compute, 0, 1, &one)
@ -335,7 +329,6 @@ TEST_P(PushConstantTest, SetAllConstantsToNonZero) {
nxt::ComputePipeline pipeline = MakeTestComputePipeline(binding.layout, spec); nxt::ComputePipeline pipeline = MakeTestComputePipeline(binding.layout, spec);
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.TransitionBufferUsage(binding.resultBuffer, nxt::BufferUsageBit::Storage)
.BeginComputePass() .BeginComputePass()
.SetPushConstants(nxt::ShaderStageBit::Compute, 0, kMaxPushConstants, &values[0]) .SetPushConstants(nxt::ShaderStageBit::Compute, 0, kMaxPushConstants, &values[0])
.SetComputePipeline(pipeline) .SetComputePipeline(pipeline)

View File

@ -61,7 +61,6 @@ class RenderPassLoadOpTests : public NXTTest {
.SetFormat(nxt::TextureFormat::R8G8B8A8Unorm) .SetFormat(nxt::TextureFormat::R8G8B8A8Unorm)
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::TransferSrc) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | nxt::TextureUsageBit::TransferSrc)
.SetInitialUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult(); .GetResult();
renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult(); renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult();

View File

@ -41,7 +41,6 @@ protected:
void SetUp() override { void SetUp() override {
NXTTest::SetUp(); NXTTest::SetUp();
mRenderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); mRenderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
mRenderPass.color.TransitionUsage(nxt::TextureUsageBit::OutputAttachment);
mBindGroupLayout = utils::MakeBindGroupLayout( mBindGroupLayout = utils::MakeBindGroupLayout(
device, { device, {
@ -97,14 +96,12 @@ protected:
data[0] = data[rowPixels + 1] = black; data[0] = data[rowPixels + 1] = black;
data[1] = data[rowPixels] = white; 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() nxt::CommandBuffer copy = device.CreateCommandBufferBuilder()
.TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst)
.CopyBufferToTexture(stagingBuffer, 0, 256, texture, 0, 0, 0, 2, 2, 1, 0) .CopyBufferToTexture(stagingBuffer, 0, 256, texture, 0, 0, 0, 2, 2, 1, 0)
.GetResult(); .GetResult();
queue.Submit(1, &copy); queue.Submit(1, &copy);
texture.FreezeUsage(nxt::TextureUsageBit::Sampled);
mTextureView = texture.CreateTextureViewBuilder().GetResult(); mTextureView = texture.CreateTextureViewBuilder().GetResult();
} }

View File

@ -483,8 +483,8 @@ TEST_F(WireTests, CallsSkippedAfterBuilderError) {
nxtBuffer buffer = nxtBufferBuilderGetResult(bufferBuilder); // Hey look an error! nxtBuffer buffer = nxtBufferBuilderGetResult(bufferBuilder); // Hey look an error!
// These calls will be skipped because of the error // These calls will be skipped because of the error
nxtBufferTransitionUsage(buffer, NXT_BUFFER_USAGE_BIT_UNIFORM); nxtBufferSetSubData(buffer, 0, 0, nullptr);
nxtCommandBufferBuilderTransitionBufferUsage(cmdBufBuilder, buffer, NXT_BUFFER_USAGE_BIT_UNIFORM); nxtCommandBufferBuilderSetIndexBuffer(cmdBufBuilder, buffer, 0);
nxtCommandBufferBuilderGetResult(cmdBufBuilder); nxtCommandBufferBuilderGetResult(cmdBufBuilder);
nxtCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder(); nxtCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
@ -502,8 +502,8 @@ TEST_F(WireTests, CallsSkippedAfterBuilderError) {
return nullptr; return nullptr;
})); }));
EXPECT_CALL(api, BufferTransitionUsage(_, _)).Times(0); EXPECT_CALL(api, BufferSetSubData(_, _, _, _)).Times(0);
EXPECT_CALL(api, CommandBufferBuilderTransitionBufferUsage(_, _, _)).Times(0); EXPECT_CALL(api, CommandBufferBuilderSetIndexBuffer(_, _, _)).Times(0);
EXPECT_CALL(api, CommandBufferBuilderGetResult(_)).Times(0); EXPECT_CALL(api, CommandBufferBuilderGetResult(_)).Times(0);
FlushClient(); FlushClient();

View File

@ -26,7 +26,6 @@ TEST_F(BindGroupValidationTest, BufferViewOffset) {
auto buffer = device.CreateBufferBuilder() auto buffer = device.CreateBufferBuilder()
.SetAllowedUsage(nxt::BufferUsageBit::Uniform) .SetAllowedUsage(nxt::BufferUsageBit::Uniform)
.SetInitialUsage(nxt::BufferUsageBit::Uniform)
.SetSize(512) .SetSize(512)
.GetResult(); .GetResult();

View File

@ -46,21 +46,18 @@ class BufferValidationTest : public ValidationTest {
return device.CreateBufferBuilder() return device.CreateBufferBuilder()
.SetSize(size) .SetSize(size)
.SetAllowedUsage(nxt::BufferUsageBit::MapRead) .SetAllowedUsage(nxt::BufferUsageBit::MapRead)
.SetInitialUsage(nxt::BufferUsageBit::MapRead)
.GetResult(); .GetResult();
} }
nxt::Buffer CreateMapWriteBuffer(uint32_t size) { nxt::Buffer CreateMapWriteBuffer(uint32_t size) {
return device.CreateBufferBuilder() return device.CreateBufferBuilder()
.SetSize(size) .SetSize(size)
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite) .SetAllowedUsage(nxt::BufferUsageBit::MapWrite)
.SetInitialUsage(nxt::BufferUsageBit::MapWrite)
.GetResult(); .GetResult();
} }
nxt::Buffer CreateSetSubDataBuffer(uint32_t size) { nxt::Buffer CreateSetSubDataBuffer(uint32_t size) {
return device.CreateBufferBuilder() return device.CreateBufferBuilder()
.SetSize(size) .SetSize(size)
.SetAllowedUsage(nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
} }
@ -86,15 +83,6 @@ class BufferValidationTest : public ValidationTest {
// Test case where creation should succeed // Test case where creation should succeed
TEST_F(BufferValidationTest, CreationSuccess) { TEST_F(BufferValidationTest, CreationSuccess) {
// Success // 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()) nxt::Buffer buf = AssertWillBeSuccess(device.CreateBufferBuilder())
.SetSize(4) .SetSize(4)
@ -111,7 +99,6 @@ TEST_F(BufferValidationTest, CreationDuplicates) {
.SetSize(4) .SetSize(4)
.SetSize(3) .SetSize(3)
.SetAllowedUsage(nxt::BufferUsageBit::Uniform) .SetAllowedUsage(nxt::BufferUsageBit::Uniform)
.SetInitialUsage(nxt::BufferUsageBit::Uniform)
.GetResult(); .GetResult();
} }
@ -121,28 +108,8 @@ TEST_F(BufferValidationTest, CreationDuplicates) {
.SetSize(4) .SetSize(4)
.SetAllowedUsage(nxt::BufferUsageBit::Vertex) .SetAllowedUsage(nxt::BufferUsageBit::Vertex)
.SetAllowedUsage(nxt::BufferUsageBit::Uniform) .SetAllowedUsage(nxt::BufferUsageBit::Uniform)
.SetInitialUsage(nxt::BufferUsageBit::Uniform)
.GetResult(); .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 // Test failure when required properties are missing
@ -251,8 +218,7 @@ TEST_F(BufferValidationTest, MapWriteOutOfRange) {
TEST_F(BufferValidationTest, MapReadWrongUsage) { TEST_F(BufferValidationTest, MapReadWrongUsage) {
nxt::Buffer buf = device.CreateBufferBuilder() nxt::Buffer buf = device.CreateBufferBuilder()
.SetSize(4) .SetSize(4)
.SetAllowedUsage(nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst) .SetAllowedUsage(nxt::BufferUsageBit::TransferDst)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.GetResult(); .GetResult();
nxt::CallbackUserdata userdata = 40600; nxt::CallbackUserdata userdata = 40600;
@ -266,8 +232,7 @@ TEST_F(BufferValidationTest, MapReadWrongUsage) {
TEST_F(BufferValidationTest, MapWriteWrongUsage) { TEST_F(BufferValidationTest, MapWriteWrongUsage) {
nxt::Buffer buf = device.CreateBufferBuilder() nxt::Buffer buf = device.CreateBufferBuilder()
.SetSize(4) .SetSize(4)
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc) .SetAllowedUsage(nxt::BufferUsageBit::TransferSrc)
.SetInitialUsage(nxt::BufferUsageBit::TransferSrc)
.GetResult(); .GetResult();
nxt::CallbackUserdata userdata = 40600; nxt::CallbackUserdata userdata = 40600;
@ -505,8 +470,7 @@ TEST_F(BufferValidationTest, SetSubDataOutOfBounds) {
TEST_F(BufferValidationTest, SetSubDataWrongUsage) { TEST_F(BufferValidationTest, SetSubDataWrongUsage) {
nxt::Buffer buf = device.CreateBufferBuilder() nxt::Buffer buf = device.CreateBufferBuilder()
.SetSize(1) .SetSize(1)
.SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Vertex) .SetAllowedUsage(nxt::BufferUsageBit::Vertex)
.SetInitialUsage(nxt::BufferUsageBit::Vertex)
.GetResult(); .GetResult();
uint8_t foo = 0; uint8_t foo = 0;

View File

@ -23,11 +23,10 @@ class CopyCommandTest : public ValidationTest {
.SetSize(size) .SetSize(size)
.SetAllowedUsage(usage) .SetAllowedUsage(usage)
.GetResult(); .GetResult();
buf.FreezeUsage(usage);
return buf; 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::TextureFormat format, nxt::TextureUsageBit usage) {
nxt::Texture tex = AssertWillBeSuccess(device.CreateTextureBuilder()) nxt::Texture tex = AssertWillBeSuccess(device.CreateTextureBuilder())
.SetDimension(nxt::TextureDimension::e2D) .SetDimension(nxt::TextureDimension::e2D)
@ -36,7 +35,6 @@ class CopyCommandTest : public ValidationTest {
.SetMipLevels(levels) .SetMipLevels(levels)
.SetAllowedUsage(usage) .SetAllowedUsage(usage)
.GetResult(); .GetResult();
tex.FreezeUsage(usage);
return tex; return tex;
} }
@ -123,7 +121,7 @@ class CopyCommandTest_B2T : public CopyCommandTest {
TEST_F(CopyCommandTest_B2T, Success) { TEST_F(CopyCommandTest_B2T, Success) {
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
nxt::Buffer source = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); 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); nxt::TextureUsageBit::TransferDst);
// Different copies, including some that touch the OOB condition // Different copies, including some that touch the OOB condition
@ -169,7 +167,7 @@ TEST_F(CopyCommandTest_B2T, Success) {
TEST_F(CopyCommandTest_B2T, OutOfBoundsOnBuffer) { TEST_F(CopyCommandTest_B2T, OutOfBoundsOnBuffer) {
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
nxt::Buffer source = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); 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); nxt::TextureUsageBit::TransferDst);
// OOB on the buffer because we copy too many pixels // OOB on the buffer because we copy too many pixels
@ -209,7 +207,7 @@ TEST_F(CopyCommandTest_B2T, OutOfBoundsOnBuffer) {
TEST_F(CopyCommandTest_B2T, OutOfBoundsOnTexture) { TEST_F(CopyCommandTest_B2T, OutOfBoundsOnTexture) {
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
nxt::Buffer source = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); 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); nxt::TextureUsageBit::TransferDst);
// OOB on the texture because x + width overflows // 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 that we force Z=0 and Depth=1 on copies to 2D textures
TEST_F(CopyCommandTest_B2T, ZDepthConstraintFor2DTextures) { TEST_F(CopyCommandTest_B2T, ZDepthConstraintFor2DTextures) {
nxt::Buffer source = CreateFrozenBuffer(16 * 4, nxt::BufferUsageBit::TransferSrc); 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); nxt::TextureUsageBit::TransferDst);
// Z=1 on an empty copy still errors // Z=1 on an empty copy still errors
@ -266,9 +264,9 @@ TEST_F(CopyCommandTest_B2T, ZDepthConstraintFor2DTextures) {
TEST_F(CopyCommandTest_B2T, IncorrectUsage) { TEST_F(CopyCommandTest_B2T, IncorrectUsage) {
nxt::Buffer source = CreateFrozenBuffer(16 * 4, nxt::BufferUsageBit::TransferSrc); nxt::Buffer source = CreateFrozenBuffer(16 * 4, nxt::BufferUsageBit::TransferSrc);
nxt::Buffer vertex = CreateFrozenBuffer(16 * 4, nxt::BufferUsageBit::Vertex); 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::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); nxt::TextureUsageBit::Sampled);
// Incorrect source usage // Incorrect source usage
@ -289,7 +287,7 @@ TEST_F(CopyCommandTest_B2T, IncorrectUsage) {
TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) { TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) {
uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1); uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1);
nxt::Buffer source = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); 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); nxt::TextureUsageBit::TransferDst);
// Default row pitch is not 256-byte aligned // Default row pitch is not 256-byte aligned
@ -318,7 +316,7 @@ TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) {
TEST_F(CopyCommandTest_B2T, IncorrectBufferOffset) { TEST_F(CopyCommandTest_B2T, IncorrectBufferOffset) {
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
nxt::Buffer source = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); 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); nxt::TextureUsageBit::TransferDst);
// Correct usage // Correct usage
@ -351,7 +349,7 @@ class CopyCommandTest_T2B : public CopyCommandTest {
// Test a successfull T2B copy // Test a successfull T2B copy
TEST_F(CopyCommandTest_T2B, Success) { TEST_F(CopyCommandTest_T2B, Success) {
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); 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::TextureUsageBit::TransferSrc);
nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst);
@ -397,7 +395,7 @@ TEST_F(CopyCommandTest_T2B, Success) {
// Test OOB conditions on the texture // Test OOB conditions on the texture
TEST_F(CopyCommandTest_T2B, OutOfBoundsOnTexture) { TEST_F(CopyCommandTest_T2B, OutOfBoundsOnTexture) {
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); 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::TextureUsageBit::TransferSrc);
nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst);
@ -433,7 +431,7 @@ TEST_F(CopyCommandTest_T2B, OutOfBoundsOnTexture) {
// Test OOB conditions on the buffer // Test OOB conditions on the buffer
TEST_F(CopyCommandTest_T2B, OutOfBoundsOnBuffer) { TEST_F(CopyCommandTest_T2B, OutOfBoundsOnBuffer) {
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); 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::TextureUsageBit::TransferSrc);
nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); 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 that we force Z=0 and Depth=1 on copies from to 2D textures
TEST_F(CopyCommandTest_T2B, ZDepthConstraintFor2DTextures) { TEST_F(CopyCommandTest_T2B, ZDepthConstraintFor2DTextures) {
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); 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::TextureUsageBit::TransferSrc);
nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); 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 T2B copies with incorrect buffer usage
TEST_F(CopyCommandTest_T2B, IncorrectUsage) { TEST_F(CopyCommandTest_T2B, IncorrectUsage) {
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1); 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::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::TextureUsageBit::Sampled);
nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst);
nxt::Buffer vertex = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::Vertex); nxt::Buffer vertex = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::Vertex);
@ -519,7 +517,7 @@ TEST_F(CopyCommandTest_T2B, IncorrectUsage) {
TEST_F(CopyCommandTest_T2B, IncorrectRowPitch) { TEST_F(CopyCommandTest_T2B, IncorrectRowPitch) {
uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1); 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::TextureUsageBit::TransferDst);
nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferSrc); 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 T2B copies with incorrect buffer offset usage
TEST_F(CopyCommandTest_T2B, IncorrectBufferOffset) { TEST_F(CopyCommandTest_T2B, IncorrectBufferOffset) {
uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1); 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::TextureUsageBit::TransferSrc);
nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst); nxt::Buffer destination = CreateFrozenBuffer(bufferSize, nxt::BufferUsageBit::TransferDst);

View File

@ -28,7 +28,6 @@ nxt::TextureView Create2DAttachment(nxt::Device& device, uint32_t width, uint32_
.SetFormat(format) .SetFormat(format)
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment)
.SetInitialUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult(); .GetResult();
return attachment.CreateTextureViewBuilder() return attachment.CreateTextureViewBuilder()

View File

@ -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 <gmock/gmock.h>
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);
}

View File

@ -77,7 +77,6 @@ nxt::RenderPassDescriptor ValidationTest::CreateSimpleRenderPass() {
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult(); .GetResult();
colorBuffer.FreezeUsage(nxt::TextureUsageBit::OutputAttachment);
auto colorView = colorBuffer.CreateTextureViewBuilder() auto colorView = colorBuffer.CreateTextureViewBuilder()
.GetResult(); .GetResult();
@ -126,7 +125,6 @@ ValidationTest::DummyRenderPass ValidationTest::CreateDummyRenderPass() {
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult(); .GetResult();
dummy.attachment.FreezeUsage(nxt::TextureUsageBit::OutputAttachment);
nxt::TextureView view = AssertWillBeSuccess(dummy.attachment.CreateTextureViewBuilder()).GetResult(); nxt::TextureView view = AssertWillBeSuccess(dummy.attachment.CreateTextureViewBuilder()).GetResult();

View File

@ -41,7 +41,6 @@ class VertexBufferValidationTest : public ValidationTest {
.SetSize(256) .SetSize(256)
.SetAllowedUsage(nxt::BufferUsageBit::Vertex) .SetAllowedUsage(nxt::BufferUsageBit::Vertex)
.GetResult(); .GetResult();
buffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
} }
return buffers; return buffers;
} }

View File

@ -97,17 +97,15 @@ namespace utils {
return builder.GetResult(); return builder.GetResult();
} }
nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, nxt::Buffer CreateBufferFromData(const nxt::Device& device,
const void* data, const void* data,
uint32_t size, uint32_t size,
nxt::BufferUsageBit usage) { nxt::BufferUsageBit usage) {
nxt::Buffer buffer = device.CreateBufferBuilder() nxt::Buffer buffer = device.CreateBufferBuilder()
.SetAllowedUsage(nxt::BufferUsageBit::TransferDst | usage) .SetAllowedUsage(nxt::BufferUsageBit::TransferDst | usage)
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
.SetSize(size) .SetSize(size)
.GetResult(); .GetResult();
buffer.SetSubData(0, size, reinterpret_cast<const uint8_t*>(data)); buffer.SetSubData(0, size, reinterpret_cast<const uint8_t*>(data));
buffer.FreezeUsage(usage);
return buffer; return buffer;
} }
@ -126,7 +124,6 @@ namespace utils {
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment | .SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment |
nxt::TextureUsageBit::TransferSrc) nxt::TextureUsageBit::TransferSrc)
.SetInitialUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult(); .GetResult();
nxt::TextureView colorView = result.color.CreateTextureViewBuilder().GetResult(); nxt::TextureView colorView = result.color.CreateTextureViewBuilder().GetResult();

View File

@ -24,17 +24,16 @@ namespace utils {
nxt::ShaderModule CreateShaderModule(const nxt::Device& device, nxt::ShaderModule CreateShaderModule(const nxt::Device& device,
nxt::ShaderStage stage, nxt::ShaderStage stage,
const char* source); const char* source);
nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, nxt::Buffer CreateBufferFromData(const nxt::Device& device,
const void* data, const void* data,
uint32_t size, uint32_t size,
nxt::BufferUsageBit usage); nxt::BufferUsageBit usage);
template <typename T> template <typename T>
nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, nxt::Buffer CreateBufferFromData(const nxt::Device& device,
nxt::BufferUsageBit usage, nxt::BufferUsageBit usage,
std::initializer_list<T> data) { std::initializer_list<T> data) {
return CreateFrozenBufferFromData(device, data.begin(), uint32_t(sizeof(T) * data.size()), return CreateBufferFromData(device, data.begin(), uint32_t(sizeof(T) * data.size()), usage);
usage);
} }
struct BasicRenderPass { struct BasicRenderPass {