~raph/dx11-toy

6d377275e6a27e72b1282230acd6a87ed28245dc — Raph Levien 2 years ago c3700a7 compiled_shader
Use precompiled shaders
5 files changed, 18 insertions(+), 5 deletions(-)

A shaders/ps.cso
M shaders/shaders.hlsl
A shaders/vs.cso
M src/d3d11.rs
M src/main.rs
A shaders/ps.cso => shaders/ps.cso +0 -0
M shaders/shaders.hlsl => shaders/shaders.hlsl +7 -0
@@ 1,3 1,10 @@
/*
Commandline:

/c/Program\ Files\ \(x86\)/Windows\ Kits/10/bin/x64/fxc shaders/shaders.hlsl //T vs_5_0 //E vs_main //Fo shaders/vs.cso
/c/Program\ Files\ \(x86\)/Windows\ Kits/10/bin/x64/fxc shaders/shaders.hlsl //T ps_5_0 //E ps_main //Fo shaders/ps.cso
*/

float4 vs_main( float4 pos : POSITION ) : SV_POSITION
{
	return pos;

A shaders/vs.cso => shaders/vs.cso +0 -0
M src/d3d11.rs => src/d3d11.rs +1 -0
@@ 206,6 206,7 @@ impl D3D11DeviceContext {
    }
}

#[allow(unused)]
impl D3DBlob {
    pub fn compile_shader(
        hlsl: &str,

M src/main.rs => src/main.rs +10 -5
@@ 1,7 1,6 @@
use std::ptr::{null, null_mut};

use winapi::shared::dxgi::DXGI_SWAP_EFFECT_SEQUENTIAL;
// compatibility is good.
use winapi::shared::{dxgi1_2, dxgiformat, dxgitype, minwindef};
use winapi::shared::dxgiformat::DXGI_FORMAT_R32G32B32_FLOAT;
use winapi::um::d3dcommon::D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;


@@ 14,8 13,9 @@ mod d3d11;
mod dxgi;
mod util;

use d3d11::D3DBlob;
//use d3d11::D3DBlob;

#[allow(unused)]
const SHADER_HLSL: &str = include_str!("../shaders/shaders.hlsl");




@@ 77,12 77,17 @@ fn main() {
            .create_swapchain_for_hwnd(&d3d_device, hwnd, &desc)
            .unwrap();

        /*
        let vertex_shader_bc =
            D3DBlob::compile_shader(SHADER_HLSL, "vs_5_0", "vs_main", 0).unwrap();
        let vertex_shader = d3d_device.create_vertex_shader(&vertex_shader_bc).unwrap();
        let pixel_shader_bc =
            D3DBlob::compile_shader(SHADER_HLSL, "ps_5_0", "ps_main", 0).unwrap();
        let pixel_shader = d3d_device.create_pixel_shader(&pixel_shader_bc).unwrap();
        */
        let vertex_shader_bc = include_bytes!("../shaders/vs.cso");
        let pixel_shader_bc = include_bytes!("../shaders/ps.cso");

        let vertex_shader = d3d_device.create_vertex_shader(vertex_shader_bc).unwrap();
        let pixel_shader = d3d_device.create_pixel_shader(pixel_shader_bc).unwrap();

        let ieds = [
            winapi::um::d3d11::D3D11_INPUT_ELEMENT_DESC {


@@ 95,7 100,7 @@ fn main() {
                InstanceDataStepRate: 0,
            },
        ];
        let input_layout = d3d_device.create_input_layout(&ieds, &vertex_shader_bc).unwrap();
        let input_layout = d3d_device.create_input_layout(&ieds, vertex_shader_bc).unwrap();

        device_context.vs_set_shader(&vertex_shader);
        device_context.ps_set_shader(&pixel_shader);