Rename nxt:: to dawn:: in examples
This commit is contained in:
parent
54e58c20b2
commit
4828d92df3
|
@ -21,11 +21,11 @@
|
|||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
nxt::Device device;
|
||||
nxt::Queue queue;
|
||||
nxt::SwapChain swapchain;
|
||||
nxt::TextureView depthStencilView;
|
||||
nxt::RenderPipeline pipeline;
|
||||
dawn::Device device;
|
||||
dawn::Queue queue;
|
||||
dawn::SwapChain swapchain;
|
||||
dawn::TextureView depthStencilView;
|
||||
dawn::RenderPipeline pipeline;
|
||||
|
||||
float RandomFloat(float min, float max) {
|
||||
float zeroOne = rand() / float(RAND_MAX);
|
||||
|
@ -49,9 +49,9 @@ void init() {
|
|||
queue = device.CreateQueue();
|
||||
swapchain = GetSwapChain(device);
|
||||
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
|
||||
|
||||
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
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
layout(location = 0) in vec4 v_color;
|
||||
|
@ -111,9 +111,9 @@ void init() {
|
|||
|
||||
pipeline = device.CreateRenderPipelineBuilder()
|
||||
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
|
||||
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
|
||||
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
|
||||
.GetResult();
|
||||
|
||||
shaderData.resize(10000);
|
||||
|
@ -128,8 +128,8 @@ void init() {
|
|||
}
|
||||
|
||||
void frame() {
|
||||
nxt::Texture backbuffer;
|
||||
nxt::RenderPassDescriptor renderPass;
|
||||
dawn::Texture backbuffer;
|
||||
dawn::RenderPassDescriptor renderPass;
|
||||
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
||||
|
||||
static int f = 0;
|
||||
|
@ -137,16 +137,16 @@ void frame() {
|
|||
|
||||
size_t i = 0;
|
||||
|
||||
nxt::CommandBuffer commands;
|
||||
dawn::CommandBuffer commands;
|
||||
{
|
||||
nxt::CommandBufferBuilder builder = device.CreateCommandBufferBuilder()
|
||||
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder()
|
||||
.BeginRenderPass(renderPass)
|
||||
.SetRenderPipeline(pipeline)
|
||||
.Clone();
|
||||
|
||||
for (int k = 0; k < 10000; k++) {
|
||||
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);
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ void init() {
|
|||
"void main() {\n"
|
||||
" gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);\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 =
|
||||
"#version 450\n"
|
||||
|
@ -53,7 +53,7 @@ void init() {
|
|||
"void main() {\n"
|
||||
" fragColor = vec4(1.0, 0.0, 0.0, 1.0);\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);
|
||||
|
|
|
@ -23,19 +23,19 @@
|
|||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
nxt::Device device;
|
||||
nxt::Queue queue;
|
||||
nxt::SwapChain swapchain;
|
||||
nxt::TextureView depthStencilView;
|
||||
dawn::Device device;
|
||||
dawn::Queue queue;
|
||||
dawn::SwapChain swapchain;
|
||||
dawn::TextureView depthStencilView;
|
||||
|
||||
nxt::Buffer modelBuffer;
|
||||
std::array<nxt::Buffer, 2> particleBuffers;
|
||||
dawn::Buffer modelBuffer;
|
||||
std::array<dawn::Buffer, 2> particleBuffers;
|
||||
|
||||
nxt::RenderPipeline renderPipeline;
|
||||
dawn::RenderPipeline renderPipeline;
|
||||
|
||||
nxt::Buffer updateParams;
|
||||
nxt::ComputePipeline updatePipeline;
|
||||
std::array<nxt::BindGroup, 2> updateBGs;
|
||||
dawn::Buffer updateParams;
|
||||
dawn::ComputePipeline updatePipeline;
|
||||
std::array<dawn::BindGroup, 2> updateBGs;
|
||||
|
||||
size_t pingpong = 0;
|
||||
|
||||
|
@ -63,10 +63,10 @@ void initBuffers() {
|
|||
{0.01, -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 };
|
||||
updateParams = utils::CreateBufferFromData(device, ¶ms, sizeof(params), nxt::BufferUsageBit::Uniform);
|
||||
updateParams = utils::CreateBufferFromData(device, ¶ms, sizeof(params), dawn::BufferUsageBit::Uniform);
|
||||
|
||||
std::vector<Particle> initialParticles(kNumParticles);
|
||||
{
|
||||
|
@ -81,7 +81,7 @@ void initBuffers() {
|
|||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
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)
|
||||
.GetResult();
|
||||
|
||||
|
@ -92,7 +92,7 @@ void initBuffers() {
|
|||
}
|
||||
|
||||
void initRender() {
|
||||
nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"(
|
||||
dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
|
||||
#version 450
|
||||
layout(location = 0) in vec2 a_particlePos;
|
||||
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
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
void main() {
|
||||
|
@ -113,27 +113,27 @@ void initRender() {
|
|||
}
|
||||
)");
|
||||
|
||||
nxt::InputState inputState = device.CreateInputStateBuilder()
|
||||
.SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32, offsetof(Particle, pos))
|
||||
.SetAttribute(1, 0, nxt::VertexFormat::FloatR32G32, offsetof(Particle, vel))
|
||||
.SetInput(0, sizeof(Particle), nxt::InputStepMode::Instance)
|
||||
.SetAttribute(2, 1, nxt::VertexFormat::FloatR32G32, 0)
|
||||
.SetInput(1, sizeof(glm::vec2), nxt::InputStepMode::Vertex)
|
||||
dawn::InputState inputState = device.CreateInputStateBuilder()
|
||||
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32, offsetof(Particle, pos))
|
||||
.SetAttribute(1, 0, dawn::VertexFormat::FloatR32G32, offsetof(Particle, vel))
|
||||
.SetInput(0, sizeof(Particle), dawn::InputStepMode::Instance)
|
||||
.SetAttribute(2, 1, dawn::VertexFormat::FloatR32G32, 0)
|
||||
.SetInput(1, sizeof(glm::vec2), dawn::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
|
||||
depthStencilView = CreateDefaultDepthStencilView(device);
|
||||
|
||||
renderPipeline = device.CreateRenderPipelineBuilder()
|
||||
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
|
||||
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
|
||||
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetInputState(inputState)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
void initSim() {
|
||||
nxt::ShaderModule module = utils::CreateShaderModule(device, nxt::ShaderStage::Compute, R"(
|
||||
dawn::ShaderModule module = utils::CreateShaderModule(device, dawn::ShaderStage::Compute, R"(
|
||||
#version 450
|
||||
|
||||
struct Particle {
|
||||
|
@ -224,23 +224,23 @@ void initSim() {
|
|||
|
||||
auto bgl = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{0, nxt::ShaderStageBit::Compute, nxt::BindingType::UniformBuffer},
|
||||
{1, nxt::ShaderStageBit::Compute, nxt::BindingType::StorageBuffer},
|
||||
{2, nxt::ShaderStageBit::Compute, nxt::BindingType::StorageBuffer},
|
||||
{0, dawn::ShaderStageBit::Compute, dawn::BindingType::UniformBuffer},
|
||||
{1, dawn::ShaderStageBit::Compute, dawn::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()
|
||||
.SetLayout(pl)
|
||||
.SetStage(nxt::ShaderStage::Compute, module, "main")
|
||||
.SetStage(dawn::ShaderStage::Compute, module, "main")
|
||||
.GetResult();
|
||||
|
||||
nxt::BufferView updateParamsView = updateParams.CreateBufferViewBuilder()
|
||||
dawn::BufferView updateParamsView = updateParams.CreateBufferViewBuilder()
|
||||
.SetExtent(0, sizeof(SimParams))
|
||||
.GetResult();
|
||||
|
||||
std::array<nxt::BufferView, 2> views;
|
||||
std::array<dawn::BufferView, 2> views;
|
||||
for (uint32_t i = 0; i < 2; ++i) {
|
||||
views[i] = particleBuffers[i].CreateBufferViewBuilder()
|
||||
.SetExtent(0, kNumParticles * sizeof(Particle))
|
||||
|
@ -250,7 +250,7 @@ void initSim() {
|
|||
for (uint32_t i = 0; i < 2; ++i) {
|
||||
updateBGs[i] = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetUsage(nxt::BindGroupUsage::Frozen)
|
||||
.SetUsage(dawn::BindGroupUsage::Frozen)
|
||||
.SetBufferViews(0, 1, &updateParamsView)
|
||||
.SetBufferViews(1, 1, &views[i])
|
||||
.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};
|
||||
auto& bufferDst = particleBuffers[(i + 1) % 2];
|
||||
return device.CreateCommandBufferBuilder()
|
||||
|
@ -284,7 +284,7 @@ void init() {
|
|||
queue = device.CreateQueue();
|
||||
swapchain = GetSwapChain(device);
|
||||
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
|
||||
nxt::TextureUsageBit::OutputAttachment, 640, 480);
|
||||
dawn::TextureUsageBit::OutputAttachment, 640, 480);
|
||||
|
||||
initBuffers();
|
||||
initRender();
|
||||
|
@ -292,11 +292,11 @@ void init() {
|
|||
}
|
||||
|
||||
void frame() {
|
||||
nxt::Texture backbuffer;
|
||||
nxt::RenderPassDescriptor renderPass;
|
||||
dawn::Texture backbuffer;
|
||||
dawn::RenderPassDescriptor renderPass;
|
||||
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
||||
|
||||
nxt::CommandBuffer commandBuffer = createCommandBuffer(renderPass, pingpong);
|
||||
dawn::CommandBuffer commandBuffer = createCommandBuffer(renderPass, pingpong);
|
||||
queue.Submit(1, &commandBuffer);
|
||||
swapchain.Present(backbuffer);
|
||||
DoFlush();
|
||||
|
|
|
@ -19,44 +19,44 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
nxt::Device device;
|
||||
dawn::Device device;
|
||||
|
||||
nxt::Buffer indexBuffer;
|
||||
nxt::Buffer vertexBuffer;
|
||||
dawn::Buffer indexBuffer;
|
||||
dawn::Buffer vertexBuffer;
|
||||
|
||||
nxt::Texture texture;
|
||||
nxt::Sampler sampler;
|
||||
dawn::Texture texture;
|
||||
dawn::Sampler sampler;
|
||||
|
||||
nxt::Queue queue;
|
||||
nxt::SwapChain swapchain;
|
||||
nxt::TextureView depthStencilView;
|
||||
nxt::RenderPipeline pipeline;
|
||||
nxt::BindGroup bindGroup;
|
||||
dawn::Queue queue;
|
||||
dawn::SwapChain swapchain;
|
||||
dawn::TextureView depthStencilView;
|
||||
dawn::RenderPipeline pipeline;
|
||||
dawn::BindGroup bindGroup;
|
||||
|
||||
void initBuffers() {
|
||||
static const uint32_t indexData[3] = {
|
||||
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] = {
|
||||
0.0f, 0.5f, 0.0f, 1.0f,
|
||||
-0.5f, -0.5f, 0.0f, 1.0f,
|
||||
0.5f, -0.5f, 0.0f, 1.0f,
|
||||
};
|
||||
vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex);
|
||||
vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData), dawn::BufferUsageBit::Vertex);
|
||||
}
|
||||
|
||||
void initTextures() {
|
||||
texture = device.CreateTextureBuilder()
|
||||
.SetDimension(nxt::TextureDimension::e2D)
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(1024, 1024, 1)
|
||||
.SetFormat(nxt::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(nxt::TextureUsageBit::TransferDst | nxt::TextureUsageBit::Sampled)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled)
|
||||
.GetResult();
|
||||
|
||||
nxt::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
|
||||
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
|
||||
sampler = device.CreateSampler(&samplerDesc);
|
||||
|
||||
// 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);
|
||||
nxt::CommandBuffer copy = device.CreateCommandBufferBuilder()
|
||||
dawn::Buffer stagingBuffer = utils::CreateBufferFromData(device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::CommandBuffer copy = device.CreateCommandBufferBuilder()
|
||||
.CopyBufferToTexture(stagingBuffer, 0, 0, texture, 0, 0, 0, 1024, 1024, 1, 0)
|
||||
.GetResult();
|
||||
|
||||
|
@ -80,12 +80,12 @@ void init() {
|
|||
queue = device.CreateQueue();
|
||||
swapchain = GetSwapChain(device);
|
||||
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
|
||||
nxt::TextureUsageBit::OutputAttachment, 640, 480);
|
||||
dawn::TextureUsageBit::OutputAttachment, 640, 480);
|
||||
|
||||
initBuffers();
|
||||
initTextures();
|
||||
|
||||
nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"(
|
||||
dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
|
||||
#version 450
|
||||
layout(location = 0) in vec4 pos;
|
||||
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
|
||||
layout(set = 0, binding = 0) uniform sampler mySampler;
|
||||
layout(set = 0, binding = 1) uniform texture2D myTexture;
|
||||
|
@ -104,35 +104,35 @@ void init() {
|
|||
})");
|
||||
|
||||
auto inputState = device.CreateInputStateBuilder()
|
||||
.SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32B32A32, 0)
|
||||
.SetInput(0, 4 * sizeof(float), nxt::InputStepMode::Vertex)
|
||||
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32A32, 0)
|
||||
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
|
||||
auto bgl = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{0, nxt::ShaderStageBit::Fragment, nxt::BindingType::Sampler},
|
||||
{1, nxt::ShaderStageBit::Fragment, nxt::BindingType::SampledTexture},
|
||||
{0, dawn::ShaderStageBit::Fragment, dawn::BindingType::Sampler},
|
||||
{1, dawn::ShaderStageBit::Fragment, dawn::BindingType::SampledTexture},
|
||||
});
|
||||
|
||||
nxt::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
|
||||
dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
|
||||
|
||||
depthStencilView = CreateDefaultDepthStencilView(device);
|
||||
|
||||
pipeline = device.CreateRenderPipelineBuilder()
|
||||
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
|
||||
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint)
|
||||
.SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
|
||||
.SetLayout(pl)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetIndexFormat(nxt::IndexFormat::Uint32)
|
||||
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetIndexFormat(dawn::IndexFormat::Uint32)
|
||||
.SetInputState(inputState)
|
||||
.GetResult();
|
||||
|
||||
nxt::TextureView view = texture.CreateTextureViewBuilder().GetResult();
|
||||
dawn::TextureView view = texture.CreateTextureViewBuilder().GetResult();
|
||||
|
||||
bindGroup = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetUsage(nxt::BindGroupUsage::Frozen)
|
||||
.SetUsage(dawn::BindGroupUsage::Frozen)
|
||||
.SetSamplers(0, 1, &sampler)
|
||||
.SetTextureViews(1, 1, &view)
|
||||
.GetResult();
|
||||
|
@ -144,12 +144,12 @@ void frame() {
|
|||
s.b += 0.02f;
|
||||
if (s.b >= 1.0f) {s.b = 0.0f;}
|
||||
|
||||
nxt::Texture backbuffer;
|
||||
nxt::RenderPassDescriptor renderPass;
|
||||
dawn::Texture backbuffer;
|
||||
dawn::RenderPassDescriptor renderPass;
|
||||
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
||||
|
||||
static const uint32_t vertexBufferOffsets[1] = {0};
|
||||
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
||||
.BeginRenderPass(renderPass)
|
||||
.SetRenderPipeline(pipeline)
|
||||
.SetBindGroup(0, bindGroup)
|
||||
|
|
|
@ -22,24 +22,24 @@
|
|||
#include <glm/glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/glm/gtc/type_ptr.hpp>
|
||||
|
||||
nxt::Device device;
|
||||
dawn::Device device;
|
||||
|
||||
nxt::Buffer indexBuffer;
|
||||
nxt::Buffer vertexBuffer;
|
||||
nxt::Buffer planeBuffer;
|
||||
nxt::Buffer cameraBuffer;
|
||||
nxt::Buffer transformBuffer[2];
|
||||
dawn::Buffer indexBuffer;
|
||||
dawn::Buffer vertexBuffer;
|
||||
dawn::Buffer planeBuffer;
|
||||
dawn::Buffer cameraBuffer;
|
||||
dawn::Buffer transformBuffer[2];
|
||||
|
||||
nxt::BindGroup cameraBindGroup;
|
||||
nxt::BindGroup bindGroup[2];
|
||||
nxt::BindGroup cubeTransformBindGroup[2];
|
||||
dawn::BindGroup cameraBindGroup;
|
||||
dawn::BindGroup bindGroup[2];
|
||||
dawn::BindGroup cubeTransformBindGroup[2];
|
||||
|
||||
nxt::Queue queue;
|
||||
nxt::SwapChain swapchain;
|
||||
nxt::TextureView depthStencilView;
|
||||
nxt::RenderPipeline pipeline;
|
||||
nxt::RenderPipeline planePipeline;
|
||||
nxt::RenderPipeline reflectionPipeline;
|
||||
dawn::Queue queue;
|
||||
dawn::SwapChain swapchain;
|
||||
dawn::TextureView depthStencilView;
|
||||
dawn::RenderPipeline pipeline;
|
||||
dawn::RenderPipeline planePipeline;
|
||||
dawn::RenderPipeline reflectionPipeline;
|
||||
|
||||
void initBuffers() {
|
||||
static const uint32_t indexData[6*6] = {
|
||||
|
@ -61,7 +61,7 @@ void initBuffers() {
|
|||
20, 21, 22,
|
||||
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] = {
|
||||
-1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
|
||||
|
@ -94,7 +94,7 @@ void initBuffers() {
|
|||
-1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
-1.0, 1.0, -1.0, 1.0, 1.0, 1.0
|
||||
};
|
||||
vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData), nxt::BufferUsageBit::Vertex);
|
||||
vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData), dawn::BufferUsageBit::Vertex);
|
||||
|
||||
static const float planeData[6 * 4] = {
|
||||
-2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
|
||||
|
@ -102,7 +102,7 @@ void initBuffers() {
|
|||
2.0, -1.0, 2.0, 0.5, 0.5, 0.5,
|
||||
-2.0, -1.0, 2.0, 0.5, 0.5, 0.5,
|
||||
};
|
||||
planeBuffer = utils::CreateBufferFromData(device, planeData, sizeof(planeData), nxt::BufferUsageBit::Vertex);
|
||||
planeBuffer = utils::CreateBufferFromData(device, planeData, sizeof(planeData), dawn::BufferUsageBit::Vertex);
|
||||
}
|
||||
|
||||
struct CameraData {
|
||||
|
@ -116,11 +116,11 @@ void init() {
|
|||
queue = device.CreateQueue();
|
||||
swapchain = GetSwapChain(device);
|
||||
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
|
||||
nxt::TextureUsageBit::OutputAttachment, 640, 480);
|
||||
dawn::TextureUsageBit::OutputAttachment, 640, 480);
|
||||
|
||||
initBuffers();
|
||||
|
||||
nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"(
|
||||
dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
|
||||
#version 450
|
||||
layout(set = 0, binding = 0) uniform cameraData {
|
||||
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
|
||||
layout(location = 2) in vec3 f_col;
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
@ -146,8 +146,8 @@ void init() {
|
|||
fragColor = vec4(f_col, 1.0);
|
||||
})");
|
||||
|
||||
nxt::ShaderModule fsReflectionModule =
|
||||
utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, R"(
|
||||
dawn::ShaderModule fsReflectionModule =
|
||||
utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, R"(
|
||||
#version 450
|
||||
layout(location = 2) in vec3 f_col;
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
@ -156,35 +156,35 @@ void init() {
|
|||
})");
|
||||
|
||||
auto inputState = device.CreateInputStateBuilder()
|
||||
.SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32B32, 0)
|
||||
.SetAttribute(1, 0, nxt::VertexFormat::FloatR32G32B32, 3 * sizeof(float))
|
||||
.SetInput(0, 6 * sizeof(float), nxt::InputStepMode::Vertex)
|
||||
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32, 0)
|
||||
.SetAttribute(1, 0, dawn::VertexFormat::FloatR32G32B32, 3 * sizeof(float))
|
||||
.SetInput(0, 6 * sizeof(float), dawn::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
|
||||
auto bgl = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{0, nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer},
|
||||
{1, nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer},
|
||||
{0, dawn::ShaderStageBit::Vertex, dawn::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()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::Uniform)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::Uniform)
|
||||
.SetSize(sizeof(CameraData))
|
||||
.GetResult();
|
||||
|
||||
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));
|
||||
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))
|
||||
.GetResult();
|
||||
|
||||
nxt::BufferView transformBufferView[2] = {
|
||||
dawn::BufferView transformBufferView[2] = {
|
||||
transformBuffer[0].CreateBufferViewBuilder()
|
||||
.SetExtent(0, sizeof(glm::mat4))
|
||||
.GetResult(),
|
||||
|
@ -195,14 +195,14 @@ void init() {
|
|||
|
||||
bindGroup[0] = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetUsage(nxt::BindGroupUsage::Frozen)
|
||||
.SetUsage(dawn::BindGroupUsage::Frozen)
|
||||
.SetBufferViews(0, 1, &cameraBufferView)
|
||||
.SetBufferViews(1, 1, &transformBufferView[0])
|
||||
.GetResult();
|
||||
|
||||
bindGroup[1] = device.CreateBindGroupBuilder()
|
||||
.SetLayout(bgl)
|
||||
.SetUsage(nxt::BindGroupUsage::Frozen)
|
||||
.SetUsage(dawn::BindGroupUsage::Frozen)
|
||||
.SetBufferViews(0, 1, &cameraBufferView)
|
||||
.SetBufferViews(1, 1, &transformBufferView[1])
|
||||
.GetResult();
|
||||
|
@ -210,49 +210,49 @@ void init() {
|
|||
depthStencilView = CreateDefaultDepthStencilView(device);
|
||||
|
||||
auto depthStencilState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthCompareFunction(nxt::CompareFunction::Less)
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Less)
|
||||
.SetDepthWriteEnabled(true)
|
||||
.GetResult();
|
||||
|
||||
pipeline = device.CreateRenderPipelineBuilder()
|
||||
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
|
||||
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint)
|
||||
.SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
|
||||
.SetLayout(pl)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetIndexFormat(nxt::IndexFormat::Uint32)
|
||||
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetIndexFormat(dawn::IndexFormat::Uint32)
|
||||
.SetInputState(inputState)
|
||||
.SetDepthStencilState(depthStencilState)
|
||||
.GetResult();
|
||||
|
||||
auto planeStencilState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthCompareFunction(nxt::CompareFunction::Less)
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Less)
|
||||
.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();
|
||||
|
||||
planePipeline = device.CreateRenderPipelineBuilder()
|
||||
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
|
||||
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint)
|
||||
.SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
|
||||
.SetLayout(pl)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetInputState(inputState)
|
||||
.SetDepthStencilState(planeStencilState)
|
||||
.GetResult();
|
||||
|
||||
auto reflectionStencilState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthCompareFunction(nxt::CompareFunction::Less)
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Less)
|
||||
.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();
|
||||
|
||||
reflectionPipeline = device.CreateRenderPipelineBuilder()
|
||||
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
|
||||
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint)
|
||||
.SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
|
||||
.SetLayout(pl)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsReflectionModule, "main")
|
||||
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(dawn::ShaderStage::Fragment, fsReflectionModule, "main")
|
||||
.SetInputState(inputState)
|
||||
.SetDepthStencilState(reflectionStencilState)
|
||||
.GetResult();
|
||||
|
@ -275,11 +275,11 @@ void frame() {
|
|||
|
||||
cameraBuffer.SetSubData(0, sizeof(CameraData), reinterpret_cast<uint8_t*>(&cameraData));
|
||||
|
||||
nxt::Texture backbuffer;
|
||||
nxt::RenderPassDescriptor renderPass;
|
||||
dawn::Texture backbuffer;
|
||||
dawn::RenderPassDescriptor renderPass;
|
||||
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
||||
|
||||
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
||||
.BeginRenderPass(renderPass)
|
||||
.SetRenderPipeline(pipeline)
|
||||
.SetBindGroup(0, bindGroup[0])
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
void PrintDeviceError(const char* message, nxt::CallbackUserdata) {
|
||||
void PrintDeviceError(const char* message, dawn::CallbackUserdata) {
|
||||
std::cout << "Device error: " << message << std::endl;
|
||||
}
|
||||
|
||||
|
@ -60,26 +60,26 @@ static utils::BackendBinding* binding = nullptr;
|
|||
|
||||
static GLFWwindow* window = nullptr;
|
||||
|
||||
static nxt::wire::CommandHandler* wireServer = nullptr;
|
||||
static nxt::wire::CommandHandler* wireClient = nullptr;
|
||||
static nxt::wire::TerribleCommandBuffer* c2sBuf = nullptr;
|
||||
static nxt::wire::TerribleCommandBuffer* s2cBuf = nullptr;
|
||||
static dawn::wire::CommandHandler* wireServer = nullptr;
|
||||
static dawn::wire::CommandHandler* wireClient = nullptr;
|
||||
static dawn::wire::TerribleCommandBuffer* c2sBuf = nullptr;
|
||||
static dawn::wire::TerribleCommandBuffer* s2cBuf = nullptr;
|
||||
|
||||
nxt::Device CreateCppNXTDevice() {
|
||||
dawn::Device CreateCppNXTDevice() {
|
||||
binding = utils::CreateBinding(backendType);
|
||||
if (binding == nullptr) {
|
||||
return nxt::Device();
|
||||
return dawn::Device();
|
||||
}
|
||||
|
||||
glfwSetErrorCallback(PrintGLFWError);
|
||||
if (!glfwInit()) {
|
||||
return nxt::Device();
|
||||
return dawn::Device();
|
||||
}
|
||||
|
||||
binding->SetupGLFWWindowHints();
|
||||
window = glfwCreateWindow(640, 480, "NXT window", nullptr, nullptr);
|
||||
if (!window) {
|
||||
return nxt::Device();
|
||||
return dawn::Device();
|
||||
}
|
||||
|
||||
binding->SetWindow(window);
|
||||
|
@ -98,15 +98,15 @@ nxt::Device CreateCppNXTDevice() {
|
|||
|
||||
case CmdBufType::Terrible:
|
||||
{
|
||||
c2sBuf = new nxt::wire::TerribleCommandBuffer();
|
||||
s2cBuf = new nxt::wire::TerribleCommandBuffer();
|
||||
c2sBuf = new dawn::wire::TerribleCommandBuffer();
|
||||
s2cBuf = new dawn::wire::TerribleCommandBuffer();
|
||||
|
||||
wireServer = nxt::wire::NewServerCommandHandler(backendDevice, backendProcs, s2cBuf);
|
||||
wireServer = dawn::wire::NewServerCommandHandler(backendDevice, backendProcs, s2cBuf);
|
||||
c2sBuf->SetHandler(wireServer);
|
||||
|
||||
nxtDevice clientDevice;
|
||||
nxtProcTable clientProcs;
|
||||
wireClient = nxt::wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf);
|
||||
wireClient = dawn::wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf);
|
||||
s2cBuf->SetHandler(wireClient);
|
||||
|
||||
procs = clientProcs;
|
||||
|
@ -117,46 +117,46 @@ nxt::Device CreateCppNXTDevice() {
|
|||
|
||||
nxtSetProcs(&procs);
|
||||
procs.deviceSetErrorCallback(cDevice, PrintDeviceError, 0);
|
||||
return nxt::Device::Acquire(cDevice);
|
||||
return dawn::Device::Acquire(cDevice);
|
||||
}
|
||||
|
||||
uint64_t GetSwapChainImplementation() {
|
||||
return binding->GetSwapChainImplementation();
|
||||
}
|
||||
|
||||
nxt::TextureFormat GetPreferredSwapChainTextureFormat() {
|
||||
dawn::TextureFormat GetPreferredSwapChainTextureFormat() {
|
||||
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()
|
||||
.SetImplementation(GetSwapChainImplementation())
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
nxt::TextureView CreateDefaultDepthStencilView(const nxt::Device& device) {
|
||||
dawn::TextureView CreateDefaultDepthStencilView(const dawn::Device& device) {
|
||||
auto depthStencilTexture = device.CreateTextureBuilder()
|
||||
.SetDimension(nxt::TextureDimension::e2D)
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(640, 480, 1)
|
||||
.SetFormat(nxt::TextureFormat::D32FloatS8Uint)
|
||||
.SetFormat(dawn::TextureFormat::D32FloatS8Uint)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
|
||||
.GetResult();
|
||||
return depthStencilTexture.CreateTextureViewBuilder()
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
void GetNextRenderPassDescriptor(const nxt::Device& device,
|
||||
const nxt::SwapChain& swapchain,
|
||||
const nxt::TextureView& depthStencilView,
|
||||
nxt::Texture* backbuffer,
|
||||
nxt::RenderPassDescriptor* info) {
|
||||
void GetNextRenderPassDescriptor(const dawn::Device& device,
|
||||
const dawn::SwapChain& swapchain,
|
||||
const dawn::TextureView& depthStencilView,
|
||||
dawn::Texture* backbuffer,
|
||||
dawn::RenderPassDescriptor* info) {
|
||||
*backbuffer = swapchain.GetNextTexture();
|
||||
auto backbufferView = backbuffer->CreateTextureViewBuilder().GetResult();
|
||||
*info = device.CreateRenderPassDescriptorBuilder()
|
||||
.SetColorAttachment(0, backbufferView, nxt::LoadOp::Clear)
|
||||
.SetDepthStencilAttachment(depthStencilView, nxt::LoadOp::Clear, nxt::LoadOp::Clear)
|
||||
.SetColorAttachment(0, backbufferView, dawn::LoadOp::Clear)
|
||||
.SetDepthStencilAttachment(depthStencilView, dawn::LoadOp::Clear, dawn::LoadOp::Clear)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,13 @@ bool ShouldQuit();
|
|||
struct GLFWwindow;
|
||||
struct GLFWwindow* GetGLFWWindow();
|
||||
|
||||
nxt::Device CreateCppNXTDevice();
|
||||
dawn::Device CreateCppNXTDevice();
|
||||
uint64_t GetSwapChainImplementation();
|
||||
nxt::TextureFormat GetPreferredSwapChainTextureFormat();
|
||||
nxt::SwapChain GetSwapChain(const nxt::Device& device);
|
||||
nxt::TextureView CreateDefaultDepthStencilView(const nxt::Device& device);
|
||||
void GetNextRenderPassDescriptor(const nxt::Device& device,
|
||||
const nxt::SwapChain& swapchain,
|
||||
const nxt::TextureView& depthStencilView,
|
||||
nxt::Texture* backbuffer,
|
||||
nxt::RenderPassDescriptor* info);
|
||||
dawn::TextureFormat GetPreferredSwapChainTextureFormat();
|
||||
dawn::SwapChain GetSwapChain(const dawn::Device& device);
|
||||
dawn::TextureView CreateDefaultDepthStencilView(const dawn::Device& device);
|
||||
void GetNextRenderPassDescriptor(const dawn::Device& device,
|
||||
const dawn::SwapChain& swapchain,
|
||||
const dawn::TextureView& depthStencilView,
|
||||
dawn::Texture* backbuffer,
|
||||
dawn::RenderPassDescriptor* info);
|
||||
|
|
|
@ -64,8 +64,8 @@ namespace gl {
|
|||
}
|
||||
|
||||
struct MaterialInfo {
|
||||
nxt::RenderPipeline pipeline;
|
||||
nxt::BindGroup bindGroup0;
|
||||
dawn::RenderPipeline pipeline;
|
||||
dawn::BindGroup bindGroup0;
|
||||
std::map<uint32_t, std::string> slotSemantics;
|
||||
};
|
||||
|
||||
|
@ -74,18 +74,18 @@ struct u_transform_block {
|
|||
glm::mat4 modelInvTr;
|
||||
};
|
||||
|
||||
nxt::Device device;
|
||||
nxt::Queue queue;
|
||||
nxt::SwapChain swapchain;
|
||||
nxt::TextureView depthStencilView;
|
||||
dawn::Device device;
|
||||
dawn::Queue queue;
|
||||
dawn::SwapChain swapchain;
|
||||
dawn::TextureView depthStencilView;
|
||||
|
||||
nxt::Buffer defaultBuffer;
|
||||
std::map<std::string, nxt::Buffer> buffers;
|
||||
std::map<std::string, nxt::CommandBuffer> commandBuffers;
|
||||
dawn::Buffer defaultBuffer;
|
||||
std::map<std::string, dawn::Buffer> buffers;
|
||||
std::map<std::string, dawn::CommandBuffer> commandBuffers;
|
||||
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, nxt::TextureView> textures;
|
||||
std::map<std::string, dawn::Sampler> samplers;
|
||||
std::map<std::string, dawn::TextureView> textures;
|
||||
|
||||
tinygltf::Scene scene;
|
||||
glm::mat4 projection = glm::perspective(glm::radians(60.f), 640.f/480, 0.1f, 2000.f);
|
||||
|
@ -100,16 +100,16 @@ namespace {
|
|||
return "";
|
||||
}
|
||||
|
||||
bool techniqueParameterTypeToVertexFormat(int type, nxt::VertexFormat *format) {
|
||||
bool techniqueParameterTypeToVertexFormat(int type, dawn::VertexFormat *format) {
|
||||
switch (type) {
|
||||
case gl::FloatVec2:
|
||||
*format = nxt::VertexFormat::FloatR32G32;
|
||||
*format = dawn::VertexFormat::FloatR32G32;
|
||||
return true;
|
||||
case gl::FloatVec3:
|
||||
*format = nxt::VertexFormat::FloatR32G32B32;
|
||||
*format = dawn::VertexFormat::FloatR32G32B32;
|
||||
return true;
|
||||
case gl::FloatVec4:
|
||||
*format = nxt::VertexFormat::FloatR32G32B32A32;
|
||||
*format = dawn::VertexFormat::FloatR32G32B32A32;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
@ -121,7 +121,7 @@ namespace {
|
|||
namespace {
|
||||
void initBuffers() {
|
||||
defaultBuffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Index)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Index)
|
||||
.SetSize(256)
|
||||
.GetResult();
|
||||
|
||||
|
@ -129,13 +129,13 @@ namespace {
|
|||
const auto& iBufferViewID = bv.first;
|
||||
const auto& iBufferView = bv.second;
|
||||
|
||||
nxt::BufferUsageBit usage = nxt::BufferUsageBit::None;
|
||||
dawn::BufferUsageBit usage = dawn::BufferUsageBit::None;
|
||||
switch (iBufferView.target) {
|
||||
case gl::ArrayBuffer:
|
||||
usage |= nxt::BufferUsageBit::Vertex;
|
||||
usage |= dawn::BufferUsageBit::Vertex;
|
||||
break;
|
||||
case gl::ElementArrayBuffer:
|
||||
usage |= nxt::BufferUsageBit::Index;
|
||||
usage |= dawn::BufferUsageBit::Index;
|
||||
break;
|
||||
case 0:
|
||||
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
|
||||
|
||||
layout(push_constant) uniform u_transform_block {
|
||||
|
@ -231,29 +231,29 @@ namespace {
|
|||
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;
|
||||
for (const auto& a : iTechnique.attributes) {
|
||||
const auto iAttributeName = a.first;
|
||||
const auto iParameter = iTechnique.parameters.at(a.second);
|
||||
nxt::VertexFormat format;
|
||||
dawn::VertexFormat format;
|
||||
if (!techniqueParameterTypeToVertexFormat(iParameter.type, &format)) {
|
||||
fprintf(stderr, "unsupported technique parameter type %d\n", iParameter.type);
|
||||
continue;
|
||||
}
|
||||
if (iParameter.semantic == "POSITION") {
|
||||
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);
|
||||
} else if (iParameter.semantic == "NORMAL") {
|
||||
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);
|
||||
} else if (iParameter.semantic == "TEXCOORD_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);
|
||||
} else {
|
||||
fprintf(stderr, "unsupported technique attribute semantic %s\n", iParameter.semantic.c_str());
|
||||
|
@ -264,40 +264,40 @@ namespace {
|
|||
if (slotsSet[i]) {
|
||||
continue;
|
||||
}
|
||||
builder.SetAttribute(i, i, nxt::VertexFormat::FloatR32G32B32A32, 0);
|
||||
builder.SetInput(i, 0, nxt::InputStepMode::Vertex);
|
||||
builder.SetAttribute(i, i, dawn::VertexFormat::FloatR32G32B32A32, 0);
|
||||
builder.SetInput(i, 0, dawn::InputStepMode::Vertex);
|
||||
}
|
||||
auto inputState = builder.GetResult();
|
||||
|
||||
constexpr nxt::ShaderStageBit kNoStages{};
|
||||
nxt::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
|
||||
constexpr dawn::ShaderStageBit kNoStages{};
|
||||
dawn::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{0, hasTexture ? nxt::ShaderStageBit::Fragment : kNoStages,
|
||||
nxt::BindingType::Sampler},
|
||||
{1, hasTexture ? nxt::ShaderStageBit::Fragment : kNoStages,
|
||||
nxt::BindingType::SampledTexture},
|
||||
{0, hasTexture ? dawn::ShaderStageBit::Fragment : kNoStages,
|
||||
dawn::BindingType::Sampler},
|
||||
{1, hasTexture ? dawn::ShaderStageBit::Fragment : kNoStages,
|
||||
dawn::BindingType::SampledTexture},
|
||||
});
|
||||
|
||||
auto depthStencilState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthCompareFunction(nxt::CompareFunction::Less)
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Less)
|
||||
.SetDepthWriteEnabled(true)
|
||||
.GetResult();
|
||||
|
||||
auto pipelineLayout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout);
|
||||
auto pipeline = device.CreateRenderPipelineBuilder()
|
||||
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
|
||||
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint)
|
||||
.SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
|
||||
.SetLayout(pipelineLayout)
|
||||
.SetStage(nxt::ShaderStage::Vertex, oVSModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, oFSModule, "main")
|
||||
.SetIndexFormat(nxt::IndexFormat::Uint16)
|
||||
.SetStage(dawn::ShaderStage::Vertex, oVSModule, "main")
|
||||
.SetStage(dawn::ShaderStage::Fragment, oFSModule, "main")
|
||||
.SetIndexFormat(dawn::IndexFormat::Uint16)
|
||||
.SetInputState(inputState)
|
||||
.SetDepthStencilState(depthStencilState)
|
||||
.GetResult();
|
||||
|
||||
auto bindGroupBuilder = device.CreateBindGroupBuilder();
|
||||
bindGroupBuilder.SetLayout(bindGroupLayout)
|
||||
.SetUsage(nxt::BindGroupUsage::Frozen);
|
||||
.SetUsage(dawn::BindGroupUsage::Frozen);
|
||||
if (hasTexture) {
|
||||
const auto& textureView = textures[iTextureID];
|
||||
const auto& iSamplerID = scene.textures[iTextureID].sampler;
|
||||
|
@ -319,15 +319,15 @@ namespace {
|
|||
const auto& iSamplerID = s.first;
|
||||
const auto& iSampler = s.second;
|
||||
|
||||
nxt::SamplerDescriptor desc = utils::GetDefaultSamplerDescriptor();
|
||||
dawn::SamplerDescriptor desc = utils::GetDefaultSamplerDescriptor();
|
||||
// TODO: wrap modes
|
||||
|
||||
switch (iSampler.magFilter) {
|
||||
case gl::Nearest:
|
||||
desc.magFilter = nxt::FilterMode::Nearest;
|
||||
desc.magFilter = dawn::FilterMode::Nearest;
|
||||
break;
|
||||
case gl::Linear:
|
||||
desc.magFilter = nxt::FilterMode::Linear;
|
||||
desc.magFilter = dawn::FilterMode::Linear;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unsupported magFilter %d\n", iSampler.magFilter);
|
||||
|
@ -337,12 +337,12 @@ namespace {
|
|||
case gl::Nearest:
|
||||
case gl::NearestMipmapNearest:
|
||||
case gl::NearestMipmapLinear:
|
||||
desc.minFilter = nxt::FilterMode::Nearest;
|
||||
desc.minFilter = dawn::FilterMode::Nearest;
|
||||
break;
|
||||
case gl::Linear:
|
||||
case gl::LinearMipmapNearest:
|
||||
case gl::LinearMipmapLinear:
|
||||
desc.minFilter = nxt::FilterMode::Linear;
|
||||
desc.minFilter = dawn::FilterMode::Linear;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unsupported minFilter %d\n", iSampler.magFilter);
|
||||
|
@ -351,11 +351,11 @@ namespace {
|
|||
switch (iSampler.minFilter) {
|
||||
case gl::NearestMipmapNearest:
|
||||
case gl::LinearMipmapNearest:
|
||||
desc.mipmapFilter = nxt::FilterMode::Nearest;
|
||||
desc.mipmapFilter = dawn::FilterMode::Nearest;
|
||||
break;
|
||||
case gl::NearestMipmapLinear:
|
||||
case gl::LinearMipmapLinear:
|
||||
desc.mipmapFilter = nxt::FilterMode::Linear;
|
||||
desc.mipmapFilter = dawn::FilterMode::Linear;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -369,10 +369,10 @@ namespace {
|
|||
const auto& iTexture = t.second;
|
||||
const auto& iImage = scene.images[iTexture.source];
|
||||
|
||||
nxt::TextureFormat format = nxt::TextureFormat::R8G8B8A8Unorm;
|
||||
dawn::TextureFormat format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
switch (iTexture.format) {
|
||||
case gl::RGBA:
|
||||
format = nxt::TextureFormat::R8G8B8A8Unorm;
|
||||
format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unsupported texture format %d\n", iTexture.format);
|
||||
|
@ -380,11 +380,11 @@ namespace {
|
|||
}
|
||||
|
||||
auto oTexture = device.CreateTextureBuilder()
|
||||
.SetDimension(nxt::TextureDimension::e2D)
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(iImage.width, iImage.height, 1)
|
||||
.SetFormat(format)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(nxt::TextureUsageBit::TransferDst | nxt::TextureUsageBit::Sampled)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled)
|
||||
.GetResult();
|
||||
// TODO: release this texture
|
||||
|
||||
|
@ -426,7 +426,7 @@ namespace {
|
|||
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()
|
||||
.CopyBufferToTexture(staging, 0, rowPitch, oTexture, 0, 0, 0, iImage.width, iImage.height, 1, 0)
|
||||
.GetResult();
|
||||
|
@ -442,7 +442,7 @@ namespace {
|
|||
queue = device.CreateQueue();
|
||||
swapchain = GetSwapChain(device);
|
||||
swapchain.Configure(GetPreferredSwapChainTextureFormat(),
|
||||
nxt::TextureUsageBit::OutputAttachment, 640, 480);
|
||||
dawn::TextureUsageBit::OutputAttachment, 640, 480);
|
||||
|
||||
depthStencilView = CreateDefaultDepthStencilView(device);
|
||||
|
||||
|
@ -454,7 +454,7 @@ namespace {
|
|||
|
||||
// Drawing
|
||||
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) {
|
||||
if (iPrim.mode != gl::Triangles) {
|
||||
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]);
|
||||
cmd.SetRenderPipeline(material.pipeline);
|
||||
cmd.SetBindGroup(0, material.bindGroup0);
|
||||
cmd.SetPushConstants(nxt::ShaderStageBit::Vertex,
|
||||
cmd.SetPushConstants(dawn::ShaderStageBit::Vertex,
|
||||
0, sizeof(u_transform_block) / sizeof(uint32_t),
|
||||
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;
|
||||
if (node.matrix.size() == 16) {
|
||||
model = glm::make_mat4(node.matrix.data());
|
||||
|
@ -554,12 +554,12 @@ namespace {
|
|||
}
|
||||
|
||||
void frame() {
|
||||
nxt::Texture backbuffer;
|
||||
nxt::RenderPassDescriptor renderPass;
|
||||
dawn::Texture backbuffer;
|
||||
dawn::RenderPassDescriptor renderPass;
|
||||
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
||||
|
||||
const auto& defaultSceneNodes = scene.scenes.at(scene.defaultScene);
|
||||
nxt::CommandBufferBuilder cmd = device.CreateCommandBufferBuilder()
|
||||
dawn::CommandBufferBuilder cmd = device.CreateCommandBufferBuilder()
|
||||
.BeginRenderPass(renderPass)
|
||||
.Clone();
|
||||
for (const auto& n : defaultSceneNodes) {
|
||||
|
|
Loading…
Reference in New Issue