slang icon indicating copy to clipboard operation
slang copied to clipboard

Implement "Image" GLSL functions to match to how much HLSL side works

Open jkwak-work opened this issue 1 year ago • 5 comments

This task is to implement "image" functions that OpenGL 4.6 spec requires.

This is also a part of the other umbrella task https://github.com/shader-slang/slang/issues/3362 .

There are 33 function names related to this task and they are described in the section 8.12 of OpenGL 4.6 spec. The function names are listed below: int imageSize(readonly writeonly gimage1D image) ivec2 imageSize(readonly writeonly gimage2D image) ivec3 imageSize(readonly writeonly gimage3D image) ivec2 imageSize(readonly writeonly gimageCube image) ivec3 imageSize(readonly writeonly gimageCubeArray image) ivec3 imageSize(readonly writeonly gimage2DArray image) ivec2 imageSize(readonly writeonly gimage2DRect image) ivec2 imageSize(readonly writeonly gimage1DArray image) ivec2 imageSize(readonly writeonly gimage2DMS image) ivec3 imageSize(readonly writeonly gimage2DMSArray image) int imageSize(readonly writeonly gimageBuffer image) int imageSamples(readonly writeonly gimage2DMS image) int imageSamples(readonly writeonly gimage2DMSArray image) gvec4 imageLoad(readonly IMAGE_PARAMS) void imageStore(writeonly IMAGE_PARAMS, gvec4 data) uint imageAtomicAdd(IMAGE_PARAMS, uint data) int imageAtomicAdd(IMAGE_PARAMS, int data) uint imageAtomicMin(IMAGE_PARAMS, uint data) int imageAtomicMin(IMAGE_PARAMS, int data) uint imageAtomicMax(IMAGE_PARAMS, uint data) int imageAtomicMax(IMAGE_PARAMS, int data) uint imageAtomicAnd(IMAGE_PARAMS, uint data) int imageAtomicAnd(IMAGE_PARAMS, int data) uint imageAtomicOr(IMAGE_PARAMS, uint data) int imageAtomicOr(IMAGE_PARAMS, int data) uint imageAtomicXor(IMAGE_PARAMS, uint data) int imageAtomicXor(IMAGE_PARAMS, int data) uint imageAtomicExchange(IMAGE_PARAMS, uint data) int imageAtomicExchange(IMAGE_PARAMS, int data) float imageAtomicExchange(IMAGE_PARAMS, float data) uint imageAtomicCompSwap(IMAGE_PARAMS, uint compare, uint data) int imageAtomicCompSwap(IMAGE_PARAMS, int compare, int data)

jkwak-work avatar Feb 26 '24 23:02 jkwak-work

to reach parity we would need extended types for image atomics (i64, u64, float): https://github.com/KhronosGroup/GLSL/blob/main/extensions/ext/GLSL_EXT_shader_image_int64.txt{

    i64image1D u64image1D

    i64image1DArray u64image1DArray

    i64image2D u64image2D

    i64image2DArray u64image2DArray

    i64image2DRect u64image2DRect

    i64image2DMS u64image2DMS

    i64image2DMSArray u64image2DMSArray

    i64image3D u64image3D

    i64imageCube u64imageCube

    i64imageCubeArray u64imageCubeArray

    i64imageBuffer u64imageBuffer


u64vec4 imageLoad(readonly IMAGE64_PARAMS);
   i64vec4 imageLoad(readonly IMAGE64_PARAMS);
   
      void imageStore(writeonly IMAGE64_PARAMS, u64vec4);
      void imageStore(writeonly IMAGE64_PARAMS, i64vec4);
  
  uint64_t imageAtomicAdd(IMAGE64_PARAMS, uint64_t data);
   int64_t imageAtomicAdd(IMAGE64_PARAMS,  int64_t data);
  
  uint64_t imageAtomicMin(IMAGE64_PARAMS, uint64_t data);
   int64_t imageAtomicMin(IMAGE64_PARAMS,  int64_t data);
  
  uint64_t imageAtomicMax(IMAGE64_PARAMS, uint64_t data);
   int64_t imageAtomicMax(IMAGE64_PARAMS,  int64_t data);
  
  uint64_t imageAtomicAnd(IMAGE64_PARAMS, uint64_t data);
   int64_t imageAtomicAnd(IMAGE64_PARAMS,  int64_t data);
  
  uint64_t imageAtomicOr (IMAGE64_PARAMS, uint64_t data);
   int64_t imageAtomicOr (IMAGE64_PARAMS,  int64_t data);
  
  uint64_t imageAtomicXor(IMAGE64_PARAMS, uint64_t data);
   int64_t imageAtomicXor(IMAGE64_PARAMS,  int64_t data);

  uint64_t imageAtomicExchange(IMAGE64_PARAMS, uint64_t data);
   int64_t imageAtomicExchange(IMAGE64_PARAMS,  int64_t data);

  uint64_t imageAtomicCompSwap(IMAGE64_PARAMS, uint64_t compare, uint64_t data);
   int64_t imageAtomicCompSwap(IMAGE64_PARAMS,  int64_t compare,  int64_t data);

}

https://github.com/KhronosGroup/GLSL/blob/main/extensions/ext/GLSL_EXT_shader_atomic_float.txt{

        float imageAtomicLoad(readonly IMAGE_PARAMS,           Returns the contents of texel atomically.
            int scope, int storage, int sem);

        void imageAtomicStore(writeonly IMAGE_PARAMS,          Stores data into the texel atomically.
            float data, int scope, int storage, int sem);

}

https://github.com/KhronosGroup/GLSL/blob/main/extensions/ext/GLSL_EXT_shader_atomic_float2.txt{ float imageAtomicMin(IMAGE_PARAMS, float data); float imageAtomicMin(IMAGE_PARAMS, float data, int scope, int storage, int sem);

        float imageAtomicMax(IMAGE_PARAMS, float data);
        float imageAtomicMax(IMAGE_PARAMS, float data, int scope, int storage, int sem);

}

ArielG-NV avatar Mar 06 '24 17:03 ArielG-NV

missing modifiers for buffer & image:

coherent

volatile

restrict

readonly

writeonly

ArielG-NV avatar Mar 06 '24 17:03 ArielG-NV

image types of importance: image1D -- float uimage1D -- 32bit uint iimage1D -- 32bit int u64image1D -- 64 bit int i64image1D -- 64 bit int

ArielG-NV avatar Mar 07 '24 18:03 ArielG-NV

will need to add a system to watch if doing readonly writeonly as parameter to error accordingly, or at a minimum emit GLSL for these as parameters (allowed to be used with opaque type parameter images)

ArielG-NV avatar Mar 07 '24 19:03 ArielG-NV

format qualifier currently missing implementation with layout() for syntax parsing

ArielG-NV avatar Mar 08 '24 15:03 ArielG-NV

currently our TextureImpl system has no concept of a "rect", 2D textures were being used so far, but this causes incorrect results (not in any tests, so does not come up).

need to add isRect param

ArielG-NV avatar Mar 12 '24 17:03 ArielG-NV

various texture formats are missing and also need to be added to testing infrastructure

ArielG-NV avatar Mar 12 '24 17:03 ArielG-NV