system still crashes
This commit is contained in:
@@ -114,6 +114,7 @@ class CommandQueue {
|
||||
MTL::CommandQueue* queue;
|
||||
OCommand activeCommand;
|
||||
Array<OCommand> pendingCommands;
|
||||
Array<OCommand> readyCommands;
|
||||
};
|
||||
class IOCommandQueue {
|
||||
public:
|
||||
|
||||
@@ -40,7 +40,10 @@ void Command::present(MTL::Drawable* drawable) { cmdBuffer->presentDrawable(draw
|
||||
|
||||
void Command::end(PEvent signal) {
|
||||
assert(!parallelEncoder);
|
||||
blitEncoder->endEncoding();
|
||||
if(blitEncoder)
|
||||
{
|
||||
blitEncoder->endEncoding();
|
||||
}
|
||||
if (signal != nullptr) {
|
||||
cmdBuffer->encodeSignalEvent(signal->getHandle(), 1);
|
||||
}
|
||||
@@ -48,7 +51,9 @@ void Command::end(PEvent signal) {
|
||||
cmdBuffer->commit();
|
||||
}
|
||||
|
||||
void Command::waitDeviceIdle() { cmdBuffer->waitUntilCompleted(); }
|
||||
void Command::waitDeviceIdle() {
|
||||
cmdBuffer->waitUntilCompleted();
|
||||
}
|
||||
|
||||
void Command::signalEvent(PEvent event) { cmdBuffer->encodeSignalEvent(event->getHandle(), 1); }
|
||||
|
||||
@@ -194,6 +199,7 @@ void ComputeCommand::dispatchIndirect(Gfx::PShaderBuffer buffer, uint32 offset){
|
||||
CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
|
||||
queue = graphics->getDevice()->newCommandQueue();
|
||||
MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
|
||||
descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus);
|
||||
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
|
||||
descriptor->release();
|
||||
}
|
||||
@@ -214,7 +220,6 @@ void CommandQueue::executeCommands(Array<Gfx::ORenderCommand> commands) {
|
||||
}
|
||||
|
||||
void CommandQueue::executeCommands(Array<Gfx::OComputeCommand> commands) {
|
||||
submitCommands();
|
||||
for (auto& command : commands) {
|
||||
auto metalCmd = Gfx::PComputeCommand(command).cast<ComputeCommand>();
|
||||
metalCmd->end();
|
||||
@@ -225,7 +230,8 @@ void CommandQueue::submitCommands(PEvent signalSemaphore) {
|
||||
activeCommand->getHandle()->addCompletedHandler(MTL::CommandBufferHandler([&](MTL::CommandBuffer* cmdBuffer) {
|
||||
for (auto it = pendingCommands.begin(); it != pendingCommands.end(); it++) {
|
||||
if ((*it)->getHandle() == cmdBuffer) {
|
||||
pendingCommands.remove(it);
|
||||
readyCommands.add(std::move(*it));
|
||||
pendingCommands.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -234,10 +240,20 @@ void CommandQueue::submitCommands(PEvent signalSemaphore) {
|
||||
activeCommand->waitDeviceIdle();
|
||||
PEvent prevCmdEvent = activeCommand->getCompletedEvent();
|
||||
pendingCommands.add(std::move(activeCommand));
|
||||
MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
|
||||
descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus);
|
||||
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
|
||||
activeCommand->waitForEvent(prevCmdEvent);
|
||||
if(!readyCommands.empty())
|
||||
{
|
||||
activeCommand = std::move(readyCommands.front());
|
||||
readyCommands.removeAt(0);
|
||||
activeCommand->waitForEvent(prevCmdEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
|
||||
descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus);
|
||||
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
|
||||
activeCommand->waitForEvent(prevCmdEvent);
|
||||
descriptor->release();
|
||||
}
|
||||
}
|
||||
|
||||
IOCommandQueue::IOCommandQueue(PGraphics graphics) : graphics(graphics) {
|
||||
|
||||
@@ -46,7 +46,9 @@ void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) { queue->getCommands
|
||||
|
||||
void Graphics::endRenderPass() { queue->getCommands()->endRenderPass(); }
|
||||
|
||||
void Graphics::waitDeviceIdle() { queue->getCommands()->waitDeviceIdle(); }
|
||||
void Graphics::waitDeviceIdle() {
|
||||
queue->submitCommands();
|
||||
}
|
||||
|
||||
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands) { queue->executeCommands(std::move(commands)); }
|
||||
|
||||
|
||||
@@ -134,6 +134,7 @@ void CachedDepthPass::render() {
|
||||
|
||||
graphics->executeCommands(std::move(commands));
|
||||
graphics->endRenderPass();
|
||||
graphics->waitDeviceIdle();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "CachedEnd");
|
||||
query->endQuery();
|
||||
}
|
||||
|
||||
@@ -270,7 +270,6 @@ void LightCullingPass::setupFrustums() {
|
||||
frustumShader = graphics->createComputeShader({0});
|
||||
// Have to compile shader before finalizing layout as parameters get mapped later
|
||||
frustumLayout->create();
|
||||
dispatchParamsLayout->create();
|
||||
|
||||
Gfx::ComputePipelineCreateInfo pipelineInfo;
|
||||
pipelineInfo.computeShader = frustumShader;
|
||||
@@ -301,6 +300,7 @@ void LightCullingPass::setupFrustums() {
|
||||
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
graphics->waitDeviceIdle();
|
||||
Gfx::PDescriptorSet dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
|
||||
dispatchParamsSet->updateBuffer(0, 0, frustumDispatchParamsBuffer);
|
||||
dispatchParamsSet->updateBuffer(1, 0, frustumBuffer);
|
||||
@@ -315,4 +315,7 @@ void LightCullingPass::setupFrustums() {
|
||||
graphics->executeCommands(std::move(commands));
|
||||
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
graphics->waitDeviceIdle();
|
||||
Frustum* frustums = (Frustum*)frustumBuffer->map();
|
||||
std::cout << frustums << std::endl;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ RenderPass::RenderPass(Gfx::PGraphics graphics) : graphics(graphics) {
|
||||
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.uniformLength = 576,//sizeof(ViewParameter),
|
||||
.uniformLength = sizeof(ViewParameter),
|
||||
});
|
||||
UniformBufferCreateInfo uniformInitializer = {
|
||||
.sourceData =
|
||||
@@ -28,28 +28,6 @@ void RenderPass::beginFrame(const Component::Camera& cam) {
|
||||
Matrix4 cameraMatrix = cam.getViewMatrix();
|
||||
Matrix4 projectionMatrix = viewport->getProjectionMatrix();
|
||||
viewParams = {
|
||||
.viewFrustum =
|
||||
{
|
||||
.planes =
|
||||
{
|
||||
Plane{
|
||||
.n = Vector(-0.62628, 0, 0.7796),
|
||||
.d = 3.898,
|
||||
},
|
||||
Plane{
|
||||
.n = Vector(0.62628, 0, 0.7796),
|
||||
.d = 3.898,
|
||||
},
|
||||
Plane{
|
||||
.n = Vector(0, 0.81915, 0.57358),
|
||||
.d = 2.86788,
|
||||
},
|
||||
Plane{
|
||||
.n = Vector(0, -0.81915, 0.57358),
|
||||
.d = 2.86788,
|
||||
},
|
||||
},
|
||||
},
|
||||
.viewMatrix = cameraMatrix,
|
||||
.inverseViewMatrix = glm::inverse(cameraMatrix),
|
||||
.projectionMatrix = projectionMatrix,
|
||||
@@ -82,7 +60,7 @@ void RenderPass::beginFrame(const Component::Camera& cam) {
|
||||
corners[i] = world / world.w;
|
||||
}
|
||||
|
||||
extract_planes_from_view_projection_matrix(viewParams.viewProjectionMatrix, viewParams.viewFrustum);
|
||||
//extract_planes_from_view_projection_matrix(viewParams.viewProjectionMatrix, viewParams.viewFrustum);
|
||||
|
||||
viewParamsBuffer->rotateBuffer(sizeof(ViewParameter));
|
||||
viewParamsBuffer->updateContents(0, sizeof(ViewParameter), &viewParams);
|
||||
|
||||
@@ -50,7 +50,6 @@ class RenderPass {
|
||||
void extract_planes_from_view_projection_matrix(const Matrix4 viewProj, Frustum& frustum);
|
||||
|
||||
struct ViewParameter {
|
||||
Frustum viewFrustum;
|
||||
Matrix4 viewMatrix;
|
||||
Matrix4 inverseViewMatrix;
|
||||
Matrix4 projectionMatrix;
|
||||
@@ -63,6 +62,8 @@ class RenderPass {
|
||||
Vector2 invScreenDimensions;
|
||||
uint32 frameIndex;
|
||||
float time;
|
||||
uint32 pad0;
|
||||
uint32 pad1;
|
||||
} viewParams;
|
||||
PRenderGraphResources resources;
|
||||
Gfx::ODescriptorLayout viewParamsLayout;
|
||||
|
||||
@@ -125,6 +125,7 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
|
||||
}
|
||||
//createInfo.typeParameter.add({Pair<const char*, const char*>("IVertexData", permutation.vertexDataName)});
|
||||
createInfo.modules.add(permutation.vertexDataName);
|
||||
//createInfo.dumpIntermediate = true;
|
||||
|
||||
if (permutation.useMeshShading) {
|
||||
if (permutation.hasTaskShader) {
|
||||
|
||||
Reference in New Issue
Block a user