mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:43:50 +02:00
Tried many different things to narrow down the issue of the corrupted memory, it seems to be linked to the grid dimendsions somehow, i m now forcing to reassign the frustum grid dimension on the 10th iteration which seems to fix the issue....
This commit is contained in:
parent
e6572a42e3
commit
ba88db1b14
11 changed files with 53 additions and 27 deletions
|
@ -42,7 +42,8 @@ Buffer::Size Buffer::getBufferGPUMemoryUsage() {
|
|||
}
|
||||
|
||||
Buffer::Buffer(Size pageSize) :
|
||||
_pages(pageSize) {
|
||||
_pages(pageSize),
|
||||
_renderPages(pageSize) {
|
||||
_bufferCPUCount++;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,10 +74,12 @@ ivec3 clusterGrid_getCluster(int index) {
|
|||
|
||||
int clusterGrid_getClusterLightId(int index, int offset) {
|
||||
int elementIndex = offset + index;
|
||||
/*
|
||||
int element = _clusterGridContent[GRID_FETCH_BUFFER(elementIndex)];
|
||||
return element;
|
||||
//int element = _clusterGridContent[GRID_FETCH_BUFFER(elementIndex)];
|
||||
// return (((elementIndex & 0x00000001) == 1) ? (element >> 16) : element) & 0x0000FFFF;
|
||||
*/
|
||||
int element = _clusterGridContent[GRID_FETCH_BUFFER((elementIndex >> 1))];
|
||||
return (((elementIndex & 0x00000001) == 1) ? (element >> 16) : element) & 0x0000FFFF;
|
||||
}
|
||||
|
||||
<@endif@>
|
||||
|
|
|
@ -101,9 +101,10 @@ void LightClusters::setDimensions(glm::uvec3 gridDims, uint32_t listBudget) {
|
|||
configDimensions.z = std::min(maxNumSlices, configDimensions.z);
|
||||
|
||||
|
||||
|
||||
static int numFrames = 0;
|
||||
numFrames++;
|
||||
auto& dims = _frustumGridBuffer->dims;
|
||||
if ((dims.x != configDimensions.x) || (dims.y != configDimensions.y) || (dims.z != configDimensions.z)) {
|
||||
if ((numFrames == 10) || (dims.x != configDimensions.x) || (dims.y != configDimensions.y) || (dims.z != configDimensions.z)) {
|
||||
_frustumGridBuffer.edit().dims = configDimensions;
|
||||
_frustumGridBuffer.edit().generateGridPlanes(_gridPlanes[0], _gridPlanes[1], _gridPlanes[2]);
|
||||
}
|
||||
|
@ -115,17 +116,23 @@ void LightClusters::setDimensions(glm::uvec3 gridDims, uint32_t listBudget) {
|
|||
_clusterGrid.resize(_numClusters, EMPTY_CLUSTER);
|
||||
// _clusterGridBuffer._size = _clusterGridBuffer._buffer->resize(_numClusters * sizeof(uint32_t));
|
||||
_clusterGridBuffer._size = (_numClusters * sizeof(uint32_t));
|
||||
_clusterGridBuffer._buffer = std::make_shared<gpu::Buffer>(_clusterGridBuffer._size, (gpu::Byte*) _clusterGrid.data()/*, _clusterGridBuffer._size*/);
|
||||
_clusterGridBuffer._buffer = std::make_shared<gpu::Buffer>(_clusterGridBuffer._size, (gpu::Byte*) _clusterGrid.data(), _clusterGridBuffer._size);
|
||||
}
|
||||
|
||||
auto configListBudget = std::min(MAX_GRID_DIMENSIONS.w, listBudget);
|
||||
if (configListBudget != _clusterContentBuffer.getNumElements()) {
|
||||
|
||||
// SInce LightINdex is 2bytes, we can fit 2 in a uint32
|
||||
if (sizeof(LightIndex) == 2) {
|
||||
configListBudget *= 2;
|
||||
}
|
||||
|
||||
if (configListBudget != _clusterContent.size()) {
|
||||
_clusterContent.clear();
|
||||
_clusterContent.resize(configListBudget, INVALID_LIGHT);
|
||||
// _clusterContentBuffer._size = _clusterContentBuffer._buffer->resize(configListBudget * sizeof(LightIndex));
|
||||
_clusterContentBuffer._size = (configListBudget * sizeof(LightIndex));
|
||||
// _clusterContentBuffer._buffer->setData(_clusterContentBuffer._size, (gpu::Byte*) _clusterContent.data());
|
||||
_clusterContentBuffer._buffer = std::make_shared<gpu::Buffer>(_clusterContentBuffer._size, (gpu::Byte*) _clusterContent.data()/*, _clusterContentBuffer._size*/);
|
||||
_clusterContentBuffer._buffer = std::make_shared<gpu::Buffer>(_clusterContentBuffer._size, (gpu::Byte*) _clusterContent.data(), _clusterContentBuffer._size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,7 +294,7 @@ uint32_t scanLightVolumeSphere(FrustumGrid& grid, const FrustumGrid::Planes plan
|
|||
return numClustersTouched;
|
||||
}
|
||||
|
||||
void LightClusters::updateClusters() {
|
||||
uint32_t LightClusters::updateClusters() {
|
||||
// Clean up last info
|
||||
std::vector< std::vector< LightIndex > > clusterGridPoint(_numClusters);
|
||||
std::vector< std::vector< LightIndex > > clusterGridSpot(_numClusters);
|
||||
|
@ -452,6 +459,8 @@ void LightClusters::updateClusters() {
|
|||
// update the buffers
|
||||
_clusterGridBuffer._buffer->setData(_clusterGridBuffer._size, (gpu::Byte*) _clusterGrid.data());
|
||||
_clusterContentBuffer._buffer->setSubData(0, indexOffset * sizeof(LightIndex), (gpu::Byte*) _clusterContent.data());
|
||||
|
||||
return numClusterTouched;
|
||||
}
|
||||
|
||||
|
||||
|
@ -492,9 +501,12 @@ void LightClusteringPass::run(const render::SceneContextPointer& sceneContext, c
|
|||
_lightClusters->updateLightStage(lightStage);
|
||||
_lightClusters->updateLightFrame(lightStage->_currentFrame, lightingModel->isPointLightEnabled(), lightingModel->isSpotLightEnabled());
|
||||
|
||||
_lightClusters->updateClusters();
|
||||
auto numClusterdLights = _lightClusters->updateClusters();
|
||||
|
||||
output = _lightClusters;
|
||||
|
||||
auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
|
||||
config->setNumClusteredLights(numClusterdLights);
|
||||
}
|
||||
|
||||
DebugLightClusters::DebugLightClusters() {
|
||||
|
|
|
@ -24,7 +24,8 @@ public:
|
|||
float rangeFar { 200.0f };
|
||||
float frustumFar { 10000.0f };
|
||||
|
||||
glm::ivec3 dims { 16, 12, 16 };
|
||||
// glm::ivec3 dims { 16, 16, 16 };
|
||||
glm::ivec3 dims { 16, 16, 16 };
|
||||
float spare;
|
||||
|
||||
glm::mat4 eyeToGridProj;
|
||||
|
@ -74,7 +75,7 @@ public:
|
|||
|
||||
void updateLightFrame(const LightStage::Frame& lightFrame, bool points = true, bool spots = true);
|
||||
|
||||
void updateClusters();
|
||||
uint32_t updateClusters();
|
||||
|
||||
ViewFrustum _frustum;
|
||||
|
||||
|
@ -94,15 +95,12 @@ public:
|
|||
const uint32_t EMPTY_CLUSTER { 0x0000FFFF };
|
||||
const LightID INVALID_LIGHT { LightStage::INVALID_INDEX };
|
||||
|
||||
using LightIndex = uint32_t;
|
||||
using LightIndex = uint16_t;
|
||||
|
||||
std::vector<uint32_t> _clusterGrid;
|
||||
std::vector<LightIndex> _clusterContent;
|
||||
gpu::BufferView _clusterGridBuffer;
|
||||
gpu::BufferView _clusterContentBuffer;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
using LightClustersPointer = std::shared_ptr<LightClusters>;
|
||||
|
@ -119,17 +117,26 @@ class LightClusteringPassConfig : public render::Job::Config {
|
|||
Q_PROPERTY(int dimZ MEMBER dimZ NOTIFY dirty)
|
||||
|
||||
Q_PROPERTY(bool freeze MEMBER freeze NOTIFY dirty)
|
||||
|
||||
Q_PROPERTY(int numClusteredLights MEMBER numClusteredLights NOTIFY dirty)
|
||||
public:
|
||||
LightClusteringPassConfig() : render::Job::Config(true){}
|
||||
float rangeNear{ 0.1f };
|
||||
float rangeFar{ 200.0f };
|
||||
|
||||
/*
|
||||
int dimX { 16 };
|
||||
int dimY { 16 };
|
||||
int dimZ { 16 };
|
||||
*/
|
||||
int dimX { 16 };
|
||||
int dimY { 16 };
|
||||
int dimZ { 16 };
|
||||
|
||||
|
||||
bool freeze{ false };
|
||||
|
||||
void setNumClusteredLights(int numLights) { numClusteredLights = numLights; emit dirty(); }
|
||||
int numClusteredLights { 0 };
|
||||
signals:
|
||||
void dirty();
|
||||
|
||||
|
@ -175,7 +182,8 @@ public:
|
|||
|
||||
bool doDrawGrid{ false };
|
||||
bool doDrawClusterFromDepth { false };
|
||||
bool doDrawContent { false };
|
||||
// bool doDrawContent { false };
|
||||
bool doDrawContent { true };
|
||||
|
||||
signals:
|
||||
void dirty();
|
||||
|
|
|
@ -136,7 +136,7 @@ LightStage::LightPointer LightStage::removeLight(Index index) {
|
|||
void LightStage::updateLightArrayBuffer(Index lightId) {
|
||||
auto lightSize = sizeof(model::Light::LightSchema);
|
||||
if (!_lightArrayBuffer) {
|
||||
_lightArrayBuffer = std::make_shared<gpu::Buffer>();
|
||||
_lightArrayBuffer = std::make_shared<gpu::Buffer>(lightSize);
|
||||
}
|
||||
|
||||
assert(checkLightId(lightId));
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
|
||||
<@include model/Light.slh@>
|
||||
|
||||
<$declareLightBuffer(120)$>
|
||||
<$declareLightBuffer(256)$>
|
||||
|
||||
uniform lightIndexBuffer {
|
||||
int lightIndex[120];
|
||||
int lightIndex[256];
|
||||
};
|
||||
|
||||
out vec4 _texCoord0;
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
<$declareStandardTransform()$>
|
||||
|
||||
<@include model/Light.slh@>
|
||||
<$declareLightBuffer(120)$>
|
||||
<$declareLightBuffer(256)$>
|
||||
|
||||
uniform lightIndexBuffer {
|
||||
int lightIndex[120];
|
||||
int lightIndex[256];
|
||||
};
|
||||
out vec4 _texCoord0;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
|
||||
<@include model/Light.slh@>
|
||||
<$declareLightBuffer(128)$>
|
||||
<$declareLightBuffer(256)$>
|
||||
|
||||
<@include LightClusterGrid.slh@>
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
// Everything about light
|
||||
<@include model/Light.slh@>
|
||||
<$declareLightBuffer(128)$>
|
||||
<$declareLightBuffer(256)$>
|
||||
<@include LightingModel.slh@>
|
||||
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
// Everything about light
|
||||
<@include model/Light.slh@>
|
||||
<$declareLightBuffer(32)$>
|
||||
<$declareLightBuffer(256)$>
|
||||
uniform lightIndexBuffer {
|
||||
int lightIndex[32];
|
||||
int lightIndex[256];
|
||||
};
|
||||
<@include LightingModel.slh@>
|
||||
|
||||
|
|
|
@ -106,6 +106,9 @@ Column {
|
|||
checked: Render.getConfig("DebugLightClusters")["doDrawContent"]
|
||||
onCheckedChanged: { Render.getConfig("DebugLightClusters")["doDrawContent"] = checked }
|
||||
}
|
||||
Label {
|
||||
text: "Num Cluster Items = " + Render.getConfig("LightClustering")["numClusteredLights"].toFixed(0)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue