More metal changes
This commit is contained in:
@@ -4,8 +4,8 @@ struct DispatchParams
|
||||
{
|
||||
uint3 numThreadGroups;
|
||||
uint pad0;
|
||||
uint3 numThreads;
|
||||
uint pad1;
|
||||
uint3 numThreads;
|
||||
uint pad1;
|
||||
RWStructuredBuffer<Frustum> frustums;
|
||||
};
|
||||
|
||||
|
||||
@@ -21,15 +21,15 @@ struct FragmentParameter
|
||||
{
|
||||
float4 position_CS : SV_Position;
|
||||
#ifndef POS_ONLY
|
||||
float3 normal_WS : NORMAL0;
|
||||
float3 tangent_WS : TANGENT0;
|
||||
float3 biTangent_WS : TANGENT1;
|
||||
float3 position_WS : POSITION2;
|
||||
float3 vertexColor : COLOR0;
|
||||
float4 texCoords0 : TEXCOORD0;
|
||||
float4 texCoords1 : TEXCOORD1;
|
||||
float4 texCoords2 : TEXCOORD2;
|
||||
float4 texCoords3 : TEXCOORD3;
|
||||
float3 normal_WS : NORMALWS;
|
||||
float3 tangent_WS : TANGENTWS;
|
||||
float3 biTangent_WS : BITANGENTWS;
|
||||
float3 position_WS : POSITIONWS;
|
||||
float3 vertexColor : COLOR;
|
||||
float4 texCoords0 : TEXCOORDS0;
|
||||
float4 texCoords1 : TEXCOORDS1;
|
||||
float4 texCoords2 : TEXCOORDS2;
|
||||
float4 texCoords3 : TEXCOORDS3;
|
||||
MaterialParameter getMaterialParameter()
|
||||
{
|
||||
MaterialParameter result;
|
||||
@@ -80,13 +80,6 @@ struct FragmentParameter
|
||||
}
|
||||
};
|
||||
|
||||
// data passed to visibility render
|
||||
struct VisibilityParameter
|
||||
{
|
||||
uint32_t triangleIndex : POSITION5;
|
||||
uint32_t meshletId : POSITION6;
|
||||
};
|
||||
|
||||
// data retrieved from VertexData
|
||||
struct VertexAttributes
|
||||
{
|
||||
|
||||
@@ -20,8 +20,8 @@ struct MeshData
|
||||
uint32_t numIndices;
|
||||
};
|
||||
|
||||
static const uint32_t MAX_VERTICES = 256;
|
||||
static const uint32_t MAX_PRIMITIVES = 256;
|
||||
static const uint32_t MAX_VERTICES = 64;
|
||||
static const uint32_t MAX_PRIMITIVES = 128;
|
||||
static const uint32_t MAX_MESHLETS_PER_INSTANCE = 2048;
|
||||
|
||||
struct InstanceData
|
||||
|
||||
@@ -159,8 +159,8 @@ static constexpr bool useAsyncCompute = false;
|
||||
static constexpr bool useMeshShading = true;
|
||||
static constexpr uint32 numFramesBuffered = 3;
|
||||
|
||||
static constexpr uint32 numVerticesPerMeshlet = 256;
|
||||
static constexpr uint32 numPrimitivesPerMeshlet = 256;
|
||||
static constexpr uint32 numVerticesPerMeshlet = 64;
|
||||
static constexpr uint32 numPrimitivesPerMeshlet = 126;
|
||||
double getCurrentFrameDelta();
|
||||
double getCurrentFrameTime();
|
||||
uint32 getCurrentFrameIndex();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "PipelineCache.h"
|
||||
#include "Descriptor.h"
|
||||
#include "Enums.h"
|
||||
#include "RenderPass.h"
|
||||
#include "Foundation/NSError.hpp"
|
||||
#include "Foundation/NSString.hpp"
|
||||
#include "Graphics.h"
|
||||
@@ -25,8 +26,7 @@ PipelineCache::PipelineCache(PGraphics graphics, const std::string& name) : grap
|
||||
PipelineCache::~PipelineCache() {}
|
||||
|
||||
PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
|
||||
PPipelineLayout layout = Gfx::PPipelineLayout(createInfo.pipelineLayout).cast<PipelineLayout>();
|
||||
|
||||
PRenderPass renderPass = createInfo.renderPass.cast<RenderPass>();
|
||||
MTL::RenderPipelineDescriptor* pipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
|
||||
|
||||
MTL::VertexDescriptor* vertexDescriptor = pipelineDescriptor->vertexDescriptor()->init();
|
||||
@@ -68,6 +68,16 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
|
||||
pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
|
||||
}
|
||||
pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology));
|
||||
for(uint c = 0; c < renderPass->getLayout().colorAttachments.size(); ++c) {
|
||||
const auto& color = renderPass->getLayout().colorAttachments[c];
|
||||
MTL::RenderPipelineColorAttachmentDescriptor* desc = MTL::RenderPipelineColorAttachmentDescriptor::alloc()->init();
|
||||
desc->setWriteMask(MTL::ColorWriteMaskAll);
|
||||
desc->setPixelFormat(cast(color.getFormat()));
|
||||
desc->setAlphaBlendOperation(MTL::BlendOperationAdd);
|
||||
desc->setDestinationAlphaBlendFactor(MTL::BlendFactorDestinationAlpha);
|
||||
desc->setBlendingEnabled(false);
|
||||
pipelineDescriptor->colorAttachments()->setObject(desc, c);
|
||||
}
|
||||
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
|
||||
pipelineDescriptor->setDepthAttachmentPixelFormat(
|
||||
cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
|
||||
@@ -131,6 +141,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
|
||||
}
|
||||
|
||||
PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
|
||||
PRenderPass renderPass = createInfo.renderPass.cast<RenderPass>();
|
||||
MTL::MeshRenderPipelineDescriptor* pipelineDescriptor = MTL::MeshRenderPipelineDescriptor::alloc()->init();
|
||||
|
||||
pipelineDescriptor->setMeshFunction(createInfo.meshShader.cast<MeshShader>()->getFunction());
|
||||
@@ -140,6 +151,16 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo crea
|
||||
if (createInfo.fragmentShader != nullptr) {
|
||||
pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
|
||||
}
|
||||
for(uint c = 0; c < renderPass->getLayout().colorAttachments.size(); ++c) {
|
||||
const auto& color = renderPass->getLayout().colorAttachments[c];
|
||||
MTL::RenderPipelineColorAttachmentDescriptor* desc = MTL::RenderPipelineColorAttachmentDescriptor::alloc()->init();
|
||||
desc->setWriteMask(MTL::ColorWriteMaskAll);
|
||||
desc->setPixelFormat(cast(color.getFormat()));
|
||||
desc->setAlphaBlendOperation(MTL::BlendOperationAdd);
|
||||
desc->setDestinationAlphaBlendFactor(MTL::BlendFactorDestinationAlpha);
|
||||
desc->setBlendingEnabled(false);
|
||||
pipelineDescriptor->colorAttachments()->setObject(desc, c);
|
||||
}
|
||||
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
|
||||
pipelineDescriptor->setDepthAttachmentPixelFormat(
|
||||
cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
|
||||
|
||||
@@ -90,7 +90,7 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic
|
||||
metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height);
|
||||
metalWindow.contentView.layer = metalLayer;
|
||||
metalWindow.contentView.wantsLayer = YES;
|
||||
framebufferFormat = Gfx::SE_FORMAT_R8G8B8A8_UNORM;
|
||||
framebufferFormat = Gfx::SE_FORMAT_B8G8R8A8_UNORM;
|
||||
|
||||
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||
createBackBuffer();
|
||||
|
||||
@@ -176,9 +176,14 @@ void DepthCullingPass::render() {
|
||||
command->bindPipeline(pipeline);
|
||||
}
|
||||
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(), set});
|
||||
uint32 offset = 0;
|
||||
VertexData::DrawCallOffsets offsets = {
|
||||
.instanceOffset = 0,
|
||||
.floatOffset = 0,
|
||||
.samplerOffset = 0,
|
||||
.textureOffset = 0,
|
||||
};
|
||||
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets),
|
||||
&offset);
|
||||
&offsets);
|
||||
if (graphics->supportMeshShading()) {
|
||||
command->drawMesh(vertexData->getNumInstances(), 1, 1);
|
||||
} else {
|
||||
|
||||
@@ -248,7 +248,7 @@ void LightCullingPass::setupFrustums() {
|
||||
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.uniformLength = sizeof(DispatchParams),
|
||||
.uniformLength = 56,//sizeof(DispatchParams),
|
||||
});
|
||||
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 1,
|
||||
@@ -264,6 +264,7 @@ void LightCullingPass::setupFrustums() {
|
||||
.modules = {"ComputeFrustums"},
|
||||
.entryPoints = {{"computeFrustums", "ComputeFrustums"}},
|
||||
.rootSignature = frustumLayout,
|
||||
.dumpIntermediate = true,
|
||||
};
|
||||
graphics->beginShaderCompilation(createInfo);
|
||||
frustumShader = graphics->createComputeShader({0});
|
||||
|
||||
@@ -7,7 +7,7 @@ RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene) : graphics(graphic
|
||||
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.uniformLength = sizeof(ViewParameter),
|
||||
.uniformLength = 576,//sizeof(ViewParameter),
|
||||
});
|
||||
UniformBufferCreateInfo uniformInitializer = {
|
||||
.sourceData =
|
||||
|
||||
@@ -8,7 +8,7 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics) : graphics(graphics)
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.uniformLength = sizeof(LightEnv)
|
||||
.uniformLength = 24,//sizeof(LightEnv)
|
||||
});
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 1,
|
||||
|
||||
Reference in New Issue
Block a user