mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-06 13:15:59 +00:00
fix formatting
This commit is contained in:
parent
084346bd5f
commit
376f1c6a8e
@ -39,25 +39,25 @@ nxt::RenderPass renderpass;
|
|||||||
nxt::Framebuffer framebuffer;
|
nxt::Framebuffer framebuffer;
|
||||||
|
|
||||||
void initBuffers() {
|
void initBuffers() {
|
||||||
static const uint32_t indexData[6*6] = {
|
static const uint32_t indexData[6*6] = {
|
||||||
0, 1, 2,
|
0, 1, 2,
|
||||||
0, 2, 3,
|
0, 2, 3,
|
||||||
|
|
||||||
4, 5, 6,
|
4, 5, 6,
|
||||||
4, 6, 7,
|
4, 6, 7,
|
||||||
|
|
||||||
8, 9, 10,
|
8, 9, 10,
|
||||||
8, 10, 11,
|
8, 10, 11,
|
||||||
|
|
||||||
12, 13, 14,
|
12, 13, 14,
|
||||||
12, 14, 15,
|
12, 14, 15,
|
||||||
|
|
||||||
16, 17, 18,
|
16, 17, 18,
|
||||||
16, 18, 19,
|
16, 18, 19,
|
||||||
|
|
||||||
20, 21, 22,
|
20, 21, 22,
|
||||||
20, 22, 23
|
20, 22, 23
|
||||||
};
|
};
|
||||||
indexBuffer = device.CreateBufferBuilder()
|
indexBuffer = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Index)
|
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Index)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||||
@ -66,37 +66,37 @@ void initBuffers() {
|
|||||||
indexBuffer.SetSubData(0, sizeof(indexData) / sizeof(uint32_t), indexData);
|
indexBuffer.SetSubData(0, sizeof(indexData) / sizeof(uint32_t), indexData);
|
||||||
indexBuffer.FreezeUsage(nxt::BufferUsageBit::Index);
|
indexBuffer.FreezeUsage(nxt::BufferUsageBit::Index);
|
||||||
|
|
||||||
static const float vertexData[6 * 4 * 6] = {
|
static const float vertexData[6 * 4 * 6] = {
|
||||||
-1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
|
-1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
|
||||||
1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
|
1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
|
||||||
1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
||||||
-1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
-1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
||||||
|
|
||||||
-1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
|
-1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
|
||||||
-1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
|
-1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
|
||||||
1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
|
1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
|
||||||
1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
|
1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
|
||||||
|
|
||||||
-1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
|
-1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
|
||||||
-1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
|
-1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
|
||||||
1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
|
1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
|
||||||
1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
|
1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
|
||||||
|
|
||||||
-1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
|
-1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
|
||||||
1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
|
1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
|
||||||
1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
|
1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
|
||||||
-1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
|
-1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
|
||||||
|
|
||||||
1.0, -1.0, -1.0, 0.0, 1.0, 1.0,
|
1.0, -1.0, -1.0, 0.0, 1.0, 1.0,
|
||||||
1.0, 1.0, -1.0, 0.0, 1.0, 1.0,
|
1.0, 1.0, -1.0, 0.0, 1.0, 1.0,
|
||||||
1.0, 1.0, 1.0, 0.0, 1.0, 1.0,
|
1.0, 1.0, 1.0, 0.0, 1.0, 1.0,
|
||||||
1.0, -1.0, 1.0, 0.0, 1.0, 1.0,
|
1.0, -1.0, 1.0, 0.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, 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, 1.0, 1.0, 1.0
|
||||||
};
|
};
|
||||||
|
|
||||||
vertexBuffer = device.CreateBufferBuilder()
|
vertexBuffer = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
||||||
@ -107,26 +107,26 @@ void initBuffers() {
|
|||||||
reinterpret_cast<const uint32_t*>(vertexData));
|
reinterpret_cast<const uint32_t*>(vertexData));
|
||||||
vertexBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
vertexBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
||||||
|
|
||||||
static const float planeData[6 * 4] = {
|
static const float planeData[6 * 4] = {
|
||||||
-2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
|
-2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
|
||||||
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,
|
||||||
-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 = device.CreateBufferBuilder()
|
planeBuffer = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Vertex)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||||
.SetSize(sizeof(planeData))
|
.SetSize(sizeof(planeData))
|
||||||
.GetResult();
|
.GetResult();
|
||||||
planeBuffer.SetSubData(0, sizeof(planeData) / sizeof(uint32_t),
|
planeBuffer.SetSubData(0, sizeof(planeData) / sizeof(uint32_t),
|
||||||
reinterpret_cast<const uint32_t*>(planeData));
|
reinterpret_cast<const uint32_t*>(planeData));
|
||||||
planeBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
planeBuffer.FreezeUsage(nxt::BufferUsageBit::Vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
glm::mat4 view;
|
glm::mat4 view;
|
||||||
glm::mat4 proj;
|
glm::mat4 proj;
|
||||||
} cameraData;
|
} cameraData;
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
@ -136,163 +136,163 @@ void init() {
|
|||||||
|
|
||||||
initBuffers();
|
initBuffers();
|
||||||
|
|
||||||
nxt::ShaderModule vsModule = CreateShaderModule(device, nxt::ShaderStage::Vertex, R"(
|
nxt::ShaderModule vsModule = CreateShaderModule(device, nxt::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;
|
||||||
mat4 proj;
|
mat4 proj;
|
||||||
} camera;
|
} camera;
|
||||||
layout(set = 0, binding = 1) uniform modelData {
|
layout(set = 0, binding = 1) uniform modelData {
|
||||||
mat4 modelMatrix;
|
mat4 modelMatrix;
|
||||||
};
|
};
|
||||||
layout(location = 0) in vec3 pos;
|
layout(location = 0) in vec3 pos;
|
||||||
layout(location = 1) in vec3 col;
|
layout(location = 1) in vec3 col;
|
||||||
layout(location = 2) out vec3 f_col;
|
layout(location = 2) out vec3 f_col;
|
||||||
void main() {
|
void main() {
|
||||||
f_col = col;
|
f_col = col;
|
||||||
gl_Position = camera.proj * camera.view * modelMatrix * vec4(pos, 1.0);
|
gl_Position = camera.proj * camera.view * modelMatrix * vec4(pos, 1.0);
|
||||||
})"
|
})"
|
||||||
);
|
);
|
||||||
|
|
||||||
nxt::ShaderModule fsModule = CreateShaderModule(device, nxt::ShaderStage::Fragment, R"(
|
nxt::ShaderModule fsModule = CreateShaderModule(device, nxt::ShaderStage::Fragment, R"(
|
||||||
#version 450
|
#version 450
|
||||||
layout(location = 2) in vec3 f_col;
|
layout(location = 2) in vec3 f_col;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
void main() {
|
void main() {
|
||||||
fragColor = vec4(f_col, 1.0);
|
fragColor = vec4(f_col, 1.0);
|
||||||
})"
|
})"
|
||||||
);
|
);
|
||||||
|
|
||||||
nxt::ShaderModule fsReflectionModule = CreateShaderModule(device, nxt::ShaderStage::Fragment, R"(
|
nxt::ShaderModule fsReflectionModule = CreateShaderModule(device, nxt::ShaderStage::Fragment, R"(
|
||||||
#version 450
|
#version 450
|
||||||
layout(location = 2) in vec3 f_col;
|
layout(location = 2) in vec3 f_col;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
void main() {
|
void main() {
|
||||||
fragColor = vec4(mix(f_col, vec3(0.5, 0.5, 0.5), 0.5), 1.0);
|
fragColor = vec4(mix(f_col, vec3(0.5, 0.5, 0.5), 0.5), 1.0);
|
||||||
})"
|
})"
|
||||||
);
|
);
|
||||||
|
|
||||||
auto inputState = device.CreateInputStateBuilder()
|
auto inputState = device.CreateInputStateBuilder()
|
||||||
.SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32B32, 0)
|
.SetAttribute(0, 0, nxt::VertexFormat::FloatR32G32B32, 0)
|
||||||
.SetAttribute(1, 0, nxt::VertexFormat::FloatR32G32B32, 3 * sizeof(float))
|
.SetAttribute(1, 0, nxt::VertexFormat::FloatR32G32B32, 3 * sizeof(float))
|
||||||
.SetInput(0, 6 * sizeof(float), nxt::InputStepMode::Vertex)
|
.SetInput(0, 6 * sizeof(float), nxt::InputStepMode::Vertex)
|
||||||
.SetInput(1, 6 * sizeof(float), nxt::InputStepMode::Vertex)
|
.SetInput(1, 6 * sizeof(float), nxt::InputStepMode::Vertex)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
nxt::BindGroupLayout bgl = device.CreateBindGroupLayoutBuilder()
|
nxt::BindGroupLayout bgl = device.CreateBindGroupLayoutBuilder()
|
||||||
.SetBindingsType(nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer, 0, 2)
|
.SetBindingsType(nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer, 0, 2)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
nxt::PipelineLayout pl = device.CreatePipelineLayoutBuilder()
|
nxt::PipelineLayout pl = device.CreatePipelineLayoutBuilder()
|
||||||
.SetBindGroupLayout(0, bgl)
|
.SetBindGroupLayout(0, bgl)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
cameraBuffer = device.CreateBufferBuilder()
|
cameraBuffer = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||||
.SetSize(sizeof(cameraData))
|
.SetSize(sizeof(cameraData))
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
glm::mat4 transform(1.0);
|
glm::mat4 transform(1.0);
|
||||||
|
|
||||||
transformBuffer[0] = device.CreateBufferBuilder()
|
transformBuffer[0] = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||||
.SetSize(sizeof(glm::mat4))
|
.SetSize(sizeof(glm::mat4))
|
||||||
.GetResult();
|
.GetResult();
|
||||||
transformBuffer[0].SetSubData(0, sizeof(glm::mat4) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&transform));
|
transformBuffer[0].SetSubData(0, sizeof(glm::mat4) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&transform));
|
||||||
transformBuffer[0].FreezeUsage(nxt::BufferUsageBit::Uniform);
|
transformBuffer[0].FreezeUsage(nxt::BufferUsageBit::Uniform);
|
||||||
|
|
||||||
transform = glm::translate(transform, glm::vec3(0.f, -2.f, 0.f));
|
transform = glm::translate(transform, glm::vec3(0.f, -2.f, 0.f));
|
||||||
|
|
||||||
transformBuffer[1] = device.CreateBufferBuilder()
|
transformBuffer[1] = device.CreateBufferBuilder()
|
||||||
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
.SetAllowedUsage(nxt::BufferUsageBit::Mapped | nxt::BufferUsageBit::Uniform)
|
||||||
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
.SetInitialUsage(nxt::BufferUsageBit::Mapped)
|
||||||
.SetSize(sizeof(glm::mat4))
|
.SetSize(sizeof(glm::mat4))
|
||||||
.GetResult();
|
.GetResult();
|
||||||
transformBuffer[1].SetSubData(0, sizeof(glm::mat4) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&transform));
|
transformBuffer[1].SetSubData(0, sizeof(glm::mat4) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&transform));
|
||||||
transformBuffer[1].FreezeUsage(nxt::BufferUsageBit::Uniform);
|
transformBuffer[1].FreezeUsage(nxt::BufferUsageBit::Uniform);
|
||||||
|
|
||||||
nxt::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder()
|
nxt::BufferView cameraBufferView = cameraBuffer.CreateBufferViewBuilder()
|
||||||
.SetExtent(0, sizeof(cameraData))
|
.SetExtent(0, sizeof(cameraData))
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
nxt::BufferView transformBufferView[2] = {
|
nxt::BufferView transformBufferView[2] = {
|
||||||
transformBuffer[0].CreateBufferViewBuilder()
|
transformBuffer[0].CreateBufferViewBuilder()
|
||||||
.SetExtent(0, sizeof(glm::mat4))
|
.SetExtent(0, sizeof(glm::mat4))
|
||||||
.GetResult(),
|
.GetResult(),
|
||||||
transformBuffer[1].CreateBufferViewBuilder()
|
transformBuffer[1].CreateBufferViewBuilder()
|
||||||
.SetExtent(0, sizeof(glm::mat4))
|
.SetExtent(0, sizeof(glm::mat4))
|
||||||
.GetResult(),
|
.GetResult(),
|
||||||
};
|
};
|
||||||
|
|
||||||
bindGroup[0] = device.CreateBindGroupBuilder()
|
bindGroup[0] = device.CreateBindGroupBuilder()
|
||||||
.SetLayout(bgl)
|
.SetLayout(bgl)
|
||||||
.SetUsage(nxt::BindGroupUsage::Frozen)
|
.SetUsage(nxt::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(nxt::BindGroupUsage::Frozen)
|
||||||
.SetBufferViews(0, 1, &cameraBufferView)
|
.SetBufferViews(0, 1, &cameraBufferView)
|
||||||
.SetBufferViews(1, 1, &transformBufferView[1])
|
.SetBufferViews(1, 1, &transformBufferView[1])
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
CreateDefaultRenderPass(device, &renderpass, &framebuffer);
|
CreateDefaultRenderPass(device, &renderpass, &framebuffer);
|
||||||
|
|
||||||
auto depthStencilState = device.CreateDepthStencilStateBuilder()
|
auto depthStencilState = device.CreateDepthStencilStateBuilder()
|
||||||
.SetDepthEnabled(true)
|
.SetDepthEnabled(true)
|
||||||
.SetStencilEnabled(false)
|
.SetStencilEnabled(false)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
pipeline = device.CreatePipelineBuilder()
|
pipeline = device.CreatePipelineBuilder()
|
||||||
.SetSubpass(renderpass, 0)
|
.SetSubpass(renderpass, 0)
|
||||||
.SetLayout(pl)
|
.SetLayout(pl)
|
||||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||||
.SetInputState(inputState)
|
.SetInputState(inputState)
|
||||||
.SetDepthStencilState(depthStencilState)
|
.SetDepthStencilState(depthStencilState)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
auto planeStencilState = device.CreateDepthStencilStateBuilder()
|
auto planeStencilState = device.CreateDepthStencilStateBuilder()
|
||||||
.SetDepthEnabled(true)
|
.SetDepthEnabled(true)
|
||||||
.SetDepthWrite(nxt::DepthWriteMode::Disabled)
|
.SetDepthWrite(nxt::DepthWriteMode::Disabled)
|
||||||
.SetStencilEnabled(true)
|
.SetStencilEnabled(true)
|
||||||
.SetStencilCompareFunction(nxt::Face::Both, nxt::CompareFunction::Always)
|
.SetStencilCompareFunction(nxt::Face::Both, nxt::CompareFunction::Always)
|
||||||
.SetStencilOperation(nxt::Face::Both, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
|
.SetStencilOperation(nxt::Face::Both, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
|
||||||
.SetStencilMask(nxt::Face::Both, 0xff, 0xff)
|
.SetStencilMask(nxt::Face::Both, 0xff, 0xff)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
planePipeline = device.CreatePipelineBuilder()
|
planePipeline = device.CreatePipelineBuilder()
|
||||||
.SetSubpass(renderpass, 0)
|
.SetSubpass(renderpass, 0)
|
||||||
.SetLayout(pl)
|
.SetLayout(pl)
|
||||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||||
.SetInputState(inputState)
|
.SetInputState(inputState)
|
||||||
.SetDepthStencilState(planeStencilState)
|
.SetDepthStencilState(planeStencilState)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
auto reflectionStencilState = device.CreateDepthStencilStateBuilder()
|
auto reflectionStencilState = device.CreateDepthStencilStateBuilder()
|
||||||
.SetDepthEnabled(true)
|
.SetDepthEnabled(true)
|
||||||
.SetDepthWrite(nxt::DepthWriteMode::Enabled)
|
.SetDepthWrite(nxt::DepthWriteMode::Enabled)
|
||||||
.SetStencilEnabled(true)
|
.SetStencilEnabled(true)
|
||||||
.SetStencilCompareFunction(nxt::Face::Both, nxt::CompareFunction::Equal)
|
.SetStencilCompareFunction(nxt::Face::Both, nxt::CompareFunction::Equal)
|
||||||
.SetStencilOperation(nxt::Face::Both, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
|
.SetStencilOperation(nxt::Face::Both, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
|
||||||
.SetStencilMask(nxt::Face::Both, 0xff, 0x00)
|
.SetStencilMask(nxt::Face::Both, 0xff, 0x00)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
reflectionPipeline = device.CreatePipelineBuilder()
|
reflectionPipeline = device.CreatePipelineBuilder()
|
||||||
.SetSubpass(renderpass, 0)
|
.SetSubpass(renderpass, 0)
|
||||||
.SetLayout(pl)
|
.SetLayout(pl)
|
||||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||||
.SetStage(nxt::ShaderStage::Fragment, fsReflectionModule, "main")
|
.SetStage(nxt::ShaderStage::Fragment, fsReflectionModule, "main")
|
||||||
.SetInputState(inputState)
|
.SetInputState(inputState)
|
||||||
.SetDepthStencilState(reflectionStencilState)
|
.SetDepthStencilState(reflectionStencilState)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
cameraData.proj = glm::perspective(glm::radians(45.0f), 1.f, 1.0f, 100.0f);
|
cameraData.proj = glm::perspective(glm::radians(45.0f), 1.f, 1.0f, 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct {uint32_t a; float b;} s;
|
struct {uint32_t a; float b;} s;
|
||||||
@ -302,34 +302,34 @@ void frame() {
|
|||||||
if (s.b >= 1.0f) {s.b = 0.0f;}
|
if (s.b >= 1.0f) {s.b = 0.0f;}
|
||||||
static const uint32_t vertexBufferOffsets[1] = {0};
|
static const uint32_t vertexBufferOffsets[1] = {0};
|
||||||
|
|
||||||
cameraData.view = glm::lookAt(
|
cameraData.view = glm::lookAt(
|
||||||
glm::vec3(8.f * std::sin(glm::radians(s.b * 360.f)), 2.f, 8.f * std::cos(glm::radians(s.b * 360.f))),
|
glm::vec3(8.f * std::sin(glm::radians(s.b * 360.f)), 2.f, 8.f * std::cos(glm::radians(s.b * 360.f))),
|
||||||
glm::vec3(0.0f, 0.0f, 0.0f),
|
glm::vec3(0.0f, 0.0f, 0.0f),
|
||||||
glm::vec3(0.0f, 1.0f, 0.0f)
|
glm::vec3(0.0f, 1.0f, 0.0f)
|
||||||
);
|
);
|
||||||
|
|
||||||
cameraBuffer.TransitionUsage(nxt::BufferUsageBit::Mapped);
|
cameraBuffer.TransitionUsage(nxt::BufferUsageBit::Mapped);
|
||||||
cameraBuffer.SetSubData(0, sizeof(cameraData) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&cameraData));
|
cameraBuffer.SetSubData(0, sizeof(cameraData) / sizeof(uint32_t), reinterpret_cast<uint32_t*>(&cameraData));
|
||||||
|
|
||||||
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
||||||
.BeginRenderPass(renderpass, framebuffer)
|
.BeginRenderPass(renderpass, framebuffer)
|
||||||
.SetPipeline(pipeline)
|
.SetPipeline(pipeline)
|
||||||
.TransitionBufferUsage(cameraBuffer, nxt::BufferUsageBit::Uniform)
|
.TransitionBufferUsage(cameraBuffer, nxt::BufferUsageBit::Uniform)
|
||||||
.SetBindGroup(0, bindGroup[0])
|
.SetBindGroup(0, bindGroup[0])
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
|
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
|
||||||
.SetIndexBuffer(indexBuffer, 0, nxt::IndexFormat::Uint32)
|
.SetIndexBuffer(indexBuffer, 0, nxt::IndexFormat::Uint32)
|
||||||
.DrawElements(36, 1, 0, 0)
|
.DrawElements(36, 1, 0, 0)
|
||||||
|
|
||||||
.SetPipeline(planePipeline)
|
.SetPipeline(planePipeline)
|
||||||
.SetStencilReference(0x1, 0x1)
|
.SetStencilReference(0x1, 0x1)
|
||||||
.SetVertexBuffers(0, 1, &planeBuffer, vertexBufferOffsets)
|
.SetVertexBuffers(0, 1, &planeBuffer, vertexBufferOffsets)
|
||||||
.DrawElements(6, 1, 0, 0)
|
.DrawElements(6, 1, 0, 0)
|
||||||
|
|
||||||
.SetPipeline(reflectionPipeline)
|
.SetPipeline(reflectionPipeline)
|
||||||
.SetStencilReference(0x1, 0x1)
|
.SetStencilReference(0x1, 0x1)
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
|
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
|
||||||
.SetBindGroup(0, bindGroup[1])
|
.SetBindGroup(0, bindGroup[1])
|
||||||
.DrawElements(36, 1, 0, 0)
|
.DrawElements(36, 1, 0, 0)
|
||||||
.EndRenderPass()
|
.EndRenderPass()
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
@ -344,7 +344,7 @@ int main(int argc, const char* argv[]) {
|
|||||||
init();
|
init();
|
||||||
|
|
||||||
while (!ShouldQuit()) {
|
while (!ShouldQuit()) {
|
||||||
frame();
|
frame();
|
||||||
USleep(16000);
|
USleep(16000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,12 +110,12 @@ namespace backend {
|
|||||||
cmd->~SetPushConstantsCmd();
|
cmd->~SetPushConstantsCmd();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Command::SetStencilReference:
|
case Command::SetStencilReference:
|
||||||
{
|
{
|
||||||
SetStencilReferenceCmd* cmd = commands->NextCommand<SetStencilReferenceCmd>();
|
SetStencilReferenceCmd* cmd = commands->NextCommand<SetStencilReferenceCmd>();
|
||||||
cmd->~SetStencilReferenceCmd();
|
cmd->~SetStencilReferenceCmd();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Command::SetBindGroup:
|
case Command::SetBindGroup:
|
||||||
{
|
{
|
||||||
SetBindGroupCmd* cmd = commands->NextCommand<SetBindGroupCmd>();
|
SetBindGroupCmd* cmd = commands->NextCommand<SetBindGroupCmd>();
|
||||||
@ -571,9 +571,9 @@ namespace backend {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::SetStencilReference:
|
case Command::SetStencilReference:
|
||||||
{
|
{
|
||||||
SetStencilReferenceCmd* cmd = iterator.NextCommand<SetStencilReferenceCmd>();
|
SetStencilReferenceCmd* cmd = iterator.NextCommand<SetStencilReferenceCmd>();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::SetBindGroup:
|
case Command::SetBindGroup:
|
||||||
|
@ -21,33 +21,33 @@ namespace backend {
|
|||||||
// DepthStencilStateBase
|
// DepthStencilStateBase
|
||||||
|
|
||||||
DepthStencilStateBase::DepthStencilStateBase(DepthStencilStateBuilder* builder)
|
DepthStencilStateBase::DepthStencilStateBase(DepthStencilStateBuilder* builder)
|
||||||
: depthEnabled(builder->depthEnabled), stencilEnabled(builder->stencilEnabled),
|
: depthEnabled(builder->depthEnabled), stencilEnabled(builder->stencilEnabled),
|
||||||
depthInfo(builder->depthInfo),
|
depthInfo(builder->depthInfo),
|
||||||
stencilInfos { builder->stencilInfos[0], builder->stencilInfos[1] } {
|
stencilInfos { builder->stencilInfos[0], builder->stencilInfos[1] } {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DepthStencilStateBase::DepthIsEnabled() const {
|
bool DepthStencilStateBase::DepthIsEnabled() const {
|
||||||
return depthEnabled;
|
return depthEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DepthStencilStateBase::StencilIsEnabled() const {
|
bool DepthStencilStateBase::StencilIsEnabled() const {
|
||||||
return stencilEnabled;
|
return stencilEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DepthStencilStateBase::DepthInfo& DepthStencilStateBase::GetDepth() const {
|
const DepthStencilStateBase::DepthInfo& DepthStencilStateBase::GetDepth() const {
|
||||||
return depthInfo;
|
return depthInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetStencil(nxt::Face face) const {
|
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetStencil(nxt::Face face) const {
|
||||||
switch (face) {
|
switch (face) {
|
||||||
case nxt::Face::Back:
|
case nxt::Face::Back:
|
||||||
return stencilInfos[0];
|
return stencilInfos[0];
|
||||||
case nxt::Face::Front:
|
case nxt::Face::Front:
|
||||||
return stencilInfos[1];
|
return stencilInfos[1];
|
||||||
default:
|
default:
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// DepthStencilStateBuilder
|
// DepthStencilStateBuilder
|
||||||
@ -59,9 +59,9 @@ namespace backend {
|
|||||||
return device->CreateDepthStencilState(this);
|
return device->CreateDepthStencilState(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthStencilStateBuilder::SetDepthEnabled(bool depthEnabled) {
|
void DepthStencilStateBuilder::SetDepthEnabled(bool depthEnabled) {
|
||||||
this->depthEnabled = depthEnabled;
|
this->depthEnabled = depthEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthStencilStateBuilder::SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction) {
|
void DepthStencilStateBuilder::SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction) {
|
||||||
depthInfo.compareFunction = depthCompareFunction;
|
depthInfo.compareFunction = depthCompareFunction;
|
||||||
@ -71,48 +71,48 @@ namespace backend {
|
|||||||
depthInfo.depthWriteMode = depthWriteMode;
|
depthInfo.depthWriteMode = depthWriteMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthStencilStateBuilder::SetStencilEnabled(bool stencilEnabled) {
|
void DepthStencilStateBuilder::SetStencilEnabled(bool stencilEnabled) {
|
||||||
this->stencilEnabled = stencilEnabled;
|
this->stencilEnabled = stencilEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthStencilStateBuilder::SetStencilOperation(nxt::Face face, nxt::StencilOperation stencilFail,
|
void DepthStencilStateBuilder::SetStencilOperation(nxt::Face face, nxt::StencilOperation stencilFail,
|
||||||
nxt::StencilOperation depthFail, nxt::StencilOperation stencilPass) {
|
nxt::StencilOperation depthFail, nxt::StencilOperation stencilPass) {
|
||||||
if (face & nxt::Face::Back) {
|
if (face & nxt::Face::Back) {
|
||||||
auto& stencilInfo = stencilInfos[0];
|
auto& stencilInfo = stencilInfos[0];
|
||||||
stencilInfo.stencilFail = stencilFail;
|
stencilInfo.stencilFail = stencilFail;
|
||||||
stencilInfo.depthFail = stencilFail;
|
stencilInfo.depthFail = stencilFail;
|
||||||
stencilInfo.stencilPass = stencilPass;
|
stencilInfo.stencilPass = stencilPass;
|
||||||
}
|
}
|
||||||
if (face & nxt::Face::Front) {
|
if (face & nxt::Face::Front) {
|
||||||
auto& stencilInfo = stencilInfos[1];
|
auto& stencilInfo = stencilInfos[1];
|
||||||
stencilInfo.stencilFail = stencilFail;
|
stencilInfo.stencilFail = stencilFail;
|
||||||
stencilInfo.depthFail = stencilFail;
|
stencilInfo.depthFail = stencilFail;
|
||||||
stencilInfo.stencilPass = stencilPass;
|
stencilInfo.stencilPass = stencilPass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthStencilStateBuilder::SetStencilCompareFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction) {
|
void DepthStencilStateBuilder::SetStencilCompareFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction) {
|
||||||
if (face & nxt::Face::Back) {
|
if (face & nxt::Face::Back) {
|
||||||
auto& stencilInfo = stencilInfos[0];
|
auto& stencilInfo = stencilInfos[0];
|
||||||
stencilInfo.compareFunction = stencilCompareFunction;
|
stencilInfo.compareFunction = stencilCompareFunction;
|
||||||
}
|
}
|
||||||
if (face & nxt::Face::Front) {
|
if (face & nxt::Face::Front) {
|
||||||
auto& stencilInfo = stencilInfos[1];
|
auto& stencilInfo = stencilInfos[1];
|
||||||
stencilInfo.compareFunction = stencilCompareFunction;
|
stencilInfo.compareFunction = stencilCompareFunction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthStencilStateBuilder::SetStencilMask(nxt::Face face, uint32_t readMask, uint32_t writeMask) {
|
void DepthStencilStateBuilder::SetStencilMask(nxt::Face face, uint32_t readMask, uint32_t writeMask) {
|
||||||
if (face & nxt::Face::Back) {
|
if (face & nxt::Face::Back) {
|
||||||
auto& stencilInfo = stencilInfos[0];
|
auto& stencilInfo = stencilInfos[0];
|
||||||
stencilInfo.readMask = readMask;
|
stencilInfo.readMask = readMask;
|
||||||
stencilInfo.writeMask = writeMask;
|
stencilInfo.writeMask = writeMask;
|
||||||
}
|
}
|
||||||
if (face & nxt::Face::Front) {
|
if (face & nxt::Face::Front) {
|
||||||
auto& stencilInfo = stencilInfos[1];
|
auto& stencilInfo = stencilInfos[1];
|
||||||
stencilInfo.readMask = readMask;
|
stencilInfo.readMask = readMask;
|
||||||
stencilInfo.writeMask = writeMask;
|
stencilInfo.writeMask = writeMask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,21 +35,21 @@ namespace backend {
|
|||||||
|
|
||||||
struct StencilInfo {
|
struct StencilInfo {
|
||||||
nxt::CompareFunction compareFunction = nxt::CompareFunction::Always;
|
nxt::CompareFunction compareFunction = nxt::CompareFunction::Always;
|
||||||
nxt::StencilOperation stencilFail = nxt::StencilOperation::Keep;
|
nxt::StencilOperation stencilFail = nxt::StencilOperation::Keep;
|
||||||
nxt::StencilOperation depthFail = nxt::StencilOperation::Keep;
|
nxt::StencilOperation depthFail = nxt::StencilOperation::Keep;
|
||||||
nxt::StencilOperation stencilPass = nxt::StencilOperation::Keep;
|
nxt::StencilOperation stencilPass = nxt::StencilOperation::Keep;
|
||||||
uint32_t readMask = 0xff;
|
uint32_t readMask = 0xff;
|
||||||
uint32_t writeMask = 0xff;
|
uint32_t writeMask = 0xff;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool DepthIsEnabled() const;
|
bool DepthIsEnabled() const;
|
||||||
bool StencilIsEnabled() const;
|
bool StencilIsEnabled() const;
|
||||||
const DepthInfo& GetDepth() const;
|
const DepthInfo& GetDepth() const;
|
||||||
const StencilInfo& GetStencil(nxt::Face face) const;
|
const StencilInfo& GetStencil(nxt::Face face) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool depthEnabled = false;
|
bool depthEnabled = false;
|
||||||
bool stencilEnabled = false;
|
bool stencilEnabled = false;
|
||||||
DepthInfo depthInfo;
|
DepthInfo depthInfo;
|
||||||
StencilInfo stencilInfos[2];
|
StencilInfo stencilInfos[2];
|
||||||
};
|
};
|
||||||
@ -59,10 +59,10 @@ namespace backend {
|
|||||||
DepthStencilStateBuilder(DeviceBase* device);
|
DepthStencilStateBuilder(DeviceBase* device);
|
||||||
|
|
||||||
// NXT API
|
// NXT API
|
||||||
void SetDepthEnabled(bool depthEnabled);
|
void SetDepthEnabled(bool depthEnabled);
|
||||||
void SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction);
|
void SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction);
|
||||||
void SetDepthWrite(nxt::DepthWriteMode depthWriteMode);
|
void SetDepthWrite(nxt::DepthWriteMode depthWriteMode);
|
||||||
void SetStencilEnabled(bool stencilEnabled);
|
void SetStencilEnabled(bool stencilEnabled);
|
||||||
void SetStencilOperation(nxt::Face face, nxt::StencilOperation stencilFail,
|
void SetStencilOperation(nxt::Face face, nxt::StencilOperation stencilFail,
|
||||||
nxt::StencilOperation depthFail, nxt::StencilOperation stencilPass);
|
nxt::StencilOperation depthFail, nxt::StencilOperation stencilPass);
|
||||||
void SetStencilCompareFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction);
|
void SetStencilCompareFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction);
|
||||||
@ -73,8 +73,8 @@ namespace backend {
|
|||||||
|
|
||||||
DepthStencilStateBase* GetResultImpl() override;
|
DepthStencilStateBase* GetResultImpl() override;
|
||||||
|
|
||||||
bool depthEnabled;
|
bool depthEnabled;
|
||||||
bool stencilEnabled;
|
bool stencilEnabled;
|
||||||
DepthStencilStateBase::DepthInfo depthInfo;
|
DepthStencilStateBase::DepthInfo depthInfo;
|
||||||
DepthStencilStateBase::StencilInfo stencilInfos[2];
|
DepthStencilStateBase::StencilInfo stencilInfos[2];
|
||||||
};
|
};
|
||||||
|
@ -96,9 +96,9 @@ namespace backend {
|
|||||||
return inputState.Get();
|
return inputState.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
DepthStencilStateBase* PipelineBase::GetDepthStencilState() {
|
DepthStencilStateBase* PipelineBase::GetDepthStencilState() {
|
||||||
return depthStencilState.Get();
|
return depthStencilState.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PipelineBase::IsCompute() const {
|
bool PipelineBase::IsCompute() const {
|
||||||
return stageMask == nxt::ShaderStageBit::Compute;
|
return stageMask == nxt::ShaderStageBit::Compute;
|
||||||
@ -123,9 +123,9 @@ namespace backend {
|
|||||||
if (!inputState) {
|
if (!inputState) {
|
||||||
inputState = device->CreateInputStateBuilder()->GetResult();
|
inputState = device->CreateInputStateBuilder()->GetResult();
|
||||||
}
|
}
|
||||||
if (!depthStencilState) {
|
if (!depthStencilState) {
|
||||||
depthStencilState = device->CreateDepthStencilStateBuilder()->GetResult();
|
depthStencilState = device->CreateDepthStencilStateBuilder()->GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
return device->CreatePipeline(this);
|
return device->CreatePipeline(this);
|
||||||
}
|
}
|
||||||
@ -165,9 +165,9 @@ namespace backend {
|
|||||||
this->inputState = inputState;
|
this->inputState = inputState;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineBuilder::SetDepthStencilState(DepthStencilStateBase* depthStencilState) {
|
void PipelineBuilder::SetDepthStencilState(DepthStencilStateBase* depthStencilState) {
|
||||||
this->depthStencilState = depthStencilState;
|
this->depthStencilState = depthStencilState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace backend {
|
|||||||
PipelineLayoutBase* GetLayout();
|
PipelineLayoutBase* GetLayout();
|
||||||
RenderPassBase* GetRenderPass();
|
RenderPassBase* GetRenderPass();
|
||||||
InputStateBase* GetInputState();
|
InputStateBase* GetInputState();
|
||||||
DepthStencilStateBase* GetDepthStencilState();
|
DepthStencilStateBase* GetDepthStencilState();
|
||||||
|
|
||||||
// TODO(cwallez@chromium.org): split compute and render pipelines
|
// TODO(cwallez@chromium.org): split compute and render pipelines
|
||||||
bool IsCompute() const;
|
bool IsCompute() const;
|
||||||
@ -61,7 +61,7 @@ namespace backend {
|
|||||||
uint32_t subpass;
|
uint32_t subpass;
|
||||||
PerStage<PushConstantInfo> pushConstants;
|
PerStage<PushConstantInfo> pushConstants;
|
||||||
Ref<InputStateBase> inputState;
|
Ref<InputStateBase> inputState;
|
||||||
Ref<DepthStencilStateBase> depthStencilState;
|
Ref<DepthStencilStateBase> depthStencilState;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PipelineBuilder : public Builder<PipelineBase> {
|
class PipelineBuilder : public Builder<PipelineBase> {
|
||||||
@ -79,7 +79,7 @@ namespace backend {
|
|||||||
void SetSubpass(RenderPassBase* renderPass, uint32_t subpass);
|
void SetSubpass(RenderPassBase* renderPass, uint32_t subpass);
|
||||||
void SetStage(nxt::ShaderStage stage, ShaderModuleBase* module, const char* entryPoint);
|
void SetStage(nxt::ShaderStage stage, ShaderModuleBase* module, const char* entryPoint);
|
||||||
void SetInputState(InputStateBase* inputState);
|
void SetInputState(InputStateBase* inputState);
|
||||||
void SetDepthStencilState(DepthStencilStateBase* depthStencilState);
|
void SetDepthStencilState(DepthStencilStateBase* depthStencilState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class PipelineBase;
|
friend class PipelineBase;
|
||||||
@ -92,7 +92,7 @@ namespace backend {
|
|||||||
nxt::ShaderStageBit stageMask;
|
nxt::ShaderStageBit stageMask;
|
||||||
PerStage<StageInfo> stages;
|
PerStage<StageInfo> stages;
|
||||||
Ref<InputStateBase> inputState;
|
Ref<InputStateBase> inputState;
|
||||||
Ref<DepthStencilStateBase> depthStencilState;
|
Ref<DepthStencilStateBase> depthStencilState;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -667,48 +667,48 @@ namespace metal {
|
|||||||
|
|
||||||
static MTLCompareFunction DepthStencilCompareFunction(nxt::CompareFunction compareFunction) {
|
static MTLCompareFunction DepthStencilCompareFunction(nxt::CompareFunction compareFunction) {
|
||||||
switch (compareFunction) {
|
switch (compareFunction) {
|
||||||
case nxt::CompareFunction::Never:
|
case nxt::CompareFunction::Never:
|
||||||
return MTLCompareFunctionNever;
|
return MTLCompareFunctionNever;
|
||||||
case nxt::CompareFunction::Less:
|
case nxt::CompareFunction::Less:
|
||||||
return MTLCompareFunctionLess;
|
return MTLCompareFunctionLess;
|
||||||
case nxt::CompareFunction::LessEqual:
|
case nxt::CompareFunction::LessEqual:
|
||||||
return MTLCompareFunctionLessEqual;
|
return MTLCompareFunctionLessEqual;
|
||||||
case nxt::CompareFunction::Greater:
|
case nxt::CompareFunction::Greater:
|
||||||
return MTLCompareFunctionGreater;
|
return MTLCompareFunctionGreater;
|
||||||
case nxt::CompareFunction::GreaterEqual:
|
case nxt::CompareFunction::GreaterEqual:
|
||||||
return MTLCompareFunctionGreaterEqual;
|
return MTLCompareFunctionGreaterEqual;
|
||||||
case nxt::CompareFunction::NotEqual:
|
case nxt::CompareFunction::NotEqual:
|
||||||
return MTLCompareFunctionNotEqual;
|
return MTLCompareFunctionNotEqual;
|
||||||
case nxt::CompareFunction::Equal:
|
case nxt::CompareFunction::Equal:
|
||||||
return MTLCompareFunctionEqual;
|
return MTLCompareFunctionEqual;
|
||||||
case nxt::CompareFunction::Always:
|
case nxt::CompareFunction::Always:
|
||||||
return MTLCompareFunctionAlways;
|
return MTLCompareFunctionAlways;
|
||||||
default:
|
default:
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static MTLStencilOperation StencilOperation(nxt::StencilOperation stencilOperation) {
|
static MTLStencilOperation StencilOperation(nxt::StencilOperation stencilOperation) {
|
||||||
switch (stencilOperation) {
|
switch (stencilOperation) {
|
||||||
case nxt::StencilOperation::Keep:
|
case nxt::StencilOperation::Keep:
|
||||||
return MTLStencilOperationKeep;
|
return MTLStencilOperationKeep;
|
||||||
case nxt::StencilOperation::Zero:
|
case nxt::StencilOperation::Zero:
|
||||||
return MTLStencilOperationZero;
|
return MTLStencilOperationZero;
|
||||||
case nxt::StencilOperation::Replace:
|
case nxt::StencilOperation::Replace:
|
||||||
return MTLStencilOperationReplace;
|
return MTLStencilOperationReplace;
|
||||||
case nxt::StencilOperation::Invert:
|
case nxt::StencilOperation::Invert:
|
||||||
return MTLStencilOperationInvert;
|
return MTLStencilOperationInvert;
|
||||||
case nxt::StencilOperation::IncrementClamp:
|
case nxt::StencilOperation::IncrementClamp:
|
||||||
return MTLStencilOperationIncrementClamp;
|
return MTLStencilOperationIncrementClamp;
|
||||||
case nxt::StencilOperation::DecrementClamp:
|
case nxt::StencilOperation::DecrementClamp:
|
||||||
return MTLStencilOperationDecrementClamp;
|
return MTLStencilOperationDecrementClamp;
|
||||||
case nxt::StencilOperation::IncrementWrap:
|
case nxt::StencilOperation::IncrementWrap:
|
||||||
return MTLStencilOperationIncrementWrap;
|
return MTLStencilOperationIncrementWrap;
|
||||||
case nxt::StencilOperation::DecrementWrap:
|
case nxt::StencilOperation::DecrementWrap:
|
||||||
return MTLStencilOperationDecrementWrap;
|
return MTLStencilOperationDecrementWrap;
|
||||||
default:
|
default:
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
||||||
@ -728,7 +728,7 @@ namespace metal {
|
|||||||
default:
|
default:
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StencilIsEnabled()) {
|
if (StencilIsEnabled()) {
|
||||||
|
@ -50,9 +50,9 @@ namespace null {
|
|||||||
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
|
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
|
||||||
return new CommandBufferBase(builder);
|
return new CommandBufferBase(builder);
|
||||||
}
|
}
|
||||||
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
|
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
|
||||||
return new DepthStencilStateBase(builder);
|
return new DepthStencilStateBase(builder);
|
||||||
}
|
}
|
||||||
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
|
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
|
||||||
return new InputStateBase(builder);
|
return new InputStateBase(builder);
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ namespace null {
|
|||||||
class Buffer;
|
class Buffer;
|
||||||
using BufferView = BufferViewBase;
|
using BufferView = BufferViewBase;
|
||||||
using CommandBuffer = CommandBufferBase;
|
using CommandBuffer = CommandBufferBase;
|
||||||
using DepthStencilState = DepthStencilStateBase;
|
using DepthStencilState = DepthStencilStateBase;
|
||||||
using InputState = InputStateBase;
|
using InputState = InputStateBase;
|
||||||
using Framebuffer = FramebufferBase;
|
using Framebuffer = FramebufferBase;
|
||||||
using Pipeline = PipelineBase;
|
using Pipeline = PipelineBase;
|
||||||
@ -60,7 +60,7 @@ namespace null {
|
|||||||
using BufferType = Buffer;
|
using BufferType = Buffer;
|
||||||
using BufferViewType = BufferView;
|
using BufferViewType = BufferView;
|
||||||
using CommandBufferType = CommandBuffer;
|
using CommandBufferType = CommandBuffer;
|
||||||
using DepthStencilStateType = DepthStencilState;
|
using DepthStencilStateType = DepthStencilState;
|
||||||
using InputStateType = InputState;
|
using InputStateType = InputState;
|
||||||
using FramebufferType = Framebuffer;
|
using FramebufferType = Framebuffer;
|
||||||
using PipelineType = Pipeline;
|
using PipelineType = Pipeline;
|
||||||
@ -88,7 +88,7 @@ namespace null {
|
|||||||
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
||||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||||
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
|
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
|
||||||
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
|
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
|
||||||
FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override;
|
FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override;
|
||||||
PipelineBase* CreatePipeline(PipelineBuilder* builder) override;
|
PipelineBase* CreatePipeline(PipelineBuilder* builder) override;
|
||||||
|
@ -184,7 +184,7 @@ namespace opengl {
|
|||||||
DepthStencilState* depthStencilState = ToBackend(lastPipeline->GetDepthStencilState());
|
DepthStencilState* depthStencilState = ToBackend(lastPipeline->GetDepthStencilState());
|
||||||
depthStencilState->ApplyStencilReferenceNow(cmd->backReference, cmd->frontReference);
|
depthStencilState->ApplyStencilReferenceNow(cmd->backReference, cmd->frontReference);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::SetBindGroup:
|
case Command::SetBindGroup:
|
||||||
{
|
{
|
||||||
|
@ -28,8 +28,8 @@ namespace opengl {
|
|||||||
|
|
||||||
void HACKCLEAR() {
|
void HACKCLEAR() {
|
||||||
glClearColor(0, 0, 0, 1);
|
glClearColor(0, 0, 0, 1);
|
||||||
glStencilMask(0xff);
|
glStencilMask(0xff);
|
||||||
glClearStencil(0);
|
glClearStencil(0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,51 +45,51 @@ namespace opengl {
|
|||||||
*device = reinterpret_cast<nxtDevice>(new Device);
|
*device = reinterpret_cast<nxtDevice>(new Device);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLuint OpenGLCompareFunction(nxt::CompareFunction compareFunction) {
|
static GLuint OpenGLCompareFunction(nxt::CompareFunction compareFunction) {
|
||||||
switch (compareFunction) {
|
switch (compareFunction) {
|
||||||
case nxt::CompareFunction::Never:
|
case nxt::CompareFunction::Never:
|
||||||
return GL_NEVER;
|
return GL_NEVER;
|
||||||
case nxt::CompareFunction::Less:
|
case nxt::CompareFunction::Less:
|
||||||
return GL_LESS;
|
return GL_LESS;
|
||||||
case nxt::CompareFunction::LessEqual:
|
case nxt::CompareFunction::LessEqual:
|
||||||
return GL_LEQUAL;
|
return GL_LEQUAL;
|
||||||
case nxt::CompareFunction::Greater:
|
case nxt::CompareFunction::Greater:
|
||||||
return GL_GREATER;
|
return GL_GREATER;
|
||||||
case nxt::CompareFunction::GreaterEqual:
|
case nxt::CompareFunction::GreaterEqual:
|
||||||
return GL_GEQUAL;
|
return GL_GEQUAL;
|
||||||
case nxt::CompareFunction::NotEqual:
|
case nxt::CompareFunction::NotEqual:
|
||||||
return GL_NOTEQUAL;
|
return GL_NOTEQUAL;
|
||||||
case nxt::CompareFunction::Equal:
|
case nxt::CompareFunction::Equal:
|
||||||
return GL_EQUAL;
|
return GL_EQUAL;
|
||||||
case nxt::CompareFunction::Always:
|
case nxt::CompareFunction::Always:
|
||||||
return GL_ALWAYS;
|
return GL_ALWAYS;
|
||||||
default:
|
default:
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLuint OpenGLStencilOperation(nxt::StencilOperation stencilOperation) {
|
static GLuint OpenGLStencilOperation(nxt::StencilOperation stencilOperation) {
|
||||||
switch (stencilOperation) {
|
switch (stencilOperation) {
|
||||||
case nxt::StencilOperation::Keep:
|
case nxt::StencilOperation::Keep:
|
||||||
return GL_KEEP;
|
return GL_KEEP;
|
||||||
case nxt::StencilOperation::Zero:
|
case nxt::StencilOperation::Zero:
|
||||||
return GL_ZERO;
|
return GL_ZERO;
|
||||||
case nxt::StencilOperation::Replace:
|
case nxt::StencilOperation::Replace:
|
||||||
return GL_REPLACE;
|
return GL_REPLACE;
|
||||||
case nxt::StencilOperation::Invert:
|
case nxt::StencilOperation::Invert:
|
||||||
return GL_INVERT;
|
return GL_INVERT;
|
||||||
case nxt::StencilOperation::IncrementClamp:
|
case nxt::StencilOperation::IncrementClamp:
|
||||||
return GL_INCR;
|
return GL_INCR;
|
||||||
case nxt::StencilOperation::DecrementClamp:
|
case nxt::StencilOperation::DecrementClamp:
|
||||||
return GL_DECR;
|
return GL_DECR;
|
||||||
case nxt::StencilOperation::IncrementWrap:
|
case nxt::StencilOperation::IncrementWrap:
|
||||||
return GL_INCR_WRAP;
|
return GL_INCR_WRAP;
|
||||||
case nxt::StencilOperation::DecrementWrap:
|
case nxt::StencilOperation::DecrementWrap:
|
||||||
return GL_DECR_WRAP;
|
return GL_DECR_WRAP;
|
||||||
default:
|
default:
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Device
|
// Device
|
||||||
|
|
||||||
@ -108,9 +108,9 @@ namespace opengl {
|
|||||||
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
|
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
|
||||||
return new CommandBuffer(this, builder);
|
return new CommandBuffer(this, builder);
|
||||||
}
|
}
|
||||||
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
|
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
|
||||||
return new DepthStencilState(this, builder);
|
return new DepthStencilState(this, builder);
|
||||||
}
|
}
|
||||||
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
|
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
|
||||||
return new InputState(this, builder);
|
return new InputState(this, builder);
|
||||||
}
|
}
|
||||||
@ -186,17 +186,17 @@ namespace opengl {
|
|||||||
|
|
||||||
// DepthStencilState
|
// DepthStencilState
|
||||||
|
|
||||||
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
||||||
: DepthStencilStateBase(builder), device(device) {
|
: DepthStencilStateBase(builder), device(device) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthStencilState::ApplyNow() {
|
void DepthStencilState::ApplyNow() {
|
||||||
if (DepthIsEnabled()) {
|
if (DepthIsEnabled()) {
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
auto& depth = GetDepth();
|
auto& depth = GetDepth();
|
||||||
glDepthFunc(OpenGLCompareFunction(depth.compareFunction));
|
glDepthFunc(OpenGLCompareFunction(depth.compareFunction));
|
||||||
switch (depth.depthWriteMode) {
|
switch (depth.depthWriteMode) {
|
||||||
case nxt::DepthWriteMode::Disabled:
|
case nxt::DepthWriteMode::Disabled:
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
break;
|
break;
|
||||||
@ -206,14 +206,14 @@ namespace opengl {
|
|||||||
default:
|
default:
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StencilIsEnabled()) {
|
if (StencilIsEnabled()) {
|
||||||
glEnable(GL_STENCIL_TEST);
|
glEnable(GL_STENCIL_TEST);
|
||||||
auto& back = GetStencil(nxt::Face::Back);
|
auto& back = GetStencil(nxt::Face::Back);
|
||||||
auto& front = GetStencil(nxt::Face::Front);
|
auto& front = GetStencil(nxt::Face::Front);
|
||||||
|
|
||||||
@ -228,13 +228,13 @@ namespace opengl {
|
|||||||
OpenGLStencilOperation(front.stencilPass)
|
OpenGLStencilOperation(front.stencilPass)
|
||||||
);
|
);
|
||||||
|
|
||||||
glStencilMaskSeparate(GL_BACK, back.writeMask);
|
glStencilMaskSeparate(GL_BACK, back.writeMask);
|
||||||
glStencilMaskSeparate(GL_FRONT, front.writeMask);
|
glStencilMaskSeparate(GL_FRONT, front.writeMask);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthStencilState::ApplyStencilReferenceNow(uint32_t backReference, uint32_t frontReference) {
|
void DepthStencilState::ApplyStencilReferenceNow(uint32_t backReference, uint32_t frontReference) {
|
||||||
if (StencilIsEnabled()) {
|
if (StencilIsEnabled()) {
|
||||||
|
@ -38,7 +38,7 @@ namespace opengl {
|
|||||||
class Buffer;
|
class Buffer;
|
||||||
class BufferView;
|
class BufferView;
|
||||||
class CommandBuffer;
|
class CommandBuffer;
|
||||||
class DepthStencilState;
|
class DepthStencilState;
|
||||||
class InputState;
|
class InputState;
|
||||||
class Pipeline;
|
class Pipeline;
|
||||||
class PipelineLayout;
|
class PipelineLayout;
|
||||||
@ -56,7 +56,7 @@ namespace opengl {
|
|||||||
using BufferType = Buffer;
|
using BufferType = Buffer;
|
||||||
using BufferViewType = BufferView;
|
using BufferViewType = BufferView;
|
||||||
using CommandBufferType = CommandBuffer;
|
using CommandBufferType = CommandBuffer;
|
||||||
using DepthStencilStateType = DepthStencilState;
|
using DepthStencilStateType = DepthStencilState;
|
||||||
using InputStateType = InputState;
|
using InputStateType = InputState;
|
||||||
using PipelineType = Pipeline;
|
using PipelineType = Pipeline;
|
||||||
using PipelineLayoutType = PipelineLayout;
|
using PipelineLayoutType = PipelineLayout;
|
||||||
@ -82,7 +82,7 @@ namespace opengl {
|
|||||||
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
||||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||||
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
|
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
|
||||||
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
|
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
|
||||||
FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override;
|
FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override;
|
||||||
PipelineBase* CreatePipeline(PipelineBuilder* builder) override;
|
PipelineBase* CreatePipeline(PipelineBuilder* builder) override;
|
||||||
@ -136,15 +136,15 @@ namespace opengl {
|
|||||||
Device* device;
|
Device* device;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DepthStencilState : public DepthStencilStateBase {
|
class DepthStencilState : public DepthStencilStateBase {
|
||||||
public:
|
public:
|
||||||
DepthStencilState(Device* device, DepthStencilStateBuilder* builder);
|
DepthStencilState(Device* device, DepthStencilStateBuilder* builder);
|
||||||
void ApplyNow();
|
void ApplyNow();
|
||||||
void ApplyStencilReferenceNow(uint32_t backReference, uint32_t frontReference);
|
void ApplyStencilReferenceNow(uint32_t backReference, uint32_t frontReference);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device* device;
|
Device* device;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Framebuffer : public FramebufferBase {
|
class Framebuffer : public FramebufferBase {
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user