private void CreateCSs() { var d3dDevice = this.deviceResources.D3DDevice; this.s_pEdgeFactorCS = d3dDevice.CreateComputeShader(File.ReadAllBytes("TessellatorCS40_EdgeFactorCS.cso"), null); this.s_pScatterVertexTriIDIndexIDCS = d3dDevice.CreateComputeShader(File.ReadAllBytes("TessellatorCS40_ScatterVertexTriIDCS.cso"), null); this.s_pScatterIndexTriIDIndexIDCS = d3dDevice.CreateComputeShader(File.ReadAllBytes("TessellatorCS40_ScatterIndexTriIDCS.cso"), null); }
private void RunComputeShader( D3D11ComputeShader pComputeShader, D3D11ShaderResourceView[] pShaderResourceViews, D3D11Buffer pNeverChangesCBCS, D3D11Buffer pCBCS, //T pCSData, //uint dwNumDataBytes, D3D11UnorderedAccessView pUnorderedAccessView, uint x, uint y, uint z) //where T : struct { var d3dContext = this.deviceResources.D3DContext; d3dContext.ComputeShaderSetShader(pComputeShader, null); d3dContext.ComputeShaderSetShaderResources(0, pShaderResourceViews); d3dContext.ComputeShaderSetUnorderedAccessViews(0, new[] { pUnorderedAccessView }, new[] { 0U }); //if (pCBCS != null) //{ // d3dContext.UpdateSubresource(pCBCS, D3D11Utils.CalcSubresource(0, 0, 1), null, pCSData, dwNumDataBytes, dwNumDataBytes); //} if (pNeverChangesCBCS != null && pCBCS != null) { d3dContext.ComputeShaderSetConstantBuffers(0, new[] { pNeverChangesCBCS, pCBCS }); } if (pNeverChangesCBCS != null && pCBCS == null) { d3dContext.ComputeShaderSetConstantBuffers(0, new[] { pNeverChangesCBCS }); } if (pNeverChangesCBCS == null && pCBCS != null) { d3dContext.ComputeShaderSetConstantBuffers(0, new[] { pCBCS }); } d3dContext.Dispatch(x, y, z); d3dContext.ComputeShaderSetUnorderedAccessViews(0, new D3D11UnorderedAccessView[] { null }, new[] { 0U }); d3dContext.ComputeShaderSetShaderResources(0, new D3D11ShaderResourceView[] { null, null, null }); d3dContext.ComputeShaderSetConstantBuffers(0, new D3D11Buffer[] { }); }
static void RunComputeShader( D3D11DeviceContext pd3dImmediateContext, D3D11ComputeShader pComputeShader, D3D11ShaderResourceView[] pShaderResourceViews, D3D11UnorderedAccessView pUnorderedAccessView, uint X, uint Y, uint Z) { pd3dImmediateContext.ComputeShaderSetShader(pComputeShader, null); pd3dImmediateContext.ComputeShaderSetShaderResources(0, pShaderResourceViews); pd3dImmediateContext.ComputeShaderSetUnorderedAccessViews(0, new[] { pUnorderedAccessView }, new[] { 0U }); pd3dImmediateContext.Dispatch(X, Y, Z); pd3dImmediateContext.ComputeShaderSetShader(null, null); pd3dImmediateContext.ComputeShaderSetUnorderedAccessViews(0, new D3D11UnorderedAccessView[] { null }, new[] { 0U }); pd3dImmediateContext.ComputeShaderSetShaderResources(0, new D3D11ShaderResourceView[] { null, null }); pd3dImmediateContext.ComputeShaderSetConstantBuffers(0, new D3D11Buffer[] { null }); }
public void CreateDeviceDependentResources(DeviceResources resources) { var d3dDevice = resources.D3DDevice; this.m_pScanCS = d3dDevice.CreateComputeShader(File.ReadAllBytes("ScanInBucketComputeShader.cso"), null); this.m_pScan2CS = d3dDevice.CreateComputeShader(File.ReadAllBytes("ScanBucketResultComputeShader.cso"), null); this.m_pScan3CS = d3dDevice.CreateComputeShader(File.ReadAllBytes("ScanAddBucketResultComputeShader.cso"), null); this.m_pAuxBuf = d3dDevice.CreateBuffer(new D3D11BufferDesc { BindOptions = D3D11BindOptions.ShaderResource | D3D11BindOptions.UnorderedAccess, StructureByteStride = 4 * 2, // If scan types other than uint2, remember change here ByteWidth = 4 * 2 * 128, MiscOptions = D3D11ResourceMiscOptions.BufferStructured, Usage = D3D11Usage.Default }); this.m_pAuxBufRV = d3dDevice.CreateShaderResourceView(this.m_pAuxBuf, new D3D11ShaderResourceViewDesc { ViewDimension = D3D11SrvDimension.Buffer, Format = DxgiFormat.Unknown, Buffer = new D3D11BufferSrv { FirstElement = 0, NumElements = 128 } }); this.m_pAuxBufUAV = d3dDevice.CreateUnorderedAccessView(this.m_pAuxBuf, new D3D11UnorderedAccessViewDesc { ViewDimension = D3D11UavDimension.Buffer, Format = DxgiFormat.Unknown, Buffer = new D3D11BufferUav { FirstElement = 0, NumElements = 128 } }); }
static void CreateComputeShader() { var d3dDevice = deviceResources.D3DDevice; string path; #if USE_STRUCTURED_BUFFERS #if TEST_DOUBLE path = "BasicCompute11_StructuredBuffer_Double.cso"; #else path = "BasicCompute11_StructuredBuffer_NoDouble.cso"; #endif #else #if TEST_DOUBLE path = "BasicCompute11_NoStructuredBuffer_Double.cso"; #else path = "BasicCompute11_NoStructuredBuffer_NoDouble.cso"; #endif #endif g_pCS = d3dDevice.CreateComputeShader(File.ReadAllBytes(path), null); }
public void CreateDeviceDependentResources(DeviceResources resources) { this.deviceResources = resources; this.fragmentCountPS = this.deviceResources.D3DDevice.CreatePixelShader( File.ReadAllBytes("FragmentCountPS.cso"), null); this.createPrefixSumPass0CS = this.deviceResources.D3DDevice.CreateComputeShader( File.ReadAllBytes("CreatePrefixSumPass0CS.cso"), null); this.createPrefixSumPass1CS = this.deviceResources.D3DDevice.CreateComputeShader( File.ReadAllBytes("CreatePrefixSumPass1CS.cso"), null); this.fillDeepBufferPS = this.deviceResources.D3DDevice.CreatePixelShader( File.ReadAllBytes("FillDeepBufferPS.cso"), null); this.sortAndRenderCS = this.deviceResources.D3DDevice.CreateComputeShader( File.ReadAllBytes("SortAndRenderCS.cso"), null); var depthStencilDesc = new D3D11DepthStencilDesc { IsDepthEnabled = false, IsStencilEnabled = false }; this.depthStencilState = this.deviceResources.D3DDevice.CreateDepthStencilState(depthStencilDesc); this.computeShaderConstantBuffer = this.deviceResources.D3DDevice.CreateBuffer( new D3D11BufferDesc(OitComputeShaderConstantBufferData.Size, D3D11BindOptions.ConstantBuffer)); this.pixelShaderConstantBuffer = this.deviceResources.D3DDevice.CreateBuffer( new D3D11BufferDesc(OitPixelShaderConstantBufferData.Size, D3D11BindOptions.ConstantBuffer)); }
static void CreateResources() { var d3dDevice = deviceResources.D3DDevice; // Create the Bitonic Sort Compute Shader g_pComputeShaderBitonic = d3dDevice.CreateComputeShader(File.ReadAllBytes("CSSortBitonic.cso"), null); // Create the Matrix Transpose Compute Shader g_pComputeShaderTranspose = d3dDevice.CreateComputeShader(File.ReadAllBytes("CSSortTranspose.cso"), null); // Create the Const Buffer var constantBufferDesc = new D3D11BufferDesc(ConstantBufferData.Size, D3D11BindOptions.ConstantBuffer); g_pCB = d3dDevice.CreateBuffer(constantBufferDesc); // Create the Buffer of Elements // Create 2 buffers for switching between when performing the transpose var bufferDesc = new D3D11BufferDesc( NUM_ELEMENTS * sizeof(uint), D3D11BindOptions.UnorderedAccess | D3D11BindOptions.ShaderResource, D3D11Usage.Default, D3D11CpuAccessOptions.None, D3D11ResourceMiscOptions.BufferStructured, sizeof(uint)); g_pBuffer1 = d3dDevice.CreateBuffer(bufferDesc); g_pBuffer2 = d3dDevice.CreateBuffer(bufferDesc); // Create the Shader Resource View for the Buffers // This is used for reading the buffer during the transpose var srvbufferDesc = new D3D11ShaderResourceViewDesc(D3D11SrvDimension.Buffer, DxgiFormat.Unknown) { Buffer = new D3D11BufferSrv { ElementWidth = NUM_ELEMENTS } }; g_pBuffer1SRV = d3dDevice.CreateShaderResourceView(g_pBuffer1, srvbufferDesc); g_pBuffer2SRV = d3dDevice.CreateShaderResourceView(g_pBuffer2, srvbufferDesc); // Create the Unordered Access View for the Buffers // This is used for writing the buffer during the sort and transpose var uavbufferDesc = new D3D11UnorderedAccessViewDesc(D3D11UavDimension.Buffer, DxgiFormat.Unknown) { Buffer = new D3D11BufferUav { NumElements = NUM_ELEMENTS } }; g_pBuffer1UAV = d3dDevice.CreateUnorderedAccessView(g_pBuffer1, uavbufferDesc); g_pBuffer2UAV = d3dDevice.CreateUnorderedAccessView(g_pBuffer2, uavbufferDesc); // Create the Readback Buffer // This is used to read the results back to the CPU var readbackBufferDesc = new D3D11BufferDesc( NUM_ELEMENTS * sizeof(uint), D3D11BindOptions.None, D3D11Usage.Staging, D3D11CpuAccessOptions.Read, D3D11ResourceMiscOptions.None, sizeof(uint)); g_pReadBackBuffer = d3dDevice.CreateBuffer(readbackBufferDesc); }
public void CreateDeviceDependentResources(DeviceResources resources) { this.deviceResources = resources; var d3dDevice = this.deviceResources.D3DDevice; // Create the shaders byte[] renderParticlesVSBytecode = File.ReadAllBytes("ParticleDrawVS.cso"); this.g_pRenderParticlesVS = d3dDevice.CreateVertexShader(renderParticlesVSBytecode, null); this.g_pRenderParticlesGS = d3dDevice.CreateGeometryShader(File.ReadAllBytes("ParticleDrawGS.cso"), null); this.g_pRenderParticlesPS = d3dDevice.CreatePixelShader(File.ReadAllBytes("ParticleDrawPS.cso"), null); this.g_pCalcCS = d3dDevice.CreateComputeShader(File.ReadAllBytes("NBodyGravityCS.cso"), null); // Create our vertex input layout D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[] { new D3D11InputElementDesc { SemanticName = "COLOR", SemanticIndex = 0, Format = DxgiFormat.R32G32B32A32Float, InputSlot = 0, AlignedByteOffset = 0, InputSlotClass = D3D11InputClassification.PerVertexData, InstanceDataStepRate = 0 } }; this.g_pParticleVertexLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, renderParticlesVSBytecode); this.CreateParticleBuffer(); this.CreateParticlePosVeloBuffers(); // Setup constant buffer this.g_pcbGS = d3dDevice.CreateBuffer(new D3D11BufferDesc(ConstantBufferGS.Size, D3D11BindOptions.ConstantBuffer)); this.g_pcbCS = d3dDevice.CreateBuffer(new D3D11BufferDesc(ConstantBufferCS.Size, D3D11BindOptions.ConstantBuffer)); // Load the Particle Texture DdsDirectX.CreateTexture( "Particle.dds", this.deviceResources.D3DDevice, this.deviceResources.D3DContext, out this.g_pParticleTexRV); D3D11SamplerDesc SamplerDesc = D3D11SamplerDesc.Default; SamplerDesc.AddressU = D3D11TextureAddressMode.Clamp; SamplerDesc.AddressV = D3D11TextureAddressMode.Clamp; SamplerDesc.AddressW = D3D11TextureAddressMode.Clamp; SamplerDesc.Filter = D3D11Filter.MinMagMipLinear; this.g_pSampleStateLinear = d3dDevice.CreateSamplerState(SamplerDesc); D3D11BlendDesc BlendStateDesc = D3D11BlendDesc.Default; D3D11RenderTargetBlendDesc[] BlendStateDescRenderTargets = BlendStateDesc.GetRenderTargets(); BlendStateDescRenderTargets[0].IsBlendEnabled = true; BlendStateDescRenderTargets[0].BlendOperation = D3D11BlendOperation.Add; BlendStateDescRenderTargets[0].SourceBlend = D3D11BlendValue.SourceAlpha; BlendStateDescRenderTargets[0].DestinationBlend = D3D11BlendValue.One; BlendStateDescRenderTargets[0].BlendOperationAlpha = D3D11BlendOperation.Add; BlendStateDescRenderTargets[0].SourceBlendAlpha = D3D11BlendValue.Zero; BlendStateDescRenderTargets[0].DestinationBlendAlpha = D3D11BlendValue.Zero; BlendStateDescRenderTargets[0].RenderTargetWriteMask = D3D11ColorWriteEnables.All; BlendStateDesc.SetRenderTargets(BlendStateDescRenderTargets); this.g_pBlendingStateParticle = d3dDevice.CreateBlendState(BlendStateDesc); D3D11DepthStencilDesc DepthStencilDesc = D3D11DepthStencilDesc.Default; DepthStencilDesc.IsDepthEnabled = false; DepthStencilDesc.DepthWriteMask = D3D11DepthWriteMask.Zero; this.g_pDepthStencilState = d3dDevice.CreateDepthStencilState(DepthStencilDesc); XMFloat3 eye = new XMFloat3(-Spread * 2, Spread * 4, -Spread * 3); XMFloat3 at = new XMFloat3(0.0f, 0.0f, 0.0f); XMFloat3 up = new XMFloat3(0.0f, 1.0f, 0.0f); this.ViewMatrix = XMMatrix.LookAtLH(eye, at, up); }
public void LoadShader(string filename, out D3D11ComputeShader shader) { byte[] data = File.ReadAllBytes(filename); shader = this.d3dDevice.CreateComputeShader(data, null); }