mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-27 00:30:26 +00:00
Starts trying to do actual composite processing.
This commit is contained in:
parent
7c23c32e44
commit
d54b937ab6
@ -8,9 +8,12 @@
|
||||
|
||||
#import "CSScanTarget.h"
|
||||
|
||||
#include <atomic>
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "BufferingScanTarget.hpp"
|
||||
#include "FIRFilter.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -22,6 +25,7 @@ struct Uniforms {
|
||||
simd::float3x3 fromRGB;
|
||||
float zoom;
|
||||
simd::float2 offset;
|
||||
float firCoefficients[8];
|
||||
};
|
||||
|
||||
constexpr size_t NumBufferedScans = 2048;
|
||||
@ -355,9 +359,8 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
#endif
|
||||
|
||||
// Build the composition pipeline if one is in use.
|
||||
const bool isSVideoOutput = modals.display_type == Outputs::Display::DisplayType::SVideo;
|
||||
if(_isUsingCompositionPipeline) {
|
||||
const bool isSVideoOutput = modals.display_type == Outputs::Display::DisplayType::SVideo;
|
||||
|
||||
pipelineDescriptor.colorAttachments[0].pixelFormat = _compositionTexture.pixelFormat;
|
||||
pipelineDescriptor.vertexFunction = [library newFunctionWithName:@"scanToComposition"];
|
||||
pipelineDescriptor.fragmentFunction =
|
||||
@ -371,6 +374,15 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
_compositionRenderPass.colorAttachments[0].storeAction = MTLStoreActionStore;
|
||||
|
||||
// TODO: set proper clear colour for S-Video.
|
||||
|
||||
// TODO: work out fir coefficients, for real.
|
||||
const float cyclesPerLine = float(modals.cycles_per_line);
|
||||
const float colourCyclesPerLine = float(modals.colour_cycle_numerator) / float(modals.colour_cycle_denominator);
|
||||
SignalProcessing::FIRFilter filter(15, cyclesPerLine, 0.0f, 16.0f * cyclesPerLine / colourCyclesPerLine);
|
||||
|
||||
float *const firCoefficients = uniforms()->firCoefficients;
|
||||
const auto calculatedCoefficients = filter.get_coefficients();
|
||||
memcpy(firCoefficients, calculatedCoefficients.data(), calculatedCoefficients.size() * sizeof(float));
|
||||
}
|
||||
|
||||
// Build the output pipeline.
|
||||
@ -378,7 +390,8 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
pipelineDescriptor.vertexFunction = [library newFunctionWithName:_isUsingCompositionPipeline ? @"lineToDisplay" : @"scanToDisplay"];
|
||||
|
||||
if(_isUsingCompositionPipeline) {
|
||||
pipelineDescriptor.fragmentFunction = [library newFunctionWithName:@"sampleRed8Green8Blue8"];
|
||||
// TODO!
|
||||
pipelineDescriptor.fragmentFunction = [library newFunctionWithName:@"convertComposite"];
|
||||
} else {
|
||||
const bool isRGBOutput = modals.display_type == Outputs::Display::DisplayType::RGB;
|
||||
pipelineDescriptor.fragmentFunction =
|
||||
|
@ -30,6 +30,10 @@ struct Uniforms {
|
||||
// Provides zoom and offset to scale the source data.
|
||||
float zoom;
|
||||
float2 offset;
|
||||
|
||||
// Describes the FIR filter in use; it'll be 15 coefficients but they're
|
||||
// symmetrical around the centre.
|
||||
float firCoefficients[8];
|
||||
};
|
||||
|
||||
namespace {
|
||||
@ -311,3 +315,26 @@ fragment float4 copyFragment(CopyInterpolator vert [[stage_in]], texture2d<float
|
||||
fragment float4 clearFragment() {
|
||||
return float4(0.0, 0.0, 0.0, 0.64);
|
||||
}
|
||||
|
||||
// MARK: - Conversion fragment shaders
|
||||
|
||||
fragment float4 convertComposite(CopyInterpolator vert [[stage_in]], texture2d<float> texture [[texture(0)]], constant Uniforms &uniforms [[buffer(0)]]) {
|
||||
const float3 colour =
|
||||
uniforms.firCoefficients[0] * texture.sample(standardSampler, vert.textureCoordinates - float2(7.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[1] * texture.sample(standardSampler, vert.textureCoordinates - float2(6.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[2] * texture.sample(standardSampler, vert.textureCoordinates - float2(5.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[3] * texture.sample(standardSampler, vert.textureCoordinates - float2(4.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[4] * texture.sample(standardSampler, vert.textureCoordinates - float2(3.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[5] * texture.sample(standardSampler, vert.textureCoordinates - float2(2.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[6] * texture.sample(standardSampler, vert.textureCoordinates - float2(1.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[7] * texture.sample(standardSampler, vert.textureCoordinates).rgb +
|
||||
uniforms.firCoefficients[6] * texture.sample(standardSampler, vert.textureCoordinates + float2(1.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[5] * texture.sample(standardSampler, vert.textureCoordinates + float2(2.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[4] * texture.sample(standardSampler, vert.textureCoordinates + float2(3.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[3] * texture.sample(standardSampler, vert.textureCoordinates + float2(4.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[2] * texture.sample(standardSampler, vert.textureCoordinates + float2(5.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[1] * texture.sample(standardSampler, vert.textureCoordinates + float2(6.0, 0.0)).rgb +
|
||||
uniforms.firCoefficients[0] * texture.sample(standardSampler, vert.textureCoordinates + float2(7.0, 0.0)).rgb;
|
||||
|
||||
return float4(colour, 1.0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user