Trying to add water
This commit is contained in:
+34
-23
@@ -15,41 +15,52 @@ PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
|
||||
Gfx::PPipelineStatisticsQuery baseQuery = res->requestQuery("BASEPASS_QUERY");
|
||||
Gfx::PPipelineStatisticsQuery lightCullQuery = res->requestQuery("LIGHTCULL_QUERY");
|
||||
Gfx::PPipelineStatisticsQuery visibilityQuery = res->requestQuery("VISIBILITY_QUERY");
|
||||
Gfx::PTimestampQuery timeQuery = res->requestTimestampQuery("TIMESTAMP");
|
||||
Gfx::PTimestampQuery cachedTS = res->requestTimestampQuery("CACHED_TS");
|
||||
Gfx::PTimestampQuery depthTS = res->requestTimestampQuery("DEPTH_TS");
|
||||
Gfx::PTimestampQuery lightCullTS = res->requestTimestampQuery("LIGHTCULL_TS");
|
||||
Gfx::PTimestampQuery visibilityTS = res->requestTimestampQuery("VISIBILITY_TS");
|
||||
Gfx::PTimestampQuery baseTS = res->requestTimestampQuery("BASE_TS");
|
||||
std::ofstream stats(fmt::format("stats{}.csv", useMeshCulling ? "" : "NOCULL"));
|
||||
stats << std::fixed << std::setprecision(0);
|
||||
stats << "RelTime,"
|
||||
<< "CachedIAV,CachedIAP,CachedVS,CachedClipInv,CachedClipPrim,CachedFS,CachedCS,CachedTS,CachedMS,"
|
||||
<< "DepthIAV,DepthIAP,DepthVS,DepthClipInv,DepthClipPrim,DepthFS,DepthCS,DepthTS,DepthMS,"
|
||||
<< "BaseIAV,BaseIAP,BaseVS,BaseClipInv,BaseClipPrim,BaseFS,BaseCS,BaseTS,BaseMS,"
|
||||
<< "LightCullIAV,LightCullIAP,LightCullVS,LightCullClipInv,LightCullClipPrim,LightCullFS,LightCullCS,LightCullTS,LightCullMS,"
|
||||
<< "VisibilityIAV,VisibilityIAP,VisibilityVS,VisibilityClipInv,VisibilityClipPrim,VisibilityFS,VisibilityCS,VisibilityTS,"
|
||||
"VisibilityMS,"
|
||||
<< "CACHED,MIPGEN,DEPTHCULL,VISIBILITY,LIGHTCULL,BASE,FrameTime" << std::endl;
|
||||
float start = 0;
|
||||
<< "CACHED,MIPGEN,DEPTHCULL,VISIBILITY,LIGHTCULL,BASE,FrameTime,"
|
||||
<< "CachedIAV,CachedIAP,CachedVS,CachedClipInv,CachedClipPrim,CachedFS,CachedCS,"
|
||||
<< "DepthIAV,DepthIAP,DepthVS,DepthClipInv,DepthClipPrim,DepthFS,DepthCS,"
|
||||
<< "BaseIAV,BaseIAP,BaseVS,BaseClipInv,BaseClipPrim,BaseFS,BaseCS,"
|
||||
<< "LightCullIAV,LightCullIAP,LightCullVS,LightCullClipInv,LightCullClipPrim,LightCullFS,LightCullCS,"
|
||||
<< "VisibilityIAV,VisibilityIAP,VisibilityVS,VisibilityClipInv,VisibilityClipPrim,VisibilityFS,VisibilityCS" << std::endl;
|
||||
uint64 start = 0;
|
||||
uint64 prevBegin = 0;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
stats << std::fixed << std::setprecision(0);
|
||||
while (getGlobals().running) {
|
||||
auto timestamps = timeQuery->getResults();
|
||||
auto cached = cachedTS->getResults();
|
||||
auto depth = depthTS->getResults();
|
||||
auto lightCull = lightCullTS->getResults();
|
||||
auto visibility = visibilityTS->getResults();
|
||||
auto base = baseTS->getResults();
|
||||
auto cachedResults = cachedQuery->getResults();
|
||||
auto depthResults = depthQuery->getResults();
|
||||
auto baseResults = baseQuery->getResults();
|
||||
auto lightCullResults = lightCullQuery->getResults();
|
||||
auto visiblityResults = visibilityQuery->getResults();
|
||||
if (start == 0) {
|
||||
start = timestamps[0].time;
|
||||
start = cached[0].time;
|
||||
}
|
||||
uint64 t0 = timestamps[0].time;
|
||||
uint64 t1 = timestamps[1].time;
|
||||
uint64 t2 = timestamps[2].time;
|
||||
uint64 t3 = timestamps[3].time;
|
||||
uint64 t4 = timestamps[4].time;
|
||||
uint64 t5 = timestamps[5].time;
|
||||
uint64 t6 = timestamps[6].time;
|
||||
if (t1 < t0 || t2 < t1 || t3 < t2 || t4 < t3 || t5 < t4 || t6 < t5)
|
||||
continue;
|
||||
stats << t0 - start << "," << cachedResults << depthResults << baseResults << lightCullResults << visiblityResults << t1 - t0
|
||||
<< "," << t2 - t1 << "," << t3 - t2 << "," << t4 - t3 << "," << t5 - t4 << "," << t6 - t5 << "," << t6 - t0 << std::endl;
|
||||
int64 relTime = cached[0].time - start;
|
||||
int64 cachedTime = cached[1].time - cached[0].time;
|
||||
int64 mipTime = depth[1].time - depth[0].time;
|
||||
int64 depthTime = depth[2].time - depth[0].time;
|
||||
int64 baseTime = base[1].time - base[0].time;
|
||||
int64 lightCullTime = lightCull[1].time - lightCull[0].time;
|
||||
int64 visibilityTime = visibility[1].time - visibility[0].time;
|
||||
int64 frameTime = cachedTime + mipTime + depthTime + baseTime + lightCullTime + visibilityTime;
|
||||
|
||||
stats << relTime << "," << cachedTime << "," << mipTime << "," << depthTime << ","
|
||||
<< visibilityTime
|
||||
<< "," << lightCullTime << "," << baseTime << ","
|
||||
<< frameTime << "," << cachedResults << depthResults << baseResults << lightCullResults << visiblityResults << std::endl;
|
||||
stats.flush();
|
||||
// std::cout << "Writing " << timestamps[0].time << std::endl;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+4
-4
@@ -64,10 +64,10 @@ int main() {
|
||||
.filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg",
|
||||
.type = TextureImportType::TEXTURE_CUBEMAP,
|
||||
});
|
||||
AssetImporter::importMesh(MeshImportArgs{
|
||||
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
|
||||
.importPath = "Whitechapel",
|
||||
});
|
||||
//ssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
|
||||
// .importPath = "Whitechapel",
|
||||
//);
|
||||
// AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
|
||||
// .importPath = "suburbs",
|
||||
|
||||
@@ -86,9 +86,9 @@ void FontAsset::load(ArchiveBuffer& buffer) {
|
||||
.width = kTexture->baseWidth,
|
||||
.height = kTexture->baseHeight,
|
||||
.depth = kTexture->baseDepth,
|
||||
.mipLevels = kTexture->numLevels,
|
||||
.layers = kTexture->numFaces,
|
||||
.elements = kTexture->numLayers,
|
||||
.useMip = true,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT,
|
||||
};
|
||||
|
||||
|
||||
@@ -47,9 +47,9 @@ void TextureAsset::load(ArchiveBuffer& buffer) {
|
||||
.width = ktxHandle->baseWidth,
|
||||
.height = ktxHandle->baseHeight,
|
||||
.depth = ktxHandle->baseDepth,
|
||||
.mipLevels = ktxHandle->numLevels,
|
||||
.layers = ktxHandle->numFaces,
|
||||
.elements = ktxHandle->numLayers,
|
||||
.useMip = true,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT,
|
||||
.name = name,
|
||||
};
|
||||
|
||||
@@ -17,7 +17,8 @@ target_sources(Engine
|
||||
Skybox.h
|
||||
SphereCollider.h
|
||||
Transform.h
|
||||
Transform.cpp)
|
||||
Transform.cpp
|
||||
WaterTile.h)
|
||||
|
||||
|
||||
target_sources(Engine
|
||||
@@ -36,4 +37,5 @@ target_sources(Engine
|
||||
ShapeBase.h
|
||||
Skybox.h
|
||||
SphereCollider.h
|
||||
Transform.h)
|
||||
Transform.h
|
||||
WaterTile.h)
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Math/Vector.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace Component
|
||||
{
|
||||
struct WaterTile
|
||||
{
|
||||
IVector2 location;
|
||||
float height;
|
||||
constexpr static float DIMENSIONS = 100;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -159,10 +159,10 @@ static constexpr bool useAsyncCompute = false;
|
||||
static constexpr bool useMeshShading = true;
|
||||
static constexpr uint32 numFramesBuffered = 3;
|
||||
|
||||
// meshlet dimensions curated by NVIDIA
|
||||
static constexpr uint32 numVerticesPerMeshlet = 256;
|
||||
static constexpr uint32 numPrimitivesPerMeshlet = 256;
|
||||
double getCurrentFrameDelta();
|
||||
double getCurrentFrameTime();
|
||||
uint32 getCurrentFrameIndex();
|
||||
|
||||
enum class QueueType {
|
||||
|
||||
@@ -62,6 +62,7 @@ class Graphics {
|
||||
virtual void waitDeviceIdle() = 0;
|
||||
|
||||
virtual void executeCommands(Array<ORenderCommand> commands) = 0;
|
||||
virtual void executeCommands(OComputeCommand commands) = 0;
|
||||
virtual void executeCommands(Array<OComputeCommand> commands) = 0;
|
||||
|
||||
virtual OTexture2D createTexture2D(const TextureCreateInfo& createInfo) = 0;
|
||||
|
||||
@@ -50,10 +50,10 @@ struct TextureCreateInfo {
|
||||
uint32 width = 1;
|
||||
uint32 height = 1;
|
||||
uint32 depth = 1;
|
||||
uint32 mipLevels = 1;
|
||||
uint32 layers = 1;
|
||||
uint32 elements = 1;
|
||||
uint32 samples = 1;
|
||||
bool useMip = false;
|
||||
Gfx::SeImageUsageFlags usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT;
|
||||
Gfx::SeMemoryPropertyFlags memoryProps = Gfx::SE_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||
std::string name;
|
||||
@@ -111,6 +111,7 @@ struct ShaderCompilationInfo {
|
||||
Array<Pair<const char*, const char*>> typeParameter;
|
||||
Map<const char*, const char*> defines;
|
||||
Gfx::PPipelineLayout rootSignature;
|
||||
bool dumpIntermediate = false;
|
||||
};
|
||||
struct ShaderCreateInfo {
|
||||
uint32 entryPointIndex;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Component/Mesh.h"
|
||||
#include "Component/WaterTile.h"
|
||||
#include "Graphics/Command.h"
|
||||
#include "Graphics/Descriptor.h"
|
||||
#include "Graphics/Enums.h"
|
||||
@@ -25,6 +26,7 @@ void Seele::addDebugVertex(DebugVertex vert) { gDebugVertices.add(vert); }
|
||||
void Seele::addDebugVertices(Array<DebugVertex> verts) { gDebugVertices.addAll(verts); }
|
||||
|
||||
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
|
||||
waterRenderer = new WaterRenderer(graphics, scene, viewParamsLayout);
|
||||
basePassLayout = graphics->createPipelineLayout("BasePassLayout");
|
||||
|
||||
basePassLayout->addDescriptorLayout(viewParamsLayout);
|
||||
@@ -96,37 +98,42 @@ void BasePass::beginFrame(const Component::Camera& cam) {
|
||||
opaqueCulling = lightCullingLayout->allocateDescriptorSet();
|
||||
transparentCulling = lightCullingLayout->allocateDescriptorSet();
|
||||
|
||||
// Debug vertices
|
||||
VertexBufferCreateInfo vertexBufferInfo = {
|
||||
.sourceData =
|
||||
{
|
||||
.size = sizeof(DebugVertex) * gDebugVertices.size(),
|
||||
.data = (uint8*)gDebugVertices.data(),
|
||||
},
|
||||
.vertexSize = sizeof(DebugVertex),
|
||||
.numVertices = (uint32)gDebugVertices.size(),
|
||||
.name = "DebugVertices",
|
||||
};
|
||||
debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
|
||||
debugVertices->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
Gfx::SE_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_INPUT_BIT);
|
||||
waterRenderer->beginFrame();
|
||||
|
||||
// Debug vertices
|
||||
{
|
||||
VertexBufferCreateInfo vertexBufferInfo = {
|
||||
.sourceData =
|
||||
{
|
||||
.size = sizeof(DebugVertex) * gDebugVertices.size(),
|
||||
.data = (uint8*)gDebugVertices.data(),
|
||||
},
|
||||
.vertexSize = sizeof(DebugVertex),
|
||||
.numVertices = (uint32)gDebugVertices.size(),
|
||||
.name = "DebugVertices",
|
||||
};
|
||||
debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
|
||||
debugVertices->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
Gfx::SE_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_INPUT_BIT);
|
||||
}
|
||||
// Skybox
|
||||
skyboxDataLayout->reset();
|
||||
textureLayout->reset();
|
||||
skyboxData.transformMatrix = glm::rotate(skyboxData.transformMatrix, (float)(Gfx::getCurrentFrameDelta()), Vector(0, 1, 0));
|
||||
skyboxBuffer->rotateBuffer(sizeof(SkyboxData));
|
||||
skyboxBuffer->updateContents(0, sizeof(SkyboxData), &skyboxData);
|
||||
skyboxBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
|
||||
skyboxDataSet->updateBuffer(0, skyboxBuffer);
|
||||
skyboxDataSet->writeChanges();
|
||||
textureSet = textureLayout->allocateDescriptorSet();
|
||||
textureSet->updateTexture(0, skybox.day);
|
||||
textureSet->updateTexture(1, skybox.night);
|
||||
textureSet->updateSampler(2, skyboxSampler);
|
||||
textureSet->writeChanges();
|
||||
{
|
||||
skyboxDataLayout->reset();
|
||||
textureLayout->reset();
|
||||
skyboxData.transformMatrix = glm::rotate(skyboxData.transformMatrix, (float)(Gfx::getCurrentFrameDelta()), Vector(0, 1, 0));
|
||||
skyboxBuffer->rotateBuffer(sizeof(SkyboxData));
|
||||
skyboxBuffer->updateContents(0, sizeof(SkyboxData), &skyboxData);
|
||||
skyboxBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
|
||||
skyboxDataSet->updateBuffer(0, skyboxBuffer);
|
||||
skyboxDataSet->writeChanges();
|
||||
textureSet = textureLayout->allocateDescriptorSet();
|
||||
textureSet->updateTexture(0, skybox.day);
|
||||
textureSet->updateTexture(1, skybox.night);
|
||||
textureSet->updateSampler(2, skyboxSampler);
|
||||
textureSet->writeChanges();
|
||||
}
|
||||
}
|
||||
|
||||
void BasePass::render() {
|
||||
@@ -138,13 +145,15 @@ void BasePass::render() {
|
||||
transparentCulling->writeChanges();
|
||||
|
||||
query->beginQuery();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "BASEPASS");
|
||||
timestamps->begin();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "BaseBegin");
|
||||
graphics->beginRenderPass(renderPass);
|
||||
Array<Gfx::ORenderCommand> commands;
|
||||
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
|
||||
permutation.setDepthCulling(true); // always use the culling info
|
||||
permutation.setPositionOnly(false);
|
||||
Array<VertexData::TransparentDraw> transparentData;
|
||||
// Base Rendering
|
||||
for (VertexData* vertexData : VertexData::getList()) {
|
||||
transparentData.addAll(vertexData->getTransparentData());
|
||||
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
|
||||
@@ -238,14 +247,18 @@ void BasePass::render() {
|
||||
commands.add(std::move(command));
|
||||
}
|
||||
}
|
||||
|
||||
Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender");
|
||||
skyboxCommand->setViewport(viewport);
|
||||
skyboxCommand->bindPipeline(pipeline);
|
||||
skyboxCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet});
|
||||
skyboxCommand->draw(36, 1, 0, 0);
|
||||
commands.add(std::move(skyboxCommand));
|
||||
|
||||
|
||||
commands.add(waterRenderer->render(viewParamsSet));
|
||||
|
||||
// Skybox
|
||||
{
|
||||
Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender");
|
||||
skyboxCommand->setViewport(viewport);
|
||||
skyboxCommand->bindPipeline(pipeline);
|
||||
skyboxCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet});
|
||||
skyboxCommand->draw(36, 1, 0, 0);
|
||||
commands.add(std::move(skyboxCommand));
|
||||
}
|
||||
// Transparent rendering
|
||||
{
|
||||
permutation.setDepthCulling(false); // ignore visibility infos for transparency
|
||||
@@ -360,7 +373,7 @@ void BasePass::render() {
|
||||
graphics->executeCommands(std::move(commands));
|
||||
graphics->endRenderPass();
|
||||
query->endQuery();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "END");
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "BaseEnd");
|
||||
timestamps->end();
|
||||
gDebugVertices.clear();
|
||||
}
|
||||
@@ -412,12 +425,13 @@ void BasePass::publishOutputs() {
|
||||
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
|
||||
resources->registerRenderPassOutput("BASEPASS_DEPTH", depthAttachment);
|
||||
|
||||
timestamps = graphics->createTimestampQuery(2, "BaseTS");
|
||||
resources->registerTimestampQueryOutput("BASE_TS", timestamps);
|
||||
query = graphics->createPipelineStatisticsQuery("BasePassPipelineStatistics");
|
||||
resources->registerQueryOutput("BASEPASS_QUERY", query);
|
||||
}
|
||||
|
||||
void BasePass::createRenderPass() {
|
||||
timestamps = resources->requestTimestampQuery("TIMESTAMP");
|
||||
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
|
||||
|
||||
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
|
||||
@@ -458,6 +472,8 @@ void BasePass::createRenderPass() {
|
||||
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
|
||||
tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID");
|
||||
|
||||
waterRenderer->setViewport(viewport, renderPass);
|
||||
|
||||
// Debug rendering
|
||||
{
|
||||
debugPipelineLayout = graphics->createPipelineLayout("DebugPassLayout");
|
||||
@@ -527,7 +543,6 @@ void BasePass::createRenderPass() {
|
||||
};
|
||||
debugPipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
|
||||
}
|
||||
|
||||
// Skybox
|
||||
{
|
||||
skyboxDataLayout = graphics->createDescriptorLayout("pSkyboxData");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "RenderPass.h"
|
||||
#include "WaterRenderer.h"
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(CameraActor)
|
||||
@@ -44,10 +45,12 @@ class BasePass : public RenderPass {
|
||||
Gfx::ODescriptorLayout lightCullingLayout;
|
||||
|
||||
Gfx::OPipelineStatisticsQuery query;
|
||||
Gfx::PTimestampQuery timestamps;
|
||||
Gfx::OTimestampQuery timestamps;
|
||||
|
||||
Gfx::PShaderBuffer cullingBuffer;
|
||||
|
||||
OWaterRenderer waterRenderer;
|
||||
|
||||
// Debug rendering
|
||||
Gfx::OVertexInput debugVertexInput;
|
||||
Gfx::OVertexBuffer debugVertices;
|
||||
|
||||
@@ -20,7 +20,9 @@ target_sources(Engine
|
||||
UIPass.h
|
||||
UIPass.cpp
|
||||
VisibilityPass.h
|
||||
VisibilityPass.cpp)
|
||||
VisibilityPass.cpp
|
||||
WaterRenderer.h
|
||||
WaterRenderer.cpp)
|
||||
|
||||
target_sources(Engine
|
||||
PUBLIC FILE_SET HEADERS
|
||||
|
||||
@@ -47,13 +47,13 @@ void CachedDepthPass::beginFrame(const Component::Camera& cam) {
|
||||
void CachedDepthPass::render() {
|
||||
query->beginQuery();
|
||||
timestamps->begin();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "CACHED");
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "CachedBegin");
|
||||
graphics->beginRenderPass(renderPass);
|
||||
Array<Gfx::ORenderCommand> commands;
|
||||
|
||||
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("CachedDepthPass");
|
||||
permutation.setPositionOnly(getGlobals().usePositionOnly);
|
||||
permutation.setDepthCulling(getGlobals().useDepthCulling);
|
||||
permutation.setDepthCulling(true);
|
||||
for (VertexData* vertexData : VertexData::getList()) {
|
||||
permutation.setVertexData(vertexData->getTypeName());
|
||||
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
|
||||
@@ -127,6 +127,8 @@ void CachedDepthPass::render() {
|
||||
|
||||
graphics->executeCommands(std::move(commands));
|
||||
graphics->endRenderPass();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "CachedEnd");
|
||||
timestamps->end();
|
||||
query->endQuery();
|
||||
}
|
||||
|
||||
@@ -161,8 +163,8 @@ void CachedDepthPass::publishOutputs() {
|
||||
query = graphics->createPipelineStatisticsQuery("CachedPipelineStatistics");
|
||||
resources->registerQueryOutput("CACHED_QUERY", query);
|
||||
|
||||
timestamps = graphics->createTimestampQuery(7, "Timestamps");
|
||||
resources->registerTimestampQueryOutput("TIMESTAMP", timestamps);
|
||||
timestamps = graphics->createTimestampQuery(2, "CachedTS");
|
||||
resources->registerTimestampQueryOutput("CACHED_TS", timestamps);
|
||||
}
|
||||
|
||||
void CachedDepthPass::createRenderPass() {
|
||||
|
||||
@@ -78,7 +78,8 @@ void DepthCullingPass::render() {
|
||||
set->updateBuffer(1, depthMipBuffer);
|
||||
set->writeChanges();
|
||||
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "DEPTHMIP");
|
||||
timestamps->begin();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "MipBegin");
|
||||
Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("DepthMipGenCommand");
|
||||
computeCommand->bindPipeline(depthInitialReduce);
|
||||
computeCommand->bindDescriptor({viewParamsSet, set});
|
||||
@@ -115,7 +116,7 @@ void DepthCullingPass::render() {
|
||||
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
|
||||
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "DEPTHCULL");
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "CullingBegin");
|
||||
graphics->beginRenderPass(renderPass);
|
||||
Array<Gfx::ORenderCommand> commands;
|
||||
|
||||
@@ -194,6 +195,8 @@ void DepthCullingPass::render() {
|
||||
|
||||
graphics->executeCommands(std::move(commands));
|
||||
graphics->endRenderPass();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "CullingEnd");
|
||||
timestamps->end();
|
||||
query->endQuery();
|
||||
// Sync depth read/write with compute read
|
||||
depthAttachment.getTexture()->pipelineBarrier(
|
||||
@@ -251,12 +254,13 @@ void DepthCullingPass::publishOutputs() {
|
||||
|
||||
depthMipGen = graphics->createComputePipeline(pipelineCreateInfo);
|
||||
|
||||
timestamps = graphics->createTimestampQuery(3, "CullingTS");
|
||||
resources->registerTimestampQueryOutput("DEPTH_TS", timestamps);
|
||||
query = graphics->createPipelineStatisticsQuery("DepthPipelineStatistics");
|
||||
resources->registerQueryOutput("DEPTH_QUERY", query);
|
||||
}
|
||||
|
||||
void DepthCullingPass::createRenderPass() {
|
||||
timestamps = resources->requestTimestampQuery("TIMESTAMP");
|
||||
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
|
||||
|
||||
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
|
||||
|
||||
@@ -33,7 +33,7 @@ class DepthCullingPass : public RenderPass {
|
||||
Gfx::ODescriptorLayout depthAttachmentLayout;
|
||||
Gfx::OPipelineLayout depthCullingLayout;
|
||||
Gfx::OPipelineStatisticsQuery query;
|
||||
Gfx::PTimestampQuery timestamps;
|
||||
Gfx::OTimestampQuery timestamps;
|
||||
|
||||
Gfx::OPipelineLayout depthComputeLayout;
|
||||
Gfx::OComputeShader depthInitialReduceShader;
|
||||
|
||||
@@ -37,7 +37,8 @@ void LightCullingPass::beginFrame(const Component::Camera& cam) {
|
||||
|
||||
void LightCullingPass::render() {
|
||||
query->beginQuery();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "LIGHTCULL");
|
||||
timestamps->begin();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "LightCullBegin");
|
||||
oLightGrid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
tLightGrid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
@@ -62,6 +63,8 @@ void LightCullingPass::render() {
|
||||
commands.add(std::move(computeCommand));
|
||||
// std::cout << "Execute" << std::endl;
|
||||
graphics->executeCommands(std::move(commands));
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "LightCullEnd");
|
||||
timestamps->end();
|
||||
query->endQuery();
|
||||
oLightIndexList->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
@@ -224,13 +227,14 @@ void LightCullingPass::publishOutputs() {
|
||||
resources->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", Gfx::PTexture2D(oLightGrid));
|
||||
resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", Gfx::PTexture2D(tLightGrid));
|
||||
|
||||
timestamps = graphics->createTimestampQuery(2, "LightCullTS");
|
||||
resources->registerTimestampQueryOutput("LIGHTCULL_TS", timestamps);
|
||||
query = graphics->createPipelineStatisticsQuery("LightCullPipelineStatistics");
|
||||
resources->registerQueryOutput("LIGHTCULL_QUERY", query);
|
||||
}
|
||||
|
||||
void LightCullingPass::createRenderPass() {
|
||||
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH").getTexture();
|
||||
timestamps = resources->requestTimestampQuery("TIMESTAMP");
|
||||
}
|
||||
|
||||
void LightCullingPass::setupFrustums() {
|
||||
|
||||
@@ -64,7 +64,7 @@ class LightCullingPass : public RenderPass {
|
||||
Gfx::PComputePipeline cullingPipeline;
|
||||
Gfx::PComputePipeline cullingEnabledPipeline;
|
||||
Gfx::OPipelineStatisticsQuery query;
|
||||
Gfx::PTimestampQuery timestamps;
|
||||
Gfx::OTimestampQuery timestamps;
|
||||
};
|
||||
DEFINE_REF(LightCullingPass)
|
||||
} // namespace Seele
|
||||
|
||||
@@ -26,7 +26,8 @@ void VisibilityPass::render() {
|
||||
visibilitySet->writeChanges();
|
||||
|
||||
query->beginQuery();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "VISIBILITY");
|
||||
timestamps->begin();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "VisibilityBegin");
|
||||
Gfx::OComputeCommand command = graphics->createComputeCommand("VisibilityCommand");
|
||||
command->bindPipeline(visibilityPipeline);
|
||||
command->bindDescriptor({viewParamsSet, visibilitySet});
|
||||
@@ -34,6 +35,8 @@ void VisibilityPass::render() {
|
||||
Array<Gfx::OComputeCommand> commands;
|
||||
commands.add(std::move(command));
|
||||
graphics->executeCommands(std::move(commands));
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "VisibilityEnd");
|
||||
timestamps->end();
|
||||
query->endQuery();
|
||||
cullingBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT,
|
||||
@@ -85,8 +88,10 @@ void VisibilityPass::publishOutputs() {
|
||||
});
|
||||
resources->registerBufferOutput("CULLINGBUFFER", cullingBuffer);
|
||||
|
||||
timestamps = graphics->createTimestampQuery(2, "VisibilityTS");
|
||||
resources->registerTimestampQueryOutput("VISIBILITY_TS", timestamps);
|
||||
|
||||
query = graphics->createPipelineStatisticsQuery("VisibilityPipelineStatistics");
|
||||
timestamps = resources->requestTimestampQuery("TIMESTAMP");
|
||||
resources->registerQueryOutput("VISIBILITY_QUERY", query);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class VisibilityPass : public RenderPass {
|
||||
Gfx::OComputeShader visibilityShader;
|
||||
Gfx::PComputePipeline visibilityPipeline;
|
||||
Gfx::OPipelineStatisticsQuery query;
|
||||
Gfx::PTimestampQuery timestamps;
|
||||
Gfx::OTimestampQuery timestamps;
|
||||
|
||||
// Holds culling information for every meshlet for each instance
|
||||
Gfx::OShaderBuffer cullingBuffer;
|
||||
|
||||
@@ -0,0 +1,474 @@
|
||||
#include "WaterRenderer.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Component/WaterTile.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Shader.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescriptorLayout viewParamsLayout)
|
||||
: graphics(graphics), scene(scene) {
|
||||
skyBox = AssetRegistry::findTexture("", "skyboxsun5deg_tn")->getTexture().cast<Gfx::TextureCube>();
|
||||
logN = (int)log2(params.N);
|
||||
threadGroupsX = ceil(params.N / 8.0f);
|
||||
threadGroupsY = ceil(params.N / 8.0f);
|
||||
|
||||
materialUniforms = graphics->createUniformBuffer(UniformBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = sizeof(MaterialParams),
|
||||
.data = (uint8*)&materialParams,
|
||||
},
|
||||
.dynamic = true,
|
||||
.name = "WaterMaterialParams",
|
||||
});
|
||||
materialUniforms->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
Gfx::SE_ACCESS_UNIFORM_READ_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT | Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
paramsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = sizeof(ComputeParams),
|
||||
},
|
||||
.dynamic = true,
|
||||
.name = "WaterComputeParams",
|
||||
});
|
||||
paramsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
initialSpectrumTextures = graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
||||
.width = params.N,
|
||||
.height = params.N,
|
||||
.elements = 4,
|
||||
.useMip = true,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
|
||||
.name = "InitialSpectrumTextures",
|
||||
});
|
||||
initialSpectrumTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
boyancyData = graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_R16_SFLOAT,
|
||||
.width = params.N,
|
||||
.height = params.N,
|
||||
.useMip = false,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
|
||||
.name = "Bouyancy",
|
||||
});
|
||||
boyancyData->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
displacementTextures = graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
||||
.width = params.N,
|
||||
.height = params.N,
|
||||
.elements = 4,
|
||||
.useMip = true,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
|
||||
.name = "DisplacementTexture",
|
||||
});
|
||||
displacementTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
slopeTextures = graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_R32G32_SFLOAT,
|
||||
.width = params.N,
|
||||
.height = params.N,
|
||||
.elements = 4,
|
||||
.useMip = true,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
|
||||
.name = "SlopeTextures",
|
||||
});
|
||||
slopeTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
spectrumTextures = graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
||||
.width = params.N,
|
||||
.height = params.N,
|
||||
.elements = 8,
|
||||
.useMip = true,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
|
||||
.name = "SpectrumTextures",
|
||||
});
|
||||
spectrumTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
spectrumBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = spectrums.size() * sizeof(SpectrumParameters),
|
||||
.data = (uint8*)spectrums.data(),
|
||||
},
|
||||
.numElements = 8,
|
||||
.dynamic = true,
|
||||
.name = "Spectrums",
|
||||
});
|
||||
spectrumBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
linearRepeatSampler = graphics->createSampler(SamplerCreateInfo{
|
||||
.magFilter = Gfx::SE_FILTER_LINEAR,
|
||||
.minFilter = Gfx::SE_FILTER_LINEAR,
|
||||
.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT,
|
||||
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT,
|
||||
.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT,
|
||||
.anisotropyEnable = true,
|
||||
.maxAnisotropy = 16,
|
||||
});
|
||||
|
||||
computeLayout = graphics->createDescriptorLayout("pParams");
|
||||
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
});
|
||||
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 1,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
});
|
||||
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 2,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
});
|
||||
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 3,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
});
|
||||
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 4,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
});
|
||||
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 5,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
});
|
||||
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 6,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 7,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
|
||||
});
|
||||
computeLayout->create();
|
||||
|
||||
pipelineLayout = graphics->createPipelineLayout("WaterComputeLayout");
|
||||
pipelineLayout->addDescriptorLayout(computeLayout);
|
||||
|
||||
ShaderCompilationInfo info = {
|
||||
.name = "WaterCompute",
|
||||
.modules = {"WaterCompute"},
|
||||
.entryPoints =
|
||||
{
|
||||
{"CS_InitializeSpectrum", "WaterCompute"},
|
||||
{"CS_PackSpectrumConjugate", "WaterCompute"},
|
||||
{"CS_UpdateSpectrumForFFT", "WaterCompute"},
|
||||
{"CS_HorizontalFFT", "WaterCompute"},
|
||||
{"CS_VerticalFFT", "WaterCompute"},
|
||||
{"CS_AssembleMaps", "WaterCompute"},
|
||||
},
|
||||
.rootSignature = pipelineLayout,
|
||||
.dumpIntermediate = true,
|
||||
};
|
||||
graphics->beginShaderCompilation(info);
|
||||
initSpectrumCS = graphics->createComputeShader({0});
|
||||
packSpectrumConjugateCS = graphics->createComputeShader({1});
|
||||
updateSpectrumForFFTCS = graphics->createComputeShader({2});
|
||||
horizontalFFTCS = graphics->createComputeShader({3});
|
||||
verticalFFTCS = graphics->createComputeShader({4});
|
||||
assembleMapsCS = graphics->createComputeShader({5});
|
||||
|
||||
pipelineLayout->create();
|
||||
|
||||
initSpectrum = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
||||
.computeShader = initSpectrumCS,
|
||||
.pipelineLayout = pipelineLayout,
|
||||
});
|
||||
packSpectrumConjugate = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
||||
.computeShader = packSpectrumConjugateCS,
|
||||
.pipelineLayout = pipelineLayout,
|
||||
});
|
||||
updateSpectrumForFFT = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
||||
.computeShader = updateSpectrumForFFTCS,
|
||||
.pipelineLayout = pipelineLayout,
|
||||
});
|
||||
horizontalFFT = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
||||
.computeShader = horizontalFFTCS,
|
||||
.pipelineLayout = pipelineLayout,
|
||||
});
|
||||
verticalFFT = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
||||
.computeShader = verticalFFTCS,
|
||||
.pipelineLayout = pipelineLayout,
|
||||
});
|
||||
assembleMaps = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
||||
.computeShader = assembleMapsCS,
|
||||
.pipelineLayout = pipelineLayout,
|
||||
});
|
||||
|
||||
materialLayout = graphics->createDescriptorLayout("pWaterMaterial");
|
||||
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
});
|
||||
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 1,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
});
|
||||
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 2,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
});
|
||||
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 3,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
});
|
||||
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 4,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
|
||||
});
|
||||
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 5,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
materialLayout->create();
|
||||
waterLayout = graphics->createPipelineLayout("WaterLayout");
|
||||
waterLayout->addDescriptorLayout(viewParamsLayout);
|
||||
waterLayout->addDescriptorLayout(materialLayout);
|
||||
|
||||
ShaderCompilationInfo createInfo = {
|
||||
.name = "WaterTiles",
|
||||
.modules = {"WaterTask", "WaterMesh", "WaterPass"},
|
||||
.entryPoints =
|
||||
{
|
||||
{"taskMain", "WaterTask"},
|
||||
{"meshMain", "WaterMesh"},
|
||||
{"main", "WaterPass"},
|
||||
},
|
||||
.rootSignature = waterLayout,
|
||||
};
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
waterTask = graphics->createTaskShader({0});
|
||||
waterMesh = graphics->createMeshShader({1});
|
||||
waterFragment = graphics->createFragmentShader({2});
|
||||
|
||||
waterLayout->create();
|
||||
}
|
||||
|
||||
WaterRenderer::~WaterRenderer() {}
|
||||
|
||||
void WaterRenderer::beginFrame() {
|
||||
std::cout << "Test" << std::endl;
|
||||
updateFFTDescriptor();
|
||||
struct WaterPayload {
|
||||
Vector2 offset;
|
||||
float extent;
|
||||
float height;
|
||||
};
|
||||
Array<WaterPayload> payloads;
|
||||
scene->view<Component::WaterTile>([&](Component::WaterTile& tile) {
|
||||
payloads.add(WaterPayload{
|
||||
.offset = Vector2(tile.location) * Component::WaterTile::DIMENSIONS,
|
||||
.extent = Component::WaterTile::DIMENSIONS,
|
||||
.height = tile.height,
|
||||
});
|
||||
});
|
||||
waterTiles = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = payloads.size() * sizeof(WaterPayload),
|
||||
.data = (uint8*)payloads.data(),
|
||||
},
|
||||
.numElements = payloads.size(),
|
||||
.name = "WaterTiles",
|
||||
});
|
||||
waterTiles->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT);
|
||||
|
||||
displacementTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT,
|
||||
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
slopeTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT,
|
||||
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
boyancyData->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT,
|
||||
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
Gfx::OComputeCommand updateCommand = graphics->createComputeCommand("WaterUpdate");
|
||||
updateCommand->bindPipeline(updateSpectrumForFFT);
|
||||
updateCommand->bindDescriptor(computeSet);
|
||||
updateCommand->dispatch(threadGroupsX, threadGroupsY, 1);
|
||||
graphics->executeCommands(std::move(updateCommand));
|
||||
|
||||
spectrumTextures->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
Gfx::OComputeCommand horizontalCommand = graphics->createComputeCommand("HorizontalFFT");
|
||||
horizontalCommand->bindPipeline(horizontalFFT);
|
||||
horizontalCommand->bindDescriptor(computeSet);
|
||||
horizontalCommand->dispatch(1, params.N, 1);
|
||||
graphics->executeCommands(std::move(horizontalCommand));
|
||||
|
||||
spectrumTextures->pipelineBarrier(
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
Gfx::OComputeCommand verticalCommand = graphics->createComputeCommand("VerticalFFT");
|
||||
verticalCommand->bindPipeline(verticalFFT);
|
||||
verticalCommand->bindDescriptor(computeSet);
|
||||
verticalCommand->dispatch(1, params.N, 1);
|
||||
graphics->executeCommands(std::move(verticalCommand));
|
||||
|
||||
spectrumTextures->pipelineBarrier(
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
Gfx::OComputeCommand assembleCommand = graphics->createComputeCommand("AssembleCommand");
|
||||
assembleCommand->bindPipeline(assembleMaps);
|
||||
assembleCommand->bindDescriptor(computeSet);
|
||||
assembleCommand->dispatch(threadGroupsX, threadGroupsY, 1);
|
||||
graphics->executeCommands(std::move(assembleCommand));
|
||||
|
||||
// transition for mipmap gen
|
||||
displacementTextures->changeLayout(
|
||||
Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_TRANSFER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
|
||||
slopeTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_TRANSFER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
|
||||
displacementTextures->generateMipmaps();
|
||||
slopeTextures->generateMipmaps();
|
||||
|
||||
displacementTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
||||
Gfx::SE_SHADER_STAGE_MESH_BIT_EXT);
|
||||
|
||||
slopeTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT);
|
||||
|
||||
boyancyData->changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT);
|
||||
|
||||
updateMaterialDescriptor();
|
||||
graphics->waitDeviceIdle();
|
||||
}
|
||||
|
||||
Gfx::ORenderCommand WaterRenderer::render(Gfx::PDescriptorSet viewParamsSet) {
|
||||
Gfx::ORenderCommand waterCommand = graphics->createRenderCommand("WaterRender");
|
||||
waterCommand->setViewport(viewport);
|
||||
waterCommand->bindPipeline(waterPipeline);
|
||||
waterCommand->bindDescriptor({viewParamsSet, materialSet});
|
||||
waterCommand->drawMesh(waterTiles->getNumElements(), 1, 1);
|
||||
return waterCommand;
|
||||
}
|
||||
|
||||
void WaterRenderer::setViewport(Gfx::PViewport _viewport, Gfx::PRenderPass renderPass) {
|
||||
viewport = _viewport;
|
||||
updateFFTDescriptor();
|
||||
Gfx::MeshPipelineCreateInfo pipelineInfo = {
|
||||
.taskShader = waterTask,
|
||||
.meshShader = waterMesh,
|
||||
.fragmentShader = waterFragment,
|
||||
.renderPass = renderPass,
|
||||
.pipelineLayout = waterLayout,
|
||||
.multisampleState =
|
||||
{
|
||||
.samples = viewport->getSamples(),
|
||||
},
|
||||
.rasterizationState =
|
||||
{
|
||||
.cullMode = Gfx::SE_CULL_MODE_BACK_BIT,
|
||||
},
|
||||
.colorBlend =
|
||||
{
|
||||
.attachmentCount = 1,
|
||||
.blendAttachments =
|
||||
{
|
||||
Gfx::ColorBlendState::BlendAttachment{
|
||||
.blendEnable = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
waterPipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
|
||||
Gfx::OComputeCommand initCmd = graphics->createComputeCommand("InitialSpectrumCompute");
|
||||
initCmd->bindPipeline(initSpectrum);
|
||||
initCmd->bindDescriptor(computeSet);
|
||||
initCmd->dispatch(threadGroupsX, threadGroupsY, 1);
|
||||
graphics->executeCommands(std::move(initCmd));
|
||||
|
||||
initialSpectrumTextures->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
Gfx::OComputeCommand packCmd = graphics->createComputeCommand("PackConjugate");
|
||||
packCmd->bindPipeline(packSpectrumConjugate);
|
||||
packCmd->bindDescriptor(computeSet);
|
||||
packCmd->dispatch(threadGroupsX, threadGroupsY, 1);
|
||||
graphics->executeCommands(std::move(packCmd));
|
||||
|
||||
initialSpectrumTextures->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
}
|
||||
|
||||
float WaterRenderer::jonswapAlpha(float fetch, float windSpeed) const {
|
||||
return 0.076f * pow(params.gravity * fetch / windSpeed / windSpeed, -0.22f);
|
||||
}
|
||||
|
||||
float WaterRenderer::jonswapPeakFrequency(float fetch, float windSpeed) const {
|
||||
return 22 * pow(windSpeed * fetch / params.gravity / params.gravity, -0.33f);
|
||||
}
|
||||
|
||||
void WaterRenderer::updateFFTDescriptor() {
|
||||
for (uint32 i = 0; i < displaySpectrums.size(); ++i) {
|
||||
spectrums[i] = {
|
||||
.scale = displaySpectrums[i].scale,
|
||||
.angle = displaySpectrums[i].windDirection / 180 * 3.1415f,
|
||||
.spreadBlend = displaySpectrums[i].spreadBlend,
|
||||
.swell = std::clamp(displaySpectrums[i].swell, 0.01f, 1.0f),
|
||||
.alpha = jonswapAlpha(displaySpectrums[i].fetch, displaySpectrums[i].windSpeed),
|
||||
.peakOmega = jonswapPeakFrequency(displaySpectrums[i].fetch, displaySpectrums[i].windSpeed),
|
||||
.gamma = displaySpectrums[i].peakEnhancement,
|
||||
.shortWavesFade = displaySpectrums[i].shortWavesFade,
|
||||
};
|
||||
}
|
||||
spectrumBuffer->updateContents(0, sizeof(SpectrumParameters) * spectrums.size(), spectrums.data());
|
||||
spectrumBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
params.deltaTime = Gfx::getCurrentFrameDelta();
|
||||
params.frameTime = Gfx::getCurrentFrameTime();
|
||||
paramsBuffer->updateContents(0, sizeof(ComputeParams), ¶ms);
|
||||
paramsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
computeLayout->reset();
|
||||
computeSet = computeLayout->allocateDescriptorSet();
|
||||
computeSet->updateBuffer(0, paramsBuffer);
|
||||
computeSet->updateTexture(1, 0, Gfx::PTexture2D(spectrumTextures));
|
||||
computeSet->updateTexture(2, 0, Gfx::PTexture2D(initialSpectrumTextures));
|
||||
computeSet->updateTexture(3, 0, Gfx::PTexture2D(displacementTextures));
|
||||
computeSet->updateTexture(4, 0, Gfx::PTexture2D(slopeTextures));
|
||||
computeSet->updateTexture(5, 0, Gfx::PTexture2D(boyancyData));
|
||||
computeSet->updateBuffer(6, 0, spectrumBuffer);
|
||||
computeSet->updateSampler(7, 0, linearRepeatSampler);
|
||||
computeSet->writeChanges();
|
||||
}
|
||||
|
||||
void WaterRenderer::updateMaterialDescriptor() {
|
||||
materialLayout->reset();
|
||||
materialSet = materialLayout->allocateDescriptorSet();
|
||||
materialSet->updateBuffer(0, materialUniforms);
|
||||
materialSet->updateTexture(1, Gfx::PTexture2D(displacementTextures));
|
||||
materialSet->updateTexture(2, Gfx::PTexture2D(slopeTextures));
|
||||
materialSet->updateTexture(3, Gfx::PTextureCube(skyBox));
|
||||
materialSet->updateSampler(4, linearRepeatSampler);
|
||||
materialSet->updateBuffer(5, waterTiles);
|
||||
materialSet->writeChanges();
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
#pragma once
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele {
|
||||
class WaterRenderer {
|
||||
public:
|
||||
WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescriptorLayout viewParamsLayout);
|
||||
~WaterRenderer();
|
||||
void beginFrame();
|
||||
Gfx::ORenderCommand render(Gfx::PDescriptorSet viewParamsSet);
|
||||
void setViewport(Gfx::PViewport viewport, Gfx::PRenderPass renderPass);
|
||||
|
||||
private:
|
||||
float jonswapAlpha(float fetch, float windSpeed) const;
|
||||
float jonswapPeakFrequency(float fetch, float windSpeed) const;
|
||||
void updateFFTDescriptor();
|
||||
void updateMaterialDescriptor();
|
||||
Gfx::PGraphics graphics;
|
||||
PScene scene;
|
||||
Gfx::ODescriptorLayout computeLayout;
|
||||
Gfx::PDescriptorSet computeSet;
|
||||
Gfx::OPipelineLayout pipelineLayout;
|
||||
|
||||
Gfx::OComputeShader initSpectrumCS;
|
||||
Gfx::PComputePipeline initSpectrum;
|
||||
Gfx::OComputeShader packSpectrumConjugateCS;
|
||||
Gfx::PComputePipeline packSpectrumConjugate;
|
||||
Gfx::OComputeShader updateSpectrumForFFTCS;
|
||||
Gfx::PComputePipeline updateSpectrumForFFT;
|
||||
Gfx::OComputeShader horizontalFFTCS;
|
||||
Gfx::PComputePipeline horizontalFFT;
|
||||
Gfx::OComputeShader verticalFFTCS;
|
||||
Gfx::PComputePipeline verticalFFT;
|
||||
Gfx::OComputeShader assembleMapsCS;
|
||||
Gfx::PComputePipeline assembleMaps;
|
||||
|
||||
struct SpectrumParameters {
|
||||
float scale;
|
||||
float angle;
|
||||
float spreadBlend;
|
||||
float swell;
|
||||
float alpha;
|
||||
float peakOmega;
|
||||
float gamma;
|
||||
float shortWavesFade;
|
||||
};
|
||||
StaticArray<SpectrumParameters, 8> spectrums;
|
||||
struct DisplaySpectrumSettings {
|
||||
float scale = 1;
|
||||
float windSpeed = 1;
|
||||
float windDirection = 0;
|
||||
float fetch = 1;
|
||||
float spreadBlend = 1;
|
||||
float swell = 1;
|
||||
float peakEnhancement = 1;
|
||||
float shortWavesFade = 1;
|
||||
};
|
||||
StaticArray<DisplaySpectrumSettings, 8> displaySpectrums;
|
||||
struct ComputeParams {
|
||||
float frameTime;
|
||||
float deltaTime;
|
||||
float gravity = 9.81f;
|
||||
float repeatTime = 200.0f;
|
||||
float depth = 20.0f;
|
||||
float lowCutoff = 0.0001f;
|
||||
float highCutoff = 9000.0f;
|
||||
int seed = 0;
|
||||
Vector2 lambda = Vector2(1, 1);
|
||||
uint32 N = 1024;
|
||||
uint32 lengthScale0 = 256;
|
||||
uint32 lengthScale1 = 256;
|
||||
uint32 lengthScale2 = 256;
|
||||
uint32 lengthScale3 = 256;
|
||||
float foamBias = -0.5f;
|
||||
float foamDecayRate = 0.05f;
|
||||
float foamAdd = 0.5f;
|
||||
float foamThreshold = 0.0f;
|
||||
} params;
|
||||
float speed = 1.0f;
|
||||
float displacementDepthFalloff = 1.0f;
|
||||
uint32 logN;
|
||||
uint32 threadGroupsX;
|
||||
uint32 threadGroupsY;
|
||||
Gfx::OUniformBuffer paramsBuffer;
|
||||
Gfx::OTexture2D spectrumTextures, initialSpectrumTextures, displacementTextures;
|
||||
Gfx::OTexture2D slopeTextures;
|
||||
Gfx::OTexture2D boyancyData;
|
||||
Gfx::OShaderBuffer spectrumBuffer;
|
||||
Gfx::OSampler linearRepeatSampler;
|
||||
|
||||
struct MaterialParams {
|
||||
Vector sunDirection = Vector(0, -1, 0);
|
||||
float displacementDepthAttenuation = 1;
|
||||
|
||||
float foamSubtract0 = 0;
|
||||
float foamSubtract1 = 0;
|
||||
float foamSubtract2 = 0;
|
||||
float foamSubtract3 = 0;
|
||||
|
||||
float normalStrength = 1;
|
||||
float foamDepthAttenuation = 1;
|
||||
float normalDepthAttenuation = 1;
|
||||
float roughness = 0.1f;
|
||||
|
||||
Vector sunIrradiance = Vector(1, 1, 1);
|
||||
float foamRoughnessModifier = 1;
|
||||
|
||||
Vector scatterColor = Vector(1, 1, 1);
|
||||
float environmentLightStrength = 1;
|
||||
|
||||
Vector bubbleColor = Vector(1, 1, 1);
|
||||
float heightModifier = 1;
|
||||
|
||||
float bubbleDensity = 1;
|
||||
float wavePeakScatterStrength = 1;
|
||||
float scatterStrength = 1;
|
||||
float scatterShadowStrength = 1;
|
||||
|
||||
Vector foamColor = Vector(1, 1, 1);
|
||||
} materialParams;
|
||||
// Water
|
||||
Gfx::OUniformBuffer materialUniforms;
|
||||
Gfx::PTextureCube skyBox;
|
||||
Gfx::OShaderBuffer waterTiles;
|
||||
Gfx::OTaskShader waterTask;
|
||||
Gfx::OMeshShader waterMesh;
|
||||
Gfx::OFragmentShader waterFragment;
|
||||
Gfx::ODescriptorLayout materialLayout;
|
||||
Gfx::PDescriptorSet materialSet;
|
||||
Gfx::OPipelineLayout waterLayout;
|
||||
Gfx::PGraphicsPipeline waterPipeline;
|
||||
|
||||
Gfx::PViewport viewport;
|
||||
};
|
||||
DEFINE_REF(WaterRenderer)
|
||||
}
|
||||
@@ -66,22 +66,22 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
|
||||
std::unique_lock l(vertexDataLock);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
Array<Vector4> pos(numVertices);
|
||||
Array<Vector2> tex[MAX_TEXCOORDS];
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
tex[i].resize(numVertices);
|
||||
texCoords[i]->readContents(offset * sizeof(Vector2), numVertices * sizeof(Vector2), tex[i].data());
|
||||
std::memcpy(tex[i].data(), texData[i].data() + offset, numVertices * sizeof(Vector2));
|
||||
Serialization::save(buffer, tex[i]);
|
||||
}
|
||||
Array<Vector4> nor(numVertices);
|
||||
Array<Vector4> tan(numVertices);
|
||||
Array<Vector4> bit(numVertices);
|
||||
Array<Vector4> col(numVertices);
|
||||
positions->readContents(offset * sizeof(Vector4), numVertices * sizeof(Vector4), pos.data());
|
||||
normals->readContents(offset * sizeof(Vector4), numVertices * sizeof(Vector4), nor.data());
|
||||
tangents->readContents(offset * sizeof(Vector4), numVertices * sizeof(Vector4), tan.data());
|
||||
biTangents->readContents(offset * sizeof(Vector4), numVertices * sizeof(Vector4), bit.data());
|
||||
colors->readContents(offset * sizeof(Vector4), numVertices * sizeof(Vector4), col.data());
|
||||
Array<Vector4> pos(numVertices);
|
||||
std::memcpy(pos.data(), posData.data() + offset, numVertices * sizeof(Vector4));
|
||||
std::memcpy(nor.data(), norData.data() + offset, numVertices * sizeof(Vector4));
|
||||
std::memcpy(tan.data(), tanData.data() + offset, numVertices * sizeof(Vector4));
|
||||
std::memcpy(bit.data(), bitData.data() + offset, numVertices * sizeof(Vector4));
|
||||
std::memcpy(col.data(), colData.data() + offset, numVertices * sizeof(Vector4));
|
||||
Serialization::save(buffer, pos);
|
||||
Serialization::save(buffer, nor);
|
||||
Serialization::save(buffer, tan);
|
||||
|
||||
@@ -17,6 +17,7 @@ BufferAllocation::BufferAllocation(PGraphics graphics, const std::string& name,
|
||||
: CommandBoundResource(graphics, name), size(bufferInfo.size), owner(owner) {
|
||||
VK_CHECK(vmaCreateBufferWithAlignment(graphics->getAllocator(), &bufferInfo, &allocInfo, alignment, &buffer, &allocation, &info));
|
||||
vmaGetAllocationMemoryProperties(graphics->getAllocator(), allocation, &properties);
|
||||
assert(!name.empty());
|
||||
VkDebugUtilsObjectNameInfoEXT nameInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
|
||||
.pNext = nullptr,
|
||||
@@ -24,11 +25,10 @@ BufferAllocation::BufferAllocation(PGraphics graphics, const std::string& name,
|
||||
.objectHandle = (uint64)buffer,
|
||||
.pObjectName = name.c_str(),
|
||||
};
|
||||
vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo);
|
||||
if (!(properties & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
|
||||
bufferSize += size;
|
||||
}
|
||||
assert(!name.empty());
|
||||
vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo);
|
||||
if (bufferInfo.usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT) {
|
||||
VkBufferDeviceAddressInfo addrInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO_KHR,
|
||||
|
||||
@@ -401,7 +401,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uin
|
||||
assert(descriptor->writeDescriptors.size() == 0);
|
||||
boundResources.add(descriptor.getHandle());
|
||||
|
||||
for (auto binding : descriptor->boundResources) {
|
||||
for (const auto& binding : descriptor->boundResources) {
|
||||
for (auto res : binding) {
|
||||
res->bind();
|
||||
boundResources.add(res);
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "CRC.h"
|
||||
#include "Command.h"
|
||||
#include "Graphics.h"
|
||||
#include "Texture.h"
|
||||
#include "RayTracing.h"
|
||||
#include "Texture.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
@@ -159,10 +159,10 @@ void DescriptorPool::reset() {
|
||||
}
|
||||
|
||||
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
||||
: Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics, owner->getLayout()->getName()), setHandle(VK_NULL_HANDLE), graphics(graphics), owner(owner){
|
||||
: Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics, owner->getLayout()->getName()), setHandle(VK_NULL_HANDLE),
|
||||
graphics(graphics), owner(owner) {
|
||||
boundResources.resize(owner->getLayout()->getBindings().size());
|
||||
for (uint32 i = 0; i < boundResources.size(); ++i)
|
||||
{
|
||||
for (uint32 i = 0; i < boundResources.size(); ++i) {
|
||||
boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount);
|
||||
}
|
||||
}
|
||||
@@ -245,7 +245,6 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer
|
||||
boundResources[binding][0] = vulkanBuffer->getAlloc();
|
||||
}
|
||||
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) {
|
||||
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
|
||||
if (boundResources[binding][index] == vulkanBuffer->getAlloc()) {
|
||||
@@ -298,8 +297,7 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState)
|
||||
boundResources[binding][0] = vulkanSampler->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateSampler(uint32_t binding, uint32 dstArrayIndex, Gfx::PSampler samplerState)
|
||||
{
|
||||
void DescriptorSet::updateSampler(uint32_t binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) {
|
||||
PSampler vulkanSampler = samplerState.cast<Sampler>();
|
||||
if (boundResources[binding][dstArrayIndex] == vulkanSampler->getHandle()) {
|
||||
return;
|
||||
@@ -325,7 +323,6 @@ void DescriptorSet::updateSampler(uint32_t binding, uint32 dstArrayIndex, Gfx::P
|
||||
boundResources[binding][dstArrayIndex] = vulkanSampler->getHandle();
|
||||
}
|
||||
|
||||
|
||||
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
|
||||
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
|
||||
if (boundResources[binding][0] == vulkanTexture->getHandle()) {
|
||||
@@ -338,12 +335,6 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
|
||||
.imageView = vulkanTexture->getView(),
|
||||
.imageLayout = cast(vulkanTexture->getLayout()),
|
||||
});
|
||||
VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
|
||||
if (samplerState != nullptr) {
|
||||
descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
} else if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT) {
|
||||
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
|
||||
}
|
||||
writeDescriptors.add(VkWriteDescriptorSet{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.pNext = nullptr,
|
||||
@@ -351,15 +342,14 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
|
||||
.dstBinding = binding,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = descriptorType,
|
||||
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
|
||||
.pImageInfo = &imageInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][0] = vulkanTexture->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture)
|
||||
{
|
||||
void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) {
|
||||
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
|
||||
if (boundResources[binding][dstArrayIndex] == vulkanTexture->getHandle()) {
|
||||
return;
|
||||
@@ -378,14 +368,13 @@ void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTe
|
||||
.dstBinding = binding,
|
||||
.dstArrayElement = dstArrayIndex,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
|
||||
.pImageInfo = &imageInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][dstArrayIndex] = vulkanTexture->getHandle();
|
||||
}
|
||||
|
||||
|
||||
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D> textures) {
|
||||
// maybe make this a parameter?
|
||||
uint32 arrayElement = 0;
|
||||
@@ -400,10 +389,6 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D>
|
||||
.imageLayout = cast(vulkanTexture->getLayout()),
|
||||
});
|
||||
|
||||
VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
|
||||
if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT) {
|
||||
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
|
||||
}
|
||||
boundResources[binding][arrayElement] = vulkanTexture->getHandle();
|
||||
writeDescriptors.add(VkWriteDescriptorSet{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
@@ -412,13 +397,12 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D>
|
||||
.dstBinding = binding,
|
||||
.dstArrayElement = arrayElement++,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = descriptorType,
|
||||
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
|
||||
.pImageInfo = &imageInfos.back(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DescriptorSet::updateSamplerArray(uint32_t binding, Array<Gfx::PSampler> samplers) {
|
||||
// maybe make this a parameter?
|
||||
uint32 arrayElement = 0;
|
||||
|
||||
@@ -175,6 +175,12 @@ void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands) {
|
||||
getGraphicsCommands()->getCommands()->executeCommands(std::move(commands));
|
||||
}
|
||||
|
||||
void Graphics::executeCommands(Gfx::OComputeCommand commands) {
|
||||
Array<Gfx::OComputeCommand> commandArray;
|
||||
commandArray.add(std::move(commands));
|
||||
getComputeCommands()->getCommands()->executeCommands(std::move(commandArray));
|
||||
}
|
||||
|
||||
void Graphics::executeCommands(Array<Gfx::OComputeCommand> commands) {
|
||||
getComputeCommands()->getCommands()->executeCommands(std::move(commands));
|
||||
}
|
||||
@@ -747,6 +753,7 @@ void Graphics::pickPhysicalDevice() {
|
||||
.pNext = &meshShaderFeatures,
|
||||
.storageBuffer8BitAccess = true,
|
||||
.uniformAndStorageBuffer8BitAccess = true,
|
||||
.shaderFloat16 = true,
|
||||
.shaderUniformBufferArrayNonUniformIndexing = true,
|
||||
.shaderSampledImageArrayNonUniformIndexing = true,
|
||||
.shaderStorageBufferArrayNonUniformIndexing = true,
|
||||
@@ -770,6 +777,7 @@ void Graphics::pickPhysicalDevice() {
|
||||
.geometryShader = true,
|
||||
.fillModeNonSolid = true,
|
||||
.wideLines = true,
|
||||
.samplerAnisotropy = true,
|
||||
.pipelineStatisticsQuery = true,
|
||||
.fragmentStoresAndAtomics = true,
|
||||
.shaderInt64 = true,
|
||||
|
||||
@@ -41,6 +41,7 @@ class Graphics : public Gfx::Graphics {
|
||||
virtual void waitDeviceIdle() override;
|
||||
|
||||
virtual void executeCommands(Array<Gfx::ORenderCommand> commands) override;
|
||||
virtual void executeCommands(Gfx::OComputeCommand commands) override;
|
||||
virtual void executeCommands(Array<Gfx::OComputeCommand> commands) override;
|
||||
|
||||
virtual Gfx::OTexture2D createTexture2D(const TextureCreateInfo& createInfo) override;
|
||||
|
||||
@@ -46,7 +46,6 @@ void QueryPool::begin() {
|
||||
void QueryPool::end() {
|
||||
PCommand cmd = graphics->getGraphicsCommands()->getCommands();
|
||||
vkCmdEndQuery(cmd->getHandle(), handle, head);
|
||||
graphics->getGraphicsCommands()->submitCommands();
|
||||
std::unique_lock l(queryMutex);
|
||||
head = (head + 1) % numQueries;
|
||||
queryCV.notify_all();
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include "Enums.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Graphics/Initializer.h"
|
||||
#include <fmt/format.h>
|
||||
#include <math.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
@@ -29,10 +29,13 @@ VkImageAspectFlags getAspectFromFormat(Gfx::SeFormat format) {
|
||||
}
|
||||
|
||||
TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage)
|
||||
: CommandBoundResource(graphics, createInfo.name), image(existingImage), width(createInfo.width), height(createInfo.height), depth(createInfo.depth),
|
||||
arrayCount(createInfo.elements), layerCount(createInfo.layers), mipLevels(createInfo.mipLevels), samples(createInfo.samples),
|
||||
: CommandBoundResource(graphics, createInfo.name), image(existingImage), width(createInfo.width), height(createInfo.height),
|
||||
depth(createInfo.depth), arrayCount(createInfo.elements), mipLevels(1), layerCount(createInfo.layers), samples(createInfo.samples),
|
||||
format(createInfo.format), usage(createInfo.usage), layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED),
|
||||
aspect(getAspectFromFormat(createInfo.format)), ownsImage(false), owner(createInfo.sourceData.owner) {
|
||||
if (createInfo.useMip) {
|
||||
mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1;
|
||||
}
|
||||
if (existingImage == VK_NULL_HANDLE) {
|
||||
VkImageType type = VK_IMAGE_TYPE_MAX_ENUM;
|
||||
VkImageCreateFlags flags = 0;
|
||||
@@ -84,6 +87,14 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
|
||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||
};
|
||||
VK_CHECK(vmaCreateImage(graphics->getAllocator(), &info, &allocInfo, &image, &allocation, nullptr));
|
||||
VkDebugUtilsObjectNameInfoEXT nameInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
|
||||
.pNext = nullptr,
|
||||
.objectType = VK_OBJECT_TYPE_IMAGE,
|
||||
.objectHandle = (uint64)image,
|
||||
.pObjectName = name.c_str(),
|
||||
};
|
||||
vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo);
|
||||
ownsImage = true;
|
||||
}
|
||||
const DataSource& sourceData = createInfo.sourceData;
|
||||
@@ -103,7 +114,8 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
|
||||
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT,
|
||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||
};
|
||||
OBufferAllocation stagingAlloc = new BufferAllocation(graphics, fmt::format("{}Staging", createInfo.name), stagingInfo, alloc, Gfx::QueueType::TRANSFER);
|
||||
OBufferAllocation stagingAlloc =
|
||||
new BufferAllocation(graphics, fmt::format("{}Staging", createInfo.name), stagingInfo, alloc, Gfx::QueueType::TRANSFER);
|
||||
vmaMapMemory(graphics->getAllocator(), stagingAlloc->allocation, &data);
|
||||
std::memcpy(data, sourceData.data, sourceData.size);
|
||||
vmaUnmapMemory(graphics->getAllocator(), stagingAlloc->allocation);
|
||||
|
||||
@@ -11,6 +11,9 @@ using namespace Seele::Vulkan;
|
||||
double currentFrameDelta = 0;
|
||||
double Gfx::getCurrentFrameDelta() { return currentFrameDelta; }
|
||||
|
||||
double currentFrameTime = 0;
|
||||
double Gfx::getCurrentFrameTime() { return currentFrameTime; }
|
||||
|
||||
uint32 currentFrameIndex = 0;
|
||||
uint32 Gfx::getCurrentFrameIndex() { return currentFrameIndex; }
|
||||
|
||||
@@ -98,6 +101,11 @@ void Window::beginFrame() {
|
||||
imageAvailableFences[currentSemaphoreIndex]->submit();
|
||||
graphics->getGraphicsCommands()->getCommands()->waitForSemaphore(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||
imageAvailableSemaphores[currentSemaphoreIndex]);
|
||||
static double start = glfwGetTime();
|
||||
double end = glfwGetTime();
|
||||
currentFrameDelta = end - start;
|
||||
currentFrameTime += currentFrameDelta;
|
||||
start = end;
|
||||
}
|
||||
|
||||
void Window::endFrame() {
|
||||
@@ -261,7 +269,6 @@ void Window::createSwapChain() {
|
||||
.width = extent.width,
|
||||
.height = extent.height,
|
||||
.depth = 1,
|
||||
.mipLevels = 1,
|
||||
.layers = 1,
|
||||
.elements = 1,
|
||||
.samples = 1,
|
||||
|
||||
@@ -48,7 +48,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
|
||||
option[3].value.intValue0 = SLANG_DEBUG_INFO_FORMAT_PDB;
|
||||
option[4].name = slang::CompilerOptionName::DumpIntermediates;
|
||||
option[4].value.kind = slang::CompilerOptionValueKind::Int;
|
||||
option[4].value.intValue0 = 0;
|
||||
option[4].value.intValue0 = info.dumpIntermediate;
|
||||
|
||||
sessionDesc.compilerOptionEntries = option.data();
|
||||
sessionDesc.compilerOptionEntryCount = option.size();
|
||||
@@ -124,6 +124,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
|
||||
layout->addMapping("pLightEnv", 3);
|
||||
layout->addMapping("pRayTracingParams", 5);
|
||||
layout->addMapping("pScene", 2);
|
||||
layout->addMapping("pWaterMaterial", 1);
|
||||
}
|
||||
|
||||
Pair<Slang::ComPtr<slang::IBlob>, std::string> Seele::generateShader(const ShaderCreateInfo& createInfo) {
|
||||
|
||||
Reference in New Issue
Block a user