Some ray tracing changes

This commit is contained in:
Dynamitos
2024-07-08 13:46:49 +02:00
parent fd8dc5ed0f
commit acf8dde8fc
21 changed files with 108051 additions and 71 deletions
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 62 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 69 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

+19
View File
@@ -1,6 +1,12 @@
import pandas as pd import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
#areas = pd.read_csv('build/s.csv')
#
#plot = areas.hist(column='area', bins=100)
#plt.yscale('log')
#plt.show()
df = pd.read_csv('build/stats.csv') df = pd.read_csv('build/stats.csv')
noculldf = pd.read_csv('build/statsNOCULL.csv') noculldf = pd.read_csv('build/statsNOCULL.csv')
@@ -60,3 +66,16 @@ nocullax.legend()
nocullfig.savefig('allnocull.png') nocullfig.savefig('allnocull.png')
combfig, combax = plt.subplots()
combax.plot(scaled_reltime, scaled_FrameTime, label='Culling Frametime')
combax.plot(nocullscaled_reltime, nocullscaled_FrameTime, label='No Culling Frametime')
combax.set_xlabel('Application Time (ms)')
combax.set_ylabel('Render Times (ms)')
combax.legend()
combfig.savefig('combined.png')
+1 -2
View File
@@ -1,7 +1,6 @@
import Common; import Common;
import LightEnv; import LightEnv;
import MaterialParameter; import MaterialParameter;
import MATERIAL_FILE_NAME;
struct LightCullingData struct LightCullingData
{ {
@@ -26,7 +25,7 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
{ {
result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf); result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
} }
for(uint i = 0; i < pLightEnv.numPointLights; ++i) for(uint i = 0; i < lightCount; ++i)
{ {
uint lightIndex = pLightCullingData.lightIndexList[startOffset + i]; uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf); result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);
+17
View File
@@ -49,6 +49,23 @@ struct FragmentParameter
return result; return result;
} }
#endif #endif
static FragmentParameter interpolate(FragmentParameter f0, FragmentParameter f1, FragmentParameter f2, float3 barycentricCoords)
{
FragmentParameter result;
result.position_CS = f0.position_CS * barycentricCoords.x + f1.position_CS * barycentricCoords.y + f2.position_CS * barycentricCoords.z;
#ifndef POS_ONLY
result.normal_WS = f0.normal_WS * barycentricCoords.x + f1.normal_WS * barycentricCoords.y + f2.normal_WS * barycentricCoords.z;
result.tangent_WS = f0.tangent_WS * barycentricCoords.x + f1.tangent_WS * barycentricCoords.y + f2.tangent_WS * barycentricCoords.z;
result.biTangent_WS = f0.biTangent_WS * barycentricCoords.x + f1.biTangent_WS * barycentricCoords.y + f2.biTangent_WS * barycentricCoords.z;
result.position_WS = f0.position_WS * barycentricCoords.x + f1.position_WS * barycentricCoords.y + f2.position_WS * barycentricCoords.z;
result.vertexColor = f0.vertexColor * barycentricCoords.x + f1.vertexColor * barycentricCoords.y + f2.vertexColor * barycentricCoords.z;
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
result.texCoords[i] = f0.texCoords[i] * barycentricCoords.x + f1.texCoords[i] * barycentricCoords.y + f2.texCoords[i] * barycentricCoords.z;
}
#endif
return result;
}
}; };
// data passed to visibility render // data passed to visibility render
+56
View File
@@ -0,0 +1,56 @@
import Common;
import RayTracingData;
import VertexData;
import MaterialParameter;
import Scene;
import LightEnv;
// simplification: all BLAS only have 1 geometry
[shader("closesthit")]
void main(inout payload Payload hitValue, in BuiltInTriangleIntersectionAttributes attr)
{
const float3 barycentricCoords = float3(1.0f - attr.barycentrics.x - attr.barycentrics.y, attr.barycentrics.x, attr.barycentrics.y);
InstanceData inst = pScene.instances[InstanceID()];
MeshData m = pScene.meshData[InstanceID()];
// offset into the index buffer
uint indexOffset = m.firstIndex;
// added to indices to reference correct part of global mesh pool
uint vertexOffset = pScene.meshletInfos[m.meshletOffset].indicesOffset;
uint vertexIndex0 = vertexOffset + pRayTracingParams.indexBuffer[indexOffset + 3 * PrimitiveIndex() + 0];
uint vertexIndex1 = vertexOffset + pRayTracingParams.indexBuffer[indexOffset + 3 * PrimitiveIndex() + 1];
uint vertexIndex2 = vertexOffset + pRayTracingParams.indexBuffer[indexOffset + 3 * PrimitiveIndex() + 2];
VertexAttributes attr0 = pVertexData.getAttributes(vertexIndex0);
VertexAttributes attr1 = pVertexData.getAttributes(vertexIndex1);
VertexAttributes attr2 = pVertexData.getAttributes(vertexIndex2);
FragmentParameter f0 = attr0.getParameter(inst.transformMatrix);
FragmentParameter f1 = attr1.getParameter(inst.transformMatrix);
FragmentParameter f2 = attr2.getParameter(inst.transformMatrix);
FragmentParameter params = FragmentParameter.interpolate(f0, f1, f2, barycentricCoords);
LightingParameter lightingParams = params.getLightingParameter();
MaterialParameter materialParams = params.getMaterialParameter();
let brdf = Material.prepare(materialParams);
float3 result = float3(0, 0, 0);
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
{
result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
}
for(uint i = 0; i < pLightEnv.numPointLights; ++i)
{
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
}
result += brdf.evaluateAmbient();
// gamma correction
result = result / (result + float3(1.0));
result = pow(result, float3(1.0/2.2));
hitValue.color = result;
}
+36
View File
@@ -0,0 +1,36 @@
import Common;
import RayTracingData;
[shader("raygeneration")]
void main()
{
const float2 pixelCenter = float2(DispatchRaysIndex().xy) + float2(0.5);
const float2 inUV = pixelCenter / float2(DispatchRaysDimensions().xy);
float2 d = inUV * 2.0 - 1.0;
float4 origin = mul(pViewParams.inverseViewMatrix, float4(0, 0, 0, 1));
float4 target = mul(pViewParams.inverseProjection, float4(d.x, d.y, 1, 1));
float4 direction = mul(pViewParams.inverseViewMatrix, float4(normalize(target.xyz), 0));
float tmin = 0.0001;
float tmax = 10000.0;
uint max_rays = 24;
uint object_type = 100;
float4 color = float4(0, 0, 0, 0);
uint current_mode = 0;
float expectedDistance = -1;
Payload payload;
RayDesc desc = {
origin.xyz,
tmin,
direction.xyz,
tmax,
};
TraceRay(pRayTracingParams.scene, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, desc, payload);
pRayTracingParams.image[DispatchRaysIndex().xy] = payload.color;
}
@@ -0,0 +1,13 @@
struct Payload
{
float3 color;
};
struct RayTracingParams
{
RaytracingAccelerationStructure scene;
RWTexture2D<float3> image;
StructuredBuffer<uint> indexBuffer;
};
ParameterBlock<RayTracingParams> pRayTracingParams;
+147 -40
View File
@@ -5,58 +5,165 @@
#include "Asset/MaterialInstanceAsset.h" #include "Asset/MaterialInstanceAsset.h"
#include "Asset/MeshAsset.h" #include "Asset/MeshAsset.h"
#include "Asset/TextureAsset.h" #include "Asset/TextureAsset.h"
#include <assimp/Exporter.hpp>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
using namespace Seele; using namespace Seele;
AssetRegistry* _instance = new AssetRegistry(); AssetRegistry* _instance = new AssetRegistry();
int main(int, char**) { int main(int, char**) {
// if(argc < 2) Assimp::Importer importer;
//{ const aiScene* scene =
// return -1; importer.ReadFile("C:\\Users\\Dynamitos\\MeshShadingDemo\\import\\models\\after-the-rain-vr-sound\\source\\WhitechapelSrc.fbx",
// } (uint32)(aiProcess_FlipUVs | aiProcess_Triangulate | aiProcess_ImproveCacheLocality));
std::filesystem::path path = std::filesystem::path("C:\\Users\\Dynamitos\\TrackClear\\Assets\\Dirt.asset");
std::ifstream stream = std::ifstream(path, std::ios::binary);
ArchiveBuffer buffer; auto interpolate = [](Vector p0, Vector p1, Vector p2) { return (p0 + p1 + p2) / 3.0f; };
buffer.readFromStream(stream);
// Read asset type //std::fstream stats("s.csv");
uint64 identifier; //stats << "area" << std::endl;
Serialization::load(buffer, identifier); for (uint32 m = 0; m < scene->mNumMeshes; ++m) {
aiMesh* mesh = scene->mMeshes[m];
Array<Vector> positions(mesh->mNumVertices);
Array<Vector> normals(mesh->mNumVertices);
Array<Vector> tangents(mesh->mNumVertices);
Array<Vector> biTangents(mesh->mNumVertices);
Array<Vector> texCoords(mesh->mNumVertices);
Array<Vector> texCoords1(mesh->mNumVertices);
if (mesh->HasTextureCoords(2))
abort();
for (int32 i = 0; i < mesh->mNumVertices; ++i) {
positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
// Read name if (mesh->mTextureCoords[0] != nullptr)
std::string name; texCoords[i] = Vector(mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].y, 0);
Serialization::load(buffer, name);
// Read folder if (mesh->mTextureCoords[1] != nullptr)
std::string folderPath; texCoords1[i] = Vector(mesh->mTextureCoords[1][i].x, mesh->mTextureCoords[1][i].y, 0);
Serialization::load(buffer, folderPath);
PAsset asset; if (mesh->mNormals != nullptr)
switch (identifier) { normals[i] = Vector(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z);
case TextureAsset::IDENTIFIER:
asset = new TextureAsset(folderPath, name); if (mesh->mTangents != nullptr)
break; tangents[i] = Vector(mesh->mTangents[i].x, mesh->mTangents[i].y, mesh->mTangents[i].z);
case MeshAsset::IDENTIFIER:
asset = new MeshAsset(folderPath, name); if (mesh->mBitangents != nullptr)
break; biTangents[i] = Vector(mesh->mBitangents[i].x, mesh->mBitangents[i].y, mesh->mBitangents[i].z);
case MaterialAsset::IDENTIFIER: }
asset = new MaterialAsset(folderPath, name);
break; struct Tri {
case MaterialInstanceAsset::IDENTIFIER: uint32 p[3];
asset = new MaterialInstanceAsset(folderPath, name); };
// TODO auto calcArea = [&positions](Tri t) {
break; Vector p1 = positions[t.p[0]];
case FontAsset::IDENTIFIER: Vector p2 = positions[t.p[1]];
asset = new FontAsset(folderPath, name); Vector p3 = positions[t.p[2]];
break; return 0.5 * glm::length(glm::cross(p2 - p1, p3 - p1));
default: };
throw new std::logic_error("Unknown Identifier"); Array<Tri> tris(mesh->mNumFaces);
for (int32 faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex) {
tris[faceIndex].p[0] = mesh->mFaces[faceIndex].mIndices[0];
tris[faceIndex].p[1] = mesh->mFaces[faceIndex].mIndices[1];
tris[faceIndex].p[2] = mesh->mFaces[faceIndex].mIndices[2];
}
auto tesselate = [&](uint32 i) {
uint32 p0 = tris[i].p[0];
uint32 p1 = tris[i].p[1];
uint32 p2 = tris[i].p[2];
uint32 p3 = positions.size();
positions.add(interpolate(positions[p0], positions[p1], positions[p2]));
if (mesh->mTextureCoords[0] != nullptr)
texCoords.add(interpolate(texCoords[p0], texCoords[p1], texCoords[p2]));
if (mesh->mTextureCoords[1] != nullptr)
texCoords1.add(interpolate(texCoords1[p0], texCoords1[p1], texCoords1[p2]));
if (mesh->mNormals != nullptr)
normals.add(interpolate(normals[p0], normals[p1], normals[p2]));
if (mesh->mTangents != nullptr)
tangents.add(interpolate(tangents[p0], tangents[p1], tangents[p2]));
if (mesh->mBitangents != nullptr)
biTangents.add(interpolate(biTangents[p0], biTangents[p1], biTangents[p2]));
tris[i].p[2] = p3;
tris.add(Tri{p1, p2, p3});
tris.add(Tri{p2, p0, p3});
};
//for (uint32 i = 0; i < tris.size(); ++i) {
// stats << calcArea(tris[i]) << std::endl;
//}
bool tess = false;
while (!tess) {
tess = true;
for (uint32 i = 0; i < tris.size(); ++i) {
if (calcArea(tris[i]) > 100.f) {
tesselate(i);
tess = false;
}
}
}
aiVector3D* newPos = new aiVector3D[positions.size()];
std::memcpy(newPos, positions.data(), positions.size() * sizeof(Vector));
if (mesh->mTextureCoords[0] != nullptr) {
aiVector3D* newTex = new aiVector3D[texCoords.size()];
std::memcpy(newTex, texCoords.data(), texCoords.size() * sizeof(Vector));
mesh->mTextureCoords[0] = newTex;
}
if (mesh->mTextureCoords[1] != nullptr) {
aiVector3D* newTex = new aiVector3D[texCoords1.size()];
std::memcpy(newTex, texCoords1.data(), texCoords1.size() * sizeof(Vector));
mesh->mTextureCoords[1] = newTex;
}
if (mesh->mNormals != nullptr) {
aiVector3D* newNor = new aiVector3D[normals.size()];
std::memcpy(newNor, normals.data(), normals.size() * sizeof(Vector));
mesh->mNormals = newNor;
}
if (mesh->mTangents != nullptr) {
aiVector3D* newTan = new aiVector3D[tangents.size()];
std::memcpy(newTan, tangents.data(), tangents.size() * sizeof(Vector));
mesh->mTangents = newTan;
}
if (mesh->mBitangents != nullptr) {
aiVector3D* newBit = new aiVector3D[biTangents.size()];
std::memcpy(newBit, biTangents.data(), biTangents.size() * sizeof(Vector));
mesh->mBitangents = newBit;
}
uint32 numFaces = tris.size();
aiFace* newFaces = new aiFace[numFaces];
for (uint32 i = 0; i < numFaces; ++i) {
newFaces[i].mNumIndices = 3;
newFaces[i].mIndices = new uint32[3];
newFaces[i].mIndices[0] = tris[i].p[0];
newFaces[i].mIndices[1] = tris[i].p[1];
newFaces[i].mIndices[2] = tris[i].p[2];
}
mesh->mNumVertices = positions.size();
mesh->mVertices = newPos;
mesh->mFaces = newFaces;
mesh->mNumFaces = tris.size();
}
Assimp::Exporter exporter;
exporter.Export(scene, "fbx",
"C:\\Users\\Dynamitos\\MeshShadingDemo\\import\\models\\after-the-rain-vr-sound\\source\\Whitechapel.fbx");
for (uint32 i = 0; i < exporter.GetExportFormatCount(); ++i) {
auto desc = exporter.GetExportFormatDescription(i);
std::cout << desc->description << " " << desc->fileExtension << " " << desc->id << " " << std::endl;
} }
asset->load(buffer);
std::cin.get();
} }
+12 -6
View File
@@ -1,7 +1,7 @@
#include "PlayView.h" #include "PlayView.h"
#include "Window/Window.h" #include "Window/Window.h"
#include <fstream>
#include <fmt/format.h> #include <fmt/format.h>
#include <fstream>
using namespace Seele; using namespace Seele;
@@ -38,11 +38,17 @@ PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
if (start == 0) { if (start == 0) {
start = timestamps[0].time; start = timestamps[0].time;
} }
stats << timestamps[0].time - start << "," << cachedResults << depthResults << baseResults << lightCullResults uint64 t0 = timestamps[0].time;
<< visiblityResults << timestamps[1].time - timestamps[0].time << "," << timestamps[2].time - timestamps[1].time << "," uint64 t1 = timestamps[1].time;
<< timestamps[3].time - timestamps[2].time << "," << timestamps[4].time - timestamps[3].time << "," uint64 t2 = timestamps[2].time;
<< timestamps[5].time - timestamps[4].time << "," << timestamps[6].time - timestamps[5].time << "," uint64 t3 = timestamps[3].time;
<< timestamps[6].time - timestamps[0].time << std::endl; 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;
stats.flush(); stats.flush();
} }
}); });
+2 -2
View File
@@ -23,7 +23,7 @@ int main(int argc, char** argv) {
useDepthCulling = false; useDepthCulling = false;
} }
std::filesystem::path binaryPath = "MeshShadingDemo.dll"; std::filesystem::path binaryPath = "C:/Users/Dynamitos/MeshShadingDemo/bin/MeshShadingDemo.dll";
graphics = new Vulkan::Graphics(); graphics = new Vulkan::Graphics();
GraphicsInitializer initializer; GraphicsInitializer initializer;
graphics->init(initializer); graphics->init(initializer);
@@ -31,7 +31,7 @@ int main(int argc, char** argv) {
vd->init(graphics); vd->init(graphics);
OWindowManager windowManager = new WindowManager(); OWindowManager windowManager = new WindowManager();
AssetRegistry::init("Assets", graphics); AssetRegistry::init("C:/Users/Dynamitos/MeshShadingDemo/Assets", graphics);
vd->commitMeshes(); vd->commitMeshes();
WindowCreateInfo mainWindowInfo = { WindowCreateInfo mainWindowInfo = {
.width = 1920, .width = 1920,
+5 -2
View File
@@ -416,7 +416,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
uint64 offset = vertexData->getMeshOffset(id); uint64 offset = vertexData->getMeshOffset(id);
collider.boundingbox.adjust(Vector(mesh->mAABB.mMin.x, mesh->mAABB.mMin.y, mesh->mAABB.mMin.z)); collider.boundingbox.adjust(Vector(mesh->mAABB.mMin.x, mesh->mAABB.mMin.y, mesh->mAABB.mMin.z));
collider.boundingbox.adjust(Vector(mesh->mAABB.mMax.x, mesh->mAABB.mMax.y, mesh->mAABB.mMax.z)); collider.boundingbox.adjust(Vector(mesh->mAABB.mMax.x, mesh->mAABB.mMax.y, mesh->mAABB.mMax.z));
work.add([=, &globalMeshes]() { work.add([=, this, &globalMeshes]() {
// assume static mesh for now // assume static mesh for now
Array<Vector4> positions(mesh->mNumVertices); Array<Vector4> positions(mesh->mNumVertices);
StaticArray<Array<Vector2>, MAX_TEXCOORDS> texCoords; StaticArray<Array<Vector2>, MAX_TEXCOORDS> texCoords;
@@ -462,7 +462,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
vertexData->loadColors(offset, colors); vertexData->loadColors(offset, colors);
Array<uint32> indices(mesh->mNumFaces * 3); Array<uint32> indices(mesh->mNumFaces * 3);
for (int32 faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex) { for (uint32 faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex) {
indices[faceIndex * 3 + 0] = mesh->mFaces[faceIndex].mIndices[0]; indices[faceIndex * 3 + 0] = mesh->mFaces[faceIndex].mIndices[0];
indices[faceIndex * 3 + 1] = mesh->mFaces[faceIndex].mIndices[1]; indices[faceIndex * 3 + 1] = mesh->mFaces[faceIndex].mIndices[1];
indices[faceIndex * 3 + 2] = mesh->mFaces[faceIndex].mIndices[2]; indices[faceIndex * 3 + 2] = mesh->mFaces[faceIndex].mIndices[2];
@@ -481,7 +481,10 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
globalMeshes[meshIndex]->meshlets = std::move(meshlets); globalMeshes[meshIndex]->meshlets = std::move(meshlets);
globalMeshes[meshIndex]->indices = std::move(indices); globalMeshes[meshIndex]->indices = std::move(indices);
globalMeshes[meshIndex]->vertexCount = mesh->mNumVertices; globalMeshes[meshIndex]->vertexCount = mesh->mNumVertices;
globalMeshes[meshIndex]->blas = graphics->createBottomLevelAccelerationStructure(Gfx::BottomLevelASCreateInfo{
.mesh = globalMeshes[meshIndex],
}); });
});
} }
getThreadPool().runAndWait(std::move(work)); getThreadPool().runAndWait(std::move(work));
} }
+3 -3
View File
@@ -125,12 +125,12 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
.structSize = sizeof(ktxBasisParams), .structSize = sizeof(ktxBasisParams),
.uastc = true, .uastc = true,
.threadCount = std::thread::hardware_concurrency() - 2, .threadCount = std::thread::hardware_concurrency() - 2,
.uastcFlags = KTX_PACK_UASTC_LEVEL_SLOWER, .uastcFlags = KTX_PACK_UASTC_LEVEL_FASTER,
.uastcRDO = true, .uastcRDO = true,
}; };
KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams)); KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams));
KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 20)); KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 10));
char writer[100]; char writer[100];
snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1"); snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1");
@@ -140,7 +140,7 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
size_t texSize; size_t texSize;
KTX_ASSERT(ktxTexture_WriteToMemory(ktxTexture(kTexture), &texData, &texSize)); KTX_ASSERT(ktxTexture_WriteToMemory(ktxTexture(kTexture), &texData, &texSize));
ktxTexture_WriteToNamedFile(ktxTexture(kTexture), args.filePath.filename().replace_extension(".ktx").generic_string().c_str()); //ktxTexture_WriteToNamedFile(ktxTexture(kTexture), args.filePath.filename().replace_extension(".ktx").generic_string().c_str());
Array<uint8> serialized(texSize); Array<uint8> serialized(texSize);
std::memcpy(serialized.data(), texData, texSize); std::memcpy(serialized.data(), texData, texSize);
+2
View File
@@ -5,7 +5,9 @@ struct MeshData {
AABB bounding; AABB bounding;
uint32 numMeshlets = 0; uint32 numMeshlets = 0;
uint32 meshletOffset = 0; uint32 meshletOffset = 0;
// offset into the global index buffer
uint32 firstIndex = 0; uint32 firstIndex = 0;
// number of indices in the global index buffer
uint32 numIndices = 0; uint32 numIndices = 0;
}; };
struct InstanceData { struct InstanceData {
+6
View File
@@ -22,6 +22,7 @@ struct MeshId {
class VertexData { class VertexData {
public: public:
struct DrawCallOffsets { struct DrawCallOffsets {
// offset into the instanceData and meshData arrays
uint32 instanceOffset = 0; uint32 instanceOffset = 0;
uint32 textureOffset = 0; uint32 textureOffset = 0;
uint32 samplerOffset = 0; uint32 samplerOffset = 0;
@@ -91,11 +92,16 @@ class VertexData {
VertexData(); VertexData();
struct MeshletDescription { struct MeshletDescription {
AABB bounding; AABB bounding;
// number of relevant entries in the vertexIndices array
uint32 vertexCount; uint32 vertexCount;
// number of relevant entries in the primitiveIndices array
uint32 primitiveCount; uint32 primitiveCount;
// starting offset into the vertexIndices array
uint32 vertexOffset; uint32 vertexOffset;
// starting offset into the primitiveIndices array
uint32 primitiveOffset; uint32 primitiveOffset;
Vector color; Vector color;
// gets added to vertex indices so that they reference the global mesh bool
uint32 indicesOffset = 0; uint32 indicesOffset = 0;
}; };
std::mutex materialDataLock; std::mutex materialDataLock;
-1
View File
@@ -675,7 +675,6 @@ void Graphics::createDevice(GraphicsInitializer initializer) {
VK_CHECK(vkCreateDevice(physicalDevice, &deviceInfo, nullptr, &handle)); VK_CHECK(vkCreateDevice(physicalDevice, &deviceInfo, nullptr, &handle));
// std::cout << "Vulkan handle: " << handle << std::endl; // std::cout << "Vulkan handle: " << handle << std::endl;
graphicsQueue = 0; graphicsQueue = 0;
computeQueue = 0; computeQueue = 0;
transferQueue = 0; transferQueue = 0;
+19 -13
View File
@@ -12,7 +12,8 @@
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
BottomLevelAS::BottomLevelAS(PGraphics graphics, const Gfx::BottomLevelASCreateInfo& createInfo) : graphics(graphics) { BottomLevelAS::BottomLevelAS(PGraphics graphics, const Gfx::BottomLevelASCreateInfo& createInfo)
: graphics(graphics), material(createInfo.mesh->referencedMaterial->getHandle()) {
VertexData* vertexData = createInfo.mesh->vertexData; VertexData* vertexData = createInfo.mesh->vertexData;
MeshData meshData = vertexData->getMeshData(createInfo.mesh->id); MeshData meshData = vertexData->getMeshData(createInfo.mesh->id);
Gfx::PShaderBuffer positionBuffer = vertexData->getPositionBuffer(); Gfx::PShaderBuffer positionBuffer = vertexData->getPositionBuffer();
@@ -37,6 +38,8 @@ BottomLevelAS::BottomLevelAS(PGraphics graphics, const Gfx::BottomLevelASCreateI
}; };
OBufferAllocation transformBuffer = OBufferAllocation transformBuffer =
new BufferAllocation(graphics, "TransformBuffer", transformBufferInfo, transformAllocInfo, Gfx::QueueType::GRAPHICS); new BufferAllocation(graphics, "TransformBuffer", transformBufferInfo, transformAllocInfo, Gfx::QueueType::GRAPHICS);
transformBuffer->updateContents(0, sizeof(VkTransformMatrixKHR), &matrix);
VkDeviceOrHostAddressConstKHR vertexDataAddress = { VkDeviceOrHostAddressConstKHR vertexDataAddress = {
.deviceAddress = .deviceAddress =
positionBuffer.cast<ShaderBuffer>()->getDeviceAddress() + vertexData->getMeshOffset(createInfo.mesh->id) * sizeof(Vector4), positionBuffer.cast<ShaderBuffer>()->getDeviceAddress() + vertexData->getMeshOffset(createInfo.mesh->id) * sizeof(Vector4),
@@ -51,18 +54,21 @@ BottomLevelAS::BottomLevelAS(PGraphics graphics, const Gfx::BottomLevelASCreateI
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR, .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR,
.pNext = nullptr, .pNext = nullptr,
.geometryType = VK_GEOMETRY_TYPE_TRIANGLES_KHR, .geometryType = VK_GEOMETRY_TYPE_TRIANGLES_KHR,
.geometry = {.triangles = .geometry =
{ {
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR, .triangles =
.pNext = nullptr, {
.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT, .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR,
.vertexData = vertexDataAddress, .pNext = nullptr,
.vertexStride = sizeof(Vector), .vertexFormat = VK_FORMAT_R32G32B32_SFLOAT,
.maxVertex = static_cast<uint32_t>(createInfo.mesh->vertexCount), .vertexData = vertexDataAddress,
.indexType = VK_INDEX_TYPE_UINT32, .vertexStride = sizeof(Vector),
.indexData = indexDataAddress, .maxVertex = static_cast<uint32_t>(createInfo.mesh->vertexCount),
.transformData = transformDataAddress, .indexType = VK_INDEX_TYPE_UINT32,
}}, .indexData = indexDataAddress,
.transformData = transformDataAddress,
},
},
.flags = VK_GEOMETRY_OPAQUE_BIT_KHR, .flags = VK_GEOMETRY_OPAQUE_BIT_KHR,
}; };
VkAccelerationStructureBuildGeometryInfoKHR structureBuildGeometry = { VkAccelerationStructureBuildGeometryInfoKHR structureBuildGeometry = {
+1 -1
View File
@@ -16,7 +16,7 @@ class BottomLevelAS : public Gfx::BottomLevelAS {
PGraphics graphics; PGraphics graphics;
VkAccelerationStructureKHR handle; VkAccelerationStructureKHR handle;
OBufferAllocation buffer; OBufferAllocation buffer;
PMaterialInstance material;
}; };
DEFINE_REF(BottomLevelAS) DEFINE_REF(BottomLevelAS)
class TopLevelAS : public Gfx::TopLevelAS { class TopLevelAS : public Gfx::TopLevelAS {
+48276
View File
File diff suppressed because it is too large Load Diff
+59435
View File
File diff suppressed because it is too large Load Diff