Job System

Job System

Job์ด๋ž€?

  • ๋‹จ์ผ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์ž‘์—… ๋‹จ์œ„

Job System์ด๋ž€?

  • ์Šค๋ ˆ๋“œ๋ฅผ ๋Œ€์‹ ํ•ด ํƒœ์Šคํฌ๋ฅผ ๋งŒ๋“ค์–ด ๋ฉ€ํ‹ฐ์Šค๋ ˆ๋“œ ์ฝ”๋“œ๋ฅผ ๊ด€๋ฆฌ
  • ์—ฌ๋Ÿฌ ์ฝ”์–ด์— ๊ฑธ์ณ ์›Œ์ปค ์Šค๋ ˆ๋“œ ๊ทธ๋ฃน์„ ๊ด€๋ฆฌ
  • ์ผ๋ฐ˜์ ์œผ๋กœ ์ปจํ…์ŠคํŠธ ๋ณ€๊ฒฝ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ์ฝ”์–ด๋‹น ํ•˜๋‚˜์˜ ์›Œ์ปค ์Šค๋ ˆ๋“œ๊ฐ€ ์žˆ์œผ๋‚˜ ์‚ฌ์šฉํ•  ์ฝ”์–ด ์˜ˆ์•ฝ๋„ ๊ฐ€๋Šฅ
  • ์žก ๋Œ€๊ธฐ์—ด์— ์ˆœ์„œ๋Œ€๋กœ ์žก์„ ๋ฐฐ์น˜ํ•˜์—ฌ ์‹คํ–‰
public class RotationSpeedSystem : JobComponentSystem
{
    [BurstCompile]
    struct RotationSpeedRotation : IJobForEach<Rotation, RotationSpeed>
    {
        public float dt;

        public void Execute(ref Rotation rotation, [ReadOnly]ref RotationSpeed speed)
        {
            rotation.value = math.mul(math.normalize(rotation.value), quaternion.axisAngle(math.up(), speed.speed * dt));
        }
    }

    // Any previously scheduled jobs reading/writing from Rotation or writing to RotationSpeed 
    // will automatically be included in the inputDeps dependency.
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new RotationSpeedRotation() { dt = Time.deltaTime };
        return job.Schedule(this, inputDeps);
    } 
}
  • ๋‹ค๋ฅธ ์‹œ์Šคํ…œ์—์„œ์˜ ์—ฌ๋Ÿฌ job๋„ ๋ณ‘๋ ฌ ์ƒํƒœ์˜ IComponentData๋ฅผ ์ƒ์†ํ•œ Data๋กœ๋ถ€ํ„ฐ read ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค
  • ์–ด๋–ค job์ด Data์— write ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์ค‘์—๋Š” ๋‹ค๋ฅธ job๋“ค์€ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์—†์œผ๋ฉฐ, ์ž‘์—… ์Šค์ผ€์ค„๋ง์„ ๊ฑธ์–ด๋‘”๋‹ค

์ž‘๋™ ๋ฐฉ์‹

  • ๋ชจ๋“  job ๊ทธ๋ฆฌ๊ณ  system์€ ์–ด๋–ค ComponentType์— ๋Œ€ํ•˜์—ฌ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ๊ฒƒ์ธ์ง€๋ฅผ ์„ ์–ธํ•œ๋‹ค
  • JobComponentSystem์€ JobHandle์„ ๋ฐ˜ํ™˜ํ•˜๊ณ , EntityManager๋ฅผ ํ†ตํ•ด raed ์ค‘์ธ์ง€ write ์ค‘์ธ์ง€ ์ž๋™์œผ๋กœ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•œ๋‹ค
  • ํ•œ system์ด A ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•ด write ์ž‘์—… ์ค‘์ด๊ณ , ๋˜ ๋‹ค๋ฅธ system์ด A ์ปดํฌ๋„ŒํŠธ ์ฝ๊ธฐ ์ž‘์—…์„ ํ•˜๋ ค ํ•œ๋‹ค๋ฉด, JobComponentSystem์ด ์ž‘์—… ํƒ€์ž… ๋ฆฌ์ŠคํŠธ๋ฅผ ์‚ดํŽด๋ณด๊ณ  write ์ž‘์—… ์ค‘์ธ ์‹œ์Šคํ…œ์ด ์žˆ์Œ์„ ์•Œ๋ฆด ๊ฒƒ์ด๋‹ค.

์•ˆ์ „ ์‹œ์Šคํ…œ

  • ๋ฐ๋“œ๋ฝ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•ด ๋ฐ์ดํ„ฐ์˜ ๋ ˆํผ๋Ÿฐ์Šค๊ฐ€ ์•„๋‹Œ ๋ณต์‚ฌ๋ณธ์„ ์ด์šฉํ•ด ์ฒ˜๋ฆฌ
  • bittable ๋ฐ์ดํ„ฐ ํƒ€์ž…์—๋งŒ ์—‘์„ธ์Šค ๊ฐ€๋Šฅ
  • memcopy๋ฅผ ์ด์šฉํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ๋ณต์‚ฌ

NativeContainer

  • ๋„ค์ดํ‹ฐ๋ธŒ ๋ฉ”๋ชจ๋ฆฌ์— ๋น„๊ต์  ์•ˆ์ „ํ•œ C# Wrapper ๋ฅผ ์ œ๊ณตํ•˜์—ฌ ๊ด€๋ฆฌ๋˜๋Š” ๊ฐ’ ํ˜•์‹
  • NavtiveContainer๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด Job์„ ํ†ตํ•ด ์‚ฌ๋ณธ์œผ๋กœ ์ž‘์—…ํ•˜๋Š” ๋Œ€์‹  ์ฃผ ์Šค๋ ˆ๋“œ์™€ ๊ณต์œ  ๋œ ๋ฐ์ดํ„ฐ์— ์ ‘๊ทผ
  • ๊ธฐ๋ณธ ์ œ๊ณต๋˜๋Š” ํƒ€์ž…์€ NativeArray

์ถœ์ฒ˜

Categories: ,

Updated: