コード例 #1
0
        public H1ShaderType CacheShaderType(H1ShaderType type)
        {
            if (!m_ShaderTypes.ContainsKey(type.Name))
            {
                RegisterShaderType(type.Name, type);
            }

            return(m_ShaderTypes[type.Name]);
        }
コード例 #2
0
        public void Compile(H1MaterialResource material, H1ShaderCompileHelper.H1ShaderCompilerEnvironment materialEnvironment)
        {
            // iterate over all vertex factory types
            var vertexFactoryTypes = H1VertexFactoryType.GetTypeList();

            foreach (var vertexFactoryType in vertexFactoryTypes)
            {
                H1MeshMaterialShaderMap meshMaterialMap = null;

                // look for existing map for this vertex factory map
                foreach (var shaderMap in m_MeshMaterialMaps)
                {
                    if (shaderMap.VertexFactoryType == vertexFactoryType)
                    {
                        meshMaterialMap = shaderMap;
                        break;
                    }
                }

                if (meshMaterialMap == null)
                {
                    // create a new mesh material shader map
                    meshMaterialMap = new H1MeshMaterialShaderMap(vertexFactoryType);
                    m_MeshMaterialMaps.Add(meshMaterialMap);
                }

                // compile mesh material map
                meshMaterialMap.BeginCompile(0, // @TODO - I need to change this appropriately!
                                             material, materialEnvironment);
            }

            // iterate over all material shader types
            var shaderTypes = H1ShaderType.GetTypeList();

            foreach (var shaderType in shaderTypes)
            {
                H1MaterialShaderType materialShaderType = shaderType.GetMaterialShaderType();
                if (materialShaderType != null &&
                    materialShaderType.ShouldCache(material) &&
                    material.ShouldCache(materialShaderType, null))
                {
                    materialShaderType.BeginCompileShader(0, // @TODO - I need to change this appropriately!
                                                          material, materialEnvironment);
                }
            }
        }
コード例 #3
0
        // note that - for this 'BeginCompile' call is called by H1MaterialMap usually!
        public void BeginCompile(uint shaderMapId, H1MaterialResource material, H1ShaderCompileHelper.H1ShaderCompilerEnvironment materialEnvironment)
        {
            // iterating shader type
            var shaderTypes = H1ShaderType.GetTypeList();

            foreach (var shaderType in shaderTypes)
            {
                H1MeshMaterialShaderType meshMaterialShaderType = shaderType.GetMeshMaterialShaderType();
                if (meshMaterialShaderType != null &&
                    m_VertexFactoryTypeRef != null &&
                    meshMaterialShaderType.ShouldCache(material, m_VertexFactoryTypeRef) &&
                    material.ShouldCache(meshMaterialShaderType, m_VertexFactoryTypeRef) &&
                    m_VertexFactoryTypeRef.ShouldCache(material, meshMaterialShaderType))
                {
                    // compile mesh material shader type (ex. vertex shader)
                    H1Shader shader = meshMaterialShaderType.BeginCompileShader(shaderMapId, material, materialEnvironment, m_VertexFactoryTypeRef);

                    // add shader to shader map
                    AddShader(meshMaterialShaderType, shader);
                }
            }
        }
コード例 #4
0
        public H1Shader(H1ShaderType type, byte[] compiledByteCode, H1ShaderParameterMap shaderParameterMap, Boolean isCreateShaderType = false)
        {
            if (isCreateShaderType)
            {
                return; // triggered by just shader type creation, skip it
            }
            // assign new H1ShaderId
            m_Id = new H1ShaderId();

            m_CompiledByteCode = compiledByteCode;
            m_ShaderTypeRef    = type;
            m_ParameterMap     = shaderParameterMap;

            Direct3D12.H1ResourceRanges resourceRanges = new Direct3D12.H1ResourceRanges();
            foreach (KeyValuePair <String, H1ParameterAllocation> parameter in shaderParameterMap.ParameterMap)
            {
                String parameterName             = parameter.Key;
                H1ParameterAllocation allocation = parameter.Value;

                // 1. constant buffer
                if (allocation.Type == H1ParameterType.ConstantBuffer)
                {
                    // insert the new range to the constant buffers
                    Direct3D12.H1BindRanges.H1Range range = new Direct3D12.H1BindRanges.H1Range();
                    range.Start  = Convert.ToByte(allocation.BufferIndex);
                    range.Length = Convert.ToByte(1);
                    resourceRanges.ConstantBuffers.AddRange(range);
                    continue;
                }

                // handling textures, samplers,...
            }

            // 2. create new shader instance
            m_DX12Shader = new Direct3D12.H1Shader(compiledByteCode, resourceRanges);
        }
コード例 #5
0
 public bool ShouldCache(H1MaterialResource material, H1ShaderType shaderType)
 {
     return(m_ShouldCacheRef(material, shaderType));
 }
コード例 #6
0
 public static bool ShouldCache(H1MaterialResource material, H1ShaderType shaderType)
 {
     return(true);
 }
コード例 #7
0
 public void AddShader(H1ShaderType shaderType, H1Shader shader)
 {
     m_Shaders.Add(shaderType, shader);
 }
コード例 #8
0
 public H1MeshMaterialShader(H1ShaderType type, byte[] compiledByteCode, H1ShaderParameterMap shaderParameterMap, Boolean isCreateShaderType = false)
     : base(type, compiledByteCode, shaderParameterMap, isCreateShaderType)
 {
 }
コード例 #9
0
 public H1GlobalShader(H1ShaderType type, byte[] compiledByteCode, H1ShaderParameterMap shaderParameterMap)
     : base(type, compiledByteCode, shaderParameterMap)
 {
 }
コード例 #10
0
        public H1Shader CompileShader(String debugGroupName, H1VertexFactoryType vertexFactoryType, H1ShaderType shaderType, H1ShaderCompileHelper.H1ShaderCompileInput input)
        {
            // compile the shader
            H1ShaderCompileHelper.H1ShaderCompileOutput shaderCompileOutput = new H1ShaderCompileHelper.H1ShaderCompileOutput();
            H1ShaderCompileHelper.CompileD3D12Shader(input, shaderCompileOutput);

            if (!shaderCompileOutput.IsSucceed)
            {
                throw new Exception("failed to compile the shader! please check!");
            }

            H1Shader outShader = null;

            if (shaderType != null)
            {
                // create shader instance
                outShader = shaderType.FinishCompileShader(shaderCompileOutput);

                if (shaderType is H1GlobalShaderType) // only for global shader, add global shaders
                {
                    m_GlobalShaders.Add(outShader);
                }
                else // otherwise add local shaders
                {
                    m_LocalShaders.Add(outShader);
                }
            }

            return(outShader);
        }
コード例 #11
0
 private void RegisterShaderType(String name, H1ShaderType shaderType)
 {
     m_ShaderTypes.Add(name, shaderType);
 }
コード例 #12
0
 public virtual bool ShouldCache(H1ShaderType shaderType, H1VertexFactoryType vertexFactoryType)
 {
     return(true);
 }