Rename nxt:: to dawn:: in examples

This commit is contained in:
Corentin Wallez 2018-07-18 13:45:46 +02:00 committed by Corentin Wallez
parent 54e58c20b2
commit 4828d92df3
8 changed files with 241 additions and 241 deletions

View File

@ -21,11 +21,11 @@
#include <cstdio> #include <cstdio>
#include <vector> #include <vector>
nxt::Device device; dawn::Device device;
nxt::Queue queue; dawn::Queue queue;
nxt::SwapChain swapchain; dawn::SwapChain swapchain;
nxt::TextureView depthStencilView; dawn::TextureView depthStencilView;
nxt::RenderPipeline pipeline; dawn::RenderPipeline pipeline;
float RandomFloat(float min, float max) { float RandomFloat(float min, float max) {
float zeroOne = rand() / float(RAND_MAX); float zeroOne = rand() / float(RAND_MAX);
@ -49,9 +49,9 @@ void init() {
queue = device.CreateQueue(); queue = device.CreateQueue();
swapchain = GetSwapChain(device); swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(), swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480); dawn::TextureUsageBit::OutputAttachment, 640, 480);
nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"( dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
#version 450 #version 450
layout(push_constant) uniform ConstantsBlock { layout(push_constant) uniform ConstantsBlock {
@ -99,7 +99,7 @@ void init() {
})" })"
); );
nxt::ShaderModule fsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, R"( dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
layout(location = 0) in vec4 v_color; layout(location = 0) in vec4 v_color;
@ -111,9 +111,9 @@ void init() {
pipeline = device.CreateRenderPipelineBuilder() pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint) .SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main") .SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main") .SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult(); .GetResult();
shaderData.resize(10000); shaderData.resize(10000);
@ -128,8 +128,8 @@ void init() {
} }
void frame() { void frame() {
nxt::Texture backbuffer; dawn::Texture backbuffer;
nxt::RenderPassDescriptor renderPass; dawn::RenderPassDescriptor renderPass;
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass); GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
static int f = 0; static int f = 0;
@ -137,16 +137,16 @@ void frame() {
size_t i = 0; size_t i = 0;
nxt::CommandBuffer commands; dawn::CommandBuffer commands;
{ {
nxt::CommandBufferBuilder builder = device.CreateCommandBufferBuilder() dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderPass) .BeginRenderPass(renderPass)
.SetRenderPipeline(pipeline) .SetRenderPipeline(pipeline)
.Clone(); .Clone();
for (int k = 0; k < 10000; k++) { for (int k = 0; k < 10000; k++) {
shaderData[i].time = f / 60.0f; shaderData[i].time = f / 60.0f;
builder.SetPushConstants(nxt::ShaderStageBit::Vertex, 0, 6, reinterpret_cast<uint32_t*>(&shaderData[i])) builder.SetPushConstants(dawn::ShaderStageBit::Vertex, 0, 6, reinterpret_cast<uint32_t*>(&shaderData[i]))
.DrawArrays(3, 1, 0, 0); .DrawArrays(3, 1, 0, 0);
i++; i++;
} }

View File

@ -45,7 +45,7 @@ void init() {
"void main() {\n" "void main() {\n"
" gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\n" " gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\n"
"}\n"; "}\n";
nxtShaderModule vsModule = utils::CreateShaderModule(nxt::Device(device), nxt::ShaderStage::Vertex, vs).Release(); nxtShaderModule vsModule = utils::CreateShaderModule(dawn::Device(device), dawn::ShaderStage::Vertex, vs).Release();
const char* fs = const char* fs =
"#version 450\n" "#version 450\n"
@ -53,7 +53,7 @@ void init() {
"void main() {\n" "void main() {\n"
" fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
"}\n"; "}\n";
nxtShaderModule fsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, fs).Release(); nxtShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, fs).Release();
{ {
nxtRenderPipelineBuilder builder = nxtDeviceCreateRenderPipelineBuilder(device); nxtRenderPipelineBuilder builder = nxtDeviceCreateRenderPipelineBuilder(device);

View File

@ -23,19 +23,19 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
nxt::Device device; dawn::Device device;
nxt::Queue queue; dawn::Queue queue;
nxt::SwapChain swapchain; dawn::SwapChain swapchain;
nxt::TextureView depthStencilView; dawn::TextureView depthStencilView;
nxt::Buffer modelBuffer; dawn::Buffer modelBuffer;
std::array<nxt::Buffer, 2> particleBuffers; std::array<dawn::Buffer, 2> particleBuffers;
nxt::RenderPipeline renderPipeline; dawn::RenderPipeline renderPipeline;
nxt::Buffer updateParams; dawn::Buffer updateParams;
nxt::ComputePipeline updatePipeline; dawn::ComputePipeline updatePipeline;
std::array<nxt::BindGroup, 2> updateBGs; std::array<dawn::BindGroup, 2> updateBGs;
size_t pingpong = 0; size_t pingpong = 0;
@ -63,10 +63,10 @@ void initBuffers() {
{0.01, -0.02}, {0.01, -0.02},
{0.00, 0.02}, {0.00, 0.02},
}; };
modelBuffer = utils::CreateBufferFromData(device, model, sizeof(model), nxt::BufferUsageBit::Vertex); modelBuffer = utils::CreateBufferFromData(device, model, sizeof(model), dawn::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::CreateBufferFromData(device, &params, sizeof(params), nxt::BufferUsageBit::Uniform); updateParams = utils::CreateBufferFromData(device, &params, sizeof(params), dawn::BufferUsageBit::Uniform);
std::vector<Particle> initialParticles(kNumParticles); std::vector<Particle> initialParticles(kNumParticles);
{ {
@ -81,7 +81,7 @@ 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(dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Storage)
.SetSize(sizeof(Particle) * kNumParticles) .SetSize(sizeof(Particle) * kNumParticles)
.GetResult(); .GetResult();
@ -92,7 +92,7 @@ void initBuffers() {
} }
void initRender() { void initRender() {
nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"( dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
#version 450 #version 450
layout(location = 0) in vec2 a_particlePos; layout(location = 0) in vec2 a_particlePos;
layout(location = 1) in vec2 a_particleVel; layout(location = 1) in vec2 a_particleVel;
@ -105,7 +105,7 @@ void initRender() {
} }
)"); )");
nxt::ShaderModule fsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, R"( dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
void main() { void main() {
@ -113,27 +113,27 @@ void initRender() {
} }
)"); )");
nxt::InputState inputState = device.CreateInputStateBuilder() dawn::InputState inputState = device.CreateInputStateBuilder()
.SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32, offsetof(Particle, pos)) .SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32, offsetof(Particle, pos))
.SetAttribute(1, 0, nxt::VertexFormat::FloatR32G32, offsetof(Particle, vel)) .SetAttribute(1, 0, dawn::VertexFormat::FloatR32G32, offsetof(Particle, vel))
.SetInput(0, sizeof(Particle), nxt::InputStepMode::Instance) .SetInput(0, sizeof(Particle), dawn::InputStepMode::Instance)
.SetAttribute(2, 1, nxt::VertexFormat::FloatR32G32, 0) .SetAttribute(2, 1, dawn::VertexFormat::FloatR32G32, 0)
.SetInput(1, sizeof(glm::vec2), nxt::InputStepMode::Vertex) .SetInput(1, sizeof(glm::vec2), dawn::InputStepMode::Vertex)
.GetResult(); .GetResult();
depthStencilView = CreateDefaultDepthStencilView(device); depthStencilView = CreateDefaultDepthStencilView(device);
renderPipeline = device.CreateRenderPipelineBuilder() renderPipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint) .SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main") .SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main") .SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetInputState(inputState) .SetInputState(inputState)
.GetResult(); .GetResult();
} }
void initSim() { void initSim() {
nxt::ShaderModule module = utils::CreateShaderModule(device, nxt::ShaderStage::Compute, R"( dawn::ShaderModule module = utils::CreateShaderModule(device, dawn::ShaderStage::Compute, R"(
#version 450 #version 450
struct Particle { struct Particle {
@ -224,23 +224,23 @@ void initSim() {
auto bgl = utils::MakeBindGroupLayout( auto bgl = utils::MakeBindGroupLayout(
device, { device, {
{0, nxt::ShaderStageBit::Compute, nxt::BindingType::UniformBuffer}, {0, dawn::ShaderStageBit::Compute, dawn::BindingType::UniformBuffer},
{1, nxt::ShaderStageBit::Compute, nxt::BindingType::StorageBuffer}, {1, dawn::ShaderStageBit::Compute, dawn::BindingType::StorageBuffer},
{2, nxt::ShaderStageBit::Compute, nxt::BindingType::StorageBuffer}, {2, dawn::ShaderStageBit::Compute, dawn::BindingType::StorageBuffer},
}); });
nxt::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
updatePipeline = device.CreateComputePipelineBuilder() updatePipeline = device.CreateComputePipelineBuilder()
.SetLayout(pl) .SetLayout(pl)
.SetStage(nxt::ShaderStage::Compute, module, "main") .SetStage(dawn::ShaderStage::Compute, module, "main")
.GetResult(); .GetResult();
nxt::BufferView updateParamsView = updateParams.CreateBufferViewBuilder() dawn::BufferView updateParamsView = updateParams.CreateBufferViewBuilder()
.SetExtent(0, sizeof(SimParams)) .SetExtent(0, sizeof(SimParams))
.GetResult(); .GetResult();
std::array<nxt::BufferView, 2> views; std::array<dawn::BufferView, 2> views;
for (uint32_t i = 0; i < 2; ++i) { for (uint32_t i = 0; i < 2; ++i) {
views[i] = particleBuffers[i].CreateBufferViewBuilder() views[i] = particleBuffers[i].CreateBufferViewBuilder()
.SetExtent(0, kNumParticles * sizeof(Particle)) .SetExtent(0, kNumParticles * sizeof(Particle))
@ -250,7 +250,7 @@ void initSim() {
for (uint32_t i = 0; i < 2; ++i) { for (uint32_t i = 0; i < 2; ++i) {
updateBGs[i] = device.CreateBindGroupBuilder() updateBGs[i] = device.CreateBindGroupBuilder()
.SetLayout(bgl) .SetLayout(bgl)
.SetUsage(nxt::BindGroupUsage::Frozen) .SetUsage(dawn::BindGroupUsage::Frozen)
.SetBufferViews(0, 1, &updateParamsView) .SetBufferViews(0, 1, &updateParamsView)
.SetBufferViews(1, 1, &views[i]) .SetBufferViews(1, 1, &views[i])
.SetBufferViews(2, 1, &views[(i + 1) % 2]) .SetBufferViews(2, 1, &views[(i + 1) % 2])
@ -258,7 +258,7 @@ void initSim() {
} }
} }
nxt::CommandBuffer createCommandBuffer(const nxt::RenderPassDescriptor& renderPass, size_t i) { dawn::CommandBuffer createCommandBuffer(const dawn::RenderPassDescriptor& renderPass, size_t i) {
static const uint32_t zeroOffsets[1] = {0}; static const uint32_t zeroOffsets[1] = {0};
auto& bufferDst = particleBuffers[(i + 1) % 2]; auto& bufferDst = particleBuffers[(i + 1) % 2];
return device.CreateCommandBufferBuilder() return device.CreateCommandBufferBuilder()
@ -284,7 +284,7 @@ void init() {
queue = device.CreateQueue(); queue = device.CreateQueue();
swapchain = GetSwapChain(device); swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(), swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480); dawn::TextureUsageBit::OutputAttachment, 640, 480);
initBuffers(); initBuffers();
initRender(); initRender();
@ -292,11 +292,11 @@ void init() {
} }
void frame() { void frame() {
nxt::Texture backbuffer; dawn::Texture backbuffer;
nxt::RenderPassDescriptor renderPass; dawn::RenderPassDescriptor renderPass;
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass); GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
nxt::CommandBuffer commandBuffer = createCommandBuffer(renderPass, pingpong); dawn::CommandBuffer commandBuffer = createCommandBuffer(renderPass, pingpong);
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
swapchain.Present(backbuffer); swapchain.Present(backbuffer);
DoFlush(); DoFlush();

View File

@ -19,44 +19,44 @@
#include <vector> #include <vector>
nxt::Device device; dawn::Device device;
nxt::Buffer indexBuffer; dawn::Buffer indexBuffer;
nxt::Buffer vertexBuffer; dawn::Buffer vertexBuffer;
nxt::Texture texture; dawn::Texture texture;
nxt::Sampler sampler; dawn::Sampler sampler;
nxt::Queue queue; dawn::Queue queue;
nxt::SwapChain swapchain; dawn::SwapChain swapchain;
nxt::TextureView depthStencilView; dawn::TextureView depthStencilView;
nxt::RenderPipeline pipeline; dawn::RenderPipeline pipeline;
nxt::BindGroup bindGroup; dawn::BindGroup bindGroup;
void initBuffers() { void initBuffers() {
static const uint32_t indexData[3] = { static const uint32_t indexData[3] = {
0, 1, 2, 0, 1, 2,
}; };
indexBuffer = utils::CreateBufferFromData(device, indexData, sizeof(indexData), nxt::BufferUsageBit::Index); indexBuffer = utils::CreateBufferFromData(device, indexData, sizeof(indexData), dawn::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::CreateBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex); vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData), dawn::BufferUsageBit::Vertex);
} }
void initTextures() { void initTextures() {
texture = device.CreateTextureBuilder() texture = device.CreateTextureBuilder()
.SetDimension(nxt::TextureDimension::e2D) .SetDimension(dawn::TextureDimension::e2D)
.SetExtent(1024, 1024, 1) .SetExtent(1024, 1024, 1)
.SetFormat(nxt::TextureFormat::R8G8B8A8Unorm) .SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::TransferDst | nxt::TextureUsageBit::Sampled) .SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled)
.GetResult(); .GetResult();
nxt::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor(); dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
sampler = device.CreateSampler(&samplerDesc); sampler = device.CreateSampler(&samplerDesc);
// Initialize the texture with arbitrary data until we can load images // Initialize the texture with arbitrary data until we can load images
@ -66,8 +66,8 @@ void initTextures() {
} }
nxt::Buffer stagingBuffer = utils::CreateBufferFromData(device, data.data(), static_cast<uint32_t>(data.size()), nxt::BufferUsageBit::TransferSrc); dawn::Buffer stagingBuffer = utils::CreateBufferFromData(device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsageBit::TransferSrc);
nxt::CommandBuffer copy = device.CreateCommandBufferBuilder() dawn::CommandBuffer copy = device.CreateCommandBufferBuilder()
.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();
@ -80,12 +80,12 @@ void init() {
queue = device.CreateQueue(); queue = device.CreateQueue();
swapchain = GetSwapChain(device); swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(), swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480); dawn::TextureUsageBit::OutputAttachment, 640, 480);
initBuffers(); initBuffers();
initTextures(); initTextures();
nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"( dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
#version 450 #version 450
layout(location = 0) in vec4 pos; layout(location = 0) in vec4 pos;
void main() { void main() {
@ -93,7 +93,7 @@ void init() {
})" })"
); );
nxt::ShaderModule fsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, R"( dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
#version 450 #version 450
layout(set = 0, binding = 0) uniform sampler mySampler; layout(set = 0, binding = 0) uniform sampler mySampler;
layout(set = 0, binding = 1) uniform texture2D myTexture; layout(set = 0, binding = 1) uniform texture2D myTexture;
@ -104,35 +104,35 @@ void init() {
})"); })");
auto inputState = device.CreateInputStateBuilder() auto inputState = device.CreateInputStateBuilder()
.SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32B32A32, 0) .SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32A32, 0)
.SetInput(0, 4 * sizeof(float), nxt::InputStepMode::Vertex) .SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
.GetResult(); .GetResult();
auto bgl = utils::MakeBindGroupLayout( auto bgl = utils::MakeBindGroupLayout(
device, { device, {
{0, nxt::ShaderStageBit::Fragment, nxt::BindingType::Sampler}, {0, dawn::ShaderStageBit::Fragment, dawn::BindingType::Sampler},
{1, nxt::ShaderStageBit::Fragment, nxt::BindingType::SampledTexture}, {1, dawn::ShaderStageBit::Fragment, dawn::BindingType::SampledTexture},
}); });
nxt::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
depthStencilView = CreateDefaultDepthStencilView(device); depthStencilView = CreateDefaultDepthStencilView(device);
pipeline = device.CreateRenderPipelineBuilder() pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint) .SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
.SetLayout(pl) .SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main") .SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main") .SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetIndexFormat(nxt::IndexFormat::Uint32) .SetIndexFormat(dawn::IndexFormat::Uint32)
.SetInputState(inputState) .SetInputState(inputState)
.GetResult(); .GetResult();
nxt::TextureView view = texture.CreateTextureViewBuilder().GetResult(); dawn::TextureView view = texture.CreateTextureViewBuilder().GetResult();
bindGroup = device.CreateBindGroupBuilder() bindGroup = device.CreateBindGroupBuilder()
.SetLayout(bgl) .SetLayout(bgl)
.SetUsage(nxt::BindGroupUsage::Frozen) .SetUsage(dawn::BindGroupUsage::Frozen)
.SetSamplers(0, 1, &sampler) .SetSamplers(0, 1, &sampler)
.SetTextureViews(1, 1, &view) .SetTextureViews(1, 1, &view)
.GetResult(); .GetResult();
@ -144,12 +144,12 @@ void frame() {
s.b += 0.02f; s.b += 0.02f;
if (s.b >= 1.0f) {s.b = 0.0f;} if (s.b >= 1.0f) {s.b = 0.0f;}
nxt::Texture backbuffer; dawn::Texture backbuffer;
nxt::RenderPassDescriptor renderPass; dawn::RenderPassDescriptor renderPass;
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass); GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
static const uint32_t vertexBufferOffsets[1] = {0}; static const uint32_t vertexBufferOffsets[1] = {0};
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderPass) .BeginRenderPass(renderPass)
.SetRenderPipeline(pipeline) .SetRenderPipeline(pipeline)
.SetBindGroup(0, bindGroup) .SetBindGroup(0, bindGroup)

