Archived
1
Fork 0

Remove default arguments in GFX api

This commit is contained in:
Joshua Goins 2022-02-21 00:16:02 -05:00
parent 0265f1920e
commit ea3049cb8a
4 changed files with 33 additions and 33 deletions

View file

@ -46,9 +46,9 @@ public:
GFXSize get_alignment(GFXSize size) override; GFXSize get_alignment(GFXSize size) override;
GFXCommandBuffer* acquire_command_buffer(bool for_presentation_use = false) override; GFXCommandBuffer* acquire_command_buffer(bool for_presentation_use) override;
void submit(GFXCommandBuffer* command_buffer, platform::window_ptr window = nullptr) override; void submit(GFXCommandBuffer* command_buffer, platform::window_ptr window) override;
private: private:
struct NativeMTLView { struct NativeMTLView {

View file

@ -169,7 +169,7 @@ bool GFXMetal::supports_feature(const GFXFeature feature) {
} }
void GFXMetal::initialize_view(void* native_handle, const platform::window_ptr identifier, const uint32_t, const uint32_t) { void GFXMetal::initialize_view(void* native_handle, const platform::window_ptr identifier, const uint32_t, const uint32_t) {
NativeMTLView* native = new NativeMTLView(); auto native = new NativeMTLView();
native->identifier = identifier; native->identifier = identifier;
native->format = (MTL::PixelFormat)platform::initialize_metal_layer(identifier, device); native->format = (MTL::PixelFormat)platform::initialize_metal_layer(identifier, device);
@ -184,7 +184,7 @@ void GFXMetal::remove_view(const platform::window_ptr identifier) {
} }
GFXBuffer* GFXMetal::create_buffer(void* data, const GFXSize size, const bool dynamicData, const GFXBufferUsage) { GFXBuffer* GFXMetal::create_buffer(void* data, const GFXSize size, const bool dynamicData, const GFXBufferUsage) {
GFXMetalBuffer* buffer = new GFXMetalBuffer(); auto buffer = new GFXMetalBuffer();
buffer->dynamicData = dynamicData; buffer->dynamicData = dynamicData;
if(buffer->dynamicData) { if(buffer->dynamicData) {
@ -209,22 +209,22 @@ GFXBuffer* GFXMetal::create_buffer(void* data, const GFXSize size, const bool dy
int currentFrameIndex = 0; int currentFrameIndex = 0;
void GFXMetal::copy_buffer(GFXBuffer* buffer, void* data, const GFXSize offset, const GFXSize size) { void GFXMetal::copy_buffer(GFXBuffer* buffer, void* data, const GFXSize offset, const GFXSize size) {
GFXMetalBuffer* metalBuffer = (GFXMetalBuffer*)buffer; auto metalBuffer = (GFXMetalBuffer*)buffer;
const unsigned char * src = reinterpret_cast<const unsigned char*>(data); auto src = reinterpret_cast<const unsigned char*>(data);
unsigned char * dest = reinterpret_cast<unsigned char *>(metalBuffer->get(currentFrameIndex)->contents()); auto dest = reinterpret_cast<unsigned char *>(metalBuffer->get(currentFrameIndex)->contents());
if(dest != nullptr) if(dest != nullptr)
memcpy(dest + offset, src, size); memcpy(dest + offset, src, size);
} }
void* GFXMetal::get_buffer_contents(GFXBuffer* buffer) { void* GFXMetal::get_buffer_contents(GFXBuffer* buffer) {
GFXMetalBuffer* metalBuffer = (GFXMetalBuffer*)buffer; auto metalBuffer = (GFXMetalBuffer*)buffer;
return reinterpret_cast<unsigned char *>(metalBuffer->get(currentFrameIndex)->contents()); return reinterpret_cast<unsigned char *>(metalBuffer->get(currentFrameIndex)->contents());
} }
GFXTexture* GFXMetal::create_texture(const GFXTextureCreateInfo& info) { GFXTexture* GFXMetal::create_texture(const GFXTextureCreateInfo& info) {
GFXMetalTexture* texture = new GFXMetalTexture(); auto texture = new GFXMetalTexture();
MTL::TextureDescriptor* textureDescriptor = MTL::TextureDescriptor::alloc()->init(); MTL::TextureDescriptor* textureDescriptor = MTL::TextureDescriptor::alloc()->init();
@ -312,7 +312,7 @@ GFXTexture* GFXMetal::create_texture(const GFXTextureCreateInfo& info) {
} }
void GFXMetal::copy_texture(GFXTexture* texture, void* data, const GFXSize) { void GFXMetal::copy_texture(GFXTexture* texture, void* data, const GFXSize) {
GFXMetalTexture* metalTexture = (GFXMetalTexture*)texture; auto metalTexture = (GFXMetalTexture*)texture;
MTL::Region region = {}; MTL::Region region = {};
region.size.width = texture->width; region.size.width = texture->width;
@ -329,8 +329,8 @@ void GFXMetal::copy_texture(GFXTexture* texture, void* data, const GFXSize) {
} }
void GFXMetal::copy_texture(GFXTexture* from, GFXTexture* to) { void GFXMetal::copy_texture(GFXTexture* from, GFXTexture* to) {
GFXMetalTexture* metalFromTexture = (GFXMetalTexture*)from; auto metalFromTexture = (GFXMetalTexture*)from;
GFXMetalTexture* metalToTexture = (GFXMetalTexture*)to; auto metalToTexture = (GFXMetalTexture*)to;
MTL::CommandBuffer* commandBuffer = command_queue->commandBuffer(); MTL::CommandBuffer* commandBuffer = command_queue->commandBuffer();
MTL::BlitCommandEncoder* commandEncoder = commandBuffer->blitCommandEncoder(); MTL::BlitCommandEncoder* commandEncoder = commandBuffer->blitCommandEncoder();
@ -341,15 +341,15 @@ void GFXMetal::copy_texture(GFXTexture* from, GFXTexture* to) {
} }
void GFXMetal::copy_texture(GFXTexture* from, GFXBuffer* to) { void GFXMetal::copy_texture(GFXTexture* from, GFXBuffer* to) {
GFXMetalTexture* metalFromTexture = (GFXMetalTexture*)from; auto metalFromTexture = (GFXMetalTexture*)from;
GFXMetalBuffer* metalToBuffer = (GFXMetalBuffer*)to; auto metalToBuffer = (GFXMetalBuffer*)to;
MTL::Origin origin; MTL::Origin origin = {};
origin.x = 0; origin.x = 0;
origin.y = 0; origin.y = 0;
origin.z = 0; origin.z = 0;
MTL::Size size; MTL::Size size = {};
size.width = from->width; size.width = from->width;
size.height = from->height; size.height = from->height;
size.depth = 1; size.depth = 1;
@ -367,7 +367,7 @@ void GFXMetal::copy_texture(GFXTexture* from, GFXBuffer* to) {
} }
GFXSampler* GFXMetal::create_sampler(const GFXSamplerCreateInfo& info) { GFXSampler* GFXMetal::create_sampler(const GFXSamplerCreateInfo& info) {
GFXMetalSampler* sampler = new GFXMetalSampler(); auto sampler = new GFXMetalSampler();
MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init(); MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init();
samplerDescriptor->setMinFilter(toFilter(info.min_filter)); samplerDescriptor->setMinFilter(toFilter(info.min_filter));
@ -390,7 +390,7 @@ GFXSampler* GFXMetal::create_sampler(const GFXSamplerCreateInfo& info) {
} }
GFXFramebuffer* GFXMetal::create_framebuffer(const GFXFramebufferCreateInfo& info) { GFXFramebuffer* GFXMetal::create_framebuffer(const GFXFramebufferCreateInfo& info) {
GFXMetalFramebuffer* framebuffer = new GFXMetalFramebuffer(); auto framebuffer = new GFXMetalFramebuffer();
for(auto& attachment : info.attachments) for(auto& attachment : info.attachments)
framebuffer->attachments.push_back((GFXMetalTexture*)attachment); framebuffer->attachments.push_back((GFXMetalTexture*)attachment);
@ -399,7 +399,7 @@ GFXFramebuffer* GFXMetal::create_framebuffer(const GFXFramebufferCreateInfo& inf
} }
GFXRenderPass* GFXMetal::create_render_pass(const GFXRenderPassCreateInfo& info) { GFXRenderPass* GFXMetal::create_render_pass(const GFXRenderPassCreateInfo& info) {
GFXMetalRenderPass* renderPass = new GFXMetalRenderPass(); auto renderPass = new GFXMetalRenderPass();
for(const auto& attachment : info.attachments) for(const auto& attachment : info.attachments)
renderPass->attachments.push_back(toPixelFormat(attachment)); renderPass->attachments.push_back(toPixelFormat(attachment));
@ -422,7 +422,7 @@ MTL::FunctionConstantValues* get_constant_values(GFXShaderConstants constants) {
} }
GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateInfo& info) { GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateInfo& info) {
GFXMetalPipeline* pipeline = new GFXMetalPipeline(); auto pipeline = new GFXMetalPipeline();
pipeline->label = info.label; pipeline->label = info.label;
NS::Error* error = nullptr; NS::Error* error = nullptr;
@ -506,7 +506,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
inputDescriptor->setStepFunction(MTL::VertexStepFunctionPerVertex); inputDescriptor->setStepFunction(MTL::VertexStepFunctionPerVertex);
inputDescriptor->setStepRate(1); inputDescriptor->setStepRate(1);
GFXMetalPipeline::VertexStride vs; GFXMetalPipeline::VertexStride vs = {};
vs.location = input.location; vs.location = input.location;
vs.stride = input.stride; vs.stride = input.stride;
@ -545,7 +545,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
pipelineDescriptor->setVertexDescriptor(descriptor); pipelineDescriptor->setVertexDescriptor(descriptor);
if(info.render_pass != nullptr) { if(info.render_pass != nullptr) {
GFXMetalRenderPass* metalRenderPass = (GFXMetalRenderPass*)info.render_pass; auto metalRenderPass = (GFXMetalRenderPass*)info.render_pass;
unsigned int i = 0; unsigned int i = 0;
for(const auto& attachment : metalRenderPass->attachments) { for(const auto& attachment : metalRenderPass->attachments) {
@ -636,7 +636,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
} }
GFXPipeline* GFXMetal::create_compute_pipeline(const GFXComputePipelineCreateInfo& info) { GFXPipeline* GFXMetal::create_compute_pipeline(const GFXComputePipelineCreateInfo& info) {
GFXMetalPipeline* pipeline = new GFXMetalPipeline(); auto pipeline = new GFXMetalPipeline();
NS::Error* error = nullptr; NS::Error* error = nullptr;
@ -730,7 +730,7 @@ void GFXMetal::submit(GFXCommandBuffer* command_buffer, const platform::window_p
GFXMetalBuffer* currentIndexBuffer = nullptr; GFXMetalBuffer* currentIndexBuffer = nullptr;
IndexType currentIndextype = IndexType::UINT32; IndexType currentIndextype = IndexType::UINT32;
MTL::Viewport currentViewport = MTL::Viewport(); MTL::Viewport currentViewport = MTL::Viewport();
MTL::ClearColor currentClearColor; MTL::ClearColor currentClearColor = {};
enum class CurrentEncoder { enum class CurrentEncoder {
None, None,
@ -990,8 +990,8 @@ void GFXMetal::submit(GFXCommandBuffer* command_buffer, const platform::window_p
{ {
needEncoder(CurrentEncoder::Blit); needEncoder(CurrentEncoder::Blit);
GFXMetalTexture* metalFromTexture = (GFXMetalTexture*)command.data.copy_texture.src; auto metalFromTexture = (GFXMetalTexture*)command.data.copy_texture.src;
GFXMetalTexture* metalToTexture = (GFXMetalTexture*)command.data.copy_texture.dst; auto metalToTexture = (GFXMetalTexture*)command.data.copy_texture.dst;
if(metalFromTexture != nullptr && metalToTexture != nullptr) { if(metalFromTexture != nullptr && metalToTexture != nullptr) {
const int slice_offset = command.data.copy_texture.to_slice + command.data.copy_texture.to_layer * 6; const int slice_offset = command.data.copy_texture.to_slice + command.data.copy_texture.to_layer * 6;
@ -1009,7 +1009,7 @@ void GFXMetal::submit(GFXCommandBuffer* command_buffer, const platform::window_p
break; break;
case GFXCommandType::SetViewport: case GFXCommandType::SetViewport:
{ {
MTL::Viewport viewport; MTL::Viewport viewport = {};
viewport.originX = command.data.set_viewport.viewport.x; viewport.originX = command.data.set_viewport.viewport.x;
viewport.originY = command.data.set_viewport.viewport.y; viewport.originY = command.data.set_viewport.viewport.y;
viewport.width = command.data.set_viewport.viewport.width; viewport.width = command.data.set_viewport.viewport.width;
@ -1027,7 +1027,7 @@ void GFXMetal::submit(GFXCommandBuffer* command_buffer, const platform::window_p
{ {
needEncoder(CurrentEncoder::Render); needEncoder(CurrentEncoder::Render);
MTL::ScissorRect rect; MTL::ScissorRect rect = {};
rect.x = command.data.set_scissor.rect.offset.x; rect.x = command.data.set_scissor.rect.offset.x;
rect.y = command.data.set_scissor.rect.offset.y; rect.y = command.data.set_scissor.rect.offset.y;
rect.width = command.data.set_scissor.rect.extent.width; rect.width = command.data.set_scissor.rect.extent.width;
@ -1039,7 +1039,7 @@ void GFXMetal::submit(GFXCommandBuffer* command_buffer, const platform::window_p
case GFXCommandType::GenerateMipmaps: { case GFXCommandType::GenerateMipmaps: {
needEncoder(CurrentEncoder::Blit); needEncoder(CurrentEncoder::Blit);
GFXMetalTexture* metalTexture = (GFXMetalTexture*)command.data.generate_mipmaps.texture; auto metalTexture = (GFXMetalTexture*)command.data.generate_mipmaps.texture;
blitEncoder->generateMipmaps(metalTexture->handle); blitEncoder->generateMipmaps(metalTexture->handle);
} }

View file

@ -360,8 +360,8 @@ public:
// misc operations // misc operations
virtual GFXSize get_alignment(const GFXSize size) { return size; } virtual GFXSize get_alignment(const GFXSize size) { return size; }
virtual GFXCommandBuffer* acquire_command_buffer(bool for_presentation_use = false) { return nullptr; } virtual GFXCommandBuffer* acquire_command_buffer(bool for_presentation_use) { return nullptr; }
virtual void submit([[maybe_unused]] GFXCommandBuffer* command_buffer, virtual void submit([[maybe_unused]] GFXCommandBuffer* command_buffer,
[[maybe_unused]] const platform::window_ptr window = nullptr) {} [[maybe_unused]] const platform::window_ptr window) {}
}; };

View file

@ -681,7 +681,7 @@ void renderer::generate_brdf() {
brdf_framebuffer = gfx->create_framebuffer(framebufferInfo); brdf_framebuffer = gfx->create_framebuffer(framebufferInfo);
// render // render
GFXCommandBuffer* command_buffer = gfx->acquire_command_buffer(); GFXCommandBuffer* command_buffer = gfx->acquire_command_buffer(false);
GFXRenderPassBeginInfo beginInfo = {}; GFXRenderPassBeginInfo beginInfo = {};
beginInfo.render_pass = brdf_render_pass; beginInfo.render_pass = brdf_render_pass;
@ -700,7 +700,7 @@ void renderer::generate_brdf() {
command_buffer->draw(0, 4, 0, 1); command_buffer->draw(0, 4, 0, 1);
gfx->submit(command_buffer); gfx->submit(command_buffer, nullptr);
} }
void renderer::create_histogram_resources() { void renderer::create_histogram_resources() {