Ejemplo n.º 1
0
 public extern static void SDK_IInputLayoutDesc_SetShaderDesc(NativePointer self, CShaderDesc.NativePointer shader);
Ejemplo n.º 2
0
 public extern static unsafe CComputeShader.NativePointer SDK_IRenderContext_CreateComputeShader(CRenderContext.NativePointer self, CShaderDesc.NativePointer desc);
Ejemplo n.º 3
0
 public extern static CConstantBuffer.NativePointer SDK_IRenderContext_CreateConstantBuffer2(CRenderContext.NativePointer self, CShaderDesc.NativePointer desc, int index);
Ejemplo n.º 4
0
        private static void OnShaderTranslated(CShaderDesc.NativePointer coreObj)
        {
            var desc = new CShaderDesc(coreObj);

            desc.Core_AddRef();

            if (bTestSlot)
            {
                string pattern = "layout\\(binding = ([0-9]+), std140\\)";
                // @"(?<=19)\d{2}\b";

                foreach (Match match in Regex.Matches(desc.GLCode, pattern))
                {
                    int slot = System.Convert.ToInt32(match.Groups[1].Value);
                    if (slot > 16)
                    {
                        Console.WriteLine(match.Value);
                    }
                }
            }

            ////var reg = new System.Text.RegularExpressions.Regex("^(-?\\d+)(\\.\\d+)?$hf");
            //var reg = new System.Text.RegularExpressions.Regex("[0-9]*\\.[0-9]+([Ee][+\\-]?[0-9]+)?hf");
            //var srcCode = desc.GLCode;
            //var result = reg.Matches(srcCode);
            //var hfNums = new List<string>();
            //foreach (System.Text.RegularExpressions.Match i in result)
            //{
            //    var src = i.ToString();
            //    hfNums.Add(src);
            //}
            //if (hfNums.Count > 0)
            //{
            //    foreach (var i in hfNums)
            //    {
            //        var tar = i.Substring(0, i.Length - 2) + 'f';
            //        srcCode = srcCode.Replace(i, tar);
            //    }
            //    desc.SetGLCode(srcCode);
            //}
            if (desc.GLCode.Contains("precision mediump float;"))
            {
                var code = desc.GLCode.Replace("precision mediump float;", "precision highp float;");
                desc.SetGLCode(code);
            }
            if (desc.GLCode.Contains("#extension GL_NV_gpu_shader5 : require"))
            {
                const string GLES_Define = "#extension GL_NV_gpu_shader5 : require\r\n" +
                                           "#define f16mat2 mat2\r\n" +
                                           "#define f16mat3 mat3\r\n" +
                                           "#define f16mat4 mat4\r\n";
                var code = desc.GLCode.Replace("#extension GL_NV_gpu_shader5 : require", GLES_Define);
                desc.SetGLCode(code);
            }
            if (desc.GLCode.Contains("#else\n#error No extension available for FP16."))
            {
                const string GLES_Define = "#elif defined(EXT_shader_16bit_storage)\r\n" +
                                           "#extension EXT_shader_16bit_storage : require\r\n" +
                                           "#define f16mat2 mat2\r\n" +
                                           "#define f16mat3 mat3\r\n" +
                                           "#define f16mat4 mat4\r\n" +
                                           "#else\r\n" +
                                           "#define float16_t float\r\n" +
                                           "#define f16vec2 vec2\r\n" +
                                           "#define f16vec3 vec3\r\n" +
                                           "#define f16vec4 vec4\r\n" +
                                           "#define float16_t float\r\n" +
                                           "#define f16mat2 mat2\r\n" +
                                           "#define f16mat3 mat3\r\n" +
                                           "#define f16mat4 mat4\r\n";

                var code = desc.GLCode.Replace("#else\n#error No extension available for FP16.", GLES_Define);
                desc.SetGLCode(code);
            }
            if (desc.GLCode.Contains("#else\n#error No extension available for Int16."))
            {
                const string GLES_Define = "#else\r\n" +
                                           "#define int16_t int\r\n" +
                                           "#define uint16_t uint\r\n";

                var code = desc.GLCode.Replace("#else\n#error No extension available for Int16.", GLES_Define);
                desc.SetGLCode(code);
            }

            if (desc.ShaderType == EShaderType.EST_VertexShader)
            {
                if (desc.GLCode.IndexOf("#extension") < 0)
                {
                    if (desc.GLCode.StartsWith("#version 310 es"))
                    {
                        const string GLES_DefaultPrecision = "#version 310 es\n" + "precision highp float;\n";
                        var          code = desc.GLCode.Replace("#version 310 es", GLES_DefaultPrecision);
                        desc.SetGLCode(code);
                    }
                    else if (desc.GLCode.StartsWith("#version 300 es"))
                    {
                        const string GLES_DefaultPrecision = "#version 300 es\n" + "precision highp float;\n";
                        var          code = desc.GLCode.Replace("#version 300 es", GLES_DefaultPrecision);
                        desc.SetGLCode(code);
                    }
                }
                else
                {
                    const string GLES_DefaultPrecision = "precision highp float;\n" + "void main()";
                    var          code = desc.GLCode.Replace("void main()", GLES_DefaultPrecision);
                    desc.SetGLCode(code);
                }
            }
        }