View File

@ -22,24 +22,24 @@
#include <glm/glm/gtc/matrix_transform.hpp> #include <glm/glm/gtc/matrix_transform.hpp>
#include <glm/glm/gtc/type_ptr.hpp> #include <glm/glm/gtc/type_ptr.hpp>
nxt::Device device; dawn::Device device;
nxt::Buffer indexBuffer; dawn::Buffer indexBuffer;
nxt::Buffer vertexBuffer; dawn::Buffer vertexBuffer;
nxt::Buffer planeBuffer; dawn::Buffer planeBuffer;
nxt::Buffer cameraBuffer; dawn::Buffer cameraBuffer;
nxt::Buffer transformBuffer[2]; dawn::Buffer transformBuffer[2];
nxt::BindGroup cameraBindGroup; dawn::BindGroup cameraBindGroup;
nxt::BindGroup bindGroup[2]; dawn::BindGroup bindGroup[2];
nxt::BindGroup cubeTransformBindGroup[2]; dawn::BindGroup cubeTransformBindGroup[2];
nxt::Queue queue; dawn::Queue queue;
nxt::SwapChain swapchain; dawn::SwapChain swapchain;
nxt::TextureView depthStencilView; dawn::TextureView depthStencilView;
nxt::RenderPipeline pipeline; dawn::RenderPipeline pipeline;
nxt::RenderPipeline planePipeline; dawn::RenderPipeline planePipeline;
nxt::RenderPipeline reflectionPipeline; dawn::RenderPipeline reflectionPipeline;
void initBuffers() { void initBuffers() {
static const uint32_t indexData[6*6] = { static const uint32_t indexData[6*6] = {
@ -61,7 +61,7 @@ void initBuffers() {
20, 21, 22, 20, 21, 22,
20, 22, 23 20, 22, 23
}; };
indexBuffer = utils::CreateBufferFromData(device, indexData, sizeof(indexData), nxt::BufferUsageBit::Index); indexBuffer = utils::CreateBufferFromData(device, indexData, sizeof(indexData), dawn::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::CreateBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex); vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData), dawn::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::CreateBufferFromData(device, planeData, sizeof(planeData), nxt::BufferUsageBit::Vertex); planeBuffer = utils::CreateBufferFromData(device, planeData, sizeof(planeData), dawn::BufferUsageBit::Vertex);
} }
struct CameraData { struct CameraData {
@ -116,11 +116,11 @@ void init() {
queue = device.CreateQueue(); queue = device.CreateQueue();
swapchain = GetSwapChain(device); swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(), swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480); dawn::TextureUsageBit::OutputAttachment, 640, 480);
initBuffers(); initBuffers();
nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"( dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
#version 450 #version 450
layout(set = 0, binding = 0) uniform cameraData { layout(set = 0, binding = 0) uniform cameraData {
mat4 view; mat4 view;
@ -138,7 +138,7 @@ void init() {
})" })"
); );
nxt::ShaderModule fsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, R"( dawn::ShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 2) in vec3 f_col; layout(location = 2) in vec3 f_col;
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -146,8 +146,8 @@ void init() {
fragColor = vec4(f_col, 1.0); fragColor = vec4(f_col, 1.0);
})"); })");
nxt::ShaderModule fsReflectionModule = dawn::ShaderModule fsReflectionModule =
utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, R"( utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 2) in vec3 f_col; layout(location = 2) in vec3 f_col;
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -156,35 +156,35 @@ void init() {
})"); })");
auto inputState = device.CreateInputStateBuilder() auto inputState = device.CreateInputStateBuilder()
.SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32B32, 0) .SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32, 0)
.SetAttribute(1, 0, nxt::VertexFormat::FloatR32G32B32, 3 * sizeof(float)) .SetAttribute(1, 0, dawn::VertexFormat::FloatR32G32B32, 3 * sizeof(float))
.SetInput(0, 6 * sizeof(float), nxt::InputStepMode::Vertex) .SetInput(0, 6 * sizeof(float), dawn::InputStepMode::Vertex)
.GetResult(); .GetResult();
auto bgl = utils::MakeBindGroupLayout( auto bgl = utils::MakeBindGroupLayout(
device, { device, {
{0, nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer}, {0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
{1, nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer}, {1, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
}); });
nxt::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
cameraBuffer = device.CreateBufferBuilder() cameraBuffer = device.CreateBufferBuilder()
.SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Uniform) .SetAllowedUsage(dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::Uniform)
.SetSize(sizeof(CameraData)) .SetSize(sizeof(CameraData))
.GetResult(); .GetResult();
glm::mat4 transform(1.0); glm::mat4 transform(1.0);
transformBuffer[0] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform); transformBuffer[0] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4), dawn::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::CreateBufferFromData(device, &transform, sizeof(glm::mat4), nxt::BufferUsageBit::Uniform); transformBuffer[1] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4), dawn::BufferUsageBit::Uniform);
nxt::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder() dawn::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder()
.SetExtent(0, sizeof(CameraData)) .SetExtent(0, sizeof(CameraData))
.GetResult(); .GetResult();
nxt::BufferView transformBufferView[2] = { dawn::BufferView transformBufferView[2] = {
transformBuffer[0].CreateBufferViewBuilder() transformBuffer[0].CreateBufferViewBuilder()
.SetExtent(0, sizeof(glm::mat4)) .SetExtent(0, sizeof(glm::mat4))
.GetResult(), .GetResult(),
@ -195,14 +195,14 @@ void init() {
bindGroup[0] = device.CreateBindGroupBuilder() bindGroup[0] = device.CreateBindGroupBuilder()
.SetLayout(bgl) .SetLayout(bgl)
.SetUsage(nxt::BindGroupUsage::Frozen) .SetUsage(dawn::BindGroupUsage::Frozen)
.SetBufferViews(0, 1, &cameraBufferView) .SetBufferViews(0, 1, &cameraBufferView)
.SetBufferViews(1, 1, &transformBufferView[0]) .SetBufferViews(1, 1, &transformBufferView[0])
.GetResult(); .GetResult();
bindGroup[1] = device.CreateBindGroupBuilder() bindGroup[1] = device.CreateBindGroupBuilder()
.SetLayout(bgl) .SetLayout(bgl)
.SetUsage(nxt::BindGroupUsage::Frozen) .SetUsage(dawn::BindGroupUsage::Frozen)
.SetBufferViews(0, 1, &cameraBufferView) .SetBufferViews(0, 1, &cameraBufferView)
.SetBufferViews(1, 1, &transformBufferView[1]) .SetBufferViews(1, 1, &transformBufferView[1])
.GetResult(); .GetResult();
@ -210,49 +210,49 @@ void init() {
depthStencilView = CreateDefaultDepthStencilView(device); depthStencilView = CreateDefaultDepthStencilView(device);
auto depthStencilState = device.CreateDepthStencilStateBuilder() auto depthStencilState = device.CreateDepthStencilStateBuilder()
.SetDepthCompareFunction(nxt::CompareFunction::Less) .SetDepthCompareFunction(dawn::CompareFunction::Less)
.SetDepthWriteEnabled(true) .SetDepthWriteEnabled(true)
.GetResult(); .GetResult();
pipeline = device.CreateRenderPipelineBuilder() pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint) .SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
.SetLayout(pl) .SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main") .SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main") .SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetIndexFormat(nxt::IndexFormat::Uint32) .SetIndexFormat(dawn::IndexFormat::Uint32)
.SetInputState(inputState) .SetInputState(inputState)
.SetDepthStencilState(depthStencilState) .SetDepthStencilState(depthStencilState)
.GetResult(); .GetResult();
auto planeStencilState = device.CreateDepthStencilStateBuilder() auto planeStencilState = device.CreateDepthStencilStateBuilder()
.SetDepthCompareFunction(nxt::CompareFunction::Less) .SetDepthCompareFunction(dawn::CompareFunction::Less)
.SetDepthWriteEnabled(false) .SetDepthWriteEnabled(false)
.SetStencilFunction(nxt::Face::Both, nxt::CompareFunction::Always, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace) .SetStencilFunction(dawn::Face::Both, dawn::CompareFunction::Always, dawn::StencilOperation::Keep, dawn::StencilOperation::Keep, dawn::StencilOperation::Replace)
.GetResult(); .GetResult();
planePipeline = device.CreateRenderPipelineBuilder() planePipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint) .SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
.SetLayout(pl) .SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main") .SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main") .SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetInputState(inputState) .SetInputState(inputState)
.SetDepthStencilState(planeStencilState) .SetDepthStencilState(planeStencilState)
.GetResult(); .GetResult();
auto reflectionStencilState = device.CreateDepthStencilStateBuilder() auto reflectionStencilState = device.CreateDepthStencilStateBuilder()
.SetDepthCompareFunction(nxt::CompareFunction::Less) .SetDepthCompareFunction(dawn::CompareFunction::Less)
.SetDepthWriteEnabled(true) .SetDepthWriteEnabled(true)
.SetStencilFunction(nxt::Face::Both, nxt::CompareFunction::Equal, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace) .SetStencilFunction(dawn::Face::Both, dawn::CompareFunction::Equal, dawn::StencilOperation::Keep, dawn::StencilOperation::Keep, dawn::StencilOperation::Replace)
.GetResult(); .GetResult();
reflectionPipeline = device.CreateRenderPipelineBuilder() reflectionPipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint) .SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
.SetLayout(pl) .SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main") .SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsReflectionModule, "main") .SetStage(dawn::ShaderStage::Fragment, fsReflectionModule, "main")
.SetInputState(inputState) .SetInputState(inputState)
.SetDepthStencilState(reflectionStencilState) .SetDepthStencilState(reflectionStencilState)
.GetResult(); .GetResult();
@ -275,11 +275,11 @@ void frame() {
cameraBuffer.SetSubData(0, sizeof(CameraData), reinterpret_cast<uint8_t*>(&cameraData)); cameraBuffer.SetSubData(0, sizeof(CameraData), reinterpret_cast<uint8_t*>(&cameraData));
nxt::Texture backbuffer; dawn::Texture backbuffer;
nxt::RenderPassDescriptor renderPass; dawn::RenderPassDescriptor renderPass;
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass); GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderPass) .BeginRenderPass(renderPass)
.SetRenderPipeline(pipeline) .SetRenderPipeline(pipeline)
.SetBindGroup(0, bindGroup[0]) .SetBindGroup(0, bindGroup[0])

