2026-03-05 20:31:51 -07:00
|
|
|
#include "pipeline.hpp"
|
2022-07-27 11:25:25 -04:00
|
|
|
|
2026-03-05 20:31:51 -07:00
|
|
|
#include "../webgpu/gpu.hpp"
|
|
|
|
|
#include "gx_fmt.hpp"
|
|
|
|
|
#include "shader_info.hpp"
|
2026-04-09 03:19:58 +02:00
|
|
|
#include "tracy/Tracy.hpp"
|
2022-07-27 11:25:25 -04:00
|
|
|
|
2026-03-05 20:31:51 -07:00
|
|
|
namespace aurora::gx {
|
|
|
|
|
static Module Log("aurora::gx");
|
2022-07-27 11:25:25 -04:00
|
|
|
|
2026-04-01 00:49:28 -06:00
|
|
|
wgpu::RenderPipeline create_pipeline(const PipelineConfig& config) {
|
2026-04-09 03:19:58 +02:00
|
|
|
ZoneScoped;
|
2026-04-01 00:49:28 -06:00
|
|
|
const auto shader = build_shader(config.shaderConfig);
|
2026-06-12 10:28:52 -06:00
|
|
|
const auto label = fmt::format("GX Pipeline {:x} shader {:x}",
|
|
|
|
|
xxh3_hash(config, static_cast<HashType>(gfx::ShaderType::GX)),
|
|
|
|
|
xxh3_hash(config.shaderConfig));
|
|
|
|
|
return build_pipeline(config, {}, shader, label.c_str());
|
2022-07-27 11:25:25 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-01 00:49:28 -06:00
|
|
|
void render(const DrawData& data, const wgpu::RenderPassEncoder& pass) {
|
2026-03-05 20:31:51 -07:00
|
|
|
if (!gfx::bind_pipeline(data.pipeline, pass)) {
|
2022-07-27 11:25:25 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-12 18:55:35 -06:00
|
|
|
const std::array offsets{data.uniformRange.offset};
|
|
|
|
|
pass.SetBindGroup(1, gfx::g_uniformBindGroup, offsets.size(), offsets.data());
|
|
|
|
|
if (data.bindGroups.textureBindGroup) {
|
2026-03-05 20:31:51 -07:00
|
|
|
pass.SetBindGroup(2, gfx::find_bind_group(data.bindGroups.textureBindGroup));
|
2022-07-27 11:25:25 -04:00
|
|
|
}
|
2026-03-05 20:31:51 -07:00
|
|
|
pass.SetIndexBuffer(gfx::g_indexBuffer, wgpu::IndexFormat::Uint16, data.idxRange.offset, data.idxRange.size);
|
2022-07-27 11:25:25 -04:00
|
|
|
if (data.dstAlpha != UINT32_MAX) {
|
2022-08-02 16:37:56 -04:00
|
|
|
const wgpu::Color color{0.f, 0.f, 0.f, data.dstAlpha / 255.f};
|
|
|
|
|
pass.SetBlendConstant(&color);
|
2022-07-27 11:25:25 -04:00
|
|
|
}
|
2026-06-04 23:43:13 -06:00
|
|
|
if (data.indexCount == 0) {
|
|
|
|
|
pass.Draw(data.vtxCount, data.instanceCount);
|
|
|
|
|
} else {
|
|
|
|
|
pass.DrawIndexed(data.indexCount, data.instanceCount);
|
|
|
|
|
}
|
2022-07-27 11:25:25 -04:00
|
|
|
}
|
2026-03-05 20:31:51 -07:00
|
|
|
} // namespace aurora::gx
|