Split Mapped usage in MapWrite and MapRead
Also make use of CreateFrozenBufferFromData where possible in the example to make the renaming easier.
This commit is contained in:
parent
613eee30c3
commit
f45bdb89c6
|
@ -62,24 +62,10 @@ void initBuffers() {
|
||||||
{0.01, -0.02},
|
{0.01, -0.02},
|
||||||
{0.00, 0.02},
|
{0.00, 0.02},
|
||||||
};
|
};
|
||||||
modelBuffer = device.CreateBufferBuilder()
|
modelBuffer = CreateFrozenBufferFromData(device, model, sizeof(model), nxt::BufferUsageBit::Vertex);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(model))
|
|
||||||
.GetResult();
|
|
||||||
modelBuffer.SetSubData(0, sizeof(model) / sizeof(uint32_t),
|
|
||||||
reinterpret_cast<uint32_t*>(model));
|
|
||||||
modelBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
|
||||||
|
|
||||||
SimParams params = { 0.04, 0.1, 0.025, 0.025, 0.02, 0.05, 0.005, kNumParticles };
|
SimParams params = { 0.04, 0.1, 0.025, 0.025, 0.02, 0.05, 0.005, kNumParticles };
|
||||||
updateParams = device.CreateBufferBuilder()
|
updateParams = CreateFrozenBufferFromData(device, ¶ms, sizeof(params), nxt::BufferUsageBit::Uniform);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(SimParams))
|
|
||||||
.GetResult();
|
|
||||||
updateParams.SetSubData(0, sizeof(SimParams) / sizeof(uint32_t),
|
|
||||||
reinterpret_cast<uint32_t*>(¶ms));
|
|
||||||
updateParams.FreezeUsage(nxt::BufferUsageBit::Uniform);
|
|
||||||
|
|
||||||
std::vector<Particle> initialParticles(kNumParticles);
|
std::vector<Particle> initialParticles(kNumParticles);
|
||||||
{
|
{
|
||||||
|
@ -94,8 +80,8 @@ void initBuffers() {
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
particleBuffers[i] = device.CreateBufferBuilder()
|
particleBuffers[i] = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Storage)
|
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Storage)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::MapWrite)
|
||||||
.SetSize(sizeof(Particle) * kNumParticles)
|
.SetSize(sizeof(Particle) * kNumParticles)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ void init() {
|
||||||
struct {uint32_t a; float b;} s;
|
struct {uint32_t a; float b;} s;
|
||||||
memset(&s, sizeof(s), 0);
|
memset(&s, sizeof(s), 0);
|
||||||
buffer = device.CreateBufferBuilder()
|
buffer = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform | nxt::BufferUsageBit::Storage)
|
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::Uniform | nxt::BufferUsageBit::Storage)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::MapWrite)
|
||||||
.SetSize(sizeof(s))
|
.SetSize(sizeof(s))
|
||||||
.GetResult();
|
.GetResult();
|
||||||
buffer.SetSubData(0, sizeof(s) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&s));
|
buffer.SetSubData(0, sizeof(s) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&s));
|
||||||
|
|
|
@ -165,8 +165,8 @@ void init() {
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
cameraBuffer = device.CreateBufferBuilder()
|
cameraBuffer = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::Uniform)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::MapWrite)
|
||||||
.SetSize(sizeof(CameraData))
|
.SetSize(sizeof(CameraData))
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ void frame() {
|
||||||
glm::vec3(0.0f, 1.0f, 0.0f)
|
glm::vec3(0.0f, 1.0f, 0.0f)
|
||||||
);
|
);
|
||||||
|
|
||||||
cameraBuffer.TransitionUsage(nxt::BufferUsageBit::Mapped);
|
cameraBuffer.TransitionUsage(nxt::BufferUsageBit::MapWrite);
|
||||||
cameraBuffer.SetSubData(0, sizeof(CameraData) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&cameraData));
|
cameraBuffer.SetSubData(0, sizeof(CameraData) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&cameraData));
|
||||||
|
|
||||||
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
||||||
|
|
|
@ -30,27 +30,14 @@ void initBuffers() {
|
||||||
static const uint32_t indexData[3] = {
|
static const uint32_t indexData[3] = {
|
||||||
0, 1, 2,
|
0, 1, 2,
|
||||||
};
|
};
|
||||||
indexBuffer = device.CreateBufferBuilder()
|
indexBuffer = CreateFrozenBufferFromData(device, indexData, sizeof(indexData), nxt::BufferUsageBit::Index);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Index)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(indexData))
|
|
||||||
.GetResult();
|
|
||||||
indexBuffer.SetSubData(0, sizeof(indexData) / sizeof(uint32_t), indexData);
|
|
||||||
indexBuffer.FreezeUsage(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 = device.CreateBufferBuilder()
|
vertexBuffer = CreateFrozenBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(vertexData))
|
|
||||||
.GetResult();
|
|
||||||
vertexBuffer.SetSubData(0, sizeof(vertexData) / sizeof(uint32_t),
|
|
||||||
reinterpret_cast<const uint32_t*>(vertexData));
|
|
||||||
vertexBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
|
|
@ -32,14 +32,7 @@ void initBuffers() {
|
||||||
-0.1f, -0.1f, 0.0f, 1.0f,
|
-0.1f, -0.1f, 0.0f, 1.0f,
|
||||||
0.1f, -0.1f, 0.0f, 1.0f,
|
0.1f, -0.1f, 0.0f, 1.0f,
|
||||||
};
|
};
|
||||||
vertexBuffer = device.CreateBufferBuilder()
|
vertexBuffer = CreateFrozenBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(vertexData))
|
|
||||||
.GetResult();
|
|
||||||
vertexBuffer.SetSubData(0, sizeof(vertexData) / sizeof(uint32_t),
|
|
||||||
reinterpret_cast<const uint32_t*>(vertexData));
|
|
||||||
vertexBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
|
||||||
|
|
||||||
static const float instanceData[8] = {
|
static const float instanceData[8] = {
|
||||||
-0.5f, -0.5f,
|
-0.5f, -0.5f,
|
||||||
|
@ -47,14 +40,7 @@ void initBuffers() {
|
||||||
0.5f, -0.5f,
|
0.5f, -0.5f,
|
||||||
0.5f, 0.5f,
|
0.5f, 0.5f,
|
||||||
};
|
};
|
||||||
instanceBuffer = device.CreateBufferBuilder()
|
instanceBuffer = CreateFrozenBufferFromData(device, instanceData, sizeof(instanceData), nxt::BufferUsageBit::Vertex);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(instanceData))
|
|
||||||
.GetResult();
|
|
||||||
instanceBuffer.SetSubData(0, sizeof(instanceData) / sizeof(uint32_t),
|
|
||||||
reinterpret_cast<const uint32_t*>(instanceData));
|
|
||||||
instanceBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
|
|
@ -34,27 +34,14 @@ void initBuffers() {
|
||||||
static const uint32_t indexData[3] = {
|
static const uint32_t indexData[3] = {
|
||||||
0, 1, 2,
|
0, 1, 2,
|
||||||
};
|
};
|
||||||
indexBuffer = device.CreateBufferBuilder()
|
indexBuffer = CreateFrozenBufferFromData(device, indexData, sizeof(indexData), nxt::BufferUsageBit::Index);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Index)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(indexData))
|
|
||||||
.GetResult();
|
|
||||||
indexBuffer.SetSubData(0, sizeof(indexData) / sizeof(uint32_t), indexData);
|
|
||||||
indexBuffer.FreezeUsage(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 = device.CreateBufferBuilder()
|
vertexBuffer = CreateFrozenBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(vertexData))
|
|
||||||
.GetResult();
|
|
||||||
vertexBuffer.SetSubData(0, sizeof(vertexData) / sizeof(uint32_t),
|
|
||||||
reinterpret_cast<const uint32_t*>(vertexData));
|
|
||||||
vertexBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initTextures() {
|
void initTextures() {
|
||||||
|
@ -76,14 +63,8 @@ void initTextures() {
|
||||||
data[i] = i % 253;
|
data[i] = i % 253;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxt::Buffer stagingBuffer = device.CreateBufferBuilder()
|
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::TransferSrc)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(data.size())
|
|
||||||
.GetResult();
|
|
||||||
stagingBuffer.SetSubData(0, data.size() / sizeof(uint32_t), reinterpret_cast<uint32_t*>(data.data()));
|
|
||||||
stagingBuffer.FreezeUsage(nxt::BufferUsageBit::TransferSrc);
|
|
||||||
|
|
||||||
|
nxt::Buffer stagingBuffer = CreateFrozenBufferFromData(device, data.data(), data.size(), nxt::BufferUsageBit::TransferSrc);
|
||||||
nxt::CommandBuffer copy = device.CreateCommandBufferBuilder()
|
nxt::CommandBuffer copy = device.CreateCommandBufferBuilder()
|
||||||
.TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst)
|
.TransitionTextureUsage(texture, nxt::TextureUsageBit::TransferDst)
|
||||||
.CopyBufferToTexture(stagingBuffer, 0, texture, 0, 0, 0, 1024, 1024, 1, 0)
|
.CopyBufferToTexture(stagingBuffer, 0, texture, 0, 0, 0, 1024, 1024, 1, 0)
|
||||||
|
|
|
@ -66,8 +66,8 @@ void init() {
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
buffer = device.CreateBufferBuilder()
|
buffer = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::Uniform)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::MapWrite)
|
||||||
.SetSize(sizeof(s))
|
.SetSize(sizeof(s))
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ void frame() {
|
||||||
s.b += 0.02;
|
s.b += 0.02;
|
||||||
if (s.b >= 1.0f) {s.b = 0.0f;}
|
if (s.b >= 1.0f) {s.b = 0.0f;}
|
||||||
|
|
||||||
buffer.TransitionUsage(nxt::BufferUsageBit::Mapped);
|
buffer.TransitionUsage(nxt::BufferUsageBit::MapWrite);
|
||||||
buffer.SetSubData(0, sizeof(s) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&s));
|
buffer.SetSubData(0, sizeof(s) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&s));
|
||||||
|
|
||||||
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
||||||
|
|
|
@ -31,14 +31,7 @@ void initBuffers() {
|
||||||
-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 = device.CreateBufferBuilder()
|
vertexBuffer = CreateFrozenBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(vertexData))
|
|
||||||
.GetResult();
|
|
||||||
vertexBuffer.SetSubData(0, sizeof(vertexData) / sizeof(uint32_t),
|
|
||||||
reinterpret_cast<const uint32_t*>(vertexData));
|
|
||||||
vertexBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
|
|
@ -38,14 +38,7 @@ void initBuffers() {
|
||||||
-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 = device.CreateBufferBuilder()
|
vertexBuffer = CreateFrozenBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(vertexData))
|
|
||||||
.GetResult();
|
|
||||||
vertexBuffer.SetSubData(0, sizeof(vertexData) / sizeof(uint32_t),
|
|
||||||
reinterpret_cast<const uint32_t*>(vertexData));
|
|
||||||
vertexBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
|
||||||
|
|
||||||
static const float vertexDataQuad[24] = {
|
static const float vertexDataQuad[24] = {
|
||||||
-1.0f, -1.0f, 0.0f, 1.0f,
|
-1.0f, -1.0f, 0.0f, 1.0f,
|
||||||
|
@ -55,14 +48,7 @@ void initBuffers() {
|
||||||
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,
|
||||||
};
|
};
|
||||||
vertexBufferQuad = device.CreateBufferBuilder()
|
vertexBufferQuad = CreateFrozenBufferFromData(device, vertexDataQuad, sizeof(vertexDataQuad), nxt::BufferUsageBit::Vertex);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(sizeof(vertexDataQuad))
|
|
||||||
.GetResult();
|
|
||||||
vertexBufferQuad.SetSubData(0, sizeof(vertexDataQuad) / sizeof(uint32_t),
|
|
||||||
reinterpret_cast<const uint32_t*>(vertexDataQuad));
|
|
||||||
vertexBufferQuad.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initTextures() {
|
void initTextures() {
|
||||||
|
|
|
@ -262,8 +262,8 @@ void CreateDefaultRenderPass(const nxt::Device& device, nxt::RenderPass* renderP
|
||||||
|
|
||||||
nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, const void* data, uint32_t size, nxt::BufferUsageBit usage) {
|
nxt::Buffer CreateFrozenBufferFromData(const nxt::Device& device, const void* data, uint32_t size, nxt::BufferUsageBit usage) {
|
||||||
nxt::Buffer buffer = device.CreateBufferBuilder()
|
nxt::Buffer buffer = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | usage)
|
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite | usage)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::MapWrite)
|
||||||
.SetSize(size)
|
.SetSize(size)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
buffer.SetSubData(0, size / sizeof(uint32_t), reinterpret_cast<const uint32_t*>(data));
|
buffer.SetSubData(0, size / sizeof(uint32_t), reinterpret_cast<const uint32_t*>(data));
|
||||||
|
|
|
@ -147,14 +147,7 @@ namespace {
|
||||||
uint32_t iBufferViewSize =
|
uint32_t iBufferViewSize =
|
||||||
iBufferView.byteLength ? iBufferView.byteLength :
|
iBufferView.byteLength ? iBufferView.byteLength :
|
||||||
(iBuffer.data.size() - iBufferView.byteOffset);
|
(iBuffer.data.size() - iBufferView.byteOffset);
|
||||||
auto oBuffer = device.CreateBufferBuilder()
|
auto oBuffer = CreateFrozenBufferFromData(device, &iBuffer.data.at(iBufferView.byteOffset), iBufferViewSize, usage);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | usage)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(iBufferViewSize)
|
|
||||||
.GetResult();
|
|
||||||
oBuffer.SetSubData(0, iBufferViewSize / sizeof(uint32_t),
|
|
||||||
reinterpret_cast<const uint32_t*>(&iBuffer.data.at(iBufferView.byteOffset)));
|
|
||||||
oBuffer.FreezeUsage(usage);
|
|
||||||
buffers[iBufferViewID] = std::move(oBuffer);
|
buffers[iBufferViewID] = std::move(oBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -272,8 +265,8 @@ namespace {
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
auto uniformBuffer = device.CreateBufferBuilder()
|
auto uniformBuffer = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
.SetAllowedUsage(nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::Uniform)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::MapWrite)
|
||||||
.SetSize(sizeof(u_transform_block))
|
.SetSize(sizeof(u_transform_block))
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
|
@ -379,16 +372,8 @@ namespace {
|
||||||
.GetResult();
|
.GetResult();
|
||||||
// TODO: release this texture
|
// TODO: release this texture
|
||||||
|
|
||||||
nxt::Buffer staging = device.CreateBufferBuilder()
|
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::TransferSrc)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(4)
|
|
||||||
.GetResult();
|
|
||||||
// TODO: release this buffer
|
|
||||||
|
|
||||||
uint32_t white = 0xffffffff;
|
uint32_t white = 0xffffffff;
|
||||||
staging.SetSubData(0, 1, &white);
|
nxt::Buffer staging = CreateFrozenBufferFromData(device, &white, sizeof(white), nxt::BufferUsageBit::TransferSrc);
|
||||||
staging.FreezeUsage(nxt::BufferUsageBit::TransferSrc);
|
|
||||||
auto cmdbuf = device.CreateCommandBufferBuilder()
|
auto cmdbuf = device.CreateCommandBufferBuilder()
|
||||||
.TransitionTextureUsage(oTexture, nxt::TextureUsageBit::TransferDst)
|
.TransitionTextureUsage(oTexture, nxt::TextureUsageBit::TransferDst)
|
||||||
.CopyBufferToTexture(staging, 0, oTexture, 0, 0, 0, 1, 1, 1, 0)
|
.CopyBufferToTexture(staging, 0, oTexture, 0, 0, 0, 1, 1, 1, 0)
|
||||||
|
@ -442,16 +427,7 @@ namespace {
|
||||||
fprintf(stderr, "unsupported image.component %d\n", iImage.component);
|
fprintf(stderr, "unsupported image.component %d\n", iImage.component);
|
||||||
}
|
}
|
||||||
|
|
||||||
nxt::Buffer staging = device.CreateBufferBuilder()
|
nxt::Buffer staging = CreateFrozenBufferFromData(device, data, numPixels * 4, nxt::BufferUsageBit::TransferSrc);
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::TransferSrc)
|
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
|
||||||
.SetSize(numPixels * 4)
|
|
||||||
.GetResult();
|
|
||||||
// TODO: release this buffer
|
|
||||||
|
|
||||||
staging.SetSubData(0, numPixels,
|
|
||||||
reinterpret_cast<const uint32_t*>(data));
|
|
||||||
staging.FreezeUsage(nxt::BufferUsageBit::TransferSrc);
|
|
||||||
auto cmdbuf = device.CreateCommandBufferBuilder()
|
auto cmdbuf = device.CreateCommandBufferBuilder()
|
||||||
.TransitionTextureUsage(oTexture, nxt::TextureUsageBit::TransferDst)
|
.TransitionTextureUsage(oTexture, nxt::TextureUsageBit::TransferDst)
|
||||||
.CopyBufferToTexture(staging, 0, oTexture, 0, 0, 0, iImage.width, iImage.height, 1, 0)
|
.CopyBufferToTexture(staging, 0, oTexture, 0, 0, 0, iImage.width, iImage.height, 1, 0)
|
||||||
|
@ -513,7 +489,7 @@ 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::Mapped);
|
material.uniformBuffer.TransitionUsage(nxt::BufferUsageBit::MapWrite);
|
||||||
material.uniformBuffer.SetSubData(0,
|
material.uniformBuffer.SetSubData(0,
|
||||||
sizeof(u_transform_block) / sizeof(uint32_t),
|
sizeof(u_transform_block) / sizeof(uint32_t),
|
||||||
reinterpret_cast<const uint32_t*>(&transforms));
|
reinterpret_cast<const uint32_t*>(&transforms));
|
||||||
|
|
|
@ -177,7 +177,8 @@
|
||||||
"category": "bitmask",
|
"category": "bitmask",
|
||||||
"values": [
|
"values": [
|
||||||
{"value": 0, "name": "none"},
|
{"value": 0, "name": "none"},
|
||||||
{"value": 1, "name": "mapped"},
|
{"value": 1, "name": "map read"},
|
||||||
|
{"value": 1, "name": "map write"},
|
||||||
{"value": 2, "name": "transfer src"},
|
{"value": 2, "name": "transfer src"},
|
||||||
{"value": 4, "name": "transfer dst"},
|
{"value": 4, "name": "transfer dst"},
|
||||||
{"value": 8, "name": "index"},
|
{"value": 8, "name": "index"},
|
||||||
|
|
|
@ -56,8 +56,8 @@ namespace backend {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(currentUsage & nxt::BufferUsageBit::Mapped)) {
|
if (!(currentUsage & nxt::BufferUsageBit::MapWrite)) {
|
||||||
device->HandleError("Buffer needs the mapped usage bit");
|
device->HandleError("Buffer needs the map write usage bit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@ namespace backend {
|
||||||
|
|
||||||
bool BufferBase::IsUsagePossible(nxt::BufferUsageBit allowedUsage, nxt::BufferUsageBit usage) {
|
bool BufferBase::IsUsagePossible(nxt::BufferUsageBit allowedUsage, nxt::BufferUsageBit usage) {
|
||||||
const nxt::BufferUsageBit allReadBits =
|
const nxt::BufferUsageBit allReadBits =
|
||||||
|
nxt::BufferUsageBit::MapRead |
|
||||||
nxt::BufferUsageBit::TransferSrc |
|
nxt::BufferUsageBit::TransferSrc |
|
||||||
nxt::BufferUsageBit::Index |
|
nxt::BufferUsageBit::Index |
|
||||||
nxt::BufferUsageBit::Vertex |
|
nxt::BufferUsageBit::Vertex |
|
||||||
|
|
Loading…
Reference in New Issue