View File

@ -27,7 +27,7 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
void PrintDeviceError(const char* message, nxt::CallbackUserdata) { void PrintDeviceError(const char* message, dawn::CallbackUserdata) {
std::cout << "Device error: " << message << std::endl; std::cout << "Device error: " << message << std::endl;
} }
@ -60,26 +60,26 @@ static utils::BackendBinding* binding = nullptr;
static GLFWwindow* window = nullptr; static GLFWwindow* window = nullptr;
static nxt::wire::CommandHandler* wireServer = nullptr; static dawn::wire::CommandHandler* wireServer = nullptr;
static nxt::wire::CommandHandler* wireClient = nullptr; static dawn::wire::CommandHandler* wireClient = nullptr;
static nxt::wire::TerribleCommandBuffer* c2sBuf = nullptr; static dawn::wire::TerribleCommandBuffer* c2sBuf = nullptr;
static nxt::wire::TerribleCommandBuffer* s2cBuf = nullptr; static dawn::wire::TerribleCommandBuffer* s2cBuf = nullptr;
nxt::Device CreateCppNXTDevice() { dawn::Device CreateCppNXTDevice() {
binding = utils::CreateBinding(backendType); binding = utils::CreateBinding(backendType);
if (binding == nullptr) { if (binding == nullptr) {
return nxt::Device(); return dawn::Device();
} }
glfwSetErrorCallback(PrintGLFWError); glfwSetErrorCallback(PrintGLFWError);
if (!glfwInit()) { if (!glfwInit()) {
return nxt::Device(); return dawn::Device();
} }
binding->SetupGLFWWindowHints(); binding->SetupGLFWWindowHints();
window = glfwCreateWindow(640, 480, "NXT window", nullptr, nullptr); window = glfwCreateWindow(640, 480, "NXT window", nullptr, nullptr);
if (!window) { if (!window) {
return nxt::Device(); return dawn::Device();
} }
binding->SetWindow(window); binding->SetWindow(window);
@ -98,15 +98,15 @@ nxt::Device CreateCppNXTDevice() {
case CmdBufType::Terrible: case CmdBufType::Terrible:
{ {
c2sBuf = new nxt::wire::TerribleCommandBuffer(); c2sBuf = new dawn::wire::TerribleCommandBuffer();
s2cBuf = new nxt::wire::TerribleCommandBuffer(); s2cBuf = new dawn::wire::TerribleCommandBuffer();
wireServer = nxt::wire::NewServerCommandHandler(backendDevice, backendProcs, s2cBuf); wireServer = dawn::wire::NewServerCommandHandler(backendDevice, backendProcs, s2cBuf);
c2sBuf->SetHandler(wireServer); c2sBuf->SetHandler(wireServer);
nxtDevice clientDevice; nxtDevice clientDevice;
nxtProcTable clientProcs; nxtProcTable clientProcs;
wireClient = nxt::wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf); wireClient = dawn::wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf);
s2cBuf->SetHandler(wireClient); s2cBuf->SetHandler(wireClient);
procs = clientProcs; procs = clientProcs;
@ -117,46 +117,46 @@ nxt::Device CreateCppNXTDevice() {
nxtSetProcs(&procs); nxtSetProcs(&procs);
procs.deviceSetErrorCallback(cDevice, PrintDeviceError, 0); procs.deviceSetErrorCallback(cDevice, PrintDeviceError, 0);
return nxt::Device::Acquire(cDevice); return dawn::Device::Acquire(cDevice);
} }
uint64_t GetSwapChainImplementation() { uint64_t GetSwapChainImplementation() {
return binding->GetSwapChainImplementation(); return binding->GetSwapChainImplementation();
} }
nxt::TextureFormat GetPreferredSwapChainTextureFormat() { dawn::TextureFormat GetPreferredSwapChainTextureFormat() {
DoFlush(); DoFlush();
return static_cast<nxt::TextureFormat>(binding->GetPreferredSwapChainTextureFormat()); return static_cast<dawn::TextureFormat>(binding->GetPreferredSwapChainTextureFormat());
} }
nxt::SwapChain GetSwapChain(const nxt::Device &device) { dawn::SwapChain GetSwapChain(const dawn::Device &device) {
return device.CreateSwapChainBuilder() return device.CreateSwapChainBuilder()
.SetImplementation(GetSwapChainImplementation()) .SetImplementation(GetSwapChainImplementation())
.GetResult(); .GetResult();
} }
nxt::TextureView CreateDefaultDepthStencilView(const nxt::Device& device) { dawn::TextureView CreateDefaultDepthStencilView(const dawn::Device& device) {
auto depthStencilTexture = device.CreateTextureBuilder() auto depthStencilTexture = device.CreateTextureBuilder()
.SetDimension(nxt::TextureDimension::e2D) .SetDimension(dawn::TextureDimension::e2D)
.SetExtent(640, 480, 1) .SetExtent(640, 480, 1)
.SetFormat(nxt::TextureFormat::D32FloatS8Uint) .SetFormat(dawn::TextureFormat::D32FloatS8Uint)
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment) .SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
.GetResult(); .GetResult();
return depthStencilTexture.CreateTextureViewBuilder() return depthStencilTexture.CreateTextureViewBuilder()
.GetResult(); .GetResult();
} }
void GetNextRenderPassDescriptor(const nxt::Device& device, void GetNextRenderPassDescriptor(const dawn::Device& device,
const nxt::SwapChain& swapchain, const dawn::SwapChain& swapchain,
const nxt::TextureView& depthStencilView, const dawn::TextureView& depthStencilView,
nxt::Texture* backbuffer, dawn::Texture* backbuffer,
nxt::RenderPassDescriptor* info) { dawn::RenderPassDescriptor* info) {
*backbuffer = swapchain.GetNextTexture(); *backbuffer = swapchain.GetNextTexture();
auto backbufferView = backbuffer->CreateTextureViewBuilder().GetResult(); auto backbufferView = backbuffer->CreateTextureViewBuilder().GetResult();
*info = device.CreateRenderPassDescriptorBuilder() *info = device.CreateRenderPassDescriptorBuilder()
.SetColorAttachment(0, backbufferView, nxt::LoadOp::Clear) .SetColorAttachment(0, backbufferView, dawn::LoadOp::Clear)
.SetDepthStencilAttachment(depthStencilView, nxt::LoadOp::Clear, nxt::LoadOp::Clear) .SetDepthStencilAttachment(depthStencilView, dawn::LoadOp::Clear, dawn::LoadOp::Clear)
.GetResult(); .GetResult();
} }

View File

@ -22,13 +22,13 @@ bool ShouldQuit();
struct GLFWwindow; struct GLFWwindow;
struct GLFWwindow* GetGLFWWindow(); struct GLFWwindow* GetGLFWWindow();
nxt::Device CreateCppNXTDevice(); dawn::Device CreateCppNXTDevice();
uint64_t GetSwapChainImplementation(); uint64_t GetSwapChainImplementation();
nxt::TextureFormat GetPreferredSwapChainTextureFormat(); dawn::TextureFormat GetPreferredSwapChainTextureFormat();
nxt::SwapChain GetSwapChain(const nxt::Device& device); dawn::SwapChain GetSwapChain(const dawn::Device& device);
nxt::TextureView CreateDefaultDepthStencilView(const nxt::Device& device); dawn::TextureView CreateDefaultDepthStencilView(const dawn::Device& device);
void GetNextRenderPassDescriptor(const nxt::Device& device, void GetNextRenderPassDescriptor(const dawn::Device& device,
const nxt::SwapChain& swapchain, const dawn::SwapChain& swapchain,
const nxt::TextureView& depthStencilView, const dawn::TextureView& depthStencilView,
nxt::Texture* backbuffer, dawn::Texture* backbuffer,
nxt::RenderPassDescriptor* info); dawn::RenderPassDescriptor* info);

View File

@ -64,8 +64,8 @@ namespace gl {
} }
struct MaterialInfo { struct MaterialInfo {
nxt::RenderPipeline pipeline; dawn::RenderPipeline pipeline;
nxt::BindGroup bindGroup0; dawn::BindGroup bindGroup0;
std::map<uint32_t, std::string> slotSemantics; std::map<uint32_t, std::string> slotSemantics;
}; };
@ -74,18 +74,18 @@ struct u_transform_block {
glm::mat4 modelInvTr; glm::mat4 modelInvTr;
}; };
nxt::Device device; dawn::Device device;
nxt::Queue queue; dawn::Queue queue;
nxt::SwapChain swapchain; dawn::SwapChain swapchain;
nxt::TextureView depthStencilView; dawn::TextureView depthStencilView;
nxt::Buffer defaultBuffer; dawn::Buffer defaultBuffer;
std::map<std::string, nxt::Buffer> buffers; std::map<std::string, dawn::Buffer> buffers;
std::map<std::string, nxt::CommandBuffer> commandBuffers; std::map<std::string, dawn::CommandBuffer> commandBuffers;
std::map<uint32_t, std::string> slotSemantics = {{0, "POSITION"}, {1, "NORMAL"}, {2, "TEXCOORD_0"}}; std::map<uint32_t, std::string> slotSemantics = {{0, "POSITION"}, {1, "NORMAL"}, {2, "TEXCOORD_0"}};
std::map<std::string, nxt::Sampler> samplers; std::map<std::string, dawn::Sampler> samplers;
std::map<std::string, nxt::TextureView> textures; std::map<std::string, dawn::TextureView> textures;
tinygltf::Scene scene; tinygltf::Scene scene;
glm::mat4 projection = glm::perspective(glm::radians(60.f), 640.f/480, 0.1f, 2000.f); glm::mat4 projection = glm::perspective(glm::radians(60.f), 640.f/480, 0.1f, 2000.f);
@ -100,16 +100,16 @@ namespace {
return ""; return "";
} }
bool techniqueParameterTypeToVertexFormat(int type, nxt::VertexFormat *format) { bool techniqueParameterTypeToVertexFormat(int type, dawn::VertexFormat *format) {
switch (type) { switch (type) {
case gl::FloatVec2: case gl::FloatVec2:
*format = nxt::VertexFormat::FloatR32G32; *format = dawn::VertexFormat::FloatR32G32;
return true; return true;
case gl::FloatVec3: case gl::FloatVec3:
*format = nxt::VertexFormat::FloatR32G32B32; *format = dawn::VertexFormat::FloatR32G32B32;
return true; return true;
case gl::FloatVec4: case gl::FloatVec4:
*format = nxt::VertexFormat::FloatR32G32B32A32; *format = dawn::VertexFormat::FloatR32G32B32A32;
return true; return true;
default: default:
return false; return false;
@ -121,7 +121,7 @@ namespace {
namespace { namespace {
void initBuffers() { void initBuffers() {
defaultBuffer = device.CreateBufferBuilder() defaultBuffer = device.CreateBufferBuilder()
.SetAllowedUsage(nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Index) .SetAllowedUsage(dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Index)
.SetSize(256) .SetSize(256)
.GetResult(); .GetResult();
@ -129,13 +129,13 @@ namespace {
const auto& iBufferViewID = bv.first; const auto& iBufferViewID = bv.first;
const auto& iBufferView = bv.second; const auto& iBufferView = bv.second;
nxt::BufferUsageBit usage = nxt::BufferUsageBit::None; dawn::BufferUsageBit usage = dawn::BufferUsageBit::None;
switch (iBufferView.target) { switch (iBufferView.target) {
case gl::ArrayBuffer: case gl::ArrayBuffer:
usage |= nxt::BufferUsageBit::Vertex; usage |= dawn::BufferUsageBit::Vertex;
break; break;
case gl::ElementArrayBuffer: case gl::ElementArrayBuffer:
usage |= nxt::BufferUsageBit::Index; usage |= dawn::BufferUsageBit::Index;
break; break;
case 0: case 0:
fprintf(stderr, "TODO: buffer view has no target; skipping\n"); fprintf(stderr, "TODO: buffer view has no target; skipping\n");
@ -175,7 +175,7 @@ namespace {
} }
} }
auto oVSModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"( auto oVSModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
#version 450 #version 450
layout(push_constant) uniform u_transform_block { layout(push_constant) uniform u_transform_block {
@ -231,29 +231,29 @@ namespace {
fragcolor = vec4(vec3(diffamb), 1); fragcolor = vec4(vec3(diffamb), 1);
})"; })";
auto oFSModule = utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, hasTexture ? oFSSourceTextured : oFSSourceUntextured); auto oFSModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, hasTexture ? oFSSourceTextured : oFSSourceUntextured);
nxt::InputStateBuilder builder = device.CreateInputStateBuilder(); dawn::InputStateBuilder builder = device.CreateInputStateBuilder();
std::bitset<3> slotsSet; std::bitset<3> slotsSet;
for (const auto& a : iTechnique.attributes) { for (const auto& a : iTechnique.attributes) {
const auto iAttributeName = a.first; const auto iAttributeName = a.first;
const auto iParameter = iTechnique.parameters.at(a.second); const auto iParameter = iTechnique.parameters.at(a.second);
nxt::VertexFormat format; dawn::VertexFormat format;
if (!techniqueParameterTypeToVertexFormat(iParameter.type, &format)) { if (!techniqueParameterTypeToVertexFormat(iParameter.type, &format)) {
fprintf(stderr, "unsupported technique parameter type %d\n", iParameter.type); fprintf(stderr, "unsupported technique parameter type %d\n", iParameter.type);
continue; continue;
} }
if (iParameter.semantic == "POSITION") { if (iParameter.semantic == "POSITION") {
builder.SetAttribute(0, 0, format, 0); builder.SetAttribute(0, 0, format, 0);
builder.SetInput(0, static_cast<uint32_t>(stridePos), nxt::InputStepMode::Vertex); builder.SetInput(0, static_cast<uint32_t>(stridePos), dawn::InputStepMode::Vertex);
slotsSet.set(0); slotsSet.set(0);
} else if (iParameter.semantic == "NORMAL") { } else if (iParameter.semantic == "NORMAL") {
builder.SetAttribute(1, 1, format, 0); builder.SetAttribute(1, 1, format, 0);
builder.SetInput(1, static_cast<uint32_t>(strideNor), nxt::InputStepMode::Vertex); builder.SetInput(1, static_cast<uint32_t>(strideNor), dawn::InputStepMode::Vertex);
slotsSet.set(1); slotsSet.set(1);
} else if (iParameter.semantic == "TEXCOORD_0") { } else if (iParameter.semantic == "TEXCOORD_0") {
builder.SetAttribute(2, 2, format, 0); builder.SetAttribute(2, 2, format, 0);
builder.SetInput(2, static_cast<uint32_t>(strideTxc), nxt::InputStepMode::Vertex); builder.SetInput(2, static_cast<uint32_t>(strideTxc), dawn::InputStepMode::Vertex);
slotsSet.set(2); slotsSet.set(2);
} else { } else {
fprintf(stderr, "unsupported technique attribute semantic %s\n", iParameter.semantic.c_str()); fprintf(stderr, "unsupported technique attribute semantic %s\n", iParameter.semantic.c_str());
@ -264,40 +264,40 @@ namespace {
if (slotsSet[i]) { if (slotsSet[i]) {
continue; continue;
} }
builder.SetAttribute(i, i, nxt::VertexFormat::FloatR32G32B32A32, 0); builder.SetAttribute(i, i, dawn::VertexFormat::FloatR32G32B32A32, 0);
builder.SetInput(i, 0, nxt::InputStepMode::Vertex); builder.SetInput(i, 0, dawn::InputStepMode::Vertex);
} }
auto inputState = builder.GetResult(); auto inputState = builder.GetResult();
constexpr nxt::ShaderStageBit kNoStages{}; constexpr dawn::ShaderStageBit kNoStages{};
nxt::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout( dawn::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, { device, {
{0, hasTexture ? nxt::ShaderStageBit::Fragment : kNoStages, {0, hasTexture ? dawn::ShaderStageBit::Fragment : kNoStages,
nxt::BindingType::Sampler}, dawn::BindingType::Sampler},
{1, hasTexture ? nxt::ShaderStageBit::Fragment : kNoStages, {1, hasTexture ? dawn::ShaderStageBit::Fragment : kNoStages,
nxt::BindingType::SampledTexture}, dawn::BindingType::SampledTexture},
}); });
auto depthStencilState = device.CreateDepthStencilStateBuilder() auto depthStencilState = device.CreateDepthStencilStateBuilder()
.SetDepthCompareFunction(nxt::CompareFunction::Less) .SetDepthCompareFunction(dawn::CompareFunction::Less)
.SetDepthWriteEnabled(true) .SetDepthWriteEnabled(true)
.GetResult(); .GetResult();
auto pipelineLayout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout); auto pipelineLayout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout);
auto pipeline = device.CreateRenderPipelineBuilder() auto pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat()) .SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint) .SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
.SetLayout(pipelineLayout) .SetLayout(pipelineLayout)
.SetStage(nxt::ShaderStage::Vertex, oVSModule, "main") .SetStage(dawn::ShaderStage::Vertex, oVSModule, "main")
.SetStage(nxt::ShaderStage::Fragment, oFSModule, "main") .SetStage(dawn::ShaderStage::Fragment, oFSModule, "main")
.SetIndexFormat(nxt::IndexFormat::Uint16) .SetIndexFormat(dawn::IndexFormat::Uint16)
.SetInputState(inputState) .SetInputState(inputState)
.SetDepthStencilState(depthStencilState) .SetDepthStencilState(depthStencilState)
.GetResult(); .GetResult();
auto bindGroupBuilder = device.CreateBindGroupBuilder(); auto bindGroupBuilder = device.CreateBindGroupBuilder();
bindGroupBuilder.SetLayout(bindGroupLayout) bindGroupBuilder.SetLayout(bindGroupLayout)
.SetUsage(nxt::BindGroupUsage::Frozen); .SetUsage(dawn::BindGroupUsage::Frozen);
if (hasTexture) { if (hasTexture) {
const auto& textureView = textures[iTextureID]; const auto& textureView = textures[iTextureID];
const auto& iSamplerID = scene.textures[iTextureID].sampler; const auto& iSamplerID = scene.textures[iTextureID].sampler;
@ -319,15 +319,15 @@ namespace {
const auto& iSamplerID = s.first; const auto& iSamplerID = s.first;
const auto& iSampler = s.second; const auto& iSampler = s.second;
nxt::SamplerDescriptor desc = utils::GetDefaultSamplerDescriptor(); dawn::SamplerDescriptor desc = utils::GetDefaultSamplerDescriptor();
// TODO: wrap modes // TODO: wrap modes
switch (iSampler.magFilter) { switch (iSampler.magFilter) {
case gl::Nearest: case gl::Nearest:
desc.magFilter = nxt::FilterMode::Nearest; desc.magFilter = dawn::FilterMode::Nearest;
break; break;
case gl::Linear: case gl::Linear:
desc.magFilter = nxt::FilterMode::Linear; desc.magFilter = dawn::FilterMode::Linear;
break; break;
default: default:
fprintf(stderr, "unsupported magFilter %d\n", iSampler.magFilter); fprintf(stderr, "unsupported magFilter %d\n", iSampler.magFilter);
@ -337,12 +337,12 @@ namespace {
case gl::Nearest: case gl::Nearest:
case gl::NearestMipmapNearest: case gl::NearestMipmapNearest:
case gl::NearestMipmapLinear: case gl::NearestMipmapLinear:
desc.minFilter = nxt::FilterMode::Nearest; desc.minFilter = dawn::FilterMode::Nearest;
break; break;
case gl::Linear: case gl::Linear:
case gl::LinearMipmapNearest: case gl::LinearMipmapNearest:
case gl::LinearMipmapLinear: case gl::LinearMipmapLinear:
desc.minFilter = nxt::FilterMode::Linear; desc.minFilter = dawn::FilterMode::Linear;
break; break;
default: default:
fprintf(stderr, "unsupported minFilter %d\n", iSampler.magFilter); fprintf(stderr, "unsupported minFilter %d\n", iSampler.magFilter);
@ -351,11 +351,11 @@ namespace {
switch (iSampler.minFilter) { switch (iSampler.minFilter) {
case gl::NearestMipmapNearest: case gl::NearestMipmapNearest:
case gl::LinearMipmapNearest: case gl::LinearMipmapNearest:
desc.mipmapFilter = nxt::FilterMode::Nearest; desc.mipmapFilter = dawn::FilterMode::Nearest;
break; break;
case gl::NearestMipmapLinear: case gl::NearestMipmapLinear:
case gl::LinearMipmapLinear: case gl::LinearMipmapLinear:
desc.mipmapFilter = nxt::FilterMode::Linear; desc.mipmapFilter = dawn::FilterMode::Linear;
break; break;
} }
@ -369,10 +369,10 @@ namespace {
const auto& iTexture = t.second; const auto& iTexture = t.second;
const auto& iImage = scene.images[iTexture.source]; const auto& iImage = scene.images[iTexture.source];
nxt::TextureFormat format = nxt::TextureFormat::R8G8B8A8Unorm; dawn::TextureFormat format = dawn::TextureFormat::R8G8B8A8Unorm;
switch (iTexture.format) { switch (iTexture.format) {
case gl::RGBA: case gl::RGBA:
format = nxt::TextureFormat::R8G8B8A8Unorm; format = dawn::TextureFormat::R8G8B8A8Unorm;
break; break;
default: default:
fprintf(stderr, "unsupported texture format %d\n", iTexture.format); fprintf(stderr, "unsupported texture format %d\n", iTexture.format);
@ -380,11 +380,11 @@ namespace {
} }
auto oTexture = device.CreateTextureBuilder() auto oTexture = device.CreateTextureBuilder()
.SetDimension(nxt::TextureDimension::e2D) .SetDimension(dawn::TextureDimension::e2D)
.SetExtent(iImage.width, iImage.height, 1) .SetExtent(iImage.width, iImage.height, 1)
.SetFormat(format) .SetFormat(format)
.SetMipLevels(1) .SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::TransferDst | nxt::TextureUsageBit::Sampled) .SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled)
.GetResult(); .GetResult();
// TODO: release this texture // TODO: release this texture
@ -426,7 +426,7 @@ namespace {
fprintf(stderr, "unsupported image.component %d\n", iImage.component); fprintf(stderr, "unsupported image.component %d\n", iImage.component);
} }
nxt::Buffer staging = utils::CreateBufferFromData(device, data, rowPitch * iImage.height, nxt::BufferUsageBit::TransferSrc); dawn::Buffer staging = utils::CreateBufferFromData(device, data, rowPitch * iImage.height, dawn::BufferUsageBit::TransferSrc);
auto cmdbuf = device.CreateCommandBufferBuilder() auto cmdbuf = device.CreateCommandBufferBuilder()
.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();
@ -442,7 +442,7 @@ namespace {
queue = device.CreateQueue(); queue = device.CreateQueue();
swapchain = GetSwapChain(device); swapchain = GetSwapChain(device);
swapchain.Configure(GetPreferredSwapChainTextureFormat(), swapchain.Configure(GetPreferredSwapChainTextureFormat(),
nxt::TextureUsageBit::OutputAttachment, 640, 480); dawn::TextureUsageBit::OutputAttachment, 640, 480);
depthStencilView = CreateDefaultDepthStencilView(device); depthStencilView = CreateDefaultDepthStencilView(device);
@ -454,7 +454,7 @@ namespace {
// Drawing // Drawing
namespace { namespace {
void drawMesh(nxt::CommandBufferBuilder& cmd, const tinygltf::Mesh& iMesh, const glm::mat4& model) { void drawMesh(dawn::CommandBufferBuilder& cmd, const tinygltf::Mesh& iMesh, const glm::mat4& model) {
for (const auto& iPrim : iMesh.primitives) { for (const auto& iPrim : iMesh.primitives) {
if (iPrim.mode != gl::Triangles) { if (iPrim.mode != gl::Triangles) {
fprintf(stderr, "unsupported primitive mode %d\n", iPrim.mode); fprintf(stderr, "unsupported primitive mode %d\n", iPrim.mode);
@ -480,7 +480,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]);
cmd.SetRenderPipeline(material.pipeline); cmd.SetRenderPipeline(material.pipeline);
cmd.SetBindGroup(0, material.bindGroup0); cmd.SetBindGroup(0, material.bindGroup0);
cmd.SetPushConstants(nxt::ShaderStageBit::Vertex, cmd.SetPushConstants(dawn::ShaderStageBit::Vertex,
0, sizeof(u_transform_block) / sizeof(uint32_t), 0, sizeof(u_transform_block) / sizeof(uint32_t),
reinterpret_cast<const uint32_t*>(&transforms)); reinterpret_cast<const uint32_t*>(&transforms));
@ -525,7 +525,7 @@ namespace {
} }
} }
void drawNode(nxt::CommandBufferBuilder& cmd, const tinygltf::Node& node, const glm::mat4& parent = glm::mat4()) { void drawNode(dawn::CommandBufferBuilder& cmd, const tinygltf::Node& node, const glm::mat4& parent = glm::mat4()) {
glm::mat4 model; glm::mat4 model;
if (node.matrix.size() == 16) { if (node.matrix.size() == 16) {
model = glm::make_mat4(node.matrix.data()); model = glm::make_mat4(node.matrix.data());
@ -554,12 +554,12 @@ namespace {
} }
void frame() { void frame() {
nxt::Texture backbuffer; dawn::Texture backbuffer;
nxt::RenderPassDescriptor renderPass; dawn::RenderPassDescriptor renderPass;
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass); GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
const auto& defaultSceneNodes = scene.scenes.at(scene.defaultScene); const auto& defaultSceneNodes = scene.scenes.at(scene.defaultScene);
nxt::CommandBufferBuilder cmd = device.CreateCommandBufferBuilder() dawn::CommandBufferBuilder cmd = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderPass) .BeginRenderPass(renderPass)
.Clone(); .Clone();
for (const auto& n : defaultSceneNodes) { for (const auto& n : defaultSceneNodes) {