Пример #1
0
UnorderedAccessView::UnorderedAccessView(UnderlyingResource resource, NativeFormat::Enum format, unsigned mipSlice, bool appendBuffer, bool forceArray)
{
    if (!resource) {
        Throw(::Exceptions::BasicLabel("NULL resource passed to UnorderedAccessView constructor"));
    }

    intrusive_ptr<ID3D::UnorderedAccessView> view = nullptr;
    if (format == NativeFormat::Unknown && mipSlice == 0 && !appendBuffer && !forceArray) {
        view = ObjectFactory(*resource).CreateUnorderedAccessView(resource);
    } else {
        D3D11_UNORDERED_ACCESS_VIEW_DESC viewDesc;
        viewDesc.Format = AsDXGIFormat(format);

        TextureDesc2D textureDesc(resource);
        if (textureDesc.Width > 0) {
            if (textureDesc.ArraySize > 1 || forceArray) {
                viewDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
                viewDesc.Texture2DArray.MipSlice = mipSlice;
                viewDesc.Texture2DArray.FirstArraySlice = 0;
                viewDesc.Texture2DArray.ArraySize = textureDesc.ArraySize;
            } else {
                viewDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
                viewDesc.Texture2D.MipSlice = mipSlice;
            }
        } else {
            TextureDesc3D t3dDesc(resource);
            if (t3dDesc.Width > 0) {
                viewDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D;
                viewDesc.Texture3D.MipSlice = mipSlice;
                viewDesc.Texture3D.FirstWSlice = 0;
                viewDesc.Texture3D.WSize = (UINT)-1;
            } else {
                TextureDesc1D t1dDesc(resource);
                if (t1dDesc.Width > 0) {
                    viewDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE1D;
                    viewDesc.Texture1D.MipSlice = mipSlice;
                } else {
                    D3DBufferDesc bufferDesc(resource);
                    viewDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
                    viewDesc.Buffer.FirstElement = 0;
                    viewDesc.Buffer.NumElements = bufferDesc.StructureByteStride ? (bufferDesc.ByteWidth/bufferDesc.StructureByteStride) : bufferDesc.ByteWidth;
                    viewDesc.Buffer.Flags = appendBuffer ? D3D11_BUFFER_UAV_FLAG_APPEND : 0;
                }
            }
        }

        view = ObjectFactory(*resource).CreateUnorderedAccessView(resource, &viewDesc);
    }

    _underlying = std::move(view);
}
Пример #2
0
DepthStencilView::DepthStencilView(
    UnderlyingResource resource,
    NativeFormat::Enum format, const SubResourceSlice& arraySlice)
{
    if (!resource) {
        Throw(::Exceptions::BasicLabel("NULL resource passed to DepthStencilView constructor"));
    }

    intrusive_ptr<ID3D::DepthStencilView> view;
    if (format == NativeFormat::Unknown) {
        view = ObjectFactory(*resource).CreateDepthStencilView(resource);
    } else {
        TextureDesc2D textureDesc(resource);

        D3D11_DEPTH_STENCIL_VIEW_DESC viewDesc;
        viewDesc.Format = AsDXGIFormat(format);
        viewDesc.Flags = 0;
        if (arraySlice._arraySize == 0) {
            if (textureDesc.SampleDesc.Count > 1) {
                viewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
            } else {
                viewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
                viewDesc.Texture2D.MipSlice = 0;
            }
        } else {
            if (textureDesc.SampleDesc.Count > 1) {
                viewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
                viewDesc.Texture2DMSArray.ArraySize = arraySlice._arraySize;
                viewDesc.Texture2DMSArray.FirstArraySlice = arraySlice._firstArraySlice;
            } else {
                viewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
                viewDesc.Texture2DArray.ArraySize = arraySlice._arraySize;
                viewDesc.Texture2DArray.FirstArraySlice = arraySlice._firstArraySlice;
                viewDesc.Texture2DArray.MipSlice = 0;
            }
        }
        view = ObjectFactory(*resource).CreateDepthStencilView(resource, &viewDesc);
    }
    _underlying = std::move(view);
}
Пример #3
0
 void DeviceContext::Bind(const IndexBuffer& ib, NativeFormat::Enum indexFormat, unsigned offset)
 {
     _underlying->IASetIndexBuffer(ib.GetUnderlying(), AsDXGIFormat(indexFormat), offset);
 }