basic flow layout
This commit is contained in:
@@ -63,13 +63,13 @@ RayTracingPass::RayTracingPass(Gfx::PGraphics graphics, PScene scene) : RenderPa
|
||||
skyBoxSampler = graphics->createSampler({});
|
||||
}
|
||||
|
||||
static uint32 i = 0;
|
||||
static uint32 pass = 0;
|
||||
static Component::Camera lastCam;
|
||||
void RayTracingPass::beginFrame(const Component::Camera& cam) {
|
||||
RenderPass::beginFrame(cam);
|
||||
if (lastCam.getCameraPosition() != cam.getCameraPosition() || lastCam.getCameraForward() != cam.getCameraForward()) {
|
||||
lastCam = cam;
|
||||
i = 0;
|
||||
pass = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ void RayTracingPass::render() {
|
||||
};
|
||||
// for (uint32 i = 0; i < sampleParams.samplesPerPixel; ++i)
|
||||
{
|
||||
sampleParams.pass = i;
|
||||
sampleParams.pass = pass;
|
||||
command->pushConstants(Gfx::SE_SHADER_STAGE_RAYGEN_BIT_KHR, 0, sizeof(SampleParams), &sampleParams);
|
||||
command->traceRays(texture->getWidth(), texture->getHeight(), 1);
|
||||
radianceAccumulator->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR,
|
||||
@@ -164,8 +164,8 @@ void RayTracingPass::render() {
|
||||
texture->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR,
|
||||
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR);
|
||||
}
|
||||
i++;
|
||||
std::cout << i << std::endl;
|
||||
pass++;
|
||||
std::cout << pass << std::endl;
|
||||
texture->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR,
|
||||
Gfx::SE_ACCESS_TRANSFER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
Array<Gfx::ORenderCommand> commands;
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphics) {
|
||||
UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphics), system(system) {
|
||||
glyphInstanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.name = "GlyphInstanceBuffer"});
|
||||
elementBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.name = "RenderStyleElements"});
|
||||
textDescriptorLayout = graphics->createDescriptorLayout("pText");
|
||||
textDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
@@ -28,15 +29,24 @@ UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphic
|
||||
textPipelineLayout->addDescriptorLayout(viewParamsLayout);
|
||||
textPipelineLayout->addDescriptorLayout(textDescriptorLayout);
|
||||
|
||||
uiDescriptorLayout = graphics->createDescriptorLayout("pParams");
|
||||
uiDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
uiDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 1,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
|
||||
});
|
||||
uiDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 2,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
.descriptorCount = 1024,
|
||||
});
|
||||
uiPipelineLayout = graphics->createPipelineLayout("UIPipeline");
|
||||
uiPipelineLayout->addDescriptorLayout(viewParamsLayout);
|
||||
uiPipelineLayout->addDescriptorLayout(uiDescriptorLayout);
|
||||
// todo:
|
||||
texts.add(TextRender{
|
||||
.text = "TestText123",
|
||||
.font = AssetRegistry::findFont("", "arial"),
|
||||
.fontSize = 12,
|
||||
.position = Vector2(0, 100),
|
||||
});
|
||||
}
|
||||
|
||||
UIPass::~UIPass() {}
|
||||
@@ -45,35 +55,49 @@ void UIPass::beginFrame(const Component::Camera& cam) {
|
||||
RenderPass::beginFrame(cam);
|
||||
glyphs.clear();
|
||||
usedTextures.clear();
|
||||
for (TextRender& render : texts) {
|
||||
TextResources& res = textResources[render.font].add();
|
||||
float x = render.position.x * viewport->getContentScaleX();
|
||||
float y = (viewport->getHeight() - render.position.y) * viewport->getContentScaleY();
|
||||
for (uint32 c : render.text) {
|
||||
const FontAsset::Glyph& glyph = render.font->getGlyphData(c);
|
||||
Vector2 bearing = Vector2(glyph.bearing) * viewport->getContentScaleX();
|
||||
Vector2 size = Vector2(glyph.size) * viewport->getContentScaleY();
|
||||
float xpos = x + glyph.bearing.x;
|
||||
float ypos = y + (size.y - bearing.y);
|
||||
|
||||
float w = size.x;
|
||||
float h = size.y;
|
||||
|
||||
glyphs.add(GlyphInstanceData{
|
||||
.x = xpos,
|
||||
.y = ypos,
|
||||
.width = w,
|
||||
.height = h,
|
||||
.glyphIndex = (uint32)usedTextures.size(),
|
||||
for (const auto& render : renderElements) {
|
||||
float x = render.position.x;
|
||||
float y = render.position.y;
|
||||
if (render.text.empty()) {
|
||||
//todo: convert using actual tree depth
|
||||
elements.add(RenderElementStyle{
|
||||
.x = x,
|
||||
.y = y,
|
||||
.w = render.dimensions.x,
|
||||
.h = render.dimensions.y,
|
||||
.color = render.backgroundColor,
|
||||
.z = render.level / 100.f,
|
||||
});
|
||||
usedTextures.add(glyph.texture);
|
||||
x += glyph.advance >> 6;
|
||||
} else {
|
||||
y = y + render.fontSize;
|
||||
for (uint32 c : render.text) {
|
||||
const FontAsset::Glyph& glyph = render.font->getGlyphData(c);
|
||||
Vector2 bearing = Vector2(glyph.bearing);
|
||||
Vector2 size = Vector2(glyph.size);
|
||||
float xpos = x + glyph.bearing.x;
|
||||
float ypos = y - bearing.y;
|
||||
|
||||
float w = size.x;
|
||||
float h = size.y;
|
||||
|
||||
glyphs.add(GlyphInstanceData{
|
||||
.x = xpos,
|
||||
.y = ypos,
|
||||
.z = render.level / 100.0f,
|
||||
.width = w,
|
||||
.height = h,
|
||||
.glyphIndex = (uint32)usedTextures.size(),
|
||||
});
|
||||
usedTextures.add(glyph.texture);
|
||||
x += glyph.advance / 64.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
glyphInstanceBuffer->rotateBuffer(sizeof(GlyphInstanceData) * glyphs.size());
|
||||
glyphInstanceBuffer->updateContents(0, sizeof(GlyphInstanceData) * glyphs.size(), glyphs.data());
|
||||
glyphInstanceBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT);
|
||||
|
||||
textDescriptorLayout->reset();
|
||||
textDescriptorSet = textDescriptorLayout->allocateDescriptorSet();
|
||||
textDescriptorSet->updateBuffer(0, 0, glyphInstanceBuffer);
|
||||
@@ -82,6 +106,16 @@ void UIPass::beginFrame(const Component::Camera& cam) {
|
||||
textDescriptorSet->updateTexture(2, i, usedTextures[i]);
|
||||
}
|
||||
textDescriptorSet->writeChanges();
|
||||
|
||||
elementBuffer->rotateBuffer(sizeof(RenderElementStyle) * elements.size());
|
||||
elementBuffer->updateContents(0, sizeof(RenderElementStyle) * elements.size(), elements.data());
|
||||
elementBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT);
|
||||
uiDescriptorLayout->reset();
|
||||
uiDescriptorSet = uiDescriptorLayout->allocateDescriptorSet();
|
||||
uiDescriptorSet->updateBuffer(0, 0, elementBuffer);
|
||||
uiDescriptorSet->updateSampler(1, 0, glyphSampler);
|
||||
uiDescriptorSet->writeChanges();
|
||||
}
|
||||
|
||||
void UIPass::render() {
|
||||
@@ -89,6 +123,9 @@ void UIPass::render() {
|
||||
Array<Gfx::ORenderCommand> commands;
|
||||
Gfx::ORenderCommand command = graphics->createRenderCommand("TextPassCommand");
|
||||
command->setViewport(viewport);
|
||||
command->bindPipeline(uiPipeline);
|
||||
command->bindDescriptor({viewParamsSet, uiDescriptorSet});
|
||||
command->draw(4, elements.size(), 0, 0);
|
||||
command->bindPipeline(textPipeline);
|
||||
command->bindDescriptor({viewParamsSet, textDescriptorSet});
|
||||
command->draw(4, glyphs.size(), 0, 0);
|
||||
@@ -142,7 +179,7 @@ void UIPass::createRenderPass() {
|
||||
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
});
|
||||
|
||||
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
|
||||
textPipeline = graphics->createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo{
|
||||
.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
|
||||
.vertexShader = textVertexShader,
|
||||
.fragmentShader = textFragmentShader,
|
||||
@@ -167,15 +204,45 @@ void UIPass::createRenderPass() {
|
||||
Gfx::SE_COLOR_COMPONENT_A_BIT,
|
||||
}},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
textPipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
|
||||
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
||||
.name = "UIVertex",
|
||||
.modules = {"UIPass"},
|
||||
.entryPoints = {{"vertexMain", "UIPass"}, {"fragmentMain", "UIPass"}},
|
||||
.rootSignature = uiPipelineLayout,
|
||||
});
|
||||
uiPipelineLayout->create();
|
||||
uiVertexShader = graphics->createVertexShader({0});
|
||||
uiFragmentShader = graphics->createFragmentShader({1});
|
||||
|
||||
uiPipeline = graphics->createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo{
|
||||
.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
|
||||
.vertexShader = uiVertexShader,
|
||||
.fragmentShader = uiFragmentShader,
|
||||
.renderPass = renderPass,
|
||||
.pipelineLayout = uiPipelineLayout,
|
||||
.rasterizationState =
|
||||
{
|
||||
.cullMode = Gfx::SE_CULL_MODE_NONE,
|
||||
},
|
||||
.colorBlend =
|
||||
{
|
||||
|
||||
.attachmentCount = 1,
|
||||
.blendAttachments = {{
|
||||
.blendEnable = true,
|
||||
.srcColorBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA,
|
||||
.dstColorBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
.srcAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
.dstAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_ZERO,
|
||||
.alphaBlendOp = Gfx::SE_BLEND_OP_ADD,
|
||||
.colorWriteMask = Gfx::SE_COLOR_COMPONENT_R_BIT | Gfx::SE_COLOR_COMPONENT_G_BIT | Gfx::SE_COLOR_COMPONENT_B_BIT |
|
||||
Gfx::SE_COLOR_COMPONENT_A_BIT,
|
||||
}},
|
||||
},
|
||||
});
|
||||
system->style();
|
||||
system->layout(UVector2(viewport->getWidth(), viewport->getHeight()));
|
||||
renderElements = system->render();
|
||||
}
|
||||
|
||||
@@ -7,13 +7,6 @@
|
||||
namespace Seele {
|
||||
DECLARE_NAME_REF(Gfx, Texture2D)
|
||||
DECLARE_NAME_REF(Gfx, RenderTargetAttachment)
|
||||
struct TextRender {
|
||||
std::string text;
|
||||
PFontAsset font;
|
||||
uint32 fontSize;
|
||||
Vector4 textColor;
|
||||
Vector2 position;
|
||||
};
|
||||
class UIPass : public RenderPass {
|
||||
public:
|
||||
UIPass(Gfx::PGraphics graphics, UI::PSystem system);
|
||||
@@ -35,21 +28,24 @@ class UIPass : public RenderPass {
|
||||
struct GlyphInstanceData {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float width;
|
||||
float height;
|
||||
uint32 glyphIndex;
|
||||
};
|
||||
struct TextData {
|
||||
Vector4 textColor;
|
||||
float scale;
|
||||
};
|
||||
|
||||
struct TextResources {
|
||||
Gfx::PShaderBuffer instanceBuffer;
|
||||
Gfx::PDescriptorSet textureArraySet;
|
||||
TextData textData;
|
||||
struct RenderElementStyle {
|
||||
float x;
|
||||
float y;
|
||||
float w;
|
||||
float h;
|
||||
Vector color;
|
||||
float opacity = 1;
|
||||
float z = 0;
|
||||
uint32 textureIndex = -1ul;
|
||||
uint32 pad0;
|
||||
uint32 pad1;
|
||||
};
|
||||
Map<PFontAsset, Array<TextResources>> textResources;
|
||||
|
||||
Gfx::RenderTargetAttachment colorAttachment;
|
||||
Gfx::RenderTargetAttachment depthAttachment;
|
||||
@@ -71,9 +67,12 @@ class UIPass : public RenderPass {
|
||||
Gfx::OPipelineLayout uiPipelineLayout;
|
||||
Gfx::PGraphicsPipeline uiPipeline;
|
||||
|
||||
Array<TextRender> texts;
|
||||
UI::PSystem system;
|
||||
Array<UI::UIRender> renderElements;
|
||||
Array<GlyphInstanceData> glyphs;
|
||||
Array<RenderElementStyle> elements;
|
||||
Gfx::OShaderBuffer glyphInstanceBuffer;
|
||||
Gfx::OShaderBuffer elementBuffer;
|
||||
Gfx::OSampler glyphSampler;
|
||||
Array<Gfx::PTexture2D> usedTextures;
|
||||
};
|
||||
|
||||
@@ -39,7 +39,11 @@ class Buffer {
|
||||
virtual ~Buffer();
|
||||
VkBuffer getHandle() const { return buffers[currentBuffer]->buffer; }
|
||||
VkDeviceAddress getDeviceAddress() const { return buffers[currentBuffer]->deviceAddress; }
|
||||
PBufferAllocation getAlloc() const { return buffers[currentBuffer]; }
|
||||
PBufferAllocation getAlloc() const {
|
||||
if (buffers.empty())
|
||||
return nullptr;
|
||||
return buffers[currentBuffer];
|
||||
}
|
||||
uint64 getSize() const { return buffers[currentBuffer]->size; }
|
||||
void updateContents(uint64 regionOffset, uint64 regionSize, void* ptr);
|
||||
void readContents(uint64 regionOffset, uint64 regionSize, void* ptr);
|
||||
|
||||
@@ -171,7 +171,7 @@ DescriptorSet::~DescriptorSet() {}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) {
|
||||
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
|
||||
if (boundResources[binding][index] == vulkanBuffer->getAlloc()) {
|
||||
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PUniformBu
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) {
|
||||
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
|
||||
if (boundResources[binding][index] == vulkanBuffer->getAlloc()) {
|
||||
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuf
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PVertexBuffer indexBuffer) {
|
||||
PVertexBuffer vulkanBuffer = indexBuffer.cast<VertexBuffer>();
|
||||
if (boundResources[binding][index] == vulkanBuffer->getAlloc()) {
|
||||
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PVertexBuf
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PIndexBuffer indexBuffer) {
|
||||
PIndexBuffer vulkanBuffer = indexBuffer.cast<IndexBuffer>();
|
||||
if (boundResources[binding][index] == vulkanBuffer->getAlloc()) {
|
||||
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,6 @@ Matrix4 Viewport::getProjectionMatrix() const {
|
||||
//);
|
||||
return glm::perspective(fieldOfView, sizeX / static_cast<float>(sizeY), 0.1f, 1000.0f);
|
||||
} else {
|
||||
return glm::ortho(0.0f, (float)sizeX, 0.0f, (float)sizeY);
|
||||
return glm::ortho(0.0f, (float)sizeX, (float)sizeY, 0.0f);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user