public Dictionary<BindpointMap, BoundResource[]> GetReadWriteResources(ShaderStageType stage)
        {
            var ret = new Dictionary<BindpointMap, BoundResource[]>();

            if (LogLoaded)
            {
                if (IsLogD3D11)
                {
                    if (stage == ShaderStageType.Compute)
                    {
                        for (int i = 0; i < m_D3D11.m_CS.UAVs.Length; i++)
                        {
                            var key = new BindpointMap(0, i);
                            var val = new BoundResource();

                            val.Id = m_D3D11.m_CS.UAVs[i].Resource;
                            val.HighestMip = (int)m_D3D11.m_CS.UAVs[i].HighestMip;
                            val.FirstSlice = (int)m_D3D11.m_CS.UAVs[i].FirstArraySlice;
                            val.typeHint = m_D3D11.m_CS.UAVs[i].Format.compType;

                            ret.Add(key, new BoundResource[] { val });
                        }
                    }
                    else
                    {
                        for (int i = 0; i < m_D3D11.m_OM.UAVs.Length; i++)
                        {
                            var key = new BindpointMap(0, i);
                            var val = new BoundResource();

                            val.Id = m_D3D11.m_OM.UAVs[i].Resource;
                            val.HighestMip = (int)m_D3D11.m_OM.UAVs[i].HighestMip;
                            val.FirstSlice = (int)m_D3D11.m_OM.UAVs[i].FirstArraySlice;
                            val.typeHint = FormatComponentType.None;

                            ret.Add(key, new BoundResource[] { val });
                        }
                    }

                    return ret;
                }
                else if (IsLogGL)
                {
                    for (int i = 0; i < m_GL.Images.Length; i++)
                    {
                        var key = new BindpointMap(0, i);
                        var val = new BoundResource();

                        val.Id = m_GL.Images[i].Resource;
                        val.HighestMip = (int)m_GL.Images[i].Level;
                        val.FirstSlice = (int)m_GL.Images[i].Layer;
                        val.typeHint = m_GL.Images[i].Format.compType;

                        ret.Add(key, new BoundResource[] { val });
                    }

                    return ret;
                }
                else if (IsLogVK)
                {
                    VulkanPipelineState.Pipeline.DescriptorSet[] descsets = m_Vulkan.graphics.DescSets;

                    if (stage == ShaderStageType.Compute)
                        descsets = m_Vulkan.compute.DescSets;

                    ShaderStageBits mask = (ShaderStageBits)(1 << (int)stage);
                    for (int set = 0; set < descsets.Length; set++)
                    {
                        var descset = descsets[set];
                        for (int slot = 0; slot < descset.bindings.Length; slot++)
                        {
                            var bind = descset.bindings[slot];

                            if ((bind.type == ShaderBindType.ReadWriteBuffer ||
                                bind.type == ShaderBindType.ReadWriteImage ||
                                bind.type == ShaderBindType.ReadWriteTBuffer
                               ) && (bind.stageFlags & mask) == mask)
                            {
                                var key = new BindpointMap(set, slot);
                                var val = new BoundResource[bind.descriptorCount];

                                for (UInt32 i = 0; i < bind.descriptorCount; i++)
                                {
                                    val[i] = new BoundResource();
                                    val[i].Id = bind.binds[i].res;
                                    val[i].HighestMip = (int)bind.binds[i].baseMip;
                                    val[i].FirstSlice = (int)bind.binds[i].baseLayer;
                                    val[i].typeHint = bind.binds[i].viewfmt.compType;
                                }

                                ret.Add(key, val);
                            }
                        }
                    }

                    return ret;
                }
            }

            return ret;
        }
