Initialize all metal objects properly
This commit is contained in:
parent
93c2639539
commit
c5713938ca
1 changed files with 18 additions and 17 deletions
|
@ -229,7 +229,7 @@ void* GFXMetal::get_buffer_contents(GFXBuffer* buffer) {
|
|||
GFXTexture* GFXMetal::create_texture(const GFXTextureCreateInfo& info) {
|
||||
GFXMetalTexture* texture = new GFXMetalTexture();
|
||||
|
||||
MTL::TextureDescriptor* textureDescriptor = MTL::TextureDescriptor::alloc();
|
||||
MTL::TextureDescriptor* textureDescriptor = MTL::TextureDescriptor::alloc()->init();
|
||||
|
||||
MTL::PixelFormat mtlFormat = toPixelFormat(info.format);
|
||||
|
||||
|
@ -275,7 +275,8 @@ GFXTexture* GFXMetal::create_texture(const GFXTextureCreateInfo& info) {
|
|||
|
||||
textureDescriptor->setPixelFormat(mtlFormat);
|
||||
textureDescriptor->setWidth(info.width);
|
||||
textureDescriptor->setWidth(info.height);
|
||||
textureDescriptor->setHeight(info.height);
|
||||
textureDescriptor->setDepth(1);
|
||||
textureDescriptor->setArrayLength(info.array_length);
|
||||
|
||||
texture->array_length = info.array_length;
|
||||
|
@ -289,7 +290,7 @@ GFXTexture* GFXMetal::create_texture(const GFXTextureCreateInfo& info) {
|
|||
texture->width = info.width;
|
||||
texture->height = info.height;
|
||||
|
||||
MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc();
|
||||
MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init();
|
||||
samplerDescriptor->setMinFilter(MTL::SamplerMinMagFilterLinear);
|
||||
samplerDescriptor->setMagFilter(MTL::SamplerMinMagFilterLinear);
|
||||
samplerDescriptor->setSAddressMode(toSamplingMode(info.samplingMode));
|
||||
|
@ -367,7 +368,7 @@ void GFXMetal::copy_texture(GFXTexture* from, GFXBuffer* to) {
|
|||
GFXSampler* GFXMetal::create_sampler(const GFXSamplerCreateInfo& info) {
|
||||
GFXMetalSampler* sampler = new GFXMetalSampler();
|
||||
|
||||
MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc();
|
||||
MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init();
|
||||
samplerDescriptor->setMinFilter(toFilter(info.min_filter));
|
||||
samplerDescriptor->setMagFilter(toFilter(info.mag_filter));
|
||||
samplerDescriptor->setSAddressMode(toSamplingMode(info.samplingMode));
|
||||
|
@ -406,7 +407,7 @@ GFXRenderPass* GFXMetal::create_render_pass(const GFXRenderPassCreateInfo& info)
|
|||
}
|
||||
|
||||
MTL::FunctionConstantValues* get_constant_values(GFXShaderConstants constants) {
|
||||
MTL::FunctionConstantValues* constantValues = MTL::FunctionConstantValues::alloc();
|
||||
MTL::FunctionConstantValues* constantValues = MTL::FunctionConstantValues::alloc()->init();
|
||||
|
||||
for(auto& constant : constants) {
|
||||
switch(constant.type) {
|
||||
|
@ -424,7 +425,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
|||
|
||||
NS::Error* error = nil;
|
||||
|
||||
MTL::RenderPipelineDescriptor* pipelineDescriptor = MTL::RenderPipelineDescriptor::alloc();
|
||||
MTL::RenderPipelineDescriptor* pipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
|
||||
|
||||
const bool has_vertex_stage = !info.shaders.vertex_src.empty();
|
||||
const bool has_fragment_stage = !info.shaders.fragment_src.empty();
|
||||
|
@ -493,11 +494,11 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
|||
pipelineDescriptor->setFragmentFunction(fragmentFunc);
|
||||
}
|
||||
|
||||
MTL::VertexDescriptor* descriptor = MTL::VertexDescriptor::alloc();
|
||||
MTL::VertexDescriptor* descriptor = MTL::VertexDescriptor::alloc()->init();
|
||||
|
||||
int i = 0;
|
||||
for(auto input : info.vertex_input.inputs) {
|
||||
MTL::VertexBufferLayoutDescriptor* inputDescriptor = MTL::VertexBufferLayoutDescriptor::alloc();
|
||||
MTL::VertexBufferLayoutDescriptor* inputDescriptor = MTL::VertexBufferLayoutDescriptor::alloc()->init();
|
||||
inputDescriptor->setStride(input.stride);
|
||||
inputDescriptor->setStepFunction(MTL::VertexStepFunctionPerVertex);
|
||||
|
||||
|
@ -536,7 +537,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
|||
break;
|
||||
}
|
||||
|
||||
MTL::VertexAttributeDescriptor* attributeDescriptor = MTL::VertexAttributeDescriptor::alloc();
|
||||
MTL::VertexAttributeDescriptor* attributeDescriptor = MTL::VertexAttributeDescriptor::alloc()->init();
|
||||
attributeDescriptor->setFormat(format);
|
||||
attributeDescriptor->setBufferIndex(attribute.binding);
|
||||
attributeDescriptor->setOffset(attribute.offset);
|
||||
|
@ -552,7 +553,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
|||
unsigned int i = 0;
|
||||
for(const auto& attachment : metalRenderPass->attachments) {
|
||||
if(attachment != MTL::PixelFormatDepth32Float) {
|
||||
MTL::RenderPipelineColorAttachmentDescriptor* colorAttachmentDescriptor = MTL::RenderPipelineColorAttachmentDescriptor::alloc();
|
||||
MTL::RenderPipelineColorAttachmentDescriptor* colorAttachmentDescriptor = MTL::RenderPipelineColorAttachmentDescriptor::alloc()->init();
|
||||
|
||||
colorAttachmentDescriptor->setPixelFormat(attachment);
|
||||
colorAttachmentDescriptor->setBlendingEnabled(info.blending.enable_blending);
|
||||
|
@ -569,7 +570,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
|||
}
|
||||
}
|
||||
} else {
|
||||
MTL::RenderPipelineColorAttachmentDescriptor* colorAttachmentDescriptor = MTL::RenderPipelineColorAttachmentDescriptor::alloc();
|
||||
MTL::RenderPipelineColorAttachmentDescriptor* colorAttachmentDescriptor = MTL::RenderPipelineColorAttachmentDescriptor::alloc()->init();
|
||||
|
||||
//colorAttachmentDescriptor->setPixelFormat(attachment); [nativeViews[0]->layer pixelFormat];
|
||||
colorAttachmentDescriptor->setBlendingEnabled(info.blending.enable_blending);
|
||||
|
@ -610,7 +611,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
|||
|
||||
pipeline->winding_mode = info.rasterization.winding_mode;
|
||||
|
||||
MTL::DepthStencilDescriptor* depthStencil = MTL::DepthStencilDescriptor::alloc();
|
||||
MTL::DepthStencilDescriptor* depthStencil = MTL::DepthStencilDescriptor::alloc()->init();
|
||||
|
||||
if(info.depth.depth_mode != GFXDepthMode::None) {
|
||||
switch(info.depth.depth_mode) {
|
||||
|
@ -677,7 +678,7 @@ GFXPipeline* GFXMetal::create_compute_pipeline(const GFXComputePipelineCreateInf
|
|||
|
||||
MTL::Function* computeFunc = computeLibrary->newFunction(NS::String::string("main0", NS::ASCIIStringEncoding));
|
||||
|
||||
MTL::ComputePipelineDescriptor* pipelineDescriptor = MTL::ComputePipelineDescriptor::alloc();
|
||||
MTL::ComputePipelineDescriptor* pipelineDescriptor = MTL::ComputePipelineDescriptor::alloc()->init();
|
||||
pipelineDescriptor->setComputeFunction(computeFunc);
|
||||
|
||||
pipeline->threadGroupSize = MTL::Size(info.workgroup_size_x, info.workgroup_size_y, info.workgroup_size_z);
|
||||
|
@ -771,20 +772,20 @@ void GFXMetal::submit(GFXCommandBuffer* command_buffer, const platform::window_p
|
|||
break;
|
||||
case CurrentEncoder::Render:
|
||||
{
|
||||
MTL::RenderPassDescriptor* descriptor = MTL::RenderPassDescriptor::alloc();
|
||||
MTL::RenderPassDescriptor* descriptor = MTL::RenderPassDescriptor::alloc()->init();
|
||||
|
||||
if(currentRenderPass != nullptr && currentFramebuffer != nullptr) {
|
||||
unsigned int i = 0;
|
||||
for(const auto& attachment : currentFramebuffer->attachments) {
|
||||
if(attachment->format == MTL::PixelFormatDepth32Float) {
|
||||
MTL::RenderPassDepthAttachmentDescriptor* depthAttachment = MTL::RenderPassDepthAttachmentDescriptor::alloc();
|
||||
MTL::RenderPassDepthAttachmentDescriptor* depthAttachment = MTL::RenderPassDepthAttachmentDescriptor::alloc()->init();
|
||||
depthAttachment->setTexture(attachment->handle);
|
||||
depthAttachment->setLoadAction(MTL::LoadActionClear);
|
||||
depthAttachment->setStoreAction(MTL::StoreActionStore);
|
||||
|
||||
descriptor->setDepthAttachment(depthAttachment);
|
||||
} else {
|
||||
MTL::RenderPassColorAttachmentDescriptor* colorAttachment = MTL::RenderPassColorAttachmentDescriptor::alloc();
|
||||
MTL::RenderPassColorAttachmentDescriptor* colorAttachment = MTL::RenderPassColorAttachmentDescriptor::alloc()->init();
|
||||
|
||||
colorAttachment->setTexture(attachment->handle);
|
||||
colorAttachment->setLoadAction(MTL::LoadActionClear);
|
||||
|
@ -797,7 +798,7 @@ void GFXMetal::submit(GFXCommandBuffer* command_buffer, const platform::window_p
|
|||
|
||||
renderEncoder = commandBuffer->renderCommandEncoder(descriptor);
|
||||
} else {
|
||||
MTL::RenderPassColorAttachmentDescriptor* colorAttachment = MTL::RenderPassColorAttachmentDescriptor::alloc();
|
||||
MTL::RenderPassColorAttachmentDescriptor* colorAttachment = MTL::RenderPassColorAttachmentDescriptor::alloc()->init();
|
||||
|
||||
//colorAttachment->setTexture(attachment->handle); drawable.texture
|
||||
colorAttachment->setLoadAction(MTL::LoadActionClear);
|
||||
|
|
Reference in a new issue