<commit_before>//
//  VSProcessor.swift
//  vs-metal
//
//  Created by satoshi on 6/21/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation
import MetalKit
import MetalPerformanceShaders

class VSProcessor: NSObject, MTKViewDelegate {
    private let context:VSContext
    private let renderer:VSRenderer
    private var runtime:VSRuntime
    private var debugCounter = 0
    
    init(context:VSContext, view:MTKView, script:VSScript) {
        self.context = context
        renderer = VSRenderer(context:context)
        runtime = script.compile(context: context)
        
        super.init()
        view.delegate = self
    }

    public func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {
        // nothing to do
    }

    public func draw(in view: MTKView) {
        debugCounter += 1
        if !context.hasUpdate {
            //print("VSS:draw texture not updated", debugCounter)
            return
        }

        do {
            let commandBufferCompute = context.commandQueue.makeCommandBuffer()
            try context.encode(runtime: runtime, commandBuffer: commandBufferCompute)
            
            let texture = try context.pop()
            let commandBufferRender = context.commandQueue.makeCommandBuffer()
            renderer.encode(commandBuffer:commandBufferRender, texture:texture.texture, view:view)
            
            commandBufferCompute.commit()
            commandBufferRender.commit()
        } catch let error {
            print("#### ERROR #### VSProcessor:draw", error)
        }
        context.flush()
    }
}<commit_msg>clean up<commit_after>//
//  VSProcessor.swift
//  vs-metal
//
//  Created by satoshi on 6/21/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation
import MetalKit
import MetalPerformanceShaders

class VSProcessor: NSObject, MTKViewDelegate {
    private let context:VSContext
    private let renderer:VSRenderer
    private var runtime:VSRuntime
    
    init(context:VSContext, view:MTKView, script:VSScript) {
        self.context = context
        renderer = VSRenderer(context:context)
        runtime = script.compile(context: context)
        
        super.init()
        view.delegate = self
    }

    public func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {
        // nothing to do
    }

    public func draw(in view: MTKView) {
        if !context.hasUpdate {
            return // no update
        }

        do {
            let commandBufferCompute = context.commandQueue.makeCommandBuffer()
            try context.encode(runtime: runtime, commandBuffer: commandBufferCompute)
            commandBufferCompute.commit()
            
            let texture = try context.pop()
            let commandBufferRender = context.commandQueue.makeCommandBuffer()
            renderer.encode(commandBuffer:commandBufferRender, texture:texture.texture, view:view)
            commandBufferRender.commit()
        } catch let error {
            print("#### ERROR #### VSProcessor:draw", error)
        }
        context.flush()
    }
}
{'fraction_non_alphanumeric': 0.09, 'fraction_numerical': 0.0064516129032258064, 'mean_word_length': 2.3165775401069517, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1033201', 'n_tokens_mistral': 841, 'n_tokens_neox': 815, 'n_words': 204}