mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 04:29:13 +12:00
rewrite shaders
This commit is contained in:
parent
e0fcfb44a8
commit
d41e77491a
5 changed files with 52 additions and 18 deletions
|
@ -407,7 +407,7 @@ if(ENABLE_METAL AND APPLE)
|
||||||
|
|
||||||
set(RENDERER_MTL_SOURCE_FILES src/core/renderer_mtl/metal_cpp_impl.cpp
|
set(RENDERER_MTL_SOURCE_FILES src/core/renderer_mtl/metal_cpp_impl.cpp
|
||||||
src/core/renderer_mtl/renderer_mtl.cpp
|
src/core/renderer_mtl/renderer_mtl.cpp
|
||||||
src/host_shaders/metal_display.metal
|
src/host_shaders/metal_shaders.metal
|
||||||
)
|
)
|
||||||
|
|
||||||
set(HEADER_FILES ${HEADER_FILES} ${RENDERER_MTL_INCLUDE_FILES})
|
set(HEADER_FILES ${HEADER_FILES} ${RENDERER_MTL_INCLUDE_FILES})
|
||||||
|
@ -419,7 +419,7 @@ if(ENABLE_METAL AND APPLE)
|
||||||
resources_renderer_mtl
|
resources_renderer_mtl
|
||||||
NAMESPACE RendererMTL
|
NAMESPACE RendererMTL
|
||||||
WHENCE "src/host_shaders/"
|
WHENCE "src/host_shaders/"
|
||||||
"src/host_shaders/metal_display.metal"
|
"src/host_shaders/metal_shaders.metal"
|
||||||
)
|
)
|
||||||
|
|
||||||
target_sources(AlberCore PRIVATE ${RENDERER_MTL_SOURCE_FILES})
|
target_sources(AlberCore PRIVATE ${RENDERER_MTL_SOURCE_FILES})
|
||||||
|
|
|
@ -29,4 +29,11 @@ class RendererMTL final : public Renderer {
|
||||||
|
|
||||||
MTL::Device* device;
|
MTL::Device* device;
|
||||||
MTL::CommandQueue* commandQueue;
|
MTL::CommandQueue* commandQueue;
|
||||||
|
|
||||||
|
// HACK
|
||||||
|
MTL::Texture* topScreenTexture;
|
||||||
|
|
||||||
|
// Pipelines
|
||||||
|
MTL::RenderPipelineState* displayPipeline;
|
||||||
|
MTL::RenderPipelineState* drawPipeline;
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,6 +36,13 @@ void RendererMTL::initGraphicsContext(SDL_Window* window) {
|
||||||
device = MTL::CreateSystemDefaultDevice();
|
device = MTL::CreateSystemDefaultDevice();
|
||||||
metalLayer->setDevice(device);
|
metalLayer->setDevice(device);
|
||||||
commandQueue = device->newCommandQueue();
|
commandQueue = device->newCommandQueue();
|
||||||
|
|
||||||
|
// HACK
|
||||||
|
MTL::TextureDescriptor* descriptor = MTL::TextureDescriptor::texture2DDescriptor(MTL::PixelFormatRGBA8Unorm, 400, 240, false);
|
||||||
|
topScreenTexture = device->newTexture(descriptor);
|
||||||
|
|
||||||
|
// Pipelines
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererMTL::clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control) {
|
void RendererMTL::clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control) {
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
struct VertexOut {
|
|
||||||
float4 position [[position]];
|
|
||||||
float2 uv;
|
|
||||||
};
|
|
||||||
|
|
||||||
vertex VertexOut vertexMain(uint vid [[vertex_id]]) {
|
|
||||||
VertexOut out;
|
|
||||||
out.uv = float2((vid << 1) & 2, vid & 2);
|
|
||||||
out.position = float4(out.uv * 2.0f + -1.0f, 0.0f, 1.0f);
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
fragment float4 fragmentMain(VertexOut in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler samplr [[sampler(0)]]) {
|
|
||||||
return tex.sample(samplr, in.uv);
|
|
||||||
}
|
|
36
src/host_shaders/metal_shaders.metal
Normal file
36
src/host_shaders/metal_shaders.metal
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
struct DisplayVertexOut {
|
||||||
|
float4 position [[position]];
|
||||||
|
float2 uv;
|
||||||
|
};
|
||||||
|
|
||||||
|
vertex DisplayVertexOut vertexDisplay(uint vid [[vertex_id]]) {
|
||||||
|
DisplayVertexOut out;
|
||||||
|
out.uv = float2((vid << 1) & 2, vid & 2);
|
||||||
|
out.position = float4(out.uv * 2.0f + -1.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment float4 fragmentDisplay(DisplayVertexOut in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler samplr [[sampler(0)]]) {
|
||||||
|
return tex.sample(samplr, in.uv);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DrawVertexIn {
|
||||||
|
float4 position [[attribute(0)]];
|
||||||
|
float4 color [[attribute(2)]];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DrawVertexOut {
|
||||||
|
float4 position [[position]];
|
||||||
|
float4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
vertex DrawVertexOut vertexDraw(DrawVertexIn in [[stage_in]]) {
|
||||||
|
DrawVertexOut out;
|
||||||
|
out.position = in.position;
|
||||||
|
out.color = in.color;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment float4 fragmentDraw(DrawVertexOut in [[stage_in]]) { return in.color; }
|
Loading…
Add table
Add a link
Reference in a new issue