Example #2
0
        private void InitStageResourcePreviews(ShaderStageType stage, ShaderResource[] resourceDetails, BindpointMap[] mapping,
            Dictionary<BindpointMap, BoundResource[]> ResList,
            ThumbnailStrip prevs, ref int prevIndex,
            bool copy, bool rw)
        {
            for (int idx = 0; idx < mapping.Length; idx++)
            {
                var key = mapping[idx];

                BoundResource[] resArray = null;

                if (ResList.ContainsKey(key))
                    resArray = ResList[key];

                int arrayLen = resArray != null ? resArray.Length : 1;

                for (int arrayIdx = 0; arrayIdx < arrayLen; arrayIdx++)
                {
                    ResourceId id = resArray != null ? resArray[arrayIdx].Id : ResourceId.Null;
                    FormatComponentType typeHint = resArray != null ? resArray[arrayIdx].typeHint : FormatComponentType.None;

                    bool used = key.used;
                    bool samplerBind = false;
                    bool otherBind = false;

                    string bindName = "";

                    foreach (var bind in resourceDetails)
                    {
                        if (bind.bindPoint == idx && bind.IsSRV)
                        {
                            bindName = bind.name;
                            otherBind = true;
                            break;
                        }

                        if (bind.bindPoint == idx)
                        {
                            if(bind.IsSampler && !bind.IsSRV)
                                samplerBind = true;
                            else
                                otherBind = true;
                        }
                    }

                    if (samplerBind && !otherBind)
                        continue;

                    if (copy)
                    {
                        used = true;
                        bindName = "Source";
                    }

                    Following follow = new Following(rw ? FollowType.ReadWrite : FollowType.ReadOnly, stage, idx, arrayIdx);
                    string slotName = String.Format("{0} {1}{2}", m_Core.CurPipelineState.Abbrev(stage), rw ? "RW " : "", idx);

                    if (arrayLen > 1)
                        slotName += String.Format("[{0}]", arrayIdx);

                    if (copy)
                        slotName = "SRC";

                    // show if
                    bool show = (used || // it's referenced by the shader - regardless of empty or not
                        (showDisabled.Checked && !used && id != ResourceId.Null) || // it's bound, but not referenced, and we have "show disabled"
                        (showEmpty.Checked && id == ResourceId.Null) // it's empty, and we have "show empty"
                        );

                    ResourcePreview prev;

                    if (prevIndex < prevs.Thumbnails.Length)
                    {
                        prev = prevs.Thumbnails[prevIndex];
                    }
                    else
                    {
                        // don't create it if we're not actually going to show it
                        if (!show)
                            continue;

                        prev = UI_CreateThumbnail(prevs);
                    }

                    prevIndex++;

                    InitResourcePreview(prev, show ? id : ResourceId.Null, typeHint, show, follow, bindName, slotName);
                }
            }
        }
        public Dictionary<BindpointMap, BoundResource[]> GetReadOnlyResources(ShaderStageType stage)
        {
            var ret = new Dictionary<BindpointMap, BoundResource[]>();

            if (LogLoaded)
            {
                if (IsLogD3D11)
                {
                    D3D11PipelineState.ShaderStage s = null;

                    switch (stage)
                    {
                        case ShaderStageType.Vertex: s = m_D3D11.m_VS; break;
                        case ShaderStageType.Domain: s = m_D3D11.m_DS; break;
                        case ShaderStageType.Hull: s = m_D3D11.m_HS; break;
                        case ShaderStageType.Geometry: s = m_D3D11.m_GS; break;
                        case ShaderStageType.Pixel: s = m_D3D11.m_PS; break;
                        case ShaderStageType.Compute: s = m_D3D11.m_CS; break;
                    }

                    for (int i = 0; i < s.SRVs.Length; i++)
                    {
                        var key = new BindpointMap(0, i);
                        var val = new BoundResource();

                        val.Id = s.SRVs[i].Resource;
                        val.HighestMip = (int)s.SRVs[i].HighestMip;
                        val.FirstSlice = (int)s.SRVs[i].FirstArraySlice;
                        val.typeHint = s.SRVs[i].Format.compType;

                        ret.Add(key, new BoundResource[] { val });
                    }

                    return ret;
                }
                else if (IsLogGL)
                {
                    for (int i = 0; i < m_GL.Textures.Length; i++)
                    {
                        var key = new BindpointMap(0, i);
                        var val = new BoundResource();

                        val.Id = m_GL.Textures[i].Resource;
                        val.HighestMip = (int)m_GL.Textures[i].HighestMip;
                        val.FirstSlice = (int)m_GL.Textures[i].FirstSlice;
                        val.typeHint = FormatComponentType.None;

                        ret.Add(key, new BoundResource[] { val });
                    }

                    return ret;
                }
                else if (IsLogVK)
                {
                    VulkanPipelineState.Pipeline.DescriptorSet[] descsets = m_Vulkan.graphics.DescSets;

                    if (stage == ShaderStageType.Compute)
                        descsets = m_Vulkan.compute.DescSets;

                    ShaderStageBits mask = (ShaderStageBits)(1 << (int)stage);

                    for (int set = 0; set < descsets.Length; set++)
                    {
                        var descset = descsets[set];
                        for (int slot = 0; slot < descset.bindings.Length; slot++)
                        {
                            var bind = descset.bindings[slot];
                            if ((bind.type == ShaderBindType.ImageSampler ||
                                bind.type == ShaderBindType.InputAttachment ||
                                bind.type == ShaderBindType.ReadOnlyImage ||
                                bind.type == ShaderBindType.ReadOnlyTBuffer
                               ) && (bind.stageFlags & mask) == mask)
                            {
                                var key = new BindpointMap(set, slot);
                                var val = new BoundResource[bind.descriptorCount];

                                for (UInt32 i = 0; i < bind.descriptorCount; i++)
                                {
                                    val[i] = new BoundResource();
                                    val[i].Id = bind.binds[i].res;
                                    val[i].HighestMip = (int)bind.binds[i].baseMip;
                                    val[i].FirstSlice = (int)bind.binds[i].baseLayer;
                                    val[i].typeHint = bind.binds[i].viewfmt.compType;
                                }

                                ret.Add(key, val);
                            }
                        }
                    }

                    return ret;
                }
            }

            return ret;
        }